public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Luis Machado <luis.machado@linaro.org>, gdb-patches@sourceware.org
Cc: david.spickett@linaro.org, catalin.marinas@arm.com,
	John Baldwin <jhb@FreeBSD.org>
Subject: Re: [PATCH,v2] [AArch64] MTE corefile support
Date: Mon, 31 May 2021 10:49:53 -0400	[thread overview]
Message-ID: <87af0c4e-7a26-ecde-dc4e-95f96ec2ccc8@polymtl.ca> (raw)
In-Reply-To: <4ae84e2c-f0c4-bcac-1e5d-b9b34d8521db@linaro.org>

On 2021-05-31 10:12 a.m., Luis Machado wrote:
>>> @@ -71,4 +72,18 @@ extern CORE_ADDR aarch64_mte_set_ltag (CORE_ADDR address, CORE_ADDR tag);
>>>      It is always possible to get the logical tag.  */
>>>   extern CORE_ADDR aarch64_mte_get_ltag (CORE_ADDR address);
>>>   +/* MTE-specific NT_MEMTAG header.  */
>>> +struct tag_dump_mte
>>> +{
>>> +  /* Size of the tag granule in bytes.  */
>>> +  uint16_t granule_byte_size;
>>> +  /* Size of the tag in bits.  */
>>> +  uint16_t tag_bit_size;
>>> +  /* Reserved field for the future.  */
>>> +  uint16_t __unused;
>>> +};
>>
>> This struct is unused.
>>
> 
> I'm inclined to leave that as documentation instead, so it is clear what the header sizes are referring to.

The thing is that somebody reading the code in the .c seeing the
arbitrary sizeofs  will note have a clue to go look at
arch/aarch64-mte-linux.h for explanations.  So another option would be
to write it as a comment near the code.  Something like:

  /* The header follows the following format:

     struct
     {
       /* Size of the tag granule in bytes.  */
       uint16_t granule_byte_size;
       /* Size of the tag in bits.  */
       uint16_t tag_bit_size;
       /* Reserved field for the future.  */
       uint16_t __unused;
     };
   */

Another option would be to have the structure and refer to its fields in
sizeof:

    store_unsigned_integer (buf, sizeof (tag_dump_mte::granule_byte_size),
			    byte_order, AARCH64_MTE_GRANULE_SIZE);

This has the advantage that the structure can still be present as documentation
in a central place, the reader of that code will naturally be pointed to
it if they need more information, and since the structure type is
actually used, it's fine to keep it there.

>> It's a little strange, NT_MEMTAG_HEADER_SIZE is defined at two places,
>> linux-tdep.h and here.  If this is really OS-independent, there should
>> probably be just one definition, in an OS-independent header file.  Not
>> sure where though...
>>
> 
> Right. I ran into this as well. I thought about this a bit, and I guess the simplest way is to have a new memtag.h header file and define it there.
> 
> It would be generic enough and other OS' would be able to include it as well. And it would work for Core files.

Sounds good.

>> The code of this function approximately up to here is really similar to
>> the code in corelow.c.  Is there a change there could be a single
>> implementation of it, that takes a callback?  Like
>>
>>    for_each_matching_memtag_note_section_matching_address
>>      (CORE_ADDR address, gdb::function_view<...> callback)
>>
>> except with a better name.
>>
> 
> I'm aware of that. I was hoping to leave this cleanup for a later stage.
> 
> A complicating factor here is that we need to traverse the NT_MEMTAG notes for two slightly different reasons.
> 
> The first is to decide if an address (no length specified) falls within one of the NT_MEMTAG entries, in which case we just return true/false;
> 
> The second is to actually fetch the tags the user has requested (via address + length). This may potentially span multiple NT_MEMTAG notes, so the callback may be invoked multiple times.
> 
> It should be possible to refactor the code to invoke callbacks, but we would need to have two callbacks (one for corelow and another for linux-tdep). The one for linux-tdep just needs to check if a note exists for a particular range, so it would be an useless callback in my opinion.
> 
> With that said, I reworked things and moved the common code to a new function. This new function goes through the notes and returns whenever we hit a note that contains the address we're looking for. Then we have a chance to do some processing, return or continue going through notes.
> 
> I think this simplifies things.

Ok, I'll see in the new version.

>> This struct is used once, in aarch64_linux_decode_memtag_note, but where
>> it's used it's not very useful, it could very well be replaced with 3
>> local variables, and then it could be removed.  I'm guessing that an
>> earlier version of this patch used this struct to read the data contents
>> directly from the buffer, but that didn't work with different byte
>> orders?
>>
> 
> Like the MTE NT_MEMTAG header, this is mostly for documentation purposes. We don't have a lot of use for the header structs right now, but may have more uses for them in the future. We may want to pass the header around and access it in a simpler way than just using local variables and skipping individual sizes.
> 
> This is because we're using a packed struct and we don't want to run into issues with alignments and padding inserted by the compilers, or having to handle endianness differences at the corelow.c level.

Yep.

> I'll do the same as I've done with the NT_MEMTAG_MTE_HEADER_SIZE case and will document this struct alongside the definition of NT_MEMTAG_HEADER_SIZE (in a new generic file, memtag.h).

As I suggested above, I think having the structure and referring to its
fields in sizeofs would be a nice solution.

Simon

  reply	other threads:[~2021-05-31 14:50 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 20:20 [PATCH] " Luis Machado
2021-05-19 10:01 ` David Spickett
2021-05-19 11:11   ` Luis Machado
2021-05-19 12:13 ` Eli Zaretskii
2021-05-21 15:12 ` Alan Hayward
2021-05-21 15:30   ` Luis Machado
2021-05-21 17:20     ` John Baldwin
2021-05-24 13:41       ` Luis Machado
2021-05-24  8:07     ` Alan Hayward
2021-05-24 12:45       ` Luis Machado
2021-05-26 14:08 ` [PATCH,v2] " Luis Machado
2021-05-29  3:14   ` Simon Marchi
2021-05-31 14:12     ` Luis Machado
2021-05-31 14:49       ` Simon Marchi [this message]
2021-05-31 14:56         ` Luis Machado
2021-05-31 14:15   ` [PATCH,v3][AArch64] " Luis Machado
2021-05-31 16:44 ` [PATCH,v4][AArch64] " Luis Machado
2021-06-01 17:45 ` [PATCH,v5][AArch64] " Luis Machado
2021-06-15 14:10   ` [Ping][PATCH,v5][AArch64] " Luis Machado
2021-06-24 14:00   ` [PATCH,v5][AArch64] " Alan Hayward
2021-06-24 14:37     ` Luis Machado
2021-06-24 15:18       ` Alan Hayward
2021-07-01 13:50   ` [PING][PATCH,v5][AArch64] " Luis Machado
2021-07-11 14:22     ` Joel Brobecker
2021-07-14 13:07       ` Catalin Marinas
2021-07-29  2:26         ` Simon Marchi
2021-07-29 16:03           ` John Baldwin
2021-07-29 18:10           ` Catalin Marinas
2021-07-29 18:20             ` Simon Marchi
2021-08-01 15:44               ` Joel Brobecker
2021-08-02 12:06                 ` Luis Machado
2021-07-19 19:05   ` Luis Machado
2021-07-27 16:10   ` Luis Machado
2022-03-31 14:03 [AArch64] " Luis Machado
2022-04-21 15:20 ` [PATCH, v2] " Luis Machado
2022-04-21 15:52   ` Eli Zaretskii
2022-04-22  8:12     ` Luis Machado
2022-04-22  8:30       ` Eli Zaretskii
2022-04-22  8:37         ` Luis Machado
2022-04-22  8:43           ` Eli Zaretskii
2022-04-22  8:44             ` Luis Machado

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=87af0c4e-7a26-ecde-dc4e-95f96ec2ccc8@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=catalin.marinas@arm.com \
    --cc=david.spickett@linaro.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.org \
    --cc=luis.machado@linaro.org \
    /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 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 read-only IMAP folder(s) and NNTP newsgroup(s).