2021-01-06 20:41:57

by Dave Jiang

[permalink] [raw]
Subject: [PATCH] x86: fix movdir64b() sparse warning

Add missing __iomem anotation to address sparse warning.

"sparse warnings: (new ones prefixed by >>)"
drivers/dma/idxd/submit.c: note: in included file (through include/linux/io.h, include/linux/pci.h):
>> arch/x86/include/asm/io.h:422:27: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *dst @@ got void [noderef] __iomem *dst @@
arch/x86/include/asm/io.h:422:27: sparse: expected void *dst
arch/x86/include/asm/io.h:422:27: sparse: got void [noderef] __iomem *dst

Fixes: 0888e1030d3e ("x86/asm: Carve out a generic movdir64b() helper for general usage")
Reported-by: kernel test robot <[email protected]>
Reviewed-by: Ben Widawsky <[email protected]>
Signed-off-by: Dave Jiang <[email protected]>
---
arch/x86/include/asm/special_insns.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index cc177b4431ae..4e234645f0c6 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -243,10 +243,10 @@ static inline void serialize(void)
}

/* The dst parameter must be 64-bytes aligned */
-static inline void movdir64b(void *dst, const void *src)
+static inline void movdir64b(void __iomem *dst, const void *src)
{
const struct { char _[64]; } *__src = src;
- struct { char _[64]; } *__dst = dst;
+ struct { char _[64]; } __iomem *__dst = dst;

/*
* MOVDIR64B %(rdx), rax.



2021-01-06 21:03:05

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH] x86: fix movdir64b() sparse warning

On Wed, Jan 6, 2021 at 12:40 PM Dave Jiang <[email protected]> wrote:
>
> Add missing __iomem anotation to address sparse warning.

s/anotation/annotation/

>
> "sparse warnings: (new ones prefixed by >>)"
> drivers/dma/idxd/submit.c: note: in included file (through include/linux/io.h, include/linux/pci.h):
> >> arch/x86/include/asm/io.h:422:27: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *dst @@ got void [noderef] __iomem *dst @@
> arch/x86/include/asm/io.h:422:27: sparse: expected void *dst
> arch/x86/include/asm/io.h:422:27: sparse: got void [noderef] __iomem *dst

The sparse spew is somewhat interesting, but what would be more
helpful is explain the why. I.e. that existing and future users expect
to be passing an __iomem annotated pointer to this routine because...
<reasons go here>. Otherwise someone (reviewer / future git blame
user) might reasonably ask, "well, why is the driver passing an
__iomem annotated pointer in the first instance?".

To Ben's point you might also duplicate part of the comment from
movdir64b and say:

"Recall, from the comment in movdir64b @__dst must be supplied as an
lvalue because this tells the compiler what the object is (its size)
the instruction accesses. I.e., not the pointers but what they point
to, thus the deref'ing '*'."

With clarified changelog for both you can add:

Reviewed-by: Dan Williams <[email protected]>

2021-01-06 21:06:31

by Ben Widawsky

[permalink] [raw]
Subject: Re: [PATCH] x86: fix movdir64b() sparse warning

On 21-01-06 12:59:35, Dan Williams wrote:
> On Wed, Jan 6, 2021 at 12:40 PM Dave Jiang <[email protected]> wrote:
> >
> > Add missing __iomem anotation to address sparse warning.
>
> s/anotation/annotation/
>
> >
> > "sparse warnings: (new ones prefixed by >>)"
> > drivers/dma/idxd/submit.c: note: in included file (through include/linux/io.h, include/linux/pci.h):
> > >> arch/x86/include/asm/io.h:422:27: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *dst @@ got void [noderef] __iomem *dst @@
> > arch/x86/include/asm/io.h:422:27: sparse: expected void *dst
> > arch/x86/include/asm/io.h:422:27: sparse: got void [noderef] __iomem *dst
>
> The sparse spew is somewhat interesting, but what would be more
> helpful is explain the why. I.e. that existing and future users expect
> to be passing an __iomem annotated pointer to this routine because...
> <reasons go here>. Otherwise someone (reviewer / future git blame
> user) might reasonably ask, "well, why is the driver passing an
> __iomem annotated pointer in the first instance?".
>
> To Ben's point you might also duplicate part of the comment from
> movdir64b and say:
>
> "Recall, from the comment in movdir64b @__dst must be supplied as an
> lvalue because this tells the compiler what the object is (its size)
> the instruction accesses. I.e., not the pointers but what they point
> to, thus the deref'ing '*'."

Thanks for pasting this, I missed that. It still doesn't make sense to me why
the compiler needs to know this. I guess it makes sense to the rest of you.

>
> With clarified changelog for both you can add:
>
> Reviewed-by: Dan Williams <[email protected]>