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 11:24:20 +0000 [thread overview]
Message-ID: <9FB274EC-4BA6-4A40-A68F-4D56A72B6A05@arm.com> (raw)
In-Reply-To: <7826d1d2-dd09-4c0c-ae3f-e34a046160ba@linaro.org>
On 13 May 2021, at 11:56, Luis Machado <luis.machado@linaro.org<mailto:luis.machado@linaro.org>> wrote:
On 5/13/21 7:50 AM, Alan Hayward wrote:
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?
The range is specified by [address, address + len). If len is non-zero, we will always have a non-empty range and therefore will always have tag granules.
Should it instead be:
if (len < granule_size)
return 0;
We want to know how many tag granules exist in a particular range. We only get 0 granules if the range is empty.
Assuming addr is aligned, then calculating length -> return value
3 * granulesize -> 3
2.5 * granulesize -> 2
2 * granulesize -> 2
1.5 * granulesize -> 1
1 * granulesize -> 1
0.5 * granulesize -> 1. - this doesn’t match the others.
0 -> 0
?
Alan.
next prev parent reply other threads:[~2021-05-13 11:24 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 [this message]
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
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=9FB274EC-4BA6-4A40-A68F-4D56A72B6A05@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).