@@ -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;
@@ -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
{ }
};
@@ -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