* [PATCH] iommu/arm-smmu-v3: Fix endianness annotations
@ 2020-09-18 14:18 Jean-Philippe Brucker
2020-09-18 15:02 ` Robin Murphy
2020-09-21 18:17 ` Will Deacon
0 siblings, 2 replies; 4+ messages in thread
From: Jean-Philippe Brucker @ 2020-09-18 14:18 UTC (permalink / raw)
To: will, robin.murphy; +Cc: Jean-Philippe Brucker, iommu, linux-arm-kernel
When building with C=1, sparse reports some issues regarding endianness
annotations:
arm-smmu-v3.c:221:26: warning: cast to restricted __le64
arm-smmu-v3.c:221:24: warning: incorrect type in assignment (different base types)
arm-smmu-v3.c:221:24: expected restricted __le64 [usertype]
arm-smmu-v3.c:221:24: got unsigned long long [usertype]
arm-smmu-v3.c:229:20: warning: incorrect type in argument 1 (different base types)
arm-smmu-v3.c:229:20: expected restricted __le64 [usertype] *[assigned] dst
arm-smmu-v3.c:229:20: got unsigned long long [usertype] *ent
arm-smmu-v3.c:229:25: warning: incorrect type in argument 2 (different base types)
arm-smmu-v3.c:229:25: expected unsigned long long [usertype] *[assigned] src
arm-smmu-v3.c:229:25: got restricted __le64 [usertype] *
arm-smmu-v3.c:396:20: warning: incorrect type in argument 1 (different base types)
arm-smmu-v3.c:396:20: expected restricted __le64 [usertype] *[assigned] dst
arm-smmu-v3.c:396:20: got unsigned long long *
arm-smmu-v3.c:396:25: warning: incorrect type in argument 2 (different base types)
arm-smmu-v3.c:396:25: expected unsigned long long [usertype] *[assigned] src
arm-smmu-v3.c:396:25: got restricted __le64 [usertype] *
arm-smmu-v3.c:1349:32: warning: invalid assignment: |=
arm-smmu-v3.c:1349:32: left side has type restricted __le64
arm-smmu-v3.c:1349:32: right side has type unsigned long
arm-smmu-v3.c:1396:53: warning: incorrect type in argument 3 (different base types)
arm-smmu-v3.c:1396:53: expected restricted __le64 [usertype] *dst
arm-smmu-v3.c:1396:53: got unsigned long long [usertype] *strtab
arm-smmu-v3.c:1424:39: warning: incorrect type in argument 1 (different base types)
arm-smmu-v3.c:1424:39: expected unsigned long long [usertype] *[assigned] strtab
arm-smmu-v3.c:1424:39: got restricted __le64 [usertype] *l2ptr
While harmless, they are incorrect and could hide actual errors during
development. Fix them.
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
There is another false positive due to passing INT_MIN to cmpxchg, and
__cmpxchg* to truncate them to u8 and u16:
arch/arm64/include/asm/cmpxchg.h:172:1: warning: cast truncates bits from constant value (ffffffff80000000 becomes 0)
arch/arm64/include/asm/cmpxchg.h:172:1: warning: cast truncates bits from constant value (ffffffff80000000 becomes 0)
I haven't found a satisfying fix so far, except adding __force to
__cmpxchg_case* which could hide actual bugs.
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index c192544e874b..83acc1e5888e 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -867,7 +867,7 @@ static void queue_write(__le64 *dst, u64 *src, size_t n_dwords)
*dst++ = cpu_to_le64(*src++);
}
-static void queue_read(__le64 *dst, u64 *src, size_t n_dwords)
+static void queue_read(u64 *dst, __le64 *src, size_t n_dwords)
{
int i;
@@ -1939,7 +1939,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd);
}
-static void arm_smmu_init_bypass_stes(u64 *strtab, unsigned int nent)
+static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent)
{
unsigned int i;
--
2.28.0
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/arm-smmu-v3: Fix endianness annotations
2020-09-18 14:18 [PATCH] iommu/arm-smmu-v3: Fix endianness annotations Jean-Philippe Brucker
@ 2020-09-18 15:02 ` Robin Murphy
2020-09-18 15:08 ` Jean-Philippe Brucker
2020-09-21 18:17 ` Will Deacon
1 sibling, 1 reply; 4+ messages in thread
From: Robin Murphy @ 2020-09-18 15:02 UTC (permalink / raw)
To: Jean-Philippe Brucker, will; +Cc: iommu, linux-arm-kernel
On 2020-09-18 15:18, Jean-Philippe Brucker wrote:
> When building with C=1, sparse reports some issues regarding endianness
> annotations:
>
> arm-smmu-v3.c:221:26: warning: cast to restricted __le64
> arm-smmu-v3.c:221:24: warning: incorrect type in assignment (different base types)
> arm-smmu-v3.c:221:24: expected restricted __le64 [usertype]
> arm-smmu-v3.c:221:24: got unsigned long long [usertype]
> arm-smmu-v3.c:229:20: warning: incorrect type in argument 1 (different base types)
> arm-smmu-v3.c:229:20: expected restricted __le64 [usertype] *[assigned] dst
> arm-smmu-v3.c:229:20: got unsigned long long [usertype] *ent
> arm-smmu-v3.c:229:25: warning: incorrect type in argument 2 (different base types)
> arm-smmu-v3.c:229:25: expected unsigned long long [usertype] *[assigned] src
> arm-smmu-v3.c:229:25: got restricted __le64 [usertype] *
> arm-smmu-v3.c:396:20: warning: incorrect type in argument 1 (different base types)
> arm-smmu-v3.c:396:20: expected restricted __le64 [usertype] *[assigned] dst
> arm-smmu-v3.c:396:20: got unsigned long long *
> arm-smmu-v3.c:396:25: warning: incorrect type in argument 2 (different base types)
> arm-smmu-v3.c:396:25: expected unsigned long long [usertype] *[assigned] src
> arm-smmu-v3.c:396:25: got restricted __le64 [usertype] *
> arm-smmu-v3.c:1349:32: warning: invalid assignment: |=
> arm-smmu-v3.c:1349:32: left side has type restricted __le64
> arm-smmu-v3.c:1349:32: right side has type unsigned long
> arm-smmu-v3.c:1396:53: warning: incorrect type in argument 3 (different base types)
> arm-smmu-v3.c:1396:53: expected restricted __le64 [usertype] *dst
> arm-smmu-v3.c:1396:53: got unsigned long long [usertype] *strtab
> arm-smmu-v3.c:1424:39: warning: incorrect type in argument 1 (different base types)
> arm-smmu-v3.c:1424:39: expected unsigned long long [usertype] *[assigned] strtab
> arm-smmu-v3.c:1424:39: got restricted __le64 [usertype] *l2ptr
>
> While harmless, they are incorrect and could hide actual errors during
> development. Fix them.
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
>
> There is another false positive due to passing INT_MIN to cmpxchg, and
> __cmpxchg* to truncate them to u8 and u16:
>
> arch/arm64/include/asm/cmpxchg.h:172:1: warning: cast truncates bits from constant value (ffffffff80000000 becomes 0)
> arch/arm64/include/asm/cmpxchg.h:172:1: warning: cast truncates bits from constant value (ffffffff80000000 becomes 0)
>
> I haven't found a satisfying fix so far, except adding __force to
> __cmpxchg_case* which could hide actual bugs.
I guess that's a general issue with the switch(sizeof()) idiom of sparse
not being aware that those cases are unreachable?
Robin.
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index c192544e874b..83acc1e5888e 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -867,7 +867,7 @@ static void queue_write(__le64 *dst, u64 *src, size_t n_dwords)
> *dst++ = cpu_to_le64(*src++);
> }
>
> -static void queue_read(__le64 *dst, u64 *src, size_t n_dwords)
> +static void queue_read(u64 *dst, __le64 *src, size_t n_dwords)
> {
> int i;
>
> @@ -1939,7 +1939,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
> arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd);
> }
>
> -static void arm_smmu_init_bypass_stes(u64 *strtab, unsigned int nent)
> +static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent)
> {
> unsigned int i;
>
>
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/arm-smmu-v3: Fix endianness annotations
2020-09-18 15:02 ` Robin Murphy
@ 2020-09-18 15:08 ` Jean-Philippe Brucker
0 siblings, 0 replies; 4+ messages in thread
From: Jean-Philippe Brucker @ 2020-09-18 15:08 UTC (permalink / raw)
To: Robin Murphy; +Cc: will, iommu, linux-arm-kernel
On Fri, Sep 18, 2020 at 04:02:26PM +0100, Robin Murphy wrote:
> On 2020-09-18 15:18, Jean-Philippe Brucker wrote:
> > When building with C=1, sparse reports some issues regarding endianness
> > annotations:
> >
> > arm-smmu-v3.c:221:26: warning: cast to restricted __le64
> > arm-smmu-v3.c:221:24: warning: incorrect type in assignment (different base types)
> > arm-smmu-v3.c:221:24: expected restricted __le64 [usertype]
> > arm-smmu-v3.c:221:24: got unsigned long long [usertype]
> > arm-smmu-v3.c:229:20: warning: incorrect type in argument 1 (different base types)
> > arm-smmu-v3.c:229:20: expected restricted __le64 [usertype] *[assigned] dst
> > arm-smmu-v3.c:229:20: got unsigned long long [usertype] *ent
> > arm-smmu-v3.c:229:25: warning: incorrect type in argument 2 (different base types)
> > arm-smmu-v3.c:229:25: expected unsigned long long [usertype] *[assigned] src
> > arm-smmu-v3.c:229:25: got restricted __le64 [usertype] *
> > arm-smmu-v3.c:396:20: warning: incorrect type in argument 1 (different base types)
> > arm-smmu-v3.c:396:20: expected restricted __le64 [usertype] *[assigned] dst
> > arm-smmu-v3.c:396:20: got unsigned long long *
> > arm-smmu-v3.c:396:25: warning: incorrect type in argument 2 (different base types)
> > arm-smmu-v3.c:396:25: expected unsigned long long [usertype] *[assigned] src
> > arm-smmu-v3.c:396:25: got restricted __le64 [usertype] *
> > arm-smmu-v3.c:1349:32: warning: invalid assignment: |=
> > arm-smmu-v3.c:1349:32: left side has type restricted __le64
> > arm-smmu-v3.c:1349:32: right side has type unsigned long
> > arm-smmu-v3.c:1396:53: warning: incorrect type in argument 3 (different base types)
> > arm-smmu-v3.c:1396:53: expected restricted __le64 [usertype] *dst
> > arm-smmu-v3.c:1396:53: got unsigned long long [usertype] *strtab
> > arm-smmu-v3.c:1424:39: warning: incorrect type in argument 1 (different base types)
> > arm-smmu-v3.c:1424:39: expected unsigned long long [usertype] *[assigned] strtab
> > arm-smmu-v3.c:1424:39: got restricted __le64 [usertype] *l2ptr
> >
> > While harmless, they are incorrect and could hide actual errors during
> > development. Fix them.
>
> Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Thanks!
> > Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> > ---
> >
> > There is another false positive due to passing INT_MIN to cmpxchg, and
> > __cmpxchg* to truncate them to u8 and u16:
> >
> > arch/arm64/include/asm/cmpxchg.h:172:1: warning: cast truncates bits from constant value (ffffffff80000000 becomes 0)
> > arch/arm64/include/asm/cmpxchg.h:172:1: warning: cast truncates bits from constant value (ffffffff80000000 becomes 0)
> >
> > I haven't found a satisfying fix so far, except adding __force to
> > __cmpxchg_case* which could hide actual bugs.
>
> I guess that's a general issue with the switch(sizeof()) idiom of sparse not
> being aware that those cases are unreachable?
Precisely. I wondered if _Generic could help, but it looks like the
problem is the same.
Thanks,
Jean
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/arm-smmu-v3: Fix endianness annotations
2020-09-18 14:18 [PATCH] iommu/arm-smmu-v3: Fix endianness annotations Jean-Philippe Brucker
2020-09-18 15:02 ` Robin Murphy
@ 2020-09-21 18:17 ` Will Deacon
1 sibling, 0 replies; 4+ messages in thread
From: Will Deacon @ 2020-09-21 18:17 UTC (permalink / raw)
To: Jean-Philippe Brucker, robin.murphy
Cc: Will Deacon, catalin.marinas, iommu, kernel-team, linux-arm-kernel
On Fri, 18 Sep 2020 16:18:57 +0200, Jean-Philippe Brucker wrote:
> When building with C=1, sparse reports some issues regarding endianness
> annotations:
>
> arm-smmu-v3.c:221:26: warning: cast to restricted __le64
> arm-smmu-v3.c:221:24: warning: incorrect type in assignment (different base types)
> arm-smmu-v3.c:221:24: expected restricted __le64 [usertype]
> arm-smmu-v3.c:221:24: got unsigned long long [usertype]
> arm-smmu-v3.c:229:20: warning: incorrect type in argument 1 (different base types)
> arm-smmu-v3.c:229:20: expected restricted __le64 [usertype] *[assigned] dst
> arm-smmu-v3.c:229:20: got unsigned long long [usertype] *ent
> arm-smmu-v3.c:229:25: warning: incorrect type in argument 2 (different base types)
> arm-smmu-v3.c:229:25: expected unsigned long long [usertype] *[assigned] src
> arm-smmu-v3.c:229:25: got restricted __le64 [usertype] *
> arm-smmu-v3.c:396:20: warning: incorrect type in argument 1 (different base types)
> arm-smmu-v3.c:396:20: expected restricted __le64 [usertype] *[assigned] dst
> arm-smmu-v3.c:396:20: got unsigned long long *
> arm-smmu-v3.c:396:25: warning: incorrect type in argument 2 (different base types)
> arm-smmu-v3.c:396:25: expected unsigned long long [usertype] *[assigned] src
> arm-smmu-v3.c:396:25: got restricted __le64 [usertype] *
> arm-smmu-v3.c:1349:32: warning: invalid assignment: |=
> arm-smmu-v3.c:1349:32: left side has type restricted __le64
> arm-smmu-v3.c:1349:32: right side has type unsigned long
> arm-smmu-v3.c:1396:53: warning: incorrect type in argument 3 (different base types)
> arm-smmu-v3.c:1396:53: expected restricted __le64 [usertype] *dst
> arm-smmu-v3.c:1396:53: got unsigned long long [usertype] *strtab
> arm-smmu-v3.c:1424:39: warning: incorrect type in argument 1 (different base types)
> arm-smmu-v3.c:1424:39: expected unsigned long long [usertype] *[assigned] strtab
> arm-smmu-v3.c:1424:39: got restricted __le64 [usertype] *l2ptr
>
> [...]
Applied to will (for-joerg/arm-smmu/updates), thanks!
[1/1] iommu/arm-smmu-v3: Fix endianness annotations
https://git.kernel.org/will/c/376cdf66f624
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-21 18:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-18 14:18 [PATCH] iommu/arm-smmu-v3: Fix endianness annotations Jean-Philippe Brucker
2020-09-18 15:02 ` Robin Murphy
2020-09-18 15:08 ` Jean-Philippe Brucker
2020-09-21 18:17 ` Will Deacon
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).