From: Nitesh Narayan Lal <nilal@xxxxxxxxxx> This patch adds the support for enabling or disabling the guest page hinting based on the STATIC key which could be set via sysctl. Signed-off-by: Nitesh Narayan Lal <nilal@xxxxxxxxxx> --- include/linux/page_hinting.h | 3 +++ kernel/sysctl.c | 10 ++++++++++ virt/kvm/page_hinting.c | 26 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/include/linux/page_hinting.h b/include/linux/page_hinting.h index 0bfb646..6f6068a 100644 --- a/include/linux/page_hinting.h +++ b/include/linux/page_hinting.h @@ -14,3 +14,6 @@ struct hypervisor_pages { extern struct hypervisor_pages hypervisor_pagelist[MAX_FGPT_ENTRIES]; extern void (*request_hypercall)(void *, int); extern void *balloon_ptr; +int guest_page_hinting_sysctl(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, loff_t *ppos); +extern int guest_page_hinting_flag; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index d9c31bc..f4c4ddc 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -67,6 +67,7 @@ #include <linux/kexec.h> #include <linux/bpf.h> #include <linux/mount.h> +#include <linux/page_hinting.h> #include <linux/uaccess.h> #include <asm/processor.h> @@ -1849,6 +1850,15 @@ static struct ctl_table fs_table[] = { .proc_handler = proc_dointvec_minmax, .extra1 = &one, }, +#ifdef CONFIG_KVM_FREE_PAGE_HINTING + { + .procname = "guest-page-hinting", + .data = &guest_page_hinting_flag, + .maxlen = sizeof(guest_page_hinting_flag), + .mode = 0644, + .proc_handler = guest_page_hinting_sysctl, + }, +#endif { } }; diff --git a/virt/kvm/page_hinting.c b/virt/kvm/page_hinting.c index 22c892b..d4bfbce 100644 --- a/virt/kvm/page_hinting.c +++ b/virt/kvm/page_hinting.c @@ -30,6 +30,28 @@ void (*request_hypercall)(void *, int); EXPORT_SYMBOL(request_hypercall); void *balloon_ptr; EXPORT_SYMBOL(balloon_ptr); +DEFINE_STATIC_KEY_FALSE(guest_page_hinting_key); +EXPORT_SYMBOL(guest_page_hinting_key); +static DEFINE_MUTEX(hinting_mutex); +int guest_page_hinting_flag; + +int guest_page_hinting_sysctl(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, + loff_t *ppos) +{ + int ret; + + mutex_lock(&hinting_mutex); + + ret = proc_dointvec(table, write, buffer, lenp, ppos); + + if (guest_page_hinting_flag) + static_key_enable(&guest_page_hinting_key.key); + else + static_key_disable(&guest_page_hinting_key.key); + mutex_unlock(&hinting_mutex); + return ret; +} static void empty_hyperlist(void) { @@ -258,6 +280,8 @@ void arch_alloc_page(struct page *page, int order) { unsigned int seq; + if (!static_branch_unlikely(&guest_page_hinting_key)) + return; /* * arch_free_page will acquire the lock once the list carrying guest * free pages is full and a hypercall will be made. Until complete free @@ -276,6 +300,8 @@ void arch_free_page(struct page *page, int order) struct kvm_free_pages *free_page_obj; unsigned long flags; + if (!static_branch_unlikely(&guest_page_hinting_key)) + return; /* * use of global variables may trigger a race condition between irq and * process context causing unwanted overwrites. This will be replaced -- 2.9.4