From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2hhV-0004VS-Ac for qemu-devel@nongnu.org; Wed, 29 Feb 2012 06:28:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S2hhO-0007LA-UO for qemu-devel@nongnu.org; Wed, 29 Feb 2012 06:28:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:8575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2hhO-0007L0-Lz for qemu-devel@nongnu.org; Wed, 29 Feb 2012 06:27:58 -0500 Message-ID: <4F4E0BB8.4020801@redhat.com> Date: Wed, 29 Feb 2012 13:27:52 +0200 From: Avi Kivity MIME-Version: 1.0 References: <4F4CC7C6.9070609@redhat.com> <20120228175914.GA28479@redhat.com> <4F4D1951.4040807@codemonkey.ws> <4F4D19C5.8030507@redhat.com> <4F4D2789.2070306@codemonkey.ws> <4F4D2848.30007@redhat.com> <4F4D290F.90907@codemonkey.ws> <20120228225805.GA8740@redhat.com> <4F4DF94A.80803@redhat.com> <20120229102306.GA4924@redhat.com> <4F4E03BE.0@redhat.com> In-Reply-To: <4F4E03BE.0@redhat.com> Content-Type: multipart/mixed; boundary="------------080008040005010209030404" Subject: Re: [Qemu-devel] [PULL] Memory core space reduction List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: qemu-devel , Anthony Liguori This is a multi-part message in MIME format. --------------080008040005010209030404 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 02/29/2012 12:53 PM, Avi Kivity wrote: > I did get an abort with -enable-kvm, but that looks like the old issue, > no? Looking into it. > > -- error compiling committee.c: too many arguments to function --------------080008040005010209030404 Content-Type: text/x-patch; name="0001-kvm-fix-unaligned-slots.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-kvm-fix-unaligned-slots.patch" >>From 4fa865c7086e2f287c91f4372df6eb5ddf40a48c Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Wed, 29 Feb 2012 13:22:12 +0200 Subject: [PATCH] kvm: fix unaligned slots kvm_set_phys_mem() may be passed sections that are not aligned to a page boundary. The current code simply brute-forces the alignment which leads to an inconsistency and an abort(). Fix by aligning the start and the end of the section correctly, discarding and unaligned head or tail. This was triggered by a guest sizing a 64-bit BAR that is smaller than a page with PCI_COMMAND_MEMORY enabled and the upper dword clear. Signed-off-by: Avi Kivity --- kvm-all.c | 15 ++++++++++++--- 1 files changed, 12 insertions(+), 3 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 839b1dd..c58c77b 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -542,17 +542,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); -- 1.7.9 --------------080008040005010209030404--