Skip to content

Commit 197ecb3

Browse files
marmarekBoris Ostrovsky
authored andcommitted
xen/balloon: add runtime control for scrubbing ballooned out pages
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 <marmarek@invisiblethingslab.com> Reviewed-by: Juergen Gross <jgross@suse.com> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
1 parent 87dffe8 commit 197ecb3

File tree

6 files changed

+33
-6
lines changed

6 files changed

+33
-6
lines changed

Documentation/ABI/stable/sysfs-devices-system-xen_memory

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,12 @@ Contact: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
7575
Description:
7676
Amount (in KiB) of low (or normal) memory in the
7777
balloon.
78+
79+
What: /sys/devices/system/xen_memory/xen_memory0/scrub_pages
80+
Date: September 2018
81+
KernelVersion: 4.20
82+
Contact: xen-devel@lists.xenproject.org
83+
Description:
84+
Control scrubbing pages before returning them to Xen for others domains
85+
use. Can be set with xen_scrub_pages cmdline
86+
parameter. Default value controlled with CONFIG_XEN_SCRUB_PAGES_DEFAULT.

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,6 +5000,12 @@
50005000
Disables the PV optimizations forcing the HVM guest to
50015001
run as generic HVM guest with no PV drivers.
50025002

5003+
xen_scrub_pages= [XEN]
5004+
Boolean option to control scrubbing pages before giving them back
5005+
to Xen, for use by other domains. Can be also changed at runtime
5006+
with /sys/devices/system/xen_memory/xen_memory0/scrub_pages.
5007+
Default value controlled with CONFIG_XEN_SCRUB_PAGES_DEFAULT.
5008+
50035009
xirc2ps_cs= [NET,PCMCIA]
50045010
Format:
50055011
<irq>,<irq_mask>,<io>,<full_duplex>,<do_sound>,<lockup_hack>[,<irq2>[,<irq3>[,<irq4>]]]

drivers/xen/Kconfig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,19 @@ config XEN_BALLOON_MEMORY_HOTPLUG_LIMIT
7979
This value is used to allocate enough space in internal
8080
tables needed for physical memory administration.
8181

82-
config XEN_SCRUB_PAGES
83-
bool "Scrub pages before returning them to system"
82+
config XEN_SCRUB_PAGES_DEFAULT
83+
bool "Scrub pages before returning them to system by default"
8484
depends on XEN_BALLOON
8585
default y
8686
help
8787
Scrub pages before returning them to the system for reuse by
8888
other domains. This makes sure that any confidential data
8989
is not accidentally visible to other domains. Is it more
90-
secure, but slightly less efficient.
90+
secure, but slightly less efficient. This can be controlled with
91+
xen_scrub_pages=0 parameter and
92+
/sys/devices/system/xen_memory/xen_memory0/scrub_pages.
93+
This option only sets the default value.
94+
9195
If in doubt, say yes.
9296

9397
config XEN_DEV_EVTCHN

drivers/xen/mem-reservation.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
#include <xen/interface/memory.h>
1616
#include <xen/mem-reservation.h>
17+
#include <linux/moduleparam.h>
18+
19+
bool __read_mostly xen_scrub_pages = IS_ENABLED(CONFIG_XEN_SCRUB_PAGES_DEFAULT);
20+
core_param(xen_scrub_pages, xen_scrub_pages, bool, 0);
1721

1822
/*
1923
* Use one extent per PAGE_SIZE to avoid to break down the page into

drivers/xen/xen-balloon.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <xen/xenbus.h>
4545
#include <xen/features.h>
4646
#include <xen/page.h>
47+
#include <xen/mem-reservation.h>
4748

4849
#define PAGES2KB(_p) ((_p)<<(PAGE_SHIFT-10))
4950

@@ -137,6 +138,7 @@ static DEVICE_ULONG_ATTR(schedule_delay, 0444, balloon_stats.schedule_delay);
137138
static DEVICE_ULONG_ATTR(max_schedule_delay, 0644, balloon_stats.max_schedule_delay);
138139
static DEVICE_ULONG_ATTR(retry_count, 0444, balloon_stats.retry_count);
139140
static DEVICE_ULONG_ATTR(max_retry_count, 0644, balloon_stats.max_retry_count);
141+
static DEVICE_BOOL_ATTR(scrub_pages, 0644, xen_scrub_pages);
140142

141143
static ssize_t show_target_kb(struct device *dev, struct device_attribute *attr,
142144
char *buf)
@@ -203,6 +205,7 @@ static struct attribute *balloon_attrs[] = {
203205
&dev_attr_max_schedule_delay.attr.attr,
204206
&dev_attr_retry_count.attr.attr,
205207
&dev_attr_max_retry_count.attr.attr,
208+
&dev_attr_scrub_pages.attr.attr,
206209
NULL
207210
};
208211

include/xen/mem-reservation.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
#include <xen/page.h>
1919

20+
extern bool xen_scrub_pages;
21+
2022
static inline void xenmem_reservation_scrub_page(struct page *page)
2123
{
22-
#ifdef CONFIG_XEN_SCRUB_PAGES
23-
clear_highpage(page);
24-
#endif
24+
if (xen_scrub_pages)
25+
clear_highpage(page);
2526
}
2627

2728
#ifdef CONFIG_XEN_HAVE_PVMMU

0 commit comments

Comments
 (0)