From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932999AbdCaKNn (ORCPT ); Fri, 31 Mar 2017 06:13:43 -0400 Received: from terminus.zytor.com ([65.50.211.136]:53809 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932577AbdCaKNm (ORCPT ); Fri, 31 Mar 2017 06:13:42 -0400 Date: Fri, 31 Mar 2017 03:07:48 -0700 From: tip-bot for Borislav Petkov Message-ID: Cc: peterz@infradead.org, bp@alien8.de, jpoimboe@redhat.com, hpa@zytor.com, mingo@kernel.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, dvlasenk@redhat.com, tglx@linutronix.de, brgerst@gmail.com, bp@suse.de, luto@kernel.org Reply-To: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org, jpoimboe@redhat.com, bp@alien8.de, peterz@infradead.org, luto@kernel.org, bp@suse.de, brgerst@gmail.com, tglx@linutronix.de, dvlasenk@redhat.com In-Reply-To: <20170330080101.ywsf5rg6ilzu4itk@pd.tnic> References: <20170330080101.ywsf5rg6ilzu4itk@pd.tnic> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/boot/32: Flip the logic in test_wp_bit() Git-Commit-ID: 952a6c2c094f4eda295f20c42e6e2d73735950fa X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 952a6c2c094f4eda295f20c42e6e2d73735950fa Gitweb: http://git.kernel.org/tip/952a6c2c094f4eda295f20c42e6e2d73735950fa Author: Borislav Petkov AuthorDate: Thu, 30 Mar 2017 09:44:05 +0200 Committer: Ingo Molnar CommitDate: Fri, 31 Mar 2017 08:08:31 +0200 x86/boot/32: Flip the logic in test_wp_bit() ... 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 Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner 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 --- arch/x86/mm/init_32.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c index 097089a..601b8e0 100644 --- a/arch/x86/mm/init_32.c +++ b/arch/x86/mm/init_32.c @@ -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)