kvm: simplify kvm_align_section()
Use ROUND_UP and simplify the code a bit. Signed-off-by: David Hildenbrand <david@redhat.com> Message-Id: <20171016144302.24284-7-david@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
90ed4bcc3a
commit
a6ffc4232a
|
@ -197,26 +197,20 @@ static hwaddr kvm_align_section(MemoryRegionSection *section,
|
||||||
hwaddr *start)
|
hwaddr *start)
|
||||||
{
|
{
|
||||||
hwaddr size = int128_get64(section->size);
|
hwaddr size = int128_get64(section->size);
|
||||||
hwaddr delta;
|
hwaddr delta, aligned;
|
||||||
|
|
||||||
*start = section->offset_within_address_space;
|
|
||||||
|
|
||||||
/* kvm works in page size chunks, but the function may be called
|
/* kvm works in page size chunks, but the function may be called
|
||||||
with sub-page size and unaligned start address. Pad the start
|
with sub-page size and unaligned start address. Pad the start
|
||||||
address to next and truncate size to previous page boundary. */
|
address to next and truncate size to previous page boundary. */
|
||||||
delta = qemu_real_host_page_size - (*start & ~qemu_real_host_page_mask);
|
aligned = ROUND_UP(section->offset_within_address_space,
|
||||||
delta &= ~qemu_real_host_page_mask;
|
qemu_real_host_page_size);
|
||||||
*start += delta;
|
delta = aligned - section->offset_within_address_space;
|
||||||
|
*start = aligned;
|
||||||
if (delta > size) {
|
if (delta > size) {
|
||||||
return 0;
|
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,
|
int kvm_physical_memory_addr_from_host(KVMState *s, void *ram,
|
||||||
|
|
Loading…
Reference in New Issue