Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1844164imw; Sat, 16 Jul 2022 16:39:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sHnbsBbjf+hT1Y0dZHWs4qMlDomtbiCSdJvcRQmwIPu3BOu4OvnzA4PmhJkZCGvhzxUCuz X-Received: by 2002:a63:d006:0:b0:419:b272:9e6d with SMTP id z6-20020a63d006000000b00419b2729e6dmr13645117pgf.608.1658014795161; Sat, 16 Jul 2022 16:39:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658014795; cv=none; d=google.com; s=arc-20160816; b=Hq9EQwsdJQOygy9VknisI5fY6xveHK9rNOf7w7xyMTnDTi9JPQTSf8zX7h6M0DQv4y 2ehdXZQrfUa17lKWNoDUks9hbmQFkLaMCr5a/z0/wnAfgyeVsUhln3EeKcQhmq56spAC ph35gj/V+Y64CUcjdtczq1CqZNqGqmkbp1dE5V1S/ApV7RZYxPaoUzQSTYZTtmuzP+39 cMKHThBeKHbCulH4SetcTzYMF0KLHZG1QgUxCvE9feiUI6i33H9RQ6uI2XJDgExcYgtS rSUCBlaEGQyUFTlDrHGePKefBzET28w4BdBi1xClMewxVMdqpGKQG92zPTBlblKYYuVc A9CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=+SkAT0acTC0wg1yKNmaNDVW/Hce09Uo6dKJ0RMDncd4=; b=0apRQfe/KdRwEENj2YR/dcMckUq9Npr8/MCWoP2wSzZs2D9AIUK1ljPTQTB284tPm0 ZYO68LFAY6MVsnbBGw8ujo4rDCwblXIr42qelzAAP0tT1xMb5vzszz9YRPhg9LULQY+V 62gAnalBrnug/nfl/sh0BtDwyW9EHl+OQnH6r0PSfGB9w9X0TTV8c3EgUBDxO0oGg5zc 3qxELzSSvyyincChCsqnbu4/Jj7x3/ZbOi4SaC2EPzW2ws/4INEMCV3VZ+BuEwE2JwPR pNH7/W6XZRFqHqd9cykR2IA+nWduM7J8i85MrsHu+RAN0QuPaD2X69cn1pjZ/B2NLuc5 oD0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aKc9I7Og; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h31-20020a63211f000000b0041288737bc6si9770986pgh.797.2022.07.16.16.39.41; Sat, 16 Jul 2022 16:39:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aKc9I7Og; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233102AbiGPXTO (ORCPT + 99 others); Sat, 16 Jul 2022 19:19:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233181AbiGPXS2 (ORCPT ); Sat, 16 Jul 2022 19:18:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FD8A23169 for ; Sat, 16 Jul 2022 16:17:56 -0700 (PDT) Message-ID: <20220716230954.275034921@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1658013474; 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: references:references; bh=+SkAT0acTC0wg1yKNmaNDVW/Hce09Uo6dKJ0RMDncd4=; b=aKc9I7OgvEqVoDkW5CNTiUQMmwvpRljeGAji+oG/7jY60IhW1W9F/Ji/geM4sPnAh7BtJ2 ErbWyHKRmwVHQ5K7OjpYEH5hYvLA+A2pt9qAsY83IpIkF2g3b1VeKlYhbCNqASToiomPuU JhTyzo4CgoIOzLz3VSwRvVi4J43pDoLJbOC+3Pb/oeMSS/HcqfVILer47yWZrjYIBTN2sG vfubuFBjSCTOkyKPlwPaF/eRbHiYy9M0eq+5HEHG/CfxZ8Ylt+zoonCU1ZmRNAyYLzkoiq 5yToAgCRVvwre1aV0H2CfarYkKhDyIvQwwu5KihO4lPt+jqzcEdDL9jiJSy7Tw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1658013474; 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: references:references; bh=+SkAT0acTC0wg1yKNmaNDVW/Hce09Uo6dKJ0RMDncd4=; b=l7zjZpIBEHlZtAneeNEraYRsIexxqaruRu5iviVajpqxakq7ZBcQgqgGvhChbitdD1YSNp JkWSBuDvqWGGSACw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Linus Torvalds , Tim Chen , Josh Poimboeuf , Andrew Cooper , Pawan Gupta , Johannes Wikner , Alyssa Milburn , Jann Horn , "H.J. Lu" , Joao Moreira , Joseph Nuzman , Steven Rostedt , "Peter Zijlstra (Intel)" Subject: [patch 27/38] x86/asm: Provide ALTERNATIVE_3 References: <20220716230344.239749011@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Sun, 17 Jul 2022 01:17:53 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra Fairly straight forward adaptation/extention of ALTERNATIVE_2. Required for call depth tracking. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/alternative.h | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -367,6 +367,7 @@ static inline int alternatives_text_rese #define old_len 141b-140b #define new_len1 144f-143f #define new_len2 145f-144f +#define new_len3 146f-145f /* * gas compatible max based on the idea from: @@ -374,7 +375,8 @@ static inline int alternatives_text_rese * * The additional "-" is needed because gas uses a "true" value of -1. */ -#define alt_max_short(a, b) ((a) ^ (((a) ^ (b)) & -(-((a) < (b))))) +#define alt_max_2(a, b) ((a) ^ (((a) ^ (b)) & -(-((a) < (b))))) +#define alt_max_3(a, b, c) (alt_max_2(alt_max_2(a, b), c)) /* @@ -386,8 +388,8 @@ static inline int alternatives_text_rese 140: \oldinstr 141: - .skip -((alt_max_short(new_len1, new_len2) - (old_len)) > 0) * \ - (alt_max_short(new_len1, new_len2) - (old_len)),0x90 + .skip -((alt_max_2(new_len1, new_len2) - (old_len)) > 0) * \ + (alt_max_2(new_len1, new_len2) - (old_len)),0x90 142: .pushsection .altinstructions,"a" @@ -404,6 +406,31 @@ static inline int alternatives_text_rese .popsection .endm +.macro ALTERNATIVE_3 oldinstr, newinstr1, feature1, newinstr2, feature2, newinstr3, feature3 +140: + \oldinstr +141: + .skip -((alt_max_3(new_len1, new_len2, new_len3) - (old_len)) > 0) * \ + (alt_max_3(new_len1, new_len2, new_len3) - (old_len)),0x90 +142: + + .pushsection .altinstructions,"a" + altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f + altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f + altinstruction_entry 140b,145f,\feature3,142b-140b,146f-145f + .popsection + + .pushsection .altinstr_replacement,"ax" +143: + \newinstr1 +144: + \newinstr2 +145: + \newinstr3 +146: + .popsection +.endm + /* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */ #define ALTERNATIVE_TERNARY(oldinstr, feature, newinstr_yes, newinstr_no) \ ALTERNATIVE_2 oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \