[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen staging] mm: make opt_bootscrub non-init



commit 43fa95ae6a64132b8ebe3025bd187ab9df68677b
Author:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
AuthorDate: Mon Nov 26 18:55:48 2018 +0100
Commit:     Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Tue Nov 27 17:02:55 2018 +0000

    mm: make opt_bootscrub non-init
    
    LLVM code generation can attempt to load from a variable in the next
    condition of an expression under certain circumstances, thus turning
    the following condition:
    
    if ( system_state < SYS_STATE_active && opt_bootscrub == BOOTSCRUB_IDLE )
    
    Into:
    
    0xffff82d080223967 <+103>: cmpl   $0x3,0x37b032(%rip) # 0xffff82d08059e9a0 
<system_state>
    0xffff82d08022396e <+110>: setb   -0x29(%rbp)
    0xffff82d080223972 <+114>: cmpl   $0x2,0x228a8b(%rip) # 0xffff82d08044c404 
<opt_bootscrub>
    
    Such code will trigger a page fault if system_state >=
    SYS_STATE_active because opt_bootscrub will be unmapped.
    
    Fix this by making opt_bootscrub non-init, thus preventing the page
    fault. The LLVM bug with the discussion about this issue can be found
    at:
    
    https://bugs.llvm.org/show_bug.cgi?id=39707
    
    I haven't been able to find any other instances of such conditional
    expression that uses system_state together with an init variable or
    function.
    
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Reviewed-by: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
    Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Julien Grall <julien.grall@xxxxxxx>
    Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 xen/common/page_alloc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 4a2cbda1db..fd3b0aaa83 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -166,7 +166,15 @@ enum bootscrub_mode {
     BOOTSCRUB_ON,
     BOOTSCRUB_IDLE,
 };
-static enum bootscrub_mode __initdata opt_bootscrub = BOOTSCRUB_IDLE;
+
+/*
+ * opt_bootscrub should live in the init section, since it's not accessed
+ * afterwards. However at least LLVM assumes there are no side effects of
+ * accessing the variable, and optimizes the condition in init_heap_pages() so
+ * opt_bootscrub is read regardless of the value of system_state:
+ * https://bugs.llvm.org/show_bug.cgi?id=39707
+ */
+static enum bootscrub_mode __read_mostly opt_bootscrub = BOOTSCRUB_IDLE;
 static int __init parse_bootscrub_param(const char *s)
 {
     /* Interpret 'bootscrub' alone in its positive boolean form */
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.