[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1 6/7] kvm: simplify kvm_align_section()
From: |
David Hildenbrand |
Subject: |
[Qemu-devel] [PATCH v1 6/7] kvm: simplify kvm_align_section() |
Date: |
Mon, 16 Oct 2017 16:43:01 +0200 |
Use ROUND_UP and simplify the code a bit.
Signed-off-by: David Hildenbrand <address@hidden>
---
accel/kvm/kvm-all.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 2835bb3801..f290f487a5 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -197,26 +197,20 @@ static hwaddr kvm_align_section(MemoryRegionSection
*section,
hwaddr *start)
{
hwaddr size = int128_get64(section->size);
- hwaddr delta;
-
- *start = section->offset_within_address_space;
+ hwaddr delta, aligned;
/* kvm works in page size chunks, but the function may be called
with sub-page size and unaligned start address. Pad the start
address to next and truncate size to previous page boundary. */
- delta = qemu_real_host_page_size - (*start & ~qemu_real_host_page_mask);
- delta &= ~qemu_real_host_page_mask;
- *start += delta;
+ aligned = ROUND_UP(section->offset_within_address_space,
+ qemu_real_host_page_size);
+ delta = aligned - section->offset_within_address_space;
+ *start = aligned;
if (delta > size) {
return 0;
}
- size -= delta;
- size &= qemu_real_host_page_mask;
- if (*start & ~qemu_real_host_page_mask) {
- return 0;
- }
- return size;
+ return (size - delta) & qemu_real_host_page_mask;
}
int kvm_physical_memory_addr_from_host(KVMState *s, void *ram,
--
2.13.5
- [Qemu-devel] [PATCH v1 0/7] kvm: slot handling fixes (and small cleanups), David Hildenbrand, 2017/10/16
- [Qemu-devel] [PATCH v1 2/7] kvm: fix alignment of ram address, David Hildenbrand, 2017/10/16
- [Qemu-devel] [PATCH v1 3/7] kvm: tolerate non-existing slot for log_start/log_stop/log_sync, David Hildenbrand, 2017/10/16
- [Qemu-devel] [PATCH v1 1/7] memory: call log_start after region_add, David Hildenbrand, 2017/10/16
- [Qemu-devel] [PATCH v1 4/7] kvm: fix error message when failing to unregister slot, David Hildenbrand, 2017/10/16
- [Qemu-devel] [PATCH v1 5/7] kvm: region_add and region_del is not called on updates, David Hildenbrand, 2017/10/16
- [Qemu-devel] [PATCH v1 6/7] kvm: simplify kvm_align_section(),
David Hildenbrand <=
- [Qemu-devel] [PATCH v1 7/7] memory: reuse section_from_flat_range(), David Hildenbrand, 2017/10/16
- Re: [Qemu-devel] [PATCH v1 0/7] kvm: slot handling fixes (and small cleanups), Paolo Bonzini, 2017/10/16