From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934771AbcATECZ (ORCPT ); Tue, 19 Jan 2016 23:02:25 -0500 Received: from terminus.zytor.com ([198.137.202.10]:55781 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933509AbcATECS (ORCPT ); Tue, 19 Jan 2016 23:02:18 -0500 Subject: Re: [PATCH] x86: static_cpu_has_safe: discard dynamic check after init To: Borislav Petkov References: <1452972124-7380-1-git-send-email-brgerst@gmail.com> <20160116193658.GC32085@pd.tnic> <20160117103337.GC8549@pd.tnic> <20160118181457.GG12651@pd.tnic> <20160118185107.GI12651@pd.tnic> <20160119011026.GA12911@pd.tnic> <20160119092213.GA15071@pd.tnic> Cc: Brian Gerst , the arch/x86 maintainers , Linux Kernel Mailing List , Ingo Molnar , Denys Vlasenko , Andy Lutomirski , Linus Torvalds From: "H. Peter Anvin" X-Enigmail-Draft-Status: N1110 Message-ID: <569F06B9.4060903@zytor.com> Date: Tue, 19 Jan 2016 20:02:01 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <20160119092213.GA15071@pd.tnic> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/19/16 01:22, Borislav Petkov wrote: > On Mon, Jan 18, 2016 at 05:33:03PM -0800, H. Peter Anvin wrote: >> Why the f do we call a subroutine for what amounts to a single bt or >> test instruction? > > No real reason. You can kick me when you see me next time: > > 4a90a99c4f80 ("x86: Add a static_cpu_has_safe variant") > So, here is my suggestion: 1. Just get rid of static_cpu_has_safe() and make static_cpu_has() safe. 2. Get rid of the non-asm goto variant and just fall back to dynamic if asm goto is unavailable. It doesn't make any sense, really, if it is supposed to be safe, and by now the asm goto-capable gcc is in more wide use. (Originally the gcc 3.x fallback to pure dynamic didn't exist, either.) 3. Put the dynamic test in the .init.text section and inline it: .section .init.text,"ax" testb %2,%3 jnz %[t_yes] jmp %[t_no] .previous ... "i" (1 << (bit & 7)), "m" (((const char *)boot_cpu_data->x86_capability)[bit >> 3]) ... (The code would be slightly simpler/cleaner with testl, but that would unnecessarily create a long immediate, or with btl, but that would be slower. We could use CONST_MASK_ADDR() and CONST_MASK() from asm/bitops.h, but I'm slightly uncomfortable with the idea of leveraging an interface which is ultimately an internal implementation detail of bitops.h that might change in the future without people realizing its implications.) The only thing we lose is the 2-byte optimization in case we have the good luck for it to actually work. At this point I'm thinking it isn't worth it, and instead that safety trumps it. It *would* be interesting to see if there are any call sites where it would actually kick in. -hpa