lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJF2gTTDnqXKuEBGttN-1sJD9GH8Y5FLP2R5cpxnWnkfyqaFVA@mail.gmail.com>
Date:   Mon, 16 May 2022 14:55:24 +0800
From:   Guo Ren <guoren@...nel.org>
To:     Heiko Stuebner <heiko@...ech.de>
Cc:     Palmer Dabbelt <palmer@...belt.com>,
        Paul Walmsley <paul.walmsley@...ive.com>,
        Albert Ou <aou@...s.berkeley.edu>,
        linux-riscv <linux-riscv@...ts.infradead.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Wei Fu <wefu@...hat.com>, liush <liush@...winnertech.com>,
        Atish Patra <atishp@...shpatra.org>,
        Anup Patel <anup@...infault.org>,
        Drew Fustini <drew@...gleboard.org>,
        Christoph Hellwig <hch@....de>, Arnd Bergmann <arnd@...db.de>,
        Chen-Yu Tsai <wens@...e.org>,
        Maxime Ripard <maxime@...no.tech>,
        Greg Favor <gfavor@...tanamicro.com>,
        Andrea Mondelli <andrea.mondelli@...wei.com>,
        Jonathan Behrens <behrensj@....edu>,
        "Xinhaoqu (Freddie)" <xinhaoqu@...wei.com>,
        Nick Kossifidis <mick@....forth.gr>,
        Allen Baum <allen.baum@...erantotech.com>,
        Josh Scheid <jscheid@...tanamicro.com>,
        Richard Trauben <rtrauben@...il.com>,
        Samuel Holland <samuel@...lland.org>,
        Christoph Muellner <cmuellner@...ux.com>,
        Philipp Tomsich <philipp.tomsich@...ll.eu>
Subject: Re: [PATCH 06/12] riscv: prevent compressed instructions in alternatives

Reviewed-by: Guo Ren <guoren@...nel.org>

On Thu, May 12, 2022 at 3:29 AM Heiko Stuebner <heiko@...ech.de> 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 <heiko@...ech.de>
> Reviewed-by: Christoph Hellwig <hch@....de>
> Reviewed-by: Philipp Tomsich <philipp.tomsich@...ll.eu>
> ---
>  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/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ