From: Igor Mammedov <imammedo@redhat.com>
To: Alexander Graf <agraf@suse.de>
Cc: qemu-ppc@nongnu.org, stuart.yoder@freescale.com,
qemu-devel@nongnu.org, pbonzini@redhat.com, kvm@vger.kernel.org,
qemu-stable@nongnu.org
Subject: Re: [PATCH] kvm: Fix memory slot page alignment logic
Date: Mon, 10 Nov 2014 13:31:01 +0100 [thread overview]
Message-ID: <20141110133101.194f5ea0@nial.usersys.redhat.com> (raw)
In-Reply-To: <1415395125-18926-1-git-send-email-agraf@suse.de>
On Fri, 7 Nov 2014 22:18:45 +0100
Alexander Graf <agraf@suse.de> wrote:
> Memory slots have to be page aligned to get entered into KVM. There
> is existing logic that tries to ensure that we pad memory slots that
> are not page aligned to the biggest region that would still fit in the
> alignment requirements.
>
> Unfortunately, that logic is broken. It tries to calculate the start
> offset based on the region size.
>
> Fix up the logic to do the thing it was intended to do and document it
> properly in the comment above it.
>
> With this patch applied, I can successfully run an e500 guest with more
> than 3GB RAM (at which point RAM starts overlapping subpage memory regions).
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
> kvm-all.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/kvm-all.c b/kvm-all.c
> index 44a5e72..596e7ce 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -634,8 +634,10 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add)
> unsigned delta;
>
> /* kvm works in page size chunks, but the function may be called
> - with sub-page size and unaligned start address. */
> - delta = TARGET_PAGE_ALIGN(size) - size;
> + with sub-page size and unaligned start address. Pad the start
> + address to next and truncate size to previous page boundary. */
I'm a bit confused how it works at all.
Lets assume that there is no mapped pages that include start_addr,
then if start_addr were padded to next page, kvm would map it from there
but the rest of QEMU would still use unaligned start_addr for MemoryRegion
that isn't even mapped.
It would seem that instead of padding up to the next page, start_addr
should be moved to the start of the page that includes it to make page
with original start_addr available to guest.
> + delta = (TARGET_PAGE_SIZE - (start_addr & ~TARGET_PAGE_MASK));
> + delta &= ~TARGET_PAGE_MASK;
> if (delta > size) {
> return;
> }
WARNING: multiple messages have this Message-ID (diff)
From: Igor Mammedov <imammedo@redhat.com>
To: Alexander Graf <agraf@suse.de>
Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org,
qemu-stable@nongnu.org, stuart.yoder@freescale.com,
qemu-ppc@nongnu.org, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH] kvm: Fix memory slot page alignment logic
Date: Mon, 10 Nov 2014 13:31:01 +0100 [thread overview]
Message-ID: <20141110133101.194f5ea0@nial.usersys.redhat.com> (raw)
In-Reply-To: <1415395125-18926-1-git-send-email-agraf@suse.de>
On Fri, 7 Nov 2014 22:18:45 +0100
Alexander Graf <agraf@suse.de> wrote:
> Memory slots have to be page aligned to get entered into KVM. There
> is existing logic that tries to ensure that we pad memory slots that
> are not page aligned to the biggest region that would still fit in the
> alignment requirements.
>
> Unfortunately, that logic is broken. It tries to calculate the start
> offset based on the region size.
>
> Fix up the logic to do the thing it was intended to do and document it
> properly in the comment above it.
>
> With this patch applied, I can successfully run an e500 guest with more
> than 3GB RAM (at which point RAM starts overlapping subpage memory regions).
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
> kvm-all.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/kvm-all.c b/kvm-all.c
> index 44a5e72..596e7ce 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -634,8 +634,10 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add)
> unsigned delta;
>
> /* kvm works in page size chunks, but the function may be called
> - with sub-page size and unaligned start address. */
> - delta = TARGET_PAGE_ALIGN(size) - size;
> + with sub-page size and unaligned start address. Pad the start
> + address to next and truncate size to previous page boundary. */
I'm a bit confused how it works at all.
Lets assume that there is no mapped pages that include start_addr,
then if start_addr were padded to next page, kvm would map it from there
but the rest of QEMU would still use unaligned start_addr for MemoryRegion
that isn't even mapped.
It would seem that instead of padding up to the next page, start_addr
should be moved to the start of the page that includes it to make page
with original start_addr available to guest.
> + delta = (TARGET_PAGE_SIZE - (start_addr & ~TARGET_PAGE_MASK));
> + delta &= ~TARGET_PAGE_MASK;
> if (delta > size) {
> return;
> }
next prev parent reply other threads:[~2014-11-10 12:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-07 21:18 [PATCH] kvm: Fix memory slot page alignment logic Alexander Graf
2014-11-07 21:18 ` [Qemu-devel] " Alexander Graf
2014-11-07 21:24 ` [Qemu-ppc] " Alexander Graf
2014-11-07 21:24 ` [Qemu-devel] " Alexander Graf
2014-11-10 12:31 ` Igor Mammedov [this message]
2014-11-10 12:31 ` [Qemu-devel] " Igor Mammedov
2014-11-10 13:16 ` Alexander Graf
2014-11-10 13:16 ` [Qemu-devel] " Alexander Graf
2014-11-10 13:54 ` Paolo Bonzini
2014-11-10 13:54 ` [Qemu-devel] " Paolo Bonzini
2014-11-10 13:55 ` Peter Maydell
2014-11-10 13:55 ` Peter Maydell
2014-11-10 14:48 ` Alexander Graf
2014-11-10 14:48 ` Alexander Graf
2014-11-10 13:55 ` Igor Mammedov
2014-11-10 13:55 ` [Qemu-devel] " Igor Mammedov
2014-11-10 14:47 ` Alexander Graf
2014-11-10 14:47 ` [Qemu-devel] " Alexander Graf
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=20141110133101.194f5ea0@nial.usersys.redhat.com \
--to=imammedo@redhat.com \
--cc=agraf@suse.de \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=stuart.yoder@freescale.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.