mirror of https://github.com/xemu-project/xemu.git
hw/xen/hvm: Get target page size at runtime
In order to build this file once for all targets, replace: TARGET_PAGE_BITS -> qemu_target_page_bits() TARGET_PAGE_SIZE -> qemu_target_page_size() TARGET_PAGE_MASK -> -qemu_target_page_size() Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Message-Id: <20231114163123.74888-4-philmd@linaro.org>
This commit is contained in:
parent
8ebb8682f6
commit
825f292d34
|
@ -23,6 +23,7 @@
|
||||||
#include "hw/xen/xen-hvm-common.h"
|
#include "hw/xen/xen-hvm-common.h"
|
||||||
#include "hw/xen/arch_hvm.h"
|
#include "hw/xen/arch_hvm.h"
|
||||||
#include <xen/hvm/e820.h>
|
#include <xen/hvm/e820.h>
|
||||||
|
#include "exec/target_page.h"
|
||||||
|
|
||||||
static MemoryRegion ram_640k, ram_lo, ram_hi;
|
static MemoryRegion ram_640k, ram_lo, ram_hi;
|
||||||
static MemoryRegion *framebuffer;
|
static MemoryRegion *framebuffer;
|
||||||
|
@ -247,6 +248,9 @@ static int xen_add_to_physmap(XenIOState *state,
|
||||||
MemoryRegion *mr,
|
MemoryRegion *mr,
|
||||||
hwaddr offset_within_region)
|
hwaddr offset_within_region)
|
||||||
{
|
{
|
||||||
|
unsigned target_page_bits = qemu_target_page_bits();
|
||||||
|
int page_size = qemu_target_page_size();
|
||||||
|
int page_mask = -page_size;
|
||||||
unsigned long nr_pages;
|
unsigned long nr_pages;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
XenPhysmap *physmap = NULL;
|
XenPhysmap *physmap = NULL;
|
||||||
|
@ -254,7 +258,7 @@ static int xen_add_to_physmap(XenIOState *state,
|
||||||
hwaddr phys_offset = memory_region_get_ram_addr(mr);
|
hwaddr phys_offset = memory_region_get_ram_addr(mr);
|
||||||
const char *mr_name;
|
const char *mr_name;
|
||||||
|
|
||||||
if (get_physmapping(start_addr, size, TARGET_PAGE_MASK)) {
|
if (get_physmapping(start_addr, size, page_mask)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
|
@ -294,9 +298,9 @@ go_physmap:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pfn = phys_offset >> TARGET_PAGE_BITS;
|
pfn = phys_offset >> target_page_bits;
|
||||||
start_gpfn = start_addr >> TARGET_PAGE_BITS;
|
start_gpfn = start_addr >> target_page_bits;
|
||||||
nr_pages = size >> TARGET_PAGE_BITS;
|
nr_pages = size >> target_page_bits;
|
||||||
rc = xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, pfn,
|
rc = xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, pfn,
|
||||||
start_gpfn);
|
start_gpfn);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
@ -310,8 +314,8 @@ go_physmap:
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid,
|
rc = xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid,
|
||||||
start_addr >> TARGET_PAGE_BITS,
|
start_addr >> target_page_bits,
|
||||||
(start_addr + size - 1) >> TARGET_PAGE_BITS,
|
(start_addr + size - 1) >> target_page_bits,
|
||||||
XEN_DOMCTL_MEM_CACHEATTR_WB);
|
XEN_DOMCTL_MEM_CACHEATTR_WB);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
error_report("pin_memory_cacheattr failed: %s", strerror(errno));
|
error_report("pin_memory_cacheattr failed: %s", strerror(errno));
|
||||||
|
@ -323,11 +327,14 @@ static int xen_remove_from_physmap(XenIOState *state,
|
||||||
hwaddr start_addr,
|
hwaddr start_addr,
|
||||||
ram_addr_t size)
|
ram_addr_t size)
|
||||||
{
|
{
|
||||||
|
unsigned target_page_bits = qemu_target_page_bits();
|
||||||
|
int page_size = qemu_target_page_size();
|
||||||
|
int page_mask = -page_size;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
XenPhysmap *physmap = NULL;
|
XenPhysmap *physmap = NULL;
|
||||||
hwaddr phys_offset = 0;
|
hwaddr phys_offset = 0;
|
||||||
|
|
||||||
physmap = get_physmapping(start_addr, size, TARGET_PAGE_MASK);
|
physmap = get_physmapping(start_addr, size, page_mask);
|
||||||
if (physmap == NULL) {
|
if (physmap == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -338,9 +345,9 @@ static int xen_remove_from_physmap(XenIOState *state,
|
||||||
DPRINTF("unmapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx", at "
|
DPRINTF("unmapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx", at "
|
||||||
"%"HWADDR_PRIx"\n", start_addr, start_addr + size, phys_offset);
|
"%"HWADDR_PRIx"\n", start_addr, start_addr + size, phys_offset);
|
||||||
|
|
||||||
size >>= TARGET_PAGE_BITS;
|
size >>= target_page_bits;
|
||||||
start_addr >>= TARGET_PAGE_BITS;
|
start_addr >>= target_page_bits;
|
||||||
phys_offset >>= TARGET_PAGE_BITS;
|
phys_offset >>= target_page_bits;
|
||||||
rc = xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start_addr,
|
rc = xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start_addr,
|
||||||
phys_offset);
|
phys_offset);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
@ -369,13 +376,16 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
|
||||||
hwaddr start_addr,
|
hwaddr start_addr,
|
||||||
ram_addr_t size)
|
ram_addr_t size)
|
||||||
{
|
{
|
||||||
hwaddr npages = size >> TARGET_PAGE_BITS;
|
unsigned target_page_bits = qemu_target_page_bits();
|
||||||
|
int page_size = qemu_target_page_size();
|
||||||
|
int page_mask = -page_size;
|
||||||
|
hwaddr npages = size >> target_page_bits;
|
||||||
const int width = sizeof(unsigned long) * 8;
|
const int width = sizeof(unsigned long) * 8;
|
||||||
size_t bitmap_size = DIV_ROUND_UP(npages, width);
|
size_t bitmap_size = DIV_ROUND_UP(npages, width);
|
||||||
int rc, i, j;
|
int rc, i, j;
|
||||||
const XenPhysmap *physmap = NULL;
|
const XenPhysmap *physmap = NULL;
|
||||||
|
|
||||||
physmap = get_physmapping(start_addr, size, TARGET_PAGE_MASK);
|
physmap = get_physmapping(start_addr, size, page_mask);
|
||||||
if (physmap == NULL) {
|
if (physmap == NULL) {
|
||||||
/* not handled */
|
/* not handled */
|
||||||
return;
|
return;
|
||||||
|
@ -389,7 +399,7 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = xen_track_dirty_vram(xen_domid, start_addr >> TARGET_PAGE_BITS,
|
rc = xen_track_dirty_vram(xen_domid, start_addr >> target_page_bits,
|
||||||
npages, dirty_bitmap);
|
npages, dirty_bitmap);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
#ifndef ENODATA
|
#ifndef ENODATA
|
||||||
|
@ -410,8 +420,7 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
|
||||||
j = ctzl(map);
|
j = ctzl(map);
|
||||||
map &= ~(1ul << j);
|
map &= ~(1ul << j);
|
||||||
memory_region_set_dirty(framebuffer,
|
memory_region_set_dirty(framebuffer,
|
||||||
(i * width + j) * TARGET_PAGE_SIZE,
|
(i * width + j) * page_size, page_size);
|
||||||
TARGET_PAGE_SIZE);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -631,17 +640,21 @@ void xen_register_framebuffer(MemoryRegion *mr)
|
||||||
|
|
||||||
void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
|
void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
|
||||||
{
|
{
|
||||||
|
unsigned target_page_bits = qemu_target_page_bits();
|
||||||
|
int page_size = qemu_target_page_size();
|
||||||
|
int page_mask = -page_size;
|
||||||
|
|
||||||
if (unlikely(xen_in_migration)) {
|
if (unlikely(xen_in_migration)) {
|
||||||
int rc;
|
int rc;
|
||||||
ram_addr_t start_pfn, nb_pages;
|
ram_addr_t start_pfn, nb_pages;
|
||||||
|
|
||||||
start = xen_phys_offset_to_gaddr(start, length, TARGET_PAGE_MASK);
|
start = xen_phys_offset_to_gaddr(start, length, page_mask);
|
||||||
|
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
length = TARGET_PAGE_SIZE;
|
length = page_size;
|
||||||
}
|
}
|
||||||
start_pfn = start >> TARGET_PAGE_BITS;
|
start_pfn = start >> target_page_bits;
|
||||||
nb_pages = ((start + length + TARGET_PAGE_SIZE - 1) >> TARGET_PAGE_BITS)
|
nb_pages = ((start + length + page_size - 1) >> target_page_bits)
|
||||||
- start_pfn;
|
- start_pfn;
|
||||||
rc = xen_modified_memory(xen_domid, start_pfn, nb_pages);
|
rc = xen_modified_memory(xen_domid, start_pfn, nb_pages);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
@ -664,6 +677,9 @@ void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
|
||||||
void arch_xen_set_memory(XenIOState *state, MemoryRegionSection *section,
|
void arch_xen_set_memory(XenIOState *state, MemoryRegionSection *section,
|
||||||
bool add)
|
bool add)
|
||||||
{
|
{
|
||||||
|
unsigned target_page_bits = qemu_target_page_bits();
|
||||||
|
int page_size = qemu_target_page_size();
|
||||||
|
int page_mask = -page_size;
|
||||||
hwaddr start_addr = section->offset_within_address_space;
|
hwaddr start_addr = section->offset_within_address_space;
|
||||||
ram_addr_t size = int128_get64(section->size);
|
ram_addr_t size = int128_get64(section->size);
|
||||||
bool log_dirty = memory_region_is_logging(section->mr, DIRTY_MEMORY_VGA);
|
bool log_dirty = memory_region_is_logging(section->mr, DIRTY_MEMORY_VGA);
|
||||||
|
@ -679,8 +695,8 @@ void arch_xen_set_memory(XenIOState *state, MemoryRegionSection *section,
|
||||||
|
|
||||||
trace_xen_client_set_memory(start_addr, size, log_dirty);
|
trace_xen_client_set_memory(start_addr, size, log_dirty);
|
||||||
|
|
||||||
start_addr &= TARGET_PAGE_MASK;
|
start_addr &= page_mask;
|
||||||
size = ROUND_UP(size, TARGET_PAGE_SIZE);
|
size = ROUND_UP(size, page_size);
|
||||||
|
|
||||||
if (add) {
|
if (add) {
|
||||||
if (!memory_region_is_rom(section->mr)) {
|
if (!memory_region_is_rom(section->mr)) {
|
||||||
|
@ -689,8 +705,8 @@ void arch_xen_set_memory(XenIOState *state, MemoryRegionSection *section,
|
||||||
} else {
|
} else {
|
||||||
mem_type = HVMMEM_ram_ro;
|
mem_type = HVMMEM_ram_ro;
|
||||||
if (xen_set_mem_type(xen_domid, mem_type,
|
if (xen_set_mem_type(xen_domid, mem_type,
|
||||||
start_addr >> TARGET_PAGE_BITS,
|
start_addr >> target_page_bits,
|
||||||
size >> TARGET_PAGE_BITS)) {
|
size >> target_page_bits)) {
|
||||||
DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n",
|
DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n",
|
||||||
start_addr);
|
start_addr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue