qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots
@ 2012-03-01 13:40 Avi Kivity
  2012-03-01 16:51 ` Bobby Powers
  2012-03-02 13:23 ` Anthony Liguori
  0 siblings, 2 replies; 7+ messages in thread
From: Avi Kivity @ 2012-03-01 13:40 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel, KVM list

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

----------------------------------------------------------------
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);

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots
  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-02 13:23 ` Anthony Liguori
  1 sibling, 1 reply; 7+ messages in thread
From: Bobby Powers @ 2012-03-01 16:51 UTC (permalink / raw)
  To: Avi Kivity; +Cc: qemu-devel, Anthony Liguori, KVM list

On Thu, Mar 1, 2012 at 8:40 AM, Avi Kivity <avi@redhat.com> 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
>
> ----------------------------------------------------------------
> 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;

Am I crazy, or does this look wrong?

>
>     while (1) {
>         mem = kvm_lookup_overlapping_slot(s, start_addr, start_addr +
> size);
>
> --
> error compiling committee.c: too many arguments to function
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots
  2012-03-01 16:51 ` Bobby Powers
@ 2012-03-01 17:03   ` Avi Kivity
  2012-03-01 17:08     ` Eric Blake
  0 siblings, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2012-03-01 17:03 UTC (permalink / raw)
  To: Bobby Powers; +Cc: qemu-devel, Anthony Liguori, KVM list

On 03/01/2012 06:51 PM, Bobby Powers wrote:
> >     /* 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;
>
> Am I crazy, or does this look wrong?

Could be both.  Why do you thing it is wrong?

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots
  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
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Blake @ 2012-03-01 17:08 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Anthony Liguori, qemu-devel, Bobby Powers, KVM list

[-- Attachment #1: Type: text/plain, Size: 731 bytes --]

On 03/01/2012 10:03 AM, Avi Kivity wrote:
>>>
>>> -    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region;
>>> +    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region
>>> + delta;
>>
>> Am I crazy, or does this look wrong?
> 
> Could be both.  Why do you thing it is wrong?

Line wrapping makes it look like we are adding two lines, one line
ending in 'section->offset_within_region', and the next line starting
with 'delta;', which is a syntax error.

But without line wrapping, we are adding just one line with
'offset_within_region + delta;' at the end of that line.

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots
  2012-03-01 17:08     ` Eric Blake
@ 2012-03-01 17:11       ` Bobby Powers
  2012-03-01 17:13       ` Avi Kivity
  1 sibling, 0 replies; 7+ messages in thread
From: Bobby Powers @ 2012-03-01 17:11 UTC (permalink / raw)
  To: Eric Blake; +Cc: KVM list, Avi Kivity, Anthony Liguori, qemu-devel

On Thu, Mar 1, 2012 at 12:08 PM, Eric Blake <eblake@redhat.com> wrote:
> On 03/01/2012 10:03 AM, Avi Kivity wrote:
>>>>
>>>> -    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region;
>>>> +    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region
>>>> + delta;
>>>
>>> Am I crazy, or does this look wrong?
>>
>> Could be both.  Why do you thing it is wrong?
>
> Line wrapping makes it look like we are adding two lines, one line
> ending in 'section->offset_within_region', and the next line starting
> with 'delta;', which is a syntax error.

yea, patch line wrapping was making my eyes see things.  okay, sorry
for the noise.

>
> But without line wrapping, we are adding just one line with
> 'offset_within_region + delta;' at the end of that line.
>
> --
> Eric Blake   eblake@redhat.com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots
  2012-03-01 17:08     ` Eric Blake
  2012-03-01 17:11       ` Bobby Powers
@ 2012-03-01 17:13       ` Avi Kivity
  1 sibling, 0 replies; 7+ messages in thread
From: Avi Kivity @ 2012-03-01 17:13 UTC (permalink / raw)
  To: Eric Blake; +Cc: Anthony Liguori, qemu-devel, Bobby Powers, KVM list

On 03/01/2012 07:08 PM, Eric Blake wrote:
> On 03/01/2012 10:03 AM, Avi Kivity wrote:
> >>>
> >>> -    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region;
> >>> +    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region
> >>> + delta;
> >>
> >> Am I crazy, or does this look wrong?
> > 
> > Could be both.  Why do you thing it is wrong?
>
> Line wrapping makes it look like we are adding two lines, one line
> ending in 'section->offset_within_region', and the next line starting
> with 'delta;', which is a syntax error.
>
> But without line wrapping, we are adding just one line with
> 'offset_within_region + delta;' at the end of that line.
>

Ah, of course.  I just copy/pasted this into thunderbird, this is not a
proper patch but a pull request.  Sorry about the confusion.

Bobby: so it does indeed look wrong.  This says nothing about your
sanity though, for that consult a qualified professional instead of
asking on the mailing list.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots
  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-02 13:23 ` Anthony Liguori
  1 sibling, 0 replies; 7+ messages in thread
From: Anthony Liguori @ 2012-03-02 13:23 UTC (permalink / raw)
  To: Avi Kivity; +Cc: qemu-devel, KVM list

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);
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-03-02 13:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).