Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2037738imm; Fri, 7 Sep 2018 09:51:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaMXPkSvp9zIlZ/IO2BmS8TqbxtLVND7OlnR3DcQ3F/szdNBrYGUwhOpcII2cZBEDsJ59uj X-Received: by 2002:a62:b20c:: with SMTP id x12-v6mr9392931pfe.201.1536339087923; Fri, 07 Sep 2018 09:51:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536339087; cv=none; d=google.com; s=arc-20160816; b=zQUIygMIeuQppamfejzIPJuYgfu0BHFz4i4LrCU7qX/tF7lOUY+Jy8l5u6Y+gTWyym 1ccTemZB79Txr69SJ7vkyxSK3pgCpbFahDSs0Lt8NZtQ/tN3pNfQlnJRBv/XG4Yedegf VGbm0ndahqwwgepFp8bAvh62mge02cm6YHzIvKADvtXFqvZ02YXL9z8TpHd8a/nsDs1Q k34oKf9iq7kC48f1UXOiNjrw8qJj59xJQA4KtGLXmO/kpKWV9gsIBjLjAtxCGGtZfj7E MGXzzYXqcfof33jtVXl3sYaE4Me/nfjFI47quw0P8X++9bj4sF32IYtsLg3la5GF6q6g 2CMQ== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tYwBvL9VQ10Ez5FgK+OrG/o+97YtIf4nmUYV83cKyuM=; b=dQs/YcRkkrRbi6MoGv5MsoQYe1OUj3vc3MfodN43qskZYgSHipEmZXF/KfKmSuiBlS v9EaL38TNkTORyN7ZSkZ98VTPKWHLLDJMWSNZc18hHxwEMkbGY/nwA38J0Oswj9ck1GP lYJ5y4oeMYI2GHW+YsCbSOJfanJeMXr4VLYMxsx1Rzx8exQdQbYwl00alqWEaXdUGSuH xtDxCoeskBC0W/FvykJwlBzfh+Sn+oO5LJ7WhG6m0GVXHjXbmLe88/Qh/BCm/sCCM+fK 9btTB/wviFFXPlyw70NW/K0ILaRQLrxHLKIRhUP5eJiyI8axEZtmG2PQy1C+O33uT467 lzIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=lr2IzAoe; 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 p16-v6si9286144pgc.82.2018.09.07.09.51.12; Fri, 07 Sep 2018 09:51:27 -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=lr2IzAoe; 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 S1726506AbeIGVbM (ORCPT + 99 others); Fri, 7 Sep 2018 17:31:12 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:33381 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726032AbeIGVbM (ORCPT ); Fri, 7 Sep 2018 17:31:12 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 7D8B22C1; Fri, 7 Sep 2018 12:49:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 07 Sep 2018 12:49:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=tYwBvL 9VQ10Ez5FgK+OrG/o+97YtIf4nmUYV83cKyuM=; b=lr2IzAoe8jSMGQJ0mFCXI6 32RZwt2p6fGqFwSDWM+kcwDqbJRzHmON8ZKPAkHUHsbeK22ZUHpS4LQPSXhsCwRe v6n2TuUxfRe1qDpXwlsHTsRVM/UN5oCI26rkO9fOEahGLrHSTrcpCg86MCcjVDgN j77nmUHAuMB6hStdfXba3w/bHoP1+j5HJXALnTxXLtt2BAkkYQU2n8PoddsrjFzj R8mgmq6RNm888DreCrzXJ63qRURQxCBF/ITltG9eqK/2C0O5n8cMSHSz3MtE+dCM jXEkDMMqcDvhh+MehTzTg17nuY2b1RzV/6t7RtsyoUUL48rK1L595EZJuAwIdnZQ == 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 12F6CE44DC; Fri, 7 Sep 2018 12:49:18 -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 v3] xen/balloon: add runtime control for scrubbing ballooned out pages Date: Fri, 7 Sep 2018 18:49:08 +0200 Message-Id: <20180907164912.21075-1-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <5B92A01D02000078001E67CE@prv1-mh.provo.novell.com> References: <5B92A01D02000078001E67CE@prv1-mh.provo.novell.com> 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 Changes in v3: - use IS_ENABLED() --- .../ABI/stable/sysfs-devices-system-xen_memory | 9 +++++++++ Documentation/admin-guide/kernel-parameters.txt | 6 ++++++ drivers/xen/Kconfig | 10 +++++++--- drivers/xen/mem-reservation.c | 4 ++++ drivers/xen/xen-balloon.c | 3 +++ include/xen/mem-reservation.h | 7 ++++--- 6 files changed, 33 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..3782cf070338 100644 --- a/drivers/xen/mem-reservation.c +++ b/drivers/xen/mem-reservation.c @@ -14,6 +14,10 @@ #include #include +#include + +bool __read_mostly xen_scrub_pages = IS_ENABLED(CONFIG_XEN_SCRUB_PAGES_DEFAULT); +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