From patchwork Fri Nov 3 20:30:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Lal X-Patchwork-Id: 10041169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1A8F9602D8 for ; Fri, 3 Nov 2017 20:31:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D68A29010 for ; Fri, 3 Nov 2017 20:31:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01E502991D; Fri, 3 Nov 2017 20:31:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BF042992A for ; Fri, 3 Nov 2017 20:31:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754719AbdKCUbO (ORCPT ); Fri, 3 Nov 2017 16:31:14 -0400 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 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3AFD3DA314; Fri, 3 Nov 2017 20:31:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3AFD3DA314 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=nilal@redhat.com Received: from Dungeon.bss.redhat.com (unknown [10.20.9.220]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC6F460317; Fri, 3 Nov 2017 20:31:08 +0000 (UTC) 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 Message-Id: <20171103203013.9521-7-nilal@redhat.com> In-Reply-To: <20171103203013.9521-1-nilal@redhat.com> References: <20171103203013.9521-1-nilal@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 03 Nov 2017 20:31:10 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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