From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753137AbcKTRcx (ORCPT ); Sun, 20 Nov 2016 12:32:53 -0500 Received: from mail.skyhub.de ([78.46.96.112]:44875 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752139AbcKTRcw (ORCPT ); Sun, 20 Nov 2016 12:32:52 -0500 Date: Sun, 20 Nov 2016 18:32:44 +0100 From: Borislav Petkov To: Andy Lutomirski Cc: Matthew Whitehead , Brian Gerst , "linux-kernel@vger.kernel.org" , X86 ML Subject: Re: [PATCH] x86/boot: Fail the boot if !M486 and CPUID is missing Message-ID: <20161120173244.a2odm3rupohvatiq@pd.tnic> References: <70eac6639f23df8be5fe03fa1984aedd5d40077a.1479598603.git.luto@kernel.org> <20161120111917.pw3alolx4fksfwbv@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20161014 (1.7.1) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 20, 2016 at 08:22:25AM -0800, Andy Lutomirski wrote: > This makes me nervous: don't some CPUs actually need the cpuid > instruction when patching alternatives? Nope, we use boot_cpu_has() in apply_alternatives() if that is what you mean. > And with this approach, we won't have the cpuid instruction there > until after patching. We will have set (or not) the X86_FEATURE_CPUID bit at early_identify_cpu() time. Looking at the code, we do call sync_core() pretty early. :-\ Hmm, that #ifdef CONFIG_M486 is there for a reason. > Why not change this function entirely: > > write_cr2(0); > > CR2 should be available on all 32-bit CPUs. It clobbers fewer > registers. Yap, just one. And not only that - it clobbers a register which gcc doesn't have to reload at all. > More usefully, CPUID causes an exit when running under > most hypervisors, and that's quite slow. The only case I can think of > where CPUID should be faster than MOV to CR2 is on Xen PV before Ivy > Bridge, and I'm not sure I care about performance there. > > (On Xen PV, it will do a hypercall instead, but the hypercall should > be good enough to serialize, too.) A nop hypercall or whatever... But yeah, pending a nod from hw people, this one sounds nice too. You can do it basically on every CPU which supports paging. And that should be all we support in Linux anyway. > Or we could do it dynamically: > > bt $X86_FEATURE_CPUID, CPU_FLAGS(boot_cpu_data) # or whatever -- I > think we need to add an asm offset > jnc 1f # here's our jump > cpuid > 1: We could... we did move the X86_FEATURE* things to a separate header so that they can be used in asm too. write_cr2(0) doesn't sound so bad either. Except what happens if someone decides to sync_core() before the first line of do_page_fault() executes... I know, it is unlikely but we do unlikely things :) But yeah, the write_cr2() sounds better if one considers the lower register pressure. Which is nice. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.