diff mbox series

[v2,1/4] gdb: aarch64: Remove MTE address checking from get_memtag

Message ID 20240328224850.2785280-2-gustavo.romero@linaro.org
State Superseded
Headers show
Series Add another way to check for MTE-tagged addresses on remote targets | expand

Commit Message

Gustavo Romero March 28, 2024, 10:48 p.m. UTC
This commit removes aarch64_linux_tagged_address_p from
aarch64_linux_get_memtag. aarch64_linux_tagged_address_p checks if an
address is tagged (MTE) or not.

The check is redundant because aarch64_linux_get_memtag is always called
from the upper layers (i.e. from printcmd.c via gdbarch hook
gdbarch_get_memtag) after either gdbarch_tagged_address_p (that already
points to aarch64_linux_tagged_address_p) has been called or
after should_validate_memtags (that calls gdbarch_tagged_address_p at
the end) has been called, so the address is already checked. Hence:

a) in print_command_1, aarch64_linux_get_memtag (via gdbarch_get_memtag
hook) is called but only after should_validate_memtags, which calls
gdbarch_tagged_address_p;

b) in do_examine, aarch64_linux_get_memtag is also called only after
gdbarch_tagged_address_p is directly called;

c) in memory_tag_check_command, gdbarch_get_memtag is called -- tags
matching or not -- after the initial check via direct call to
gdbarch_tagged_address_p;

d) in memory_tag_print_tag_command, address is checked directly via
gdbarch_tagged_address_p before gdbarch_get_memtag is called.

Also, because after this change the address checking only happens at the
upper layer it now allows the address checking to be specialized easily
per target, via a target hook.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
---
 gdb/aarch64-linux-tdep.c | 4 ----
 1 file changed, 4 deletions(-)

Comments

Thiago Jung Bauermann March 30, 2024, 12:37 a.m. UTC | #1
Gustavo Romero <gustavo.romero@linaro.org> writes:

> This commit removes aarch64_linux_tagged_address_p from
> aarch64_linux_get_memtag. aarch64_linux_tagged_address_p checks if an
> address is tagged (MTE) or not.
>
> The check is redundant because aarch64_linux_get_memtag is always called
> from the upper layers (i.e. from printcmd.c via gdbarch hook
> gdbarch_get_memtag) after either gdbarch_tagged_address_p (that already
> points to aarch64_linux_tagged_address_p) has been called or
> after should_validate_memtags (that calls gdbarch_tagged_address_p at
> the end) has been called, so the address is already checked. Hence:
>
> a) in print_command_1, aarch64_linux_get_memtag (via gdbarch_get_memtag
> hook) is called but only after should_validate_memtags, which calls
> gdbarch_tagged_address_p;
>
> b) in do_examine, aarch64_linux_get_memtag is also called only after
> gdbarch_tagged_address_p is directly called;
>
> c) in memory_tag_check_command, gdbarch_get_memtag is called -- tags
> matching or not -- after the initial check via direct call to
> gdbarch_tagged_address_p;
>
> d) in memory_tag_print_tag_command, address is checked directly via
> gdbarch_tagged_address_p before gdbarch_get_memtag is called.

In cases c) and d), gdbarch_get_memtag gets called even if
gdbarch_tagged_address_p returns false, so won't this commit change the
behaviour of those functions in that case? I don't know enough about MTE
to be sure.

--
Thiago
Thiago Jung Bauermann March 30, 2024, 12:55 a.m. UTC | #2
Thiago Jung Bauermann <thiago.bauermann@linaro.org> writes:

> Gustavo Romero <gustavo.romero@linaro.org> writes:
>
>> This commit removes aarch64_linux_tagged_address_p from
>> aarch64_linux_get_memtag. aarch64_linux_tagged_address_p checks if an
>> address is tagged (MTE) or not.
>>
>> The check is redundant because aarch64_linux_get_memtag is always called
>> from the upper layers (i.e. from printcmd.c via gdbarch hook
>> gdbarch_get_memtag) after either gdbarch_tagged_address_p (that already
>> points to aarch64_linux_tagged_address_p) has been called or
>> after should_validate_memtags (that calls gdbarch_tagged_address_p at
>> the end) has been called, so the address is already checked. Hence:
>>
>> a) in print_command_1, aarch64_linux_get_memtag (via gdbarch_get_memtag
>> hook) is called but only after should_validate_memtags, which calls
>> gdbarch_tagged_address_p;
>>
>> b) in do_examine, aarch64_linux_get_memtag is also called only after
>> gdbarch_tagged_address_p is directly called;
>>
>> c) in memory_tag_check_command, gdbarch_get_memtag is called -- tags
>> matching or not -- after the initial check via direct call to
>> gdbarch_tagged_address_p;
>>
>> d) in memory_tag_print_tag_command, address is checked directly via
>> gdbarch_tagged_address_p before gdbarch_get_memtag is called.
>
> In cases c) and d), gdbarch_get_memtag gets called even if
> gdbarch_tagged_address_p returns false, so won't this commit change the
> behaviour of those functions in that case? I don't know enough about MTE
> to be sure.

I just realised that in cases c) and d) an error will be thrown by
show_addr_not_tagged if gdbarch_tagged_address_p returns false, so
gdbarch_get_memtag doesn't get called in that case and my concern isn't
valid. Sorry about that.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>

--
Thiago
Gustavo Romero April 4, 2024, 5:15 a.m. UTC | #3
Hi Thiago,

On 3/29/24 9:55 PM, Thiago Jung Bauermann wrote:
> Thiago Jung Bauermann <thiago.bauermann@linaro.org> writes:
> 
>> Gustavo Romero <gustavo.romero@linaro.org> writes:
>>
>>> This commit removes aarch64_linux_tagged_address_p from
>>> aarch64_linux_get_memtag. aarch64_linux_tagged_address_p checks if an
>>> address is tagged (MTE) or not.
>>>
>>> The check is redundant because aarch64_linux_get_memtag is always called
>>> from the upper layers (i.e. from printcmd.c via gdbarch hook
>>> gdbarch_get_memtag) after either gdbarch_tagged_address_p (that already
>>> points to aarch64_linux_tagged_address_p) has been called or
>>> after should_validate_memtags (that calls gdbarch_tagged_address_p at
>>> the end) has been called, so the address is already checked. Hence:
>>>
>>> a) in print_command_1, aarch64_linux_get_memtag (via gdbarch_get_memtag
>>> hook) is called but only after should_validate_memtags, which calls
>>> gdbarch_tagged_address_p;
>>>
>>> b) in do_examine, aarch64_linux_get_memtag is also called only after
>>> gdbarch_tagged_address_p is directly called;
>>>
>>> c) in memory_tag_check_command, gdbarch_get_memtag is called -- tags
>>> matching or not -- after the initial check via direct call to
>>> gdbarch_tagged_address_p;
>>>
>>> d) in memory_tag_print_tag_command, address is checked directly via
>>> gdbarch_tagged_address_p before gdbarch_get_memtag is called.
>>
>> In cases c) and d), gdbarch_get_memtag gets called even if
>> gdbarch_tagged_address_p returns false, so won't this commit change the
>> behaviour of those functions in that case? I don't know enough about MTE
>> to be sure.
> 
> I just realised that in cases c) and d) an error will be thrown by
> show_addr_not_tagged if gdbarch_tagged_address_p returns false, so
> gdbarch_get_memtag doesn't get called in that case and my concern isn't
> valid. Sorry about that.

Yeah. No worries, I also missed that show_addr_not_tagged throws an error
the first time I read this part, it looked like just printing function :)


> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>

Thanks for the review.


Cheers,
Gustavo
diff mbox series

Patch

diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 0b9784f38e4..50055ac3f48 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -2575,10 +2575,6 @@  aarch64_linux_get_memtag (struct gdbarch *gdbarch, struct value *address,
     tag = aarch64_mte_get_ltag (addr);
   else
     {
-      /* Make sure we are dealing with a tagged address to begin with.  */
-      if (!aarch64_linux_tagged_address_p (gdbarch, address))
-	return nullptr;
-
       /* Remove the top byte.  */
       addr = gdbarch_remove_non_address_bits (gdbarch, addr);
       std::optional<CORE_ADDR> atag = aarch64_mte_get_atag (addr);