Re: [PULL] Urgent memory fix for kvm with unaligned memory slots

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 1, 2012 at 8:40 AM, Avi Kivity <avi@xxxxxxxxxx> 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@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux