kpatch/kmod/core/kpatch.h

49 lines
1.4 KiB
C
Raw Normal View History

/*
* kpatch.h
*
* Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
* Copyright (C) 2013-2014 Josh Poimboeuf <jpoimboe@redhat.com>
*
2014-03-05 03:34:03 +00:00
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA,
* 02110-1301, USA.
*
* Contains the API for the core kpatch module used by the patch modules
*/
#ifndef _KPATCH_H_
#define _KPATCH_H_
#include <linux/types.h>
struct kpatch_func {
unsigned long new_addr;
unsigned long new_size;
unsigned long old_addr;
unsigned long old_size;
struct hlist_node node;
kmod/core: Support live patching on NMI handlers Support live patching on NMI handlers. This adds checks for possible inconsistency of live patching on NMI handlers. The inconsistency problem means that any concurrent execution of old function and new function, which can lead unexpected results. Current kpatch checks possible inconsistency problem with stop_machine, which can cover only threads and normal interrupts. However, beacuse NMI can not stop with it, stop_machine is not enough for live patching on NMI handlers or sub-functions which are invoked in the NMI context. To check for possible inconsistency of live patching on those functions, add an atomic flag to count patching target functions invoked in NMI context while updating kpatch hash table. If the flag is set by the target functions in NMI, we can not ensure there is no concurrent execution on it. This fixes the issue #65. Changes from v5: - Fix to add a NULL check in kpatch_get_committed_func(). Changes from v4: - Change kpatch_operation to atomic_t. - Use smp_rmb/wmb barriers between kpatch_operation and kpatch_status. - Check in_nmi() first and if true, access kpatch_operation. Changes from v3: - Fix kpatch_apply/remove_patch to return 0 if succeeded. Changes from v2: - Clean up kpatch_get_committed_func as same style of kpatch_get_func. - Rename opr to op in kpatch_ftrace_handler. - Consolidate in_nmi() and kpatch_operation check into one condition. - Fix UNPATCH/PATCH mistype in kpatch_register. Changes from v1: - Rename inconsistent_flag to kpatch_status. - Introduce new enums and helper functions for kpatch_status. - Use hash_del_rcu instead of hlist_del_rcu. - Rename get_committed_func to kpatch_get_committed_func. - Use ACCESS_ONCE for kpatch_operation to prevent compiler optimization. - Fix to remove (!func || func->updating) condition from NMI check. - Add more precise comments. - Fix setting order of kpatch_status and kpatch_operation. Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
2014-04-23 01:58:45 +00:00
bool updating;
};
struct kpatch_module {
struct module *mod;
struct kpatch_func *funcs;
int num_funcs;
};
extern int kpatch_register(struct kpatch_module *kpmod);
extern int kpatch_unregister(struct kpatch_module *kpmod);
#endif /* _KPATCH_H_ */