From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Zheyu Ma <zheyuma97@gmail.com>, Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org,
"Xingtao Yao (Fujitsu)" <yaoxt.fnst@fujitsu.com>,
"Cédric Le Goater" <clg@kaod.org>,
"Andrew Jeffery" <andrew@aj.id.au>
Subject: Re: [PATCH] hw/misc/bcm2835_thermal: Handle invalid address accesses gracefully
Date: Mon, 1 Jul 2024 13:18:28 +0200 [thread overview]
Message-ID: <edf25494-1fd0-4a8c-959b-c4547da0ab23@linaro.org> (raw)
In-Reply-To: <20240630151414.2969772-1-zheyuma97@gmail.com>
Hi Zheyu,
On 30/6/24 17:14, Zheyu Ma wrote:
> This commit handles invalid address accesses gracefully in both read and write
> functions. Instead of asserting and aborting, it logs an error message and returns
> a neutral value for read operations and does nothing for write operations.
>
> Error log:
> ERROR:hw/misc/bcm2835_thermal.c:55:bcm2835_thermal_read: code should not be reached
> Bail out! ERROR:hw/misc/bcm2835_thermal.c:55:bcm2835_thermal_read: code should not be reached
> Aborted
>
> Reproducer:
> cat << EOF | qemu-system-aarch64 -display \
> none -machine accel=qtest, -m 512M -machine raspi3b -m 1G -qtest stdio
> readw 0x3f212003
Thanks for this very interesting bug report (and reproducer).
> EOF
>
> Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
> ---
> hw/misc/bcm2835_thermal.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/hw/misc/bcm2835_thermal.c b/hw/misc/bcm2835_thermal.c
> index ee7816b8a5..5c2a429d58 100644
> --- a/hw/misc/bcm2835_thermal.c
> +++ b/hw/misc/bcm2835_thermal.c
> @@ -51,8 +51,10 @@ static uint64_t bcm2835_thermal_read(void *opaque, hwaddr addr, unsigned size)
> val = FIELD_DP32(bcm2835_thermal_temp2adc(25), STAT, VALID, true);
> break;
> default:
> - /* MemoryRegionOps are aligned, so this can not happen. */
> - g_assert_not_reached();
Like Xingtao Yao mentioned, I believe the current code is correct
and shouldn't be reached.
Why is it reached? You might have uncovered a core memory bug.
Likely around access_with_adjusted_size() in system/memory.c.
I'll keep investigating, but so far it reminds me a previous
patch from Andrew, but it isn't the fix:
https://patchwork.ozlabs.org/project/qemu-devel/patch/20170630030058.28943-1-andrew@aj.id.au/
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "bcm2835_thermal_read: invalid address 0x%"
> + HWADDR_PRIx "\n", addr);
> + val = 0;
> }
> return val;
> }
next prev parent reply other threads:[~2024-07-01 11:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-30 15:14 [PATCH] hw/misc/bcm2835_thermal: Handle invalid address accesses gracefully Zheyu Ma
2024-07-01 3:29 ` Xingtao Yao (Fujitsu) via
2024-07-01 11:18 ` Philippe Mathieu-Daudé [this message]
2024-07-01 13:26 ` 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=edf25494-1fd0-4a8c-959b-c4547da0ab23@linaro.org \
--to=philmd@linaro.org \
--cc=andrew@aj.id.au \
--cc=clg@kaod.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=yaoxt.fnst@fujitsu.com \
--cc=zheyuma97@gmail.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 NNTP newsgroup(s).