public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Alan Hayward <Alan.Hayward@arm.com>
To: Luis Machado <luis.machado@linaro.org>
Cc: "gdb-patches\\@sourceware.org" <gdb-patches@sourceware.org>,
	nd <nd@arm.com>
Subject: Re: [PATCH] [GDB,AArch64] Fix off-by-one when calculating tag granules.
Date: Thu, 13 May 2021 10:50:40 +0000	[thread overview]
Message-ID: <158C1AAE-82C7-4A58-8C42-C36542DFAEAC@arm.com> (raw)
In-Reply-To: <20210511132026.3673157-1-luis.machado@linaro.org>



On 11 May 2021, at 14:20, Luis Machado via Gdb-patches <gdb-patches@sourceware.org<mailto:gdb-patches@sourceware.org>> wrote:

When we want to fetch tags from a memory range, the last address in that
range is not included.

There is a off-by-one error in aarch64_mte_get_tag_granules, which this
patch fixes.

gdb/ChangeLog:

YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org<mailto:luis.machado@linaro.org>>

* arch/aarch64-mte-linux.c (aarch64_mte_get_tag_granules): Don't
include the last address in the range.
---
gdb/arch/aarch64-mte-linux.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/arch/aarch64-mte-linux.c b/gdb/arch/aarch64-mte-linux.c
index 959c0247ed5..7c2ae9a7058 100644
--- a/gdb/arch/aarch64-mte-linux.c
+++ b/gdb/arch/aarch64-mte-linux.c
@@ -31,9 +31,10 @@ aarch64_mte_get_tag_granules (CORE_ADDR addr, size_t len, size_t granule_size)
 /* Start address */
 CORE_ADDR s_addr = align_down (addr, granule_size);
 /* End address */
-  CORE_ADDR e_addr = align_down (addr + len, granule_size);
+  CORE_ADDR e_addr = align_down (addr + len - 1, granule_size);

-  /* We always have at least 1 granule.  */
+  /* We always have at least 1 granule because len is non-zero at this
+     point.  */
 return 1 + (e_addr - s_addr) / granule_size;

Ok,  I’m happy with round down because we never want to read/write a partial tag

But if len is greater than zero, but less than the size of a one tag, then it returns 1. Is that correct?
Should it instead be:
 if (len < granule_size)
   return 0;

}

--
2.25.1

      parent reply	other threads:[~2021-05-13 10:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 13:20 Luis Machado
2021-05-13 10:50 ` Alan Hayward
2021-05-13 10:56   ` Luis Machado
2021-05-13 11:24     ` Alan Hayward
2021-05-13 11:50       ` Luis Machado
2021-05-13 12:59         ` Alan Hayward
2021-05-13 13:15           ` Luis Machado
2021-05-13 10:50 ` Alan Hayward [this message]

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=158C1AAE-82C7-4A58-8C42-C36542DFAEAC@arm.com \
    --to=alan.hayward@arm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@linaro.org \
    --cc=nd@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 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).