From: 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
Subject: [Patch v4 6/6] KVM: Enabling guest page hinting via static key
Date: Fri, 3 Nov 2017 16:30:13 -0400 [thread overview]
Message-ID: <20171103203013.9521-7-nilal@redhat.com> (raw)
In-Reply-To: <20171103203013.9521-1-nilal@redhat.com>
From: Nitesh Narayan Lal <nilal@redhat.com>
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@redhat.com>
---
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
next prev parent reply other threads:[~2017-11-03 20:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-03 20:30 [Patch v4 0/6] KVM: Guest page hinting nilal
2017-11-03 20:30 ` [Patch v4 1/6] KVM: Support for guest " nilal
2017-11-13 17:59 ` Michael S. Tsirkin
2017-11-15 19:38 ` Nitesh Narayan Lal
2017-11-15 20:06 ` Michael S. Tsirkin
2017-11-03 20:30 ` [Patch v4 2/6] KVM: Guest page hinting functionality nilal
2017-11-13 18:03 ` Michael S. Tsirkin
2017-11-03 20:30 ` [Patch v4 3/6] KVM: Adding tracepoints for guest page hinting nilal
2017-11-03 20:30 ` [Patch v4 4/6] virtio: Exposes added descriptor to the other side synchronously nilal
2017-11-03 20:30 ` [Patch v4 5/6] KVM: Sending hyperlist to the host via hinting_vq nilal
2017-11-03 20:30 ` nilal [this message]
2017-11-03 20:37 ` [QEMU PATCH] kvm: Support for guest page hinting nilal
2017-11-03 20:37 ` nilal
2017-11-06 11:21 ` Pankaj Gupta
2017-11-06 14:21 ` Nitesh Narayan Lal
2017-11-12 21:23 ` [Patch v4 0/6] KVM: Guest " Rik van Riel
2017-11-13 15:14 ` Nitesh Narayan Lal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171103203013.9521-7-nilal@redhat.com \
--to=nilal@redhat.com \
--cc=david@redhat.com \
--cc=dodgen@google.com \
--cc=konrad.wilk@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pagupta@redhat.com \
--cc=pbonzini@redhat.com \
--cc=riel@redhat.com \
--cc=wei.w.wang@intel.com \
--cc=yang.zhang.wz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox