Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1966533imj; Fri, 8 Feb 2019 10:10:19 -0800 (PST) X-Google-Smtp-Source: AHgI3IbPfJHO01mqLWe1tS/qc/dJ3D2AWSAK5gAsiYjlvz3/JFcoodxV/LRFTUfgCwHA/LKAFQzJ X-Received: by 2002:a62:c28e:: with SMTP id w14mr23499762pfk.115.1549649419277; Fri, 08 Feb 2019 10:10:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549649419; cv=none; d=google.com; s=arc-20160816; b=Tyjo55DAHzDE70Zx+l4q7Fcv4p7n/WjXjaDAgOy2S3E7GWhhZrau9GeKKgMBBNEgqg gbxPQIr5alyKKX8ODmd98P5dsUweHLOCuntpZqPCYP4C3qQbjp8QQZ7qI4bClHy9tklj bf7ZQJCKyB/ke8gZo/G4SiyJBkR8/rX8eqj6ApipSXuyrJY6LYtKDR48DuP/lOp/vsaz fg1OpER6flIj4yrKZsboeS+JWS0glajzpA/IkG06Zyb2waRxTNBMkBewT92dq+tg3A3a uMPgBqjzzuT9GZnIVmkjkSlmXmz6nF1uL7jW6WzVPI3zmlVzwyRiiBHsmBDO3ZGUszQ1 Tqhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1ha8tiaDoQDUW/w4Eg9NVxaHOTac5NWivcizqdQ179M=; b=LZMFsXUMggFyePkwm8GbvGRKjH5ngMU9r3kqrItAuOhs9rA7fXZRJkzqhCprxcerm1 biKU5b8GIwHq4usLLvnsWbxldoX5Au8er5r76wtY0SavetvfW5cxTs3J/kMGlNYBDBgu PESu8jz+1/RqG986hK1yH1sGPiTFBkPY1JWp1+bBQ8hTjgmbup0V/6lEGpfnxNSXIqRp lfqMMrGb6pjXjBIylU8k3ci51CVBIBwrPtKkqFU5vaHDljqqZzHHlM68nZyR9inLuQeK gKJaXOZj022DC795vcCNlUWs/BEmiEr9iS8ZLKG2Nv0J4BdEk+OZCbeRYY/CNS6lp0wu 6veA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VDqodEhz; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si2661068pgv.24.2019.02.08.10.10.03; Fri, 08 Feb 2019 10:10:19 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VDqodEhz; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727968AbfBHSIC (ORCPT + 99 others); Fri, 8 Feb 2019 13:08:02 -0500 Received: from mail-it1-f195.google.com ([209.85.166.195]:55388 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727373AbfBHSIC (ORCPT ); Fri, 8 Feb 2019 13:08:02 -0500 Received: by mail-it1-f195.google.com with SMTP id m62so10896550ith.5; Fri, 08 Feb 2019 10:08:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1ha8tiaDoQDUW/w4Eg9NVxaHOTac5NWivcizqdQ179M=; b=VDqodEhzP/xST8wGK5OrHBtM0hJWOrVvpmcLj+dps2H5Tz8/68X4XeqbZi0gXJMI7n RYSiWoeoEyXX5sEEWBE7kypMtrsCfWXjm/ZPFtsENx5tK0Q9XvdF4pBVJ9sbAj/3Neei S9Z8uEcMgTO6BMnlkRW8ykgwKF7yIRZ1QPlkN/d9S6cuvOI+nUk09dGohOENjaitI05K xU9+8cJS/7n0d+kldh2g16SEBDL1XaG1+kbd/3pqBIg42swbygzie6lyYFfR++ctwRb6 3VsL21eR+CyMO36j+HtTGlkKVGPRoti8euAnVPGBtc4RZOelxqzE9dX81l+Ra9SIlRY3 8WIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1ha8tiaDoQDUW/w4Eg9NVxaHOTac5NWivcizqdQ179M=; b=PKaVwKNNmM2X9kHWirYPpI4PDoYReLNCl2ysdsxVKJhkdrTHf1zSu+WlqKyERTZJ5t Xsxri1Mu1Gv84u8ygW7wlFxZZKb5jYX2mm7A6fPBvLFhB9ZVjfV/P/r7Z+8FUV1FKPj5 VP1DMPnLb9XyQSbfDRbMLRxFNFat/Xjh8oGS7P4pi5wgfCtrftpF3lXKgAFdKanKLTsx he9fEV7xTGW6LBjiSvNL4dS6PAIea3GmIrtb8a2u1QrTRVm4NYXHvrsVjcZLY4MRd2Fj fsSaqrlU28bhOLFH5XRie09/Oe2z51g1T89BBAeqyPfMMrWnWtMfGpxPeJlpYuNOCWe2 ZxXw== X-Gm-Message-State: AHQUAuazJYzHnhk9X/lpRIhDIvsXfJrD3obo/OkrLdsvr2sczbPoMavg IghQ4YoVoBr0Zhy0C2w+C2aGZ3rrW3Z1R41crog= X-Received: by 2002:a5e:8c14:: with SMTP id n20mr3449441ioj.200.1549649280774; Fri, 08 Feb 2019 10:08:00 -0800 (PST) MIME-Version: 1.0 References: <20190204201854.2328-1-nitesh@redhat.com> <20190204201854.2328-3-nitesh@redhat.com> In-Reply-To: <20190204201854.2328-3-nitesh@redhat.com> From: Alexander Duyck Date: Fri, 8 Feb 2019 10:07:49 -0800 Message-ID: Subject: Re: [RFC][Patch v8 2/7] KVM: Enabling guest free page hinting via static key To: Nitesh Narayan Lal Cc: kvm list , LKML , Paolo Bonzini , lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, Yang Zhang , Rik van Riel , david@redhat.com, "Michael S. Tsirkin" , dodgen@google.com, Konrad Rzeszutek Wilk , dhildenb@redhat.com, Andrea Arcangeli Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 4, 2019 at 2:11 PM Nitesh Narayan Lal wrote: > > 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 > { } > }; Since you are adding a new sysctl shouldn't you also be updating Documentation/sysctl/vm.txt? > 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); I'm not entirely sure this flag makes sense to me. What is to prevent someone from turning this on when there is no means of actually using the hints. I understand right now that guest_free_page doesn't actually do anything, but when it does I would assume it has to interact with a device. If that device is not present would it still make sense for us to be generating hints? > + > +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 >