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 X-Spam-Level: X-Spam-Status: No, score=-28.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 A6511C43461 for ; Wed, 14 Apr 2021 19:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A7B3611AD for ; Wed, 14 Apr 2021 19:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353375AbhDNTW4 (ORCPT ); Wed, 14 Apr 2021 15:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353370AbhDNTWy (ORCPT ); Wed, 14 Apr 2021 15:22:54 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE7E3C061756 for ; Wed, 14 Apr 2021 12:22:30 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id r20so24475127ljk.4 for ; Wed, 14 Apr 2021 12:22:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PUOYXNfICZdC1+9G6F70MzTNDWMZ0Mz9R8OhGw2MATA=; b=thrADslz3ToX7uQBnxWvFoINCJNnr6ngJ+dVi9lut9X4zfnY8g1wvwlW0ElJoXAkx5 TMrFJGf4rs1Cvs85Z5PgLK2b4MB12ixyLb8wzp52LNINPbF6Orwb6o+8AAQXrKYiTKTw TrjFGLHCH8zBAjFQdc8gGv3bXXjOUxGY1oYulm/OmrIt4zCJXR6ZEfwbFGo3ZXNOf2m5 9R4EKJkcIeA4VQlAeY5l+GPe5sUzJ3Xf0CJO6079ZJNUoGRmmdKi07HsEdpyGNEglEx9 sy7DmPKgarJzSZNB4cpO704cM2jMIW6SXXtxRgjnonnAPEtkRIkdSCx/Pc8tPYTI/1fD ga4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PUOYXNfICZdC1+9G6F70MzTNDWMZ0Mz9R8OhGw2MATA=; b=d4QY52sWgMtpPbSEJwENlLCltNbaUIgaa/Xipec1pqbSqdEelUv6+hPV2PrP6jvTkC Q+QSYvk/1VyklE+4mz/nyJG0XyxLZbk4pzQCr+MnKXcNXVbsH0ZSC4/g3Xm54ngtFMk5 t2tw6z6coOu2vY2yG1KiNZpXgRXeZHD9vGBvo9PEIxJQb9SWpdSeQaMD1yjcKqerPIAM 7GyP8E77boM4/wzhjncKuuGd+r4TEILNryPOB/p6zPVkd3ccocjeAFQvNX6PAd7aGPXc ANUF6nRRv4lFXi4UfyiN1xUJRUK1/NrjQ866dVsPmK1KMBwORj1gcHb2nFeGeEqa6+Fq srNw== X-Gm-Message-State: AOAM531T77UDMW+m5dLB35eWURuFlsgkqWa9zABKfbdvhBLxcMtIes66 OH6BpQzKub9dl+eYCJ1G7mF+plQbEhL/3Mi3B2FeCQ== X-Google-Smtp-Source: ABdhPJwANq4izR9wSH8/54RE6iS58ESvhjt5HzFkQu+osbE8ndiFXYYZTkcxTEz7tzXd7P68r30w9dJqp3FR/dq9ths= X-Received: by 2002:a2e:b008:: with SMTP id y8mr23815586ljk.233.1618428149110; Wed, 14 Apr 2021 12:22:29 -0700 (PDT) MIME-Version: 1.0 References: <20210414000803.662534-1-nathan@kernel.org> In-Reply-To: <20210414000803.662534-1-nathan@kernel.org> From: Nick Desaulniers Date: Wed, 14 Apr 2021 12:22:17 -0700 Message-ID: Subject: Re: [PATCH] arm64: alternatives: Move length validation in alternative_{insn,endif} To: Nathan Chancellor Cc: Catalin Marinas , Will Deacon , Sami Tolvanen , Jian Cai , Linux ARM , LKML , clang-built-linux , "# 3.4.x" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 13, 2021 at 5:09 PM Nathan Chancellor wrote: > > After commit 2decad92f473 ("arm64: mte: Ensure TIF_MTE_ASYNC_FAULT is > set atomically"), LLVM's integrated assembler fails to build entry.S: > > :5:7: error: expected assembly-time absolute expression > .org . - (664b-663b) + (662b-661b) > ^ > :6:7: error: expected assembly-time absolute expression > .org . - (662b-661b) + (664b-663b) > ^ > > The root cause is LLVM's assembler has a one-pass design, meaning it > cannot figure out these instruction lengths when the .org directive is > outside of the subsection that they are in, which was changed by the > .arch_extension directive added in the above commit. > > Apply the same fix from commit 966a0acce2fc ("arm64/alternatives: move > length validation inside the subsection") to the alternative_endif > macro, shuffling the .org directives so that the length validation > happen will always happen in the same subsections. alternative_insn has > not shown any issue yet but it appears that it could have the same issue > in the future so just preemptively change it. Thanks Nathan. Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers I did some additional disassembly comparison. In case we ever need it again, I'll copy it below for posterity. $ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu make LLVM=1 LLVM_IAS=1 -j72 O=/tmp/a defconfig all $ b4 am https://lore.kernel.org/lkml/20210414000803.662534-1-nathan@kernel.org/ -o - | git am -3 $ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu make LLVM=1 LLVM_IAS=1 -j72 O=/tmp/b defconfig all $ for f in $(find /tmp/a/arch/arm64 -name \*.o); do llvm-objdump -dr $f > $f.txt; done $ for f in $(find /tmp/b/arch/arm64 -name \*.o); do llvm-objdump -dr $f > $f.txt; done $ for f in $(find /tmp/a/arch/arm64 -name \*.o); do diff -u $f.txt $(echo $f.txt|sed 's/a/b/'); done | less For no difference. You can check more sections than .text by changing `-d` to `-D` for llvm-objdump, though you're going to get a lot of noise related to changes in .strtab and relocations referring to debug info (.debug_str). But if I drop your patch, rebuild, and recompare, I see the same differences. > > Cc: stable@vger.kernel.org > Fixes: f7b93d42945c ("arm64/alternatives: use subsections for replacement sequences") > Link: https://github.com/ClangBuiltLinux/linux/issues/1347 > Signed-off-by: Nathan Chancellor > --- > > Apologies if my explanation or terminology is off, I am only now getting > more familiar with assembly. > > arch/arm64/include/asm/alternative-macros.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/alternative-macros.h b/arch/arm64/include/asm/alternative-macros.h > index 5df500dcc627..8a078fc662ac 100644 > --- a/arch/arm64/include/asm/alternative-macros.h > +++ b/arch/arm64/include/asm/alternative-macros.h > @@ -97,9 +97,9 @@ > .popsection > .subsection 1 > 663: \insn2 > -664: .previous > - .org . - (664b-663b) + (662b-661b) > +664: .org . - (664b-663b) + (662b-661b) > .org . - (662b-661b) + (664b-663b) > + .previous > .endif > .endm > > @@ -169,11 +169,11 @@ > */ > .macro alternative_endif > 664: > + .org . - (664b-663b) + (662b-661b) > + .org . - (662b-661b) + (664b-663b) > .if .Lasm_alt_mode==0 > .previous > .endif > - .org . - (664b-663b) + (662b-661b) > - .org . - (662b-661b) + (664b-663b) > .endm > > /* > > base-commit: 738fa58ee1328481d1d7889e7c430b3401c571b9 > -- > 2.31.1.272.g89b43f80a5 > -- Thanks, ~Nick Desaulniers 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 X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 176C5C433B4 for ; Wed, 14 Apr 2021 19:29:54 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 8B60C60238 for ; Wed, 14 Apr 2021 19:29:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B60C60238 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tdqsV2V6Rqk63zKOHRlLtDB/BmDwbtoTDFN6uBcUOHc=; b=ShlG6VO2CXvRxnI8om7Z6RCtt 98LJpyH1PPbY65CIab3uIPAtUr9ps749RCgPdseosYP4aW7+hzQQ8vU3R6J4C85NL+j8KST1dHUAg 0In2udtSGJXBV33Z2MSD7yNKI17sP/VoTU6DM2bX0xaWsoSoHXE3nKubD1IGWGwqEhbUHjOcb1e6+ FIOylk89AfTcz/2KrmgeN4yKzuWQ3OKWtiN44oBkpWmVoN9DFNiHOH5JyuVq5lW+mAnFMkxaUsStB KnBgXBWq8Gq7eRPNW1RELheUuCnyftb/DI6MTl7EA1qc3W5pbTyl0GUAgtO0zdC5ywbG/mjpyG2WX lq7bDXG0A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lWlAW-00DZML-F7; Wed, 14 Apr 2021 19:27:22 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lWl5x-00DXgl-7K for linux-arm-kernel@desiato.infradead.org; Wed, 14 Apr 2021 19:22:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=PUOYXNfICZdC1+9G6F70MzTNDWMZ0Mz9R8OhGw2MATA=; b=pHcLSQnMmUbj0hCUTIzYvMGMET hbibm1a5/XWD4zbCVOkmeV2ilscT4PB523SS9egAr0uZC3IO2YC4kvLGqajRUPabJ7pGSG8VQehxV lDOZVmWYz3OeQTqIe+Vmlrq+eNeybRLUBX18A9J5ahFwvoRvnzFX/AcImXDs5n2DbOUOwTp8709FV tRXiWPd8zjvmJ1yvT7tAZJ72tGDvgBvd651cCZaJXe76VWgcfpKFTMvbkHDbamKxMaBmiOQ959xl4 yzTHjzjGQTU4LOgEUxQCYSj0bQ5rpnbigEPXVN6n37jSYbCwkGV7AK4D8mSbyHJNzr9HcDec9koOP wVgop5Dg==; Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lWl5u-00831v-CK for linux-arm-kernel@lists.infradead.org; Wed, 14 Apr 2021 19:22:35 +0000 Received: by mail-lj1-x234.google.com with SMTP id u4so24478524ljo.6 for ; Wed, 14 Apr 2021 12:22:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PUOYXNfICZdC1+9G6F70MzTNDWMZ0Mz9R8OhGw2MATA=; b=thrADslz3ToX7uQBnxWvFoINCJNnr6ngJ+dVi9lut9X4zfnY8g1wvwlW0ElJoXAkx5 TMrFJGf4rs1Cvs85Z5PgLK2b4MB12ixyLb8wzp52LNINPbF6Orwb6o+8AAQXrKYiTKTw TrjFGLHCH8zBAjFQdc8gGv3bXXjOUxGY1oYulm/OmrIt4zCJXR6ZEfwbFGo3ZXNOf2m5 9R4EKJkcIeA4VQlAeY5l+GPe5sUzJ3Xf0CJO6079ZJNUoGRmmdKi07HsEdpyGNEglEx9 sy7DmPKgarJzSZNB4cpO704cM2jMIW6SXXtxRgjnonnAPEtkRIkdSCx/Pc8tPYTI/1fD ga4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PUOYXNfICZdC1+9G6F70MzTNDWMZ0Mz9R8OhGw2MATA=; b=IBDZoVOASUmDTvjZV72DvQ1VERwnvBuKt2xsot5U2QbqnhFT6NOB9deJwE8Q/oaVuv dtWDiX6APY5TFOa4YFyzl+kUnbzT+YRnD+O5aVsm0w+TAnLyg/iskM4Gu/yoQr8QDWMt Z7Zki+e77eLtLOj4j1oeCr7h/K3/NZ93FcPs1bzXwARPH7nrHEXmALeyeRrkH/fWIoMP 2YawOu1ENH2YtbHokporwCIqHNetlkcmcL+3cRMRDldUykF9gFjDoUIwhRKwTB0mY6Nr W15O/k9BoaF2MQ7Q948stOAqNkxUCykKHkkgDxxs7/FNOOzSH1RvJHW+NkMf9C1r9xPU QILA== X-Gm-Message-State: AOAM532vPIAIF66Be9sbRjMkc/ekT+747tn5kCF+SSl2Y294q85CpkMT ieg+tow/iL036uNCN5TjT+WaK+xZ+OHb981hZxAQaw== X-Google-Smtp-Source: ABdhPJwANq4izR9wSH8/54RE6iS58ESvhjt5HzFkQu+osbE8ndiFXYYZTkcxTEz7tzXd7P68r30w9dJqp3FR/dq9ths= X-Received: by 2002:a2e:b008:: with SMTP id y8mr23815586ljk.233.1618428149110; Wed, 14 Apr 2021 12:22:29 -0700 (PDT) MIME-Version: 1.0 References: <20210414000803.662534-1-nathan@kernel.org> In-Reply-To: <20210414000803.662534-1-nathan@kernel.org> From: Nick Desaulniers Date: Wed, 14 Apr 2021 12:22:17 -0700 Message-ID: Subject: Re: [PATCH] arm64: alternatives: Move length validation in alternative_{insn, endif} To: Nathan Chancellor Cc: Catalin Marinas , Will Deacon , Sami Tolvanen , Jian Cai , Linux ARM , LKML , clang-built-linux , "# 3.4.x" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210414_122234_485518_CE959D27 X-CRM114-Status: GOOD ( 25.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Apr 13, 2021 at 5:09 PM Nathan Chancellor wrote: > > After commit 2decad92f473 ("arm64: mte: Ensure TIF_MTE_ASYNC_FAULT is > set atomically"), LLVM's integrated assembler fails to build entry.S: > > :5:7: error: expected assembly-time absolute expression > .org . - (664b-663b) + (662b-661b) > ^ > :6:7: error: expected assembly-time absolute expression > .org . - (662b-661b) + (664b-663b) > ^ > > The root cause is LLVM's assembler has a one-pass design, meaning it > cannot figure out these instruction lengths when the .org directive is > outside of the subsection that they are in, which was changed by the > .arch_extension directive added in the above commit. > > Apply the same fix from commit 966a0acce2fc ("arm64/alternatives: move > length validation inside the subsection") to the alternative_endif > macro, shuffling the .org directives so that the length validation > happen will always happen in the same subsections. alternative_insn has > not shown any issue yet but it appears that it could have the same issue > in the future so just preemptively change it. Thanks Nathan. Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers I did some additional disassembly comparison. In case we ever need it again, I'll copy it below for posterity. $ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu make LLVM=1 LLVM_IAS=1 -j72 O=/tmp/a defconfig all $ b4 am https://lore.kernel.org/lkml/20210414000803.662534-1-nathan@kernel.org/ -o - | git am -3 $ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu make LLVM=1 LLVM_IAS=1 -j72 O=/tmp/b defconfig all $ for f in $(find /tmp/a/arch/arm64 -name \*.o); do llvm-objdump -dr $f > $f.txt; done $ for f in $(find /tmp/b/arch/arm64 -name \*.o); do llvm-objdump -dr $f > $f.txt; done $ for f in $(find /tmp/a/arch/arm64 -name \*.o); do diff -u $f.txt $(echo $f.txt|sed 's/a/b/'); done | less For no difference. You can check more sections than .text by changing `-d` to `-D` for llvm-objdump, though you're going to get a lot of noise related to changes in .strtab and relocations referring to debug info (.debug_str). But if I drop your patch, rebuild, and recompare, I see the same differences. > > Cc: stable@vger.kernel.org > Fixes: f7b93d42945c ("arm64/alternatives: use subsections for replacement sequences") > Link: https://github.com/ClangBuiltLinux/linux/issues/1347 > Signed-off-by: Nathan Chancellor > --- > > Apologies if my explanation or terminology is off, I am only now getting > more familiar with assembly. > > arch/arm64/include/asm/alternative-macros.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/alternative-macros.h b/arch/arm64/include/asm/alternative-macros.h > index 5df500dcc627..8a078fc662ac 100644 > --- a/arch/arm64/include/asm/alternative-macros.h > +++ b/arch/arm64/include/asm/alternative-macros.h > @@ -97,9 +97,9 @@ > .popsection > .subsection 1 > 663: \insn2 > -664: .previous > - .org . - (664b-663b) + (662b-661b) > +664: .org . - (664b-663b) + (662b-661b) > .org . - (662b-661b) + (664b-663b) > + .previous > .endif > .endm > > @@ -169,11 +169,11 @@ > */ > .macro alternative_endif > 664: > + .org . - (664b-663b) + (662b-661b) > + .org . - (662b-661b) + (664b-663b) > .if .Lasm_alt_mode==0 > .previous > .endif > - .org . - (664b-663b) + (662b-661b) > - .org . - (662b-661b) + (664b-663b) > .endm > > /* > > base-commit: 738fa58ee1328481d1d7889e7c430b3401c571b9 > -- > 2.31.1.272.g89b43f80a5 > -- Thanks, ~Nick Desaulniers _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel