Skip to content

Commit

Permalink
x86/boot/32: Flip the logic in test_wp_bit()
Browse files Browse the repository at this point in the history
... to have a natural "likely()" in the code flow and thus have the
success case with a branch 99.999% of the times non-taken and function
return code following it instead of jumping to it each time.

This puts the panic() call at the end of the function - it is going to
be practically unreachable anyway.

The C code is a bit more readable too.

No functionality change.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: boris.ostrovsky@oracle.com
Cc: jgross@suse.com
Cc: thgarnie@google.com
Link: http://lkml.kernel.org/r/20170330080101.ywsf5rg6ilzu4itk@pd.tnic
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Borislav Petkov authored and Ingo Molnar committed Mar 31, 2017
1 parent 4af1711 commit 952a6c2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions arch/x86/mm/init_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,19 +726,18 @@ static void __init test_wp_bit(void)
{
char z = 0;

printk(KERN_INFO
"Checking if this processor honours the WP bit even in supervisor mode...");
printk(KERN_INFO "Checking if this processor honours the WP bit even in supervisor mode...");

__set_fixmap(FIX_WP_TEST, __pa_symbol(empty_zero_page), PAGE_KERNEL_RO);

if (probe_kernel_write((char *)fix_to_virt(FIX_WP_TEST), &z, 1) == 0) {
printk(KERN_CONT "No.\n");
panic("Linux doesn't support CPUs with broken WP.");
if (probe_kernel_write((char *)fix_to_virt(FIX_WP_TEST), &z, 1)) {
clear_fixmap(FIX_WP_TEST);
printk(KERN_CONT "Ok.\n");
return;
}

clear_fixmap(FIX_WP_TEST);

printk(KERN_CONT "Ok.\n");
printk(KERN_CONT "No.\n");
panic("Linux doesn't support CPUs with broken WP.");
}

void __init mem_init(void)
Expand Down

0 comments on commit 952a6c2

Please sign in to comment.