From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Subject: Re: [PATCH for-8.1] accel/tcg: Avoid reading too much in load_atom_{2,4}
Date: Thu, 10 Aug 2023 17:53:19 +0200 [thread overview]
Message-ID: <de3548d1-1885-4131-f6f9-d78bb9b50a16@linaro.org> (raw)
In-Reply-To: <20230810154802.16663-1-richard.henderson@linaro.org>
On 10/8/23 17:48, Richard Henderson wrote:
> When load_atom_extract_al16_or_al8 is inexpensive, we want to use
> it early, in order to avoid the overhead of required_atomicity.
> However, we must not read past the end of the page.
>
> Reported-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> diff --git a/accel/tcg/ldst_atomicity.c.inc b/accel/tcg/ldst_atomicity.c.inc
> index e5c590a499..5d92485a49 100644
> --- a/accel/tcg/ldst_atomicity.c.inc
> +++ b/accel/tcg/ldst_atomicity.c.inc
> @@ -404,7 +404,10 @@ static uint16_t load_atom_2(CPUArchState *env, uintptr_t ra,
> return load_atomic2(pv);
> }
> if (HAVE_ATOMIC128_RO) {
> - return load_atom_extract_al16_or_al8(pv, 2);
> + intptr_t left_in_page = pi | TARGET_PAGE_MASK;
> + if (likely(left_in_page <= -16)) {
> + return load_atom_extract_al16_or_al8(pv, 2);
> + }
> }
>
> atmax = required_atomicity(env, pi, memop);
> @@ -443,7 +446,10 @@ static uint32_t load_atom_4(CPUArchState *env, uintptr_t ra,
> return load_atomic4(pv);
> }
> if (HAVE_ATOMIC128_RO) {
> - return load_atom_extract_al16_or_al8(pv, 4);
> + intptr_t left_in_page = pi | TARGET_PAGE_MASK;
> + if (likely(left_in_page <= -16)) {
> + return load_atom_extract_al16_or_al8(pv, 4);
> + }
> }
Makes sense, so to the best of my knowledge:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
next prev parent reply other threads:[~2023-08-10 15:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 15:48 [PATCH for-8.1] accel/tcg: Avoid reading too much in load_atom_{2,4} Richard Henderson
2023-08-10 15:53 ` Philippe Mathieu-Daudé [this message]
2023-08-10 15:56 ` [PATCH for-8.1] accel/tcg: Avoid reading too much in load_atom_{2, 4} Peter Maydell
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=de3548d1-1885-4131-f6f9-d78bb9b50a16@linaro.org \
--to=philmd@linaro.org \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@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 NNTP newsgroup(s).