* [kvm-unit-tests PATCH] arm64: mte: Fix MTE granule mask
@ 2025-09-05 12:41 Vladimir Murzin
2025-09-08 11:49 ` Alexandru Elisei
2025-09-08 18:38 ` Andrew Jones
0 siblings, 2 replies; 4+ messages in thread
From: Vladimir Murzin @ 2025-09-05 12:41 UTC (permalink / raw)
To: kvmarm; +Cc: alexandru.elisei, andrew.jones
So it generates correct mask when used together with MTE_TAG_SHIFT
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
---
arm/mte.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arm/mte.c b/arm/mte.c
index 95d58aaa..a1bed8a7 100644
--- a/arm/mte.c
+++ b/arm/mte.c
@@ -26,7 +26,7 @@
#define MTE_TCF_ASYMM 0b11
#define MTE_GRANULE_SIZE UL(16)
-#define MTE_GRANULE_MASK (~(MTE_GRANULE_SIZE - 1))
+#define MTE_GRANULE_MASK (MTE_GRANULE_SIZE - 1)
#define MTE_TAG_SHIFT 56
#define untagged(p) \
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [kvm-unit-tests PATCH] arm64: mte: Fix MTE granule mask
2025-09-05 12:41 [kvm-unit-tests PATCH] arm64: mte: Fix MTE granule mask Vladimir Murzin
@ 2025-09-08 11:49 ` Alexandru Elisei
2025-09-08 12:09 ` Vladimir Murzin
2025-09-08 18:38 ` Andrew Jones
1 sibling, 1 reply; 4+ messages in thread
From: Alexandru Elisei @ 2025-09-08 11:49 UTC (permalink / raw)
To: Vladimir Murzin; +Cc: kvmarm, andrew.jones
Hi Vladimir,
On Fri, Sep 05, 2025 at 01:41:29PM +0100, Vladimir Murzin wrote:
> So it generates correct mask when used together with MTE_TAG_SHIFT
>
> Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
> ---
> arm/mte.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arm/mte.c b/arm/mte.c
> index 95d58aaa..a1bed8a7 100644
> --- a/arm/mte.c
> +++ b/arm/mte.c
> @@ -26,7 +26,7 @@
> #define MTE_TCF_ASYMM 0b11
>
> #define MTE_GRANULE_SIZE UL(16)
> -#define MTE_GRANULE_MASK (~(MTE_GRANULE_SIZE - 1))
> +#define MTE_GRANULE_MASK (MTE_GRANULE_SIZE - 1)
And this is how it's used:
#define untagged(p) \
({ \
unsigned long __in = (unsigned long)(p); \
typeof(p) __out = (typeof(p))(__in & ~(MTE_GRANULE_MASK << MTE_TAG_SHIFT)); \
I'm going to walk through how MTE_GRANULE_MASK is used, just to make sure I got
things right this time.
Without this change:
MTE_GRANULE_MASK = ~(0..01..1) = 1..10..0 -> LSB 4 bits are zero
~(MTE_GRANULE_MASK << MTE_TAG_SHIFT) = ~(1..10..0) = 0..01..1 -> bits 63:60 are
zero, and what is masked is actually the PAC field, not the logical tag.
With this patch:
MTE_GRANULE_MASK = 0..01..1 -> LSB 4 bits are 1
~(MTE_GRANULE_MASK << MTE_TAG_SHIFT) = ~(0..01..10..0) = 1..10..01..1 -> bits
59:56 are 0, and the logical tag is masked, which is what we want, so:
Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com>
Also curious, I remember running the tests and I didn't see an error, how did
you catch this?
Thanks,
Alex
> #define MTE_TAG_SHIFT 56
>
> #define untagged(p) \
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [kvm-unit-tests PATCH] arm64: mte: Fix MTE granule mask
2025-09-08 11:49 ` Alexandru Elisei
@ 2025-09-08 12:09 ` Vladimir Murzin
0 siblings, 0 replies; 4+ messages in thread
From: Vladimir Murzin @ 2025-09-08 12:09 UTC (permalink / raw)
To: Alexandru Elisei; +Cc: kvmarm, andrew.jones
Hi Alexandru,
On 9/8/25 12:49, Alexandru Elisei wrote:
> Hi Vladimir,
>
> On Fri, Sep 05, 2025 at 01:41:29PM +0100, Vladimir Murzin wrote:
>> So it generates correct mask when used together with MTE_TAG_SHIFT
>>
>> Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
>> ---
>> arm/mte.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arm/mte.c b/arm/mte.c
>> index 95d58aaa..a1bed8a7 100644
>> --- a/arm/mte.c
>> +++ b/arm/mte.c
>> @@ -26,7 +26,7 @@
>> #define MTE_TCF_ASYMM 0b11
>>
>> #define MTE_GRANULE_SIZE UL(16)
>> -#define MTE_GRANULE_MASK (~(MTE_GRANULE_SIZE - 1))
>> +#define MTE_GRANULE_MASK (MTE_GRANULE_SIZE - 1)
> And this is how it's used:
>
> #define untagged(p) \
> ({ \
> unsigned long __in = (unsigned long)(p); \
> typeof(p) __out = (typeof(p))(__in & ~(MTE_GRANULE_MASK << MTE_TAG_SHIFT)); \
>
> I'm going to walk through how MTE_GRANULE_MASK is used, just to make sure I got
> things right this time.
>
> Without this change:
>
> MTE_GRANULE_MASK = ~(0..01..1) = 1..10..0 -> LSB 4 bits are zero
> ~(MTE_GRANULE_MASK << MTE_TAG_SHIFT) = ~(1..10..0) = 0..01..1 -> bits 63:60 are
> zero, and what is masked is actually the PAC field, not the logical tag.
>
> With this patch:
>
> MTE_GRANULE_MASK = 0..01..1 -> LSB 4 bits are 1
> ~(MTE_GRANULE_MASK << MTE_TAG_SHIFT) = ~(0..01..10..0) = 1..10..01..1 -> bits
> 59:56 are 0, and the logical tag is masked, which is what we want, so:
>
> Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com>
>
All correct, before the change we generate mask 0x0fff_ffff_ffff_ffff yet after
the change it becomes 0xf0ff_ffff_ffff_ffff
> Also curious, I remember running the tests and I didn't see an error, how did
> you catch this?
By eyes :D
Thanks
Vladimir
>
> Thanks,
> Alex
>
>> #define MTE_TAG_SHIFT 56
>>
>> #define untagged(p) \
>> --
>> 2.34.1
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [kvm-unit-tests PATCH] arm64: mte: Fix MTE granule mask
2025-09-05 12:41 [kvm-unit-tests PATCH] arm64: mte: Fix MTE granule mask Vladimir Murzin
2025-09-08 11:49 ` Alexandru Elisei
@ 2025-09-08 18:38 ` Andrew Jones
1 sibling, 0 replies; 4+ messages in thread
From: Andrew Jones @ 2025-09-08 18:38 UTC (permalink / raw)
To: Vladimir Murzin; +Cc: kvmarm, alexandru.elisei
On Fri, Sep 05, 2025 at 01:41:29PM +0100, Vladimir Murzin wrote:
> So it generates correct mask when used together with MTE_TAG_SHIFT
>
> Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
> ---
> arm/mte.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arm/mte.c b/arm/mte.c
> index 95d58aaa..a1bed8a7 100644
> --- a/arm/mte.c
> +++ b/arm/mte.c
> @@ -26,7 +26,7 @@
> #define MTE_TCF_ASYMM 0b11
>
> #define MTE_GRANULE_SIZE UL(16)
> -#define MTE_GRANULE_MASK (~(MTE_GRANULE_SIZE - 1))
> +#define MTE_GRANULE_MASK (MTE_GRANULE_SIZE - 1)
> #define MTE_TAG_SHIFT 56
>
> #define untagged(p) \
> --
> 2.34.1
>
Merged.
Thanks,
drew
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-08 18:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-05 12:41 [kvm-unit-tests PATCH] arm64: mte: Fix MTE granule mask Vladimir Murzin
2025-09-08 11:49 ` Alexandru Elisei
2025-09-08 12:09 ` Vladimir Murzin
2025-09-08 18:38 ` Andrew Jones
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.