[PATCH] iommu/ipmmu-vmsa: Add missing 'U' in IMTTLBR0_TTBR_MASK for shifted constant

Oleksandr Tyshchenko posted 1 patch 9 months, 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20230704203032.4062921-1-olekstysh@gmail.com
xen/drivers/passthrough/arm/ipmmu-vmsa.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] iommu/ipmmu-vmsa: Add missing 'U' in IMTTLBR0_TTBR_MASK for shifted constant
Posted by Oleksandr Tyshchenko 9 months, 4 weeks ago
From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

With enabling both CONFIG_UBSAN and CONFIG_IPMMU_VMSA I have got the following
splat when an IOMMU driver tried to setup page tables:

(XEN) ipmmu: /soc/iommu@e67b0000: d1: Set IPMMU context 1 (pgd 0x77fe90000)
(XEN) ================================================================================
(XEN) UBSAN: Undefined behaviour in drivers/passthrough/arm/ipmmu-vmsa.c:558:51
(XEN) left shift of 1048575 by 12 places cannot be represented in type 'int'
(XEN) Xen WARN at common/ubsan/ubsan.c:172
(XEN) ---[ Xen-4.18-unstable  arm64  debug=y ubsan=y  Tainted:      S ]----
...

This points to shifted constant in IMTTLBR0_TTBR_MASK. Fix that by adding
missing 'U' to it.

This should also address MISRA Rule 7.2:

A "u" or "U" suffix shall be applied to all integer constants that
are represented in an unsigned type.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
---
 xen/drivers/passthrough/arm/ipmmu-vmsa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
index 24b9e09a6b..0ccfa53255 100644
--- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c
+++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
@@ -201,7 +201,7 @@ static DEFINE_SPINLOCK(ipmmu_devices_lock);
 #define IMTTBCR_TSZ0_SHIFT             0
 
 #define IMTTLBR0              0x0010
-#define IMTTLBR0_TTBR_MASK    (0xfffff << 12)
+#define IMTTLBR0_TTBR_MASK    (0xfffffU << 12)
 #define IMTTUBR0              0x0014
 #define IMTTUBR0_TTBR_MASK    (0xff << 0)
 
-- 
2.34.1
Re: [PATCH] iommu/ipmmu-vmsa: Add missing 'U' in IMTTLBR0_TTBR_MASK for shifted constant
Posted by Stefano Stabellini 9 months, 3 weeks ago
On Tue, 4 Jul 2023, Oleksandr Tyshchenko wrote:
> From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> 
> With enabling both CONFIG_UBSAN and CONFIG_IPMMU_VMSA I have got the following
> splat when an IOMMU driver tried to setup page tables:
> 
> (XEN) ipmmu: /soc/iommu@e67b0000: d1: Set IPMMU context 1 (pgd 0x77fe90000)
> (XEN) ================================================================================
> (XEN) UBSAN: Undefined behaviour in drivers/passthrough/arm/ipmmu-vmsa.c:558:51
> (XEN) left shift of 1048575 by 12 places cannot be represented in type 'int'
> (XEN) Xen WARN at common/ubsan/ubsan.c:172
> (XEN) ---[ Xen-4.18-unstable  arm64  debug=y ubsan=y  Tainted:      S ]----
> ...
> 
> This points to shifted constant in IMTTLBR0_TTBR_MASK. Fix that by adding
> missing 'U' to it.
> 
> This should also address MISRA Rule 7.2:
> 
> A "u" or "U" suffix shall be applied to all integer constants that
> are represented in an unsigned type.
> 
> Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

Acked-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>  xen/drivers/passthrough/arm/ipmmu-vmsa.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
> index 24b9e09a6b..0ccfa53255 100644
> --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c
> +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
> @@ -201,7 +201,7 @@ static DEFINE_SPINLOCK(ipmmu_devices_lock);
>  #define IMTTBCR_TSZ0_SHIFT             0
>  
>  #define IMTTLBR0              0x0010
> -#define IMTTLBR0_TTBR_MASK    (0xfffff << 12)
> +#define IMTTLBR0_TTBR_MASK    (0xfffffU << 12)
>  #define IMTTUBR0              0x0014
>  #define IMTTUBR0_TTBR_MASK    (0xff << 0)
>  
> -- 
> 2.34.1
>
Re: [PATCH] iommu/ipmmu-vmsa: Add missing 'U' in IMTTLBR0_TTBR_MASK for shifted constant
Posted by Julien Grall 9 months, 2 weeks ago
Hi,

On 05/07/2023 23:55, Stefano Stabellini wrote:
> On Tue, 4 Jul 2023, Oleksandr Tyshchenko wrote:
>> From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>>
>> With enabling both CONFIG_UBSAN and CONFIG_IPMMU_VMSA I have got the following
>> splat when an IOMMU driver tried to setup page tables:
>>
>> (XEN) ipmmu: /soc/iommu@e67b0000: d1: Set IPMMU context 1 (pgd 0x77fe90000)
>> (XEN) ================================================================================
>> (XEN) UBSAN: Undefined behaviour in drivers/passthrough/arm/ipmmu-vmsa.c:558:51
>> (XEN) left shift of 1048575 by 12 places cannot be represented in type 'int'
>> (XEN) Xen WARN at common/ubsan/ubsan.c:172
>> (XEN) ---[ Xen-4.18-unstable  arm64  debug=y ubsan=y  Tainted:      S ]----
>> ...
>>
>> This points to shifted constant in IMTTLBR0_TTBR_MASK. Fix that by adding
>> missing 'U' to it.
>>
>> This should also address MISRA Rule 7.2:
>>
>> A "u" or "U" suffix shall be applied to all integer constants that
>> are represented in an unsigned type.
>>
>> Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> 
> Acked-by: Stefano Stabellini <sstabellini@kernel.org>

This is now committed.

Cheers,

-- 
Julien Grall