qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Avi Kivity <avi@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>, KVM list <kvm@vger.kernel.org>
Subject: Re: [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots
Date: Fri, 02 Mar 2012 07:23:23 -0600	[thread overview]
Message-ID: <4F50C9CB.9070604@codemonkey.ws> (raw)
In-Reply-To: <4F4F7C47.6090005@redhat.com>

On 03/01/2012 07:40 AM, Avi Kivity wrote:
> The memory core may generate RAM memory regions that are not page
> aligned, but the kvm code is not prepared to handle them well and will
> abort under certain conditions.  This patch fixes the problem.
>
> Please pull from:
>
>    git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git memory/urgent

Pulled.  Thanks.

Regards,

Anthony Liguori

>
> ----------------------------------------------------------------
> Avi Kivity (1):
>        kvm: fix unaligned slots
>
>   kvm-all.c |   15 ++++++++++++---
>   1 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/kvm-all.c b/kvm-all.c
> index c4babda..4b7a4ae 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -541,17 +541,26 @@ static void kvm_set_phys_mem(MemoryRegionSection
> *section, bool add)
>       target_phys_addr_t start_addr = section->offset_within_address_space;
>       ram_addr_t size = section->size;
>       void *ram = NULL;
> +    unsigned delta;
>
>       /* kvm works in page size chunks, but the function may be called
>          with sub-page size and unaligned start address. */
> -    size = TARGET_PAGE_ALIGN(size);
> -    start_addr = TARGET_PAGE_ALIGN(start_addr);
> +    delta = TARGET_PAGE_ALIGN(size) - size;
> +    if (delta>  size) {
> +        return;
> +    }
> +    start_addr += delta;
> +    size -= delta;
> +    size&= TARGET_PAGE_MASK;
> +    if (!size || (start_addr&  ~TARGET_PAGE_MASK)) {
> +        return;
> +    }
>
>       if (!memory_region_is_ram(mr)) {
>           return;
>       }
>
> -    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region;
> +    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region
> + delta;
>
>       while (1) {
>           mem = kvm_lookup_overlapping_slot(s, start_addr, start_addr +
> size);
>

      parent reply	other threads:[~2012-03-02 13:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-01 13:40 [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots Avi Kivity
2012-03-01 16:51 ` Bobby Powers
2012-03-01 17:03   ` Avi Kivity
2012-03-01 17:08     ` Eric Blake
2012-03-01 17:11       ` Bobby Powers
2012-03-01 17:13       ` Avi Kivity
2012-03-02 13:23 ` Anthony Liguori [this message]

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=4F50C9CB.9070604@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --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).