linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RISC-V: selftests: fix cbo.c compilation error
@ 2024-01-17  8:25 Yunhui Cui
  2024-01-17  9:16 ` Andrew Jones
  0 siblings, 1 reply; 3+ messages in thread
From: Yunhui Cui @ 2024-01-17  8:25 UTC (permalink / raw)
  To: shuah, paul.walmsley, palmer, aou, cuiyunhui, ajones, xiao.w.wang,
	linux-kselftest, linux-riscv, linux-kernel, xuzhipeng.1973

When compiling with -O0, the following error will occur:
cbo.c: In function 'cbo_insn':
cbo.c:43:9: warning: 'asm' operand 1 probably does not match constraints
   43 |         asm volatile(
      |         ^~~
cbo.c:43:9: warning: 'asm' operand 2 probably does not match constraints
cbo.c:43:9: error: impossible constraint in 'asm'

Add __attribute__((optimize("O"))) to fix.

Fixes: a29e2a48afe3 ("RISC-V: selftests: Add CBO tests")
Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
Suggested-by: Zhipeng Xu <xuzhipeng.1973@bytedance.com>
---
 tools/testing/selftests/riscv/hwprobe/cbo.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/selftests/riscv/hwprobe/cbo.c
index 50a2cc8aef38..ff1d8e843d70 100644
--- a/tools/testing/selftests/riscv/hwprobe/cbo.c
+++ b/tools/testing/selftests/riscv/hwprobe/cbo.c
@@ -36,7 +36,7 @@ static void sigill_handler(int sig, siginfo_t *info, void *context)
 	regs[0] += 4;
 }
 
-static void cbo_insn(char *base, int fn)
+static __always_inline void cbo_insn(char *base, int fn)
 {
 	uint32_t insn = MK_CBO(fn);
 
@@ -47,10 +47,11 @@ static void cbo_insn(char *base, int fn)
 	: : "r" (base), "i" (fn), "i" (insn) : "a0", "a1", "memory");
 }
 
-static void cbo_inval(char *base) { cbo_insn(base, 0); }
-static void cbo_clean(char *base) { cbo_insn(base, 1); }
-static void cbo_flush(char *base) { cbo_insn(base, 2); }
-static void cbo_zero(char *base)  { cbo_insn(base, 4); }
+#define OPTIMIZE __attribute__((optimize("O")))
+OPTIMIZE static void cbo_inval(char *base) { cbo_insn(base, 0); }
+OPTIMIZE static void cbo_clean(char *base) { cbo_insn(base, 1); }
+OPTIMIZE static void cbo_flush(char *base) { cbo_insn(base, 2); }
+OPTIMIZE static void cbo_zero(char *base)  { cbo_insn(base, 4); }
 
 static void test_no_zicbom(void *arg)
 {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: selftests: fix cbo.c compilation error
  2024-01-17  8:25 [PATCH] RISC-V: selftests: fix cbo.c compilation error Yunhui Cui
@ 2024-01-17  9:16 ` Andrew Jones
  2024-01-17  9:34   ` [External] " yunhui cui
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Jones @ 2024-01-17  9:16 UTC (permalink / raw)
  To: Yunhui Cui
  Cc: shuah, paul.walmsley, palmer, aou, xiao.w.wang, linux-kselftest,
	linux-riscv, linux-kernel, xuzhipeng.1973

On Wed, Jan 17, 2024 at 04:25:14PM +0800, Yunhui Cui wrote:
> When compiling with -O0, the following error will occur:
> cbo.c: In function 'cbo_insn':
> cbo.c:43:9: warning: 'asm' operand 1 probably does not match constraints
>    43 |         asm volatile(
>       |         ^~~
> cbo.c:43:9: warning: 'asm' operand 2 probably does not match constraints
> cbo.c:43:9: error: impossible constraint in 'asm'
> 
> Add __attribute__((optimize("O"))) to fix.
> 
> Fixes: a29e2a48afe3 ("RISC-V: selftests: Add CBO tests")
> Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
> Suggested-by: Zhipeng Xu <xuzhipeng.1973@bytedance.com>
> ---
>  tools/testing/selftests/riscv/hwprobe/cbo.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/selftests/riscv/hwprobe/cbo.c
> index 50a2cc8aef38..ff1d8e843d70 100644
> --- a/tools/testing/selftests/riscv/hwprobe/cbo.c
> +++ b/tools/testing/selftests/riscv/hwprobe/cbo.c
> @@ -36,7 +36,7 @@ static void sigill_handler(int sig, siginfo_t *info, void *context)
>  	regs[0] += 4;
>  }
>  
> -static void cbo_insn(char *base, int fn)
> +static __always_inline void cbo_insn(char *base, int fn)
>  {
>  	uint32_t insn = MK_CBO(fn);
>  
> @@ -47,10 +47,11 @@ static void cbo_insn(char *base, int fn)
>  	: : "r" (base), "i" (fn), "i" (insn) : "a0", "a1", "memory");
>  }
>  
> -static void cbo_inval(char *base) { cbo_insn(base, 0); }
> -static void cbo_clean(char *base) { cbo_insn(base, 1); }
> -static void cbo_flush(char *base) { cbo_insn(base, 2); }
> -static void cbo_zero(char *base)  { cbo_insn(base, 4); }
> +#define OPTIMIZE __attribute__((optimize("O")))
> +OPTIMIZE static void cbo_inval(char *base) { cbo_insn(base, 0); }
> +OPTIMIZE static void cbo_clean(char *base) { cbo_insn(base, 1); }
> +OPTIMIZE static void cbo_flush(char *base) { cbo_insn(base, 2); }
> +OPTIMIZE static void cbo_zero(char *base)  { cbo_insn(base, 4); }
>  
>  static void test_no_zicbom(void *arg)
>  {
> -- 
> 2.20.1
>

Hi Yunhui,

Thanks for the bug report, but this isn't the right fix. The real problem
is that I didn't ensure operands 1 and 2 match their constraints, just as
the warning you discovered says. To do that, I should have made cbo_insn()
a macro and not used the local variable, i.e. ensure 'fn' and 'insn' are
indeed constants derived from the 0,1,2,4 constants.

I'll send a patch with your reported-by.

Thanks,
drew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [External] Re: [PATCH] RISC-V: selftests: fix cbo.c compilation error
  2024-01-17  9:16 ` Andrew Jones
@ 2024-01-17  9:34   ` yunhui cui
  0 siblings, 0 replies; 3+ messages in thread
From: yunhui cui @ 2024-01-17  9:34 UTC (permalink / raw)
  To: Andrew Jones
  Cc: shuah, paul.walmsley, palmer, aou, xiao.w.wang, linux-kselftest,
	linux-riscv, linux-kernel, xuzhipeng.1973

Hi drew,

On Wed, Jan 17, 2024 at 5:16 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> On Wed, Jan 17, 2024 at 04:25:14PM +0800, Yunhui Cui wrote:
> > When compiling with -O0, the following error will occur:
> > cbo.c: In function 'cbo_insn':
> > cbo.c:43:9: warning: 'asm' operand 1 probably does not match constraints
> >    43 |         asm volatile(
> >       |         ^~~
> > cbo.c:43:9: warning: 'asm' operand 2 probably does not match constraints
> > cbo.c:43:9: error: impossible constraint in 'asm'
> >
> > Add __attribute__((optimize("O"))) to fix.
> >
> > Fixes: a29e2a48afe3 ("RISC-V: selftests: Add CBO tests")
> > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
> > Suggested-by: Zhipeng Xu <xuzhipeng.1973@bytedance.com>
> > ---
> >  tools/testing/selftests/riscv/hwprobe/cbo.c | 11 ++++++-----
> >  1 file changed, 6 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/selftests/riscv/hwprobe/cbo.c
> > index 50a2cc8aef38..ff1d8e843d70 100644
> > --- a/tools/testing/selftests/riscv/hwprobe/cbo.c
> > +++ b/tools/testing/selftests/riscv/hwprobe/cbo.c
> > @@ -36,7 +36,7 @@ static void sigill_handler(int sig, siginfo_t *info, void *context)
> >       regs[0] += 4;
> >  }
> >
> > -static void cbo_insn(char *base, int fn)
> > +static __always_inline void cbo_insn(char *base, int fn)
> >  {
> >       uint32_t insn = MK_CBO(fn);
> >
> > @@ -47,10 +47,11 @@ static void cbo_insn(char *base, int fn)
> >       : : "r" (base), "i" (fn), "i" (insn) : "a0", "a1", "memory");
> >  }
> >
> > -static void cbo_inval(char *base) { cbo_insn(base, 0); }
> > -static void cbo_clean(char *base) { cbo_insn(base, 1); }
> > -static void cbo_flush(char *base) { cbo_insn(base, 2); }
> > -static void cbo_zero(char *base)  { cbo_insn(base, 4); }
> > +#define OPTIMIZE __attribute__((optimize("O")))
> > +OPTIMIZE static void cbo_inval(char *base) { cbo_insn(base, 0); }
> > +OPTIMIZE static void cbo_clean(char *base) { cbo_insn(base, 1); }
> > +OPTIMIZE static void cbo_flush(char *base) { cbo_insn(base, 2); }
> > +OPTIMIZE static void cbo_zero(char *base)  { cbo_insn(base, 4); }
> >
> >  static void test_no_zicbom(void *arg)
> >  {
> > --
> > 2.20.1
> >
>
> Hi Yunhui,
>
> Thanks for the bug report, but this isn't the right fix. The real problem
> is that I didn't ensure operands 1 and 2 match their constraints, just as
> the warning you discovered says. To do that, I should have made cbo_insn()
> a macro and not used the local variable, i.e. ensure 'fn' and 'insn' are
> indeed constants derived from the 0,1,2,4 constants.
>
> I'll send a patch with your reported-by.
Okay, if you want to use macros to fix it, you can. thanks!

Thanks,
Yunhui

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-17  9:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-17  8:25 [PATCH] RISC-V: selftests: fix cbo.c compilation error Yunhui Cui
2024-01-17  9:16 ` Andrew Jones
2024-01-17  9:34   ` [External] " yunhui cui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).