From: Avi Kivity <avi@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
Anthony Liguori <anthony@codemonkey.ws>
Subject: Re: [Qemu-devel] [PULL] Memory core space reduction
Date: Wed, 29 Feb 2012 13:27:52 +0200 [thread overview]
Message-ID: <4F4E0BB8.4020801@redhat.com> (raw)
In-Reply-To: <4F4E03BE.0@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 210 bytes --]
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
[-- Attachment #2: 0001-kvm-fix-unaligned-slots.patch --]
[-- Type: text/x-patch, Size: 1887 bytes --]
>From 4fa865c7086e2f287c91f4372df6eb5ddf40a48c Mon Sep 17 00:00:00 2001
From: Avi Kivity <avi@redhat.com>
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 <avi@redhat.com>
---
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
next prev parent reply other threads:[~2012-02-29 11:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-28 12:25 [Qemu-devel] [PULL] Memory core space reduction Avi Kivity
2012-02-28 12:26 ` Avi Kivity
2012-02-28 17:59 ` Michael S. Tsirkin
2012-02-28 18:13 ` Anthony Liguori
2012-02-28 18:15 ` Avi Kivity
2012-02-28 18:31 ` Anthony Liguori
2012-02-28 18:56 ` Anthony Liguori
2012-02-28 19:14 ` Anthony Liguori
2012-02-28 19:17 ` Avi Kivity
2012-02-28 19:20 ` Anthony Liguori
2012-02-28 22:58 ` Michael S. Tsirkin
2012-02-29 10:09 ` Avi Kivity
2012-02-29 10:23 ` Michael S. Tsirkin
2012-02-29 10:53 ` Avi Kivity
2012-02-29 11:25 ` Michael S. Tsirkin
2012-02-29 11:31 ` Avi Kivity
2012-02-29 11:45 ` Avi Kivity
2012-02-29 14:15 ` Michael S. Tsirkin
2012-02-29 11:27 ` Avi Kivity [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-02-28 12:24 Avi Kivity
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=4F4E0BB8.4020801@redhat.com \
--to=avi@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=mst@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.