From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
mark.cave-ayland@ilande.co.uk,
Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [Qemu-devel] [PATCH] memory: info mtree check mr range overflow
Date: Tue, 14 Mar 2017 16:59:10 +0200 [thread overview]
Message-ID: <20170314165824-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1489496187-624-1-git-send-email-peterx@redhat.com>
On Tue, Mar 14, 2017 at 08:56:27PM +0800, Peter Xu wrote:
> The address of memory regions might overflow when something wrong
> happened, like reported in:
>
> https://lists.gnu.org/archive/html/qemu-devel/2017-03/msg02043.html
>
> For easier debugging, let's try to detect it.
>
> Reported-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> Signed-off-by: Peter Xu <peterx@redhat.com>
I think I already commented on this.
Please use Int128 math instead of hacks around 64 bit math.
> ---
> memory.c | 21 ++++++++++++++++-----
> 1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/memory.c b/memory.c
> index 284894b..64b0a60 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -2494,6 +2494,7 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f,
> MemoryRegionListHead submr_print_queue;
> const MemoryRegion *submr;
> unsigned int i;
> + hwaddr cur_start, cur_end;
>
> if (!mr) {
> return;
> @@ -2503,6 +2504,18 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f,
> mon_printf(f, MTREE_INDENT);
> }
>
> + cur_start = base + mr->addr;
> + cur_end = cur_start + MR_SIZE(mr->size);
> +
> + /*
> + * Try to detect overflow of memory region. This should never
> + * happen normally. When it happens, we dump something to warn the
> + * user who is observing this.
> + */
> + if (cur_start < base || cur_end < cur_start) {
> + mon_printf(f, "[DETECTED OVERFLOW!] ");
> + }
> +
> if (mr->alias) {
> MemoryRegionList *ml;
> bool found = false;
> @@ -2522,8 +2535,7 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f,
> mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx
> " (prio %d, %s): alias %s @%s " TARGET_FMT_plx
> "-" TARGET_FMT_plx "%s\n",
> - base + mr->addr,
> - base + mr->addr + MR_SIZE(mr->size),
> + cur_start, cur_end,
> mr->priority,
> memory_region_type((MemoryRegion *)mr),
> memory_region_name(mr),
> @@ -2534,8 +2546,7 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f,
> } else {
> mon_printf(f,
> TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %s): %s%s\n",
> - base + mr->addr,
> - base + mr->addr + MR_SIZE(mr->size),
> + cur_start, cur_end,
> mr->priority,
> memory_region_type((MemoryRegion *)mr),
> memory_region_name(mr),
> @@ -2562,7 +2573,7 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f,
> }
>
> QTAILQ_FOREACH(ml, &submr_print_queue, queue) {
> - mtree_print_mr(mon_printf, f, ml->mr, level + 1, base + mr->addr,
> + mtree_print_mr(mon_printf, f, ml->mr, level + 1, cur_start,
> alias_print_queue);
> }
>
> --
> 2.7.4
next prev parent reply other threads:[~2017-03-14 14:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-14 12:56 [Qemu-devel] [PATCH] memory: info mtree check mr range overflow Peter Xu
2017-03-14 14:59 ` Michael S. Tsirkin [this message]
2017-03-15 1:24 ` Michael S. Tsirkin
2017-03-15 3:15 ` Peter Xu
2017-03-15 3:30 ` Michael S. Tsirkin
2017-03-15 4:04 ` Peter Xu
2017-03-15 4:23 ` Michael S. Tsirkin
2017-03-15 13:30 ` Mark Cave-Ayland
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=20170314165824-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.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).