From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Zheyu Ma <zheyuma97@gmail.com>, Paul Zimmerman <pauldzim@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] hw/usb/hcd-dwc2: Handle invalid address access in read and write functions
Date: Tue, 18 Jun 2024 16:04:57 +0200 [thread overview]
Message-ID: <ef0941df-ab08-4e1b-ade4-843a46356112@linaro.org> (raw)
In-Reply-To: <20240618135610.3109175-1-zheyuma97@gmail.com>
Cc'ing Paul.
On 18/6/24 15:56, Zheyu Ma wrote:
> This commit modifies the dwc2_hsotg_read() and dwc2_hsotg_write() functions
> to handle invalid address access gracefully. Instead of using
> g_assert_not_reached(), which causes the program to abort, the functions
> now log an error message and return a default value for reads or do
> nothing for writes.
>
> This change prevents the program from aborting and provides clear log
> messages indicating when an invalid memory address is accessed.
>
> Reproducer:
> cat << EOF | qemu-system-aarch64 -display none \
> -machine accel=qtest, -m 512M -machine raspi2b -m 1G -nodefaults \
> -usb -drive file=null-co://,if=none,format=raw,id=disk0 -device \
> usb-storage,port=1,drive=disk0 -qtest stdio
> readl 0x3f980dfb
> EOF
>
> Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
> ---
> hw/usb/hcd-dwc2.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c
> index 8cac9c0a06..b4f0652c7d 100644
> --- a/hw/usb/hcd-dwc2.c
> +++ b/hw/usb/hcd-dwc2.c
> @@ -1128,7 +1128,10 @@ static uint64_t dwc2_hsotg_read(void *ptr, hwaddr addr, unsigned size)
> val = dwc2_pcgreg_read(ptr, addr, (addr - HSOTG_REG(0xe00)) >> 2, size);
> break;
> default:
> - g_assert_not_reached();
> + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
> + __func__, addr);
> + val = 0;
> + break;
> }
>
> return val;
> @@ -1160,7 +1163,9 @@ static void dwc2_hsotg_write(void *ptr, hwaddr addr, uint64_t val,
> dwc2_pcgreg_write(ptr, addr, (addr - HSOTG_REG(0xe00)) >> 2, val, size);
> break;
> default:
> - g_assert_not_reached();
> + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
> + __func__, addr);
> + break;
> }
> }
>
next prev parent reply other threads:[~2024-06-18 14:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 13:56 [PATCH] hw/usb/hcd-dwc2: Handle invalid address access in read and write functions Zheyu Ma
2024-06-18 14:04 ` Philippe Mathieu-Daudé [this message]
2024-06-18 18:58 ` Paul Zimmerman
2024-06-18 20:37 ` Philippe Mathieu-Daudé
2024-06-18 21:32 ` Paul Zimmerman
2024-06-20 10:14 ` 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=ef0941df-ab08-4e1b-ade4-843a46356112@linaro.org \
--to=philmd@linaro.org \
--cc=pauldzim@gmail.com \
--cc=qemu-devel@nongnu.org \
--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).