mm: make opt_bootscrub non-init
PATCH v2 1/1 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.
---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Sergey Dyasli <[email protected]>
---
Changes since v1:
- Make opt_bootscrub read mostly.
- Add a comment about why opt_bootscrub is not in the init section.
--- xen/common/page_alloc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
xen/common/page_alloc.c +8 -1
@@ -166,7 +166,14 @@ 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 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 */
Signature · 7 lines
2.19.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
xen/common/page_alloc.c enum bootscrub_mode { · line 172
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 18:55, <[email protected]> wrote:
xen/common/page_alloc.c +4
-1@@ -166,7 +166,14 @@ 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 so opt_bootscrub is
... the condition in init_heap_pages() ...
(which I guess can be folded in while committing).
Jan
xen/common/page_alloc.c enum bootscrub_mode { · line 179
Quoted 7 lines
xen/common/page_alloc.c +4
-0+* 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 */
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · Jan Beulich
xen/common/page_alloc.c enum bootscrub_mode { · line 172
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 18:55, <[email protected]> wrote:
xen/common/page_alloc.c +4
-1@@ -166,7 +166,14 @@ 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 so opt_bootscrub is ... the condition in
init_heap_pages()...
Quoted 1 line
(which I guess can be folded in while committing).
Yes please.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 16 lines · Roger Pau Monné
Quoted 15 lines · Jan Beulich
xen/common/page_alloc.c enum bootscrub_mode { · line 172
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 18:55, <[email protected]> wrote:
xen/common/page_alloc.c +4
-1@@ -166,7 +166,14 @@ 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 so opt_bootscrub is ... the condition in
init_heap_pages()...
Quoted 4 lines
Quoted 1 line
(which I guess can be folded in while committing).
Yes please.
I have fixed this and taken the liberty to add a blank line before this comment block.
Wei.
Quoted 1 line
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel