From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [Qemu-devel] [PULL] Urgent memory fix for kvm with unaligned memory slots Date: Fri, 02 Mar 2012 07:23:23 -0600 Message-ID: <4F50C9CB.9070604@codemonkey.ws> References: <4F4F7C47.6090005@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: qemu-devel , KVM list To: Avi Kivity Return-path: Received: from mail-pw0-f46.google.com ([209.85.160.46]:55869 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752924Ab2CBNX1 (ORCPT ); Fri, 2 Mar 2012 08:23:27 -0500 Received: by mail-pw0-f46.google.com with SMTP id un15so102706pbc.19 for ; Fri, 02 Mar 2012 05:23:26 -0800 (PST) In-Reply-To: <4F4F7C47.6090005@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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); >