Skip to contentSkip to conversation

mm/page_alloc: add bootscrub=idle cmdline option

PATCH In review Sergey Dyasli 2 participants 2 messages Oct 3, 2018 – Oct 8, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/page_alloc: add bootscrub=idle cmdline option

Scrubbing RAM during boot may take a long time on machines with lots of RAM. Add 'idle' option which marks all pages dirty initially so they would eventually be scrubbed in idle-loop on every online CPU.

Performance of idle-loop scrubbing is worse than bootscrub but it's guaranteed that the allocator will return scrubbed pages by doing eager scrubbing during allocation (unless MEMF_no_scrub was provided).

---
CC: Andrew Cooper <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Tim Deegan <[email protected]>

---
 docs/misc/xen-command-line.markdown |  7 +++++-
 xen/common/page_alloc.c             | 36 +++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 5 deletions(-)
docs/misc/xen-command-line.markdown +6 -1
index 1ffd586224..4c60905837 100644
@@ -227,7 +227,7 @@ that byte `0x12345678` is bad, you would place `badpage=0x12345` on
 Xen's command line.
 
 ### bootscrub
-> `= <boolean>`
+> `= <boolean> | idle`
 
 > Default: `true`
 
@@ -235,6 +235,11 @@ Scrub free RAM during boot.  This is a safety feature to prevent
 accidentally leaking sensitive VM data into other VMs if Xen crashes
 and reboots.
 
+In `idle` mode, RAM is scrubbed in background on all CPUs during idle-loop
+with a guarantee that memory allocations always provide scrubbed pages.
+This option reduces boot time on machines with a large amount of RAM while
+still providing security benefits.
+
 ### bootscrub\_chunk
 > `= <size>`
 
xen/common/page_alloc.c +32 -4
index 16e1b0c357..c85f44874a 100644
@@ -161,8 +161,32 @@ string_param("badpage", opt_badpage);
 /*
  * no-bootscrub -> Free pages are not zeroed during boot.
  */
-static bool_t opt_bootscrub __initdata = 1;
-boolean_param("bootscrub", opt_bootscrub);
+enum {
+    BOOTSCRUB_OFF = 0,
+    BOOTSCRUB_ON,
+    BOOTSCRUB_IDLE,
+};
+static int __read_mostly opt_bootscrub = BOOTSCRUB_ON;
+static int __init parse_bootscrub_param(const char *s)
+{
+    if ( *s == '\0' )
+        return 0;
+
+    if ( !strcmp(s, "idle") )
+        opt_bootscrub = BOOTSCRUB_IDLE;
+    else
+        opt_bootscrub = parse_bool(s, NULL);
+
+    if ( opt_bootscrub < 0 )
+    {
+        opt_bootscrub = BOOTSCRUB_ON;
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+custom_param("bootscrub", parse_bootscrub_param);
 
 /*
  * bootscrub_chunk -> Amount of bytes to scrub lockstep on non-SMT CPUs
@@ -1763,7 +1787,8 @@ static void init_heap_pages(
             nr_pages -= n;
         }
 
-        free_heap_pages(pg + i, 0, scrub_debug);
+        free_heap_pages(pg + i, 0, scrub_debug ||
+                                   opt_bootscrub == BOOTSCRUB_IDLE);
     }
 }
 
@@ -2039,8 +2064,11 @@ void __init heap_init_late(void)
      */
     setup_low_mem_virq();
 
-    if ( opt_bootscrub )
+    if ( opt_bootscrub == BOOTSCRUB_ON )
         scrub_heap_pages();
+    else if ( opt_bootscrub == BOOTSCRUB_IDLE )
+        printk("Scrubbing Free RAM on %d nodes in background\n",
+               num_online_nodes());
 }
 
 
Signature · 7 lines
2.17.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 03.10.18 at 12:28, <[email protected]> wrote:

Scrubbing RAM during boot may take a long time on machines with lots of RAM. Add 'idle' option which marks all pages dirty initially so they would eventually be scrubbed in idle-loop on every online CPU.

Performance of idle-loop scrubbing is worse than bootscrub but it's guaranteed that the allocator will return scrubbed pages by doing eager scrubbing during allocation (unless MEMF_no_scrub was provided).

I've commented on this before: Without clarifying what "performance" means in this context, the statement's truth cannot be verified. To certain (many?) people, performance in the context of booting a system may mean the time it takes until the system is fully up. I think idle scrubbing helps this rather than making it worse.

docs/misc/xen-command-line.markdown that byte `0x12345678` is bad, you would place `badpage=0x12345` on · line 232

Quoted 10 lines
docs/misc/xen-command-line.markdown +1 -1
@@ -227,7 +227,7 @@ that byte `0x12345678` is bad, you would place `badpage=0x12345` on
 Xen's command line.
 
 ### bootscrub
-> `= <boolean>`
+> `= <boolean> | idle`
 
 > Default: `true`

Any reason not to make "idle" the default? Iirc that was the plan anyway.

Quoted 4 lines
xen/common/page_alloc.c +0 -0
@@ -161,8 +161,32 @@ string_param("badpage", opt_badpage);
 /*

xen/common/page_alloc.c string_param("badpage", opt_badpage); · line 169

Quoted 10 lines
xen/common/page_alloc.c +6 -2
  * no-bootscrub -> Free pages are not zeroed during boot.
  */
-static bool_t opt_bootscrub __initdata = 1;
-boolean_param("bootscrub", opt_bootscrub);
+enum {
+    BOOTSCRUB_OFF = 0,
+    BOOTSCRUB_ON,
+    BOOTSCRUB_IDLE,
+};
+static int __read_mostly opt_bootscrub = BOOTSCRUB_ON;

Why "int" when you've just made yourself an enum?

xen/common/page_alloc.c string_param("badpage", opt_badpage); · line 180

Quoted 11 lines
xen/common/page_alloc.c +11 -0
+static int __init parse_bootscrub_param(const char *s)
+{
+    if ( *s == '\0' )
+        return 0;
+
+    if ( !strcmp(s, "idle") )
+        opt_bootscrub = BOOTSCRUB_IDLE;
+    else
+        opt_bootscrub = parse_bool(s, NULL);
+
+    if ( opt_bootscrub < 0 )

Can you please follow the model used elsewhere, where parse_bool() gets called first? Also can "bootscrub" alone please have the same meaning as "bootscrub=yes"?

xen/common/page_alloc.c string_param("badpage", opt_badpage); · line 189

Quoted 9 lines
xen/common/page_alloc.c +9 -0
+    {
+        opt_bootscrub = BOOTSCRUB_ON;
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+custom_param("bootscrub", parse_bootscrub_param);

No blank line between function and its own custom_param() please.

xen/common/page_alloc.c static void init_heap_pages( · line 1791

Quoted 7 lines
xen/common/page_alloc.c +2 -1
@@ -1763,7 +1787,8 @@ static void init_heap_pages(
             nr_pages -= n;
         }
 
-        free_heap_pages(pg + i, 0, scrub_debug);
+        free_heap_pages(pg + i, 0, scrub_debug ||
+                                   opt_bootscrub == BOOTSCRUB_IDLE);

So this is the hunk explaining why the variable can't be __initdata. The question though is whether the resulting post-init behavior is actually correct; it's certainly odd for a boot related option to have an effect post-boot as well.

xen/common/page_alloc.c void __init heap_init_late(void) · line 2071

Quoted 10 lines
xen/common/page_alloc.c +4 -1
@@ -2039,8 +2064,11 @@ void __init heap_init_late(void)
      */
     setup_low_mem_virq();
 
-    if ( opt_bootscrub )
+    if ( opt_bootscrub == BOOTSCRUB_ON )
         scrub_heap_pages();
+    else if ( opt_bootscrub == BOOTSCRUB_IDLE )
+        printk("Scrubbing Free RAM on %d nodes in background\n",
+               num_online_nodes());

switch()? And is the reference to the node count really meaningful in the logged message?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel