File livepatch_main.c of Package kernel-livepatch-SLE15_Update_2.8541

/*
 * livepatch_main.c - kernel live patch main infrastructure
 *
 * Copyright (c) 2014 SUSE
 *  Author: Miroslav Benes <mbenes@suse.cz>
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include <linux/livepatch.h>
#include <linux/module.h>
#include <linux/types.h>

#include "uname_patch/livepatch_uname.h"

/* Auto expanded KLP_PATCHES_INCLUDES: */
#include "bsc1097108/livepatch_bsc1097108.h"
#include "bsc1099306/livepatch_bsc1099306.h"
#include "bsc1105026/livepatch_bsc1105026.h"


static struct klp_object objs[] = {
	/* Auto expanded KLP_PATCHES_OBJS: */
	{
		.name = NULL,
		.funcs = (struct klp_func[]) {
			{ .old_name = "SyS_newuname", .new_func = klp_sys_newuname, },
#if IS_ENABLED(CONFIG_X86_64) && IS_ENABLED(CONFIG_KVM)
			{ .old_name = "irq_enter", .new_func = klp_irq_enter, },
#endif
			{ }
		}
	},
#if IS_ENABLED(CONFIG_X86_64) && IS_ENABLED(CONFIG_KVM)
	{
		.name = "kvm",
		.funcs = (struct klp_func[]) {
			{ .old_name = "segmented_read_std", .new_func = klp_segmented_read_std, },
			{ .old_name = "segmented_write_std", .new_func = klp_segmented_write_std, },
			{ .old_name = "kvm_write_guest_virt_system", .new_func = klp_kvm_write_guest_virt_system, },
			{ .old_name = "x86_emulate_instruction", .new_func = klp_x86_emulate_instruction, },
			{ .old_name = "kvm_arch_vcpu_ioctl_run", .new_func = klp_kvm_arch_vcpu_ioctl_run, },
			{ .old_name = "kvm_arch_sched_in", .new_func = klp_kvm_arch_sched_in, },
			{ .old_name = "kvm_arch_vcpu_create", .new_func = klp_kvm_arch_vcpu_create, },
			{ .old_name = "kvm_handle_page_fault", .new_func = klp_kvm_handle_page_fault, },
			{ }
		}
	},
#endif
#if IS_ENABLED(CONFIG_X86_64) && IS_ENABLED(CONFIG_KVM)
	{
		.name = "kvm_intel",
		.funcs = (struct klp_func[]) {
			{ .old_name = "vmx_save_host_state", .new_func = klp_vmx_save_host_state, },
			{ .old_name = "vmx_handle_external_intr", .new_func = klp_vmx_handle_external_intr, },
			{ .old_name = "nested_vmx_run", .new_func = klp_nested_vmx_run, },
			{ }
		}
	},
#endif
#if IS_ENABLED(CONFIG_XEN_NETDEV_BACKEND)
	{
		.name = "xen_netback",
		.funcs = (struct klp_func[]) {
			{ .old_name = "xenvif_set_hash_mapping", .new_func = klp_xenvif_set_hash_mapping, },
			{ }
		}
	},
#endif
	{ }
};

static struct klp_patch patch = {
	.mod = THIS_MODULE,
	.objs = objs,
	.replace = true,
};

static int __init klp_patch_init(void)
{
	int retval;

	pr_info("livepatch: initializing\n");

	retval = klp_patch_uname_init();
	if (retval)
		return retval;

	/* Auto expanded KLP_PATCHES_INIT_CALLS: */
	retval = livepatch_bsc1097108_init();
	if (retval)
		goto err_bsc1097108;

	retval = livepatch_bsc1099306_init();
	if (retval)
		goto err_bsc1099306;

	retval = livepatch_bsc1105026_init();
	if (retval)
		goto err_bsc1105026;

	retval = klp_register_patch(&patch);
	if (retval)
		goto err_patches_cleanup;
	retval = klp_enable_patch(&patch);
	if (!retval)
		return retval;

	WARN_ON(klp_unregister_patch(&patch));

err_patches_cleanup:
	/* Auto expanded KLP_PATCHES_INIT_ERR_HANDLERS: */
	livepatch_bsc1105026_cleanup();
err_bsc1105026:
	livepatch_bsc1099306_cleanup();
err_bsc1099306:
	livepatch_bsc1097108_cleanup();
err_bsc1097108:

	return retval;
}

static void __exit klp_patch_cleanup(void)
{
	pr_info("livepatch: removed\n");

	/* Auto expanded KLP_PATCHES_CLEANUP_CALLS: */
	livepatch_bsc1097108_cleanup();
	livepatch_bsc1099306_cleanup();
	livepatch_bsc1105026_cleanup();


	WARN_ON(klp_unregister_patch(&patch));
}

module_init(klp_patch_init);
module_exit(klp_patch_cleanup);

MODULE_LICENSE("GPL");
MODULE_INFO(livepatch, "Y");