Re: [PATCH V4 23/23] crypto: hisilicon/qm: Workaround to enable build with RISC-V clang

From: Arnd Bergmann
Date: Wed Apr 05 2023 - 04:55:57 EST


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@xxxxxxxxxxxxxxxx>

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