From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74056C433F5 for ; Mon, 16 May 2022 06:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240587AbiEPGzr (ORCPT ); Mon, 16 May 2022 02:55:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240570AbiEPGzo (ORCPT ); Mon, 16 May 2022 02:55:44 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 460E6366A8 for ; Sun, 15 May 2022 23:55:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 7E743CE1101 for ; Mon, 16 May 2022 06:55:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9F5EC36AE7 for ; Mon, 16 May 2022 06:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652684136; bh=VqIRCv2LMNB0QFdFUt96jLC25HR73ExKxi3u86pjpWE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Qru5duK8wRBYYrhrERVxr3VWex79J7Nw+63a7Aegi/amXc63tnm9Lnl4KH2VR3bjy WezbNMt1G3ZeDuJeUN2+cOU0TL/R6HOlmcxTmaym2uH5d7nEqmiFuLFs5R3zYD/ZHC qZBuX6hY8fYIHQ2h+E7Bam7Cbg+2mbGDswRhsloejAvGDtm1Ijkmni3pjg+Ejekgoh hhICXed1kIIujYIoqSN/DUaKtjlPo3QfCY6kKbQFiULvN8A4M3LIahmO7LwyjUB9U4 qHCVxD0kFrldnbmhQoaYMf1nz9Eb/98f7rLlorzE3RdfteoYAMOlhaBzFaCP6+9kki oGHUU1S/6bIBg== Received: by mail-ua1-f51.google.com with SMTP id ay15so5450314uab.9 for ; Sun, 15 May 2022 23:55:36 -0700 (PDT) X-Gm-Message-State: AOAM5319E2FSIiiiahVcJKqvPykBPSf5DjQw6thBBZzUHN1hcBuI0uP5 /g7qDrwoKgtz+AaLooEjsi47PcWhw+vQEo/0MKU= X-Google-Smtp-Source: ABdhPJxmtz2zRffn70WwdXZCEN/EtZzhyD5YAzH08JCQyLUCluirTTig9RHWjzPE9xvnfEBH+E790EU75vYagB1kBNc= X-Received: by 2002:a9f:23c2:0:b0:365:958:e807 with SMTP id 60-20020a9f23c2000000b003650958e807mr5603921uao.114.1652684135694; Sun, 15 May 2022 23:55:35 -0700 (PDT) MIME-Version: 1.0 References: <20220511192921.2223629-1-heiko@sntech.de> <20220511192921.2223629-7-heiko@sntech.de> In-Reply-To: <20220511192921.2223629-7-heiko@sntech.de> From: Guo Ren Date: Mon, 16 May 2022 14:55:24 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 06/12] riscv: prevent compressed instructions in alternatives To: Heiko Stuebner Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , linux-riscv , Linux Kernel Mailing List , Wei Fu , liush , Atish Patra , Anup Patel , Drew Fustini , Christoph Hellwig , Arnd Bergmann , Chen-Yu Tsai , Maxime Ripard , Greg Favor , Andrea Mondelli , Jonathan Behrens , "Xinhaoqu (Freddie)" , Nick Kossifidis , Allen Baum , Josh Scheid , Richard Trauben , Samuel Holland , Christoph Muellner , Philipp Tomsich Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reviewed-by: Guo Ren On Thu, May 12, 2022 at 3:29 AM Heiko Stuebner wrote: > > 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 > Reviewed-by: Christoph Hellwig > Reviewed-by: Philipp Tomsich > --- > arch/riscv/include/asm/alternative-macros.h | 24 +++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/arch/riscv/include/asm/alternative-macros.h b/arch/riscv/include/asm/alternative-macros.h > index 8c2bbc7bbe50..e13b1f6bb400 100644 > --- a/arch/riscv/include/asm/alternative-macros.h > +++ b/arch/riscv/include/asm/alternative-macros.h > @@ -21,7 +21,11 @@ > .popsection > .subsection 1 > 888 : > + .option push > + .option norvc > + .option norelax > \new_c > + .option pop > 889 : > .previous > .org . - (889b - 888b) + (887b - 886b) > @@ -31,7 +35,11 @@ > > .macro __ALTERNATIVE_CFG old_c, new_c, vendor_id, errata_id, enable > 886 : > + .option push > + .option norvc > + .option norelax > \old_c > + .option pop > 887 : > ALT_NEW_CONTENT \vendor_id, \errata_id, \enable, \new_c > .endm > @@ -42,7 +50,11 @@ > .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 > + .option norelax > \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 > @@ -76,7 +88,11 @@ > ".popsection\n" \ > ".subsection 1\n" \ > "888 :\n" \ > + ".option push\n" \ > + ".option norvc\n" \ > + ".option norelax\n" \ > new_c "\n" \ > + ".option pop\n" \ > "889 :\n" \ > ".previous\n" \ > ".org . - (887b - 886b) + (889b - 888b)\n" \ > @@ -85,7 +101,11 @@ > > #define __ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, enable) \ > "886 :\n" \ > + ".option push\n" \ > + ".option norvc\n" \ > + ".option norelax\n" \ > old_c "\n" \ > + ".option pop\n" \ > "887 :\n" \ > ALT_NEW_CONTENT(vendor_id, errata_id, enable, new_c) > > @@ -97,7 +117,11 @@ > new_c_2, vendor_id_2, errata_id_2, \ > enable_2) \ > "886 :\n" \ > + ".option push\n" \ > + ".option norvc\n" \ > + ".option norelax\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.35.1 > -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/