Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4291562ima; Mon, 4 Feb 2019 13:45:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IbZ3IygPJ6+DV4KnphZ+eEedzcGeSm2qwsHhjyY6vB7f+SfPt750rDg6SmvG+8cxGhOCJ3f X-Received: by 2002:a62:5c41:: with SMTP id q62mr1484810pfb.171.1549316741960; Mon, 04 Feb 2019 13:45:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549316741; cv=none; d=google.com; s=arc-20160816; b=Yb4WnAMkl+srwRveh4/R6qqu0b48H/Oehp2KEeRJRZ7lm6gnGYdqDCoC6HRI8gUiR3 YmlmHuV2LKKg0kwTbzRkUzJcXZ1mJCIrvEOJ/Fd1bySPbIirNUcJULCjIXE9RBJDxYqq c7uWQ+i20m+etnFFo8e3+MN4aJxxiaddWQ0RwZduremLdARqKn3h703ZQpwJOcSLc4LR bwe9mlGwp0/Os/+Y7BWcpqdKxUDJFffkZHhcoBgpHNlQJlIjktRuL/g+aZgGG3SuyQvk xMr4wf1SJyvuB+9fPG4YFI9uhLi+VWazWhTiVw/WHs9lGeFD/snQvLQyur+RuQ9TCMJq 6kCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=M2wHK6jFJPmk/2wDd4tzT4k469b75YFknkmF6N3j0mQ=; b=AvC7+PI9aDD6W3v70h3qnBiCZF4v07rk1kU/dsW1NkfncKpa8dQE4kKnPlNvtrVtrm 0B/S3DOXlPAjbrT0PO2x3rgL1jeSbhPGTszj3zAR6OLVley5z490emnH/nKFvjeA4kqF 0jve/iqOp0ie5ktFb1DfgU8Trm5XcatS9Iv7EXN+9B3sUUMfkg7cy/nkv/V0Xummm/EF NQek2ByU2Krrlelhocj25Ml+WZV1RzTmLBBe49SK5Km6GRaMrY7HMuvF5cTiqcwCNPkG 623kdV6DmvNr1eRKvXy3Nihh5D6+8pION+xzyQSzgWL4n9Ju512IYJW8Gb6tAMlgV/Kc 4/CA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f10si1007339pgo.356.2019.02.04.13.45.25; Mon, 04 Feb 2019 13:45:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728135AbfBDUTp (ORCPT + 99 others); Mon, 4 Feb 2019 15:19:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48122 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728042AbfBDUTk (ORCPT ); Mon, 4 Feb 2019 15:19:40 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D69D8B10E; Mon, 4 Feb 2019 20:19:39 +0000 (UTC) Received: from virtlab420.virt.lab.eng.bos.redhat.com (virtlab420.virt.lab.eng.bos.redhat.com [10.19.152.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D0538AD93; Mon, 4 Feb 2019 20:19:37 +0000 (UTC) From: Nitesh Narayan Lal To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, yang.zhang.wz@gmail.com, riel@surriel.com, david@redhat.com, mst@redhat.com, dodgen@google.com, konrad.wilk@oracle.com, dhildenb@redhat.com, aarcange@redhat.com Subject: [RFC][Patch v8 2/7] KVM: Enabling guest free page hinting via static key Date: Mon, 4 Feb 2019 15:18:49 -0500 Message-Id: <20190204201854.2328-3-nitesh@redhat.com> In-Reply-To: <20190204201854.2328-1-nitesh@redhat.com> References: <20190204201854.2328-1-nitesh@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 04 Feb 2019 20:19:39 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch enables the guest free page hinting support to enable or disable based on the STATIC key which could be set via sysctl. Signed-off-by: Nitesh Narayan Lal --- include/linux/gfp.h | 2 ++ include/linux/page_hinting.h | 5 +++++ kernel/sysctl.c | 9 +++++++++ virt/kvm/page_hinting.c | 23 +++++++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index e596527284ba..8389219a076a 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -461,6 +461,8 @@ static inline struct zonelist *node_zonelist(int nid, gfp_t flags) #define HAVE_ARCH_FREE_PAGE static inline void arch_free_page(struct page *page, int order) { + if (!static_branch_unlikely(&guest_page_hinting_key)) + return; guest_free_page(page, order); } #endif diff --git a/include/linux/page_hinting.h b/include/linux/page_hinting.h index b54f7428f348..9bdcf63e1306 100644 --- a/include/linux/page_hinting.h +++ b/include/linux/page_hinting.h @@ -14,4 +14,9 @@ struct hypervisor_pages { unsigned int order; }; +extern int guest_page_hinting_flag; +extern struct static_key_false guest_page_hinting_key; + +int guest_page_hinting_sysctl(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, loff_t *ppos); void guest_free_page(struct page *page, int order); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index ba4d9e85feb8..5d53629c9bfb 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1690,6 +1690,15 @@ static struct ctl_table vm_table[] = { .extra1 = (void *)&mmap_rnd_compat_bits_min, .extra2 = (void *)&mmap_rnd_compat_bits_max, }, +#endif +#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 818bd6b84e0c..4a34ea8db0c8 100644 --- a/virt/kvm/page_hinting.c +++ b/virt/kvm/page_hinting.c @@ -1,6 +1,7 @@ #include #include #include +#include /* * struct kvm_free_pages - Tracks the pages which are freed by the guest. @@ -31,6 +32,28 @@ struct page_hinting { DEFINE_PER_CPU(struct page_hinting, hinting_obj); +struct static_key_false guest_page_hinting_key = STATIC_KEY_FALSE_INIT; +EXPORT_SYMBOL(guest_page_hinting_key); +static DEFINE_MUTEX(hinting_mutex); +int guest_page_hinting_flag; +EXPORT_SYMBOL(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; +} + void guest_free_page(struct page *page, int order) { } -- 2.17.2