Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD963C433E0 for ; Wed, 10 Mar 2021 06:07:41 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1ECD664F84 for ; Wed, 10 Mar 2021 06:07:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1ECD664F84 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=alien8.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.95856.180941 (Exim 4.92) (envelope-from ) id 1lJs02-0000kH-55; Wed, 10 Mar 2021 06:07:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 95856.180941; Wed, 10 Mar 2021 06:07:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJs02-0000kA-1a; Wed, 10 Mar 2021 06:07:14 +0000 Received: by outflank-mailman (input) for mailman id 95856; Wed, 10 Mar 2021 06:07:12 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJs00-0000k5-Pf for xen-devel@lists.xenproject.org; Wed, 10 Mar 2021 06:07:12 +0000 Received: from mail.skyhub.de (unknown [5.9.137.197]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ad481ac3-204b-4ed9-97c0-e238f8d67c5a; Wed, 10 Mar 2021 06:07:11 +0000 (UTC) Received: from zn.tnic (p200300ec2f0a99002de44af59edd037d.dip0.t-ipconnect.de [IPv6:2003:ec:2f0a:9900:2de4:4af5:9edd:37d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id E62DF1EC0473; Wed, 10 Mar 2021 07:07:09 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ad481ac3-204b-4ed9-97c0-e238f8d67c5a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1615356430; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=BzBbQnXUuiDK+nmPzIwIGL4n/Loc18opf7QU0fcWCJI=; b=EFBzBnX3lsz0uqv3rvfnAcgyzAPvVERZQvmn6qwVVk3XZ7ShVAeGR0lCSjJr6bRb2Z6d5m loNpBlkOf+e6lbtfnVNg9sMVA12nr5iwtTNQ4pYnEi+mB9nQxRqVvotZuQGZvt5WwBhuqD 676DJkplf/Co08k5EvawCocwKqd5DV0= Date: Wed, 10 Mar 2021 07:07:05 +0100 From: Borislav Petkov To: Juergen Gross Cc: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Subject: Re: [PATCH v6 04/12] x86/alternative: support not-feature Message-ID: <20210310060705.GB23521@zn.tnic> References: <20210309134813.23912-1-jgross@suse.com> <20210309134813.23912-5-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210309134813.23912-5-jgross@suse.com> On Tue, Mar 09, 2021 at 02:48:05PM +0100, Juergen Gross wrote: > Add support for alternative patching for the case a feature is not > present on the current cpu. > > For users of ALTERNATIVE() and friends an inverted feature is specified > by applying the ALT_NOT() macro to it, e.g.: > > ALTERNATIVE(old, new, ALT_NOT(feature)) > > Signed-off-by: Juergen Gross > --- > V5: > - split off from next patch > - reworked to use flag byte (Boris Petkov) > V6: > - rework again to not use flag byte (Boris Petkov) > --- > arch/x86/include/asm/alternative-asm.h | 3 +++ > arch/x86/include/asm/alternative.h | 3 +++ > arch/x86/kernel/alternative.c | 19 ++++++++++++++----- > 3 files changed, 20 insertions(+), 5 deletions(-) LGTM, minor touchups I'd do ontop: --- diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index 89889618ae01..fd205cdcfbad 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -55,18 +55,18 @@ ".long 999b - .\n\t" \ ".popsection\n\t" +#define ALTINSTR_FLAG_INV (1 << 15) +#define ALT_NOT(feat) ((feat) | ALTINSTR_FLAG_INV) + struct alt_instr { s32 instr_offset; /* original instruction */ s32 repl_offset; /* offset to replacement instruction */ u16 cpuid; /* cpuid bit set for replacement */ -#define ALTINSTR_FLAG_INV (1 << 15) u8 instrlen; /* length of original instruction */ u8 replacementlen; /* length of new instruction */ u8 padlen; /* length of build-time padding */ } __packed; -#define ALT_NOT(feat) ((feat) | ALTINSTR_FLAG_INV) - /* * Debug flag that can be tested to see whether alternative * instructions were patched in already: diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index d8e669a1546f..133b549dc091 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -397,9 +397,10 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start, BUG_ON(feature >= (NCAPINTS + NBUGINTS) * 32); /* - * Drop out if either: - * - feature not available, but required, or - * - feature available, but NOT required + * Patch if either: + * - feature is present + * - feature not present but ALTINSTR_FLAG_INV is set to mean, + * patch if feature is *NOT* present. */ if (!boot_cpu_has(feature) == !(a->cpuid & ALTINSTR_FLAG_INV)) { if (a->padlen > 1) -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette