Message ID | 20230404182037.863533-24-sunilvl@ventanamicro.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp86800vqo; Tue, 4 Apr 2023 11:40:43 -0700 (PDT) X-Google-Smtp-Source: AKy350YgJmmAR5yQB6ynl2w5p6m+7ck+zdx5p+6yUk7RTxKpWDoqFZ6moqVeUnKk8XZ9zMZLgLlt X-Received: by 2002:a17:902:da8f:b0:19c:da7f:a234 with SMTP id j15-20020a170902da8f00b0019cda7fa234mr3719283plx.67.1680633643464; Tue, 04 Apr 2023 11:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680633643; cv=none; d=google.com; s=arc-20160816; b=nspMKhgwB1hEYL5/nrBgqiawKwctcaYUECB2g4/g9r2gLENjD8VQqhUtMEhvq/J+g2 54NXskW0X6tOpNvVmSljC+h2tDZtKwX8nVp6enQ9FabvFcMrauQExnjAIdd3Qw9uW/FL f5fUOQJ85EbtZLqvuT9Zw8vt+90jOn8Hfx2uKbiGVBLmSOweKncj93PfGxAlyoLAG5Sb XPeYRyL7u8gTyor0AjKwdgk7kGa3PJga30IgScQidHNUz0U2+/ktKyv4MkZ4kPP7h5C1 j/Q8IlO7wdpc+CtSc2Wqvxnegxu0J45CIw5U3QZHDKsyGB+Ct3tvh1+OibdjPPrenAus fNJA== 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 :dkim-signature; bh=Gqxa4spepTnsUwVbNTwSWIuFxwC658E+AuuPxXktYUk=; b=w45mjklUm36uHKAI9bh23se0TVQCc1FysJVazVqM0Dn/dKnkpD8dr84H7WWSRaCNO5 Xxg/3mhCpfeJYP8iaqEaEOPYZ3dNCn8s1KzEHaeTD95jVzV0cCmFF2w9CtCotcxzf411 LDp8M/hT2siLpSmHcWjHK4w9XAxngq5bbUPx9lxkfEIcVjx1/GvVZw5ac4V4kCjs7MTa vvnbzid08wJR9g+kyAbb3DA06ZbTHx8WYMb9e1EGambTFfCINl3eeAy/MZJz8w0c3u64 w1Lfhyyrs8LRlcT3V+bwr69vDoWMxf0oDdvGC8l3s5u5N7oDLZCKwD+Bmypllyf1JRXy Pfyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=kAvoNYqd; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t185-20020a635fc2000000b004fc21da0340si11344625pgb.129.2023.04.04.11.40.31; Tue, 04 Apr 2023 11:40:43 -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=@ventanamicro.com header.s=google header.b=kAvoNYqd; 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 S236470AbjDDS0r (ORCPT <rfc822;a1648639935@gmail.com> + 99 others); Tue, 4 Apr 2023 14:26:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236451AbjDDS0L (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 4 Apr 2023 14:26:11 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E28A729F for <linux-kernel@vger.kernel.org>; Tue, 4 Apr 2023 11:23:37 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id o11so32175074ple.1 for <linux-kernel@vger.kernel.org>; Tue, 04 Apr 2023 11:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680632608; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Gqxa4spepTnsUwVbNTwSWIuFxwC658E+AuuPxXktYUk=; b=kAvoNYqdv/gD8yskD/3UsIZZx/i7x6fcbhJrbItIXOVXMaf2J/ZphfqXiq9a0kB1u6 PmIxtinJIL/VK4LPrFwgURCxv3uMUJaXR8WupowGpRdbZYxe85vGf7ADA3kpdGLGAjbw doyBX/v48bQyNdsiTbpiqy+9xqhSQ/wjueeo3mWjHXI7j5kcoXr3GBMPSRO6QBlcfYJL R/rE84Q8SYe+o93Fsj2ITB9DYOXg1jXgXV57Lpo/XLRh+NBFQ/p1nNn9hZqy4KxK2o/2 A9STBeEYXkETh3CnhrVKqaS3widasWrESAX5SSaNCUkVwZAhEOTn5+5CcS1XD6b614hV WsTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680632608; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gqxa4spepTnsUwVbNTwSWIuFxwC658E+AuuPxXktYUk=; b=mEnMhwl7UZPR4/cR8rfzSVPXuKw28QciuO7q1d6xYs6IPU7hR3fmr0MSogAdOLCib/ NtFFnn0EMIqS06xQJPyV+mEbM2fh3SUnECNlCDdz9Mz7T83Z2QRsq8IS44gZd/82Vx1U o/5GbJh9siy0NAFWhynq88otZY43aKSD6xQENTgr9aAeXK8fB7OaJirZoWF6mtqtCQm2 SpJ/+5QROOygOHqBkzzdAFhA14exSDjffrwcTsFZmTs4PntBI3NWFhGnn0D2jfz7A35g FoQTya/N5QKWiniq4p3OqCNBOlcmCD8+HQpHGW0T5H54eY58ZeSRa0lwySKSoqDxYpkI hMjg== X-Gm-Message-State: AAQBX9d+mjy6kiI2pUvxpRH6bh7hKcImxCpVvaO5o1nn+PzhdOkEXuwp 2iGQVj98i7l+aa4bLm21MGOdaA== X-Received: by 2002:a05:6a20:6687:b0:db:6a5a:3ce7 with SMTP id o7-20020a056a20668700b000db6a5a3ce7mr2798195pzh.12.1680632608339; Tue, 04 Apr 2023 11:23:28 -0700 (PDT) Received: from localhost.localdomain ([106.51.184.50]) by smtp.gmail.com with ESMTPSA id o12-20020a056a001bcc00b0062dcf5c01f9sm9018524pfw.36.2023.04.04.11.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:23:28 -0700 (PDT) From: Sunil V L <sunilvl@ventanamicro.com> To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-crypto@vger.kernel.org, platform-driver-x86@vger.kernel.org, llvm@lists.linux.dev Cc: Jonathan Corbet <corbet@lwn.net>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Len Brown <lenb@kernel.org>, Daniel Lezcano <daniel.lezcano@linaro.org>, Thomas Gleixner <tglx@linutronix.de>, Weili Qian <qianweili@huawei.com>, Zhou Wang <wangzhou1@hisilicon.com>, Herbert Xu <herbert@gondor.apana.org.au>, Marc Zyngier <maz@kernel.org>, Maximilian Luz <luzmaximilian@gmail.com>, Hans de Goede <hdegoede@redhat.com>, Mark Gross <markgross@kernel.org>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, "Rafael J . Wysocki" <rafael@kernel.org>, "David S . Miller" <davem@davemloft.net>, Sunil V L <sunilvl@ventanamicro.com> Subject: [PATCH V4 23/23] crypto: hisilicon/qm: Workaround to enable build with RISC-V clang Date: Tue, 4 Apr 2023 23:50:37 +0530 Message-Id: <20230404182037.863533-24-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230404182037.863533-1-sunilvl@ventanamicro.com> References: <20230404182037.863533-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762272103100313100?= X-GMAIL-MSGID: =?utf-8?q?1762272103100313100?= |
Series |
Add basic ACPI support for RISC-V
|
|
Commit Message
Sunil V L
April 4, 2023, 6:20 p.m. UTC
With CONFIG_ACPI enabled for RISC-V, this driver gets enabled in
allmodconfig build. The gcc tool chain builds this driver removing the
inline arm64 assembly code. However, clang for RISC-V tries to build
the arm64 assembly and below error is seen.
drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint '+Q' in asm
"+Q" (*((char __iomem *)fun_base))
^
It appears that RISC-V clang is not smart enough to detect
IS_ENABLED(CONFIG_ARM64) and remove the dead code.
As a workaround, move this check to preprocessing stage which works
with the RISC-V clang tool chain.
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
---
drivers/crypto/hisilicon/qm.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
Comments
Hey Sunil, This one made me scratch my head for a bit.. On Tue, Apr 04, 2023 at 11:50:37PM +0530, Sunil V L wrote: > With CONFIG_ACPI enabled for RISC-V, this driver gets enabled in > allmodconfig build. The gcc tool chain builds this driver removing the > inline arm64 assembly code. However, clang for RISC-V tries to build > the arm64 assembly and below error is seen. There's actually nothing RISC-V specific about that behaviour, that's just how clang works. Quoting Nathan: "Clang performs semantic analysis (i.e., validates assembly) before dead code elimination, so IS_ENABLED() is not sufficient for avoiding that error." > drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint '+Q' in asm > "+Q" (*((char __iomem *)fun_base)) > ^ > It appears that RISC-V clang is not smart enough to detect > IS_ENABLED(CONFIG_ARM64) and remove the dead code. So I think this statement is just not true, it can remove dead code, but only after it has done the semantic analysis. The reason that this has not been seen before, again quoting Nathan, is: "arm64 and x86_64 both support the Q constraint, we cannot build LoongArch yet (although it does not have support for Q either so same boat as RISC-V), and ia64 is dead/unsupported in LLVM. Those are the only architectures that support ACPI, so I guess that explains why we have seen no issues aside from RISC-V so far." > As a workaround, move this check to preprocessing stage which works > with the RISC-V clang tool chain. I don't think there's much else you can do! Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Perhaps it is also worth adding: Link: https://github.com/ClangBuiltLinux/linux/issues/999 Cheers, Conor. > Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> > --- > drivers/crypto/hisilicon/qm.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c > index e4c84433a88a..a5f521529ab2 100644 > --- a/drivers/crypto/hisilicon/qm.c > +++ b/drivers/crypto/hisilicon/qm.c > @@ -611,13 +611,9 @@ EXPORT_SYMBOL_GPL(hisi_qm_wait_mb_ready); > static void qm_mb_write(struct hisi_qm *qm, const void *src) > { > void __iomem *fun_base = qm->io_base + QM_MB_CMD_SEND_BASE; > - unsigned long tmp0 = 0, tmp1 = 0; > > - if (!IS_ENABLED(CONFIG_ARM64)) { > - memcpy_toio(fun_base, src, 16); > - dma_wmb(); > - return; > - } > +#if IS_ENABLED(CONFIG_ARM64) > + unsigned long tmp0 = 0, tmp1 = 0; > > asm volatile("ldp %0, %1, %3\n" > "stp %0, %1, %2\n" > @@ -627,6 +623,11 @@ static void qm_mb_write(struct hisi_qm *qm, const void *src) > "+Q" (*((char __iomem *)fun_base)) > : "Q" (*((char *)src)) > : "memory"); > +#else > + memcpy_toio(fun_base, src, 16); > + dma_wmb(); > +#endif > + > } > > static int qm_mb_nolock(struct hisi_qm *qm, struct qm_mailbox *mailbox) > -- > 2.34.1 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv
On Tue, Apr 4, 2023, at 20:20, Sunil V L wrote: > With CONFIG_ACPI enabled for RISC-V, this driver gets enabled in > allmodconfig build. The gcc tool chain builds this driver removing the > inline arm64 assembly code. However, clang for RISC-V tries to build > the arm64 assembly and below error is seen. > > drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint > '+Q' in asm > "+Q" (*((char __iomem *)fun_base)) > ^ > It appears that RISC-V clang is not smart enough to detect > IS_ENABLED(CONFIG_ARM64) and remove the dead code. > > As a workaround, move this check to preprocessing stage which works > with the RISC-V clang tool chain. > > Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> Your patch looks correct for this particular problem, but I see that there are a couple of other issues in the same function: > - } > +#if IS_ENABLED(CONFIG_ARM64) > + unsigned long tmp0 = 0, tmp1 = 0; > > asm volatile("ldp %0, %1, %3\n" > "stp %0, %1, %2\n" > @@ -627,6 +623,11 @@ static void qm_mb_write(struct hisi_qm *qm, const > void *src) > "+Q" (*((char __iomem *)fun_base)) > : "Q" (*((char *)src)) > : "memory"); For the arm64 version: - the "dmb oshst" barrier needs to come before the stp, not after it, otherwise there is no guarantee that data written to memory is visible by the device when the mailbox gets triggered - The input/output arguments need to be pointers to 128-bit types, either a struct or a __uint128_t - this lacks a byteswap on big-endian kernels > +#else > + memcpy_toio(fun_base, src, 16); > + dma_wmb(); > +#endif This version has the same problems, plus the write is not actually atomic. I wonder if a pair of writeq() calls would just do the right thing here for both arm64 and others, or possibly a writeq() followed by a writeq_relaxed() to avoid the extra dmb() in the middle. Arnd
Hi Conor, On Tue, Apr 04, 2023 at 10:59:41PM +0100, Conor Dooley wrote: > Hey Sunil, > > This one made me scratch my head for a bit.. > > On Tue, Apr 04, 2023 at 11:50:37PM +0530, Sunil V L wrote: > > With CONFIG_ACPI enabled for RISC-V, this driver gets enabled in > > allmodconfig build. The gcc tool chain builds this driver removing the > > inline arm64 assembly code. However, clang for RISC-V tries to build > > the arm64 assembly and below error is seen. > > There's actually nothing RISC-V specific about that behaviour, that's > just how clang works. Quoting Nathan: > "Clang performs semantic analysis (i.e., validates assembly) before > dead code elimination, so IS_ENABLED() is not sufficient for avoiding > that error." > Huh, It never occurred to me that this issue could be known already since I always thought we are hitting this first time since ACPI is enabled only now for RISC-V. Thank you very much!. > > drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint '+Q' in asm > > "+Q" (*((char __iomem *)fun_base)) > > ^ > > It appears that RISC-V clang is not smart enough to detect > > IS_ENABLED(CONFIG_ARM64) and remove the dead code. > > So I think this statement is just not true, it can remove dead code, but > only after it has done the semantic analysis. > Yes, with more details now, let me update the commit message. > The reason that this has not been seen before, again quoting Nathan, is: > "arm64 and x86_64 both support the Q constraint, we cannot build > LoongArch yet (although it does not have support for Q either so same > boat as RISC-V), and ia64 is dead/unsupported in LLVM. Those are the > only architectures that support ACPI, so I guess that explains why we > have seen no issues aside from RISC-V so far." > > > As a workaround, move this check to preprocessing stage which works > > with the RISC-V clang tool chain. > > I don't think there's much else you can do! > Reviewed-by: Conor Dooley <conor.dooley@microchip.com> > > Perhaps it is also worth adding: > Link: https://github.com/ClangBuiltLinux/linux/issues/999 > Sure, Thank you very much for digging this! Thanks, Sunil
On Tue, Apr 11, 2023, at 13:42, Weili Qian wrote: > On 2023/4/5 16:16, Arnd Bergmann wrote: >> On Tue, Apr 4, 2023, at 20:20, Sunil V L wrote: >>> With CONFIG_ACPI enabled for RISC-V, this driver gets enabled in >>> allmodconfig build. The gcc tool chain builds this driver removing the >>> inline arm64 assembly code. However, clang for RISC-V tries to build >>> the arm64 assembly and below error is seen. >>> >>> drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint >>> '+Q' in asm >>> "+Q" (*((char __iomem *)fun_base)) >>> ^ >>> It appears that RISC-V clang is not smart enough to detect >>> IS_ENABLED(CONFIG_ARM64) and remove the dead code. >>> >>> As a workaround, move this check to preprocessing stage which works >>> with the RISC-V clang tool chain. >>> >>> Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> >> >> Your patch looks correct for this particular problem, but I >> see that there are a couple of other issues in the same function: >> >>> - } >>> +#if IS_ENABLED(CONFIG_ARM64) >>> + unsigned long tmp0 = 0, tmp1 = 0; >>> >>> asm volatile("ldp %0, %1, %3\n" >>> "stp %0, %1, %2\n" >>> @@ -627,6 +623,11 @@ static void qm_mb_write(struct hisi_qm *qm, const >>> void *src) >>> "+Q" (*((char __iomem *)fun_base)) >>> : "Q" (*((char *)src)) >>> : "memory"); >> >> For the arm64 version: >> >> - the "dmb oshst" barrier needs to come before the stp, not after >> it, otherwise there is no guarantee that data written to memory >> is visible by the device when the mailbox gets triggered >> - The input/output arguments need to be pointers to 128-bit types, >> either a struct or a __uint128_t >> - this lacks a byteswap on big-endian kernels > Sorry for the late reply. > > - the execution order relies on the data dependency between ldp and stp: > load "src" to "tmp0" and "tmp1", then > store "tmp0" and "tmp1" to "fun_base"; Not entirely sure how that data dependency would help serialize the store into the DMA buffer against the device access. The problem here is not the qm_mailbox structure but the data pointed to by the 'u64 base' (e.g. struct qm_eqc *eqc) which may still be in a store buffer waiting to make it to physical memory at the time the mailbox store triggers the DMA from the device. > The "dmb oshst" is used to ensure that the stp instruction has been executed > before CPU checking mailbox status. Whether the execution order > cannot be guaranteed via data dependency? There is no need to have barriers between MMIO operations, they are implicitly serialized already. In this case specifically, the read is even on the same address as the write. Note that the "dmb oshst" does not actually guarantee that the store has made it to the device, as (at least on PCIe semantics) it can be posted, but the read from the same address does guarantee that the write is completed first, and this may be required to ensure that it does not complete after the mutex_unlock(). > - The input argument "src" is struct "struct qm_mailbox". > - Before call this funcion, the data has been byteswapped. > > mailbox->w0 = cpu_to_le16((cmd) | > ((op) ? 0x1 << QM_MB_OP_SHIFT : 0) | > (0x1 << QM_MB_BUSY_SHIFT)); > mailbox->queue_num = cpu_to_le16(queue); > mailbox->base_l = cpu_to_le32(lower_32_bits(base)); > mailbox->base_h = cpu_to_le32(upper_32_bits(base)); > mailbox->rsvd = 0; Right, this bit does look correct. Arnd
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index e4c84433a88a..a5f521529ab2 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -611,13 +611,9 @@ EXPORT_SYMBOL_GPL(hisi_qm_wait_mb_ready); static void qm_mb_write(struct hisi_qm *qm, const void *src) { void __iomem *fun_base = qm->io_base + QM_MB_CMD_SEND_BASE; - unsigned long tmp0 = 0, tmp1 = 0; - if (!IS_ENABLED(CONFIG_ARM64)) { - memcpy_toio(fun_base, src, 16); - dma_wmb(); - return; - } +#if IS_ENABLED(CONFIG_ARM64) + unsigned long tmp0 = 0, tmp1 = 0; asm volatile("ldp %0, %1, %3\n" "stp %0, %1, %2\n" @@ -627,6 +623,11 @@ static void qm_mb_write(struct hisi_qm *qm, const void *src) "+Q" (*((char __iomem *)fun_base)) : "Q" (*((char *)src)) : "memory"); +#else + memcpy_toio(fun_base, src, 16); + dma_wmb(); +#endif + } static int qm_mb_nolock(struct hisi_qm *qm, struct qm_mailbox *mailbox)