From: Alexandru Elisei <alexandru.elisei@arm.com>
To: Vladimir Murzin <vladimir.murzin@arm.com>
Cc: kvmarm@lists.linux.dev, andrew.jones@linux.dev
Subject: Re: [kvm-unit-tests PATCH] arm64: mte: Fix MTE granule mask
Date: Mon, 8 Sep 2025 12:49:01 +0100 [thread overview]
Message-ID: <aL7CrQdvNy2V7VwA@e140010.arm.com> (raw)
In-Reply-To: <20250905124129.32435-1-vladimir.murzin@arm.com>
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
>
next prev parent reply other threads:[~2025-09-08 11:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 12:41 [kvm-unit-tests PATCH] arm64: mte: Fix MTE granule mask Vladimir Murzin
2025-09-08 11:49 ` Alexandru Elisei [this message]
2025-09-08 12:09 ` Vladimir Murzin
2025-09-08 18:38 ` Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aL7CrQdvNy2V7VwA@e140010.arm.com \
--to=alexandru.elisei@arm.com \
--cc=andrew.jones@linux.dev \
--cc=kvmarm@lists.linux.dev \
--cc=vladimir.murzin@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.