From: nilal@redhat.com Subject: [Patch v4 6/6] KVM: Enabling guest page hinting via static key Date: Fri, 3 Nov 2017 16:30:13 -0400 Message-ID: <20171103203013.9521-7-nilal@redhat.com> References: <20171103203013.9521-1-nilal@redhat.com> To: kvm@vger.kernel.org, pbonzini@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, yang.zhang.wz@gmail.com, riel@redhat.com, david@redhat.com, mst@redhat.com, dodgen@google.com, konrad.wilk@oracle.com Return-path: Received: from mx1.redhat.com ([209.132.183.28]:62285 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754501AbdKCUbK (ORCPT ); Fri, 3 Nov 2017 16:31:10 -0400 In-Reply-To: <20171103203013.9521-1-nilal@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: From: Nitesh Narayan Lal 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 --- 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 #include #include +#include #include #include @@ -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