From: Marcel Apfelbaum <marcel.a@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Jan Kiszka" <jan.kiszka@siemens.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Anthony Liguori" <anthony@codemonkey.ws>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>,
"Richard Henderson" <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH] exec: fix regression by making system-memory region UINT64_MAX size
Date: Mon, 04 Nov 2013 11:33:56 +0200 [thread overview]
Message-ID: <1383557636.2264.8.camel@localhost.localdomain> (raw)
In-Reply-To: <20131104061814.GA3324@redhat.com>
On Mon, 2013-11-04 at 08:18 +0200, Michael S. Tsirkin wrote:
> On Sun, Nov 03, 2013 at 09:26:06PM +0000, Peter Maydell wrote:
> > On 3 November 2013 20:48, Marcel Apfelbaum <marcel.a@redhat.com> wrote:
> > > The problem appears when a root memory region within an
> > > address space with size < UINT64_MAX has overlapping children
> > > with the same size. If the size of the root memory region is UINT64_MAX
> > > everyting is ok.
> > >
> > > Solved the regression by making the system-memory region
> > > of size UINT64_MAX instead of INT64_MAX.
> > >
> > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> > > ---
> > > In the mean time I am investigating why the
> > > root memory region has to be UINT64_MAX size in order
> > > to have overlapping children
> >
> > > system_memory = g_malloc(sizeof(*system_memory));
> > > - memory_region_init(system_memory, NULL, "system", INT64_MAX);
> > > + memory_region_init(system_memory, NULL, "system", UINT64_MAX);
> > > address_space_init(&address_space_memory, system_memory, "memory");
> >
> > As you say above we should investigate why this caused a
> > problem, but I was surprised the system memory space isn't
> > already maximum size. It turns out that that change was
> > introduced in commit 8417cebf in an attempt to avoid overflow
> > issues by sticking to signed 64 bit arithmetic. This approach was
> > subsequently ditched in favour of using proper 128 bit arithmetic
> > in commit 08dafab4, but we never changed the init call for
> > the system memory back to UINT64_MAX. So I think this is
> > a good change in itself.
> >
> > -- PMM
>
> I think I debugged it.
>
> So this patch seems to help simply because we only have
> sanity checking asserts in the subpage path. UINT64_MAX will make
> the region a number of full pages and avoid
> hitting the checks.
>
>
> I think I see what the issue is: exec.c
> assumes that TARGET_PHYS_ADDR_SPACE_BITS is enough
> to render any section in system memory:
> number of page table levels is calculated from that:
>
> #define P_L2_LEVELS \
> (((TARGET_PHYS_ADDR_SPACE_BITS - TARGET_PAGE_BITS - 1) / L2_BITS) + 1)
>
> any other bits are simply ignored:
>
> for (i = P_L2_LEVELS - 1; i >= 0 && !lp.is_leaf; i--) {
> if (lp.ptr == PHYS_MAP_NODE_NIL) {
> return §ions[PHYS_SECTION_UNASSIGNED];
> }
> p = nodes[lp.ptr];
> lp = p[(index >> (i * L2_BITS)) & (L2_SIZE - 1)];
> }
>
> so mask by L2_SIZE - 1 means that each round looks at L2_BITS bits,
> and there are at most P_L2_LEVELS.
>
> Any other bits are simply ignored.
Michael, thanks for helping to debug this issue.
Let me see if I got it right:
If the system memory size is INT64_MAX (0x7fffffffffffffff), the address of the
last page (0x7ffffffffffff) has more bits (55) that TARGET_PHYS_ADDR_SPACE_BITS (52)
and cannot be correctly mapped into page levels?
Thanks,
Marcel
> This is very wrong and can break in a number of other ways,
> for example I think we will also hit this assert
> if we have a non aligned 64 bit BAR of a PCI device.
>
> I think the fastest solution is to just limit
> system memory size of TARGET_PAGE_BITS.
> I sent a patch like this.
>
>
>
next prev parent reply other threads:[~2013-11-04 9:36 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-03 20:48 [Qemu-devel] [PATCH] exec: fix regression by making system-memory region UINT64_MAX size Marcel Apfelbaum
2013-11-03 21:26 ` Peter Maydell
2013-11-04 6:18 ` Michael S. Tsirkin
2013-11-04 9:33 ` Marcel Apfelbaum [this message]
2013-11-04 9:59 ` Michael S. Tsirkin
2013-11-07 20:27 ` Jordan Justen
2013-11-07 20:44 ` Marcel Apfelbaum
2013-11-07 21:12 ` Laszlo Ersek
2013-11-07 21:21 ` [Qemu-devel] [edk2] " Paolo Bonzini
2013-11-07 21:32 ` Laszlo Ersek
2013-11-07 21:24 ` [Qemu-devel] " Marcel Apfelbaum
2013-11-07 21:31 ` Paolo Bonzini
2013-11-07 21:38 ` Marcel Apfelbaum
2013-11-07 21:51 ` Peter Maydell
2013-11-07 22:06 ` Marcel Apfelbaum
2013-11-08 8:05 ` Paolo Bonzini
2013-11-08 10:44 ` Peter Maydell
2013-11-08 11:00 ` Paolo Bonzini
2013-11-08 15:16 ` Marcel Apfelbaum
2013-11-08 15:08 ` Marcel Apfelbaum
2013-11-08 16:12 ` Paolo Bonzini
2013-11-08 16:19 ` Marcel Apfelbaum
2013-11-07 21:48 ` Laszlo Ersek
2013-11-07 22:09 ` Marcel Apfelbaum
2013-11-07 22:23 ` [Qemu-devel] [PATCH 0/2] " Laszlo Ersek
2013-11-07 22:23 ` [Qemu-devel] [PATCH 1/2] i386/pc: propagate flash size from pc_system_flash_init() to pc_init1() Laszlo Ersek
2013-11-08 6:09 ` Jordan Justen
2013-11-08 15:07 ` Laszlo Ersek
2013-11-08 15:16 ` Peter Maydell
2013-11-08 15:27 ` Laszlo Ersek
2013-11-08 15:28 ` Peter Maydell
2013-11-07 22:23 ` [Qemu-devel] [PATCH 2/2] i386/pc_piix: the pci-hole should end where the system flash starts Laszlo Ersek
2013-11-08 10:14 ` [Qemu-devel] reverting commit a53ae8e934cd54686875b5bcfc2f434244ee55d6 Re: [edk2] [PATCH 0/2] Re: exec: fix regression by making system-memory region UINT64_MAX size Paolo Bonzini
2013-11-08 16:37 ` [Qemu-devel] " Igor Mammedov
2013-11-08 15:42 ` [Qemu-devel] [PATCH] " Andreas Färber
2013-11-08 16:19 ` Laszlo Ersek
2013-11-08 16:26 ` Paolo Bonzini
2013-11-08 17:09 ` Andreas Färber
2013-11-08 17:15 ` Paolo Bonzini
2013-11-08 17:30 ` Laszlo Ersek
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=1383557636.2264.8.camel@localhost.localdomain \
--to=marcel.a@redhat.com \
--cc=afaerber@suse.de \
--cc=anthony@codemonkey.ws \
--cc=jan.kiszka@siemens.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).