Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3405342pxp; Tue, 8 Mar 2022 13:45:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyaaDcFE58fXlK87Chib1y/96427/KW4D5xA5DOfy6D7fDmwvTtWFgxTpyCvRdsIL77HhHr X-Received: by 2002:a05:6402:3582:b0:416:6413:d2ae with SMTP id y2-20020a056402358200b004166413d2aemr7674558edc.192.1646775904989; Tue, 08 Mar 2022 13:45:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646775904; cv=none; d=google.com; s=arc-20160816; b=u2zIArYdkEqD/DIw+1BKfeuVfL3x/n2FkWN7hgA5uQIVVZv28zxum2ywY24uZE0X+6 idqZIi1h3MCw+iqKYqYAYjuFQQ2auuJECS1hiG0WxZM5ESFnuFr/4x7vDeclGXI6ysg8 xE1dgtDtf55XjKlttiNz4BZtcROWxFU0jS049iLauXk3N/ce+hv+qCSYuqls3gth9P8P NgTXSxwtSoyT/QvQ6JVPLKJ2S7iQXY8+qIoOqGRGFZO0JImqCKfROIGbfpMykkmHOGUM 1++yV8PcwvJ7Yf8Rj6NfomWm9+TIsYa9tGcHi0GwcZ/nQNxkSiGgslHnvhRmvxGH5bxE 69SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ifr3fo3Grj3tha09pOgs1PgAF1BRacVsSDp+i5gATLo=; b=0jZXHhr61RG/GLy39JQ3/gwut84DTEkLWE7aFPGlJOT+8b4jG1uBA9ufdwm7vkNXFF A7eTKceh3RXitJQ46UCBiN/PPYqa/IJYsoCHQO+X1osXUYXgkOvmSr/rXLdLoOkAjieC wTWtlAYalasMnG4dUAP8wrXu6JV+v20PKz9F9w3TACFwFngpMmI5OvgEMM1eWNkLKQIr QLas7X8MVZd8toSKDQp+qdq72hvYUZHEp4Vv0jXsFd/Wm0mm350AkVEbbhDZJfJ3A0ol u0Be8ExTS69yH932M5RMSOPYZjym22zehgrkH7bnCZ3KW7b81CKQcsL3Ic+YKDO14efa oO6g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 18-20020a170906311200b006d62ccbbddcsi1300ejx.1001.2022.03.08.13.44.40; Tue, 08 Mar 2022 13:45:04 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245422AbiCGUye (ORCPT + 99 others); Mon, 7 Mar 2022 15:54:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245363AbiCGUyS (ORCPT ); Mon, 7 Mar 2022 15:54:18 -0500 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6087727FEC for ; Mon, 7 Mar 2022 12:53:22 -0800 (PST) Received: from ip5b412258.dynamic.kabel-deutschland.de ([91.65.34.88] helo=phil.lan) by gloria.sntech.de with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nRKM3-0002DJ-Qu; Mon, 07 Mar 2022 21:53:19 +0100 From: Heiko Stuebner To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, wefu@redhat.com, liush@allwinnertech.com, guoren@kernel.org, atishp@atishpatra.org, anup@brainfault.org, drew@beagleboard.org, hch@lst.de, arnd@arndb.de, wens@csie.org, maxime@cerno.tech, gfavor@ventanamicro.com, andrea.mondelli@huawei.com, behrensj@mit.edu, xinhaoqu@huawei.com, mick@ics.forth.gr, allen.baum@esperantotech.com, jscheid@ventanamicro.com, rtrauben@gmail.com, samuel@sholland.org, cmuellner@linux.com, philipp.tomsich@vrull.eu, Heiko Stuebner Subject: [PATCH v7 07/13] riscv: prevent compressed instructions in alternatives Date: Mon, 7 Mar 2022 21:53:04 +0100 Message-Id: <20220307205310.1905628-8-heiko@sntech.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220307205310.1905628-1-heiko@sntech.de> References: <20220307205310.1905628-1-heiko@sntech.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_NONE, T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR 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 Instructions are opportunistically compressed by the RISC-V assembler when possible, but in alternatives-blocks both the old and new content need to be the same size, so having the toolchain do somewhat random optimizations will cause strange side-effects like "attempt to move .org backwards" compile-time errors. Already a simple "and" used in alternatives assembly will cause these mismatched code sizes. So prevent compressed instructions to be generated in alternatives- code and use option-push and -pop to only limit this to the relevant code blocks Signed-off-by: Heiko Stuebner --- arch/riscv/include/asm/alternative-macros.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/riscv/include/asm/alternative-macros.h b/arch/riscv/include/asm/alternative-macros.h index c0fb11fad631..3a52884bf23d 100644 --- a/arch/riscv/include/asm/alternative-macros.h +++ b/arch/riscv/include/asm/alternative-macros.h @@ -19,7 +19,10 @@ .popsection .subsection 1 888 : + .option push + .option norvc \new_c + .option pop 889 : .previous .org . - (889b - 888b) + (887b - 886b) @@ -29,7 +32,10 @@ .macro __ALTERNATIVE_CFG old_c, new_c, vendor_id, errata_id, enable 886 : + .option push + .option norvc \old_c + .option pop 887 : ALT_NEW_CONTENT \vendor_id, \errata_id, \enable, \new_c .endm @@ -40,7 +46,10 @@ .macro __ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \ new_c_2, vendor_id_2, errata_id_2, enable_2 886 : + .option push + .option norvc \old_c + .option pop 887 : ALT_NEW_CONTENT \vendor_id_1, \errata_id_1, \enable_1, \new_c_1 ALT_NEW_CONTENT \vendor_id_2, \errata_id_2, \enable_2, \new_c_2 @@ -70,7 +79,10 @@ ".popsection\n" \ ".subsection 1\n" \ "888 :\n" \ + ".option push\n" \ + ".option norvc\n" \ new_c "\n" \ + ".option pop\n" \ "889 :\n" \ ".previous\n" \ ".org . - (887b - 886b) + (889b - 888b)\n" \ @@ -79,7 +91,10 @@ #define __ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, enable) \ "886 :\n" \ + ".option push\n" \ + ".option norvc\n" \ old_c "\n" \ + ".option pop\n" \ "887 :\n" \ ALT_NEW_CONTENT(vendor_id, errata_id, enable, new_c) @@ -89,7 +104,10 @@ #define __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \ new_c_2, vendor_id_2, errata_id_2, enable_2) \ "886 :\n" \ + ".option push\n" \ + ".option norvc\n" \ old_c "\n" \ + ".option pop\n" \ "887 :\n" \ ALT_NEW_CONTENT(vendor_id_1, errata_id_1, enable_1, new_c_1) \ ALT_NEW_CONTENT(vendor_id_2, errata_id_2, enable_2, new_c_2) -- 2.30.2