hw/xen: Have most of Xen files become target-agnostic
cover hw/xen: Have most of Xen files become target-agnostic
Hi,
After discussing with Alex Bennée I realized most Xen code should be target-agnostic. David Woodhouse confirmed that last week, so I had a quick look and here is the result.
More work is required to be able to instanciate Xen HW in an heterogeneous machine, but this doesn't make sense yet until we can run multiple accelerators concurrently.
Only build-tested.
Regards,
Phil.
Philippe Mathieu-Daudé (10):
sysemu/xen: Forbid using Xen headers in user emulation hw/xen/xen_arch_hvm: Rename prototypes using 'xen_arch_' prefix hw/xen: Merge 'hw/xen/arch_hvm.h' in 'hw/xen/xen-hvm-common.h' hw/xen: Factor xen_arch_align_ioreq_data() out of handle_ioreq() hw/xen: Use target-agnostic qemu_target_page_bits() hw/xen: Reduce inclusion of 'cpu.h' to target-specific sources sysemu/xen-mapcache: Check Xen availability with
CONFIG_XEN_IS_POSSIBLE
system/physmem: Only include 'hw/xen/xen.h' when Xen is available hw/xen: Extract 'xen_igd.h' from 'xen_pt.h'
hw/xen: Have most of Xen files become target-agnostic
hw/xen/xen_pt.h | 14 -------------- include/hw/arm/xen_arch_hvm.h | 9 --------- include/hw/i386/xen_arch_hvm.h | 11 ----------- include/hw/xen/arch_hvm.h | 5 ----- include/hw/xen/xen-hvm-common.h | 8 +++++++- include/hw/xen/xen_igd.h | 23 +++++++++++++++++++++++ include/sysemu/xen-mapcache.h | 3 ++- include/sysemu/xen.h | 8 ++++---- accel/xen/xen-all.c | 1 + hw/arm/xen_arm.c | 14 +++++++++++--- hw/i386/pc_piix.c | 1 + hw/i386/xen/xen-hvm.c | 16 ++++++++++++---- hw/xen/xen-hvm-common.c | 16 +++++++--------- hw/xen/xen_pt.c | 3 ++- hw/xen/xen_pt_config_init.c | 3 ++- hw/xen/xen_pt_graphics.c | 3 ++- hw/xen/xen_pt_stub.c | 2 +- system/physmem.c | 5 ++++- accel/xen/meson.build | 2 +- hw/block/dataplane/meson.build | 2 +- hw/xen/meson.build | 13 ++++--------- 21 files changed, 85 insertions(+), 77 deletions(-) delete mode 100644 include/hw/arm/xen_arch_hvm.h delete mode 100644 include/hw/i386/xen_arch_hvm.h delete mode 100644 include/hw/xen/arch_hvm.h create mode 100644 include/hw/xen/xen_igd.h
Signature · 1 line
2.41.0
PATCH 1/10 sysemu/xen: Forbid using Xen headers in user emulation
Xen is a system specific accelerator, it makes no sense to include its headers in user emulation.
--- include/sysemu/xen.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/sysemu/xen.h +4 -4
@@ -10,6 +10,10 @@#ifndef SYSEMU_XEN_H #define SYSEMU_XEN_H +#ifdef CONFIG_USER_ONLY +#error Cannot include sysemu/xen.h from user emulation +#endif +#include "exec/cpu-common.h" #ifdef NEED_CPU_H
@@ -26,16 +30,13 @@ extern bool xen_allowed;#define xen_enabled () (xen_allowed) -#ifndef CONFIG_USER_ONLYvoid xen_hvm_modified_memory (ram_addr_t start,ram_addr_t length);void xen_ram_alloc (ram_addr_t ram_addr,ram_addr_t size,struct MemoryRegion *mr,Error **errp); -#endif#else /* !CONFIG_XEN_IS_POSSIBLE */ #define xen_enabled () 0 -#ifndef CONFIG_USER_ONLYstatic inline void xen_hvm_modified_memory (ram_addr_t start,ram_addr_t length) {/* nothing */
@@ -45,7 +46,6 @@ static inline void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, {g_assert_not_reached (); } -#endif #endif /* CONFIG_XEN_IS_POSSIBLE */
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 01/10] sysemu/xen: Forbid using Xen headers in user emulation
Quoted 7 lines · Philippe Mathieu-Daudé
Xen is a system specific accelerator, it makes no sense to include its headers in user emulation.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/sysemu/xen.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
r~
Re: [PATCH-for-9.0 01/10] sysemu/xen: Forbid using Xen headers in user emulation
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
Xen is a system specific accelerator, it makes no sense to include its headers in user emulation.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
PATCH 2/10 hw/xen/xen_arch_hvm: Rename prototypes using 'xen_arch_' prefix
In reply to Philippe Mathieu-DaudéUse a common 'xen_arch_' prefix for architecture-specific functions. Rename xen_arch_set_memory() and xen_arch_handle_ioreq().
--- include/hw/arm/xen_arch_hvm.h | 4 ++-- include/hw/i386/xen_arch_hvm.h | 4 ++-- hw/arm/xen_arm.c | 4 ++-- hw/i386/xen/xen-hvm.c | 6 +++--- hw/xen/xen-hvm-common.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-)
include/hw/arm/xen_arch_hvm.h +2 -2
@@ -2,8 +2,8 @@#define HW_XEN_ARCH_ARM_HVM_H #include <xen/hvm/ioreq.h> -void arch_handle_ioreq (XenIOState *state,ioreq_t *req); -void arch_xen_set_memory (XenIOState *state, +void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req); +void xen_arch_set_memory (XenIOState *state,MemoryRegionSection *section,bool add);#endif
include/hw/i386/xen_arch_hvm.h +2 -2
@@ -4,8 +4,8 @@#include <xen/hvm/ioreq.h> #include "hw/xen/xen-hvm-common.h" -void arch_handle_ioreq (XenIOState *state,ioreq_t *req); -void arch_xen_set_memory (XenIOState *state, +void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req); +void xen_arch_set_memory (XenIOState *state,MemoryRegionSection *section,bool add);#endif
hw/arm/xen_arm.c +2 -2
@@ -129,14 +129,14 @@ static void xen_init_ram(MachineState *machine) } } -void arch_handle_ioreq (XenIOState *state,ioreq_t *req) +void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req) {hw_error ("Invalid ioreq type 0x%x\n" , req->type);return ; } -void arch_xen_set_memory (XenIOState *state,MemoryRegionSection *section, +void xen_arch_set_memory (XenIOState *state,MemoryRegionSection *section,bool add) { }
hw/i386/xen/xen-hvm.c +3 -3
@@ -659,8 +659,8 @@ void qmp_xen_set_global_dirty_log(bool enable, Error **errp) } } -void arch_xen_set_memory (XenIOState *state,MemoryRegionSection *section, -bool add) +void xen_arch_set_memory (XenIOState *state,MemoryRegionSection *section, +bool add) {hwaddr start_addr = section->offset_within_address_space;ram_addr_t size =int128_get64 (section->size);
@@ -700,7 +700,7 @@ void arch_xen_set_memory(XenIOState *state, MemoryRegionSection *section, } } -void arch_handle_ioreq (XenIOState *state,ioreq_t *req) +void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req) {switch (req->type) {case IOREQ_TYPE_VMWARE_PORT :
hw/xen/xen-hvm-common.c +2 -2
@@ -65,7 +65,7 @@ static void xen_set_memory(struct MemoryListener *listener, } } -arch_xen_set_memory (state, section, add); +xen_arch_set_memory (state, section, add); } void xen_region_add(MemoryListener *listener,
@@ -452,7 +452,7 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)cpu_ioreq_config (state, req);break ;default : -arch_handle_ioreq (state, req); +xen_arch_handle_ioreq (state, req); }if (req->dir ==IOREQ_READ ) { trace_handle_ioreq_read(req, req->type, req->df, req->data_is_ptr,
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 02/10] hw/xen/xen_arch_hvm: Rename prototypes using 'xen_arch_' prefix
Quoted 4 lines · Philippe Mathieu-Daudé
Use a common '
xen_arch_' prefix for architecture-specific functions. Renamexen_arch_set_memory()andxen_arch_handle_ioreq().Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Re: [PATCH-for-9.0 02/10] hw/xen/xen_arch_hvm: Rename prototypes using 'xen_arch_' prefix
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
Use a common '
xen_arch_' prefix for architecture-specific functions. Renamexen_arch_set_memory()andxen_arch_handle_ioreq().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/arm/xen_arch_hvm.h | 4 ++-- include/hw/i386/xen_arch_hvm.h | 4 ++-- hw/arm/xen_arm.c | 4 ++-- hw/i386/xen/xen-hvm.c | 6 +++--- hw/xen/xen-hvm-common.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-)
r~
PATCH 3/10 hw/xen: Merge 'hw/xen/arch_hvm.h' in 'hw/xen/xen-hvm-common.h'
In reply to Philippe Mathieu-DaudéWe don't need a target-specific header for common target-specific prototypes. Declare xen_arch_handle_ioreq() and xen_arch_set_memory() in "hw/xen/xen-hvm-common.h".
--- include/hw/arm/xen_arch_hvm.h | 9 --------- include/hw/i386/xen_arch_hvm.h | 11 ----------- include/hw/xen/arch_hvm.h | 5 ----- include/hw/xen/xen-hvm-common.h | 6 ++++++ hw/arm/xen_arm.c | 1 - hw/i386/xen/xen-hvm.c | 1 - hw/xen/xen-hvm-common.c | 1 - 7 files changed, 6 insertions(+), 28 deletions(-) delete mode 100644 include/hw/arm/xen_arch_hvm.h delete mode 100644 include/hw/i386/xen_arch_hvm.h delete mode 100644 include/hw/xen/arch_hvm.h
include/hw/arm/xen_arch_hvm.h deleted +0 -9
@@ -1,9 +0,0 @@ -#ifndef HW_XEN_ARCH_ARM_HVM_H -#define HW_XEN_ARCH_ARM_HVM_H - -#include <xen/hvm/ioreq.h> -void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req); -void xen_arch_set_memory (XenIOState *state, -MemoryRegionSection *section, -bool add); -#endif
include/hw/i386/xen_arch_hvm.h deleted +0 -11
@@ -1,11 +0,0 @@ -#ifndef HW_XEN_ARCH_I386_HVM_H -#define HW_XEN_ARCH_I386_HVM_H - -#include <xen/hvm/ioreq.h> -#include "hw/xen/xen-hvm-common.h" - -void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req); -void xen_arch_set_memory (XenIOState *state, -MemoryRegionSection *section, -bool add); -#endif
include/hw/xen/arch_hvm.h deleted +0 -5
@@ -1,5 +0,0 @@ -#if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) -#include "hw/i386/xen_arch_hvm.h" -#elif defined(TARGET_ARM ) || defined(TARGET_ARM_64 ) -#include "hw/arm/xen_arch_hvm.h" -#endif
include/hw/xen/xen-hvm-common.h +6 -0
@@ -96,4 +96,10 @@ void xen_register_ioreq(XenIOState *state, unsigned int max_cpus, const MemoryListener *xen_memory_listener);void cpu_ioreq_pio (ioreq_t *req); + +void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req); +void xen_arch_set_memory (XenIOState *state, +MemoryRegionSection *section, +bool add); +#endif /* HW_XEN_HVM_COMMON_H */
hw/arm/xen_arm.c +0 -1
@@ -33,7 +33,6 @@#include "sysemu/sysemu.h" #include "hw/xen/xen-hvm-common.h" #include "sysemu/tpm.h" -#include "hw/xen/arch_hvm.h" #define TYPE_XEN_ARM MACHINE_TYPE_NAME("xenpvh")OBJECT_DECLARE_SIMPLE_TYPE (XenArmState,XEN_ARM )
hw/i386/xen/xen-hvm.c +0 -1
@@ -21,7 +21,6 @@#include "qemu/range.h" #include "hw/xen/xen-hvm-common.h" -#include "hw/xen/arch_hvm.h" #include <xen/hvm/e820.h> static MemoryRegion ram_640k, ram_lo, ram_hi;
hw/xen/xen-hvm-common.c +0 -1
@@ -7,7 +7,6 @@#include "hw/xen/xen-hvm-common.h" #include "hw/xen/xen-bus.h" #include "hw/boards.h" -#include "hw/xen/arch_hvm.h" MemoryRegion ram_memory;
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 03/10] hw/xen: Merge 'hw/xen/arch_hvm.h' in 'hw/xen/xen-hvm-common.h'
Quoted 5 lines · Philippe Mathieu-Daudé
We don't need a target-specific header for common target-specific prototypes. Declare
xen_arch_handle_ioreq()andxen_arch_set_memory()in "hw/xen/xen-hvm-common.h".Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Re: [PATCH-for-9.0 03/10] hw/xen: Merge 'hw/xen/arch_hvm.h' in 'hw/xen/xen-hvm-common.h'
In reply to Philippe Mathieu-DaudéQuoted 14 lines · Philippe Mathieu-Daudé
We don't need a target-specific header for common target-specific prototypes. Declare
xen_arch_handle_ioreq()andxen_arch_set_memory()in "hw/xen/xen-hvm-common.h".Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/arm/xen_arch_hvm.h | 9 --------- include/hw/i386/xen_arch_hvm.h | 11 ----------- include/hw/xen/arch_hvm.h | 5 ----- include/hw/xen/xen-hvm-common.h | 6 ++++++ hw/arm/xen_arm.c | 1 - hw/i386/xen/xen-hvm.c | 1 - hw/xen/xen-hvm-common.c | 1 - 7 files changed, 6 insertions(+), 28 deletions(-)
Quoted 4 lines
delete mode 100644
include/hw/arm/xen_arch_hvm.hdelete mode 100644include/hw/i386/xen_arch_hvm.hdelete mode 100644include/hw/xen/arch_hvm.h
r~
PATCH 4/10 hw/xen: Factor xen_arch_align_ioreq_data() out of handle_ioreq()
In reply to Philippe Mathieu-DaudéPer commit f17068c1c7 ("xen-hvm: reorganize xen-hvm and move common function to xen-hvm-common"), handle_ioreq() is expected to be target-agnostic. However it uses 'target_ulong', which is a target specific definition.
In order to compile this file once for all targets, factor the target-specific code out of handle_ioreq() as a per-target handler called xen_arch_align_ioreq_data().
---
Should we have a 'unsigned qemu_target_long_bits();' helper such qemu_target_page_foo() API and target_words_bigendian()?
--- include/hw/xen/xen-hvm-common.h | 1 + hw/arm/xen_arm.c | 8 ++++++++ hw/i386/xen/xen-hvm.c | 8 ++++++++ hw/xen/xen-hvm-common.c | 5 +---- 4 files changed, 18 insertions(+), 4 deletions(-)
include/hw/xen/xen-hvm-common.h +1 -0
@@ -97,6 +97,7 @@ void xen_register_ioreq(XenIOState *state, unsigned int max_cpus,void cpu_ioreq_pio (ioreq_t *req); +void xen_arch_align_ioreq_data (ioreq_t *req);void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req); void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section,
hw/arm/xen_arm.c +8 -0
@@ -128,6 +128,14 @@ static void xen_init_ram(MachineState *machine) } } +void xen_arch_align_ioreq_data (ioreq_t *req) +{ +if (!req->data_is_ptr && (req->dir ==IOREQ_WRITE ) + && (req->size <sizeof (target_ulong))) { + req->data &= ((target_ulong )1 << (8 * req->size)) -1 ; + } +} +void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req) {hw_error ("Invalid ioreq type 0x%x\n" , req->type);
hw/i386/xen/xen-hvm.c +8 -0
@@ -699,6 +699,14 @@ void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, } } +void xen_arch_align_ioreq_data (ioreq_t *req) +{ +if (!req->data_is_ptr && (req->dir ==IOREQ_WRITE ) + && (req->size <sizeof (target_ulong))) { + req->data &= ((target_ulong )1 << (8 * req->size)) -1 ; + } +} +void xen_arch_handle_ioreq (XenIOState *state,ioreq_t *req) {switch (req->type) {
hw/xen/xen-hvm-common.c +1 -4
@@ -426,10 +426,7 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)trace_handle_ioreq (req, req->type, req->dir, req->df, req->data_is_ptr, req->addr, req->data, req->count, req->size); -if (!req->data_is_ptr && (req->dir ==IOREQ_WRITE ) && - (req->size <sizeof (target_ulong))) { - req->data &= ((target_ulong )1 << (8 * req->size)) -1 ; - } +xen_arch_align_ioreq_data (req);if (req->dir ==IOREQ_WRITE ) trace_handle_ioreq_write(req, req->type, req->df, req->data_is_ptr,
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 04/10] hw/xen: Factor xen_arch_align_ioreq_data() out of handle_ioreq()
Quoted 10 lines · Philippe Mathieu-Daudé
Per commit
f17068c1c7("xen-hvm: reorganize xen-hvm and move common function to xen-hvm-common"),handle_ioreq()is expected to be target-agnostic. However it uses 'target_ulong', which is a target specific definition.In order to compile this file once for all targets, factor the target-specific code out of
handle_ioreq()as a per-target handler calledxen_arch_align_ioreq_data().Signed-off-by Philippe Mathieu-Daudé <[email protected]>
I prefer commits like this to explicitly state 'No function change intended', and on that basis:
But...
Quoted 6 lines
hw/i386/xen/xen-hvm.c +0
-0@@ -699,6 +699,14 @@ void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, } }
hw/i386/xen/xen-hvm.c
Quoted 8 lines
hw/i386/xen/xen-hvm.c +8
-0+void xen_arch_align_ioreq_data (ioreq_t *req) +{ + if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) + && (req->size < sizeof(target_ulong))) { + req->data &= ((target_ulong) 1 << (8 * req->size)) - 1; + } +} +
If a 64-bit Xen host is running a 32-bit guest, what is target_ulong, and what is the actual alignment? I think we are actually communicating with the 64-bit Xen and it's 64 bits, although the *guest* is 32?
I guess the only time when this would matter is when using qemu-system-i386 as the device model on 64-bit Xen? And that's not going to work for various reasons including this?
(I should clarify that I'm not objecting to your patch series, but I just to understand just what the situation is, before you make it *look* saner than it is... :)
Re: [PATCH-for-9.0 04/10] hw/xen: Factor xen_arch_align_ioreq_data() out of handle_ioreq()
In reply to Philippe Mathieu-Daudéhw/xen/xen-hvm-common.c static void handle_ioreq(XenIOState *state, ioreq_t *req) · line 432
Quoted 12 lines · Philippe Mathieu-Daudé
hw/xen/xen-hvm-common.c +0
-4@@ -426,10 +426,7 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)trace_handle_ioreq (req, req->type, req->dir, req->df, req->data_is_ptr, req->addr, req->data, req->count, req->size); -if (!req->data_is_ptr && (req->dir ==IOREQ_WRITE ) && - (req->size <sizeof (target_ulong))) { - req->data &= ((target_ulong )1 << (8 * req->size)) -1 ; - }
I suspect this should never have been using target_ulong at all: req->data is uint64_t.
r~
Re: [PATCH-for-9.0 04/10] hw/xen: Factor xen_arch_align_ioreq_data() out of handle_ioreq()
Quoted 16 lines · Richard Henderson
hw/xen/xen-hvm-common.c static void handle_ioreq(XenIOState *state, · line 432
Quoted 12 lines · Philippe Mathieu-Daudé
hw/xen/xen-hvm-common.c +0
-4@@ -426,10 +426,7 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req) trace_handle_ioreq(req, req->type, req->dir, req->df, req->data_is_ptr, req->addr, req->data, req->count, req->size); - if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) && - (req->size < sizeof (target_ulong))) { - req->data &= ((target_ulong) 1 << (8 * req->size)) - 1; - }I suspect this should never have been using
target_ulongat all:req->dataisuint64_t.
This could replace it:
-- >8 --
- if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) &&
- (req->size < sizeof (target_ulong))) {
- req->data &= ((target_ulong) 1 << (8 * req->size)) - 1;
+ if (!req->data_is_ptr && (req->dir == IOREQ_WRITE)) {
+ req->data = extract64(req->data, 0, BITS_PER_BYTE * req->size);
}---
Some notes while looking at this.
Per xen/include/public/hvm/ioreq.h header:
#define IOREQ_TYPE_PIO 0 /* pio */ #define IOREQ_TYPE_COPY 1 /* mmio ops */ #define IOREQ_TYPE_PCI_CONFIG 2 #define IOREQ_TYPE_VMWARE_PORT 3 #define IOREQ_TYPE_TIMEOFFSET 7 #define IOREQ_TYPE_INVALIDATE 8 /* mapcache */
struct ioreq {
uint64_t addr; /* physical address */
uint64_t data; /* data (or paddr of data) */
uint32_t count; /* for rep prefixes */
uint32_t size; /* size in bytes */
uint32_t vp_eport; /* evtchn for notifications to/from device
model */
uint16_t _pad0;
uint8_t state:4;
uint8_t data_is_ptr:1; /* if 1, data above is the guest paddr
* of the real data to use. */
uint8_t dir:1; /* 1=read, 0=write */
uint8_t df:1;
uint8_t _pad1:1;
uint8_t type; /* I/O type */ };
typedef struct ioreq ioreq_t;
If 'data' is not a pointer, it is a u64.
- In PIO / VMWARE_PORT modes, only 32-bit are used.
- In MMIO COPY mode, memory is accessed by chunks of 64-bit
- In PCI_CONFIG mode, access is u8 or u16 or u32.
- None of TIMEOFFSET / INVALIDATE use 'req'.
- Fallback is only used in x86 for VMWARE_PORT.
--
Regards,
Phil.
PATCH 5/10 hw/xen: Use target-agnostic qemu_target_page_bits()
In reply to Philippe Mathieu-DaudéInstead of the target-specific TARGET_PAGE_BITS definition, use qemu_target_page_bits() which is target agnostic.
--- hw/xen/xen-hvm-common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/xen/xen-hvm-common.c +4 -2
@@ -1,6 +1,7 @@#include "qemu/osdep.h" #include "qemu/units.h" #include "qapi/error.h" +#include "exec/target_page.h" #include "trace.h" #include "hw/pci/pci_host.h"
@@ -13,6 +14,7 @@ MemoryRegion ram_memory;void xen_ram_alloc (ram_addr_t ram_addr,ram_addr_t size,MemoryRegion *mr,Error **errp) { +unsigned target_page_bits =qemu_target_page_bits ();unsigned long nr_pfn;xen_pfn_t *pfn_list;int i;
@@ -31,11 +33,11 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr,trace_xen_ram_alloc (ram_addr, size); - nr_pfn = size >>TARGET_PAGE_BITS ; + nr_pfn = size >> target_page_bits; pfn_list =g_new (xen_pfn_t, nr_pfn);for (i =0 ; i < nr_pfn; i++) { - pfn_list[i] = (ram_addr >>TARGET_PAGE_BITS ) + i; + pfn_list[i] = (ram_addr >> target_page_bits) + i; }if (xc_domain_populate_physmap_exact (xen_xc, xen_domid, nr_pfn,0 ,0 , pfn_list)) {
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 05/10] hw/xen: Use target-agnostic qemu_target_page_bits()
Quoted 7 lines · Philippe Mathieu-Daudé
Instead of the target-specific
TARGET_PAGE_BITSdefinition, useqemu_target_page_bits()which is target agnostic.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/xen/xen-hvm-common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
r~
Re: [PATCH-for-9.0 05/10] hw/xen: Use target-agnostic qemu_target_page_bits()
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
Instead of the target-specific
TARGET_PAGE_BITSdefinition, useqemu_target_page_bits()which is target agnostic.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
PATCH 6/10 hw/xen: Reduce inclusion of 'cpu.h' to target-specific sources
In reply to Philippe Mathieu-DaudéWe rarely need to include "cpu.h" in headers. Including it 'taint' headers to be target-specific. Here only the i386/arm implementations requires "cpu.h", so include it there and remove from the "hw/xen/xen-hvm-common.h" *common* header.
--- include/hw/xen/xen-hvm-common.h | 1 - hw/arm/xen_arm.c | 1 + hw/i386/xen/xen-hvm.c | 1 + 3 files changed, 2 insertions(+), 1 deletion(-)
include/hw/xen/xen-hvm-common.h +0 -1
@@ -4,7 +4,6 @@#include "qemu/osdep.h" #include "qemu/units.h" -#include "cpu.h" #include "hw/pci/pci.h" #include "hw/hw.h" #include "hw/xen/xen_native.h"
hw/arm/xen_arm.c +1 -0
@@ -33,6 +33,7 @@#include "sysemu/sysemu.h" #include "hw/xen/xen-hvm-common.h" #include "sysemu/tpm.h" +#include "cpu.h" #define TYPE_XEN_ARM MACHINE_TYPE_NAME("xenpvh")OBJECT_DECLARE_SIMPLE_TYPE (XenArmState,XEN_ARM )
hw/i386/xen/xen-hvm.c +1 -0
@@ -22,6 +22,7 @@#include "hw/xen/xen-hvm-common.h" #include <xen/hvm/e820.h> +#include "cpu.h" static MemoryRegion ram_640k, ram_lo, ram_hi;static MemoryRegion *framebuffer;
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 06/10] hw/xen: Reduce inclusion of 'cpu.h' to target-specific sources
Quoted 11 lines · Philippe Mathieu-Daudé
We rarely need to include "
cpu.h" in headers. Including it 'taint' headers to be target-specific. Here only the i386/arm implementations requires "cpu.h", so include it there and remove from the "hw/xen/xen-hvm-common.h" *common* header.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/xen/xen-hvm-common.h | 1 - hw/arm/xen_arm.c | 1 + hw/i386/xen/xen-hvm.c | 1 + 3 files changed, 2 insertions(+), 1 deletion(-)
r~
Re: [PATCH-for-9.0 06/10] hw/xen: Reduce inclusion of 'cpu.h' to target-specific sources
In reply to Philippe Mathieu-DaudéQuoted 6 lines · Philippe Mathieu-Daudé
We rarely need to include "
cpu.h" in headers. Including it 'taint' headers to be target-specific. Here only the i386/arm implementations requires "cpu.h", so include it there and remove from the "hw/xen/xen-hvm-common.h" *common* header.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
PATCH 7/10 sysemu/xen-mapcache: Check Xen availability with CONFIG_XEN_IS_POSSIBLE
In reply to Philippe Mathieu-Daudé"sysemu/xen.h" defines CONFIG_XEN_IS_POSSIBLE as a target-agnostic version of CONFIG_XEN. Use it in order to use "sysemu/xen-mapcache.h" in target-agnostic files.
--- include/sysemu/xen-mapcache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/sysemu/xen-mapcache.h +2 -1
@@ -10,10 +10,11 @@#define XEN_MAPCACHE_H #include "exec/cpu-common.h" +#include "sysemu/xen.h" typedef hwaddr (*phys_offset_to_gaddr_t )(hwaddr phys_offset,ram_addr_t size); -#ifdef CONFIG_XEN +#ifdef CONFIG_XEN_IS_POSSIBLE void xen_map_cache_init (phys_offset_to_gaddr_t f,void *opaque);
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 07/10] sysemu/xen-mapcache: Check Xen availability with CONFIG_XEN_IS_POSSIBLE
Quoted 5 lines · Philippe Mathieu-Daudé
"
sysemu/xen.h" definesCONFIG_XEN_IS_POSSIBLEas a target-agnostic version ofCONFIG_XEN. Use it in order to use "sysemu/xen-mapcache.h" in target-agnostic files.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Noting that CONFIG_XEN_IS_POSSIBLE is for Xen accelerator support, and may not be set in all cases when we're hosting Xen-compatible guests,
Re: [PATCH-for-9.0 07/10] sysemu/xen-mapcache: Check Xen availability with CONFIG_XEN_IS_POSSIBLE
Quoted 9 lines · David Woodhouse
Quoted 5 lines · Philippe Mathieu-Daudé
"
sysemu/xen.h" definesCONFIG_XEN_IS_POSSIBLEas a target-agnostic version ofCONFIG_XEN. Use it in order to use "sysemu/xen-mapcache.h" in target-agnostic files.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Noting that
CONFIG_XEN_IS_POSSIBLEis for Xen accelerator support, and may not be set in all cases when we're hosting Xen-compatible guests,
As is CONFIG_XEN.
Maybe be worth renaming CONFIG_ACCEL_XEN if you think we need guest hw specific CONFIG_foo_XEN variables.
Quoted 1 line
Reviewed-by David Woodhouse <[email protected]>
Thanks!
Re: [PATCH-for-9.0 07/10] sysemu/xen-mapcache: Check Xen availability with CONFIG_XEN_IS_POSSIBLE
Quoted 5 lines · Philippe Mathieu-Daudé
As is
CONFIG_XEN.Maybe be worth renaming
CONFIG_ACCEL_XENif you think we need guest hw specificCONFIG_foo_XENvariables.
I don't think so. We have CONFIG_XEN_BUS and CONFIG_XEN_EMU (from commit 820c1aba519b) which I think are all we need.
Thanks.
Re: [PATCH-for-9.0 07/10] sysemu/xen-mapcache: Check Xen availability with CONFIG_XEN_IS_POSSIBLE
In reply to Philippe Mathieu-DaudéCc'ing Paolo
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 5 lines · David Woodhouse
Quoted 4 lines · Philippe Mathieu-Daudé
"
sysemu/xen.h" definesCONFIG_XEN_IS_POSSIBLEas a target-agnostic version ofCONFIG_XEN. Use it in order to use "sysemu/xen-mapcache.h" in target-agnostic files.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Noting that
CONFIG_XEN_IS_POSSIBLEis for Xen accelerator support, and may not be set in all cases when we're hosting Xen-compatible guests,As is
CONFIG_XEN.
Actually we have:
- host Xen support
. CONFIG_XEN_BACKEND
- QEMU Xen accelerator
. CONFIG_XEN
- HW models
. CONFIG_XEN (old / generic models)
. CONFIG_XEN_BUS
. XEN_IGD_PASSTHROUGH (PCI stuff)
. CONFIG_XEN_EMU (Xen on KVM)
Paolo, David, is that correct?
When can we have CONFIG_XEN without CONFIG_XEN_BACKEND (and vice-et-versa)?
So for clarity CONFIG_XEN could be split as:
- CONFIG_ACCEL_XEN
- CONFIG_XEN_MACHINE_FV (Fully-virtualized)
- CONFIG_XEN_MACHINE_PV (Para-virtualized)
Quoted 6 lines
Maybe be worth renaming
CONFIG_ACCEL_XENif you think we need guest hw specificCONFIG_foo_XENvariables.Quoted 1 line
Reviewed-by David Woodhouse <[email protected]>Thanks!
PATCH 8/10 system/physmem: Only include 'hw/xen/xen.h' when Xen is available
In reply to Philippe Mathieu-Daudé"hw/xen/xen.h" contains declarations for Xen hardware. There is no point including it when Xen is not available. When Xen is not available, we have enough with declarations of "sysemu/xen.h".
--- system/physmem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
system/physmem.c +4 -1
@@ -35,9 +35,9 @@#include "hw/qdev-core.h" #include "hw/qdev-properties.h" #include "hw/boards.h" -#include "hw/xen/xen.h" #include "sysemu/kvm.h" #include "sysemu/tcg.h" +#include "sysemu/xen.h" #include "sysemu/qtest.h" #include "qemu/timer.h" #include "qemu/config-file.h"
@@ -51,6 +51,9 @@#include "sysemu/hostmem.h" #include "sysemu/hw_accel.h" #include "sysemu/xen-mapcache.h" +#ifdef CONFIG_XEN +#include "hw/xen/xen.h" +#endif #include "trace/trace-root.h" #ifdef CONFIG_FALLOCATE_PUNCH_HOLE
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 08/10] system/physmem: Only include 'hw/xen/xen.h' when Xen is available
Quoted 2 lines · Philippe Mathieu-Daudé
"
hw/xen/xen.h" contains declarations for Xen hardware. There is no point including it when Xen is not available.
... if even when Xen *is* available, AFAICT. Can you just remove the inclusion of hw/xen/xen.h entirely? I think that still builds, at least for x86.
Quoted 2 lines
When Xen is not
available, we have enough with declarations of "sysemu/xen.h".
... and system/xen-mapcache.h
Quoted 1 line
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Re: [PATCH-for-9.0 08/10] system/physmem: Only include 'hw/xen/xen.h' when Xen is available
Quoted 7 lines · David Woodhouse
Quoted 2 lines · Philippe Mathieu-Daudé
"
hw/xen/xen.h" contains declarations for Xen hardware. There is no point including it when Xen is not available.... if even when Xen *is* available, AFAICT. Can you just remove the inclusion of
hw/xen/xen.hentirely? I think that still builds, at least for x86.
Yep, also on aarch64, thanks!
Quoted 7 lines
Quoted 2 lines
When Xen is not
available, we have enough with declarations of "sysemu/xen.h".... and
system/xen-mapcache.hQuoted 1 line
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
PATCH 9/10 hw/xen: Extract 'xen_igd.h' from 'xen_pt.h'
In reply to Philippe Mathieu-Daudé"hw/xen/xen_pt.h" requires "hw/xen/xen_native.h" which is target specific. It also declares IGD methods, which are not target specific.
Target-agnostic code can use IGD methods. To allow that, extract these methos into a new "hw/xen/xen_igd.h" header.
---
What license for the new "hw/xen/xen_igd.h" header?
--- hw/xen/xen_pt.h | 14 -------------- include/hw/xen/xen_igd.h | 23 +++++++++++++++++++++++ accel/xen/xen-all.c | 1 + hw/i386/pc_piix.c | 1 + hw/xen/xen_pt.c | 3 ++- hw/xen/xen_pt_config_init.c | 3 ++- hw/xen/xen_pt_graphics.c | 3 ++- hw/xen/xen_pt_stub.c | 2 +- 8 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 include/hw/xen/xen_igd.h
hw/xen/xen_pt.h +0 -14
@@ -5,9 +5,6 @@#include "xen-host-pci-device.h" #include "qom/object.h" -bool xen_igd_gfx_pt_enabled (void ); -void xen_igd_gfx_pt_set (bool value,Error **errp); - void xen_pt_log(const PCIDevice *d, const char *f, ...) G_GNUC_PRINTF(2, 3); #define XEN_PT_ERR(d, _f, _a...) xen_pt_log(d, "%s: Error: "_f, __func__, ##_a)
@@ -52,12 +49,6 @@ typedef struct XenPTDeviceClass {XenPTQdevRealize pci_qdev_realize; } XenPTDeviceClass; -uint32_t igd_read_opregion (XenPCIPassthroughState *s); -void xen_igd_reserve_slot (PCIBus *pci_bus); -void igd_write_opregion (XenPCIPassthroughState *s,uint32_t val); -void xen_igd_passthrough_isa_bridge_create (XenPCIPassthroughState *s, -XenHostPCIDevice *dev); -/* function type for config reg */ typedef int (*xen_pt_conf_reg_init ) (XenPCIPassthroughState *, XenPTRegInfo *, uint32_t real_offset,
@@ -343,11 +334,6 @@ static inline bool xen_pt_has_msix_mapping(XenPCIPassthroughState *s, int bar)void *pci_assign_dev_load_option_rom (PCIDevice *dev,int *size,unsigned int domain,unsigned int bus,unsigned int slot,unsigned int function); -static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) -{ -return (xen_igd_gfx_pt_enabled () - && ((dev->class_code >>0x8 ) ==PCI_CLASS_DISPLAY_VGA )); -}int xen_pt_register_vga_regions (XenHostPCIDevice *dev);int xen_pt_unregister_vga_regions (XenHostPCIDevice *dev); void xen_pt_setup_vga(XenPCIPassthroughState *s, XenHostPCIDevice *dev,
include/hw/xen/xen_igd.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef XEN_IGD_H +#define XEN_IGD_H + +#include "hw/xen/xen-host-pci-device.h" + +typedef struct XenPCIPassthroughState XenPCIPassthroughState ; + +bool xen_igd_gfx_pt_enabled (void ); +void xen_igd_gfx_pt_set (bool value,Error **errp); + +uint32_t igd_read_opregion (XenPCIPassthroughState *s); +void xen_igd_reserve_slot (PCIBus *pci_bus); +void igd_write_opregion (XenPCIPassthroughState *s,uint32_t val); +void xen_igd_passthrough_isa_bridge_create (XenPCIPassthroughState *s, +XenHostPCIDevice *dev); + +static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) +{ +return (xen_igd_gfx_pt_enabled () + && ((dev->class_code >>0x8 ) ==PCI_CLASS_DISPLAY_VGA )); +} + +#endif
accel/xen/xen-all.c +1 -0
@@ -15,6 +15,7 @@#include "hw/xen/xen_native.h" #include "hw/xen/xen-legacy-backend.h" #include "hw/xen/xen_pt.h" +#include "hw/xen/xen_igd.h" #include "chardev/char.h" #include "qemu/accel.h" #include "sysemu/cpus.h"
hw/i386/pc_piix.c +1 -0
@@ -56,6 +56,7 @@#ifdef CONFIG_XEN #include <xen/hvm/hvm_info_table.h> #include "hw/xen/xen_pt.h" +#include "hw/xen/xen_igd.h" #endif #include "hw/xen/xen-x86.h" #include "hw/xen/xen.h"
hw/xen/xen_pt.c +2 -1
@@ -59,7 +59,8 @@#include "hw/pci/pci.h" #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" -#include "xen_pt.h" +#include "hw/xen/xen_pt.h" +#include "hw/xen/xen_igd.h" #include "hw/xen/xen.h" #include "hw/xen/xen-legacy-backend.h" #include "qemu/range.h"
hw/xen/xen_pt_config_init.c +2 -1
@@ -15,7 +15,8 @@#include "qemu/osdep.h" #include "qapi/error.h" #include "qemu/timer.h" -#include "xen_pt.h" +#include "hw/xen/xen_pt.h" +#include "hw/xen/xen_igd.h" #include "hw/xen/xen-legacy-backend.h" #define XEN_PT_MERGE_VALUE (value, data, val_mask) \
hw/xen/xen_pt_graphics.c +2 -1
@@ -3,7 +3,8 @@*/ #include "qemu/osdep.h" #include "qapi/error.h" -#include "xen_pt.h" +#include "hw/xen/xen_pt.h" +#include "hw/xen/xen_igd.h" #include "xen-host-pci-device.h" static unsigned long igd_guest_opregion;
hw/xen/xen_pt_stub.c +1 -1
@@ -6,7 +6,7 @@*/ #include "qemu/osdep.h" -#include "hw/xen/xen_pt.h" +#include "hw/xen/xen_igd.h" #include "qapi/error.h" bool xen_igd_gfx_pt_enabled (void )
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 09/10] hw/xen: Extract 'xen_igd.h' from 'xen_pt.h'
Quoted 8 lines · Philippe Mathieu-Daudé
"
hw/xen/xen_pt.h" requires "hw/xen/xen_native.h" which is target specific. It also declares IGD methods, which are not target specific.Target-agnostic code can use IGD methods. To allow that, extract these methos into a new "
hw/xen/xen_igd.h" header.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 2 lines
---
What license for the new "hw/xen/xen_igd.h" header?
The existing xen_pt.h came in with xen_pt.c (GPLv2) in commit eaab4d60d. I think it has to be GPLv2 (and not later) just like xen_pt.c?
PATCH 10/10 hw/xen: Have most of Xen files become target-agnostic
In reply to Philippe Mathieu-DaudéPrevious commits re-organized the target-specific bits from Xen files. We can now build the common files once instead of per-target.
--- accel/xen/meson.build | 2 +- hw/block/dataplane/meson.build | 2 +- hw/xen/meson.build | 13 ++++--------- 3 files changed, 6 insertions(+), 11 deletions(-)
accel/xen/meson.build +1 -1
@@ -1 +1 @@ -specific_ss.add(when: 'CONFIG_XEN', if_true: files('xen-all.c')) +system_ss.add(when: 'CONFIG_XEN', if_true: files('xen-all.c'))
hw/block/dataplane/meson.build +1 -1
@@ -1,2 +1,2 @@ system_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c')) -specific_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-block.c')) +system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-block.c'))
hw/xen/meson.build +4 -9
@@ -9,15 +9,12 @@ system_ss.add(when: ['CONFIG_XEN_BUS'], if_true: files( system_ss.add(when: ['CONFIG_XEN', xen], if_true: files( 'xen-operations.c', + 'xen-hvm-common.c', + 'xen-mapcache.c', )) -xen_specific_ss = ss.source_set() -xen_specific_ss.add(files( - 'xen-mapcache.c', - 'xen-hvm-common.c', -)) if have_xen_pci_passthrough - xen_specific_ss.add(files( + system_ss.add(files( 'xen-host-pci-device.c', 'xen_pt.c', 'xen_pt_config_init.c',
@@ -26,7 +23,5 @@ if have_xen_pci_passthrough 'xen_pt_msi.c', )) else - xen_specific_ss.add(files('xen_pt_stub.c')) + system_ss.add(files('xen_pt_stub.c')) endif - -specific_ss.add_all(when: ['CONFIG_XEN', xen], if_true: xen_specific_ss)
Signature · 1 line
2.41.0
Quoted 5 lines · Philippe Mathieu-Daudé
Previous commits re-organized the target-specific bits from Xen files. We can now build the common files once instead of per-target.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>