Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1973571imm; Fri, 7 Sep 2018 08:55:48 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbg/h3S0C838wBQGi3L9LFs+jftMBrHfFl9o7V7ZCBa+i6GL0DNcpUZ89bZt861yd7n7scA X-Received: by 2002:a63:d70e:: with SMTP id d14-v6mr9099752pgg.110.1536335748303; Fri, 07 Sep 2018 08:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536335748; cv=none; d=google.com; s=arc-20160816; b=JumuoGFXIxTXcmpWVxDHok3f5cRW2o8/6SaQ6lMKpOfdI95I9z367EDwH9HMee86W1 LoUd8U6XR3+p45gJEmYW5qUdarb0aFHpuVBpDoXDY2xksDk0VUrluxvTwo432ApH0V/+ Nmdp2jGs/jfA2D+p8q4Rk99IWPdqtakfW41aCARhkjDTYJ0iuxc8OwNf1EKZQqxE1FzI Cg1KG7a36Jp/8N7uXrSFCbnFAju8LNM4n+ChhbqdAH6q9AA4tVz/aX5rWOofbEVe9fxZ Akc62Y0+2ZoHaeMANfGGTHg4aEMaQB0G5gNvyIi80gjb4KEfNHru5ERXs0Nq19v/js2E pvVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:organization :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=NMk6PXoQUKoQYta4lntG2iWYQxHrWv0r3tp30o9uqpY=; b=zfaMco2m/wjQNt+8pHqu8luA3k+sDPUeuS+7tIM/qO6IO13rsDtAwTeLgfxRI9hQDz 69kZ08VOP65JRQ1gL4Nw0MOwi4LOP3B0/rAGbCk8fE0LcQM2xC4/qjziWl4dWzk2iJq8 7OFSL1VFiTobB6ZpuOzPDxT9k4j3Z0EmuBGof3Ddr0S0PQ6ixVDahSk/YCQgYyVEPrV9 tW6i6OWKKN5qLL5cjmqVDC24jcastMDYjZ4RCI4FYO8sQWESHdl7oP+DdGZJF6Cz+8x8 iNyIhvIR94OKb5HWVsCvcFqFWvrFSPEUl+zOfCn1e2BYxmJuDlCYkhedFFD/MR9AlECs 9G1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=pdYupuzs; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d11-v6si5782207pla.245.2018.09.07.08.55.33; Fri, 07 Sep 2018 08:55:48 -0700 (PDT) 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=@messagingengine.com header.s=fm3 header.b=pdYupuzs; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730199AbeIGUNp (ORCPT + 99 others); Fri, 7 Sep 2018 16:13:45 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:55207 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727993AbeIGUNo (ORCPT ); Fri, 7 Sep 2018 16:13:44 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 802903F2; Fri, 7 Sep 2018 11:32:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 07 Sep 2018 11:32:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=NMk6PXoQUKoQYta4lntG2iWYQxHrW v0r3tp30o9uqpY=; b=pdYupuzsuC4pRdy9NxGFJ0JKRIMk0xSNZpUn4X8oupDvR IQAd+KaPSFV1U0slHYXUMmImYfgSKSxUw0c1cD3FOtE3Dyqew/duSC6ElXjxOzMk tZYvPvqgCO/PsbS/hqoS3sRrH6yhh/jkQHhQZhyRp/+8brpTJbIrMSIxj8cv7OE3 hyLOG4lBUUglNL1GUvPau7FH1cDZBsRoV5IuIGGlqdX6rUNkJY0Yl29vzfAXnY/J kJKFLDuqNMjDse85HDgHph9x/adEN0pMA4ff/Ik4z3nSx2if4pakovx/i3jzSo2g wBCvSNc6GoxKh4A8x2gY+SQ+/hdzlD41IV2hRYezA== X-ME-Proxy: X-ME-Sender: Received: from localhost.localdomain (ip5b40bfaa.dynamic.kabel-deutschland.de [91.64.191.170]) by mail.messagingengine.com (Postfix) with ESMTPA id D58BA10292; Fri, 7 Sep 2018 11:32:13 -0400 (EDT) From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Jonathan Corbet , Boris Ostrovsky , Juergen Gross , Thomas Gleixner , Ingo Molnar , Bjorn Helgaas , Greg Kroah-Hartman , Kai-Heng Feng , Thymo van Beers , Jiri Kosina , Konrad Rzeszutek Wilk , Frederic Weisbecker , David Rientjes , linux-kernel@vger.kernel.org (open list), linux-doc@vger.kernel.org (open list:DOCUMENTATION) Subject: [PATCH v2] xen/balloon: add runtime control for scrubbing ballooned out pages Date: Fri, 7 Sep 2018 17:31:14 +0200 Message-Id: <20180907153117.17258-1-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Organization: Invisible Things Lab Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Scrubbing pages on initial balloon down can take some time, especially in nested virtualization case (nested EPT is slow). When HVM/PVH guest is started with memory= significantly lower than maxmem=, all the extra pages will be scrubbed before returning to Xen. But since most of them weren't used at all at that point, Xen needs to populate them first (from populate-on-demand pool). In nested virt case (Xen inside KVM) this slows down the guest boot by 15-30s with just 1.5GB needed to be returned to Xen. Add runtime parameter to enable/disable it, to allow initially disabling scrubbing, then enable it back during boot (for example in initramfs). Such usage relies on assumption that a) most pages ballooned out during initial boot weren't used at all, and b) even if they were, very few secrets are in the guest at that time (before any serious userspace kicks in). Convert CONFIG_XEN_SCRUB_PAGES to CONFIG_XEN_SCRUB_PAGES_DEFAULT (also enabled by default), controlling default value for the new runtime switch. Signed-off-by: Marek Marczykowski-Górecki --- Changes in v2: - move sysfs control to /sys/devices/system/xen_memory - use core_param() to avoid confusing prefix for the option name - document option - change CONFIG_XEN_SCRUB_PAGES to CONFIG_XEN_SCRUB_PAGES_DEFAULT, controlling only the default value for the runtime option --- .../ABI/stable/sysfs-devices-system-xen_memory | 9 +++++++++ Documentation/admin-guide/kernel-parameters.txt | 6 ++++++ drivers/xen/Kconfig | 10 +++++++--- drivers/xen/mem-reservation.c | 8 ++++++++ drivers/xen/xen-balloon.c | 3 +++ include/xen/mem-reservation.h | 7 ++++--- 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Documentation/ABI/stable/sysfs-devices-system-xen_memory b/Documentation/ABI/stable/sysfs-devices-system-xen_memory index caa311d59ac1..6d83f95a8a8e 100644 --- a/Documentation/ABI/stable/sysfs-devices-system-xen_memory +++ b/Documentation/ABI/stable/sysfs-devices-system-xen_memory @@ -75,3 +75,12 @@ Contact: Konrad Rzeszutek Wilk Description: Amount (in KiB) of low (or normal) memory in the balloon. + +What: /sys/devices/system/xen_memory/xen_memory0/scrub_pages +Date: September 2018 +KernelVersion: 4.20 +Contact: xen-devel@lists.xenproject.org +Description: + Control scrubbing pages before returning them to Xen for others domains + use. Can be set with xen_scrub_pages cmdline + parameter. Default value controlled with CONFIG_XEN_SCRUB_PAGES_DEFAULT. diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9871e649ffef..0f20282629de 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4994,6 +4994,12 @@ Disables the PV optimizations forcing the HVM guest to run as generic HVM guest with no PV drivers. + xen_scrub_pages= [XEN] + Boolean option to control scrubbing pages before giving them back + to Xen, for use by other domains. Can be also changed at runtime + with /sys/devices/system/xen_memory/xen_memory0/scrub_pages. + Default value controlled with CONFIG_XEN_SCRUB_PAGES_DEFAULT. + xirc2ps_cs= [NET,PCMCIA] Format: ,,,,,[,[,[,]]] diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig index b459edfacff3..90d387b50ab7 100644 --- a/drivers/xen/Kconfig +++ b/drivers/xen/Kconfig @@ -79,15 +79,19 @@ config XEN_BALLOON_MEMORY_HOTPLUG_LIMIT This value is used to allocate enough space in internal tables needed for physical memory administration. -config XEN_SCRUB_PAGES - bool "Scrub pages before returning them to system" +config XEN_SCRUB_PAGES_DEFAULT + bool "Scrub pages before returning them to system by default" depends on XEN_BALLOON default y help Scrub pages before returning them to the system for reuse by other domains. This makes sure that any confidential data is not accidentally visible to other domains. Is it more - secure, but slightly less efficient. + secure, but slightly less efficient. This can be controlled with + xen_scrub_pages=0 parameter and + /sys/devices/system/xen_memory/xen_memory0/scrub_pages. + This option only sets the default value. + If in doubt, say yes. config XEN_DEV_EVTCHN diff --git a/drivers/xen/mem-reservation.c b/drivers/xen/mem-reservation.c index 084799c6180e..14276e2d76fe 100644 --- a/drivers/xen/mem-reservation.c +++ b/drivers/xen/mem-reservation.c @@ -14,6 +14,14 @@ #include #include +#include + +#ifdef CONFIG_XEN_SCRUB_PAGES_DEFAULT +bool __read_mostly xen_scrub_pages = true; +#else +bool __read_mostly xen_scrub_pages = false; +#endif +core_param(xen_scrub_pages, xen_scrub_pages, bool, 0); /* * Use one extent per PAGE_SIZE to avoid to break down the page into diff --git a/drivers/xen/xen-balloon.c b/drivers/xen/xen-balloon.c index 294f35ce9e46..63c1494a8d73 100644 --- a/drivers/xen/xen-balloon.c +++ b/drivers/xen/xen-balloon.c @@ -44,6 +44,7 @@ #include #include #include +#include #define PAGES2KB(_p) ((_p)<<(PAGE_SHIFT-10)) @@ -137,6 +138,7 @@ static DEVICE_ULONG_ATTR(schedule_delay, 0444, balloon_stats.schedule_delay); static DEVICE_ULONG_ATTR(max_schedule_delay, 0644, balloon_stats.max_schedule_delay); static DEVICE_ULONG_ATTR(retry_count, 0444, balloon_stats.retry_count); static DEVICE_ULONG_ATTR(max_retry_count, 0644, balloon_stats.max_retry_count); +static DEVICE_BOOL_ATTR(scrub_pages, 0644, xen_scrub_pages); static ssize_t show_target_kb(struct device *dev, struct device_attribute *attr, char *buf) @@ -203,6 +205,7 @@ static struct attribute *balloon_attrs[] = { &dev_attr_max_schedule_delay.attr.attr, &dev_attr_retry_count.attr.attr, &dev_attr_max_retry_count.attr.attr, + &dev_attr_scrub_pages.attr.attr, NULL }; diff --git a/include/xen/mem-reservation.h b/include/xen/mem-reservation.h index 80b52b4945e9..a2ab516fcd2c 100644 --- a/include/xen/mem-reservation.h +++ b/include/xen/mem-reservation.h @@ -17,11 +17,12 @@ #include +extern bool xen_scrub_pages; + static inline void xenmem_reservation_scrub_page(struct page *page) { -#ifdef CONFIG_XEN_SCRUB_PAGES - clear_highpage(page); -#endif + if (xen_scrub_pages) + clear_highpage(page); } #ifdef CONFIG_XEN_HAVE_PVMMU -- 2.17.1