diff mbox series

RISC-V: selftests: cbo: Use exported __cpu_to_le32() with uapi header

Message ID 20240321115250.801731-1-woodrow.shen@sifive.com (mailing list archive)
State Superseded
Headers show
Series RISC-V: selftests: cbo: Use exported __cpu_to_le32() with uapi header | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR success PR summary
conchuod/patch-1-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh
conchuod/patch-1-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh
conchuod/patch-1-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh
conchuod/patch-1-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh
conchuod/patch-1-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh
conchuod/patch-1-test-6 success .github/scripts/patches/tests/checkpatch.sh
conchuod/patch-1-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh
conchuod/patch-1-test-8 success .github/scripts/patches/tests/header_inline.sh
conchuod/patch-1-test-9 success .github/scripts/patches/tests/kdoc.sh
conchuod/patch-1-test-10 success .github/scripts/patches/tests/module_param.sh
conchuod/patch-1-test-11 success .github/scripts/patches/tests/verify_fixes.sh
conchuod/patch-1-test-12 success .github/scripts/patches/tests/verify_signedoff.sh

Commit Message

Woodrow Shen March 21, 2024, 11:52 a.m. UTC
From: Hsieh-Tseng Shen <woodrow.shen@sifive.com>

cpu_to_le32 is not defined in uapi headers, and it could cause an error
of impossible constraint in 'asm' during compilation. However,
the reason is due to undefined reference to cpu_to_le32.
__cpu_to_le32() defined from byteorder.h should be used instead.

Signed-off-by: Hsieh-Tseng Shen <woodrow.shen@sifive.com>
---
 tools/testing/selftests/riscv/hwprobe/cbo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Woodrow Shen March 21, 2024, 12:14 p.m. UTC | #1
Short background: while I'm building the riscv/hwprobe tests, it seems
I always hit the "error: impossible constraint in 'asm'" even though
the commit https://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git/commit/tools/testing/selftests/riscv/hwprobe/cbo.c?id=0de65288d75ff96c30e216557d979fb9342c4323
is applied. I'm not sure if this only happens to me as I tried to
build them on a clean debian chroot. To apply this patch makes the
build happy, but if there is no need to change, please ignore this
patch.

And sorry to forget cc more maintainers for reviewing.

Cheers,
Woodrow


On Thu, Mar 21, 2024 at 7:52 PM <woodrow.shen@sifive.com> wrote:
>
> From: Hsieh-Tseng Shen <woodrow.shen@sifive.com>
>
> cpu_to_le32 is not defined in uapi headers, and it could cause an error
> of impossible constraint in 'asm' during compilation. However,
> the reason is due to undefined reference to cpu_to_le32.
> __cpu_to_le32() defined from byteorder.h should be used instead.
>
> Signed-off-by: Hsieh-Tseng Shen <woodrow.shen@sifive.com>
> ---
>  tools/testing/selftests/riscv/hwprobe/cbo.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/selftests/riscv/hwprobe/cbo.c
> index c537d52fafc5..b2dd18b3e360 100644
> --- a/tools/testing/selftests/riscv/hwprobe/cbo.c
> +++ b/tools/testing/selftests/riscv/hwprobe/cbo.c
> @@ -15,11 +15,12 @@
>  #include <linux/compiler.h>
>  #include <linux/kernel.h>
>  #include <asm/ucontext.h>
> +#include <asm/byteorder.h>
>
>  #include "hwprobe.h"
>  #include "../../kselftest.h"
>
> -#define MK_CBO(fn) cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
> +#define MK_CBO(fn) __cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
>
>  static char mem[4096] __aligned(4096) = { [0 ... 4095] = 0xa5 };
>
> --
> 2.34.1
>
Andrew Jones March 22, 2024, 8:40 a.m. UTC | #2
On Thu, Mar 21, 2024 at 08:14:34PM +0800, Woodrow Shen wrote:
> Short background: while I'm building the riscv/hwprobe tests, it seems
> I always hit the "error: impossible constraint in 'asm'" even though
> the commit https://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git/commit/tools/testing/selftests/riscv/hwprobe/cbo.c?id=0de65288d75ff96c30e216557d979fb9342c4323
> is applied. I'm not sure if this only happens to me as I tried to
> build them on a clean debian chroot. To apply this patch makes the
> build happy, but if there is no need to change, please ignore this
> patch.

It looks like I managed to mess up my fix to my mess up. Clearly I
shouldn't still have a potential function call in a macro which I want
to always resolve to a literal. Instead of using cpu_to_le32 I should
use something that results in ___constant_swab32, like your suggestion
of __cpu_to_le32. I'm not sure we want to depend on Linux UAPI that isn't
in the tools directory though, so maybe we should just reproduce it here.
Something like

#if __BYTE_ORDER == __BIG_ENDIAN
# define constant_swab32(_x)                     \
    ((((_x) & 0x000000ffU) << 24) |              \
     (((_x) & 0x0000ff00U) <<  8) |              \
     (((_x) & 0x00ff0000U) >>  8) |              \
     (((_x) & 0xff000000U) >> 24))
#else
# constant_swab32(_x) (_x)
#endif

#define MK_CBO(fn) constant_swab32((uint32_t)(fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)

Thanks,
drew

> 
> And sorry to forget cc more maintainers for reviewing.
> 
> Cheers,
> Woodrow
> 
> 
> On Thu, Mar 21, 2024 at 7:52 PM <woodrow.shen@sifive.com> wrote:
> >
> > From: Hsieh-Tseng Shen <woodrow.shen@sifive.com>
> >
> > cpu_to_le32 is not defined in uapi headers, and it could cause an error
> > of impossible constraint in 'asm' during compilation. However,
> > the reason is due to undefined reference to cpu_to_le32.
> > __cpu_to_le32() defined from byteorder.h should be used instead.
> >
> > Signed-off-by: Hsieh-Tseng Shen <woodrow.shen@sifive.com>
> > ---
> >  tools/testing/selftests/riscv/hwprobe/cbo.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/selftests/riscv/hwprobe/cbo.c
> > index c537d52fafc5..b2dd18b3e360 100644
> > --- a/tools/testing/selftests/riscv/hwprobe/cbo.c
> > +++ b/tools/testing/selftests/riscv/hwprobe/cbo.c
> > @@ -15,11 +15,12 @@
> >  #include <linux/compiler.h>
> >  #include <linux/kernel.h>
> >  #include <asm/ucontext.h>
> > +#include <asm/byteorder.h>
> >
> >  #include "hwprobe.h"
> >  #include "../../kselftest.h"
> >
> > -#define MK_CBO(fn) cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
> > +#define MK_CBO(fn) __cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
> >
> >  static char mem[4096] __aligned(4096) = { [0 ... 4095] = 0xa5 };
> >
> > --
> > 2.34.1
> >
diff mbox series

Patch

diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/selftests/riscv/hwprobe/cbo.c
index c537d52fafc5..b2dd18b3e360 100644
--- a/tools/testing/selftests/riscv/hwprobe/cbo.c
+++ b/tools/testing/selftests/riscv/hwprobe/cbo.c
@@ -15,11 +15,12 @@ 
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <asm/ucontext.h>
+#include <asm/byteorder.h>
 
 #include "hwprobe.h"
 #include "../../kselftest.h"
 
-#define MK_CBO(fn) cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
+#define MK_CBO(fn) __cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
 
 static char mem[4096] __aligned(4096) = { [0 ... 4095] = 0xa5 };