IOREQ feature (+ virtio-mmio) on Arm
cover IOREQ feature (+ virtio-mmio) on Arm
From: Oleksandr Tyshchenko <[email protected]>
Hello all.
The purpose of this patch series is to add IOREQ/DM support to Xen on Arm. You can find an initial discussion at [1] and RFC patch series at [2].
Xen on Arm requires some implementation to forward guest MMIO access to a device model in order to implement virtio-mmio backend or even mediator outside of hypervisor. As Xen on x86 already contains required support this patch series tries to make it common and introduce Arm specific bits plus some new functionality. Patch series is based on Julien's PoC "xen/arm: Add support for Guest IO forwarding to a device emulator". Besides splitting existing IOREQ/DM support and introducing Arm side, the patch series also includes virtio-mmio related changes (last 2 patches for toolstack) for the reviewers to be able to see how the whole picture could look like.
According to the initial discussion there are a few open questions/concerns regarding security, performance in VirtIO solution:
1. virtio-mmio vs virtio-pci, SPI vs MSI, different use-cases require different transport...
2. virtio backend is able to access all guest memory, some kind of protection is needed: 'virtio-iommu in Xen' vs 'pre-shared-memory & memcpys in guest'
3. interface between toolstack and 'out-of-qemu' virtio backend, avoid using Xenstore in virtio backend if possible.
4. a lot of 'foreing mapping' could lead to the memory exhaustion, Julien has some idea regarding that.
Looks like all of them are valid and worth considering, but the first thing which we need on Arm is a mechanism to forward guest IO to a device emulator, so let's focus on it in the first place.
***
There are a lot of changes since RFC series, several critical TODOs were resolved on Arm, Arm code were improved and hardened, but one TODO still remains which is "PIO handling" on Arm. The "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.
I left interface untouched in the following patch "xen/dm: Introduce xendevicemodel_set_irq_level DM op" since there is still an open discussion what interface to use/what information to pass to the hypervisor.
Also I decided to drop the following patch:
"[RFC PATCH V1 07/12] A collection of tweaks to be able to run emulator in driver domain" as I got an advise to write our own policy using FLASK which would cover our use case (with emulator in driver domain) rather than tweak Xen.
***
Patch series [3] was rebased on "1 month old staging branch"
(79c2d51 tools: bump library version numbers) and tested on Renesas Salvator-X board + H3 ES3.0 SoC (Arm64) with virtio-mmio disk backend (we will share it later) running in driver domain and unmodified Linux Guest running on existing virtio-blk driver (frontend). No issues were observed. Guest domain 'reboot/destroy' use-cases work properly. Patch series was only build-tested on x86.
Please note, build-test passed for the following modes:
1. x86: CONFIG_HVM=y / CONFIG_IOREQ_SERVER=y (default)
2. x86: #CONFIG_HVM is not set / #CONFIG_IOREQ_SERVER is not set
3. Arm64: CONFIG_HVM=y / CONFIG_IOREQ_SERVER=y (default)
4. Arm64: CONFIG_HVM=y / #CONFIG_IOREQ_SERVER is not set (!)5. Arm32: CONFIG_HVM=y / CONFIG_IOREQ_SERVER=y (default)
6. Arm32: CONFIG_HVM=y / #CONFIG_IOREQ_SERVER is not set
(!) Please note, the build on Arm32 was broken for the RFC series (see cmpxchg usage in hvm_send_buffered_ioreq()) due to the lack of cmpxchg_64 support on Arm32.
But, there is a patch on review to address this issue: https://patchwork.kernel.org/patch/11715559/
Together with the following patch in this series: "xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()" we are able to fix Arm32 and harden IOREQ code on Arm.
***
Any feedback/help would be highly appreciated.
[1] https://lists.xenproject.org/archives/html/xen-devel/2020-07/msg00825.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2020-08/msg00071.html
[3] https://github.com/otyshchenko1/xen/commits/ioreq_4.14_ml2
Oleksandr Tyshchenko (16):
x86/ioreq: Prepare IOREQ feature for making it common xen/ioreq: Make x86's IOREQ feature common
xen/ioreq: Make x86's hvm_ioreq_needs_completion() common xen/ioreq: Provide alias for the handle_mmio() xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common xen/dm: Make x86's DM feature common
xen/mm: Make x86's XENMEM_resource_ioreq_server handling common arm/ioreq: Introduce arch specific bits for IOREQ/DM features xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm xen/ioreq: Introduce hvm_domain_has_ioreq_server() xen/dm: Introduce xendevicemodel_set_irq_level DM op xen/ioreq: Make x86's invalidate qemu mapcache handling common xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
libxl: Introduce basic virtio-mmio support on Arm
[RFC] libxl: Add support for virtio-disk configuration
MAINTAINERS | 8 +- tools/libs/devicemodel/core.c | 18 + tools/libs/devicemodel/include/xendevicemodel.h | 4 + tools/libs/devicemodel/libxendevicemodel.map | 1 + tools/libxl/Makefile | 4 +- tools/libxl/libxl_arm.c | 94 +- tools/libxl/libxl_create.c | 1 + tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types.idl | 16 + tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_virtio_disk.c | 109 ++ tools/xl/Makefile | 2 +- tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 15 + tools/xl/xl_parse.c | 116 ++ tools/xl/xl_virtio_disk.c | 46 + xen/arch/arm/Kconfig | 1 + xen/arch/arm/Makefile | 2 + xen/arch/arm/dm.c | 67 ++ xen/arch/arm/domain.c | 9 + xen/arch/arm/io.c | 11 +- xen/arch/arm/ioreq.c | 142 +++ xen/arch/arm/p2m.c | 16 + xen/arch/arm/traps.c | 41 +- xen/arch/x86/Kconfig | 1 + xen/arch/x86/hvm/dm.c | 289 +---- xen/arch/x86/hvm/emulate.c | 2 +- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/hypercall.c | 9 +- xen/arch/x86/hvm/intercept.c | 1 + xen/arch/x86/hvm/io.c | 16 +- xen/arch/x86/hvm/ioreq.c | 1426 +--------------------- xen/arch/x86/hvm/stdvga.c | 2 +- xen/arch/x86/hvm/vmx/realmode.c | 1 + xen/arch/x86/hvm/vmx/vvmx.c | 3 +- xen/arch/x86/mm.c | 46 +- xen/arch/x86/mm/p2m.c | 5 +- xen/arch/x86/mm/shadow/common.c | 2 +- xen/common/Kconfig | 3 + xen/common/Makefile | 2 + xen/common/dm.c | 288 +++++ xen/common/ioreq.c | 1433 +++++++++++++++++++++++ xen/common/memory.c | 54 +- xen/include/asm-arm/domain.h | 47 + xen/include/asm-arm/hvm/ioreq.h | 108 ++ xen/include/asm-arm/mm.h | 8 - xen/include/asm-arm/mmio.h | 1 + xen/include/asm-arm/p2m.h | 11 +- xen/include/asm-arm/paging.h | 4 + xen/include/asm-x86/hvm/domain.h | 36 +- xen/include/asm-x86/hvm/io.h | 17 - xen/include/asm-x86/hvm/ioreq.h | 47 +- xen/include/asm-x86/hvm/vcpu.h | 7 - xen/include/asm-x86/mm.h | 4 - xen/include/asm-x86/p2m.h | 3 +- xen/include/public/arch-arm.h | 5 + xen/include/public/hvm/dm_op.h | 15 + xen/include/xen/hypercall.h | 12 + xen/include/xen/ioreq.h | 146 +++ xen/include/xen/sched.h | 2 + xen/include/xsm/dummy.h | 4 +- xen/include/xsm/xsm.h | 6 +- xen/xsm/dummy.c | 2 +- xen/xsm/flask/hooks.c | 5 +- 64 files changed, 2940 insertions(+), 1863 deletions(-) create mode 100644 tools/libxl/libxl_virtio_disk.c create mode 100644 tools/xl/xl_virtio_disk.c create mode 100644 xen/arch/arm/dm.c create mode 100644 xen/arch/arm/ioreq.c create mode 100644 xen/common/dm.c create mode 100644 xen/common/ioreq.c create mode 100644 xen/include/asm-arm/hvm/ioreq.h create mode 100644 xen/include/xen/ioreq.h
Signature · 1 line
2.7.4
PATCH 1/16 x86/ioreq: Prepare IOREQ feature for making it common
From: Oleksandr Tyshchenko <[email protected]>
As a lot of x86 code can be re-used on Arm later on, this patch prepares IOREQ support before moving to the common code. This way we will get almost a verbatim copy for a code movement.
This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- new patch, was split from:
"[RFC PATCH V1 01/12] hvm/ioreq: Make x86's IOREQ feature common"
- fold the check of p->type into hvm_get_ioreq_server_range_type() and make it return success/failure
- remove relocate_portio_handler() call from arch_hvm_ioreq_destroy()
in arch/x86/hvm/ioreq.c - introduce arch_hvm_destroy_ioreq_server()/arch_handle_hvm_io_completion() --- --- xen/arch/x86/hvm/ioreq.c | 117 ++++++++++++++++++++++++++-------------- xen/include/asm-x86/hvm/ioreq.h | 16 ++++++ 2 files changed, 93 insertions(+), 40 deletions(-)
xen/arch/x86/hvm/ioreq.c +77 -40
@@ -170,6 +170,29 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p)return true; } +bool arch_handle_hvm_io_completion (enum hvm_io_completion io_completion) +{ +switch ( io_completion ) + { +case HVMIO_realmode_completion: + { +struct hvm_emulate_ctxt ctxt; + +hvm_emulate_init_once (&ctxt,NULL ,guest_cpu_user_regs ()); +vmx_realmode_emulate_one (&ctxt); +hvm_emulate_writeback (&ctxt); + +break ; + } + +default : +ASSERT_UNREACHABLE (); +break ; + } + +return true; +} +bool handle_hvm_io_completion (struct vcpu *v) {struct domain *d = v->domain;
@@ -209,19 +232,8 @@ bool handle_hvm_io_completion(struct vcpu *v)return handle_pio (vio->io_req.addr, vio->io_req.size, vio->io_req.dir); -case HVMIO_realmode_completion: - { -struct hvm_emulate_ctxt ctxt; - -hvm_emulate_init_once (&ctxt,NULL ,guest_cpu_user_regs ()); -vmx_realmode_emulate_one (&ctxt); -hvm_emulate_writeback (&ctxt); - -break ; - }default : -ASSERT_UNREACHABLE (); -break ; +return arch_handle_hvm_io_completion (io_completion); }return true;
@@ -836,6 +848,12 @@ int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,return rc; } +/* Called when target domain is paused */ +int arch_hvm_destroy_ioreq_server (struct hvm_ioreq_server *s) +{ +return p2m_set_ioreq_server (s->target,0 , s); +} +int hvm_destroy_ioreq_server (struct domain *d,ioservid_t id) {struct hvm_ioreq_server *s;
@@ -855,7 +873,7 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)domain_pause (d); -p2m_set_ioreq_server (d,0 , s); +arch_hvm_destroy_ioreq_server (s);hvm_ioreq_server_disable (s);
@@ -1215,8 +1233,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)struct hvm_ioreq_server *s;unsigned int id; -if ( !relocate_portio_handler (d,0xcf8 ,0xcf8 ,4 ) ) -return ; +arch_hvm_ioreq_destroy (d);spin_lock_recursive (&d->arch.hvm.ioreq_server.lock);
@@ -1239,19 +1256,15 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)spin_unlock_recursive (&d->arch.hvm.ioreq_server.lock); } -struct hvm_ioreq_server *hvm_select_ioreq_server (struct domain *d, -ioreq_t *p) +int hvm_get_ioreq_server_range_type (struct domain *d, +ioreq_t *p, +uint8_t *type, +uint64_t *addr) { -struct hvm_ioreq_server *s; -uint32_t cf8; -uint8_t type; -uint64_t addr; -unsigned int id; +uint32_t cf8 = d->arch.hvm.pci_cf8;if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) -return NULL ; - - cf8 = d->arch.hvm.pci_cf8; +return -EINVAL ; if ( p->type == IOREQ_TYPE_PIO && (p->addr & ~3) == 0xcfc &&
@@ -1264,8 +1277,8 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, reg =hvm_pci_decode_addr (cf8, p->addr, &sbdf);/* PCI config data cycle */ - type =XEN_DMOP_IO_RANGE_PCI ; - addr = ((uint64_t )sbdf.sbdf <<32 ) | reg; + *type =XEN_DMOP_IO_RANGE_PCI ; + *addr = ((uint64_t )sbdf.sbdf <<32 ) | reg;/* AMD extended configuration space access? */ if ( CF8_ADDR_HI(cf8) && d->arch.cpuid->x86_vendor == X86_VENDOR_AMD &&
@@ -1277,16 +1290,30 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,if ( !rdmsr_safe (MSR_AMD64_NB_CFG , msr_val) && (msr_val & (1ULL <<AMD64_NB_CFG_CF8_EXT_ENABLE_BIT )) ) - addr |=CF8_ADDR_HI (cf8); + *addr |=CF8_ADDR_HI (cf8); } }else { - type = (p->type ==IOREQ_TYPE_PIO ) ? -XEN_DMOP_IO_RANGE_PORT :XEN_DMOP_IO_RANGE_MEMORY ; - addr = p->addr; + *type = (p->type ==IOREQ_TYPE_PIO ) ? +XEN_DMOP_IO_RANGE_PORT :XEN_DMOP_IO_RANGE_MEMORY ; + *addr = p->addr; } +return 0 ; +} + +struct hvm_ioreq_server *hvm_select_ioreq_server (struct domain *d, +ioreq_t *p) +{ +struct hvm_ioreq_server *s; +uint8_t type; +uint64_t addr; +unsigned int id; + +if (hvm_get_ioreq_server_range_type (d, p, &type, &addr) ) +return NULL ; + FOR_EACH_IOREQ_SERVER(d, id, s) {struct rangeset *r;
@@ -1351,7 +1378,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) pg = iorp->va;if ( !pg ) -return X86EMUL_UNHANDLEABLE ; +return IOREQ_IO_UNHANDLED ;/* * Return 0 for the cases we can't deal with:
@@ -1381,7 +1408,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)break ;default :gdprintk (XENLOG_WARNING ,"unexpected ioreq size: %u\n" , p->size); -return X86EMUL_UNHANDLEABLE ; +return IOREQ_IO_UNHANDLED ; }spin_lock (&s->bufioreq_lock);
@@ -1391,7 +1418,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) {/* The queue is full: send the iopacket through the normal path. */ spin_unlock (&s->bufioreq_lock); -return X86EMUL_UNHANDLEABLE ; +return IOREQ_IO_UNHANDLED ; } pg->buf_ioreq[pg->ptrs.write_pointer %IOREQ_BUFFER_SLOT_NUM ] = bp;
@@ -1422,7 +1449,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)notify_via_xen_event_channel (d, s->bufioreq_evtchn);spin_unlock (&s->bufioreq_lock); -return X86EMUL_OKAY ; +return IOREQ_IO_HANDLED ; } int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,
@@ -1438,7 +1465,7 @@ int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,return hvm_send_buffered_ioreq (s, proto_p);if (unlikely (!vcpu_start_shutdown_deferral (curr)) ) -return X86EMUL_RETRY ; +return IOREQ_IO_RETRY ; list_for_each_entry ( sv, &s->ioreq_vcpu_list,
@@ -1478,11 +1505,11 @@ int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,notify_via_xen_event_channel (d, port); sv->pending = true; -return X86EMUL_RETRY ; +return IOREQ_IO_RETRY ; } } -return X86EMUL_UNHANDLEABLE ; +return IOREQ_IO_UNHANDLED ; }unsigned int hvm_broadcast_ioreq (ioreq_t *p,bool buffered)
@@ -1496,7 +1523,7 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered)if ( !s->enabled )continue ; -if (hvm_send_ioreq (s, p, buffered) ==X86EMUL_UNHANDLEABLE ) +if (hvm_send_ioreq (s, p, buffered) ==IOREQ_IO_UNHANDLED ) failed++; }
@@ -1515,11 +1542,21 @@ static int hvm_access_cf8(return X86EMUL_UNHANDLEABLE ; } +void arch_hvm_ioreq_init (struct domain *d) +{ +register_portio_handler (d,0xcf8 ,4 , hvm_access_cf8); +} + +void arch_hvm_ioreq_destroy (struct domain *d) +{ + +} +void hvm_ioreq_init (struct domain *d) {spin_lock_init (&d->arch.hvm.ioreq_server.lock); -register_portio_handler (d,0xcf8 ,4 , hvm_access_cf8); +arch_hvm_ioreq_init (d); }/*
xen/include/asm-x86/hvm/ioreq.h +16 -0
@@ -55,6 +55,22 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered);void hvm_ioreq_init (struct domain *d); +int arch_hvm_destroy_ioreq_server (struct hvm_ioreq_server *s); + +bool arch_handle_hvm_io_completion (enum hvm_io_completion io_completion); + +int hvm_get_ioreq_server_range_type (struct domain *d, +ioreq_t *p, +uint8_t *type, +uint64_t *addr); + +void arch_hvm_ioreq_init (struct domain *d); +void arch_hvm_ioreq_destroy (struct domain *d); + +#define IOREQ_IO_HANDLED X86EMUL_OKAY +#define IOREQ_IO_UNHANDLED X86EMUL_UNHANDLEABLE +#define IOREQ_IO_RETRY X86EMUL_RETRY +#endif /* __ASM_X86_HVM_IOREQ_H__ */ /*
Signature · 1 line
2.7.4
Re: [PATCH V1 01/16] x86/ioreq: Prepare IOREQ feature for making it common
Quoted 8 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
As a lot of x86 code can be re-used on Arm later on, this patch prepares IOREQ support before moving to the common code. This way we will get almost a verbatim copy for a code movement.
This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.
This is all fine, but you should then go on and explain what you're doing, and why (at which point it may become obvious that it would be more helpful to split this into a couple of steps). In particular something as suspicious as ...
Quoted 7 lines
Changes RFC -> V1:
- new patch, was split from:
"[RFC PATCH V1 01/12] hvm/ioreq: Make x86's IOREQ feature common"
- fold the check ofp->typeintohvm_get_ioreq_server_range_type()and make it return success/failure
- removerelocate_portio_handler()call fromarch_hvm_ioreq_destroy()in arch/x86/hvm/ioreq.c
... this (see below).
xen/arch/x86/hvm/ioreq.c static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p) · line 173
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +1
-0@@ -170,6 +170,29 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p)return true; } +bool arch_handle_hvm_io_completion (enum hvm_io_completion io_completion)
Do we need "handle" in here? Without it, I'd also not have to ask about moving hvm further to the front of the name...
xen/arch/x86/hvm/ioreq.c int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling, · line 855
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c +5
-0@@ -836,6 +848,12 @@ int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,return rc; } +/* Called when target domain is paused */ +int arch_hvm_destroy_ioreq_server (struct hvm_ioreq_server *s) +{ +return p2m_set_ioreq_server (s->target,0 , s); +}
Why return "int" when ...
xen/arch/x86/hvm/ioreq.c int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id) · line 876
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +1
-1@@ -855,7 +873,7 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)domain_pause (d); -p2m_set_ioreq_server (d,0 , s); +arch_hvm_destroy_ioreq_server (s);
... the result has been ignored anyway? Or otherwise I guess you'd want to add error handling here (but then the result of p2m_set_ioreq_server() should still get ignored, for backwards compatibility).
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1236
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +1
-2@@ -1215,8 +1233,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)struct hvm_ioreq_server *s;unsigned int id; -if ( !relocate_portio_handler (d,0xcf8 ,0xcf8 ,4 ) ) -return ; +arch_hvm_ioreq_destroy (d);
So the call to relocate_portio_handler() simply goes away. No replacement, no explanation?
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1260
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c +2
-2@@ -1239,19 +1256,15 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)spin_unlock_recursive (&d->arch.hvm.ioreq_server.lock); } -struct hvm_ioreq_server *hvm_select_ioreq_server (struct domain *d, -ioreq_t *p) +int hvm_get_ioreq_server_range_type(struct domain *d, + ioreq_t *p,
At least p, but perhaps also d can gain const?
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1262
Quoted 2 lines
xen/arch/x86/hvm/ioreq.c +2
-0+uint8_t *type, + uint64_t *addr)
By the name the function returns a type for a range (albeit without it being clear where the two bounds of such a range actually live). By the implementation is looks more like you mean "range_and_type", albeit still without there really being a range passed back to the caller. Therefore I think I need some clarification on what's intended before even being able to suggest something. From ...
xen/arch/x86/hvm/ioreq.c struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, · line 1315
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+struct hvm_ioreq_server *hvm_select_ioreq_server (struct domain *d, +ioreq_t *p) +{ +struct hvm_ioreq_server *s; +uint8_t type; +uint64_t addr; +unsigned int id; + +if (hvm_get_ioreq_server_range_type (d, p, &type, &addr) ) +return NULL ;
... this use - maybe hvm_ioreq_server_get_type_addr() (albeit I don't like this name very much)?
xen/arch/x86/hvm/ioreq.c static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) · line 1381
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +1
-1@@ -1351,7 +1378,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) pg = iorp->va;if ( !pg ) -return X86EMUL_UNHANDLEABLE ; +return IOREQ_IO_UNHANDLED ;
At this example - why the IO infix, duplicating the prefix? I'd suggest to either drop it (if the remaining identifiers are deemed unambiguous enough) or use e.g. IOREQ_STATUS_*.
xen/arch/x86/hvm/ioreq.c static int hvm_access_cf8( · line 1553
Quoted 13 lines
xen/arch/x86/hvm/ioreq.c +9
-0@@ -1515,11 +1542,21 @@ static int hvm_access_cf8(return X86EMUL_UNHANDLEABLE ; } +void arch_hvm_ioreq_init (struct domain *d) +{ +register_portio_handler (d,0xcf8 ,4 , hvm_access_cf8); +} + +void arch_hvm_ioreq_destroy (struct domain *d) +{ + +}
Stray blank line?
Jan
Re: [PATCH V1 01/16] x86/ioreq: Prepare IOREQ feature for making it common
On 14.09.20 16:52, Jan Beulich wrote:
Hi Jan
Quoted 7 lines · Oleksandr Tyshchenko
Quoted 6 lines
From: Oleksandr Tyshchenko <[email protected]>
As a lot of x86 code can be re-used on Arm later on, this patch prepares IOREQ support before moving to the common code. This way we will get almost a verbatim copy for a code movement.
Quoted 5 lines
Quoted 2 lines
This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.
This is all fine, but you should then go on and explain what you're doing, and why (at which point it may become obvious that it would be more helpful to split this into a couple of steps).
Got it. Will add an explanation.
Quoted 18 lines
In particular
something as suspicious as ...Quoted 7 lines
Changes RFC -> V1:
- new patch, was split from:
"[RFC PATCH V1 01/12] hvm/ioreq: Make x86's IOREQ feature common"
- fold the check ofp->typeintohvm_get_ioreq_server_range_type()and make it return success/failure
- removerelocate_portio_handler()call fromarch_hvm_ioreq_destroy()inarch/x86/hvm/ioreq.c... this (see below).
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +0
-0@@ -170,6 +170,29 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p)return true; }
Quoted 3 lines
xen/arch/x86/hvm/ioreq.c static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p) · line 173
Quoted 1 line
xen/arch/x86/hvm/ioreq.c +1
-0+bool arch_handle_hvm_io_completion (enum hvm_io_completion io_completion)Do we need "handle" in here? Without it, I'd also not have to ask about moving hvm further to the front of the name...
For me without "handle" it will sound a bit confusing because of the enum type which has a similar name but without "arch" prefix:
bool arch_hvm_io_completion(enum hvm_io_completion io_completion)
Shall I then move "hvm" to the front of the name here?
Quoted 14 lines
xen/arch/x86/hvm/ioreq.c int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling, · line 855
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +5
-0@@ -836,6 +848,12 @@ int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,return rc; } +/* Called when target domain is paused */ +int arch_hvm_destroy_ioreq_server (struct hvm_ioreq_server *s) +{ +return p2m_set_ioreq_server (s->target,0 , s); +}Why return "int" when ...
Quoted 2 lines
xen/arch/x86/hvm/ioreq.c +0
-0@@ -855,7 +873,7 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id) · line 876
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +1
-1domain_pause (d); -p2m_set_ioreq_server (d,0 , s); +arch_hvm_destroy_ioreq_server (s);... the result has been ignored anyway? Or otherwise I guess you'd want to add error handling here (but then the result of
p2m_set_ioreq_server()should still get ignored, for backwards compatibility).
I didn't have a plan to add error handling here. Agree, will make arch_hvm_destroy_ioreq_server() returning void.
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1236
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c +1
-2@@ -1215,8 +1233,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)struct hvm_ioreq_server *s;unsigned int id; -if ( !relocate_portio_handler (d,0xcf8 ,0xcf8 ,4 ) ) -return ; +arch_hvm_ioreq_destroy (d);So the call to
relocate_portio_handler()simply goes away. No replacement, no explanation?
As I understand from the review comment on that for the RFC patch, there is no a lot of point of keeping this. Indeed, looking at the code I got the same opinion. I should have added an explanation in the commit description at least. Or shall I return the call back?
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1260
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c +2
-2@@ -1239,19 +1256,15 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)spin_unlock_recursive (&d->arch.hvm.ioreq_server.lock); } -struct hvm_ioreq_server *hvm_select_ioreq_server (struct domain *d, -ioreq_t *p) +int hvm_get_ioreq_server_range_type(struct domain *d, + ioreq_t *p,At least p, but perhaps also d can gain const?
Agree, will add.
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1262
Quoted 3 lines
xen/arch/x86/hvm/ioreq.c +2
-0+uint8_t *type, + uint64_t *addr)By the name the function returns a type for a range (albeit without it being clear where the two bounds of such a range actually live). By the implementation is looks more like you mean "
range_and_type", albeit still without there really being a range passed back to the caller. Therefore I think I need some clarification on what's intended before even being able to suggest something.
This function is just an attempt to split arch specific things (cf8 handling) from "common" hvm_select_ioreq_server().
Quoted 14 lines
From ...
xen/arch/x86/hvm/ioreq.c struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, · line 1315
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+struct hvm_ioreq_server *hvm_select_ioreq_server (struct domain *d, +ioreq_t *p) +{ +struct hvm_ioreq_server *s; +uint8_t type; +uint64_t addr; +unsigned int id; + +if (hvm_get_ioreq_server_range_type (d, p, &type, &addr) ) +return NULL ;... this use - maybe
hvm_ioreq_server_get_type_addr()(albeit I don't like this name very much)?
Yes, hvm_ioreq_server_get_type_addr() better represents what function does.
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) · line 1381
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +1
-1@@ -1351,7 +1378,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) pg = iorp->va;if ( !pg ) -return X86EMUL_UNHANDLEABLE ; +return IOREQ_IO_UNHANDLED ;At this example - why the IO infix, duplicating the prefix? I'd suggest to either drop it (if the remaining identifiers are deemed unambiguous enough) or use e.g. IOREQ_STATUS_*.
Agree, I would prefer IOREQ_STATUS_*
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +0
-0@@ -1515,11 +1542,21 @@ static int hvm_access_cf8(return X86EMUL_UNHANDLEABLE ; }
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c static int hvm_access_cf8( · line 1553
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c +9
-0+void arch_hvm_ioreq_init (struct domain *d) +{ +register_portio_handler (d,0xcf8 ,4 , hvm_access_cf8); +} + +void arch_hvm_ioreq_destroy (struct domain *d) +{ + +}Stray blank line?
Will remove.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 01/16] x86/ioreq: Prepare IOREQ feature for making it common
Quoted 8 lines · Oleksandr
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Oleksandr Tyshchenko
xen/arch/x86/hvm/ioreq.c +0
-0@@ -170,6 +170,29 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p)return true; }
Quoted 7 lines
Quoted 3 lines
xen/arch/x86/hvm/ioreq.c static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p) · line 173
Quoted 1 line
xen/arch/x86/hvm/ioreq.c +1
-0+bool arch_handle_hvm_io_completion (enum hvm_io_completion io_completion)Do we need "handle" in here? Without it, I'd also not have to ask about moving hvm further to the front of the name...
For me without "handle" it will sound a bit confusing because of the enum type which
has a similar name but without "arch" prefix:
boolarch_hvm_io_completion(enum hvm_io_completion io_completion)
Every function handles something; there's no point including "handle" in every name. Or else we'd have handle_memset() instead of just memset(), for example.
Quoted 1 line
Shall I then move "hvm" to the front of the name here?
As per comments on later patches, I think we want to consider dropping hvm prefixes or infixes altogether from the functions involved here.
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1236
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +1
-2@@ -1215,8 +1233,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)struct hvm_ioreq_server *s;unsigned int id; -if ( !relocate_portio_handler (d,0xcf8 ,0xcf8 ,4 ) ) -return ; +arch_hvm_ioreq_destroy (d);So the call to
relocate_portio_handler()simply goes away. No replacement, no explanation?
Quoted 6 lines
As I understand from the review comment on that for the RFC patch, there is no
a lot of point of keeping this. Indeed, looking at the code I got the same opinion.
I should have added an explanation in the commit description at least. Or shall I return the call back?
If there's a reason to drop it (which I can't see, but I also don't recall seeing the discussion you're mentioning), then doing so should be a separate patch with suitable reasoning. In the patch here you definitely should only transform what's already there.
Jan
Re: [PATCH V1 01/16] x86/ioreq: Prepare IOREQ feature for making it common
On 21.09.20 15:31, Jan Beulich wrote:
Hi
Quoted 12 lines · Oleksandr
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Oleksandr Tyshchenko
xen/arch/x86/hvm/ioreq.c static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p) · line 173
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +1
-0@@ -170,6 +170,29 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p)return true; } +bool arch_handle_hvm_io_completion (enum hvm_io_completion io_completion)Do we need "handle" in here? Without it, I'd also not have to ask about moving hvm further to the front of the name...
Quoted 7 lines
Quoted 4 lines
For me without "handle" it will sound a bit confusing because of the enum type which
has a similar name but without "arch" prefix:
boolarch_hvm_io_completion(enum hvm_io_completion io_completion)Every function handles something; there's no point including "handle" in every name. Or else we'd have
handle_memset()instead of justmemset(), for example.
Got it. Will remove "handle" here.
Quoted 19 lines
Quoted 2 lines
Shall I then move "hvm" to the front of the name here?
As per comments on later patches, I think we want to consider dropping hvm prefixes or infixes altogether from the functions involved here.
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1236
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +1
-2@@ -1215,8 +1233,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)struct hvm_ioreq_server *s;unsigned int id; -if ( !relocate_portio_handler (d,0xcf8 ,0xcf8 ,4 ) ) -return ; +arch_hvm_ioreq_destroy (d);So the call to
relocate_portio_handler()simply goes away. No replacement, no explanation?Quoted 6 lines
As I understand from the review comment on that for the RFC patch, there is no
a lot of point of keeping this. Indeed, looking at the code I got the same opinion.
I should have added an explanation in the commit description at least. Or shall I return the call back?
Quoted 5 lines
If there's a reason to drop it (which I can't see, but I also don't recall seeing the discussion you're mentioning), then doing so should be a separate patch with suitable reasoning. In the patch here you definitely should only transform what's already there.
Sounds reasonable. Please see the comment below relocate_portio_handler() here:
https://www.mail-archive.com/[email protected]/msg78512.html
However, I might interpret the request incorrectly.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 01/16] x86/ioreq: Prepare IOREQ feature for making it common
Quoted 24 lines · Oleksandr
Quoted 18 lines · Jan Beulich
Quoted 11 lines · Oleksandr
Quoted 10 lines · Jan Beulich
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1236
Quoted 7 lines · Oleksandr Tyshchenko
xen/arch/x86/hvm/ioreq.c +1
-2@@ -1215,8 +1233,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)struct hvm_ioreq_server *s;unsigned int id; -if ( !relocate_portio_handler (d,0xcf8 ,0xcf8 ,4 ) ) -return ; +arch_hvm_ioreq_destroy (d);So the call to
relocate_portio_handler()simply goes away. No replacement, no explanation?Quoted 6 lines
As I understand from the review comment on that for the RFC patch, there is no
a lot of point of keeping this. Indeed, looking at the code I got the same opinion.
I should have added an explanation in the commit description at least. Or shall I return the call back?Quoted 5 lines
If there's a reason to drop it (which I can't see, but I also don't recall seeing the discussion you're mentioning), then doing so should be a separate patch with suitable reasoning. In the patch here you definitely should only transform what's already there.
Quoted 5 lines
Sounds reasonable. Please see the comment below
relocate_portio_handler()here:
https://www.mail-archive.com/[email protected]/msg78512.htmlHowever, I might interpret the request incorrectly.
I'm afraid you do: The way you've coded it the function was a no-op. But that's because you broke the caller by not bailing from hvm_destroy_all_ioreq_servers() if relocate_portio_handler() returned false. IOW you did assume that moving the "return" statement into an inline function would have an effect on its caller(s). For questions like this one it also often helps to look at the commit introducing the construct in question (b3344bb1cae0 in this case): Chances are that the description helps, albeit I agree there are many cases (particularly the farther you get into distant past) where it isn't of much help.
Jan
Re: [PATCH V1 01/16] x86/ioreq: Prepare IOREQ feature for making it common
On 21.09.20 16:29, Jan Beulich wrote:
Hi
Quoted 30 lines · Oleksandr
Quoted 24 lines · Jan Beulich
Quoted 18 lines · Oleksandr
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Oleksandr Tyshchenko
xen/arch/x86/hvm/ioreq.c void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1236
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +1
-2@@ -1215,8 +1233,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)struct hvm_ioreq_server *s;unsigned int id; -if ( !relocate_portio_handler (d,0xcf8 ,0xcf8 ,4 ) ) -return ; +arch_hvm_ioreq_destroy (d);So the call to
relocate_portio_handler()simply goes away. No replacement, no explanation?Quoted 6 lines
As I understand from the review comment on that for the RFC patch, there is no
a lot of point of keeping this. Indeed, looking at the code I got the same opinion.
I should have added an explanation in the commit description at least. Or shall I return the call back?Quoted 5 lines
If there's a reason to drop it (which I can't see, but I also don't recall seeing the discussion you're mentioning), then doing so should be a separate patch with suitable reasoning. In the patch here you definitely should only transform what's already there.
Quoted 5 lines
Sounds reasonable. Please see the comment below
relocate_portio_handler()here:
https://www.mail-archive.com/[email protected]/msg78512.htmlHowever, I might interpret the request incorrectly.
Quoted 10 lines
I'm afraid you do: The way you've coded it the function was a no-op. But that's because you broke the caller by not bailing from
hvm_destroy_all_ioreq_servers()ifrelocate_portio_handler()returned false. IOW you did assume that moving the "return" statement into an inline function would have an effect on its caller(s). For questions like this one it also often helps to look at the commit introducing the construct in question (b3344bb1cae0in this case): Chances are that the description helps, albeit I agree there are many cases (particularly the farther you get into distant past) where it isn't of much help.
Hmm, now it's clear to me what I did wrong. By calling relocate_portio_handler() here we don't really want to relocate something, we just use it as a flag to indicate whether we need to actually release IOREQ resources down the hvm_destroy_all_ioreq_servers(). Thank you for the explanation, it wasn't obvious to me at the beginning. But, now the question is how to do it in a correct way and retain current behavior (to not break callers)?
I see two options here:
1. Place the check of relocate_portio_handler() in arch_hvm_ioreq_destroy() and make the later returning bool. The "common" hvm_destroy_all_ioreq_servers() will check for the return value and bail out if false.
2. Don't use relocate_portio_handler(), instead introduce a flag into struct hvm_domain's ioreq_server sub-structure.
Personally I don't like much the option 1 and option 2 is a little bit overhead.
What do you think?
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 01/16] x86/ioreq: Prepare IOREQ feature for making it common
Quoted 60 lines · Oleksandr
Quoted 30 lines · Jan Beulich
Quoted 24 lines · Oleksandr
Quoted 18 lines · Jan Beulich
Quoted 11 lines · Oleksandr
Quoted 10 lines · Jan Beulich
Review void hvm_destroy_all_ioreq_servers(struct domain *d) · line 1236
Quoted 7 lines · Oleksandr Tyshchenko
(quoted diff) +1
-2@@ -1215,8 +1233,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d) struct hvm_ioreq_server *s; unsigned int id; - if ( !relocate_portio_handler(d, 0xcf8, 0xcf8, 4) ) - return; + arch_hvm_ioreq_destroy(d);So the call to
relocate_portio_handler()simply goes away. No replacement, no explanation?Quoted 6 lines
As I understand from the review comment on that for the RFC patch, there is no
a lot of point of keeping this. Indeed, looking at the code I got the same opinion.
I should have added an explanation in the commit description at least. Or shall I return the call back?Quoted 5 lines
If there's a reason to drop it (which I can't see, but I also don't recall seeing the discussion you're mentioning), then doing so should be a separate patch with suitable reasoning. In the patch here you definitely should only transform what's already there.
Quoted 5 lines
Sounds reasonable. Please see the comment below
relocate_portio_handler()here:
https://www.mail-archive.com/[email protected]/msg78512.htmlHowever, I might interpret the request incorrectly.
Quoted 10 lines
I'm afraid you do: The way you've coded it the function was a no-op. But that's because you broke the caller by not bailing from
hvm_destroy_all_ioreq_servers()ifrelocate_portio_handler()returned false. IOW you did assume that moving the "return" statement into an inline function would have an effect on its caller(s). For questions like this one it also often helps to look at the commit introducing the construct in question (b3344bb1cae0in this case): Chances are that the description helps, albeit I agree there are many cases (particularly the farther you get into distant past) where it isn't of much help.Hmm, now it's clear to me what I did wrong. By calling
relocate_portio_handler()here we don't really want to relocate something, we just use it as a flag to indicate whether we need to actually release IOREQ resources down thehvm_destroy_all_ioreq_servers(). Thank you for the explanation, it wasn't obvious to me at the beginning. But, now the question is how to do it in a correct way and retain current behavior (to not break callers)?I see two options here:
1. Place the check ofrelocate_portio_handler()inarch_hvm_ioreq_destroy()and make the later returning bool. The "common"hvm_destroy_all_ioreq_servers()will check for the
return value and bail out if false.
2. Don't userelocate_portio_handler(), instead introduce a flag into struct hvm_domain'sioreq_serversub-structure.
Quoted 2 lines
Personally I don't like much the option 1 and option 2 is a little bit overhead.
Well, 1 is what matches current behavior, so I'd advocate for you not changing the abstract model. Or else, again, change the abstract model in a separate prereq patch.
Jan
Re: [PATCH V1 01/16] x86/ioreq: Prepare IOREQ feature for making it common
In reply to Oleksandr TyshchenkoHi,
Quoted 5 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
As a lot of x86 code can be re-used on Arm later on, this patch prepares IOREQ support before moving to the common code. This way we will get almost a verbatim copy for a code movement.
FWIW, I agree with Jan that we need more details what and why you are going it. It would be worth considering to split in smaller patch.
Quoted 5 lines
This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.
Signed-off-by Julien Grall <[email protected]>
Usually the first signed-off is the author of the patch. However, this patch look quite far off from what I originally wrote.
So I don't feel my signed-off-by is actually warrant here. If you want to credit me, then you can mention it in the commit message.
Quoted 2 lines
Signed-off-by Oleksandr Tyshchenko <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 01/16] x86/ioreq: Prepare IOREQ feature for making it common
Quoted 1 line · Julien Grall
Hi,
Hi Julien
Quoted 9 lines · Oleksandr Tyshchenko
Quoted 5 lines
From: Oleksandr Tyshchenko <[email protected]>
As a lot of x86 code can be re-used on Arm later on, this patch prepares IOREQ support before moving to the common code. This way we will get almost a verbatim copy for a code movement.
FWIW, I agree with Jan that we need more details what and why you are going it. It would be worth considering to split in smaller patch.
ok
Quoted 11 lines
Quoted 7 lines
This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.
Signed-off-by Julien Grall <[email protected]>Usually the first signed-off is the author of the patch. However, this patch look quite far off from what I originally wrote.
So I don't feel my signed-off-by is actually warrant here. If you want to credit me, then you can mention it in the commit message.
This is related to all patches is this series. This patch series is the second attempt (the first was RFC) to make IOREQ support common and it became quite different from the initial commit.
I am sorry, I got completely lost whether the particular patch in this series is close to what you originally wrote or far from, I mean whether I should retain your SoB and whether I should drop it. So in order *not to make a mistake* is such an important question, I decided to add your SoB to each patch in this series and also add a note to each patch describing where this series came from.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Oleksandr Tyshchenko <[email protected]>Cheers,
Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH 2/16 xen/ioreq: Make x86's IOREQ feature common
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
As a lot of x86 code can be re-used on Arm later on, this patch moves previously prepared IOREQ support to the common code.
The code movement is almost a verbatim copy with re-ordering the headers alphabetically.
This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- was split into three patches:
- x86/ioreq: Prepare IOREQ feature for making it common
- xen/ioreq: Make x86's IOREQ feature common
- xen/ioreq: Make x86's hvm_ioreq_needs_completion() common
- update MAINTAINERS file
- do not use a separate subdir for the IOREQ stuff, move it to:
- xen/common/ioreq.c
- xen/include/xen/ioreq.h
- update x86's files to include xen/ioreq.h
- remove unneeded headers in arch/x86/hvm/ioreq.c
- re-order the headers alphabetically in common/ioreq.c
- update common/ioreq.c according to the newly introduced arch functions:
arch_hvm_destroy_ioreq_server()/arch_handle_hvm_io_completion()
---
--- MAINTAINERS | 8 +- xen/arch/x86/Kconfig | 1 + xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/emulate.c | 2 +- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/io.c | 2 +- xen/arch/x86/hvm/ioreq.c | 1425 +-------------------------------------- xen/arch/x86/hvm/stdvga.c | 2 +- xen/arch/x86/hvm/vmx/vvmx.c | 3 +- xen/arch/x86/mm.c | 2 +- xen/arch/x86/mm/shadow/common.c | 2 +- xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/ioreq.c | 1410 ++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/ioreq.h | 35 +- xen/include/xen/ioreq.h | 82 +++ 16 files changed, 1533 insertions(+), 1449 deletions(-) create mode 100644 xen/common/ioreq.c create mode 100644 xen/include/xen/ioreq.h
MAINTAINERS +7 -1
@@ -333,6 +333,13 @@ X: xen/drivers/passthrough/vtd/ X: xen/drivers/passthrough/device_tree.c F: xen/include/xen/iommu.h +I/O EMULATION (IOREQ) +M: Paul Durrant <[email protected]> +S: Supported +F: xen/common/ioreq.c +F: xen/include/xen/ioreq.h +F: xen/include/public/hvm/ioreq.h + KCONFIG M: Doug Goldstein <[email protected]> S: Supported
@@ -549,7 +556,6 @@ F: xen/arch/x86/hvm/ioreq.c F: xen/include/asm-x86/hvm/emulate.h F: xen/include/asm-x86/hvm/io.h F: xen/include/asm-x86/hvm/ioreq.h -F: xen/include/public/hvm/ioreq.h X86 MEMORY MANAGEMENT M: Jan Beulich <[email protected]>
xen/arch/x86/Kconfig +1 -0
@@ -91,6 +91,7 @@ config PV_LINEAR_PT config HVM def_bool !PV_SHIM_EXCLUSIVE + select IOREQ_SERVER prompt "HVM support" ---help--- Interfaces to support HVM domains. HVM domains require hardware
xen/arch/x86/hvm/dm.c +1 -1
@@ -17,12 +17,12 @@#include <xen/event.h> #include <xen/guest_access.h> #include <xen/hypercall.h> +#include <xen/ioreq.h> #include <xen/nospec.h> #include <xen/sched.h> #include <asm/hap.h> #include <asm/hvm/cacheattr.h> -#include <asm/hvm/ioreq.h> #include <asm/shadow.h> #include <xsm/xsm.h>
xen/arch/x86/hvm/emulate.c +1 -1
@@ -10,6 +10,7 @@*/ #include <xen/init.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/sched.h> #include <xen/paging.h>
@@ -20,7 +21,6 @@#include <asm/xstate.h> #include <asm/hvm/emulate.h> #include <asm/hvm/hvm.h> -#include <asm/hvm/ioreq.h> #include <asm/hvm/monitor.h> #include <asm/hvm/trace.h> #include <asm/hvm/support.h>
xen/arch/x86/hvm/hvm.c +1 -1
@@ -20,6 +20,7 @@#include <xen/ctype.h> #include <xen/init.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/trace.h> #include <xen/sched.h>
@@ -64,7 +65,6 @@#include <asm/hvm/trace.h> #include <asm/hvm/nestedhvm.h> #include <asm/hvm/monitor.h> -#include <asm/hvm/ioreq.h> #include <asm/hvm/viridian.h> #include <asm/hvm/vm_event.h> #include <asm/altp2m.h>
xen/arch/x86/hvm/io.c +1 -1
@@ -19,6 +19,7 @@*/ #include <xen/init.h> +#include <xen/ioreq.h> #include <xen/mm.h> #include <xen/lib.h> #include <xen/errno.h>
@@ -35,7 +36,6 @@#include <asm/shadow.h> #include <asm/p2m.h> #include <asm/hvm/hvm.h> -#include <asm/hvm/ioreq.h> #include <asm/hvm/support.h> #include <asm/hvm/vpt.h> #include <asm/hvm/vpic.h>
xen/arch/x86/hvm/ioreq.c +17 -1408
1,465 lines not on this page · raw message
xen/arch/x86/hvm/stdvga.c +1 -1
@@ -27,10 +27,10 @@* can have side effects. */ +#include <xen/ioreq.h> #include <xen/types.h> #include <xen/sched.h> #include <xen/domain_page.h> -#include <asm/hvm/ioreq.h> #include <asm/hvm/support.h> #include <xen/numa.h> #include <xen/paging.h>
xen/arch/x86/hvm/vmx/vvmx.c +2 -1
@@ -19,10 +19,11 @@* */ +#include <xen/ioreq.h> +#include <asm/types.h> #include <asm/mtrr.h> #include <asm/p2m.h> -#include <asm/hvm/ioreq.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vvmx.h> #include <asm/hvm/nestedhvm.h>
xen/arch/x86/mm.c +1 -1
@@ -100,6 +100,7 @@*/ #include <xen/init.h> +#include <xen/ioreq.h> #include <xen/kernel.h> #include <xen/lib.h> #include <xen/mm.h>
@@ -141,7 +142,6 @@#include <asm/io_apic.h> #include <asm/pci.h> #include <asm/guest.h> -#include <asm/hvm/ioreq.h> #include <asm/hvm/grant_table.h> #include <asm/pv/domain.h>
xen/arch/x86/mm/shadow/common.c +1 -1
@@ -20,6 +20,7 @@* along with this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <xen/ioreq.h> #include <xen/types.h> #include <xen/mm.h> #include <xen/trace.h>
@@ -34,7 +35,6 @@#include <asm/current.h> #include <asm/flushtlb.h> #include <asm/shadow.h> -#include <asm/hvm/ioreq.h> #include <xen/numa.h> #include "private.h"
xen/common/Kconfig +3 -0
@@ -139,6 +139,9 @@ config HYPFS_CONFIG Disable this option in case you want to spare some memory or you want to hide the .config contents from dom0. +config IOREQ_SERVER + bool + config KEXEC bool "kexec support" default y
xen/common/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_GRANT_TABLE) += grant_table.o obj-y += guestcopy.o obj-bin-y += gunzip.init.o obj-$(CONFIG_HYPFS) += hypfs.o +obj-$(CONFIG_IOREQ_SERVER) += ioreq.o obj-y += irq.o obj-y += kernel.o obj-y += keyhandler.o
xen/common/ioreq.c new file +1410 -0
1,386 lines not on this page · raw message
xen/include/xen/ioreq.h new file +82 -0
82 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Quoted 7 lines · Oleksandr Tyshchenko
--- MAINTAINERS | 8 +- xen/arch/x86/Kconfig | 1 + xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/emulate.c | 2 +- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/io.c | 2 +-
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c | 1425 +-------------------------------------- xen/arch/x86/hvm/stdvga.c | 2 +- xen/arch/x86/hvm/vmx/vvmx.c | 3 +- xen/arch/x86/mm.c | 2 +- xen/arch/x86/mm/shadow/common.c | 2 +- xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/ioreq.c | 1410 ++++++++++++++++++++++++++++++++++++++
This suggests it was almost the entire file which got moved. It would be really nice if you could convince git to show the diff here, rather than removal and addition of 1400 lines.
Additionally I wonder whether what's left in the original file wouldn't better become inline functions now. If this was done in the previous patch, the change would be truly a rename then, I think.
xen/include/asm-x86/hvm/ioreq.h line 24
Quoted 12 lines
xen/include/asm-x86/hvm/ioreq.h +3
-3@@ -19,41 +19,12 @@#ifndef __ASM_X86_HVM_IOREQ_H__#define __ASM_X86_HVM_IOREQ_H__ -bool hvm_io_pending (struct vcpu *v); -bool handle_hvm_io_completion (struct vcpu *v); -bool is_ioreq_server_page (struct domain *d,const struct page_info *page); +#include <asm/hvm/emulate.h> +#include <asm/hvm/hvm.h> +#include <asm/hvm/vmx/vmx.h>
Are all three really needed here? Especially the last one strikes me as odd.
Quoted 13 lines
xen/include/xen/ioreq.h new file +10
-0@@ -0,0 +1,82 @@ +/* +* ioreq.h: Hardware virtual machine assist interface definitions. +* +* Copyright (c) 2016 Citrix Systems Inc. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT
xen/include/xen/ioreq.h line 20
Quoted 10 lines
xen/include/xen/ioreq.h new file +10
-0+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __IOREQ_H__ +#define __IOREQ_H__
__XEN_IOREQ_H__ please.
xen/include/xen/ioreq.h line 24
Quoted 3 lines
xen/include/xen/ioreq.h new file +3
-0+#include <xen/sched.h> + +#include <asm/hvm/ioreq.h>
Is this include really needed here (i.e. by the code further down in the file, and hence by everyone including this header), or rather just in a few specific .c files?
xen/include/xen/ioreq.h line 27
Quoted 2 lines
xen/include/xen/ioreq.h new file +2
-0+#define GET_IOREQ_SERVER (d, id) \ + (d)->arch.hvm.ioreq_server.server[id]
arch.hvm.* feels like a layering violation when used in this header.
Jan
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
On 14.09.20 17:17, Jan Beulich wrote:
Hi Jan
Quoted 16 lines · Oleksandr Tyshchenko
Quoted 7 lines
--- MAINTAINERS | 8 +- xen/arch/x86/Kconfig | 1 + xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/emulate.c | 2 +- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/io.c | 2 +-Quoted 8 lines
xen/arch/x86/hvm/ioreq.c | 1425 +-------------------------------------- xen/arch/x86/hvm/stdvga.c | 2 +- xen/arch/x86/hvm/vmx/vvmx.c | 3 +- xen/arch/x86/mm.c | 2 +- xen/arch/x86/mm/shadow/common.c | 2 +- xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/ioreq.c | 1410 ++++++++++++++++++++++++++++++++++++++
Quoted 7 lines
This suggests it was almost the entire file which got moved. It would be really nice if you could convince git to show the diff here, rather than removal and addition of 1400 lines.
Additionally I wonder whether what's left in the original file wouldn't better become inline functions now. If this was done in the previous patch, the change would be truly a rename then, I think.
Last time when trying to make something inline in arch files for the RFC series (I don't remember exactly for what it was) I got completely stuck with the build issues due to the header (inter-?)dependencies, which I failed to resolve). Anyway I got your point and will try to experiment with that.
Quoted 7 lines
Quoted 7 lines
xen/include/asm-x86/hvm/ioreq.h +0
-0@@ -19,41 +19,12 @@#ifndef __ASM_X86_HVM_IOREQ_H__#define __ASM_X86_HVM_IOREQ_H__
Quoted 8 lines
xen/include/asm-x86/hvm/ioreq.h line 24
Quoted 6 lines
xen/include/asm-x86/hvm/ioreq.h +3
-3-bool hvm_io_pending (struct vcpu *v); -bool handle_hvm_io_completion (struct vcpu *v); -bool is_ioreq_server_page (struct domain *d,const struct page_info *page); +#include <asm/hvm/emulate.h> +#include <asm/hvm/hvm.h> +#include <asm/hvm/vmx/vmx.h> Are all three really needed here? Especially the last one strikes me as odd.
We can leave only #include <asm/hvm/emulate.h> here and move #include <asm/hvm/vmx/vmx.h> to x86/hvm/ioreq.c. Also #include <asm/hvm/hvm.h> could be dropped.
Quoted 17 lines
Quoted 17 lines
xen/include/xen/ioreq.h new file +13
-0@@ -0,0 +1,82 @@ +/* +* ioreq.h: Hardware virtual machine assist interface definitions. +* +* Copyright (c) 2016 Citrix Systems Inc. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details.
Quoted 8 lines
xen/include/xen/ioreq.h line 20
Quoted 7 lines
xen/include/xen/ioreq.h new file +7
-0+* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __IOREQ_H__ +#define __IOREQ_H__
__XEN_IOREQ_H__please.
ok
Quoted 7 lines
xen/include/xen/ioreq.h line 24
Quoted 4 lines
xen/include/xen/ioreq.h new file +3
-0+#include <xen/sched.h> + +#include <asm/hvm/ioreq.h> Is this include really needed here (i.e. by the code further down in the file, and hence by everyone including this header), or rather just in a few specific .c files?
I think, just in few specific .c files. Which are x86/hvm/ioreq.c and common/ioreq.c now and several other files later on (x86/hvm/dm.c, arm/io.c, etc) Shall I include that header in these files instead?
Quoted 4 lines
xen/include/xen/ioreq.h line 27
Quoted 3 lines
xen/include/xen/ioreq.h new file +2
-0+#define GET_IOREQ_SERVER (d, id) \ + (d)->arch.hvm.ioreq_server.server[id]arch.hvm.* feels like a layering violation when used in this header.
Got it. The only reason why GET_IOREQ_SERVER is here is inline get_ioreq_server(). I will make it non-inline and move both to common/ioreq.c. I assume this layering violation issue applies for hvm_domain_has_ioreq_server() introduced in
[PATCH V1 11/16] xen/ioreq: Introduce hvm_domain_has_ioreq_server()
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Quoted 37 lines · Oleksandr
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Oleksandr Tyshchenko
xen/include/xen/ioreq.h new file +13
-0@@ -0,0 +1,82 @@ +/* +* ioreq.h: Hardware virtual machine assist interface definitions. +* +* Copyright (c) 2016 Citrix Systems Inc. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. Quoted 8 lines
xen/include/xen/ioreq.h line 20
Quoted 7 lines
xen/include/xen/ioreq.h new file +7
-0+* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __IOREQ_H__ +#define __IOREQ_H__
__XEN_IOREQ_H__please.ok
Quoted 7 lines
xen/include/xen/ioreq.h line 24
Quoted 4 lines
xen/include/xen/ioreq.h new file +3
-0+#include <xen/sched.h> + +#include <asm/hvm/ioreq.h> Is this include really needed here (i.e. by the code further down in the file, and hence by everyone including this header), or rather just in a few specific .c files?
Quoted 4 lines
I think, just in few specific .c files. Which are
x86/hvm/ioreq.candcommon/ioreq.cnow and several other files later on (x86/hvm/dm.c,arm/io.c, etc)
Shall I include that header in these files instead?
Yes please, and please take this as a common guideline. While private headers are often used to include things needed by all of the (typically few) users of the header, non-private ones shouldn't create unnecessary dependencies on other headers. As you've said further up - you did run into hard to resolve header dependencies yourself, and the practice of including headers without strict need is one of the reasons of such problems.
Quoted 6 lines
Quoted 3 lines
xen/include/xen/ioreq.h line 27
Quoted 2 lines
xen/include/xen/ioreq.h new file +2
-0+#define GET_IOREQ_SERVER (d, id) \ + (d)->arch.hvm.ioreq_server.server[id]arch.hvm.* feels like a layering violation when used in this header.
Got it. The only reason why
GET_IOREQ_SERVERis here is inlineget_ioreq_server(). I will make it non-inline and move both tocommon/ioreq.c.
Which won't make the layering violation go away. It's still common rather than per-arch code then. As suggested elsewhere, I think the whole ioreq_server struct wants to move into struct domain itself, perhaps inside a new #ifdef (iirc one of the patches introduces a suitable Kconfig option). This goes alongside my suggestion to drop the "hvm" prefixes and infixes from involved function names.
Jan
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
On 22.09.20 09:33, Jan Beulich wrote:
Hi Jan
Quoted 40 lines · Oleksandr
Quoted 35 lines · Jan Beulich
Quoted 17 lines · Oleksandr Tyshchenko
Quoted 16 lines
xen/include/xen/ioreq.h new file +13
-0@@ -0,0 +1,82 @@ +/* +* ioreq.h: Hardware virtual machine assist interface definitions. +* +* Copyright (c) 2016 Citrix Systems Inc. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. Quoted 8 lines
xen/include/xen/ioreq.h line 20
Quoted 7 lines
xen/include/xen/ioreq.h new file +7
-0+* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __IOREQ_H__ +#define __IOREQ_H__
__XEN_IOREQ_H__please.ok
Quoted 6 lines
xen/include/xen/ioreq.h line 24
Quoted 3 lines
xen/include/xen/ioreq.h new file +3
-0+#include <xen/sched.h> + +#include <asm/hvm/ioreq.h> Is this include really needed here (i.e. by the code further down in the file, and hence by everyone including this header), or rather just in a few specific .c files?
Quoted 4 lines
I think, just in few specific .c files. Which are
x86/hvm/ioreq.candcommon/ioreq.cnow and several other files later on (x86/hvm/dm.c,arm/io.c, etc)
Shall I include that header in these files instead?
Quoted 8 lines
Yes please, and please take this as a common guideline. While private headers are often used to include things needed by all of the (typically few) users of the header, non-private ones shouldn't create unnecessary dependencies on other headers. As you've said further up - you did run into hard to resolve header dependencies yourself, and the practice of including headers without strict need is one of the reasons of such problems.
Got it.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
xen/include/xen/ioreq.h line 27
Quoted 3 lines
xen/include/xen/ioreq.h new file +2
-0+#define GET_IOREQ_SERVER (d, id) \ + (d)->arch.hvm.ioreq_server.server[id]arch.hvm.* feels like a layering violation when used in this header.
Quoted 8 lines
Quoted 3 lines
Got it. The only reason why
GET_IOREQ_SERVERis here is inlineget_ioreq_server(). I will make it non-inline and move both tocommon/ioreq.c.Which won't make the layering violation go away. It's still common rather than per-arch code then. As suggested elsewhere, I think the whole
ioreq_serverstruct wants to move into struct domain itself, perhaps inside a new #ifdef (iirc one of the patches introduces a suitableKconfigoption).
Well, your advise regarding ioreq_server sounds reasonable, but the common ioreq.c
still will have other *arch.hvm.* for both vcpu and domain. So looks like other involved structs should be moved into *common* struct domain/vcpu itself, correct? Some of them could be moved easily since contain the same fields (arch.hvm.ioreq_gfn), but some of them couldn't and seems to require to pull a lot of changes to the Xen code (arch.hvm.params, arch.hvm.hvm_io), I am afraid. Or I missed something?
Quoted 3 lines
This goes
alongside my suggestion to drop the "hvm" prefixes and infixes from involved function names.
Well, I assume this request as well as the request above should be addressed in the follow-up patches, as we want to keep the code movement in current patch as (almost) verbatim copy, Am I correct?
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Quoted 15 lines · Oleksandr
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Oleksandr
Quoted 4 lines · Jan Beulich
xen/include/xen/ioreq.h line 27
Quoted 2 lines · Oleksandr Tyshchenko
xen/include/xen/ioreq.h new file +2
-0+#define GET_IOREQ_SERVER (d, id) \ + (d)->arch.hvm.ioreq_server.server[id]arch.hvm.* feels like a layering violation when used in this header.
Quoted 8 lines
Quoted 3 lines
Got it. The only reason why
GET_IOREQ_SERVERis here is inlineget_ioreq_server(). I will make it non-inline and move both tocommon/ioreq.c.Which won't make the layering violation go away. It's still common rather than per-arch code then. As suggested elsewhere, I think the whole
ioreq_serverstruct wants to move into struct domain itself, perhaps inside a new #ifdef (iirc one of the patches introduces a suitableKconfigoption).
Quoted 9 lines
Well, your advise regarding
ioreq_serversounds reasonable, but the commonioreq.c
still will have other *arch.hvm.* for both vcpu and domain. So looks like other involved structs should be moved
into *common* struct domain/vcpu itself, correct? Some of them could be moved easily since contain the same fields (arch.hvm.ioreq_gfn), but some of them couldn't and seems to require to pull a lot of changes to the Xen code (arch.hvm.params, arch.hvm.hvm_io), I am afraid. Or I missed something?
arch.hvm.params, iirc, is an x86 concept, and hence would need abstracting away anyway. I expect this will be common pattern:
Either you want things to become generic (structure fields living directly in struct domain, or at least not under arch.hvm), or things need abstracting for per-arch handling.
Quoted 7 lines
Quoted 3 lines
This goes
alongside my suggestion to drop the "hvm" prefixes and infixes from involved function names.Well, I assume this request as well as the request above should be addressed in the follow-up patches, as we want to keep the code movement in current patch as (almost) verbatim copy,
Am I correct?
The renaming could imo be done before or after the move, but within a single series. Doing it (or some of it) during the move may be acceptable, but this primarily depends on the overall effect on the patch that this would have. I.e. the patch better wouldn't become gigantic just because all the renaming gets done in one go, and it's hundreds of places that need touching.
Jan
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
On 22.09.20 13:54, Jan Beulich wrote:
Hi Jan
Quoted 25 lines · Oleksandr
Quoted 15 lines · Jan Beulich
Quoted 6 lines · Oleksandr
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Oleksandr Tyshchenko
Review
Quoted 2 lines
(quoted diff) +2
-0+#define GET_IOREQ_SERVER(d, id) \ + (d)->arch.hvm.ioreq_server.server[id]arch.hvm.* feels like a layering violation when used in this header.
Quoted 8 lines
Quoted 3 lines
Got it. The only reason why
GET_IOREQ_SERVERis here is inlineget_ioreq_server(). I will make it non-inline and move both tocommon/ioreq.c.Which won't make the layering violation go away. It's still common rather than per-arch code then. As suggested elsewhere, I think the whole
ioreq_serverstruct wants to move into struct domain itself, perhaps inside a new #ifdef (iirc one of the patches introduces a suitableKconfigoption).Quoted 9 lines
Well, your advise regarding
ioreq_serversounds reasonable, but the commonioreq.c
still will have other *arch.hvm.* for both vcpu and domain. So looks like other involved structs should be moved
into *common* struct domain/vcpu itself, correct? Some of them could be moved easily since contain the same fields (arch.hvm.ioreq_gfn), but some of them couldn't and seems to require to pull a lot of changes to the Xen code (arch.hvm.params, arch.hvm.hvm_io), I am afraid. Or I missed something?
Quoted 5 lines
arch.hvm.params, iirc, is an x86 concept, and hence would need abstracting away anyway. I expect this will be common pattern:
Either you want things to become generic (structure fields living directly in struct domain, or at least not under arch.hvm), or things need abstracting for per-arch handling.
Got it.
Let me please clarify one more question.
In order to avoid the layering violation in current patch we could apply a complex approach.
1. *arch.hvm.ioreq_gfn* and *arch.hvm.ioreq_server*: Both structs go into common struct domain.
2. *arch.hvm.params*: Two functions that use it (hvm_alloc_legacy_ioreq_gfn/hvm_free_legacy_ioreq_gfn) either go into arch code completely or specific macro is used in common code:
#define ioreq_get_params(d, i) ((d)->arch.hvm.params[i])
I would prefer macro than moving functions to arch code (which are equal and should remain in sync).
3. *arch.hvm.hvm_io*: We could also use the following:
#define ioreq_get_io_completion(v) ((v)->arch.hvm.hvm_io.io_completion) #define ioreq_get_io_req(v) ((v)->arch.hvm.hvm_io.io_req)
This way struct hvm_vcpu_io won't be used in common code as well.
Are #2, 3 appropriate to go with?
Dirty non-tested patch (which applied on top of the whole series and targets Arm only) shows how it could look like.
xen/common/ioreq.c +0 -0
@@ -194,7 +194,7 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p)
bool handle_hvm_io_completion(struct vcpu *v)
{
struct domain *d = v->domain;
- struct hvm_vcpu_io *vio = &v->arch.hvm.hvm_io;
+ ioreq_t io_req = ioreq_get_io_req(v);
struct hvm_ioreq_server *s;
struct hvm_ioreq_vcpu *sv;
enum hvm_io_completion io_completion;
@@ -209,14 +209,14 @@ bool handle_hvm_io_completion(struct vcpu *v) if ( sv && !hvm_wait_for_io(sv, get_ioreq(s, v)) ) return false;
- vio->io_req.state = hvm_ioreq_needs_completion(&vio->io_req) ? + io_req.state = hvm_ioreq_needs_completion(&io_req) ? STATE_IORESP_READY : STATE_IOREQ_NONE;
msix_write_completion(v);
vcpu_end_shutdown_deferral(v);
- io_completion = vio->io_completion;
- vio->io_completion = HVMIO_no_completion; + io_completion = ioreq_get_io_completion(v); + ioreq_get_io_completion(v) = HVMIO_no_completion;
switch ( io_completion )
{
@@ -227,8 +227,8 @@ bool handle_hvm_io_completion(struct vcpu *v) return ioreq_handle_complete_mmio();
case HVMIO_pio_completion:
- return handle_pio(vio->io_req.addr, vio->io_req.size, - vio->io_req.dir);
+ return handle_pio(io_req.addr, io_req.size, + io_req.dir);
default:
return arch_handle_hvm_io_completion(io_completion);
@@ -247,7 +247,7 @@ static gfn_t hvm_alloc_legacy_ioreq_gfn(struct hvm_ioreq_server *s) for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ )
{
if ( !test_and_clear_bit(i, &d->ioreq_gfn.legacy_mask) )
- return _gfn(d->arch.hvm.params[i]);
+ return _gfn(ioreq_get_params(d, i));
}
return INVALID_GFN;
@@ -279,7 +279,7 @@ static bool hvm_free_legacy_ioreq_gfn(struct hvm_ioreq_server *s,
for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) {
- if ( gfn_eq(gfn, _gfn(d->arch.hvm.params[i])) )
+ if ( gfn_eq(gfn, _gfn(ioreq_get_params(d, i))) ) break;
}
if ( i > HVM_PARAM_BUFIOREQ_PFN )
xen/include/asm-arm/domain.h +0 -0
@@ -21,6 +21,8 @@ struct hvm_domain
uint64_t params[HVM_NR_PARAMS];
};
+#define ioreq_get_params(d, i) ((d)->arch.hvm.params[i]) +
#ifdef CONFIG_ARM_64
enum domain_type {
DOMAIN_32BIT,
@@ -120,6 +122,9 @@ struct hvm_vcpu_io { unsigned long mmio_gpfn;
};
+#define ioreq_get_io_completion(v) ((v)->arch.hvm.hvm_io.io_completion) +#define ioreq_get_io_req(v) ((v)->arch.hvm.hvm_io.io_req)
+
struct arch_vcpu
{
struct {
(END)
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
This goes
alongside my suggestion to drop the "hvm" prefixes and infixes from involved function names.Well, I assume this request as well as the request above should be addressed in the follow-up patches, as we want to keep the code movement in current patch as (almost) verbatim copy,
Am I correct?
Quoted 6 lines
The renaming could imo be done before or after the move, but within a single series. Doing it (or some of it) during the move may be acceptable, but this primarily depends on the overall effect on the patch that this would have. I.e. the patch better wouldn't become gigantic just because all the renaming gets done in one go, and it's hundreds of places that need touching.
Got it as well.
Thank you for the explanation.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Quoted 6 lines · Oleksandr
2. *arch.hvm.params*: Two functions that use it (hvm_alloc_legacy_ioreq_gfn/hvm_free_legacy_ioreq_gfn) either go into arch code completely or
specific macro is used in common code:#define
ioreq_get_params(d, i)((d)->arch.hvm.params[i])
If Arm has the concept of params, then perhaps. But I didn't think Arm does ...
Quoted 2 lines
I would prefer macro than moving functions to arch code (which are
equal and should remain in sync).
Yes, if the rest of the code is identical, I agree it's better to merely abstract away small pieces like this one.
Quoted 6 lines
3. *arch.hvm.hvm_io*: We could also use the following:
#define
ioreq_get_io_completion(v)((v)->arch.hvm.hvm_io.io_completion) #defineioreq_get_io_req(v)((v)->arch.hvm.hvm_io.io_req)This way struct
hvm_vcpu_iowon't be used in common code as well.
But if Arm needs similar field, why keep them in arch.hvm.hvm_io?
Quoted 13 lines
xen/common/ioreq.c +1
-1@@ -194,7 +194,7 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p) bool handle_hvm_io_completion(struct vcpu *v) { struct domain *d = v->domain; - struct hvm_vcpu_io *vio = &v->arch.hvm.hvm_io; + ioreq_t io_req = ioreq_get_io_req(v); struct hvm_ioreq_server *s; struct hvm_ioreq_vcpu *sv;enum
hvm_io_completionio_completion;
xen/common/ioreq.c bool handle_hvm_io_completion(struct vcpu *v) · line 213
Quoted 6 lines
xen/common/ioreq.c +1
-1@@ -209,14 +209,14 @@ bool handle_hvm_io_completion(struct vcpu *v) if ( sv && !hvm_wait_for_io(sv, get_ioreq(s, v)) ) return false; - vio->io_req.state = hvm_ioreq_needs_completion(&vio->io_req) ? + io_req.state = hvm_ioreq_needs_completion(&io_req) ? STATE_IORESP_READY : STATE_IOREQ_NONE;
This is unlikely to be correct - you're now updating an on-stack copy of the ioreq_t instead of what vio points at.
xen/common/ioreq.c bool handle_hvm_io_completion(struct vcpu *v) · line 218
Quoted 7 lines
xen/common/ioreq.c +2
-2msix_write_completion(v); vcpu_end_shutdown_deferral(v); - io_completion = vio->io_completion; - vio->io_completion = HVMIO_no_completion; + io_completion = ioreq_get_io_completion(v); + ioreq_get_io_completion(v) = HVMIO_no_completion;
I think it's at least odd to have an lvalue with this kind of a name. Perhaps want to drop "get" if it's really meant to be used like this.
Quoted 19 lines
xen/common/ioreq.c +1
-1@@ -247,7 +247,7 @@ static gfn_t hvm_alloc_legacy_ioreq_gfn(struct hvm_ioreq_server *s) for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { if ( !test_and_clear_bit(i, &d->ioreq_gfn.legacy_mask) ) - return _gfn(d->arch.hvm.params[i]); + return _gfn(ioreq_get_params(d, i)); }return
INVALID_GFN;xen/common/ioreq.c +1
-1@@ -279,7 +279,7 @@ static bool hvm_free_legacy_ioreq_gfn(struct hvm_ioreq_server *s, for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { - if ( gfn_eq(gfn, _gfn(d->arch.hvm.params[i])) ) + if ( gfn_eq(gfn, _gfn(ioreq_get_params(d, i))) ) break; }
Quoted 1 line
if ( i >
HVM_PARAM_BUFIOREQ_PFN)
And these two are needed by Arm? Shouldn't Arm exclusively use the new model, via acquire_resource?
Jan
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
On 22.09.20 18:52, Jan Beulich wrote:
Hi Jan
Quoted 9 lines · Oleksandr
Quoted 6 lines
2. *arch.hvm.params*: Two functions that use it (hvm_alloc_legacy_ioreq_gfn/hvm_free_legacy_ioreq_gfn) either go into arch code completely or
specific macro is used in common code:#define ioreq_get_params(d, i) ((d)->arch.hvm.params[i])If Arm has the concept of params, then perhaps. But I didn't think Arm does ...
I think it has in some degree, there is a handling of HVMOP_set_param/HVMOP_get_param and also there is a code to setup HVM_PARAM_CALLBACK_IRQ.
Quoted 5 lines
Quoted 3 lines
I would prefer macro than moving functions to arch code (which are
equal and should remain in sync).Yes, if the rest of the code is identical, I agree it's better to merely abstract away small pieces like this one.
ok
Quoted 8 lines
Quoted 7 lines
3. *arch.hvm.hvm_io*: We could also use the following:
#define ioreq_get_io_completion(v) ((v)->arch.hvm.hvm_io.io_completion) #define ioreq_get_io_req(v) ((v)->arch.hvm.hvm_io.io_req)This way struct
hvm_vcpu_iowon't be used in common code as well.But if Arm needs similar field, why keep them in arch.hvm.hvm_io?
Yes, Arm needs the "some" fields, but not "all of them" as x86 has. For example Arm needs only the following (at least in the context of this series):
+struct hvm_vcpu_io {
+ /* I/O request in flight to device model. */
+ enum hvm_io_completion io_completion;
+ ioreq_t io_req;
+
+ /*
+ * HVM emulation:
+ * Linear address @mmio_gla maps to MMIO physical frame @mmio_gpfn. + * The latter is known to be an MMIO frame (not RAM).
+ * This translation is only valid for accesses as per @mmio_access. + */
+ struct npfec mmio_access;
+ unsigned long mmio_gla;
+ unsigned long mmio_gpfn;
+};
But for x86 the number of fields is quite bigger. If they were in same way applicable for both archs (as what we have with ioreq_server struct) I would move it to the common domain. I didn't think of a better idea than just abstracting accesses to these (used in common ioreq.c) two fields by macro.
Quoted 17 lines
Quoted 17 lines
xen/common/ioreq.c +1
-1@@ -194,7 +194,7 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p) bool handle_hvm_io_completion(struct vcpu *v) { struct domain *d = v->domain; - struct hvm_vcpu_io *vio = &v->arch.hvm.hvm_io; + ioreq_t io_req = ioreq_get_io_req(v); struct hvm_ioreq_server *s; struct hvm_ioreq_vcpu *sv;enum
hvm_io_completionio_completion;xen/common/ioreq.c +0
-0@@ -209,14 +209,14 @@ bool handle_hvm_io_completion(struct vcpu *v) if ( sv && !hvm_wait_for_io(sv, get_ioreq(s, v)) ) return false;
Quoted 5 lines
xen/common/ioreq.c bool handle_hvm_io_completion(struct vcpu *v) · line 213
Quoted 3 lines
xen/common/ioreq.c +1
-1- vio->io_req.state = hvm_ioreq_needs_completion(&vio->io_req) ? + io_req.state = hvm_ioreq_needs_completion(&io_req) ? STATE_IORESP_READY : STATE_IOREQ_NONE;This is unlikely to be correct - you're now updating an on-stack copy of the
ioreq_tinstead of what vio points at.
Oh, thank you for pointing this, I should have used ioreq_t *io_req = &ioreq_get_io_req(v); I don't like ioreq_get_io_req much), probably ioreq_req would sound a little bit better?
Quoted 11 lines
xen/common/ioreq.c bool handle_hvm_io_completion(struct vcpu *v) · line 218
Quoted 8 lines
xen/common/ioreq.c +2
-2msix_write_completion(v); vcpu_end_shutdown_deferral(v); - io_completion = vio->io_completion; - vio->io_completion = HVMIO_no_completion; + io_completion = ioreq_get_io_completion(v); + ioreq_get_io_completion(v) = HVMIO_no_completion;I think it's at least odd to have an lvalue with this kind of a name. Perhaps want to drop "get" if it's really meant to be used like this.
ok
Quoted 14 lines
Quoted 14 lines
xen/common/ioreq.c +1
-1@@ -247,7 +247,7 @@ static gfn_t hvm_alloc_legacy_ioreq_gfn(struct hvm_ioreq_server *s) for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { if ( !test_and_clear_bit(i, &d->ioreq_gfn.legacy_mask) ) - return _gfn(d->arch.hvm.params[i]); + return _gfn(ioreq_get_params(d, i)); }return
INVALID_GFN;xen/common/ioreq.c +0
-0@@ -279,7 +279,7 @@ static bool hvm_free_legacy_ioreq_gfn(struct hvm_ioreq_server *s,
Quoted 9 lines
Quoted 7 lines
xen/common/ioreq.c +1
-1for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { - if ( gfn_eq(gfn, _gfn(d->arch.hvm.params[i])) ) + if ( gfn_eq(gfn, _gfn(ioreq_get_params(d, i))) ) break; }if ( i >
HVM_PARAM_BUFIOREQ_PFN)And these two are needed by Arm? Shouldn't Arm exclusively use the new model, via
acquire_resource?
I dropped HVMOP plumbing on Arm as it was requested. Only acquire interface should be used.
This code is not supposed to be called on Arm, but it is a part of common code and we need to find a way how to abstract away *arch.hvm.params* Am I correct?
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Quoted 29 lines · Oleksandr
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Oleksandr
3. *arch.hvm.hvm_io*: We could also use the following:
#define ioreq_get_io_completion(v) ((v)->arch.hvm.hvm_io.io_completion) #define ioreq_get_io_req(v) ((v)->arch.hvm.hvm_io.io_req)This way struct
hvm_vcpu_iowon't be used in common code as well.But if Arm needs similar field, why keep them in arch.hvm.hvm_io?
Yes, Arm needs the "some" fields, but not "all of them" as x86 has. For example Arm needs only the following (at least in the context of this series):
(quoted diff) +15
-0+struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame @mmio_gpfn. + * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access. + */ + struct npfec mmio_access; + unsigned long mmio_gla; + unsigned long mmio_gpfn; +};
Quoted 5 lines
But for x86 the number of fields is quite bigger. If they were in same way applicable for both archs (as what we have with
ioreq_serverstruct) I would move it to the common domain. I didn't think of a better idea than just abstracting accesses to these (used in commonioreq.c) two fields by macro.
I'm surprised Arm would need all the three last fields that you mention. Both here and ...
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
(quoted diff) +1
-1@@ -247,7 +247,7 @@ static gfn_t hvm_alloc_legacy_ioreq_gfn(struct hvm_ioreq_server *s) for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { if ( !test_and_clear_bit(i, &d->ioreq_gfn.legacy_mask) ) - return _gfn(d->arch.hvm.params[i]); + return _gfn(ioreq_get_params(d, i)); }return
INVALID_GFN;(quoted diff) +0
-0@@ -279,7 +279,7 @@ static bool hvm_free_legacy_ioreq_gfn(struct hvm_ioreq_server *s,Quoted 9 lines
Quoted 7 lines
(quoted diff) +1
-1for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { - if ( gfn_eq(gfn, _gfn(d->arch.hvm.params[i])) ) + if ( gfn_eq(gfn, _gfn(ioreq_get_params(d, i))) ) break; }if ( i >
HVM_PARAM_BUFIOREQ_PFN)And these two are needed by Arm? Shouldn't Arm exclusively use the new model, via
acquire_resource?
Quoted 4 lines
I dropped HVMOP plumbing on Arm as it was requested. Only acquire interface should be used.
This code is not supposed to be called on Arm, but it is a part of common code and we need to find a way how to abstract away *arch.hvm.params*
... here I wonder whether you aren't moving more pieces to common code than are actually arch-independent. I think a prereq step missing so far is to clearly identify which pieces of the code are arch-independent, and work towards abstracting away all of the arch-dependent ones.
Jan
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
On 24.09.20 13:58, Jan Beulich wrote:
Hi Jan
Quoted 64 lines · Oleksandr
Quoted 29 lines · Jan Beulich
Quoted 8 lines · Oleksandr
Quoted 6 lines
3. *arch.hvm.hvm_io*: We could also use the following:
#define ioreq_get_io_completion(v) ((v)->arch.hvm.hvm_io.io_completion) #define ioreq_get_io_req(v) ((v)->arch.hvm.hvm_io.io_req)This way struct
hvm_vcpu_iowon't be used in common code as well.But if Arm needs similar field, why keep them in arch.hvm.hvm_io?
Yes, Arm needs the "some" fields, but not "all of them" as x86 has. For example Arm needs only the following (at least in the context of this series):
(quoted diff) +15
-0+struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame @mmio_gpfn. + * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access. + */ + struct npfec mmio_access; + unsigned long mmio_gla; + unsigned long mmio_gpfn; +};Quoted 5 lines
But for x86 the number of fields is quite bigger. If they were in same way applicable for both archs (as what we have with
ioreq_serverstruct) I would move it to the common domain. I didn't think of a better idea than just abstracting accesses to these (used in commonioreq.c) two fields by macro.I'm surprised Arm would need all the three last fields that you mention. Both here and ...
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
(quoted diff) +1
-1@@ -247,7 +247,7 @@ static gfn_t hvm_alloc_legacy_ioreq_gfn(struct hvm_ioreq_server *s) for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { if ( !test_and_clear_bit(i, &d->ioreq_gfn.legacy_mask) ) - return _gfn(d->arch.hvm.params[i]); + return _gfn(ioreq_get_params(d, i)); }return INVALID_GFN;(quoted diff) +0
-0@@ -279,7 +279,7 @@ static bool hvm_free_legacy_ioreq_gfn(struct hvm_ioreq_server *s,Quoted 9 lines
Quoted 7 lines
(quoted diff) +1
-1for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { - if ( gfn_eq(gfn, _gfn(d->arch.hvm.params[i])) ) + if ( gfn_eq(gfn, _gfn(ioreq_get_params(d, i))) ) break; }if ( i >
HVM_PARAM_BUFIOREQ_PFN)And these two are needed by Arm? Shouldn't Arm exclusively use the new model, via
acquire_resource?Quoted 4 lines
I dropped HVMOP plumbing on Arm as it was requested. Only acquire interface should be used.
This code is not supposed to be called on Arm, but it is a part of common code and we need to find a way how to abstract away *arch.hvm.params*
Quoted 5 lines
... here I wonder whether you aren't moving more pieces to common code than are actually arch-independent. I think a prereq step missing so far is to clearly identify which pieces of the code are arch-independent, and work towards abstracting away all of the arch-dependent ones.
Unfortunately, not all things are clear and obvious from the very beginning.
I have to admit, I didn't even imagine earlier that *arch.hvm.* usage in the common code is a layering violation issue. Hopefully, now it is clear as well as the steps to avoid it in future.
...
I saw your advise (but haven't answered yet there) regarding splitting struct hvm_vcpu_io in
[PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features. I think, it makes sense.
The only remaining bits I would like to clarify here is *arch.hvm.params*. Should we really want to move HVM params field to the common code rather than abstracting away by proposed macro? Although stores a few IOREQ params, it is not a (completely) IOREQ stuff and is specific to the architecture.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Quoted 43 lines · Oleksandr
Quoted 29 lines · Jan Beulich
Quoted 24 lines · Oleksandr
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksandr
(quoted diff) +1
-1@@ -247,7 +247,7 @@ static gfn_t hvm_alloc_legacy_ioreq_gfn(struct hvm_ioreq_server *s) for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { if ( !test_and_clear_bit(i, &d->ioreq_gfn.legacy_mask) ) - return _gfn(d->arch.hvm.params[i]); + return _gfn(ioreq_get_params(d, i)); }return INVALID_GFN;(quoted diff) +0
-0@@ -279,7 +279,7 @@ static bool hvm_free_legacy_ioreq_gfn(struct hvm_ioreq_server *s,Quoted 9 lines
Quoted 7 lines
(quoted diff) +1
-1for ( i = HVM_PARAM_IOREQ_PFN; i <= HVM_PARAM_BUFIOREQ_PFN; i++ ) { - if ( gfn_eq(gfn, _gfn(d->arch.hvm.params[i])) ) + if ( gfn_eq(gfn, _gfn(ioreq_get_params(d, i))) ) break; }if ( i >
HVM_PARAM_BUFIOREQ_PFN)And these two are needed by Arm? Shouldn't Arm exclusively use the new model, via
acquire_resource?Quoted 4 lines
I dropped HVMOP plumbing on Arm as it was requested. Only acquire interface should be used.
This code is not supposed to be called on Arm, but it is a part of common code and we need to find a way how to abstract away *arch.hvm.params*Quoted 5 lines
... here I wonder whether you aren't moving more pieces to common code than are actually arch-independent. I think a prereq step missing so far is to clearly identify which pieces of the code are arch-independent, and work towards abstracting away all of the arch-dependent ones.
Unfortunately, not all things are clear and obvious from the very beginning. I have to admit, I didn't even imagine earlier that *arch.hvm.* usage in the common code is a layering violation issue.
Hopefully, now it is clear as well as the steps to avoid it in future....
Quoted 8 lines
I saw your advise (but haven't answered yet there) regarding splitting struct
hvm_vcpu_ioin
[PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features. I think, it makes sense.
The only remaining bits I would like to clarify here is *arch.hvm.params*. Should we really want to move HVM params field to the common code
rather than abstracting away by proposed macro?
I don't think I suggested doing so. In fact I recall having voiced my expectation that Arm wouldn't use this at all. So yes, I agree this better wouldn't be moved out of arch.hvm, but instead accesses be abstracted by another means.
Jan
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
In reply to Oleksandr TyshchenkoQuoted 27 lines · Oleksandr Tyshchenko
xen/common/ioreq.c new file +27
-0+static bool hvm_wait_for_io (struct hvm_ioreq_vcpu *sv,ioreq_t *p) +{ +unsigned int prev_state =STATE_IOREQ_NONE ; +unsigned int state = p->state; +uint64_t data = ~0 ; + +smp_rmb (); + +/* +* The only reason we should see this condition be false is when an +* emulator dying races with I/O being requested. +*/ +while (likely (state !=STATE_IOREQ_NONE ) ) + { +if (unlikely (state < prev_state) ) + { +gdprintk (XENLOG_ERR ,"Weird HVM ioreq state transition %u -> %u\n" , + prev_state, state); + sv->pending = false; +domain_crash (sv->vcpu->domain); +return false;/* bail */ + } + +switch ( prev_state = state ) + { +case STATE_IORESP_READY :/* IORESP_READY -> NONE */ + p->state =STATE_IOREQ_NONE ;
xen/common/ioreq.c line 138
Quoted 10 lines
xen/common/ioreq.c new file +10
-0+ data = p->data; +break ; + +case STATE_IOREQ_READY :/* IOREQ_{READY,INPROCESS} -> IORESP_READY */ +case STATE_IOREQ_INPROCESS : +wait_on_xen_event_channel (sv->ioreq_evtchn, + ({ state = p->state; +smp_rmb (); + state != prev_state; })); +continue ;
As I pointed out previously [1], this helper was implemented with the expectation that wait_on_xen_event_channel() will not return if the vCPU got rescheduled.
However, this assumption doesn't hold on Arm.
I can see two solution:
1) Re-execute the caller
2) Prevent an IOREQ to disappear until the loop finish.
@Paul any opinions?
Cheers,
[1] https://lore.kernel.org/xen-devel/[email protected]/
Signature · 1 line
Julien Grall
RE: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Quoted 56 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 24 September 2020 19:01
To: Oleksandr Tyshchenko <[email protected]>; [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>; Paul Durrant <[email protected]>; Jun Nakajima <[email protected]>; Kevin Tian <[email protected]>; Tim Deegan <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature commonQuoted 27 lines · Oleksandr Tyshchenko
xen/common/ioreq.c new file +27
-0+static bool hvm_wait_for_io (struct hvm_ioreq_vcpu *sv,ioreq_t *p) +{ +unsigned int prev_state =STATE_IOREQ_NONE ; +unsigned int state = p->state; +uint64_t data = ~0 ; + +smp_rmb (); + +/* +* The only reason we should see this condition be false is when an +* emulator dying races with I/O being requested. +*/ +while (likely (state !=STATE_IOREQ_NONE ) ) + { +if (unlikely (state < prev_state) ) + { +gdprintk (XENLOG_ERR ,"Weird HVM ioreq state transition %u -> %u\n" , + prev_state, state); + sv->pending = false; +domain_crash (sv->vcpu->domain); +return false;/* bail */ + } + +switch ( prev_state = state ) + { +case STATE_IORESP_READY :/* IORESP_READY -> NONE */ + p->state =STATE_IOREQ_NONE ;xen/common/ioreq.c line 138
Quoted 10 lines
xen/common/ioreq.c new file +10
-0+ data = p->data; +break ; + +case STATE_IOREQ_READY :/* IOREQ_{READY,INPROCESS} -> IORESP_READY */ +case STATE_IOREQ_INPROCESS : +wait_on_xen_event_channel (sv->ioreq_evtchn, + ({ state = p->state; +smp_rmb (); + state != prev_state; })); +continue ;As I pointed out previously [1], this helper was implemented with the expectation that
wait_on_xen_event_channel()will not return if the vCPU got rescheduled.
Quoted 7 lines
However, this assumption doesn't hold on Arm.
I can see two solution:
1) Re-execute the caller
2) Prevent an IOREQ to disappear until the loop finish.@Paul any opinions?
The ioreq control plane is largely predicated on there being no pending I/O when the state of a server is modified, and it is assumed that domain_pause() is sufficient to achieve this. If that assumption doesn't hold then we need additional synchronization.
Paul
Quoted 9 lines
Cheers,
[1]
https://lore.kernel.org/xen-devel/[email protected]/--
Julien Grall
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Hi Julien
Quoted 57 lines · Paul Durrant
Quoted 57 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 24 September 2020 19:01
To: Oleksandr Tyshchenko <[email protected]>; [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>; Paul Durrant <[email protected]>; Jun Nakajima <[email protected]>; Kevin Tian <[email protected]>; Tim Deegan <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature commonQuoted 27 lines · Oleksandr Tyshchenko
xen/common/ioreq.c new file +27
-0+static bool hvm_wait_for_io (struct hvm_ioreq_vcpu *sv,ioreq_t *p) +{ +unsigned int prev_state =STATE_IOREQ_NONE ; +unsigned int state = p->state; +uint64_t data = ~0 ; + +smp_rmb (); + +/* +* The only reason we should see this condition be false is when an +* emulator dying races with I/O being requested. +*/ +while (likely (state !=STATE_IOREQ_NONE ) ) + { +if (unlikely (state < prev_state) ) + { +gdprintk (XENLOG_ERR ,"Weird HVM ioreq state transition %u -> %u\n" , + prev_state, state); + sv->pending = false; +domain_crash (sv->vcpu->domain); +return false;/* bail */ + } + +switch ( prev_state = state ) + { +case STATE_IORESP_READY :/* IORESP_READY -> NONE */ + p->state =STATE_IOREQ_NONE ;xen/common/ioreq.c line 138
Quoted 10 lines
xen/common/ioreq.c new file +10
-0+ data = p->data; +break ; + +case STATE_IOREQ_READY :/* IOREQ_{READY,INPROCESS} -> IORESP_READY */ +case STATE_IOREQ_INPROCESS : +wait_on_xen_event_channel (sv->ioreq_evtchn, + ({ state = p->state; +smp_rmb (); + state != prev_state; })); +continue ;As I pointed out previously [1], this helper was implemented with the expectation that
wait_on_xen_event_channel()will not return if the vCPU got rescheduled.However, this assumption doesn't hold on Arm.
Quoted 9 lines
Quoted 5 lines
I can see two solution:
1) Re-execute the caller
2) Prevent an IOREQ to disappear until the loop finish.@Paul any opinions?
The ioreq control plane is largely predicated on there being no pending I/O when the state of a server is modified, and it is assumed that
domain_pause()is sufficient to achieve this. If that assumption doesn't hold then we need additional synchronization.Paul
May I please clarify whether a concern still stands (with what was said above) and we need an additional synchronization on Arm?
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Hi,
Quoted 70 lines · Oleksandr
Hi Julien
Quoted 66 lines · Paul Durrant
Quoted 58 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 24 September 2020 19:01
To: Oleksandr Tyshchenko <[email protected]>; [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>; Paul Durrant <[email protected]>; Jun Nakajima <[email protected]>; Kevin Tian <[email protected]>; Tim Deegan <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature commonQuoted 33 lines · Oleksandr Tyshchenko
xen/common/ioreq.c new file +10
-0+static bool hvm_wait_for_io (struct hvm_ioreq_vcpu *sv,ioreq_t *p) +{ + unsigned int prev_state = STATE_IOREQ_NONE; + unsigned int state = p->state; + uint64_t data = ~0; + + smp_rmb(); + + /* +* The only reason we should see this condition be false is when an
+ * emulator dying races with I/O being requested.
+ */
+ while (likely(state != STATE_IOREQ_NONE))
+ {
+ if (unlikely(state < prev_state))
+ {
+ gdprintk(XENLOG_ERR, "Weird HVM ioreq state transition %u -> %u\n",
+prev_state, state);
+sv->pending= false;
+domain_crash(sv->vcpu->domain);
+ return false; /* bail */
+ }xen/common/ioreq.c new file +9
-0+ + switch ( prev_state = state ) + { + case STATE_IORESP_READY: /* IORESP_READY -> NONE */ + p->state = STATE_IOREQ_NONE; + data = p->data; + break; + + case STATE_IOREQ_READY: /* IOREQ_{READY,INPROCESS} ->Quoted 7 lines
IORESP_READY*/
+ caseSTATE_IOREQ_INPROCESS:
+ wait_on_xen_event_channel(sv->ioreq_evtchn, + ({ state =p->state; +smp_rmb();
+ state !=prev_state; })); + continue;As I pointed out previously [1], this helper was implemented with the expectation that
wait_on_xen_event_channel()will not return if the vCPU got rescheduled.Quoted 7 lines
However, this assumption doesn't hold on Arm.
I can see two solution:
1) Re-execute the caller
2) Prevent an IOREQ to disappear until the loop finish.@Paul any opinions?
The ioreq control plane is largely predicated on there being no pending I/O when the state of a server is modified, and it is assumed that
domain_pause()is sufficient to achieve this. If that assumption doesn't hold then we need additional synchronization.
I don't think this assumption even hold on x86 because domain_pause() will not wait for I/O to finish.
On x86, the context switch will reset the stack and therefore wait_on_xen_event_channel() is not going to return. Instead, handle_hvm_io_completion() will be called from the tail callback in context_switch(). get_pending_vcpu() would return NULL as the IOREQ server disappeared. Although, it is not clear whether the vCPU will continue to run (or not).
Did I miss anything?
Regarding the fix itself, I am not sure what sort of synchronization we can do. Are you suggesting to wait for the I/O to complete? If so, how do we handle the case the IOREQ server died?
Quoted 1 line
May I please clarify whether a concern still stands (with what was said above) and we need an additional synchronization on Arm?
Yes the concern is still there (See above).
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Quoted 105 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 30 September 2020 18:48
To: Oleksandr <[email protected]>; [email protected]
Cc: [email protected]; 'Oleksandr Tyshchenko' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'George Dunlap' <[email protected]>; 'Ian Jackson' <[email protected]>; 'Jan Beulich' <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'Wei Liu' <[email protected]>; 'Roger Pau Monné' <[email protected]>; 'Jun Nakajima' <[email protected]>; 'Kevin Tian' <[email protected]>; 'Tim Deegan' <[email protected]>; 'Julien Grall' <[email protected]>
Subject: Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature commonHi,
Quoted 79 lines · Oleksandr
Hi Julien
Quoted 75 lines · Paul Durrant
Quoted 64 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 24 September 2020 19:01
To: Oleksandr Tyshchenko <[email protected]>; [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Andrew Cooper <[email protected]>;
George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau
Monné <[email protected]>; Paul Durrant <[email protected]>; Jun Nakajima <[email protected]>;
Kevin Tian <[email protected]>; Tim Deegan <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature commonQuoted 34 lines · Oleksandr Tyshchenko
xen/common/ioreq.c new file +10
-0+static bool hvm_wait_for_io (struct hvm_ioreq_vcpu *sv,ioreq_t *p) +{ +unsigned int prev_state =STATE_IOREQ_NONE ; +unsigned int state = p->state; +uint64_t data = ~0 ; + +smp_rmb (); + +/* +* The only reason we should see this condition be false is when an
xen/common/ioreq.c new file +7
-0+* emulator dying races with I/O being requested. +*/ +while (likely (state !=STATE_IOREQ_NONE ) ) + { +if (unlikely (state < prev_state) ) + { + gdprintk(XENLOG_ERR, "Weird HVM ioreq state transition%u -> %u\n",
xen/common/ioreq.c new file +14
-0+ prev_state, state); + sv->pending = false; +domain_crash (sv->vcpu->domain); +return false;/* bail */ + } + +switch ( prev_state = state ) + { +case STATE_IORESP_READY :/* IORESP_READY -> NONE */ + p->state =STATE_IOREQ_NONE ; + data = p->data; +break ; + +case STATE_IOREQ_READY :/* IOREQ_{READY,INPROCESS} ->
IORESP_READY*/xen/common/ioreq.c line 138
Quoted 6 lines
xen/common/ioreq.c new file +6
-0+case STATE_IOREQ_INPROCESS : +wait_on_xen_event_channel (sv->ioreq_evtchn, + ({ state = p->state; +smp_rmb (); + state != prev_state; })); +continue ;As I pointed out previously [1], this helper was implemented with the expectation that
wait_on_xen_event_channel()will not return if the vCPU got rescheduled.Quoted 7 lines
However, this assumption doesn't hold on Arm.
I can see two solution:
1) Re-execute the caller
2) Prevent an IOREQ to disappear until the loop finish.@Paul any opinions?
The ioreq control plane is largely predicated on there being no pending I/O when the state of a server is modified, and it is assumed that
domain_pause()is sufficient to achieve this. If that assumption doesn't hold then we need additional synchronization.I don't think this assumption even hold on x86 because
domain_pause()will not wait for I/O to finish.On x86, the context switch will reset the stack and therefore
wait_on_xen_event_channel()is not going to return. Instead,handle_hvm_io_completion()will be called from the tail callback incontext_switch().get_pending_vcpu()would return NULL as the IOREQ server disappeared. Although, it is not clear whether the vCPU will continue to run (or not).
Quoted 6 lines
Did I miss anything?
Regarding the fix itself, I am not sure what sort of synchronization we can do. Are you suggesting to wait for the I/O to complete? If so, how do we handle the case the IOREQ server died?
s/IOREQ server/emulator but that is a good point. If domain_pause() did wait for I/O to complete then this would have always been a problem so, with hindsight, it should have been obvious this was not the case.
Digging back, it looks like things would have probably been ok before 125833f5f1f0 "x86: fix ioreq-server event channel vulnerability" because, wait_on_xen_event_channel() and the loop condition above it did not dereference anything that would disappear with IOREQ server destruction (they used the shared page, which at this point was always a magic page and hence part of the target domain's memory). So things have probably been broken since 2014.
To fix the problem I think it is sufficient that we go back to a wait loop that can tolerate the IOREQ server disappearing between iterations and deals with that as a completed emulation (albeit returning f's for reads and sinking writes).
Paul
Quoted 9 lines
Quoted 2 lines
May I please clarify whether a concern still stands (with what was said above) and we need an additional synchronization on Arm?
Yes the concern is still there (See above).
Cheers,
--
Julien Grall
Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
In reply to Julien GrallQuoted 3 lines · Julien Grall
Regarding the fix itself, I am not sure what sort of synchronization we can do. Are you suggesting to wait for the I/O to complete? If so, how do we handle the case the IOREQ server died?
In simple cases retrying the entire request may be an option. However, if the server died after some parts of a multi-part operation were done already, I guess the resulting loss of state is bad enough to warrant crashing the guest. This shouldn't be much different from e.g. a device disappearing from a bare metal system - any partial I/O done to/from it will leave the machine in an unpredictable state, which it may be too difficult to recover from without rebooting. (Of course, staying with this analogue, it may also be okay to simple consider the operation "complete", leaving it to the guest to recover. The main issue on the hypervisor side then would be to ensure we don't expose any uninitialized [due to not having got written to] data to the guest.)
Jan
RE: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common
Quoted 17 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 01 October 2020 09:49
To: Julien Grall <[email protected]>
Cc: Oleksandr <[email protected]>; [email protected]; [email protected]; 'Oleksandr Tyshchenko' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'George Dunlap' <[email protected]>; 'Ian Jackson' <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'Wei Liu' <[email protected]>; 'Roger Pau Monné' <[email protected]>; 'Jun Nakajima' <[email protected]>; 'Kevin Tian' <[email protected]>; 'Tim Deegan' <[email protected]>; 'Julien Grall' <[email protected]>
Subject: Re: [PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature commonQuoted 3 lines · Julien Grall
Regarding the fix itself, I am not sure what sort of synchronization we can do. Are you suggesting to wait for the I/O to complete? If so, how do we handle the case the IOREQ server died?
Quoted 13 lines
In simple cases retrying the entire request may be an option. However, if the server died after some parts of a multi-part operation were done already, I guess the resulting loss of state is bad enough to warrant crashing the guest. This shouldn't be much different from e.g. a device disappearing from a bare metal system - any partial I/O done to/from it will leave the machine in an unpredictable state, which it may be too difficult to recover from without rebooting. (Of course, staying with this analogue, it may also be okay to simple consider the operation "complete", leaving it to the guest to recover. The main issue on the hypervisor side then would be to ensure we don't expose any uninitialized [due to not having got written to] data to the guest.)
I'll try to take a look today and come up with a patch.
Paul
PATCH 3/16 xen/ioreq: Make x86's hvm_ioreq_needs_completion() common
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
The IOREQ is a common feature now and this helper will be used on Arm as is. Move it to include/xen/ioreq.h
Although PIO handling on Arm is not introduced with the current series (it will be implemented when we add support for vPCI), technically the PIOs exist on Arm (however they are accessed the same way as MMIO) and it would be better not to diverge now.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- new patch, was split from:
"[RFC PATCH V1 01/12] hvm/ioreq: Make x86's IOREQ feature common"
---
--- xen/arch/x86/hvm/vmx/realmode.c | 1 + xen/include/asm-x86/hvm/vcpu.h | 7 ------- xen/include/xen/ioreq.h | 7 +++++++ 3 files changed, 8 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/vmx/realmode.c +1 -0
@@ -10,6 +10,7 @@*/ #include <xen/init.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/sched.h> #include <xen/paging.h>
xen/include/asm-x86/hvm/vcpu.h +0 -7
@@ -91,13 +91,6 @@ struct hvm_vcpu_io {const struct g2m_ioport *g2m_ioport; }; -static inline bool hvm_ioreq_needs_completion (const ioreq_t *ioreq) -{ -return ioreq->state ==STATE_IOREQ_READY && - !ioreq->data_is_ptr && - (ioreq->type !=IOREQ_TYPE_PIO || ioreq->dir !=IOREQ_WRITE ); -} -struct nestedvcpu {bool_t nv_guestmode;/* vcpu in guestmode? */ void *nv_vvmcx;/* l1 guest virtual VMCB/VMCS */
xen/include/xen/ioreq.h +7 -0
@@ -35,6 +35,13 @@ static inline struct hvm_ioreq_server *get_ioreq_server(const struct domain *d,return GET_IOREQ_SERVER (d, id); } +static inline bool hvm_ioreq_needs_completion (const ioreq_t *ioreq) +{ +return ioreq->state ==STATE_IOREQ_READY && + !ioreq->data_is_ptr && + (ioreq->type !=IOREQ_TYPE_PIO || ioreq->dir !=IOREQ_WRITE ); +} +bool hvm_io_pending (struct vcpu *v);bool handle_hvm_io_completion (struct vcpu *v);bool is_ioreq_server_page (struct domain *d,const struct page_info *page);
Signature · 1 line
2.7.4
Re: [PATCH V1 03/16] xen/ioreq: Make x86's hvm_ioreq_needs_completion() common
xen/include/xen/ioreq.h static inline struct hvm_ioreq_server *get_ioreq_server(const struct domain *d, · line 43
Quoted 12 lines · Oleksandr Tyshchenko
xen/include/xen/ioreq.h +6
-0@@ -35,6 +35,13 @@ static inline struct hvm_ioreq_server *get_ioreq_server(const struct domain *d,return GET_IOREQ_SERVER (d, id); } +static inline bool hvm_ioreq_needs_completion (const ioreq_t *ioreq) +{ +return ioreq->state ==STATE_IOREQ_READY && + !ioreq->data_is_ptr && + (ioreq->type !=IOREQ_TYPE_PIO || ioreq->dir !=IOREQ_WRITE ); +}
While the PIO aspect has been discussed to some length, what about the data_is_ptr concept? I didn't think there were Arm insns fitting this? Instead I thought some other Arm-specific adjustments to the protocol might be needed. At which point the question of course would be in how far ioreq_t as a whole really fits Arm in its current shape.
Jan
Re: [PATCH V1 03/16] xen/ioreq: Make x86's hvm_ioreq_needs_completion() common
On 14.09.20 17:59, Jan Beulich wrote:
Hi Jan
Quoted 7 lines · Oleksandr Tyshchenko
Quoted 6 lines
xen/include/xen/ioreq.h +0
-0@@ -35,6 +35,13 @@ static inline struct hvm_ioreq_server *get_ioreq_server(const struct domain *d,return GET_IOREQ_SERVER (d, id); }
Quoted 11 lines
xen/include/xen/ioreq.h static inline struct hvm_ioreq_server *get_ioreq_server(const struct domain *d, · line 43
Quoted 6 lines
xen/include/xen/ioreq.h +6
-0+static inline bool hvm_ioreq_needs_completion (const ioreq_t *ioreq) +{ +return ioreq->state ==STATE_IOREQ_READY && + !ioreq->data_is_ptr && + (ioreq->type !=IOREQ_TYPE_PIO || ioreq->dir !=IOREQ_WRITE ); +}While the PIO aspect has been discussed to some length, what about the
data_is_ptrconcept? I didn't think there were Arm insns fitting this? Instead I thought some other Arm-specific adjustments to the protocol might be needed. At which point the question of course would be in how farioreq_tas a whole really fits Arm in its current shape.
I may mistake here but I don't think the "data_is_ptr" is supported.
It worth mentioning that on Arm, all the accesses to MMIO region will do a single memory access. So we set "df" to 0 and "count" to 1. Other ioreq_t fields are in use.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 03/16] xen/ioreq: Make x86's hvm_ioreq_needs_completion() common
In reply to Jan BeulichHi,
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Oleksandr Tyshchenko
xen/include/xen/ioreq.h +0
-0@@ -35,6 +35,13 @@ static inline struct hvm_ioreq_server *get_ioreq_server(const struct domain *d,return GET_IOREQ_SERVER (d, id); }
Quoted 12 lines
xen/include/xen/ioreq.h static inline struct hvm_ioreq_server *get_ioreq_server(const struct domain *d, · line 43
Quoted 6 lines
xen/include/xen/ioreq.h +6
-0+static inline bool hvm_ioreq_needs_completion (const ioreq_t *ioreq) +{ +return ioreq->state ==STATE_IOREQ_READY && + !ioreq->data_is_ptr && + (ioreq->type !=IOREQ_TYPE_PIO || ioreq->dir !=IOREQ_WRITE ); +}While the PIO aspect has been discussed to some length, what about the
data_is_ptrconcept? I didn't think there were Arm insns fitting this? Instead I thought some other Arm-specific adjustments to the protocol might be needed. At which point the question of course would be in how farioreq_tas a whole really fits Arm in its current shape.
I would rather not try to re-invent ioreq_t for Arm if we don't need to. This is only going to increase the amount of arch specific code in a device emulator that really ought to be agnostic.
At the moment, I think it is fine to have "unused" field on Arm as long as they contain the right value.
So I would rather keep the check in common code as well.
Cheers,
Signature · 1 line
Julien Grall
PATCH 4/16 xen/ioreq: Provide alias for the handle_mmio()
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
The IOREQ is a common feature now and Arm will have its own implementation.
But the name of the function is pretty generic and can be confusing on Arm (we already have a try_handle_mmio()).
In order not to rename the function (which is used for a varying set of purposes on x86) globally and get non-confusing variant on Arm provide an alias ioreq_handle_complete_mmio() to be used on common and Arm code.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- new patch
---
--- xen/common/ioreq.c | 2 +- xen/include/asm-x86/hvm/ioreq.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
xen/common/ioreq.c +1 -1
@@ -189,7 +189,7 @@ bool handle_hvm_io_completion(struct vcpu *v)break ;case HVMIO_mmio_completion: -return handle_mmio (); +return ioreq_handle_complete_mmio ();case HVMIO_pio_completion: return handle_pio(vio->io_req.addr, vio->io_req.size,
xen/include/asm-x86/hvm/ioreq.h +2 -0
@@ -42,6 +42,8 @@ void arch_hvm_ioreq_destroy(struct domain *d);#define IOREQ_IO_UNHANDLED X86EMUL_UNHANDLEABLE#define IOREQ_IO_RETRY X86EMUL_RETRY +#define ioreq_handle_complete_mmio handle_mmio +#endif /* __ASM_X86_HVM_IOREQ_H__ */ /*
Signature · 1 line
2.7.4
Re: [PATCH V1 04/16] xen/ioreq: Provide alias for the handle_mmio()
xen/common/ioreq.c bool handle_hvm_io_completion(struct vcpu *v) · line 192
Quoted 8 lines · Oleksandr Tyshchenko
xen/common/ioreq.c +1
-1@@ -189,7 +189,7 @@ bool handle_hvm_io_completion(struct vcpu *v)break ;case HVMIO_mmio_completion: -return handle_mmio (); +return ioreq_handle_complete_mmio ();
Again the question: Any particular reason to have "handle" in here? With the abstraction simply named ioreq_complete_mmio() feel free to add
Jan
Re: [PATCH V1 04/16] xen/ioreq: Provide alias for the handle_mmio()
On 14.09.20 18:10, Jan Beulich wrote:
Hi Jan
Quoted 10 lines · Oleksandr Tyshchenko
xen/common/ioreq.c bool handle_hvm_io_completion(struct vcpu *v) · line 192
Quoted 8 lines
xen/common/ioreq.c +1
-1@@ -189,7 +189,7 @@ bool handle_hvm_io_completion(struct vcpu *v)break ;case HVMIO_mmio_completion: -return handle_mmio (); +return ioreq_handle_complete_mmio ();Again the question: Any particular reason to have "handle" in here?
"Handle" has been already discussed in previous patches). Will remove.
Quoted 3 lines
With the abstraction simply named
ioreq_complete_mmio()feel free to addAcked-by Jan Beulich <[email protected]>
Thank you.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 04/16] xen/ioreq: Provide alias for the handle_mmio()
In reply to Oleksandr TyshchenkoHi Oleksandr,
Quoted 8 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
The IOREQ is a common feature now and Arm will have its own implementation.
But the name of the function is pretty generic and can be confusing on Arm (we already have a
try_handle_mmio()).
Quoted 6 lines
In order not to rename the function (which is used for a varying set of purposes on x86) globally and get non-confusing variant on Arm provide an alias
ioreq_handle_complete_mmio()to be used on common and Arm code.Signed-off-by Julien Grall <[email protected]>
This doesn't look like a code I wrote... Can you make sure I am only credited on what I wrote?
Quoted 1 line
Signed-off-by Oleksandr Tyshchenko <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 04/16] xen/ioreq: Provide alias for the handle_mmio()
Quoted 1 line · Julien Grall
Hi Oleksandr,
Hi Julien
Quoted 10 lines · Oleksandr Tyshchenko
Quoted 8 lines
From: Oleksandr Tyshchenko <[email protected]>
The IOREQ is a common feature now and Arm will have its own implementation.
But the name of the function is pretty generic and can be confusing on Arm (we already have a
try_handle_mmio()).
Quoted 8 lines
Quoted 6 lines
In order not to rename the function (which is used for a varying set of purposes on x86) globally and get non-confusing variant on Arm provide an alias
ioreq_handle_complete_mmio()to be used on common and Arm code.Signed-off-by Julien Grall <[email protected]>This doesn't look like a code I wrote... Can you make sure I am only credited on what I wrote?
I am sorry, for the next series I will re-check all patches.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH 5/16 xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
The IOREQ is a common feature now and these helpers will be used on Arm as is. Move them to include/xen/ioreq.h
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- new patch
---
--- xen/arch/x86/hvm/intercept.c | 1 + xen/include/asm-x86/hvm/io.h | 16 ---------------- xen/include/xen/ioreq.h | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 16 deletions(-)
xen/arch/x86/hvm/intercept.c +1 -0
@@ -17,6 +17,7 @@* this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <xen/ioreq.h> #include <xen/types.h> #include <xen/sched.h> #include <asm/regs.h>
xen/include/asm-x86/hvm/io.h +0 -16
@@ -40,22 +40,6 @@ struct hvm_mmio_ops {hvm_mmio_write_t write; }; -static inline paddr_t hvm_mmio_first_byte (const ioreq_t *p) -{ -return unlikely (p->df) ? - p->addr - (p->count -1ul ) * p->size : - p->addr; -} - -static inline paddr_t hvm_mmio_last_byte (const ioreq_t *p) -{ -unsigned long size = p->size; - -return unlikely (p->df) ? - p->addr + size -1 : - p->addr + (p->count * size) -1 ; -} -typedef int (*portio_action_t )(int dir,unsigned int port,unsigned int bytes,uint32_t *val);
xen/include/xen/ioreq.h +16 -0
@@ -35,6 +35,22 @@ static inline struct hvm_ioreq_server *get_ioreq_server(const struct domain *d,return GET_IOREQ_SERVER (d, id); } +static inline paddr_t hvm_mmio_first_byte (const ioreq_t *p) +{ +return unlikely (p->df) ? + p->addr - (p->count -1ul ) * p->size : + p->addr; +} + +static inline paddr_t hvm_mmio_last_byte (const ioreq_t *p) +{ +unsigned long size = p->size; + +return unlikely (p->df) ? + p->addr + size -1 : + p->addr + (p->count * size) -1 ; +} +static inline bool hvm_ioreq_needs_completion (const ioreq_t *ioreq) { return ioreq->state == STATE_IOREQ_READY &&
Signature · 1 line
2.7.4
Re: [PATCH V1 05/16] xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common
Quoted 4 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
The IOREQ is a common feature now and these helpers will be used on Arm as is. Move them to
include/xen/ioreq.h
I think you also want to renamed them to replace the hvm_ prefix by ioreq_.
Jan
Re: [PATCH V1 05/16] xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common
On 14.09.20 18:13, Jan Beulich wrote:
Hi Jan
Quoted 7 lines · Oleksandr Tyshchenko
Quoted 4 lines
From: Oleksandr Tyshchenko <[email protected]>
The IOREQ is a common feature now and these helpers will be used on Arm as is. Move them to
include/xen/ioreq.hI think you also want to renamed them to replace the
hvm_prefix byioreq_.
ok
Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH 6/16 xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
The IOREQ is a common feature now and these structs will be used on Arm as is. Move them to xen/ioreq.h
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- new patch
---
--- xen/include/asm-x86/hvm/domain.h | 34 ---------------------------------- xen/include/xen/ioreq.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 34 deletions(-)
xen/include/asm-x86/hvm/domain.h +0 -34
@@ -30,40 +30,6 @@#include <public/hvm/dm_op.h> -struct hvm_ioreq_page { -gfn_t gfn; -struct page_info *page; -void *va; -}; - -struct hvm_ioreq_vcpu { -struct list_head list_entry; -struct vcpu *vcpu; -evtchn_port_t ioreq_evtchn; -bool pending; -}; - -#define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1) -#define MAX_NR_IO_RANGES 256 - -struct hvm_ioreq_server { -struct domain *target, *emulator; - -/* Lock to serialize toolstack modifications */ -spinlock_t lock; - -struct hvm_ioreq_page ioreq; -struct list_head ioreq_vcpu_list; -struct hvm_ioreq_page bufioreq; - -/* Lock to serialize access to buffered ioreq ring */ -spinlock_t bufioreq_lock; -evtchn_port_t bufioreq_evtchn; -struct rangeset *range[NR_IO_RANGE_TYPES ]; -bool enabled; -uint8_t bufioreq_handling; -}; -#ifdef CONFIG_MEM_SHARING struct mem_sharing_domain {
xen/include/xen/ioreq.h +34 -0
@@ -23,6 +23,40 @@#include <asm/hvm/ioreq.h> +struct hvm_ioreq_page { +gfn_t gfn; +struct page_info *page; +void *va; +}; + +struct hvm_ioreq_vcpu { +struct list_head list_entry; +struct vcpu *vcpu; +evtchn_port_t ioreq_evtchn; +bool pending; +}; + +#define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1) +#define MAX_NR_IO_RANGES 256 + +struct hvm_ioreq_server { +struct domain *target, *emulator; + +/* Lock to serialize toolstack modifications */ +spinlock_t lock; + +struct hvm_ioreq_page ioreq; +struct list_head ioreq_vcpu_list; +struct hvm_ioreq_page bufioreq; + +/* Lock to serialize access to buffered ioreq ring */ +spinlock_t bufioreq_lock; +evtchn_port_t bufioreq_evtchn; +struct rangeset *range[NR_IO_RANGE_TYPES ]; +bool enabled; +uint8_t bufioreq_handling; +}; +#define GET_IOREQ_SERVER (d, id) \ (d)->arch.hvm.ioreq_server.server[id]
Signature · 1 line
2.7.4
Re: [PATCH V1 06/16] xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common
Quoted 29 lines · Oleksandr Tyshchenko
xen/include/xen/ioreq.h +23
-0@@ -23,6 +23,40 @@#include <asm/hvm/ioreq.h> +struct hvm_ioreq_page { +gfn_t gfn; +struct page_info *page; +void *va; +}; + +struct hvm_ioreq_vcpu { +struct list_head list_entry; +struct vcpu *vcpu; +evtchn_port_t ioreq_evtchn; +bool pending; +}; + +#define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1) +#define MAX_NR_IO_RANGES 256 + +struct hvm_ioreq_server { +struct domain *target, *emulator; + +/* Lock to serialize toolstack modifications */ +spinlock_t lock; + +struct hvm_ioreq_page ioreq;
xen/include/xen/ioreq.h line 58
Quoted 10 lines
xen/include/xen/ioreq.h +10
-0+struct list_head ioreq_vcpu_list; +struct hvm_ioreq_page bufioreq; + +/* Lock to serialize access to buffered ioreq ring */ +spinlock_t bufioreq_lock; +evtchn_port_t bufioreq_evtchn; +struct rangeset *range[NR_IO_RANGE_TYPES ]; +bool enabled; +uint8_t bufioreq_handling; +};
Besides there again being the question of hvm_ prefixes here, is the bufioreq concept something Arm is meaning to make use of? If not, this may want to become conditional ...
Jan
Re: [PATCH V1 06/16] xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common
Hi Jan,
Quoted 36 lines · Jan Beulich
Quoted 35 lines · Oleksandr Tyshchenko
xen/include/xen/ioreq.h +29
-0@@ -23,6 +23,40 @@#include <asm/hvm/ioreq.h> +struct hvm_ioreq_page { +gfn_t gfn; +struct page_info *page; +void *va; +}; + +struct hvm_ioreq_vcpu { +struct list_head list_entry; +struct vcpu *vcpu; +evtchn_port_t ioreq_evtchn; +bool pending; +}; + +#define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1) +#define MAX_NR_IO_RANGES 256 + +struct hvm_ioreq_server { +struct domain *target, *emulator; + +/* Lock to serialize toolstack modifications */ +spinlock_t lock; + +struct hvm_ioreq_page ioreq; +struct list_head ioreq_vcpu_list; +struct hvm_ioreq_page bufioreq; + +/* Lock to serialize access to buffered ioreq ring */ +spinlock_t bufioreq_lock; +evtchn_port_t bufioreq_evtchn;
Quoted 8 lines
xen/include/xen/ioreq.h line 58
Quoted 4 lines
xen/include/xen/ioreq.h +4
-0+struct rangeset *range[NR_IO_RANGE_TYPES ]; +bool enabled; +uint8_t bufioreq_handling; +};Besides there again being the question of
hvm_prefixes here, is the bufioreq concept something Arm is meaning to make use of? If not, this may want to become conditional ...
Yes, I would like to make use of it to optimize virtio notifications as we don't need to wait for them to be processed by the IOREQ server.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 06/16] xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common
In reply to Jan BeulichOn 14.09.20 18:16, Jan Beulich wrote:
Hi Jan
Quoted 35 lines · Oleksandr Tyshchenko
Quoted 34 lines
xen/include/xen/ioreq.h +28
-0@@ -23,6 +23,40 @@#include <asm/hvm/ioreq.h> +struct hvm_ioreq_page { +gfn_t gfn; +struct page_info *page; +void *va; +}; + +struct hvm_ioreq_vcpu { +struct list_head list_entry; +struct vcpu *vcpu; +evtchn_port_t ioreq_evtchn; +bool pending; +}; + +#define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1) +#define MAX_NR_IO_RANGES 256 + +struct hvm_ioreq_server { +struct domain *target, *emulator; + +/* Lock to serialize toolstack modifications */ +spinlock_t lock; + +struct hvm_ioreq_page ioreq; +struct list_head ioreq_vcpu_list; +struct hvm_ioreq_page bufioreq; + +/* Lock to serialize access to buffered ioreq ring */ +spinlock_t bufioreq_lock;
Quoted 8 lines
xen/include/xen/ioreq.h line 58
Quoted 5 lines
xen/include/xen/ioreq.h +5
-0+evtchn_port_t bufioreq_evtchn; +struct rangeset *range[NR_IO_RANGE_TYPES ]; +bool enabled; +uint8_t bufioreq_handling; +};Besides there again being the question of
hvm_prefixes here, is the bufioreq concept something Arm is meaning to make use of? If not, this may want to become conditional ...
The hvm_ prefixes will be removed.
Regarding bufioreq concept I agree with what Julien said. Although we don't need it right away on Arm we can use it later on for the virtio improvements.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH 7/16 xen/dm: Make x86's DM feature common
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
As a lot of x86 code can be re-used on Arm later on, this patch splits devicemodel support into common and arch specific parts.
Also update XSM code a bit to let DM op be used on Arm.
This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- update XSM, related changes were pulled from:
[RFC PATCH V1 04/12] xen/arm: Introduce arch specific bits for IOREQ/DM features
---
--- xen/arch/x86/hvm/dm.c | 287 +++----------------------------------------- xen/common/Makefile | 1 + xen/common/dm.c | 287 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/hypercall.h | 12 ++ xen/include/xsm/dummy.h | 4 +- xen/include/xsm/xsm.h | 6 +- xen/xsm/dummy.c | 2 +- xen/xsm/flask/hooks.c | 5 +- 8 files changed, 327 insertions(+), 277 deletions(-) create mode 100644 xen/common/dm.c
xen/arch/x86/hvm/dm.c +19 -268
@@ -29,13 +29,6 @@#include <public/hvm/hvm_op.h> -struct dmop_args { -domid_t domid; -unsigned int nr_bufs; -/* Reserve enough buf elements for all current hypercalls. */ -struct xen_dm_op_buf buf[2 ]; -}; - static bool _raw_copy_from_guest_buf_offset(void *dst, const struct dmop_args *args, unsigned int buf_idx,
@@ -338,148 +331,20 @@ static int inject_event(struct domain *d,return 0 ; } -static int dm_op (const struct dmop_args *op_args) +int arch_dm_op (struct xen_dm_op *op,struct domain *d, +const struct dmop_args *op_args,bool *const_op) { -struct domain *d; -struct xen_dm_op op; -bool const_op = true;long rc; -size_t offset; - -static const uint8_t op_size[] = { - [XEN_DMOP_create_ioreq_server] =sizeof (struct xen_dm_op_create_ioreq_server ), - [XEN_DMOP_get_ioreq_server_info] =sizeof (struct xen_dm_op_get_ioreq_server_info ), - [XEN_DMOP_map_io_range_to_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range ), - [XEN_DMOP_unmap_io_range_from_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range ), - [XEN_DMOP_set_ioreq_server_state] =sizeof (struct xen_dm_op_set_ioreq_server_state ), - [XEN_DMOP_destroy_ioreq_server] =sizeof (struct xen_dm_op_destroy_ioreq_server ), - [XEN_DMOP_track_dirty_vram] =sizeof (struct xen_dm_op_track_dirty_vram ), - [XEN_DMOP_set_pci_intx_level] =sizeof (struct xen_dm_op_set_pci_intx_level ), - [XEN_DMOP_set_isa_irq_level] =sizeof (struct xen_dm_op_set_isa_irq_level ), - [XEN_DMOP_set_pci_link_route] =sizeof (struct xen_dm_op_set_pci_link_route ), - [XEN_DMOP_modified_memory] =sizeof (struct xen_dm_op_modified_memory ), - [XEN_DMOP_set_mem_type] =sizeof (struct xen_dm_op_set_mem_type ), - [XEN_DMOP_inject_event] =sizeof (struct xen_dm_op_inject_event ), - [XEN_DMOP_inject_msi] =sizeof (struct xen_dm_op_inject_msi ), - [XEN_DMOP_map_mem_type_to_ioreq_server] =sizeof (struct xen_dm_op_map_mem_type_to_ioreq_server ), - [XEN_DMOP_remote_shutdown] =sizeof (struct xen_dm_op_remote_shutdown ), - [XEN_DMOP_relocate_memory] =sizeof (struct xen_dm_op_relocate_memory ), - [XEN_DMOP_pin_memory_cacheattr] =sizeof (struct xen_dm_op_pin_memory_cacheattr ), - }; - - rc =rcu_lock_remote_domain_by_id (op_args->domid, &d); -if ( rc ) -return rc; - -if ( !is_hvm_domain (d) ) - goto out; - - rc =xsm_dm_op (XSM_DM_PRIV , d); -if ( rc ) - goto out; - - offset = offsetof(struct xen_dm_op , u); - - rc = -EFAULT ; -if ( op_args->buf[0 ].size < offset ) - goto out; - -if (copy_from_guest_offset ((void *)&op, op_args->buf[0 ].h,0 , offset) ) - goto out; - -if ( op.op >=ARRAY_SIZE (op_size) ) - { - rc = -EOPNOTSUPP ; - goto out; - } - - op.op =array_index_nospec (op.op,ARRAY_SIZE (op_size)); - -if ( op_args->buf[0 ].size < offset + op_size[op.op] ) - goto out; - -if (copy_from_guest_offset ((void *)&op.u, op_args->buf[0 ].h, offset, - op_size[op.op]) ) - goto out; - - rc = -EINVAL ; -if ( op.pad ) - goto out; - -switch ( op.op ) - { -case XEN_DMOP_create_ioreq_server: - { -struct xen_dm_op_create_ioreq_server *data = - &op.u.create_ioreq_server; - - const_op = false; - - rc = -EINVAL ; -if ( data->pad[0 ] || data->pad[1 ] || data->pad[2 ] ) -break ; - - rc =hvm_create_ioreq_server (d, data->handle_bufioreq, - &data->id); -break ; - } -case XEN_DMOP_get_ioreq_server_info: +switch ( op->op ) { -struct xen_dm_op_get_ioreq_server_info *data = - &op.u.get_ioreq_server_info; -const uint16_t valid_flags = XEN_DMOP_no_gfns; - - const_op = false; - - rc = -EINVAL ; -if ( data->flags & ~valid_flags ) -break ; - - rc =hvm_get_ioreq_server_info (d, data->id, - (data->flags & XEN_DMOP_no_gfns) ? -NULL : &data->ioreq_gfn, - (data->flags & XEN_DMOP_no_gfns) ? -NULL : &data->bufioreq_gfn, - &data->bufioreq_port); -break ; - } - -case XEN_DMOP_map_io_range_to_ioreq_server: - { -const struct xen_dm_op_ioreq_server_range *data = - &op.u.map_io_range_to_ioreq_server; - - rc = -EINVAL ; -if ( data->pad ) -break ; - - rc =hvm_map_io_range_to_ioreq_server (d, data->id, data->type, - data->start, data->end); -break ; - } - -case XEN_DMOP_unmap_io_range_from_ioreq_server: - { -const struct xen_dm_op_ioreq_server_range *data = - &op.u.unmap_io_range_from_ioreq_server; - - rc = -EINVAL ; -if ( data->pad ) -break ; - - rc =hvm_unmap_io_range_from_ioreq_server (d, data->id, data->type, - data->start, data->end); -break ; - } -case XEN_DMOP_map_mem_type_to_ioreq_server: {struct xen_dm_op_map_mem_type_to_ioreq_server *data = - &op.u.map_mem_type_to_ioreq_server; + &op->u.map_mem_type_to_ioreq_server;unsigned long first_gfn = data->opaque; - const_op = false; + *const_op = false; rc = -EOPNOTSUPP ;if ( !hap_enabled (d) )
@@ -523,36 +388,10 @@ static int dm_op(const struct dmop_args *op_args)break ; } -case XEN_DMOP_set_ioreq_server_state: - { -const struct xen_dm_op_set_ioreq_server_state *data = - &op.u.set_ioreq_server_state; - - rc = -EINVAL ; -if ( data->pad ) -break ; - - rc =hvm_set_ioreq_server_state (d, data->id, !!data->enabled); -break ; - } - -case XEN_DMOP_destroy_ioreq_server: - { -const struct xen_dm_op_destroy_ioreq_server *data = - &op.u.destroy_ioreq_server; - - rc = -EINVAL ; -if ( data->pad ) -break ; - - rc =hvm_destroy_ioreq_server (d, data->id); -break ; - } -case XEN_DMOP_track_dirty_vram: {const struct xen_dm_op_track_dirty_vram *data = - &op.u.track_dirty_vram; + &op->u.track_dirty_vram; rc = -EINVAL ;if ( data->pad )
@@ -568,7 +407,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_set_pci_intx_level: {const struct xen_dm_op_set_pci_intx_level *data = - &op.u.set_pci_intx_level; + &op->u.set_pci_intx_level; rc = set_pci_intx_level(d, data->domain, data->bus, data->device, data->intx,
@@ -579,7 +418,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_set_isa_irq_level: {const struct xen_dm_op_set_isa_irq_level *data = - &op.u.set_isa_irq_level; + &op->u.set_isa_irq_level; rc =set_isa_irq_level (d, data->isa_irq, data->level);break ;
@@ -588,7 +427,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_set_pci_link_route: {const struct xen_dm_op_set_pci_link_route *data = - &op.u.set_pci_link_route; + &op->u.set_pci_link_route; rc =hvm_set_pci_link_route (d, data->link, data->isa_irq);break ;
@@ -597,19 +436,19 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_modified_memory: {struct xen_dm_op_modified_memory *data = - &op.u.modified_memory; + &op->u.modified_memory; rc =modified_memory (d, op_args, data); - const_op = !rc; + *const_op = !rc;break ; }case XEN_DMOP_set_mem_type: {struct xen_dm_op_set_mem_type *data = - &op.u.set_mem_type; + &op->u.set_mem_type; - const_op = false; + *const_op = false; rc = -EINVAL ;if ( data->pad )
@@ -622,7 +461,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_inject_event: {const struct xen_dm_op_inject_event *data = - &op.u.inject_event; + &op->u.inject_event; rc = -EINVAL ;if ( data->pad0 || data->pad1 )
@@ -635,7 +474,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_inject_msi: {const struct xen_dm_op_inject_msi *data = - &op.u.inject_msi; + &op->u.inject_msi; rc = -EINVAL ;if ( data->pad )
@@ -648,7 +487,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_remote_shutdown: {const struct xen_dm_op_remote_shutdown *data = - &op.u.remote_shutdown; + &op->u.remote_shutdown;domain_shutdown (d, data->reason); rc =0 ;
@@ -657,7 +496,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_relocate_memory: { -struct xen_dm_op_relocate_memory *data = &op.u.relocate_memory; +struct xen_dm_op_relocate_memory *data = &op->u.relocate_memory;struct xen_add_to_physmap xatp = { .domid = op_args->domid, .size = data->size,
@@ -680,7 +519,7 @@ static int dm_op(const struct dmop_args *op_args) data->size -= rc; data->src_gfn += rc; data->dst_gfn += rc; - const_op = false; + *const_op = false; rc = -ERESTART ; }break ;
@@ -689,7 +528,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_pin_memory_cacheattr: {const struct xen_dm_op_pin_memory_cacheattr *data = - &op.u.pin_memory_cacheattr; + &op->u.pin_memory_cacheattr;if ( data->pad ) {
@@ -707,94 +546,6 @@ static int dm_op(const struct dmop_args *op_args)break ; } -if ( (!rc || rc == -ERESTART ) && - !const_op &©_to_guest_offset (op_args->buf[0 ].h, offset, - (void *)&op.u, op_size[op.op]) ) - rc = -EFAULT ; - - out: -rcu_unlock_domain (d); - -return rc; -} - -CHECK_dm_op_create_ioreq_server; -CHECK_dm_op_get_ioreq_server_info; -CHECK_dm_op_ioreq_server_range; -CHECK_dm_op_set_ioreq_server_state; -CHECK_dm_op_destroy_ioreq_server; -CHECK_dm_op_track_dirty_vram; -CHECK_dm_op_set_pci_intx_level; -CHECK_dm_op_set_isa_irq_level; -CHECK_dm_op_set_pci_link_route; -CHECK_dm_op_modified_memory; -CHECK_dm_op_set_mem_type; -CHECK_dm_op_inject_event; -CHECK_dm_op_inject_msi; -CHECK_dm_op_remote_shutdown; -CHECK_dm_op_relocate_memory; -CHECK_dm_op_pin_memory_cacheattr; - -int compat_dm_op (domid_t domid, -unsigned int nr_bufs, -XEN_GUEST_HANDLE_PARAM (void ) bufs) -{ -struct dmop_args args; -unsigned int i; -int rc; - -if ( nr_bufs >ARRAY_SIZE (args.buf) ) -return -E2BIG ; - - args.domid = domid; - args.nr_bufs =array_index_nospec (nr_bufs,ARRAY_SIZE (args.buf) +1 ); - -for ( i =0 ; i < args.nr_bufs; i++ ) - { -struct compat_dm_op_buf cmp; - -if (copy_from_guest_offset (&cmp, bufs, i,1 ) ) -return -EFAULT ; - -#define XLAT_dm_op_buf_HNDL_h (_d_, _s_) \ - guest_from_compat_handle((_d_)->h, (_s_)->h) - -XLAT_dm_op_buf (&args.buf[i], &cmp); - -#undef XLAT_dm_op_buf_HNDL_h - } - - rc =dm_op (&args); - -if ( rc == -ERESTART ) - rc =hypercall_create_continuation (__HYPERVISOR_dm_op,"iih" , - domid, nr_bufs, bufs); - -return rc; -} - -long do_dm_op (domid_t domid, -unsigned int nr_bufs, -XEN_GUEST_HANDLE_PARAM (xen_dm_op_buf_t) bufs) -{ -struct dmop_args args; -int rc; - -if ( nr_bufs >ARRAY_SIZE (args.buf) ) -return -E2BIG ; - - args.domid = domid; - args.nr_bufs =array_index_nospec (nr_bufs,ARRAY_SIZE (args.buf) +1 ); - -if (copy_from_guest_offset (&args.buf[0 ], bufs,0 , args.nr_bufs) ) -return -EFAULT ; - - rc =dm_op (&args); - -if ( rc == -ERESTART ) - rc =hypercall_create_continuation (__HYPERVISOR_dm_op,"iih" , - domid, nr_bufs, bufs); -return rc; }
xen/common/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE) += device_tree.o +obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domctl.o obj-y += domain.o obj-y += event_2l.o
xen/common/dm.c new file +287 -0
287 lines not on this page · raw message
xen/include/xen/hypercall.h +12 -0
@@ -150,6 +150,18 @@ do_dm_op( unsigned int nr_bufs, XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs); +struct dmop_args { +domid_t domid; +unsigned int nr_bufs; +/* Reserve enough buf elements for all current hypercalls. */ +struct xen_dm_op_buf buf[2 ]; +}; + +int arch_dm_op (struct xen_dm_op *op, +struct domain *d, +const struct dmop_args *op_args, +bool *const_op); +#ifdef CONFIG_HYPFS extern long do_hypfs_op(
xen/include/xsm/dummy.h +2 -2
@@ -723,14 +723,14 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int } } +#endif /* CONFIG_X86 */ + static XSM_INLINE int xsm_dm_op(XSM_DEFAULT_ARG struct domain *d) {XSM_ASSERT_ACTION (XSM_DM_PRIV );return xsm_default_action (action, current->domain, d); } -#endif /* CONFIG_X86 */ -#ifdef CONFIG_ARGO static XSM_INLINE int xsm_argo_enable(const struct domain *d) {
xen/include/xsm/xsm.h +3 -3
@@ -177,8 +177,8 @@ struct xsm_operations {int (*ioport_permission) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);int (*ioport_mapping) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);int (*pmu_op) (struct domain *d,unsigned int op); -int (*dm_op) (struct domain *d);#endif +int (*dm_op) (struct domain *d);int (*xen_version) (uint32_t cmd);int (*domain_resource_map) (struct domain *d);#ifdef CONFIG_ARGO
@@ -688,13 +688,13 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int return xsm_ops->pmu_op(d, op); } +#endif /* CONFIG_X86 */ +static inline int xsm_dm_op (xsm_default_t def,struct domain *d) {return xsm_ops->dm_op (d); } -#endif /* CONFIG_X86 */ -static inline int xsm_xen_version (xsm_default_t def,uint32_t op) {return xsm_ops->xen_version (op);
xen/xsm/dummy.c +1 -1
@@ -148,8 +148,8 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, ioport_permission);set_to_dummy_if_null (ops, ioport_mapping);set_to_dummy_if_null (ops, pmu_op); -set_to_dummy_if_null (ops, dm_op);#endif +set_to_dummy_if_null (ops, dm_op);set_to_dummy_if_null (ops, xen_version);set_to_dummy_if_null (ops, domain_resource_map);#ifdef CONFIG_ARGO
xen/xsm/flask/hooks.c +2 -3
@@ -1662,14 +1662,13 @@ static int flask_pmu_op (struct domain *d, unsigned int op) return -EPERM; } } +#endif /* CONFIG_X86 */ static int flask_dm_op (struct domain *d) {return current_has_perm (d,SECCLASS_HVM ,HVM__DM ); } -#endif /* CONFIG_X86 */ -static int flask_xen_version (uint32_t op) {u32 dsid =domain_sid (current->domain);
@@ -1872,8 +1871,8 @@ static struct xsm_operations flask_ops = { .ioport_permission = flask_ioport_permission, .ioport_mapping = flask_ioport_mapping, .pmu_op = flask_pmu_op, - .dm_op = flask_dm_op, #endif + .dm_op = flask_dm_op, .xen_version = flask_xen_version, .domain_resource_map = flask_domain_resource_map, #ifdef CONFIG_ARGO
Signature · 1 line
2.7.4
Re: [PATCH V1 07/16] xen/dm: Make x86's DM feature common
Quoted 11 lines · Oleksandr Tyshchenko
xen/include/xen/hypercall.h +5
-0@@ -150,6 +150,18 @@ do_dm_op( unsigned int nr_bufs, XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs); +struct dmop_args { +domid_t domid; +unsigned int nr_bufs; +/* Reserve enough buf elements for all current hypercalls. */ +struct xen_dm_op_buf buf[2 ];
xen/include/xen/hypercall.h do_dm_op( · line 167
Quoted 10 lines
xen/include/xen/hypercall.h +7
-0+}; + +int arch_dm_op (struct xen_dm_op *op, +struct domain *d, +const struct dmop_args *op_args, +bool *const_op); +#ifdef CONFIG_HYPFS extern long do_hypfs_op(
There are exactly two CUs which need to see these two declarations. Personally I think they should go into a new header, or at least into one that half-way fits (from the pov of its other contents) and doesn't get included by half the code base. But maybe it's just me ...
Jan
Re: [PATCH V1 07/16] xen/dm: Make x86's DM feature common
On 14.09.20 18:56, Jan Beulich wrote:
Hi Jan
Quoted 19 lines · Oleksandr Tyshchenko
Quoted 18 lines
xen/include/xen/hypercall.h +12
-0@@ -150,6 +150,18 @@ do_dm_op( unsigned int nr_bufs, XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs); +struct dmop_args { +domid_t domid; +unsigned int nr_bufs; +/* Reserve enough buf elements for all current hypercalls. */ +struct xen_dm_op_buf buf[2 ]; +}; + +int arch_dm_op (struct xen_dm_op *op, +struct domain *d, +const struct dmop_args *op_args, +bool *const_op); +
Quoted 8 lines
xen/include/xen/hypercall.h do_dm_op( · line 167
Quoted 3 lines
xen/include/xen/hypercall.h +0
-0#ifdef CONFIG_HYPFS extern long do_hypfs_op(There are exactly two CUs which need to see these two declarations. Personally I think they should go into a new header, or at least into one that half-way fits (from the pov of its other contents) and doesn't get included by half the code base. But maybe it's just me ...
I am afraid, I didn't get why this header is not suitable for keeping this stuff...
But, I don't against moving this into a new header (probably dm.h?)
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 07/16] xen/dm: Make x86's DM feature common
Quoted 32 lines · Oleksandr
On 14.09.20 18:56, Jan Beulich wrote:
Hi JanQuoted 19 lines · Oleksandr Tyshchenko
Quoted 18 lines
xen/include/xen/hypercall.h +12
-0@@ -150,6 +150,18 @@ do_dm_op( unsigned int nr_bufs, XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs); +struct dmop_args { +domid_t domid; +unsigned int nr_bufs; +/* Reserve enough buf elements for all current hypercalls. */ +struct xen_dm_op_buf buf[2 ]; +}; + +int arch_dm_op (struct xen_dm_op *op, +struct domain *d, +const struct dmop_args *op_args, +bool *const_op); +Quoted 8 lines
xen/include/xen/hypercall.h do_dm_op( · line 167
Quoted 3 lines
xen/include/xen/hypercall.h +0
-0#ifdef CONFIG_HYPFS extern long do_hypfs_op(There are exactly two CUs which need to see these two declarations. Personally I think they should go into a new header, or at least into one that half-way fits (from the pov of its other contents) and doesn't get included by half the code base. But maybe it's just me ...
Quoted 2 lines
I am afraid, I didn't get why this header is not suitable for keeping this stuff...
While I have no major objection against exposing arch_dm_op() to more than just the relevant CUs, I don't think I'd like to see struct dmop_args becoming visible to "everyone", and in particular changes to it causing a re-build of (almost) everything.
Jan
Re: [PATCH V1 07/16] xen/dm: Make x86's DM feature common
On 24.09.20 14:03, Jan Beulich wrote:
Hi Jan
Quoted 31 lines · Oleksandr
Quoted 30 lines · Jan Beulich
Hi Jan
Quoted 27 lines · Oleksandr Tyshchenko
Quoted 11 lines
xen/include/xen/hypercall.h +5
-0@@ -150,6 +150,18 @@ do_dm_op( unsigned int nr_bufs, XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs); +struct dmop_args { +domid_t domid; +unsigned int nr_bufs; +/* Reserve enough buf elements for all current hypercalls. */ +struct xen_dm_op_buf buf[2 ];xen/include/xen/hypercall.h do_dm_op( · line 167
Quoted 10 lines
xen/include/xen/hypercall.h +7
-0+}; + +int arch_dm_op (struct xen_dm_op *op, +struct domain *d, +const struct dmop_args *op_args, +bool *const_op); +#ifdef CONFIG_HYPFS extern long do_hypfs_op(There are exactly two CUs which need to see these two declarations. Personally I think they should go into a new header, or at least into one that half-way fits (from the pov of its other contents) and doesn't get included by half the code base. But maybe it's just me ...
Quoted 6 lines
Quoted 2 lines
I am afraid, I didn't get why this header is not suitable for keeping this stuff...
While I have no major objection against exposing
arch_dm_op()to more than just the relevant CUs, I don't think I'd like to see structdmop_argsbecoming visible to "everyone", and in particular changes to it causing a re-build of (almost) everything.
Thank you for clarification, I got your point
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 07/16] xen/dm: Make x86's DM feature common
In reply to Oleksandr TyshchenkoQuoted 1 line · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
I believe I am the original author of this code. So this needs to be fixed accordingly.
Quoted 866 lines
As a lot of x86 code can be re-used on Arm later on, this patch splits devicemodel support into common and arch specific parts.
Also update XSM code a bit to let DM op be used on Arm.
This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes RFC -> V1:
- update XSM, related changes were pulled from:
[RFC PATCH V1 04/12] xen/arm: Introduce arch specific bits for IOREQ/DM features
------ xen/arch/x86/hvm/dm.c | 287 +++----------------------------------------- xen/common/Makefile | 1 + xen/common/dm.c | 287 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/hypercall.h | 12 ++ xen/include/xsm/dummy.h | 4 +- xen/include/xsm/xsm.h | 6 +- xen/xsm/dummy.c | 2 +- xen/xsm/flask/hooks.c | 5 +- 8 files changed, 327 insertions(+), 277 deletions(-)create mode 100644
xen/common/dm.cxen/arch/x86/hvm/dm.c +19
-268@@ -29,13 +29,6 @@#include <public/hvm/hvm_op.h> -struct dmop_args { -domid_t domid; -unsigned int nr_bufs; -/* Reserve enough buf elements for all current hypercalls. */ -struct xen_dm_op_buf buf[2 ]; -}; - static bool _raw_copy_from_guest_buf_offset(void *dst, const struct dmop_args *args, unsigned int buf_idx,@@ -338,148 +331,20 @@ static int inject_event(struct domain *d,return 0 ; } -static int dm_op (const struct dmop_args *op_args) +int arch_dm_op (struct xen_dm_op *op,struct domain *d, +const struct dmop_args *op_args,bool *const_op) { -struct domain *d; -struct xen_dm_op op; -bool const_op = true;long rc; -size_t offset; - -static const uint8_t op_size[] = { - [XEN_DMOP_create_ioreq_server] =sizeof (struct xen_dm_op_create_ioreq_server ), - [XEN_DMOP_get_ioreq_server_info] =sizeof (struct xen_dm_op_get_ioreq_server_info ), - [XEN_DMOP_map_io_range_to_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range ), - [XEN_DMOP_unmap_io_range_from_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range ), - [XEN_DMOP_set_ioreq_server_state] =sizeof (struct xen_dm_op_set_ioreq_server_state ), - [XEN_DMOP_destroy_ioreq_server] =sizeof (struct xen_dm_op_destroy_ioreq_server ), - [XEN_DMOP_track_dirty_vram] =sizeof (struct xen_dm_op_track_dirty_vram ), - [XEN_DMOP_set_pci_intx_level] =sizeof (struct xen_dm_op_set_pci_intx_level ), - [XEN_DMOP_set_isa_irq_level] =sizeof (struct xen_dm_op_set_isa_irq_level ), - [XEN_DMOP_set_pci_link_route] =sizeof (struct xen_dm_op_set_pci_link_route ), - [XEN_DMOP_modified_memory] =sizeof (struct xen_dm_op_modified_memory ), - [XEN_DMOP_set_mem_type] =sizeof (struct xen_dm_op_set_mem_type ), - [XEN_DMOP_inject_event] =sizeof (struct xen_dm_op_inject_event ), - [XEN_DMOP_inject_msi] =sizeof (struct xen_dm_op_inject_msi ), - [XEN_DMOP_map_mem_type_to_ioreq_server] =sizeof (struct xen_dm_op_map_mem_type_to_ioreq_server ), - [XEN_DMOP_remote_shutdown] =sizeof (struct xen_dm_op_remote_shutdown ), - [XEN_DMOP_relocate_memory] =sizeof (struct xen_dm_op_relocate_memory ), - [XEN_DMOP_pin_memory_cacheattr] =sizeof (struct xen_dm_op_pin_memory_cacheattr ), - }; - - rc =rcu_lock_remote_domain_by_id (op_args->domid, &d); -if ( rc ) -return rc; - -if ( !is_hvm_domain (d) ) - goto out; - - rc =xsm_dm_op (XSM_DM_PRIV , d); -if ( rc ) - goto out; - - offset = offsetof(struct xen_dm_op , u); - - rc = -EFAULT ; -if ( op_args->buf[0 ].size < offset ) - goto out; - -if (copy_from_guest_offset ((void *)&op, op_args->buf[0 ].h,0 , offset) ) - goto out; - -if ( op.op >=ARRAY_SIZE (op_size) ) - { - rc = -EOPNOTSUPP ; - goto out; - } - - op.op =array_index_nospec (op.op,ARRAY_SIZE (op_size)); - -if ( op_args->buf[0 ].size < offset + op_size[op.op] ) - goto out; - -if (copy_from_guest_offset ((void *)&op.u, op_args->buf[0 ].h, offset, - op_size[op.op]) ) - goto out; - - rc = -EINVAL ; -if ( op.pad ) - goto out; - -switch ( op.op ) - { -case XEN_DMOP_create_ioreq_server: - { -struct xen_dm_op_create_ioreq_server *data = - &op.u.create_ioreq_server; - - const_op = false; - - rc = -EINVAL ; -if ( data->pad[0 ] || data->pad[1 ] || data->pad[2 ] ) -break ; - - rc =hvm_create_ioreq_server (d, data->handle_bufioreq, - &data->id); -break ; - } -case XEN_DMOP_get_ioreq_server_info: +switch ( op->op ) { -struct xen_dm_op_get_ioreq_server_info *data = - &op.u.get_ioreq_server_info; -const uint16_t valid_flags = XEN_DMOP_no_gfns; - - const_op = false; - - rc = -EINVAL ; -if ( data->flags & ~valid_flags ) -break ; - - rc =hvm_get_ioreq_server_info (d, data->id, - (data->flags & XEN_DMOP_no_gfns) ? -NULL : &data->ioreq_gfn, - (data->flags & XEN_DMOP_no_gfns) ? -NULL : &data->bufioreq_gfn, - &data->bufioreq_port); -break ; - } - -case XEN_DMOP_map_io_range_to_ioreq_server: - { -const struct xen_dm_op_ioreq_server_range *data = - &op.u.map_io_range_to_ioreq_server; - - rc = -EINVAL ; -if ( data->pad ) -break ; - - rc =hvm_map_io_range_to_ioreq_server (d, data->id, data->type, - data->start, data->end); -break ; - } - -case XEN_DMOP_unmap_io_range_from_ioreq_server: - { -const struct xen_dm_op_ioreq_server_range *data = - &op.u.unmap_io_range_from_ioreq_server; - - rc = -EINVAL ; -if ( data->pad ) -break ; - - rc =hvm_unmap_io_range_from_ioreq_server (d, data->id, data->type, - data->start, data->end); -break ; - } -case XEN_DMOP_map_mem_type_to_ioreq_server: {struct xen_dm_op_map_mem_type_to_ioreq_server *data = - &op.u.map_mem_type_to_ioreq_server; + &op->u.map_mem_type_to_ioreq_server;unsigned long first_gfn = data->opaque; - const_op = false; + *const_op = false; rc = -EOPNOTSUPP ;if ( !hap_enabled (d) )@@ -523,36 +388,10 @@ static int dm_op(const struct dmop_args *op_args)break ; } -case XEN_DMOP_set_ioreq_server_state: - { -const struct xen_dm_op_set_ioreq_server_state *data = - &op.u.set_ioreq_server_state; - - rc = -EINVAL ; -if ( data->pad ) -break ; - - rc =hvm_set_ioreq_server_state (d, data->id, !!data->enabled); -break ; - } - -case XEN_DMOP_destroy_ioreq_server: - { -const struct xen_dm_op_destroy_ioreq_server *data = - &op.u.destroy_ioreq_server; - - rc = -EINVAL ; -if ( data->pad ) -break ; - - rc =hvm_destroy_ioreq_server (d, data->id); -break ; - } -case XEN_DMOP_track_dirty_vram: {const struct xen_dm_op_track_dirty_vram *data = - &op.u.track_dirty_vram; + &op->u.track_dirty_vram; rc = -EINVAL ;if ( data->pad )@@ -568,7 +407,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_set_pci_intx_level: {const struct xen_dm_op_set_pci_intx_level *data = - &op.u.set_pci_intx_level; + &op->u.set_pci_intx_level; rc = set_pci_intx_level(d, data->domain, data->bus, data->device, data->intx,@@ -579,7 +418,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_set_isa_irq_level: {const struct xen_dm_op_set_isa_irq_level *data = - &op.u.set_isa_irq_level; + &op->u.set_isa_irq_level; rc =set_isa_irq_level (d, data->isa_irq, data->level);break ;@@ -588,7 +427,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_set_pci_link_route: {const struct xen_dm_op_set_pci_link_route *data = - &op.u.set_pci_link_route; + &op->u.set_pci_link_route; rc =hvm_set_pci_link_route (d, data->link, data->isa_irq);break ;@@ -597,19 +436,19 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_modified_memory: {struct xen_dm_op_modified_memory *data = - &op.u.modified_memory; + &op->u.modified_memory; rc =modified_memory (d, op_args, data); - const_op = !rc; + *const_op = !rc;break ; }case XEN_DMOP_set_mem_type: {struct xen_dm_op_set_mem_type *data = - &op.u.set_mem_type; + &op->u.set_mem_type; - const_op = false; + *const_op = false; rc = -EINVAL ;if ( data->pad )@@ -622,7 +461,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_inject_event: {const struct xen_dm_op_inject_event *data = - &op.u.inject_event; + &op->u.inject_event; rc = -EINVAL ;if ( data->pad0 || data->pad1 )@@ -635,7 +474,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_inject_msi: {const struct xen_dm_op_inject_msi *data = - &op.u.inject_msi; + &op->u.inject_msi; rc = -EINVAL ;if ( data->pad )@@ -648,7 +487,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_remote_shutdown: {const struct xen_dm_op_remote_shutdown *data = - &op.u.remote_shutdown; + &op->u.remote_shutdown;domain_shutdown (d, data->reason); rc =0 ;@@ -657,7 +496,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_relocate_memory: { -struct xen_dm_op_relocate_memory *data = &op.u.relocate_memory; +struct xen_dm_op_relocate_memory *data = &op->u.relocate_memory;struct xen_add_to_physmap xatp = { .domid = op_args->domid, .size = data->size,@@ -680,7 +519,7 @@ static int dm_op(const struct dmop_args *op_args) data->size -= rc; data->src_gfn += rc; data->dst_gfn += rc; - const_op = false; + *const_op = false; rc = -ERESTART ; }break ;@@ -689,7 +528,7 @@ static int dm_op(const struct dmop_args *op_args)case XEN_DMOP_pin_memory_cacheattr: {const struct xen_dm_op_pin_memory_cacheattr *data = - &op.u.pin_memory_cacheattr; + &op->u.pin_memory_cacheattr;if ( data->pad ) {@@ -707,94 +546,6 @@ static int dm_op(const struct dmop_args *op_args)break ; } -if ( (!rc || rc == -ERESTART ) && - !const_op &©_to_guest_offset (op_args->buf[0 ].h, offset, - (void *)&op.u, op_size[op.op]) ) - rc = -EFAULT ; - - out: -rcu_unlock_domain (d); - -return rc; -} - -CHECK_dm_op_create_ioreq_server; -CHECK_dm_op_get_ioreq_server_info; -CHECK_dm_op_ioreq_server_range; -CHECK_dm_op_set_ioreq_server_state; -CHECK_dm_op_destroy_ioreq_server; -CHECK_dm_op_track_dirty_vram; -CHECK_dm_op_set_pci_intx_level; -CHECK_dm_op_set_isa_irq_level; -CHECK_dm_op_set_pci_link_route; -CHECK_dm_op_modified_memory; -CHECK_dm_op_set_mem_type; -CHECK_dm_op_inject_event; -CHECK_dm_op_inject_msi; -CHECK_dm_op_remote_shutdown; -CHECK_dm_op_relocate_memory; -CHECK_dm_op_pin_memory_cacheattr; - -int compat_dm_op (domid_t domid, -unsigned int nr_bufs, -XEN_GUEST_HANDLE_PARAM (void ) bufs) -{ -struct dmop_args args; -unsigned int i; -int rc; - -if ( nr_bufs >ARRAY_SIZE (args.buf) ) -return -E2BIG ; - - args.domid = domid; - args.nr_bufs =array_index_nospec (nr_bufs,ARRAY_SIZE (args.buf) +1 ); - -for ( i =0 ; i < args.nr_bufs; i++ ) - { -struct compat_dm_op_buf cmp; - -if (copy_from_guest_offset (&cmp, bufs, i,1 ) ) -return -EFAULT ; - -#define XLAT_dm_op_buf_HNDL_h (_d_, _s_) \ - guest_from_compat_handle((_d_)->h, (_s_)->h) - -XLAT_dm_op_buf (&args.buf[i], &cmp); - -#undef XLAT_dm_op_buf_HNDL_h - } - - rc =dm_op (&args); - -if ( rc == -ERESTART ) - rc =hypercall_create_continuation (__HYPERVISOR_dm_op,"iih" , - domid, nr_bufs, bufs); - -return rc; -} - -long do_dm_op (domid_t domid, -unsigned int nr_bufs, -XEN_GUEST_HANDLE_PARAM (xen_dm_op_buf_t) bufs) -{ -struct dmop_args args; -int rc; - -if ( nr_bufs >ARRAY_SIZE (args.buf) ) -return -E2BIG ; - - args.domid = domid; - args.nr_bufs =array_index_nospec (nr_bufs,ARRAY_SIZE (args.buf) +1 ); - -if (copy_from_guest_offset (&args.buf[0 ], bufs,0 , args.nr_bufs) ) -return -EFAULT ; - - rc =dm_op (&args); - -if ( rc == -ERESTART ) - rc =hypercall_create_continuation (__HYPERVISOR_dm_op,"iih" , - domid, nr_bufs, bufs); -return rc; }xen/common/Makefile +1
-0@@ -6,6 +6,7 @@ obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE) += device_tree.o +obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domctl.o obj-y += domain.o obj-y += event_2l.oxen/common/dm.c new file +287
-0@@ -0,0 +1,287 @@ +/* +* Copyright (c) 2016 Citrix Systems Inc. +* Copyright (c) 2019 Arm ltd. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <xen/guest_access.h> +#include <xen/hypercall.h> +#include <xen/ioreq.h> +#include <xen/nospec.h> + +static int dm_op (const struct dmop_args *op_args) +{ +struct domain *d; +struct xen_dm_op op; +long rc; +bool const_op = true; +const size_t offset = offsetof(struct xen_dm_op , u); + +static const uint8_t op_size[] = { + [XEN_DMOP_create_ioreq_server] =sizeof (struct xen_dm_op_create_ioreq_server ), + [XEN_DMOP_get_ioreq_server_info] =sizeof (struct xen_dm_op_get_ioreq_server_info ), + [XEN_DMOP_map_io_range_to_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range ), + [XEN_DMOP_unmap_io_range_from_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range ), + [XEN_DMOP_set_ioreq_server_state] =sizeof (struct xen_dm_op_set_ioreq_server_state ), + [XEN_DMOP_destroy_ioreq_server] =sizeof (struct xen_dm_op_destroy_ioreq_server ), + [XEN_DMOP_track_dirty_vram] =sizeof (struct xen_dm_op_track_dirty_vram ), + [XEN_DMOP_set_pci_intx_level] =sizeof (struct xen_dm_op_set_pci_intx_level ), + [XEN_DMOP_set_isa_irq_level] =sizeof (struct xen_dm_op_set_isa_irq_level ), + [XEN_DMOP_set_pci_link_route] =sizeof (struct xen_dm_op_set_pci_link_route ), + [XEN_DMOP_modified_memory] =sizeof (struct xen_dm_op_modified_memory ), + [XEN_DMOP_set_mem_type] =sizeof (struct xen_dm_op_set_mem_type ), + [XEN_DMOP_inject_event] =sizeof (struct xen_dm_op_inject_event ), + [XEN_DMOP_inject_msi] =sizeof (struct xen_dm_op_inject_msi ), + [XEN_DMOP_map_mem_type_to_ioreq_server] =sizeof (struct xen_dm_op_map_mem_type_to_ioreq_server ), + [XEN_DMOP_remote_shutdown] =sizeof (struct xen_dm_op_remote_shutdown ), + [XEN_DMOP_relocate_memory] =sizeof (struct xen_dm_op_relocate_memory ), + [XEN_DMOP_pin_memory_cacheattr] =sizeof (struct xen_dm_op_pin_memory_cacheattr ), + }; + + rc =rcu_lock_remote_domain_by_id (op_args->domid, &d); +if ( rc ) +return rc; + +if ( !is_hvm_domain (d) ) + goto out; + + rc =xsm_dm_op (XSM_DM_PRIV , d); +if ( rc ) + goto out; + + rc = -EFAULT ; +if ( op_args->buf[0 ].size < offset ) + goto out; + +if (copy_from_guest_offset ((void *)&op, op_args->buf[0 ].h,0 , offset) ) + goto out; + +if ( op.op >=ARRAY_SIZE (op_size) ) + { + rc = -EOPNOTSUPP ; + goto out; + } + + op.op =array_index_nospec (op.op,ARRAY_SIZE (op_size)); + +if ( op_args->buf[0 ].size < offset + op_size[op.op] ) + goto out; + +if (copy_from_guest_offset ((void *)&op.u, op_args->buf[0 ].h, offset, + op_size[op.op]) ) + goto out; + + rc = -EINVAL ; +if ( op.pad ) + goto out; + +switch ( op.op ) + { +case XEN_DMOP_create_ioreq_server: + { +struct xen_dm_op_create_ioreq_server *data = + &op.u.create_ioreq_server; + + const_op = false; + + rc = -EINVAL ; +if ( data->pad[0 ] || data->pad[1 ] || data->pad[2 ] ) +break ; + + rc =hvm_create_ioreq_server (d, data->handle_bufioreq, + &data->id); +break ; + } + +case XEN_DMOP_get_ioreq_server_info: + { +struct xen_dm_op_get_ioreq_server_info *data = + &op.u.get_ioreq_server_info; +const uint16_t valid_flags = XEN_DMOP_no_gfns; + + const_op = false; + + rc = -EINVAL ; +if ( data->flags & ~valid_flags ) +break ; + + rc =hvm_get_ioreq_server_info (d, data->id, + (data->flags & XEN_DMOP_no_gfns) ? +NULL : (unsigned long *)&data->ioreq_gfn, + (data->flags & XEN_DMOP_no_gfns) ? +NULL : (unsigned long *)&data->bufioreq_gfn, + &data->bufioreq_port); +break ; + } + +case XEN_DMOP_map_io_range_to_ioreq_server: + { +const struct xen_dm_op_ioreq_server_range *data = + &op.u.map_io_range_to_ioreq_server; + + rc = -EINVAL ; +if ( data->pad ) +break ; + + rc =hvm_map_io_range_to_ioreq_server (d, data->id, data->type, + data->start, data->end); +break ; + } + +case XEN_DMOP_unmap_io_range_from_ioreq_server: + { +const struct xen_dm_op_ioreq_server_range *data = + &op.u.unmap_io_range_from_ioreq_server; + + rc = -EINVAL ; +if ( data->pad ) +break ; + + rc =hvm_unmap_io_range_from_ioreq_server (d, data->id, data->type, + data->start, data->end); +break ; + } + +case XEN_DMOP_set_ioreq_server_state: + { +const struct xen_dm_op_set_ioreq_server_state *data = + &op.u.set_ioreq_server_state; + + rc = -EINVAL ; +if ( data->pad ) +break ; + + rc =hvm_set_ioreq_server_state (d, data->id, !!data->enabled); +break ; + } + +case XEN_DMOP_destroy_ioreq_server: + { +const struct xen_dm_op_destroy_ioreq_server *data = + &op.u.destroy_ioreq_server; + + rc = -EINVAL ; +if ( data->pad ) +break ; + + rc =hvm_destroy_ioreq_server (d, data->id); +break ; + } + +default : + rc =arch_dm_op (&op, d, op_args, &const_op); + } + +if ( (!rc || rc == -ERESTART ) && + !const_op &©_to_guest_offset (op_args->buf[0 ].h, offset, + (void *)&op.u, op_size[op.op]) ) + rc = -EFAULT ; + + out: +rcu_unlock_domain (d); + +return rc; +} + +#ifdef CONFIG_COMPAT +CHECK_dm_op_create_ioreq_server; +CHECK_dm_op_get_ioreq_server_info; +CHECK_dm_op_ioreq_server_range; +CHECK_dm_op_set_ioreq_server_state; +CHECK_dm_op_destroy_ioreq_server; +CHECK_dm_op_track_dirty_vram; +CHECK_dm_op_set_pci_intx_level; +CHECK_dm_op_set_isa_irq_level; +CHECK_dm_op_set_pci_link_route; +CHECK_dm_op_modified_memory; +CHECK_dm_op_set_mem_type; +CHECK_dm_op_inject_event; +CHECK_dm_op_inject_msi; +CHECK_dm_op_remote_shutdown; +CHECK_dm_op_relocate_memory; +CHECK_dm_op_pin_memory_cacheattr; + +int compat_dm_op (domid_t domid, +unsigned int nr_bufs, +XEN_GUEST_HANDLE_PARAM (void ) bufs) +{ +struct dmop_args args; +unsigned int i; +int rc; + +if ( nr_bufs >ARRAY_SIZE (args.buf) ) +return -E2BIG ; + + args.domid = domid; + args.nr_bufs =array_index_nospec (nr_bufs,ARRAY_SIZE (args.buf) +1 ); + +for ( i =0 ; i < args.nr_bufs; i++ ) + { +struct compat_dm_op_buf cmp; + +if (copy_from_guest_offset (&cmp, bufs, i,1 ) ) +return -EFAULT ; + +#define XLAT_dm_op_buf_HNDL_h (_d_, _s_) \ + guest_from_compat_handle((_d_)->h, (_s_)->h) + +XLAT_dm_op_buf (&args.buf[i], &cmp); + +#undef XLAT_dm_op_buf_HNDL_h + } + + rc =dm_op (&args); + +if ( rc == -ERESTART ) + rc =hypercall_create_continuation (__HYPERVISOR_dm_op,"iih" , + domid, nr_bufs, bufs); + +return rc; +} +#endif + +long do_dm_op (domid_t domid, +unsigned int nr_bufs, +XEN_GUEST_HANDLE_PARAM (xen_dm_op_buf_t) bufs) +{ +struct dmop_args args; +int rc; + +if ( nr_bufs >ARRAY_SIZE (args.buf) ) +return -E2BIG ; + + args.domid = domid; + args.nr_bufs =array_index_nospec (nr_bufs,ARRAY_SIZE (args.buf) +1 ); + +if (copy_from_guest_offset (&args.buf[0 ], bufs,0 , args.nr_bufs) ) +return -EFAULT ; + + rc =dm_op (&args); + +if ( rc == -ERESTART ) + rc =hypercall_create_continuation (__HYPERVISOR_dm_op,"iih" , + domid, nr_bufs, bufs); + +return rc; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/xen/hypercall.h +12
-0@@ -150,6 +150,18 @@ do_dm_op( unsigned int nr_bufs, XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs); +struct dmop_args { +domid_t domid; +unsigned int nr_bufs; +/* Reserve enough buf elements for all current hypercalls. */ +struct xen_dm_op_buf buf[2 ]; +}; + +int arch_dm_op (struct xen_dm_op *op, +struct domain *d, +const struct dmop_args *op_args, +bool *const_op); +#ifdef CONFIG_HYPFS extern long do_hypfs_op(xen/include/xsm/dummy.h +2
-2@@ -723,14 +723,14 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int } } +#endif /* CONFIG_X86 */ + static XSM_INLINE int xsm_dm_op(XSM_DEFAULT_ARG struct domain *d) {XSM_ASSERT_ACTION (XSM_DM_PRIV );return xsm_default_action (action, current->domain, d); } -#endif /* CONFIG_X86 */ -#ifdef CONFIG_ARGO static XSM_INLINE int xsm_argo_enable(const struct domain *d) {xen/include/xsm/xsm.h +3
-3@@ -177,8 +177,8 @@ struct xsm_operations {int (*ioport_permission) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);int (*ioport_mapping) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);int (*pmu_op) (struct domain *d,unsigned int op); -int (*dm_op) (struct domain *d);#endif +int (*dm_op) (struct domain *d);int (*xen_version) (uint32_t cmd);int (*domain_resource_map) (struct domain *d);#ifdef CONFIG_ARGO @@ -688,13 +688,13 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int return xsm_ops->pmu_op(d, op); } +#endif /* CONFIG_X86 */ +static inline int xsm_dm_op (xsm_default_t def,struct domain *d) {return xsm_ops->dm_op (d); } -#endif /* CONFIG_X86 */ -static inline int xsm_xen_version (xsm_default_t def,uint32_t op) {return xsm_ops->xen_version (op);xen/xsm/dummy.c +1
-1@@ -148,8 +148,8 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, ioport_permission);set_to_dummy_if_null (ops, ioport_mapping);set_to_dummy_if_null (ops, pmu_op); -set_to_dummy_if_null (ops, dm_op);#endif +set_to_dummy_if_null (ops, dm_op);set_to_dummy_if_null (ops, xen_version);set_to_dummy_if_null (ops, domain_resource_map);#ifdef CONFIG_ARGO xen/xsm/flask/hooks.c +2
-3@@ -1662,14 +1662,13 @@ static int flask_pmu_op (struct domain *d, unsigned int op) return -EPERM; } } +#endif /* CONFIG_X86 */ static int flask_dm_op (struct domain *d) {return current_has_perm (d,SECCLASS_HVM ,HVM__DM ); } -#endif /* CONFIG_X86 */ -static int flask_xen_version (uint32_t op) {u32 dsid =domain_sid (current->domain);@@ -1872,8 +1871,8 @@ static struct xsm_operations flask_ops = { .ioport_permission = flask_ioport_permission, .ioport_mapping = flask_ioport_mapping, .pmu_op = flask_pmu_op, - .dm_op = flask_dm_op, #endif + .dm_op = flask_dm_op, .xen_version = flask_xen_version, .domain_resource_map = flask_domain_resource_map, #ifdef CONFIG_ARGO
Signature · 1 line
Julien Grall
Re: [PATCH V1 07/16] xen/dm: Make x86's DM feature common
On 23.09.20 20:35, Julien Grall wrote:
Hi Julien
Quoted 5 lines · Oleksandr Tyshchenko
Quoted 1 line
From: Oleksandr Tyshchenko <[email protected]>
I believe I am the original author of this code. So this needs to be fixed accordingly.
Sorry, will fix.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH 8/16 xen/mm: Make x86's XENMEM_resource_ioreq_server handling common
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
As x86 implementation of XENMEM_resource_ioreq_server can be re-used on Arm later on, this patch makes it common and removes arch_acquire_resource as unneeded.
This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- no changes
---
--- xen/arch/x86/mm.c | 44 -------------------------------------------- xen/common/memory.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- xen/include/asm-arm/mm.h | 8 -------- xen/include/asm-x86/mm.h | 4 ---- 4 files changed, 43 insertions(+), 58 deletions(-)
xen/arch/x86/mm.c +0 -44
@@ -4594,50 +4594,6 @@ int xenmem_add_to_physmap_one(return rc; } -int arch_acquire_resource (struct domain *d,unsigned int type, -unsigned int id,unsigned long frame, -unsigned int nr_frames,xen_pfn_t mfn_list[]) -{ -int rc; - -switch ( type ) - { -#ifdef CONFIG_HVM -case XENMEM_resource_ioreq_server: - { -ioservid_t ioservid = id; -unsigned int i; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) -break ; - -if ( id != (unsigned int )ioservid ) -break ; - - rc =0 ; -for ( i =0 ; i < nr_frames; i++ ) - { -mfn_t mfn; - - rc =hvm_get_ioreq_server_frame (d, id, frame + i, &mfn); -if ( rc ) -break ; - - mfn_list[i] =mfn_x (mfn); - } -break ; - } -#endif - -default : - rc = -EOPNOTSUPP ; -break ; - } - -return rc; -} -long arch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {int rc;
xen/common/memory.c +43 -2
64 lines not on this page · raw message
xen/include/asm-arm/mm.h +0 -8
@@ -358,14 +358,6 @@ static inline void put_page_and_type(struct page_info *page)void clear_and_clean_page (struct page_info *page); -static inline -int arch_acquire_resource (struct domain *d,unsigned int type,unsigned int id, -unsigned long frame,unsigned int nr_frames, -xen_pfn_t mfn_list[]) -{ -return -EOPNOTSUPP ; -} -unsigned int arch_get_dma_bitsize (void );#endif /* __ARCH_ARM_MM__ */
xen/include/asm-x86/mm.h +0 -4
@@ -649,8 +649,4 @@ static inline bool arch_mfn_in_directmap(unsigned long mfn) return mfn <= (virt_to_mfn(eva - 1) + 1); } -int arch_acquire_resource (struct domain *d,unsigned int type, -unsigned int id,unsigned long frame, -unsigned int nr_frames,xen_pfn_t mfn_list[]); -#endif /* __ASM_X86_MM_H__ */
Signature · 1 line
2.7.4
PATCH 9/16 arm/ioreq: Introduce arch specific bits for IOREQ/DM features
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality, add remaining bits as well as address several TODOs.
Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.
Please note, at the moment build on Arm32 is broken (see cmpxchg usage in hvm_send_buffered_ioreq()) due to the lack of cmpxchg_64 support on Arm32. There is a patch on review to address this issue:
https://patchwork.kernel.org/patch/11715559/
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
- update patch description
- update asm-arm/hvm/ioreq.h according to the newly introduced arch functions:
- arch_hvm_destroy_ioreq_server()
- arch_handle_hvm_io_completion()
- update arch files to include xen/ioreq.h
- remove HVMOP plumbing
- rewrite a logic to handle properly case when hvm_send_ioreq() returns IO_RETRY
- add a logic to handle properly handle_hvm_io_completion() return value
- rename handle_mmio() to ioreq_handle_complete_mmio()
- move paging_mark_pfn_dirty() to asm-arm/paging.h
- remove forward declaration for hvm_ioreq_server in asm-arm/paging.h
- move try_fwd_ioserv() to ioreq.c, provide stubs if !CONFIG_IOREQ_SERVER
- do not remove #ifdef CONFIG_IOREQ_SERVER in memory.c for guarding xen/ioreq.h
- use gdprintk in try_fwd_ioserv(), remove unneeded prints
- update list of #include-s
- move has_vpci() to asm-arm/domain.h
- add a comment (TODO) to unimplemented yet handle_pio()
- remove hvm_mmio_first(last)_byte() and hvm_ioreq_(page/vcpu/server) structs from the arch files, they were already moved to the common code
- remove set_foreign_p2m_entry() changes, they will be properly implemented in the follow-up patch
- select IOREQ_SERVER for Arm instead of Arm64 in Kconfig
- remove x86's realmode and other unneeded stubs from xen/ioreq.h
- clafify ioreq_t p.df usage in try_fwd_ioserv()
- set ioreq_t p.count to 1 in try_fwd_ioserv()
---
--- xen/arch/arm/Kconfig | 1 + xen/arch/arm/Makefile | 2 + xen/arch/arm/dm.c | 33 ++++++++++ xen/arch/arm/domain.c | 9 +++ xen/arch/arm/io.c | 11 +++- xen/arch/arm/ioreq.c | 142 ++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/traps.c | 32 +++++++-- xen/include/asm-arm/domain.h | 46 +++++++++++++ xen/include/asm-arm/hvm/ioreq.h | 108 ++++++++++++++++++++++++++++++ xen/include/asm-arm/mmio.h | 1 + xen/include/asm-arm/paging.h | 4 ++ 11 files changed, 384 insertions(+), 5 deletions(-) create mode 100644 xen/arch/arm/dm.c create mode 100644 xen/arch/arm/ioreq.c create mode 100644 xen/include/asm-arm/hvm/ioreq.h
xen/arch/arm/Kconfig +1 -0
@@ -21,6 +21,7 @@ config ARM select HAS_PASSTHROUGH select HAS_PDX select IOMMU_FORCE_PT_SHARE + select IOREQ_SERVER config ARCH_DEFCONFIG string
xen/arch/arm/Makefile +2 -0
@@ -13,6 +13,7 @@ obj-y += cpuerrata.o obj-y += cpufeature.o obj-y += decode.o obj-y += device.o +obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domain.o obj-y += domain_build.init.o obj-y += domctl.o
@@ -27,6 +28,7 @@ obj-y += guest_atomics.o obj-y += guest_walk.o obj-y += hvm.o obj-y += io.o +obj-$(CONFIG_IOREQ_SERVER) += ioreq.o obj-y += irq.o obj-y += kernel.init.o obj-$(CONFIG_LIVEPATCH) += livepatch.o
xen/arch/arm/dm.c new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright (c) 2019 Arm ltd. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <xen/hypercall.h> + +int arch_dm_op (struct xen_dm_op *op,struct domain *d, +const struct dmop_args *op_args,bool *const_op) +{ +return -EOPNOTSUPP ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/arm/domain.c +9 -0
@@ -14,6 +14,7 @@#include <xen/grant_table.h> #include <xen/hypercall.h> #include <xen/init.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/livepatch.h> #include <xen/sched.h>
@@ -681,6 +682,10 @@ int arch_domain_create(struct domain *d,ASSERT (config !=NULL ); +#ifdef CONFIG_IOREQ_SERVER +hvm_ioreq_init (d); +#endif +/* p2m_init relies on some value initialized by the IOMMU subsystem */ if ( (rc =iommu_domain_init (d, config->iommu_opts)) !=0 ) goto fail;
@@ -999,6 +1004,10 @@ int domain_relinquish_resources(struct domain *d)if (ret )return ret; +#ifdef CONFIG_IOREQ_SERVER +hvm_destroy_all_ioreq_servers (d); +#endif + PROGRESS(xen): ret =relinquish_memory (d, &d->xenpage_list);if ( ret )
xen/arch/arm/io.c +10 -1
@@ -16,6 +16,7 @@* GNU General Public License for more details. */ +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/spinlock.h> #include <xen/sched.h>
@@ -123,7 +124,15 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs, handler =find_mmio_handler (v->domain, info.gpa);if ( !handler ) -return IO_UNHANDLED ; + { +int rc; + + rc =try_fwd_ioserv (regs, v, &info); +if ( rc ==IO_HANDLED ) +return handle_ioserv (regs, v); + +return rc; + }/* All the instructions used on emulated MMIO region should be valid */ if ( !dabt.valid )
xen/arch/arm/ioreq.c new file +142 -0
142 lines not on this page · raw message
xen/arch/arm/traps.c +28 -4
@@ -21,6 +21,7 @@#include <xen/hypercall.h> #include <xen/init.h> #include <xen/iocap.h> +#include <xen/ioreq.h> #include <xen/irq.h> #include <xen/lib.h> #include <xen/mem_access.h>
@@ -1384,6 +1385,9 @@ static arm_hypercall_t arm_hypercall_table[] = {#ifdef CONFIG_HYPFS HYPERCALL(hypfs_op, 5),#endif +#ifdef CONFIG_IOREQ_SERVER + HYPERCALL(dm_op, 3), +#endif };#ifndef NDEBUG
@@ -1955,9 +1959,14 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,case IO_HANDLED :advance_pc (regs, hsr);return ; +case IO_RETRY : +/* finish later */ +return ;case IO_UNHANDLED :/* IO unhandled, try another way to handle it. */ break ; +default : +ASSERT_UNREACHABLE (); } }
@@ -2249,12 +2258,23 @@ static void check_for_pcpu_work(void)* Process pending work for the vCPU. Any call should be fast or * implement preemption. */ -static void check_for_vcpu_work (void ) +static bool check_for_vcpu_work (void ) {struct vcpu *v = current; +#ifdef CONFIG_IOREQ_SERVER +bool handled; + +local_irq_enable (); + handled =handle_hvm_io_completion (v); +local_irq_disable (); + +if ( !handled ) +return true; +#endif +if (likely (!v->arch.need_flush_to_ram) ) -return ; +return false;/* * Give a chance for the pCPU to process work before handling the vCPU
@@ -2265,6 +2285,8 @@ static void check_for_vcpu_work(void)local_irq_enable ();p2m_flush_vm (v);local_irq_disable (); + +return false; }/*
@@ -2277,8 +2299,10 @@ void leave_hypervisor_to_guest(void) {local_irq_disable (); -check_for_vcpu_work (); -check_for_pcpu_work (); +do + { +check_for_pcpu_work (); + }while (check_for_vcpu_work () );vgic_sync_to_lrs ();
xen/include/asm-arm/domain.h +46 -0
74 lines not on this page · raw message
xen/include/asm-arm/hvm/ioreq.h new file +108 -0
108 lines not on this page · raw message
xen/include/asm-arm/mmio.h +1 -0
@@ -37,6 +37,7 @@ enum io_stateIO_ABORT ,/* The IO was handled by the helper and led to an abort. */ IO_HANDLED ,/* The IO was successfully handled by the helper. */ IO_UNHANDLED ,/* The IO was not handled by the helper. */ + IO_RETRY, /* Retry the emulation for some reason */ }; typedef int (*mmio_read_t)(struct vcpu *v, mmio_info_t *info,
xen/include/asm-arm/paging.h +4 -0
@@ -4,6 +4,10 @@#define paging_mode_translate (d) (1)#define paging_mode_external (d) (1) +static inline void paging_mark_pfn_dirty (struct domain *d,pfn_t pfn) +{ +} +#endif /* XEN_PAGING_H */ /*
Signature · 1 line
2.7.4
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
Hello all.
Quoted 65 lines
/*
xen/include/asm-arm/hvm/ioreq.h new file +58
-0@@ -0,0 +1,108 @@ +/* +* hvm.h: Hardware virtual machine assist interface definitions. +* +* Copyright (c) 2016 Citrix Systems Inc. +* Copyright (c) 2019 Arm ltd. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __ASM_ARM_HVM_IOREQ_H__ +#define __ASM_ARM_HVM_IOREQ_H__ + +#include <public/hvm/ioreq.h> +#include <public/hvm/dm_op.h> + +#ifdef CONFIG_IOREQ_SERVER +enum io_state handle_ioserv (struct cpu_user_regs *regs,struct vcpu *v); +enum io_state try_fwd_ioserv (struct cpu_user_regs *regs, +struct vcpu *v,mmio_info_t *info); +#else +static inline enum io_state handle_ioserv (struct cpu_user_regs *regs, +struct vcpu *v) +{ +return IO_UNHANDLED ; +} + +static inline enum io_state try_fwd_ioserv (struct cpu_user_regs *regs, +struct vcpu *v,mmio_info_t *info) +{ +return IO_UNHANDLED ; +} +#endif + +bool ioreq_handle_complete_mmio (void ); + +static inline bool handle_pio (uint16_t port,unsigned int size,int dir) +{ +/* +* TODO: For Arm64, the main user will be PCI. So this should be +* implemented when we add support for vPCI. +*/ +BUG (); +return true; +} + +static inline int arch_hvm_destroy_ioreq_server (struct hvm_ioreq_server *s) +{ +return 0 ;
xen/include/asm-arm/hvm/ioreq.h line 68
Quoted 10 lines
xen/include/asm-arm/hvm/ioreq.h new file +10
-0+} + +static inline void msix_write_completion (struct vcpu *v) +{ +} + +static inline bool arch_handle_hvm_io_completion ( +enum hvm_io_completion io_completion) +{ +ASSERT_UNREACHABLE ();
I am sorry, but there should be return true;
to avoid "no return statement in function returning non-void [-Werror=return-type]" I am a little bit puzzled why I didn't spot this build error earlier.
Quoted 1 line
xen/include/asm-arm/hvm/ioreq.h new file +1
-0+}
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
In reply to Oleksandr Tyshchenkoxen/arch/arm/traps.c void leave_hypervisor_to_guest(void) · line 2305
Quoted 10 lines · Oleksandr Tyshchenko
xen/arch/arm/traps.c +4
-2@@ -2277,8 +2299,10 @@ void leave_hypervisor_to_guest(void) {local_irq_disable (); -check_for_vcpu_work (); -check_for_pcpu_work (); +do + { +check_for_pcpu_work (); + }while (check_for_vcpu_work () );
Looking at patch 11 I've stumbled across changes done to code related to this, and now I wonder: There's no mention in the description of why this safe (i.e. not a potentially unbounded loop).
As a nit - the opening brace does not belong on its own line in this specific case.
Jan
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
On 16.09.20 10:51, Jan Beulich wrote:
Hi Jan
Quoted 5 lines · Oleksandr Tyshchenko
Quoted 4 lines
xen/arch/arm/traps.c +0
-0@@ -2277,8 +2299,10 @@ void leave_hypervisor_to_guest(void) {local_irq_disable ();
Quoted 10 lines
xen/arch/arm/traps.c void leave_hypervisor_to_guest(void) · line 2305
Quoted 6 lines
xen/arch/arm/traps.c +4
-2-check_for_vcpu_work (); -check_for_pcpu_work (); +do + { +check_for_pcpu_work (); + }while (check_for_vcpu_work () );Looking at patch 11 I've stumbled across changes done to code related to this, and now I wonder: There's no mention in the description of why this safe (i.e. not a potentially unbounded loop).
Indeed there was a discussion regarding that. Probably I should have added an explanation.
Please see the thoughts about that and a reason why it was decided to let the vCPU to spin forever if I/O never completes (check_for_vcpu_work() never returns false) and why it was considered as safe action:
https://patchwork.kernel.org/patch/11698549/#23540209
Quoted 3 lines
As a nit - the opening brace does not belong on its own line in this specific case.
ok
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
In reply to Oleksandr TyshchenkoHi,
Quoted 1 line · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
I believe I am the originally author of this code...
Quoted 3 lines
This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality, add remaining bits as well as address several TODOs.
Find a bit weird to add code with TODOs that are handled in the same series? Can't we just split this patch in smaller one where everything is addressed from start?
Quoted 8 lines
Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.
Quoted 4 lines
Please note, at the moment build on Arm32 is broken (see cmpxchg usage in
hvm_send_buffered_ioreq()) due to the lack ofcmpxchg_64support on Arm32. There is a patch on review to address this issue:
https://patchwork.kernel.org/patch/11715559/
This has been committed.
Quoted 27 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>---
--- xen/arch/arm/Kconfig | 1 + xen/arch/arm/Makefile | 2 + xen/arch/arm/dm.c | 33 ++++++++++ xen/arch/arm/domain.c | 9 +++ xen/arch/arm/io.c | 11 +++- xen/arch/arm/ioreq.c | 142 ++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/traps.c | 32 +++++++-- xen/include/asm-arm/domain.h | 46 +++++++++++++ xen/include/asm-arm/hvm/ioreq.h | 108 ++++++++++++++++++++++++++++++ xen/include/asm-arm/mmio.h | 1 + xen/include/asm-arm/paging.h | 4 ++ 11 files changed, 384 insertions(+), 5 deletions(-)create mode 100644
xen/arch/arm/dm.ccreate mode 100644xen/arch/arm/ioreq.ccreate mode 100644xen/include/asm-arm/hvm/ioreq.hxen/arch/arm/Kconfig +0
-0
xen/arch/arm/Kconfig config ARM · line 24
Quoted 4 lines
xen/arch/arm/Kconfig +1
-0@@ -21,6 +21,7 @@ config ARM select HAS_PASSTHROUGH select HAS_PDX select IOMMU_FORCE_PT_SHARE + select IOREQ_SERVER
I would prefer if IOREQ_SERVER is not included in the default build of Xen. This is fairly big feature that require a lot more testing.
Quoted 158 lines
xen/arch/arm/Kconfig +0
-0config ARCH_DEFCONFIG stringxen/arch/arm/Makefile +2
-0@@ -13,6 +13,7 @@ obj-y += cpuerrata.o obj-y += cpufeature.o obj-y += decode.o obj-y += device.o +obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domain.o obj-y += domain_build.init.o obj-y += domctl.o@@ -27,6 +28,7 @@ obj-y += guest_atomics.o obj-y += guest_walk.o obj-y += hvm.o obj-y += io.o +obj-$(CONFIG_IOREQ_SERVER) += ioreq.o obj-y += irq.o obj-y += kernel.init.o obj-$(CONFIG_LIVEPATCH) += livepatch.oxen/arch/arm/dm.c new file +33
-0@@ -0,0 +1,33 @@ +/* +* Copyright (c) 2019 Arm ltd. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <xen/hypercall.h> + +int arch_dm_op (struct xen_dm_op *op,struct domain *d, +const struct dmop_args *op_args,bool *const_op) +{ +return -EOPNOTSUPP ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/domain.c +9
-0@@ -14,6 +14,7 @@#include <xen/grant_table.h> #include <xen/hypercall.h> #include <xen/init.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/livepatch.h> #include <xen/sched.h> @@ -681,6 +682,10 @@ int arch_domain_create(struct domain *d,ASSERT (config !=NULL ); +#ifdef CONFIG_IOREQ_SERVER +hvm_ioreq_init (d); +#endif +/* p2m_init relies on some value initialized by the IOMMU subsystem */ if ( (rc =iommu_domain_init (d, config->iommu_opts)) !=0 ) goto fail;@@ -999,6 +1004,10 @@ int domain_relinquish_resources(struct domain *d)if (ret )return ret; +#ifdef CONFIG_IOREQ_SERVER +hvm_destroy_all_ioreq_servers (d); +#endif + PROGRESS(xen): ret =relinquish_memory (d, &d->xenpage_list);if ( ret )xen/arch/arm/io.c +10
-1@@ -16,6 +16,7 @@* GNU General Public License for more details. */ +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/spinlock.h> #include <xen/sched.h> @@ -123,7 +124,15 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs, handler =find_mmio_handler (v->domain, info.gpa);if ( !handler ) -return IO_UNHANDLED ; + { +int rc; + + rc =try_fwd_ioserv (regs, v, &info); +if ( rc ==IO_HANDLED ) +return handle_ioserv (regs, v); + +return rc; + }/* All the instructions used on emulated MMIO region should be valid */ if ( !dabt.valid )xen/arch/arm/ioreq.c new file +27
-0@@ -0,0 +1,142 @@ +/* +* arm/ioreq.c: hardware virtual machine I/O emulation +* +* Copyright (c) 2019 Arm ltd. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <xen/domain.h> +#include <xen/ioreq.h> + +#include <public/hvm/ioreq.h> + +#include <asm/traps.h> + +enum io_state handle_ioserv (struct cpu_user_regs *regs,struct vcpu *v) +{
xen/arch/arm/ioreq.c line 37
Quoted 10 lines
xen/arch/arm/ioreq.c new file +10
-0+const union hsr hsr = { .bits = regs->hsr }; +const struct hsr_dabt dabt = hsr.dabt; +/* Code is similar to handle_read */ +uint8_t size = (1 << dabt.size) *8 ; +register_t r = v->arch.hvm.hvm_io.io_req.data; + +/* We are done with the IO */ + v->arch.hvm.hvm_io.io_req.state =STATE_IOREQ_NONE ; + +/* XXX: Do we need to take care of write here ? */
It doesn't look like we need to do anything for write as they have completed. Is there anything else we need to confirm?
Quoted 238 lines
xen/arch/arm/ioreq.c new file +105
-0+if ( dabt.write ) +return IO_HANDLED ; + +/* +* Sign extend if required. +* Note that we expect the read handler to have zeroed the bits +* outside the requested access size. +*/ +if ( dabt.sign && (r & (1UL << (size -1 ))) ) + { +/* +* We are relying on register_t using the same as +* an unsigned long in order to keep the 32-bit assembly +* code smaller. +*/ +BUILD_BUG_ON (sizeof (register_t) !=sizeof (unsigned long )); + r |= (~0UL ) << size; + } + +set_user_reg (regs, dabt.reg, r); + +return IO_HANDLED ; +} + +enum io_state try_fwd_ioserv (struct cpu_user_regs *regs, +struct vcpu *v,mmio_info_t *info) +{ +struct hvm_vcpu_io *vio = &v->arch.hvm.hvm_io; +ioreq_t p = { + .type =IOREQ_TYPE_COPY , + .addr = info->gpa, + .size =1 << info->dabt.size, + .count =1 , + .dir = !info->dabt.write, +/* +* On x86, df is used by 'rep' instruction to tell the direction +* to iterate (forward or backward). +* On Arm, all the accesses to MMIO region will do a single +* memory access. So for now, we can safely always set to 0. +*/ + .df =0 , + .data =get_user_reg (regs, info->dabt.reg), + .state =STATE_IOREQ_READY , + }; +struct hvm_ioreq_server *s =NULL ; +enum io_state rc; + +switch ( vio->io_req.state ) + { +case STATE_IOREQ_NONE : +break ; + +case STATE_IORESP_READY : +return IO_HANDLED ; + +default : +gdprintk (XENLOG_ERR ,"wrong state %u\n" , vio->io_req.state); +return IO_ABORT ; + } + + s =hvm_select_ioreq_server (v->domain, &p); +if ( !s ) +return IO_UNHANDLED ; + +if ( !info->dabt.valid ) +return IO_ABORT ; + + vio->io_req = p; + + rc =hvm_send_ioreq (s, &p,0 ); +if ( rc !=IO_RETRY || v->domain->is_shutting_down ) + vio->io_req.state =STATE_IOREQ_NONE ; +else if ( !hvm_ioreq_needs_completion (&vio->io_req) ) + rc =IO_HANDLED ; +else + vio->io_completion = HVMIO_mmio_completion; + +return rc; +} + +bool ioreq_handle_complete_mmio (void ) +{ +struct vcpu *v = current; +struct cpu_user_regs *regs =guest_cpu_user_regs (); +const union hsr hsr = { .bits = regs->hsr }; +paddr_t addr = v->arch.hvm.hvm_io.io_req.addr; + +if (try_handle_mmio (regs, hsr, addr) ==IO_HANDLED ) + { +advance_pc (regs, hsr); +return true; + } + +return false; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/traps.c +28
-4@@ -21,6 +21,7 @@#include <xen/hypercall.h> #include <xen/init.h> #include <xen/iocap.h> +#include <xen/ioreq.h> #include <xen/irq.h> #include <xen/lib.h> #include <xen/mem_access.h> @@ -1384,6 +1385,9 @@ static arm_hypercall_t arm_hypercall_table[] = {#ifdef CONFIG_HYPFS HYPERCALL(hypfs_op, 5),#endif +#ifdef CONFIG_IOREQ_SERVER + HYPERCALL(dm_op, 3), +#endif };#ifndef NDEBUG @@ -1955,9 +1959,14 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,case IO_HANDLED :advance_pc (regs, hsr);return ; +case IO_RETRY : +/* finish later */ +return ;case IO_UNHANDLED :/* IO unhandled, try another way to handle it. */ break ; +default : +ASSERT_UNREACHABLE (); } }@@ -2249,12 +2258,23 @@ static void check_for_pcpu_work(void)* Process pending work for the vCPU. Any call should be fast or * implement preemption. */ -static void check_for_vcpu_work (void ) +static bool check_for_vcpu_work (void ) {struct vcpu *v = current; +#ifdef CONFIG_IOREQ_SERVER +bool handled; + +local_irq_enable (); + handled =handle_hvm_io_completion (v); +local_irq_disable (); + +if ( !handled ) +return true; +#endif +if (likely (!v->arch.need_flush_to_ram) ) -return ; +return false;/* * Give a chance for the pCPU to process work before handling the vCPU @@ -2265,6 +2285,8 @@ static void check_for_vcpu_work(void)local_irq_enable ();p2m_flush_vm (v);local_irq_disable (); + +return false; }/* @@ -2277,8 +2299,10 @@ void leave_hypervisor_to_guest(void) {local_irq_disable (); -check_for_vcpu_work (); -check_for_pcpu_work (); +do + { +check_for_pcpu_work (); + }while (check_for_vcpu_work () );vgic_sync_to_lrs ();xen/include/asm-arm/domain.h +29
-0@@ -11,10 +11,27 @@#include <asm/vgic.h> #include <asm/vpl011.h> #include <public/hvm/params.h> +#include <public/hvm/dm_op.h> +#include <public/hvm/ioreq.h> + +#define MAX_NR_IOREQ_SERVERS 8struct hvm_domain {uint64_t params[HVM_NR_PARAMS ]; + +/* Guest page range used for non-default ioreq servers */ +struct { +unsigned long base; +unsigned long mask; +unsigned long legacy_mask;/* indexed by HVM param number */ + } ioreq_gfn; + +/* Lock protects all other values in the sub-struct and the default */ +struct { +spinlock_t lock; +struct hvm_ioreq_server *server[MAX_NR_IOREQ_SERVERS ]; + } ioreq_server; };#ifdef CONFIG_ARM_64 @@ -91,6 +108,28 @@ struct arch_domain#endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { +/* I/O request in flight to device model. */ +enum hvm_io_completion io_completion; +ioreq_t io_req; + +/*
xen/include/asm-arm/domain.h struct arch_domain · line 132
Quoted 10 lines
xen/include/asm-arm/domain.h +10
-0+* HVM emulation: +* Linear address @mmio_gla maps to MMIO physical frame @mmio_gpfn. +* The latter is known to be an MMIO frame (not RAM). +* This translation is only valid for accesses as per @mmio_access. +*/ +struct npfec mmio_access; +unsigned long mmio_gla; +unsigned long mmio_gpfn; +}; +
Why do we need to re-define most of this? Can't this just be in common code?
I would also rather not define them if !CONFIG_IOREQ_SERVER is not set.
xen/include/asm-arm/domain.h struct arch_vcpu · line 249
Quoted 11 lines
xen/include/asm-arm/domain.h +4
-0struct arch_vcpu { struct {@@ -204,6 +243,11 @@ struct arch_vcpu*/ bool need_flush_to_ram; +struct hvm_vcpu + { +struct hvm_vcpu_io hvm_io; + } hvm;
The IOREQ code is meant to be agnostic from the type of guest, so I don't really see a reason for the common code to access arch.hvm.
This should be abstracted appropriately.
Quoted 61 lines
xen/include/asm-arm/domain.h +3
-0+ } __cacheline_aligned;void vcpu_show_execution_state (struct vcpu *);@@ -262,6 +306,8 @@ static inline void arch_vcpu_block(struct vcpu *v) {}#define arch_vm_assist_valid_mask (d) (1UL << VMASST_TYPE_runstate_update_flag) +#define has_vpci (d) ({ (void)(d); false; }) +#endif /* __ASM_DOMAIN_H__ */ /* xen/include/asm-arm/hvm/ioreq.h new file +42
-0@@ -0,0 +1,108 @@ +/* +* hvm.h: Hardware virtual machine assist interface definitions. +* +* Copyright (c) 2016 Citrix Systems Inc. +* Copyright (c) 2019 Arm ltd. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __ASM_ARM_HVM_IOREQ_H__ +#define __ASM_ARM_HVM_IOREQ_H__ + +#include <public/hvm/ioreq.h> +#include <public/hvm/dm_op.h> + +#ifdef CONFIG_IOREQ_SERVER +enum io_state handle_ioserv (struct cpu_user_regs *regs,struct vcpu *v); +enum io_state try_fwd_ioserv (struct cpu_user_regs *regs, +struct vcpu *v,mmio_info_t *info); +#else +static inline enum io_state handle_ioserv (struct cpu_user_regs *regs, +struct vcpu *v) +{ +return IO_UNHANDLED ; +} + +static inline enum io_state try_fwd_ioserv (struct cpu_user_regs *regs, +struct vcpu *v,mmio_info_t *info) +{ +return IO_UNHANDLED ; +} +#endif
xen/include/asm-arm/hvm/ioreq.h line 52
Quoted 10 lines
xen/include/asm-arm/hvm/ioreq.h new file +10
-0+ +bool ioreq_handle_complete_mmio (void ); + +static inline bool handle_pio (uint16_t port,unsigned int size,int dir) +{ +/* +* TODO: For Arm64, the main user will be PCI. So this should be +* implemented when we add support for vPCI. +*/ +BUG ();
Why do you use a BUG() and not an ASSERT_UNREACHABLE()?
Quoted 74 lines
xen/include/asm-arm/hvm/ioreq.h new file +56
-0+return true; +} + +static inline int arch_hvm_destroy_ioreq_server (struct hvm_ioreq_server *s) +{ +return 0 ; +} + +static inline void msix_write_completion (struct vcpu *v) +{ +} + +static inline bool arch_handle_hvm_io_completion ( +enum hvm_io_completion io_completion) +{ +ASSERT_UNREACHABLE (); +} + +static inline int hvm_get_ioreq_server_range_type (struct domain *d, +ioreq_t *p, +uint8_t *type, +uint64_t *addr) +{ +if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) +return -EINVAL ; + + *type = (p->type ==IOREQ_TYPE_PIO ) ? +XEN_DMOP_IO_RANGE_PORT :XEN_DMOP_IO_RANGE_MEMORY ; + *addr = p->addr; + +return 0 ; +} + +static inline void arch_hvm_ioreq_init (struct domain *d) +{ +} + +static inline void arch_hvm_ioreq_destroy (struct domain *d) +{ +} + +#define IOREQ_IO_HANDLED IO_HANDLED +#define IOREQ_IO_UNHANDLED IO_UNHANDLED +#define IOREQ_IO_RETRY IO_RETRY + +#endif /* __ASM_ARM_HVM_IOREQ_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/asm-arm/mmio.h +1
-0@@ -37,6 +37,7 @@ enum io_stateIO_ABORT ,/* The IO was handled by the helper and led to an abort. */ IO_HANDLED ,/* The IO was successfully handled by the helper. */ IO_UNHANDLED ,/* The IO was not handled by the helper. */ + IO_RETRY, /* Retry the emulation for some reason */ }; typedef int (*mmio_read_t)(struct vcpu *v, mmio_info_t *info,xen/include/asm-arm/paging.h +0
-0
xen/include/asm-arm/paging.h line 13
Quoted 10 lines
xen/include/asm-arm/paging.h +4
-0@@ -4,6 +4,10 @@#define paging_mode_translate (d) (1)#define paging_mode_external (d) (1) +static inline void paging_mark_pfn_dirty (struct domain *d,pfn_t pfn) +{ +} +#endif /* XEN_PAGING_H */ /*
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
Quoted 1 line · Julien Grall
Hi,
Hi Julien
Quoted 5 lines · Oleksandr Tyshchenko
Quoted 1 line
From: Oleksandr Tyshchenko <[email protected]>
I believe I am the originally author of this code...
Sorry, will fix
Quoted 6 lines
Quoted 4 lines
This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality, add remaining bits as well as address several TODOs.
Find a bit weird to add code with TODOs that are handled in the same series? Can't we just split this patch in smaller one where everything is addressed from start?
Sorry if I wasn't clear in description. Let me please clarify.
Corresponding RFC patch had 3 major TODOs:
1. Handle properly when hvm_send_ioreq() returns IO_RETRY
2. Proper ref-counting for the foreign entries in set_foreign_p2m_entry()
3. Check the return value of handle_hvm_io_completion() *and* avoid calling handle_hvm_io_completion() on every return.
TODO #1 was fixed in current patch
TODO #2 was fixed in "xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm"
TODO #3 was partially fixed in current patch (check the return value of handle_hvm_io_completion()).
The second part of TODO #3 (avoid calling handle_hvm_io_completion() on every return) was moved to a separate patch "xen/ioreq: Introduce hvm_domain_has_ioreq_server()" and fixed (or probably improved is a better word) there along with introducing a mechanism to actually improve.
Could you please clarify how this patch could be split in smaller one?
Quoted 10 lines
Quoted 10 lines
Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.
Quoted 6 lines
Quoted 4 lines
Please note, at the moment build on Arm32 is broken (see cmpxchg usage in
hvm_send_buffered_ioreq()) due to the lack ofcmpxchg_64support on Arm32. There is a patch on review to address this issue:
https://patchwork.kernel.org/patch/11715559/This has been committed.
Thank you for the patch, will remove a notice.
Quoted 24 lines
Quoted 24 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>---
---
xen/arch/arm/Kconfig | 1 + xen/arch/arm/Makefile | 2 +
xen/arch/arm/dm.c | 33 ++++++++++ xen/arch/arm/domain.c | 9 +++ xen/arch/arm/io.c | 11 +++- xen/arch/arm/ioreq.c | 142
++++++++++++++++++++++++++++++++++++++++
xen/arch/arm/traps.c | 32 +++++++-- xen/include/asm-arm/domain.h | 46 +++++++++++++xen/include/asm-arm/hvm/ioreq.h| 108 ++++++++++++++++++++++++++++++ xen/include/asm-arm/mmio.h | 1 + xen/include/asm-arm/paging.h | 4 ++11 files changed, 384 insertions(+), 5 deletions(-)create mode 100644
xen/arch/arm/dm.ccreate mode 100644xen/arch/arm/ioreq.ccreate mode 100644xen/include/asm-arm/hvm/ioreq.h
Quoted 11 lines
Quoted 9 lines
xen/arch/arm/Kconfig +0
-0@@ -21,6 +21,7 @@ config ARMselect
HAS_PASSTHROUGH
selectHAS_PDX
selectIOMMU_FORCE_PT_SHARE
+ selectIOREQ_SERVERI would prefer if
IOREQ_SERVERis not included in the default build of Xen. This is fairly big feature that require a lot more testing.
Sounds reasonable. Will remove.
Quoted 168 lines
Quoted 168 lines
config
ARCH_DEFCONFIG
stringxen/arch/arm/Makefile +0
-0@@ -13,6 +13,7 @@ obj-y += cpuerrata.oobj-y += cpufeature.o
obj-y += decode.o
obj-y += device.o
+obj-$(CONFIG_IOREQ_SERVER) += dm.o
obj-y += domain.o
obj-y += domain_build.init.o
obj-y += domctl.oxen/arch/arm/Makefile +0
-0@@ -27,6 +28,7 @@ obj-y += guest_atomics.oobj-y += guest_walk.o
obj-y += hvm.o
obj-y += io.o
+obj-$(CONFIG_IOREQ_SERVER) += ioreq.o
obj-y += irq.o
obj-y += kernel.init.o
obj-$(CONFIG_LIVEPATCH) += livepatch.oxen/arch/arm/dm.c new file +4
-0@@ -0,0 +1,33 @@ +/* +* Copyright (c) 2019 Arm ltd. +* +* This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */xen/arch/arm/dm.c new file +18
-0+ +#include <xen/hypercall.h> + +int arch_dm_op (struct xen_dm_op *op,struct domain *d, + const struct dmop_args *op_args, bool *const_op) +{ + return -EOPNOTSUPP; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/domain.c +1
-0@@ -14,6 +14,7 @@ #include <xen/grant_table.h> #include <xen/hypercall.h> #include <xen/init.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/livepatch.h> #include <xen/sched.h>@@ -681,6 +682,10 @@ int arch_domain_create(struct domain *d, ASSERT(config != NULL);+#ifdef
CONFIG_IOREQ_SERVER
+hvm_ioreq_init(d);xen/arch/arm/domain.c +2
-0+#endif +/*
p2m_initrelies on some value initialized by the IOMMU subsystem */ if ( (rc =iommu_domain_init(d, config->iommu_opts)) != 0 ) goto fail;xen/arch/arm/domain.c +0
-0@@ -999,6 +1004,10 @@ int domain_relinquish_resources(struct domain *d) if (ret ) return ret;+#ifdef
CONFIG_IOREQ_SERVER
+hvm_destroy_all_ioreq_servers(d);xen/arch/arm/domain.c +2
-0+#endif +PROGRESS(xen):
ret =relinquish_memory(d, &d->xenpage_list); if ( ret )xen/arch/arm/io.c +0
-0@@ -16,6 +16,7 @@* GNU General Public License for more details. */ +#include <
xen/ioreq.h>
#include <xen/lib.h>
#include <xen/spinlock.h>
#include <xen/sched.h>xen/arch/arm/io.c +9
-1@@ -123,7 +124,15 @@ enum io_state try_handle_mmio(structcpu_user_regs *regs, handler = find_mmio_handler(v->domain, info.gpa); if ( !handler ) - return IO_UNHANDLED; + { + int rc; + + rc = try_fwd_ioserv(regs, v, &info); + if ( rc == IO_HANDLED ) + return handle_ioserv(regs, v); + + return rc; + } /* All the instructions used on emulated MMIO region should be valid */ if ( !dabt.valid )xen/arch/arm/ioreq.c new file +6
-0@@ -0,0 +1,142 @@ +/* +* arm/ioreq.c: hardware virtual machine I/O emulation +* +* Copyright (c) 2019 Arm ltd. +* +* This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */xen/arch/arm/ioreq.c new file +14
-0+ +#include <xen/domain.h> +#include <xen/ioreq.h> + +#include <public/hvm/ioreq.h> + +#include <asm/traps.h> + +enum io_state handle_ioserv (struct cpu_user_regs *regs,struct vcpu *v) +{ + const union hsr hsr = { .bits = regs->hsr }; + const struct hsr_dabt dabt = hsr.dabt; + /* Code is similar to handle_read */ + uint8_t size = (1 << dabt.size) * 8;
Quoted 8 lines
xen/arch/arm/ioreq.c line 37
Quoted 6 lines
+
register_tr =v->arch.hvm.hvm_io.io_req.data;xen/arch/arm/ioreq.c new file +5
-0+ + /* We are done with the IO */ + v->arch.hvm.hvm_io.io_req.state = STATE_IOREQ_NONE; + + /* XXX: Do we need to take care of write here ? */It doesn't look like we need to do anything for write as they have completed. Is there anything else we need to confirm?
Agree, it was discussed for the RFC series. I forgot to remove it.
Quoted 238 lines
Quoted 238 lines
+ if ( dabt.write )
+ returnIO_HANDLED;xen/arch/arm/ioreq.c new file +34
-0+ + /* + * Sign extend if required. + * Note that we expect the read handler to have zeroed the bits + * outside the requested access size. + */ + if ( dabt.sign && (r & (1UL << (size - 1))) ) + { + /* + * We are relying on register_t using the same as + * an unsigned long in order to keep the 32-bit assembly + * code smaller. + */ + BUILD_BUG_ON(sizeof(register_t) != sizeof(unsigned long)); + r |= (~0UL) << size; + } + + set_user_reg(regs, dabt.reg, r); + + return IO_HANDLED; +} + +enum io_state try_fwd_ioserv (struct cpu_user_regs *regs, + struct vcpu *v, mmio_info_t *info) +{ + struct hvm_vcpu_io *vio = &v->arch.hvm.hvm_io; + ioreq_t p = { + .type = IOREQ_TYPE_COPY, + .addr = info->gpa, + .size = 1 << info->dabt.size, + .count = 1, + .dir = !info->dabt.write, + /* + * On x86, df is used by 'rep' instruction to tell thedirection
+ * to iterate (forward or backward).
+ * On Arm, all the accesses to MMIO region will do a single + * memory access. So for now, we can safely always set to 0. + */
+ .df = 0,
+ .data =get_user_reg(regs, info->dabt.reg),
+ .state =STATE_IOREQ_READY,
+ };
+ structhvm_ioreq_server*s = NULL;
+ enumio_staterc;xen/arch/arm/ioreq.c new file +59
-0+ + switch ( vio->io_req.state ) + { + case STATE_IOREQ_NONE: + break; + + case STATE_IORESP_READY: + return IO_HANDLED; + + default: + gdprintk(XENLOG_ERR, "wrong state %u\n", vio->io_req.state); + return IO_ABORT; + } + + s = hvm_select_ioreq_server(v->domain, &p); + if ( !s ) + return IO_UNHANDLED; + + if ( !info->dabt.valid ) + return IO_ABORT; + + vio->io_req = p; + + rc = hvm_send_ioreq(s, &p, 0); + if ( rc != IO_RETRY || v->domain->is_shutting_down ) + vio->io_req.state = STATE_IOREQ_NONE; + else if ( !hvm_ioreq_needs_completion(&vio->io_req) ) + rc = IO_HANDLED; + else + vio->io_completion = HVMIO_mmio_completion; + + return rc; +} + +bool ioreq_handle_complete_mmio (void ) +{ + struct vcpu *v = current; + struct cpu_user_regs *regs = guest_cpu_user_regs(); + const union hsr hsr = { .bits = regs->hsr }; + paddr_t addr = v->arch.hvm.hvm_io.io_req.addr; + + if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED ) + { + advance_pc(regs, hsr); + return true; + } + + return false; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/traps.c +4
-0@@ -21,6 +21,7 @@ #include <xen/hypercall.h> #include <xen/init.h> #include <xen/iocap.h> +#include <xen/ioreq.h> #include <xen/irq.h> #include <xen/lib.h> #include <xen/mem_access.h>@@ -1384,6 +1385,9 @@ static arm_hypercall_t arm_hypercall_table[] = { #ifdef CONFIG_HYPFS HYPERCALL(hypfs_op, 5), #endif +#ifdef CONFIG_IOREQ_SERVER + HYPERCALL(dm_op, 3), +#endif }; #ifndef NDEBUG@@ -1955,9 +1959,14 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,case
IO_HANDLED:
advance_pc(regs, hsr);
return;
+ caseIO_RETRY:
+ /* finish later */
+ return;
caseIO_UNHANDLED:
/* IO unhandled, try another way to handle it. */ break;
+ default:
+ASSERT_UNREACHABLE();
}
}
@@ -2249,12 +2258,23 @@ static voidcheck_for_pcpu_work(void)
* Process pending work for the vCPU. Any call should be fast or
* implement preemption.
*/xen/arch/arm/traps.c +1
-1-static void check_for_vcpu_work (void ) +static bool check_for_vcpu_work (void ){
struct vcpu *v = current;
+#ifdefCONFIG_IOREQ_SERVER
+ bool handled;xen/arch/arm/traps.c +9
-0+ + local_irq_enable(); + handled = handle_hvm_io_completion(v); + local_irq_disable(); + + if ( !handled ) + return true; +#endif +if (
likely(!v->arch.need_flush_to_ram))
- return;
+ return false;
/*
* Give a chance for the pCPU to process work before handling the vCPUxen/arch/arm/traps.c +6
-1@@ -2265,6 +2285,8 @@ static void check_for_vcpu_work(void) local_irq_enable(); p2m_flush_vm(v); local_irq_disable(); + + return false; } /*@@ -2277,8 +2299,10 @@ void leave_hypervisor_to_guest(void) { local_irq_disable(); - check_for_vcpu_work(); - check_for_pcpu_work(); + do + { + check_for_pcpu_work(); + } while ( check_for_vcpu_work() ); vgic_sync_to_lrs();diff --git
a/xen/include/asm-arm/domain.hb/xen/include/asm-arm/domain.hindex 6819a3b..d1c48d7 100644xen/include/asm-arm/domain.h +4
-0@@ -11,10 +11,27 @@ #include <asm/vgic.h> #include <asm/vpl011.h> #include <public/hvm/params.h> +#include <public/hvm/dm_op.h> +#include <public/hvm/ioreq.h> + +#define MAX_NR_IOREQ_SERVERS 8struct
hvm_domain
{
uint64_t params[HVM_NR_PARAMS];xen/include/asm-arm/domain.h +9
-0+ + /* Guest page range used for non-default ioreq servers */ + struct { + unsigned long base; + unsigned long mask; + unsigned long legacy_mask; /* indexed by HVM param number */ + } ioreq_gfn; + + /* Lock protects all other values in the sub-struct and thedefault */
+ struct {
+ spinlock_t lock;
+ structhvm_ioreq_server*server[MAX_NR_IOREQ_SERVERS]; + }ioreq_server;
};
#ifdefCONFIG_ARM_64xen/include/asm-arm/domain.h +13
-0@@ -91,6 +108,28 @@ struct arch_domain #endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame@mmio_gpfn.
+ * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access.
Quoted 8 lines
xen/include/asm-arm/domain.h
Quoted 6 lines
+ */
+ struct npfecmmio_access;
+ unsigned longmmio_gla;
+ unsigned longmmio_gpfn;xen/include/asm-arm/domain.h +2
-0+}; +Why do we need to re-define most of this? Can't this just be in common code?
Jan asked almost the similar question in "[PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common". Please see my answer there:
https://patchwork.kernel.org/patch/11769105/#23637511
Theoretically we could move this to the common code, but the question is how to be with other struct fields the x86's struct hvm_vcpu_io has/needs but Arm's seems not, would it be possible to logically split struct hvm_vcpu_io into common and arch parts?
struct hvm_vcpu_io {
/* I/O request in flight to device model. */
enum hvm_io_completion io_completion;
ioreq_t io_req;
/*
* HVM emulation:
* Linear address @mmio_gla maps to MMIO physical frame @mmio_gpfn. * The latter is known to be an MMIO frame (not RAM).
* This translation is only valid for accesses as per @mmio_access. */
struct npfec mmio_access;
unsigned long mmio_gla;
unsigned long mmio_gpfn;
/*
* We may need to handle up to 3 distinct memory accesses per
* instruction.
*/
struct hvm_mmio_cache mmio_cache[3];
unsigned int mmio_cache_count;
/* For retries we shouldn't re-fetch the instruction. */ unsigned int mmio_insn_bytes;
unsigned char mmio_insn[16];
struct hvmemul_cache *cache;
/*
* For string instruction emulation we need to be able to signal a
* necessary retry through other than function return codes. */
bool_t mmio_retry;
unsigned long msix_unmask_address;
unsigned long msix_snoop_address;
unsigned long msix_snoop_gpa;
const struct g2m_ioport *g2m_ioport;
};
Quoted 2 lines
I would also rather not define them if !CONFIG_IOREQ_SERVER is not set.
ok
Quoted 16 lines
Quoted 9 lines
struct
arch_vcpu
{
struct {xen/include/asm-arm/domain.h +0
-0@@ -204,6 +243,11 @@ struct arch_vcpu*/ bool need_flush_to_ram;Quoted 4 lines
+ struct
hvm_vcpu
+ {
+ structhvm_vcpu_iohvm_io;
+ } hvm;The IOREQ code is meant to be agnostic from the type of guest, so I don't really see a reason for the common code to access arch.hvm.
Quoted 1 line
This should be abstracted appropriately.
Yes, there is a discussion pending in "[PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common" about layering violation issue. There won't be any uses of *arch.hvm* in the common ioreq come in next series. Everything containing *arch.hvm* in the common code will be abstracted away.
Quoted 72 lines
Quoted 72 lines
+
}__cacheline_aligned;
voidvcpu_show_execution_state(struct vcpu *);xen/include/asm-arm/domain.h +1
-0@@ -262,6 +306,8 @@ static inline void arch_vcpu_block(struct vcpu *v) {} #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag) +#define has_vpci(d) ({ (void)(d); false; }) + #endif /* __ASM_DOMAIN_H__ */ /*xen/include/asm-arm/hvm/ioreq.h new file +7
-0@@ -0,0 +1,108 @@ +/* +* hvm.h: Hardware virtual machine assist interface definitions. +* +* Copyright (c) 2016 Citrix Systems Inc. +* Copyright (c) 2019 Arm ltd. +* +* This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */xen/include/asm-arm/hvm/ioreq.h new file +9
-0+ +#ifndef __ASM_ARM_HVM_IOREQ_H__ +#define __ASM_ARM_HVM_IOREQ_H__ + +#include <public/hvm/ioreq.h> +#include <public/hvm/dm_op.h> + +#ifdef CONFIG_IOREQ_SERVER +enum io_state handle_ioserv(struct cpu_user_regs *regs, struct vcpu*v);
xen/include/asm-arm/hvm/ioreq.h new file +11
-0+enum io_state try_fwd_ioserv (struct cpu_user_regs *regs, + struct vcpu *v, mmio_info_t *info); +#else +static inline enum io_state handle_ioserv (struct cpu_user_regs *regs, + struct vcpu *v) +{ + return IO_UNHANDLED; +} + +static inline enum io_state try_fwd_ioserv(struct cpu_user_regs *regs, + struct vcpu *v,
mmio_info_t*info)xen/include/asm-arm/hvm/ioreq.h new file +8
-0+{ + return IO_UNHANDLED; +} +#endif + +bool ioreq_handle_complete_mmio (void ); + +static inline bool handle_pio(uint16_t port, unsigned int size, intdir)
Quoted 8 lines
Quoted 6 lines
+{
+ /*
+ * TODO: For Arm64, the main user will be PCI. So this should be + * implemented when we add support for vPCI.
+ */
+BUG();Why do you use a
BUG()and not anASSERT_UNREACHABLE()?
Yes, ASSERT_UNREACHABLE() is better suited here.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
Quoted 39 lines · Oleksandr
Quoted 24 lines · Julien Grall
Quoted 23 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
xen/include/asm-arm/domain.h +13
-0@@ -91,6 +108,28 @@ struct arch_domain #endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame@mmio_gpfn.
+ * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access.
+ */Quoted 8 lines
Review
Quoted 5 lines
+ struct npfec
mmio_access;
+ unsigned longmmio_gla;
+ unsigned longmmio_gpfn;(quoted diff) +2
-0+}; +Why do we need to re-define most of this? Can't this just be in common code?
Jan asked almost the similar question in "[PATCH V1 02/16] xen/ioreq:
Make x86's IOREQ feature common".
Please see my answer there:
https://patchwork.kernel.org/patch/11769105/#23637511
Quoted 5 lines
Theoretically we could move this to the common code, but the question is how to be with other struct fields the x86's struct
hvm_vcpu_iohas/needs but
Arm's seems not, would it be possible to logically split structhvm_vcpu_iointo common and arch parts?
Have struct vcpu_io and struct arch_vcpu_io as a sub-part of it?
Jan
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
On 24.09.20 14:08, Jan Beulich wrote:
Hi Jan
Quoted 38 lines · Oleksandr
Quoted 37 lines · Julien Grall
Quoted 23 lines · Oleksandr Tyshchenko
Quoted 22 lines
From: Oleksandr Tyshchenko <[email protected]>
xen/include/asm-arm/domain.h +13
-0@@ -91,6 +108,28 @@ struct arch_domain #endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame@mmio_gpfn.
+ * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access.Quoted 8 lines
Review
Quoted 6 lines
+ */
+ struct npfecmmio_access;
+ unsigned longmmio_gla;
+ unsigned longmmio_gpfn;(quoted diff) +2
-0+}; +Why do we need to re-define most of this? Can't this just be in common code?
Jan asked almost the similar question in "[PATCH V1 02/16] xen/ioreq:
Make x86's IOREQ feature common".
Please see my answer there:
https://patchwork.kernel.org/patch/11769105/#23637511
Quoted 6 lines
Quoted 5 lines
Theoretically we could move this to the common code, but the question is how to be with other struct fields the x86's struct
hvm_vcpu_iohas/needs but
Arm's seems not, would it be possible to logically split structhvm_vcpu_iointo common and arch parts?Have struct
vcpu_ioand structarch_vcpu_ioas a sub-part of it?
Although it is going to pull a lot of changes into x86/hvm/*, yes this way
we indeed could logically split struct hvm_vcpu_io into common and arch parts in a clear way. If it is really worth it, I will start looking into it.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
On 24.09.20 19:02, Oleksandr wrote:
Hi
Quoted 48 lines · Jan Beulich
Hi Jan
Quoted 43 lines · Oleksandr
Quoted 42 lines · Julien Grall
Quoted 23 lines · Oleksandr Tyshchenko
Quoted 22 lines
From: Oleksandr Tyshchenko <[email protected]>
xen/include/asm-arm/domain.h +13
-0@@ -91,6 +108,28 @@ struct arch_domain #endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame@mmio_gpfn.
+ * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access.Quoted 8 lines
Review
Quoted 6 lines
+ */
+ struct npfecmmio_access;
+ unsigned longmmio_gla;
+ unsigned longmmio_gpfn;(quoted diff) +2
-0+}; +Why do we need to re-define most of this? Can't this just be in common code?
Jan asked almost the similar question in "[PATCH V1 02/16] xen/ioreq:
Make x86's IOREQ feature common".
Please see my answer there:
https://patchwork.kernel.org/patch/11769105/#23637511Theoretically we could move this to the common code, but the question is how to be with other struct fields the x86's struct
hvm_vcpu_iohas/needs but
Arm's seems not, would it be possible to logically split structhvm_vcpu_iointo common and arch parts?
Quoted 4 lines
Quoted 1 line
Have struct
vcpu_ioand structarch_vcpu_ioas a sub-part of it?Although it is going to pull a lot of changes into x86/hvm/*, yes this way
we indeed could logically split structhvm_vcpu_iointo common and arch parts in a clear way. If it is really worth it, I will start looking into it.
Julien, I noticed that three fields mmio* are not used within current series on Arm. Do we expect them to be used later on? I would rather not add fields which are not used. We could add them when needed.
Would be the following acceptable?
1. Both fields "io_completion" and "io_req" (which seems to be the only fields used in common/ioreq.c) are moved to common struct vcpu as part of struct vcpu_io, enum hvm_io_completion is also moved (and renamed).
2. We remove everything related to hvm_vcpu* from the Arm header.
3. x86's struct hvm_vcpu_io stays as it is (but without two fields "io_completion" and "io_req").
I think, this way we separate a common part and reduce Xen changes (which are getting bigger).
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
Quoted 6 lines · Oleksandr
On 24.09.20 19:02, Oleksandr wrote:
Julien, I noticed that three fields mmio* are not used within current series on Arm. Do we expect them to be used later on?
I would rather not add fields which are not used. We could add them when needed.
Quoted 10 lines
Would be the following acceptable?
1. Both fields "io_completion" and "io_req" (which seems to be the only fields used incommon/ioreq.c) are moved to common struct vcpu as part of structvcpu_io,
enumhvm_io_completionis also moved (and renamed).
2. We remove everything related to hvm_vcpu* from the Arm header.
3. x86's structhvm_vcpu_iostays as it is (but without two fields "io_completion" and "io_req").
I think, this way we separate a common part and reduce Xen changes
(which are getting bigger).
If this works, it would be my preference too. So far I was left under the impression that you did move / mention further fields for a reason.
Jan
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
On 25.09.20 09:51, Jan Beulich wrote:
Hi Jan
Quoted 17 lines · Oleksandr
Quoted 6 lines · Oleksandr
Julien, I noticed that three fields mmio* are not used within current series on Arm. Do we expect them to be used later on?
I would rather not add fields which are not used. We could add them when needed.Quoted 10 lines
Would be the following acceptable?
1. Both fields "io_completion" and "io_req" (which seems to be the only fields used incommon/ioreq.c) are moved to common struct vcpu as part of structvcpu_io,
enumhvm_io_completionis also moved (and renamed).
2. We remove everything related to hvm_vcpu* from the Arm header.
3. x86's structhvm_vcpu_iostays as it is (but without two fields "io_completion" and "io_req").
I think, this way we separate a common part and reduce Xen changes
(which are getting bigger).
Quoted 1 line
If this works, it would be my preference too.
Thanks. I will wait for Julien's input on that and if he doesn't have any objections I will go this direction.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
In reply to OleksandrHi,
Quoted 45 lines · Oleksandr
Quoted 44 lines · Oleksandr
Quoted 43 lines · Jan Beulich
Quoted 42 lines · Oleksandr
Quoted 23 lines · Julien Grall
Quoted 22 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
xen/include/asm-arm/domain.h +13
-0@@ -91,6 +108,28 @@ struct arch_domain #endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame@mmio_gpfn.
+ * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access.Quoted 8 lines
Review
Quoted 6 lines
+ */
+ struct npfecmmio_access;
+ unsigned longmmio_gla;
+ unsigned longmmio_gpfn;(quoted diff) +2
-0+}; +Why do we need to re-define most of this? Can't this just be in common code?
Jan asked almost the similar question in "[PATCH V1 02/16] xen/ioreq:
Make x86's IOREQ feature common".
Please see my answer there:
https://patchwork.kernel.org/patch/11769105/#23637511Theoretically we could move this to the common code, but the question is how to be with other struct fields the x86's struct
hvm_vcpu_iohas/needs but
Arm's seems not, would it be possible to logically split structhvm_vcpu_iointo common and arch parts?
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Have struct
vcpu_ioand structarch_vcpu_ioas a sub-part of it?Although it is going to pull a lot of changes into x86/hvm/*, yes this way
we indeed could logically split structhvm_vcpu_iointo common and arch parts in a clear way. If it is really worth it, I will start looking into it.Julien, I noticed that three fields mmio* are not used within current series on Arm. Do we expect them to be used later on?
IIRC, I just copied them blindly when writing the PoC.
The information can already be found using the HSR (syndrome register), so those fields would be redundant for us.
Quoted 7 lines
Would be the following acceptable?
1. Both fields "io_completion" and "io_req" (which seems to be the only fields used incommon/ioreq.c) are moved to common struct vcpu as part of structvcpu_io, enumhvm_io_completionis also moved (and renamed).
2. We remove everything related to hvm_vcpu* from the Arm header.
3. x86's structhvm_vcpu_iostays as it is (but without two fields "io_completion" and "io_req").
I think, this way we separate a common part and reduce Xen changes
(which are getting bigger).
The plan looks reasonable to me.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
Quoted 1 line · Julien Grall
Hi,
Hi Julien.
Quoted 48 lines · Oleksandr
Quoted 46 lines · Oleksandr
Quoted 45 lines · Jan Beulich
Quoted 44 lines · Oleksandr
Quoted 37 lines · Julien Grall
Quoted 23 lines · Oleksandr Tyshchenko
Quoted 22 lines
From: Oleksandr Tyshchenko <[email protected]>
(quoted diff) +13
-0@@ -91,6 +108,28 @@ struct arch_domain #endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame@mmio_gpfn.
+ * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access.Quoted 8 lines
Review
Quoted 6 lines
+ */
+ struct npfecmmio_access;
+ unsigned longmmio_gla;
+ unsigned longmmio_gpfn;(quoted diff) +2
-0+}; +Why do we need to re-define most of this? Can't this just be in common code?
Jan asked almost the similar question in "[PATCH V1 02/16] xen/ioreq:
Make x86's IOREQ feature common".
Please see my answer there:
https://patchwork.kernel.org/patch/11769105/#23637511Quoted 5 lines
Theoretically we could move this to the common code, but the question is how to be with other struct fields the x86's struct
hvm_vcpu_iohas/needs but
Arm's seems not, would it be possible to logically split structhvm_vcpu_iointo common and arch parts?Have struct
vcpu_ioand structarch_vcpu_ioas a sub-part of it?
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Although it is going to pull a lot of changes into x86/hvm/*, yes this way
we indeed could logically split structhvm_vcpu_iointo common and arch parts in a clear way. If it is really worth it, I will start looking into it.Julien, I noticed that three fields mmio* are not used within current series on Arm. Do we expect them to be used later on?
IIRC, I just copied them blindly when writing the PoC.
The information can already be found using the HSR (syndrome register), so those fields would be redundant for us.
Got it.
Quoted 10 lines
Quoted 8 lines
Would be the following acceptable?
1. Both fields "io_completion" and "io_req" (which seems to be the only fields used incommon/ioreq.c) are moved to common struct vcpu as part of structvcpu_io, enumhvm_io_completionis also moved (and renamed).
2. We remove everything related to hvm_vcpu* from the Arm header.
3. x86's structhvm_vcpu_iostays as it is (but without two fields "io_completion" and "io_req").
I think, this way we separate a common part and reduce Xen changes (which are getting bigger).The plan looks reasonable to me.
OK, will follow it. Thank you
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
In reply to Jan BeulichQuoted 40 lines · Jan Beulich
Quoted 39 lines · Oleksandr
Quoted 24 lines · Julien Grall
Quoted 23 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
xen/include/asm-arm/domain.h +13
-0@@ -91,6 +108,28 @@ struct arch_domain #endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame@mmio_gpfn.
+ * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access.
+ */Quoted 8 lines
Review
Quoted 5 lines
+ struct npfec
mmio_access;
+ unsigned longmmio_gla;
+ unsigned longmmio_gpfn;(quoted diff) +2
-0+}; +Why do we need to re-define most of this? Can't this just be in common code?
Jan asked almost the similar question in "[PATCH V1 02/16] xen/ioreq:
Make x86's IOREQ feature common".
Please see my answer there:
https://patchwork.kernel.org/patch/11769105/#23637511
Quoted 7 lines
Quoted 5 lines
Theoretically we could move this to the common code, but the question is how to be with other struct fields the x86's struct
hvm_vcpu_iohas/needs but
Arm's seems not, would it be possible to logically split structhvm_vcpu_iointo common and arch parts?Have struct
vcpu_ioand structarch_vcpu_ioas a sub-part of it?
+1 for the idea.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
In reply to OleksandrQuoted 28 lines · Oleksandr
Quoted 1 line · Julien Grall
Hi,
Hi Julien
Quoted 5 lines · Oleksandr Tyshchenko
Quoted 1 line
From: Oleksandr Tyshchenko <[email protected]>
I believe I am the originally author of this code...
Sorry, will fix
Quoted 6 lines
Quoted 4 lines
This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality, add remaining bits as well as address several TODOs.
Find a bit weird to add code with TODOs that are handled in the same series? Can't we just split this patch in smaller one where everything is addressed from start?
Sorry if I wasn't clear in description. Let me please clarify.
Corresponding RFC patch had 3 major TODOs:
1. Handle properly whenhvm_send_ioreq()returnsIO_RETRY
2. Proper ref-counting for the foreign entries inset_foreign_p2m_entry()
3. Check the return value ofhandle_hvm_io_completion()*and* avoid callinghandle_hvm_io_completion()on every return.
Quoted 5 lines
TODO #1 was fixed in current patch
TODO #2 was fixed in "xen/mm: Handle properly reference inset_foreign_p2m_entry()on Arm"
TODO #3 was partially fixed in current patch (check the return value ofhandle_hvm_io_completion()).
The second part of TODO #3 (avoid callinghandle_hvm_io_completion()on every return) was moved to a separate patch "xen/ioreq: Introducehvm_domain_has_ioreq_server()" and fixed (or probably improved is a better word) there along with introducing a mechanism to actually improve.
Right, none of those TODOs are described in the code. So it makes more difficult to know what you are actually referring to.
I would suggest to reshuffle the series so the TODOs are addressed before when possible.
Quoted 2 lines
Could you please clarify how this patch could be split in smaller one?
This patch is going to be reduced a fair bit if you make some of the structure common. The next steps would be to move anything that is not directly related to IOREQ out.
From a quick look, there are few things that can be moved in separate patches:
- The addition of the ASSERT_UNREACHABLE()
- The addition of the loop in leave_hypervisor_to_guest() as I think
it deserve some explanation.
- The sign extension in handle_ioserv() can possibly be abstracted.
Actually the code is quite similar to handle_read().
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Please note, at the moment build on Arm32 is broken (see cmpxchg usage in
hvm_send_buffered_ioreq()) due to the lack ofcmpxchg_64support on Arm32. There is a patch on review to address this issue:
https://patchwork.kernel.org/patch/11715559/This has been committed.
Thank you for the patch, will remove a notice.
For future reference, I think such notice would be better after --- as they don't need to be part of the commit message.
Quoted 288 lines
Quoted 239 lines
Quoted 239 lines
+ if ( dabt.write )
+ returnIO_HANDLED;xen/arch/arm/ioreq.c new file +34
-0+ + /* + * Sign extend if required. + * Note that we expect the read handler to have zeroed the bits + * outside the requested access size. + */ + if ( dabt.sign && (r & (1UL << (size - 1))) ) + { + /* + * We are relying on register_t using the same as + * an unsigned long in order to keep the 32-bit assembly + * code smaller. + */ + BUILD_BUG_ON(sizeof(register_t) != sizeof(unsigned long)); + r |= (~0UL) << size; + } + + set_user_reg(regs, dabt.reg, r); + + return IO_HANDLED; +} + +enum io_state try_fwd_ioserv (struct cpu_user_regs *regs, + struct vcpu *v, mmio_info_t *info) +{ + struct hvm_vcpu_io *vio = &v->arch.hvm.hvm_io; + ioreq_t p = { + .type = IOREQ_TYPE_COPY, + .addr = info->gpa, + .size = 1 << info->dabt.size, + .count = 1, + .dir = !info->dabt.write, + /* + * On x86, df is used by 'rep' instruction to tell thedirection
+ * to iterate (forward or backward).
+ * On Arm, all the accesses to MMIO region will do a single + * memory access. So for now, we can safely always set to 0. + */
+ .df = 0,
+ .data =get_user_reg(regs, info->dabt.reg),
+ .state =STATE_IOREQ_READY,
+ };
+ structhvm_ioreq_server*s = NULL;
+ enumio_staterc;xen/arch/arm/ioreq.c new file +59
-0+ + switch ( vio->io_req.state ) + { + case STATE_IOREQ_NONE: + break; + + case STATE_IORESP_READY: + return IO_HANDLED; + + default: + gdprintk(XENLOG_ERR, "wrong state %u\n", vio->io_req.state); + return IO_ABORT; + } + + s = hvm_select_ioreq_server(v->domain, &p); + if ( !s ) + return IO_UNHANDLED; + + if ( !info->dabt.valid ) + return IO_ABORT; + + vio->io_req = p; + + rc = hvm_send_ioreq(s, &p, 0); + if ( rc != IO_RETRY || v->domain->is_shutting_down ) + vio->io_req.state = STATE_IOREQ_NONE; + else if ( !hvm_ioreq_needs_completion(&vio->io_req) ) + rc = IO_HANDLED; + else + vio->io_completion = HVMIO_mmio_completion; + + return rc; +} + +bool ioreq_handle_complete_mmio (void ) +{ + struct vcpu *v = current; + struct cpu_user_regs *regs = guest_cpu_user_regs(); + const union hsr hsr = { .bits = regs->hsr }; + paddr_t addr = v->arch.hvm.hvm_io.io_req.addr; + + if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED ) + { + advance_pc(regs, hsr); + return true; + } + + return false; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/traps.c +4
-0@@ -21,6 +21,7 @@ #include <xen/hypercall.h> #include <xen/init.h> #include <xen/iocap.h> +#include <xen/ioreq.h> #include <xen/irq.h> #include <xen/lib.h> #include <xen/mem_access.h>@@ -1384,6 +1385,9 @@ static arm_hypercall_t arm_hypercall_table[] = { #ifdef CONFIG_HYPFS HYPERCALL(hypfs_op, 5), #endif +#ifdef CONFIG_IOREQ_SERVER + HYPERCALL(dm_op, 3), +#endif }; #ifndef NDEBUG@@ -1955,9 +1959,14 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,case
IO_HANDLED:
advance_pc(regs, hsr);
return;
+ caseIO_RETRY:
+ /* finish later */
+ return;
caseIO_UNHANDLED:
/* IO unhandled, try another way to handle it. */ break;
+ default:
+ASSERT_UNREACHABLE();
}
}
@@ -2249,12 +2258,23 @@ static voidcheck_for_pcpu_work(void)
* Process pending work for the vCPU. Any call should be fast or
* implement preemption.
*/xen/arch/arm/traps.c +1
-1-static void check_for_vcpu_work (void ) +static bool check_for_vcpu_work (void ){
struct vcpu *v = current;
+#ifdefCONFIG_IOREQ_SERVER
+ bool handled;xen/arch/arm/traps.c +9
-0+ + local_irq_enable(); + handled = handle_hvm_io_completion(v); + local_irq_disable(); + + if ( !handled ) + return true; +#endif +if (
likely(!v->arch.need_flush_to_ram))
- return;
+ return false;
/*
* Give a chance for the pCPU to process work before handling the vCPUxen/arch/arm/traps.c +6
-1@@ -2265,6 +2285,8 @@ static void check_for_vcpu_work(void) local_irq_enable(); p2m_flush_vm(v); local_irq_disable(); + + return false; } /*@@ -2277,8 +2299,10 @@ void leave_hypervisor_to_guest(void) { local_irq_disable(); - check_for_vcpu_work(); - check_for_pcpu_work(); + do + { + check_for_pcpu_work(); + } while ( check_for_vcpu_work() ); vgic_sync_to_lrs();diff --git
a/xen/include/asm-arm/domain.hb/xen/include/asm-arm/domain.hindex 6819a3b..d1c48d7 100644xen/include/asm-arm/domain.h +4
-0@@ -11,10 +11,27 @@ #include <asm/vgic.h> #include <asm/vpl011.h> #include <public/hvm/params.h> +#include <public/hvm/dm_op.h> +#include <public/hvm/ioreq.h> + +#define MAX_NR_IOREQ_SERVERS 8struct
hvm_domain
{
uint64_t params[HVM_NR_PARAMS];xen/include/asm-arm/domain.h +9
-0+ + /* Guest page range used for non-default ioreq servers */ + struct { + unsigned long base; + unsigned long mask; + unsigned long legacy_mask; /* indexed by HVM param number */ + } ioreq_gfn; + + /* Lock protects all other values in the sub-struct and thedefault */
+ struct {
+ spinlock_t lock;
+ structhvm_ioreq_server*server[MAX_NR_IOREQ_SERVERS]; + }ioreq_server;
};
#ifdefCONFIG_ARM_64xen/include/asm-arm/domain.h +13
-0@@ -91,6 +108,28 @@ struct arch_domain #endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame@mmio_gpfn.
+ * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access.Quoted 8 lines
xen/include/asm-arm/domain.h
Quoted 6 lines
+ */
+ struct npfecmmio_access;
+ unsigned longmmio_gla;
+ unsigned longmmio_gpfn;xen/include/asm-arm/domain.h +2
-0+}; +Why do we need to re-define most of this? Can't this just be in common code?
Jan asked almost the similar question in "[PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common". Please see my answer there:
https://patchwork.kernel.org/patch/11769105/#23637511Theoretically we could move this to the common code, but the question is how to be with other struct fields the x86's struct
hvm_vcpu_iohas/needs but Arm's seems not, would it be possible to logically split structhvm_vcpu_iointo common and arch parts?struct
hvm_vcpu_io{
/* I/O request in flight to device model. */
enumhvm_io_completionio_completion;
ioreq_tio_req;/*
* HVM emulation:
* Linear address @mmio_gla maps to MMIO physical frame @mmio_gpfn. * The latter is known to be an MMIO frame (not RAM).
* This translation is only valid for accesses as per @mmio_access. */
struct npfecmmio_access;
unsigned longmmio_gla;
unsigned longmmio_gpfn;/*
* We may need to handle up to 3 distinct memory accesses per
* instruction.
*/
structhvm_mmio_cachemmio_cache[3];
unsigned intmmio_cache_count;/* For retries we shouldn't re-fetch the instruction. */ unsigned int
mmio_insn_bytes;
unsigned char mmio_insn[16];
structhvmemul_cache*cache;/*
* For string instruction emulation we need to be able to signal a
* necessary retry through other than function return codes. */
bool_tmmio_retry;
Quoted 6 lines
unsigned long
msix_unmask_address;
unsigned longmsix_snoop_address;
unsigned longmsix_snoop_gpa;const struct
g2m_ioport*g2m_ioport;
};
I think Jan made some suggestion today. Let me know if you require more input.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
On 24.09.20 20:25, Julien Grall wrote:
Hi Julien.
Quoted 37 lines · Oleksandr
Quoted 28 lines · Julien Grall
Quoted 1 line
Hi,
Hi Julien
Quoted 5 lines · Oleksandr Tyshchenko
Quoted 1 line
From: Oleksandr Tyshchenko <[email protected]>
I believe I am the originally author of this code...
Sorry, will fix
Quoted 6 lines
Quoted 4 lines
This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality, add remaining bits as well as address several TODOs.
Find a bit weird to add code with TODOs that are handled in the same series? Can't we just split this patch in smaller one where everything is addressed from start?
Sorry if I wasn't clear in description. Let me please clarify.
Corresponding RFC patch had 3 major TODOs:
1. Handle properly whenhvm_send_ioreq()returnsIO_RETRY
2. Proper ref-counting for the foreign entries inset_foreign_p2m_entry()
3. Check the return value ofhandle_hvm_io_completion()*and* avoid callinghandle_hvm_io_completion()on every return.Quoted 5 lines
TODO #1 was fixed in current patch
TODO #2 was fixed in "xen/mm: Handle properly reference inset_foreign_p2m_entry()on Arm"
TODO #3 was partially fixed in current patch (check the return value ofhandle_hvm_io_completion()).
The second part of TODO #3 (avoid callinghandle_hvm_io_completion()on every return) was moved to a separate patch "xen/ioreq: Introducehvm_domain_has_ioreq_server()" and fixed (or probably improved is a better word) there along with introducing a mechanism to actually improve.
Quoted 3 lines
Right, none of those TODOs are described in the code. So it makes more difficult to know what you are actually referring to.
I would suggest to reshuffle the series so the TODOs are addressed before when possible.
ok, I will try to prepare something.
Quoted 5 lines
Quoted 3 lines
Could you please clarify how this patch could be split in smaller one?
This patch is going to be reduced a fair bit if you make some of the structure common. The next steps would be to move anything that is not directly related to IOREQ out.
Thank you for the clarification.
Yes, however, I believed everything in this patch is directly related to IOREQ...
Quoted 4 lines
From a quick look, there are few things that can be moved in separate patches:
- The addition of theASSERT_UNREACHABLE()
Did you mean the addition of the ASSERT_UNREACHABLE() to arch_handle_hvm_io_completion/handle_pio can moved to separate patches? Sorry, I don't quite understand, for what benefit?
Quoted 1 line
- The addition of the loop in
leave_hypervisor_to_guest()as I think it deserve some explanation.
Agree that loop in leave_hypervisor_to_guest() needs explanation. Will move to separate patch. But, this way I need to return corresponding TODO back to this patch.
Quoted 1 line
- The sign extension in
handle_ioserv()can possibly be abstracted. Actually the code is quite similar tohandle_read().
Ok, will consider that.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.
Please note, at the moment build on Arm32 is broken (see cmpxchg usage in
hvm_send_buffered_ioreq()) due to the lack ofcmpxchg_64support on Arm32. There is a patch on review to address this issue:
https://patchwork.kernel.org/patch/11715559/
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
This has been committed.
Thank you for the patch, will remove a notice.
For future reference, I think such notice would be better after --- as they don't need to be part of the commit message.
Got it.
Quoted 292 lines
Quoted 292 lines
Quoted 241 lines
Quoted 241 lines
+ if ( dabt.write )
+ returnIO_HANDLED;xen/arch/arm/ioreq.c new file +34
-0+ + /* + * Sign extend if required. + * Note that we expect the read handler to have zeroed the bits + * outside the requested access size. + */ + if ( dabt.sign && (r & (1UL << (size - 1))) ) + { + /* + * We are relying on register_t using the same as + * an unsigned long in order to keep the 32-bit assembly + * code smaller. + */ + BUILD_BUG_ON(sizeof(register_t) != sizeof(unsigned long)); + r |= (~0UL) << size; + } + + set_user_reg(regs, dabt.reg, r); + + return IO_HANDLED; +} + +enum io_state try_fwd_ioserv (struct cpu_user_regs *regs, + struct vcpu *v, mmio_info_t *info) +{ + struct hvm_vcpu_io *vio = &v->arch.hvm.hvm_io; + ioreq_t p = { + .type = IOREQ_TYPE_COPY, + .addr = info->gpa, + .size = 1 << info->dabt.size, + .count = 1, + .dir = !info->dabt.write, + /* + * On x86, df is used by 'rep' instruction to tell thedirection
+ * to iterate (forward or backward).
+ * On Arm, all the accesses to MMIO region will do a single + * memory access. So for now, we can safely always set to 0. + */
+ .df = 0,
+ .data =get_user_reg(regs, info->dabt.reg),
+ .state =STATE_IOREQ_READY,
+ };
+ structhvm_ioreq_server*s = NULL;
+ enumio_staterc;xen/arch/arm/ioreq.c new file +59
-0+ + switch ( vio->io_req.state ) + { + case STATE_IOREQ_NONE: + break; + + case STATE_IORESP_READY: + return IO_HANDLED; + + default: + gdprintk(XENLOG_ERR, "wrong state %u\n", vio->io_req.state); + return IO_ABORT; + } + + s = hvm_select_ioreq_server(v->domain, &p); + if ( !s ) + return IO_UNHANDLED; + + if ( !info->dabt.valid ) + return IO_ABORT; + + vio->io_req = p; + + rc = hvm_send_ioreq(s, &p, 0); + if ( rc != IO_RETRY || v->domain->is_shutting_down ) + vio->io_req.state = STATE_IOREQ_NONE; + else if ( !hvm_ioreq_needs_completion(&vio->io_req) ) + rc = IO_HANDLED; + else + vio->io_completion = HVMIO_mmio_completion; + + return rc; +} + +bool ioreq_handle_complete_mmio (void ) +{ + struct vcpu *v = current; + struct cpu_user_regs *regs = guest_cpu_user_regs(); + const union hsr hsr = { .bits = regs->hsr }; + paddr_t addr = v->arch.hvm.hvm_io.io_req.addr; + + if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED ) + { + advance_pc(regs, hsr); + return true; + } + + return false; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/traps.c +4
-0@@ -21,6 +21,7 @@ #include <xen/hypercall.h> #include <xen/init.h> #include <xen/iocap.h> +#include <xen/ioreq.h> #include <xen/irq.h> #include <xen/lib.h> #include <xen/mem_access.h>@@ -1384,6 +1385,9 @@ static arm_hypercall_t arm_hypercall_table[] = { #ifdef CONFIG_HYPFS HYPERCALL(hypfs_op, 5), #endif +#ifdef CONFIG_IOREQ_SERVER + HYPERCALL(dm_op, 3), +#endif }; #ifndef NDEBUG@@ -1955,9 +1959,14 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,case
IO_HANDLED:
advance_pc(regs, hsr);
return;
+ caseIO_RETRY:
+ /* finish later */
+ return;
caseIO_UNHANDLED:
/* IO unhandled, try another way to handle it. */ break;
+ default:
+ASSERT_UNREACHABLE();
}
}
@@ -2249,12 +2258,23 @@ static voidcheck_for_pcpu_work(void)
* Process pending work for the vCPU. Any call should be fast or
* implement preemption.
*/xen/arch/arm/traps.c +1
-1-static void check_for_vcpu_work (void ) +static bool check_for_vcpu_work (void ){
struct vcpu *v = current;
+#ifdefCONFIG_IOREQ_SERVER
+ bool handled;xen/arch/arm/traps.c +9
-0+ + local_irq_enable(); + handled = handle_hvm_io_completion(v); + local_irq_disable(); + + if ( !handled ) + return true; +#endif +if (
likely(!v->arch.need_flush_to_ram))
- return;
+ return false;
/*
* Give a chance for the pCPU to process work before handling the vCPUxen/arch/arm/traps.c +6
-1@@ -2265,6 +2285,8 @@ static void check_for_vcpu_work(void) local_irq_enable(); p2m_flush_vm(v); local_irq_disable(); + + return false; } /*@@ -2277,8 +2299,10 @@ void leave_hypervisor_to_guest(void) { local_irq_disable(); - check_for_vcpu_work(); - check_for_pcpu_work(); + do + { + check_for_pcpu_work(); + } while ( check_for_vcpu_work() ); vgic_sync_to_lrs();diff --git
a/xen/include/asm-arm/domain.hb/xen/include/asm-arm/domain.hindex 6819a3b..d1c48d7 100644xen/include/asm-arm/domain.h +4
-0@@ -11,10 +11,27 @@ #include <asm/vgic.h> #include <asm/vpl011.h> #include <public/hvm/params.h> +#include <public/hvm/dm_op.h> +#include <public/hvm/ioreq.h> + +#define MAX_NR_IOREQ_SERVERS 8struct
hvm_domain
{
uint64_t params[HVM_NR_PARAMS];xen/include/asm-arm/domain.h +9
-0+ + /* Guest page range used for non-default ioreq servers */ + struct { + unsigned long base; + unsigned long mask; + unsigned long legacy_mask; /* indexed by HVM param number */ + } ioreq_gfn; + + /* Lock protects all other values in the sub-struct and thedefault */
+ struct {
+ spinlock_t lock;
+ structhvm_ioreq_server*server[MAX_NR_IOREQ_SERVERS]; + }ioreq_server;
};
#ifdefCONFIG_ARM_64xen/include/asm-arm/domain.h +13
-0@@ -91,6 +108,28 @@ struct arch_domain #endif } __cacheline_aligned; +enum hvm_io_completion { + HVMIO_no_completion, + HVMIO_mmio_completion, + HVMIO_pio_completion +}; + +struct hvm_vcpu_io { + /* I/O request in flight to device model. */ + enum hvm_io_completion io_completion; + ioreq_t io_req; + + /* + * HVM emulation: + * Linear address @mmio_gla maps to MMIO physical frame@mmio_gpfn.
+ * The latter is known to be an MMIO frame (not RAM). + * This translation is only valid for accesses as per @mmio_access.Quoted 8 lines
xen/include/asm-arm/domain.h
Quoted 6 lines
+ */
+ struct npfecmmio_access;
+ unsigned longmmio_gla;
+ unsigned longmmio_gpfn;xen/include/asm-arm/domain.h +2
-0+}; +Why do we need to re-define most of this? Can't this just be in common code?
Jan asked almost the similar question in "[PATCH V1 02/16] xen/ioreq: Make x86's IOREQ feature common". Please see my answer there:
https://patchwork.kernel.org/patch/11769105/#23637511Theoretically we could move this to the common code, but the question is how to be with other struct fields the x86's struct
hvm_vcpu_iohas/needs but Arm's seems not, would it be possible to logically split structhvm_vcpu_iointo common and arch parts?struct
hvm_vcpu_io{
/* I/O request in flight to device model. */
enumhvm_io_completionio_completion;
ioreq_tio_req;/*
* HVM emulation:
* Linear address @mmio_gla maps to MMIO physical frame @mmio_gpfn.
* The latter is known to be an MMIO frame (not RAM). * This translation is only valid for accesses as per @mmio_access.
*/
struct npfecmmio_access;
unsigned longmmio_gla;
unsigned longmmio_gpfn;/*
* We may need to handle up to 3 distinct memory accesses per
* instruction.
*/
structhvm_mmio_cachemmio_cache[3];
unsigned intmmio_cache_count;/* For retries we shouldn't re-fetch the instruction. */ unsigned int
mmio_insn_bytes;
unsigned char mmio_insn[16];
structhvmemul_cache*cache;/*
* For string instruction emulation we need to be able to signal a
* necessary retry through other than function return codes. */
bool_tmmio_retry;
Quoted 8 lines
Quoted 6 lines
unsigned long
msix_unmask_address;
unsigned longmsix_snoop_address;
unsigned longmsix_snoop_gpa;const struct
g2m_ioport*g2m_ioport;
};I think Jan made some suggestion today. Let me know if you require more input.
Yes. I am considering this now. I provided my thoughts on that a little bit earlier. Could you please clarify there.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
Hi Oleksandr,
Quoted 16 lines · Oleksandr
Quoted 7 lines · Julien Grall
Quoted 4 lines · Oleksandr
Quoted 2 lines · Julien Grall
Quoted 1 line · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
Could you please clarify how this patch could be split in smaller one?
This patch is going to be reduced a fair bit if you make some of the structure common. The next steps would be to move anything that is not directly related to IOREQ out.
Thank you for the clarification.
Yes, however, I believed everything in this patch is directly related to IOREQ...Quoted 2 lines
Quoted 5 lines
Quoted 2 lines
From a quick look, there are few things that can be moved in separate patches:
- The addition of theASSERT_UNREACHABLE()Did you mean the addition of the
ASSERT_UNREACHABLE()to arch_handle_hvm_io_completion/handle_pio can moved to separate patches? Sorry, I don't quite understand, for what benefit?
Sorry I didn't realize there was multiple ASSERT_UNREACHABLE() in the code. I was referring to the one in the follow chunk:
@@ -1955,9 +1959,14 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,
case IO_HANDLED:
advance_pc(regs, hsr);
return;
+ case IO_RETRY:
+ /* finish later */
+ return;
case IO_UNHANDLED:
/* IO unhandled, try another way to handle it. */
break;
+ default:
+ ASSERT_UNREACHABLE();
}
}While I understand the reason this was added, to me this doesn't seem to be directly related to this patch.
In fact, the switch case will be done on an enum. So without the default, the compiler will be able to notice if we are adding a new field. With this new approach, you would only notice at runtime (assuming the path is exercised).
So what do we gain?
[...]
Quoted 4 lines
Quoted 1 line
I think Jan made some suggestion today. Let me know if you require more input.
Yes. I am considering this now. I provided my thoughts on that a little bit earlier. Could you please clarify there.
I have replied to it.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 09/16] arm/ioreq: Introduce arch specific bits for IOREQ/DM features
Quoted 1 line · Julien Grall
Hi Oleksandr,
Hi Julien.
Quoted 42 lines · Oleksandr
Quoted 16 lines · Julien Grall
Quoted 7 lines · Oleksandr
Quoted 4 lines · Julien Grall
Quoted 2 lines · Oleksandr Tyshchenko
Quoted 1 line
From: Oleksandr Tyshchenko <[email protected]>
Could you please clarify how this patch could be split in smaller one?
This patch is going to be reduced a fair bit if you make some of the structure common. The next steps would be to move anything that is not directly related to IOREQ out.
Thank you for the clarification.
Yes, however, I believed everything in this patch is directly related to IOREQ...Quoted 2 lines
Quoted 5 lines
Quoted 2 lines
From a quick look, there are few things that can be moved in separate patches:
- The addition of theASSERT_UNREACHABLE()Did you mean the addition of the
ASSERT_UNREACHABLE()to arch_handle_hvm_io_completion/handle_pio can moved to separate patches? Sorry, I don't quite understand, for what benefit?Sorry I didn't realize there was multiple
ASSERT_UNREACHABLE()in the code. I was referring to the one in the follow chunk:(quoted diff) +0
-0@@ -1955,9 +1959,14 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,case
IO_HANDLED:
advance_pc(regs, hsr);
return;
+ caseIO_RETRY:
+ /* finish later */
+ return;
caseIO_UNHANDLED:
/* IO unhandled, try another way to handle it. */ break;
+ default:
+ASSERT_UNREACHABLE();
}
}
Quoted 5 lines
While I understand the reason this was added, to me this doesn't seem to be directly related to this patch.
In fact, the switch case will be done on an enum. So without the default, the compiler will be able to notice if we are adding a new field. With this new approach, you would only notice at runtime (assuming the path is exercised).
So what do we gain?
Hmm, now I am in doubt whether we really need to put ASSERT_UNREACHABLE() here. Also we would notice it at the runtime for debug builds only.
Quoted 9 lines
[...]
Quoted 4 lines
Quoted 1 line
I think Jan made some suggestion today. Let me know if you require more input.
Yes. I am considering this now. I provided my thoughts on that a little bit earlier. Could you please clarify there.
I have replied to it.
Thank you.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH 10/16 xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
This patch implements reference counting of foreign entries in in set_foreign_p2m_entry() on Arm. This is a mandatory action if we want to run emulator (IOREQ server) in other than dom0 domain, as we can't trust it to do the right thing if it is not running in dom0. So we need to grab a reference on the page to avoid it disappearing.
It was tested with IOREQ feature to confirm that all the pages given to this function belong to a domain, so we can use the same approach as for XENMAPSPACE_gmfn_foreign handling in xenmem_add_to_physmap_one().
This involves adding an extra parameter for the foreign domain to set_foreign_p2m_entry().
Also remove restriction for the hardware domain in the common code if we run on Arm.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- new patch, was split from:
"[RFC PATCH V1 04/12] xen/arm: Introduce arch specific bits for IOREQ/DM features"
- rewrite a logic to handle properly reference in set_foreign_p2m_entry() instead of treating foreign entries as p2m_ram_rw
---
--- xen/arch/arm/p2m.c | 16 ++++++++++++++++ xen/arch/x86/mm/p2m.c | 5 +++-- xen/common/memory.c | 4 +++- xen/include/asm-arm/p2m.h | 11 ++--------- xen/include/asm-x86/p2m.h | 3 ++- 5 files changed, 26 insertions(+), 13 deletions(-)
xen/arch/arm/p2m.c +16 -0
@@ -1385,6 +1385,22 @@ int guest_physmap_remove_page(struct domain *d, gfn_t gfn, mfn_t mfn,return p2m_remove_mapping (d, gfn, (1 << page_order), mfn); } +int set_foreign_p2m_entry (struct domain *d,struct domain *fd, +unsigned long gfn,mfn_t mfn) +{ +struct page_info *page =mfn_to_page (mfn); +int rc; + +if ( !get_page (page, fd) ) +return -EINVAL ; + + rc =guest_physmap_add_entry (d,_gfn (gfn), mfn,0 , p2m_map_foreign_rw); +if ( rc ) +put_page (page); + +return 0 ; +} +static struct page_info *p2m_allocate_root (void ) {struct page_info *page;
xen/arch/x86/mm/p2m.c +3 -2
@@ -1320,7 +1320,8 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn_l, }/* Set foreign mfn in the given guest's p2m table. */ -int set_foreign_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn) +int set_foreign_p2m_entry (struct domain *d,struct domain *fd, +unsigned long gfn,mfn_t mfn) {return set_typed_p2m_entry (d, gfn, mfn,PAGE_ORDER_4K , p2m_map_foreign,p2m_get_hostp2m (d)->default_access);
@@ -2619,7 +2620,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,* will update the m2p table which will result in mfn -> gpfn of dom0 * and not fgfn of domU. */ - rc =set_foreign_p2m_entry (tdom, gpfn, mfn); + rc =set_foreign_p2m_entry (tdom, fdom, gpfn, mfn);if ( rc ) gdprintk(XENLOG_WARNING, "set_foreign_p2m_entry failed. " "gpfn:%lx mfn:%lx fgfn:%lx td:%d fd:%d\n",
xen/common/memory.c +3 -1
@@ -1155,6 +1155,7 @@ static int acquire_resource(xen_pfn_t gfn_list[ARRAY_SIZE (mfn_list)];unsigned int i; +#ifndef CONFIG_ARM /* * FIXME: Until foreign pages inserted into the P2M are properly * reference counted, it is unsafe to allow mapping of
@@ -1162,13 +1163,14 @@ static int acquire_resource(*/ if ( !is_hardware_domain (currd) )return -EACCES ; +#endif if (copy_from_guest (gfn_list, xmar.frame_list, xmar.nr_frames) ) rc = -EFAULT ;for ( i =0 ; !rc && i < xmar.nr_frames; i++ ) { - rc =set_foreign_p2m_entry (currd, gfn_list[i], + rc =set_foreign_p2m_entry (currd, d, gfn_list[i],_mfn (mfn_list[i]));/* rc should be -EIO for any iteration other than the first */ if ( rc && i )
xen/include/asm-arm/p2m.h +2 -9
@@ -381,15 +381,8 @@ static inline gfn_t gfn_next_boundary(gfn_t gfn, unsigned int order)return gfn_add (gfn,1UL << order); } -static inline int set_foreign_p2m_entry (struct domain *d,unsigned long gfn, -mfn_t mfn) -{ -/* -* NOTE: If this is implemented then proper reference counting of -* foreign entries will need to be implemented. -*/ -return -EOPNOTSUPP ; -} +int set_foreign_p2m_entry (struct domain *d,struct domain *fd, +unsigned long gfn,mfn_t mfn);/* * A vCPU has cache enabled only when the MMU is enabled and data cache
xen/include/asm-x86/p2m.h +2 -1
@@ -635,7 +635,8 @@ int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start, unsigned long end);/* Set foreign entry in the p2m table (for priv-mapping) */ -int set_foreign_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn); +int set_foreign_p2m_entry (struct domain *d,struct domain *fd, +unsigned long gfn,mfn_t mfn);/* Set mmio addresses in the p2m table (for pass-through) */ int set_mmio_p2m_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
Signature · 1 line
2.7.4
Re: [PATCH V1 10/16] xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
Quoted 11 lines · Oleksandr Tyshchenko
xen/common/memory.c +1
-0@@ -1155,6 +1155,7 @@ static int acquire_resource(xen_pfn_t gfn_list[ARRAY_SIZE (mfn_list)];unsigned int i; +#ifndef CONFIG_ARM /* * FIXME: Until foreign pages inserted into the P2M are properly * reference counted, it is unsafe to allow mapping of
xen/common/memory.c static int acquire_resource( · line 1166
Quoted 4 lines
xen/common/memory.c +1
-0@@ -1162,13 +1163,14 @@ static int acquire_resource(*/ if ( !is_hardware_domain (currd) )return -EACCES ; +#endif
Instead of #ifdef, may I ask that a predicate like arch_refcounts_p2m() be used?
xen/common/memory.c static int acquire_resource( · line 1174
Quoted 8 lines
xen/common/memory.c +1
-1if (copy_from_guest (gfn_list, xmar.frame_list, xmar.nr_frames) ) rc = -EFAULT ;for ( i =0 ; !rc && i < xmar.nr_frames; i++ ) { - rc =set_foreign_p2m_entry (currd, gfn_list[i], + rc =set_foreign_p2m_entry (currd, d, gfn_list[i],_mfn (mfn_list[i]));
Is it going to lead to proper behavior when d == currd, specifically for Arm but also in the abstract model? If you expose this to other than Dom0, this case needs at least considering (and hence mentioning in the description of why it's safe to permit if you don't reject such attempts). Personally I'd view it as wrong to use p2m_map_foreign_rw in this case, even in the event that it can be shown that nothing breaks in such a case. But I'm open to be convinced of the opposite.
Quoted 7 lines
xen/include/asm-arm/p2m.h +0
-1@@ -381,15 +381,8 @@ static inline gfn_t gfn_next_boundary(gfn_t gfn, unsigned int order)return gfn_add (gfn,1UL << order); } -static inline int set_foreign_p2m_entry(struct domain *d, unsigned long gfn,
xen/include/asm-arm/p2m.h static inline gfn_t gfn_next_boundary(gfn_t gfn, unsigned int order) · line 385
Quoted 10 lines
xen/include/asm-arm/p2m.h +2
-8- mfn_t mfn) -{ -/* -* NOTE: If this is implemented then proper reference counting of -* foreign entries will need to be implemented. -*/ -return -EOPNOTSUPP ; -} +int set_foreign_p2m_entry (struct domain *d,struct domain *fd, +unsigned long gfn,mfn_t mfn);
With this and ...
xen/include/asm-x86/p2m.h int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start, · line 639
Quoted 9 lines
xen/include/asm-x86/p2m.h +2
-1@@ -635,7 +635,8 @@ int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start, unsigned long end);/* Set foreign entry in the p2m table (for priv-mapping) */ -int set_foreign_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn); +int set_foreign_p2m_entry (struct domain *d,struct domain *fd, +unsigned long gfn,mfn_t mfn);
... this now being identical (and as a result it being expected that future ports would also want to implement a proper function) except for the stray blank in the Arm variant, I'd like it to be at least considered to move the declaration to xen/p2m-common.h.
Jan
Re: [PATCH V1 10/16] xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
Hi,
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Oleksandr Tyshchenko
xen/common/memory.c +0
-0@@ -1155,6 +1155,7 @@ static int acquire_resource(xen_pfn_t gfn_list[ARRAY_SIZE (mfn_list)];unsigned int i;
Quoted 12 lines
xen/common/memory.c static int acquire_resource( · line 1166
Quoted 9 lines
xen/common/memory.c +2
-0+#ifndef CONFIG_ARM /* * FIXME: Until foreign pages inserted into the P2M are properly * reference counted, it is unsafe to allow mapping of @@ -1162,13 +1163,14 @@ static int acquire_resource(*/ if ( !is_hardware_domain (currd) )return -EACCES ; +#endif Instead of #ifdef, may I ask that a predicate like
arch_refcounts_p2m()be used?
+1
Quoted 10 lines
xen/common/memory.c static int acquire_resource( · line 1174
Quoted 9 lines
xen/common/memory.c +1
-1if (copy_from_guest (gfn_list, xmar.frame_list, xmar.nr_frames) ) rc = -EFAULT ;for ( i =0 ; !rc && i < xmar.nr_frames; i++ ) { - rc =set_foreign_p2m_entry (currd, gfn_list[i], + rc =set_foreign_p2m_entry (currd, d, gfn_list[i],_mfn (mfn_list[i]));
Quoted 5 lines
Is it going to lead to proper behavior when d == currd, specifically for Arm but also in the abstract model? If you expose this to other than Dom0, this case needs at least considering (and hence mentioning in the description of why it's safe to permit if you don't reject such attempts).
This is already rejected by rcu_lock_remote_domain_by_id().
Quoted 4 lines
Personally I'd view it as wrong to use
p2m_map_foreign_rwin this case, even in the event that it can be shown that nothing breaks in such a case. But I'm open to be convinced of the opposite.
I would agree that p2m_map_foreign_rw would be wrong to use when currd == d. But this cannot happen, so I think p2m_map_foreign_rw is the proper type.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 10/16] xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
Quoted 8 lines · Julien Grall
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Oleksandr Tyshchenko
for ( i = 0; !rc && i < xmar.nr_frames; i++ ) {xen/common/memory.c +1
-1- rc =set_foreign_p2m_entry (currd, gfn_list[i], + rc =set_foreign_p2m_entry (currd, d, gfn_list[i],_mfn (mfn_list[i]));
Quoted 7 lines
Quoted 5 lines
Is it going to lead to proper behavior when d == currd, specifically for Arm but also in the abstract model? If you expose this to other than Dom0, this case needs at least considering (and hence mentioning in the description of why it's safe to permit if you don't reject such attempts).
This is already rejected by
rcu_lock_remote_domain_by_id().
Oh, yes, I'm sorry for overlooking this.
Jan
Re: [PATCH V1 10/16] xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Julien Grall
Quoted 12 lines · Jan Beulich
xen/common/memory.c static int acquire_resource( · line 1174
Quoted 5 lines · Oleksandr Tyshchenko
for ( i = 0; !rc && i < xmar.nr_frames; i++ ) {xen/common/memory.c +1
-1- rc =set_foreign_p2m_entry (currd, gfn_list[i], + rc =set_foreign_p2m_entry (currd, d, gfn_list[i],_mfn (mfn_list[i]));Is it going to lead to proper behavior when d == currd, specifically for Arm but also in the abstract model? If you expose this to other than Dom0, this case needs at least considering (and hence mentioning in the description of why it's safe to permit if you don't reject such attempts).
Quoted 3 lines
Quoted 1 line
This is already rejected by
rcu_lock_remote_domain_by_id().Oh, yes, I'm sorry for overlooking this.
That's fine, I also overlooked it when I originally wrote the code.
@oleksandr, it might be worth mentioning in the commit message and maybe in the code this subtlety.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 10/16] xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
On 16.09.20 11:55, Julien Grall wrote:
Hi Julien, Jan
Quoted 18 lines · Jan Beulich
Quoted 15 lines · Julien Grall
Quoted 14 lines · Jan Beulich
Quoted 12 lines · Oleksandr Tyshchenko
Quoted 5 lines
for ( i = 0; !rc && i < xmar.nr_frames; i++ ) {
- rc = set_foreign_p2m_entry(currd, gfn_list[i], + rc =set_foreign_p2m_entry(currd, d, gfn_list[i], _mfn(mfn_list[i]));Is it going to lead to proper behavior when d == currd, specifically for Arm but also in the abstract model? If you expose this to other than Dom0, this case needs at least considering (and hence mentioning in the description of why it's safe to permit if you don't reject such attempts).
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
This is already rejected by
rcu_lock_remote_domain_by_id().Oh, yes, I'm sorry for overlooking this.
That's fine, I also overlooked it when I originally wrote the code.
@oleksandr, it might be worth mentioning in the commit message and maybe in the code this subtlety.
Yes, will do.
Also the following will be taken into the account:
1. Implement arch_refcounts_p2m()
2. Move function declaration to xen/p2m-common.h
3. Add const to new parameter
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 10/16] xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
In reply to Oleksandr Tyshchenkoxen/include/asm-x86/p2m.h int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start, · line 639
Quoted 9 lines · Oleksandr Tyshchenko
xen/include/asm-x86/p2m.h +2
-1@@ -635,7 +635,8 @@ int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start, unsigned long end);/* Set foreign entry in the p2m table (for priv-mapping) */ -int set_foreign_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn); +int set_foreign_p2m_entry (struct domain *d,struct domain *fd, +unsigned long gfn,mfn_t mfn);
Once
https://lists.xenproject.org/archives/html/xen-devel/2020-09/msg01092.html
has gone in, the new parameter wants to be const-qualified.
Jan
PATCH 11/16 xen/ioreq: Introduce hvm_domain_has_ioreq_server()
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
This patch introduces a helper the main purpose of which is to check if a domain is using IOREQ server(s).
On Arm the benefit is to avoid calling handle_hvm_io_completion() (which implies iterating over all possible IOREQ servers anyway) on every return in leave_hypervisor_to_guest() if there is no active servers for the particular domain.
This involves adding an extra per-domain variable to store the count of servers in use.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- new patch
---
--- xen/arch/arm/traps.c | 15 +++++++++------ xen/common/ioreq.c | 9 ++++++++- xen/include/asm-arm/domain.h | 1 + xen/include/asm-x86/hvm/domain.h | 1 + xen/include/xen/ioreq.h | 5 +++++ 5 files changed, 24 insertions(+), 7 deletions(-)
xen/arch/arm/traps.c +9 -6
@@ -2263,14 +2263,17 @@ static bool check_for_vcpu_work(void)struct vcpu *v = current;#ifdef CONFIG_IOREQ_SERVER -bool handled; +if (hvm_domain_has_ioreq_server (v->domain) ) + { +bool handled; -local_irq_enable (); - handled =handle_hvm_io_completion (v); -local_irq_disable (); +local_irq_enable (); + handled =handle_hvm_io_completion (v); +local_irq_disable (); -if ( !handled ) -return true; +if ( !handled ) +return true; + }#endif if (likely (!v->arch.need_flush_to_ram) )
xen/common/ioreq.c +8 -1
@@ -38,9 +38,15 @@ static void set_ioreq_server(struct domain *d, unsigned int id, struct hvm_ioreq_server *s) {ASSERT (id <MAX_NR_IOREQ_SERVERS ); -ASSERT (!s || !d->arch.hvm.ioreq_server.server[id]); +ASSERT ((!s && d->arch.hvm.ioreq_server.server[id]) || + (s && !d->arch.hvm.ioreq_server.server[id])); d->arch.hvm.ioreq_server.server[id] = s; + +if ( s ) + d->arch.hvm.ioreq_server.nr_servers ++; +else + d->arch.hvm.ioreq_server.nr_servers --; }/*
@@ -1395,6 +1401,7 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered)void hvm_ioreq_init (struct domain *d) {spin_lock_init (&d->arch.hvm.ioreq_server.lock); + d->arch.hvm.ioreq_server.nr_servers =0 ;arch_hvm_ioreq_init (d); }
xen/include/asm-arm/domain.h +1 -0
@@ -31,6 +31,7 @@ struct hvm_domainstruct {spinlock_t lock;struct hvm_ioreq_server *server[MAX_NR_IOREQ_SERVERS ]; +unsigned int nr_servers; } ioreq_server; };
xen/include/asm-x86/hvm/domain.h +1 -0
@@ -77,6 +77,7 @@ struct hvm_domain {struct {spinlock_t lock;struct hvm_ioreq_server *server[MAX_NR_IOREQ_SERVERS ]; +unsigned int nr_servers; } ioreq_server;/* Cached CF8 for guest PCI config cycles */
xen/include/xen/ioreq.h +5 -0
@@ -57,6 +57,11 @@ struct hvm_ioreq_server {uint8_t bufioreq_handling; }; +static inline bool hvm_domain_has_ioreq_server (const struct domain *d) +{ +return (d->arch.hvm.ioreq_server.nr_servers >0 ); +} +#define GET_IOREQ_SERVER (d, id) \ (d)->arch.hvm.ioreq_server.server[id]
Signature · 1 line
2.7.4
Re: [PATCH V1 11/16] xen/ioreq: Introduce hvm_domain_has_ioreq_server()
Quoted 5 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
This patch introduces a helper the main purpose of which is to check if a domain is using IOREQ server(s).
Quoted 7 lines
On Arm the benefit is to avoid calling
handle_hvm_io_completion()(which implies iterating over all possible IOREQ servers anyway) on every return inleave_hypervisor_to_guest()if there is no active servers for the particular domain.This involves adding an extra per-domain variable to store the count of servers in use.
Since only Arm needs the variable (and the helper), perhaps both should be Arm-specific (which looks to be possible without overly much hassle)?
xen/common/ioreq.c static void set_ioreq_server(struct domain *d, unsigned int id, · line 42
Quoted 9 lines
xen/common/ioreq.c +2
-1@@ -38,9 +38,15 @@ static void set_ioreq_server(struct domain *d, unsigned int id, struct hvm_ioreq_server *s) {ASSERT (id <MAX_NR_IOREQ_SERVERS ); -ASSERT (!s || !d->arch.hvm.ioreq_server.server[id]); +ASSERT ((!s && d->arch.hvm.ioreq_server.server[id]) || + (s && !d->arch.hvm.ioreq_server.server[id]));
For one, this can be had with less redundancy (and imo even improved clarity, but I guess this latter aspect my depend on personal preferences):
ASSERT(d->arch.hvm.ioreq_server.server[id] ? !s : !!s);
But then I wonder whether the original intention wasn't rather such that replacing NULL by NULL is permissible. Paul?
xen/common/ioreq.c static void set_ioreq_server(struct domain *d, unsigned int id, · line 49
Quoted 6 lines
xen/common/ioreq.c +5
-0d->arch.hvm.ioreq_server.server[id] = s; + +if ( s ) + d->arch.hvm.ioreq_server.nr_servers ++; +else + d->arch.hvm.ioreq_server.nr_servers --;
Nit: Stray blanks (should be there only with binary operators).
xen/common/ioreq.c unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered) · line 1404
Quoted 5 lines
xen/common/ioreq.c +1
-0@@ -1395,6 +1401,7 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered)void hvm_ioreq_init (struct domain *d) {spin_lock_init (&d->arch.hvm.ioreq_server.lock); + d->arch.hvm.ioreq_server.nr_servers =0 ;
There's no need for this - struct domain instances start out all zero anyway.
xen/include/xen/ioreq.h struct hvm_ioreq_server { · line 63
Quoted 10 lines
xen/include/xen/ioreq.h +4
-0@@ -57,6 +57,11 @@ struct hvm_ioreq_server {uint8_t bufioreq_handling; }; +static inline bool hvm_domain_has_ioreq_server (const struct domain *d) +{ +return (d->arch.hvm.ioreq_server.nr_servers >0 ); +}
This is safe only when d == current->domain and it's not paused, or when they're distinct and d is paused. Otherwise the result is stale before the caller can inspect it. This wants documenting by at least a comment, but perhaps better by suitable ASSERT()s.
As in earlier patches I don't think a hvm_ prefix should be used here.
Also as a nit: The parentheses here are unnecessary, and strictly speaking the "> 0" is, too.
Jan
RE: [PATCH V1 11/16] xen/ioreq: Introduce hvm_domain_has_ioreq_server()
Quoted 10 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 16 September 2020 09:05
To: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>
Cc: [email protected]; Oleksandr Tyshchenko <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Volodymyr Babchuk <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 11/16] xen/ioreq: Introducehvm_domain_has_ioreq_server()
Quoted 11 lines
Quoted 10 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
This patch introduces a helper the main purpose of which is to check if a domain is using IOREQ server(s).
On Arm the benefit is to avoid calling
handle_hvm_io_completion()(which implies iterating over all possible IOREQ servers anyway) on every return inleave_hypervisor_to_guest()if there is no active servers for the particular domain.
Is this really worth it? The limit on the number of ioreq serves is small... just 8. I doubt you'd be able measure the difference.
Quoted 20 lines
Quoted 2 lines
This involves adding an extra per-domain variable to store the count of servers in use.
Since only Arm needs the variable (and the helper), perhaps both should be Arm-specific (which looks to be possible without overly much hassle)?
xen/common/ioreq.c static void set_ioreq_server(struct domain *d, unsigned int id, · line 42
Quoted 9 lines
xen/common/ioreq.c +2
-1@@ -38,9 +38,15 @@ static void set_ioreq_server(struct domain *d, unsigned int id, struct hvm_ioreq_server *s) {ASSERT (id <MAX_NR_IOREQ_SERVERS ); -ASSERT (!s || !d->arch.hvm.ioreq_server.server[id]); +ASSERT ((!s && d->arch.hvm.ioreq_server.server[id]) || + (s && !d->arch.hvm.ioreq_server.server[id]));For one, this can be had with less redundancy (and imo even improved clarity, but I guess this latter aspect my depend on personal preferences):
Quoted 5 lines
ASSERT(d->arch.hvm.ioreq_server.server[id] ? !s : !!s);But then I wonder whether the original intention wasn't rather such that replacing NULL by NULL is permissible. Paul?
Yikes, that's a long time ago.. but I can't see why the check for !s would be there unless it was indeed intended to allow replacing NULL with NULL.
Paul
Re: [PATCH V1 11/16] xen/ioreq: Introduce hvm_domain_has_ioreq_server()
Quoted 16 lines · Paul Durrant
Quoted 16 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 16 September 2020 09:05
To: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>
Cc: [email protected]; Oleksandr Tyshchenko <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Volodymyr Babchuk <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 11/16] xen/ioreq: Introducehvm_domain_has_ioreq_server()Quoted 5 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
This patch introduces a helper the main purpose of which is to check if a domain is using IOREQ server(s).
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
On Arm the benefit is to avoid calling
handle_hvm_io_completion()(which implies iterating over all possible IOREQ servers anyway) on every return inleave_hypervisor_to_guest()if there is no active servers for the particular domain.Is this really worth it? The limit on the number of ioreq serves is small... just 8.
When I suggested this, I failed to realize there was only 8 IOREQ servers available. However, I would not be surprised if this increase long term as we want to use
Quoted 1 line
I doubt you'd be able measure the difference.
Bear in mind that entry/exit to the hypervisor is pretty "cheap" on Arm compare to x86. So we want to avoid doing extra work if it is not necessary.
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH V1 11/16] xen/ioreq: Introduce hvm_domain_has_ioreq_server()
Quoted 36 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 16 September 2020 09:39
To: [email protected]; 'Jan Beulich' <[email protected]>; 'Oleksandr Tyshchenko' <[email protected]>
Cc: [email protected]; 'Oleksandr Tyshchenko' <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'Volodymyr Babchuk' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'Wei Liu' <[email protected]>; 'Roger Pau Monné' <[email protected]>; 'Julien Grall' <[email protected]>
Subject: Re: [PATCH V1 11/16] xen/ioreq: Introducehvm_domain_has_ioreq_server()Quoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 16 September 2020 09:05
To: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>
Cc: [email protected]; Oleksandr Tyshchenko <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Volodymyr Babchuk <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>;Roger
Quoted 15 lines
Quoted 14 lines
Pau Monné <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 11/16] xen/ioreq: Introducehvm_domain_has_ioreq_server()Quoted 10 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
This patch introduces a helper the main purpose of which is to check if a domain is using IOREQ server(s).
On Arm the benefit is to avoid calling
handle_hvm_io_completion()(which implies iterating over all possible IOREQ servers anyway) on every return inleave_hypervisor_to_guest()if there is no active servers for the particular domain.
Quoted 5 lines
Quoted 1 line
Is this really worth it? The limit on the number of ioreq serves is small... just 8.
When I suggested this, I failed to realize there was only 8 IOREQ servers available. However, I would not be surprised if this increase long term as we want to use
If that happens then we'll probably want to move (back to) a list rather than an array...
Quoted 5 lines
Quoted 2 lines
I doubt you'd be able measure the difference.
Bear in mind that entry/exit to the hypervisor is pretty "cheap" on Arm compare to x86. So we want to avoid doing extra work if it is not necessary.
... which will seamlessly deal with this issue.
Paul
Quoted 4 lines
Cheers,
--
Julien Grall
Re: [PATCH V1 11/16] xen/ioreq: Introduce hvm_domain_has_ioreq_server()
On 16.09.20 11:43, Paul Durrant wrote:
Hi all.
Quoted 39 lines
Quoted 35 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 16 September 2020 09:39
To: [email protected]; 'Jan Beulich' <[email protected]>; 'Oleksandr Tyshchenko' <[email protected]>
Cc: [email protected]; 'Oleksandr Tyshchenko' <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'Volodymyr Babchuk' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'Wei Liu' <[email protected]>; 'Roger Pau Monné' <[email protected]>; 'Julien Grall' <[email protected]>
Subject: Re: [PATCH V1 11/16] xen/ioreq: Introducehvm_domain_has_ioreq_server()Quoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 16 September 2020 09:05
To: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>
Cc: [email protected]; Oleksandr Tyshchenko <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Volodymyr Babchuk <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>;Roger
Quoted 14 lines
Quoted 14 lines
Pau Monné <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 11/16] xen/ioreq: Introducehvm_domain_has_ioreq_server()Quoted 10 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
This patch introduces a helper the main purpose of which is to check if a domain is using IOREQ server(s).
On Arm the benefit is to avoid calling
handle_hvm_io_completion()(which implies iterating over all possible IOREQ servers anyway) on every return inleave_hypervisor_to_guest()if there is no active servers for the particular domain.Quoted 4 lines
Quoted 1 line
Is this really worth it? The limit on the number of ioreq serves is small... just 8.
When I suggested this, I failed to realize there was only 8 IOREQ servers available. However, I would not be surprised if this increase long term as we want to use
Quoted 7 lines
If that happens then we'll probably want to move (back to) a list rather than an array...
Quoted 4 lines
Quoted 1 line
I doubt you'd be able measure the difference.
Bear in mind that entry/exit to the hypervisor is pretty "cheap" on Arm compare to x86. So we want to avoid doing extra work if it is not necessary.
... which will seamlessly deal with this issue.
Please note that in addition to benefit for the exit part on Arm we could also use this helper to check if domain is using IOREQ here [1] to avoid an extra action (send_invalidate_req() call).
[1] https://patchwork.kernel.org/patch/11769143/
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 11/16] xen/ioreq: Introduce hvm_domain_has_ioreq_server()
In reply to Jan BeulichOn 16.09.20 11:04, Jan Beulich wrote:
Hi Jan
Quoted 11 lines · Oleksandr Tyshchenko
Quoted 10 lines
From: Oleksandr Tyshchenko <[email protected]>
This patch introduces a helper the main purpose of which is to check if a domain is using IOREQ server(s).
On Arm the benefit is to avoid calling
handle_hvm_io_completion()(which implies iterating over all possible IOREQ servers anyway) on every return inleave_hypervisor_to_guest()if there is no active servers for the particular domain.
Quoted 4 lines
Quoted 2 lines
This involves adding an extra per-domain variable to store the count of servers in use.
Since only Arm needs the variable (and the helper), perhaps both should be Arm-specific (which looks to be possible without overly much hassle)?
Please note that the whole ioreq_server struct are going be moved to "common" domain and new variable is going to go into it. I am wondering whether this single-line helper could be used on x86 or potential new arch ...
Quoted 14 lines
xen/common/ioreq.c static void set_ioreq_server(struct domain *d, unsigned int id, · line 42
Quoted 10 lines
xen/common/ioreq.c +2
-1@@ -38,9 +38,15 @@ static void set_ioreq_server(struct domain *d, unsigned int id, struct hvm_ioreq_server *s) {ASSERT (id <MAX_NR_IOREQ_SERVERS ); -ASSERT (!s || !d->arch.hvm.ioreq_server.server[id]); +ASSERT ((!s && d->arch.hvm.ioreq_server.server[id]) || + (s && !d->arch.hvm.ioreq_server.server[id]));For one, this can be had with less redundancy (and imo even improved clarity, but I guess this latter aspect my depend on personal preferences):
Quoted 1 line
ASSERT(d->arch.hvm.ioreq_server.server[id] ? !s : !!s);
This construction indeed better.
Quoted 11 lines
But then I wonder whether the original intention wasn't rather such that replacing NULL by NULL is permissible. Paul?
xen/common/ioreq.c static void set_ioreq_server(struct domain *d, unsigned int id, · line 49
Quoted 6 lines
xen/common/ioreq.c +5
-0d->arch.hvm.ioreq_server.server[id] = s; + +if ( s ) + d->arch.hvm.ioreq_server.nr_servers ++; +else + d->arch.hvm.ioreq_server.nr_servers --;Nit: Stray blanks (should be there only with binary operators).
ok
Quoted 8 lines
xen/common/ioreq.c unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered) · line 1404
Quoted 6 lines
xen/common/ioreq.c +1
-0@@ -1395,6 +1401,7 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered)void hvm_ioreq_init (struct domain *d) {spin_lock_init (&d->arch.hvm.ioreq_server.lock); + d->arch.hvm.ioreq_server.nr_servers =0 ;There's no need for this - struct domain instances start out all zero anyway.
ok
Quoted 7 lines
Quoted 7 lines
xen/include/xen/ioreq.h +0
-0@@ -57,6 +57,11 @@ struct hvm_ioreq_server {uint8_t bufioreq_handling; };
Quoted 8 lines
xen/include/xen/ioreq.h struct hvm_ioreq_server { · line 63
Quoted 4 lines
xen/include/xen/ioreq.h +4
-0+static inline bool hvm_domain_has_ioreq_server (const struct domain *d) +{ +return (d->arch.hvm.ioreq_server.nr_servers >0 ); +}This is safe only when d ==
current->domainand it's not paused, or when they're distinct and d is paused. Otherwise the result is stale before the caller can inspect it. This wants documenting by at least a comment, but perhaps better by suitable ASSERT()s.
Agree, will use ASSERT()s.
Quoted 3 lines
As in earlier patches I don't think a
hvm_prefix should be used here.
ok
Quoted 3 lines
Also as a nit: The parentheses here are unnecessary, and strictly speaking the "> 0" is, too.
ok
Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH 12/16 xen/dm: Introduce xendevicemodel_set_irq_level DM op
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
This patch adds ability to the device emulator to notify otherend (some entity running in the guest) using a SPI and implements Arm specific bits for it. Proposed interface allows emulator to set the logical level of a one of a domain's IRQ lines.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Please note, I left interface untouched since there is still an open discussion what interface to use/what information to pass to the hypervisor. The question whether we should abstract away the state of the line or not.
Changes RFC -> V1:
- check incoming parameters in arch_dm_op()
- add explicit padding to struct xen_dm_op_set_irq_level
---
--- tools/libs/devicemodel/core.c | 18 +++++++++++++ tools/libs/devicemodel/include/xendevicemodel.h | 4 +++ tools/libs/devicemodel/libxendevicemodel.map | 1 + xen/arch/arm/dm.c | 36 ++++++++++++++++++++++++- xen/common/dm.c | 1 + xen/include/public/hvm/dm_op.h | 15 +++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-)
tools/libs/devicemodel/core.c +18 -0
@@ -430,6 +430,24 @@ int xendevicemodel_set_isa_irq_level(return xendevicemodel_op (dmod, domid,1 , &op,sizeof (op)); } +int xendevicemodel_set_irq_level ( +xendevicemodel_handle *dmod,domid_t domid,uint32_t irq, +unsigned int level) +{ +struct xen_dm_op op; +struct xen_dm_op_set_irq_level *data; + +memset (&op,0 ,sizeof (op)); + + op.op = XEN_DMOP_set_irq_level; + data = &op.u.set_irq_level; + + data->irq = irq; + data->level = level; + +return xendevicemodel_op (dmod, domid,1 , &op,sizeof (op)); +} +int xendevicemodel_set_pci_link_route (xendevicemodel_handle *dmod,domid_t domid,uint8_t link,uint8_t irq) {
tools/libs/devicemodel/include/xendevicemodel.h +4 -0
@@ -209,6 +209,10 @@ int xendevicemodel_set_isa_irq_level( xendevicemodel_handle *dmod, domid_t domid, uint8_t irq, unsigned int level); +int xendevicemodel_set_irq_level ( +xendevicemodel_handle *dmod,domid_t domid,unsigned int irq, +unsigned int level); +/** * This function maps a PCI INTx line to a an IRQ line. *
tools/libs/devicemodel/libxendevicemodel.map +1 -0
@@ -32,6 +32,7 @@ VERS_1.2 { global: xendevicemodel_relocate_memory; xendevicemodel_pin_memory_cacheattr; + xendevicemodel_set_irq_level; } VERS_1.1; VERS_1.3 {
xen/arch/arm/dm.c +35 -1
@@ -15,11 +15,45 @@*/ #include <xen/hypercall.h> +#include <asm/vgic.h> int arch_dm_op (struct xen_dm_op *op,struct domain *d,const struct dmop_args *op_args,bool *const_op) { -return -EOPNOTSUPP ; +int rc; + +switch ( op->op ) + { +case XEN_DMOP_set_irq_level: + { +const struct xen_dm_op_set_irq_level *data = + &op->u.set_irq_level; + +/* Only SPIs are supported */ +if ( (data->irq <NR_LOCAL_IRQS ) || (data->irq >=vgic_num_irqs (d)) ) + { + rc = -EINVAL ; +break ; + } + +if ( data->level !=0 && data->level !=1 ) + { + rc = -EINVAL ; +break ; + } + + +vgic_inject_irq (d,NULL , data->irq, data->level); + rc =0 ; +break ; + } + +default : + rc = -EOPNOTSUPP ; +break ; + } + +return rc; }/*
xen/common/dm.c +1 -0
@@ -47,6 +47,7 @@ static int dm_op(const struct dmop_args *op_args) [XEN_DMOP_remote_shutdown] = sizeof(struct xen_dm_op_remote_shutdown), [XEN_DMOP_relocate_memory] = sizeof(struct xen_dm_op_relocate_memory), [XEN_DMOP_pin_memory_cacheattr] = sizeof(struct xen_dm_op_pin_memory_cacheattr), + [XEN_DMOP_set_irq_level] =sizeof (struct xen_dm_op_set_irq_level ), }; rc =rcu_lock_remote_domain_by_id (op_args->domid, &d);
xen/include/public/hvm/dm_op.h +15 -0
@@ -417,6 +417,20 @@ struct xen_dm_op_pin_memory_cacheattr {uint32_t pad; }; +/* +* XEN_DMOP_set_irq_level: Set the logical level of a one of a domain's +* IRQ lines. +* XXX Handle PPIs. +*/ +#define XEN_DMOP_set_irq_level 19 + +struct xen_dm_op_set_irq_level { +uint32_t irq; +/* IN - Level: 0 -> deasserted, 1 -> asserted */ +uint8_t level; +uint8_t pad[3 ]; +}; +struct xen_dm_op {uint32_t op;uint32_t pad;
@@ -430,6 +444,7 @@ struct xen_dm_op {struct xen_dm_op_track_dirty_vram track_dirty_vram;struct xen_dm_op_set_pci_intx_level set_pci_intx_level;struct xen_dm_op_set_isa_irq_level set_isa_irq_level; +struct xen_dm_op_set_irq_level set_irq_level;struct xen_dm_op_set_pci_link_route set_pci_link_route;struct xen_dm_op_modified_memory modified_memory;struct xen_dm_op_set_mem_type set_mem_type;
Signature · 1 line
2.7.4
Re: [PATCH V1 12/16] xen/dm: Introduce xendevicemodel_set_irq_level DM op
(+ Paul and Andre)
Hi,
Adding Paul as the author of DMOP and Andre as this is GIC related.
Quoted 1 line · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
Looking at the PoC I shared with you, this code was originally written by me.
Quoted 5 lines
This patch adds ability to the device emulator to notify otherend (some entity running in the guest) using a SPI and implements Arm specific bits for it. Proposed interface allows emulator to set the logical level of a one of a domain's IRQ lines.
It would be good to explain in the commit message why we can't use the existing DMOP to inject an interrupt.
Quoted 86 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Please note, I left interface untouched since there is still an open discussion what interface to use/what information to pass to the hypervisor. The question whether we should abstract away the state of the line or not.
Changes RFC -> V1:
- check incoming parameters inarch_dm_op()
- add explicit padding to structxen_dm_op_set_irq_level
------ tools/libs/devicemodel/core.c | 18 +++++++++++++ tools/libs/devicemodel/include/xendevicemodel.h | 4 +++ tools/libs/devicemodel/libxendevicemodel.map | 1 + xen/arch/arm/dm.c | 36 ++++++++++++++++++++++++- xen/common/dm.c | 1 + xen/include/public/hvm/dm_op.h | 15 +++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-)tools/libs/devicemodel/core.c +18
-0@@ -430,6 +430,24 @@ int xendevicemodel_set_isa_irq_level(return xendevicemodel_op (dmod, domid,1 , &op,sizeof (op)); } +int xendevicemodel_set_irq_level ( +xendevicemodel_handle *dmod,domid_t domid,uint32_t irq, +unsigned int level) +{ +struct xen_dm_op op; +struct xen_dm_op_set_irq_level *data; + +memset (&op,0 ,sizeof (op)); + + op.op = XEN_DMOP_set_irq_level; + data = &op.u.set_irq_level; + + data->irq = irq; + data->level = level; + +return xendevicemodel_op (dmod, domid,1 , &op,sizeof (op)); +} +int xendevicemodel_set_pci_link_route (xendevicemodel_handle *dmod,domid_t domid,uint8_t link,uint8_t irq) {tools/libs/devicemodel/include/xendevicemodel.h +4
-0@@ -209,6 +209,10 @@ int xendevicemodel_set_isa_irq_level( xendevicemodel_handle *dmod, domid_t domid, uint8_t irq, unsigned int level); +int xendevicemodel_set_irq_level ( +xendevicemodel_handle *dmod,domid_t domid,unsigned int irq, +unsigned int level); +/** * This function maps a PCI INTx line to a an IRQ line. * tools/libs/devicemodel/libxendevicemodel.map +1
-0@@ -32,6 +32,7 @@ VERS_1.2 { global: xendevicemodel_relocate_memory; xendevicemodel_pin_memory_cacheattr; + xendevicemodel_set_irq_level; } VERS_1.1; VERS_1.3 {xen/arch/arm/dm.c +0
-0
xen/arch/arm/dm.c line 17
Quoted 3 lines
xen/arch/arm/dm.c +0
-0@@ -15,11 +15,45 @@*/ #include <xen/hypercall.h>
NIT: newline between <xen/*> and <asm/*> includes.
Quoted 18 lines
xen/arch/arm/dm.c +13
-1+#include <asm/vgic.h> int arch_dm_op (struct xen_dm_op *op,struct domain *d,const struct dmop_args *op_args,bool *const_op) { -return -EOPNOTSUPP ; +int rc; + +switch ( op->op ) + { +case XEN_DMOP_set_irq_level: + { +const struct xen_dm_op_set_irq_level *data = + &op->u.set_irq_level; + +/* Only SPIs are supported */ +if ( (data->irq <NR_LOCAL_IRQS ) || (data->irq >=vgic_num_irqs (d)) ) + {
xen/arch/arm/dm.c line 44
Quoted 10 lines
xen/arch/arm/dm.c +10
-0+ rc = -EINVAL ; +break ; + } + +if ( data->level !=0 && data->level !=1 ) + { + rc = -EINVAL ; +break ; + } +
I think we want to check the padding is always 0.
xen/arch/arm/dm.c line 46
Quoted 2 lines
xen/arch/arm/dm.c +2
-0+ +vgic_inject_irq (d,NULL , data->irq, data->level);
So, this interface will allow the device emulator to raise/lower the line for an HW mapped interrupt. I think this will mess up with the internal state machine.
It would probably be better if a device emulator can only raise/lower the line for non-allocated interrupts (see d->arch.vgic.allocated_irqs). Any thoughts?
Quoted 30 lines
xen/arch/arm/dm.c +10
-0+ rc =0 ; +break ; + } + +default : + rc = -EOPNOTSUPP ; +break ; + } + +return rc; }/* xen/common/dm.c +1
-0@@ -47,6 +47,7 @@ static int dm_op(const struct dmop_args *op_args) [XEN_DMOP_remote_shutdown] = sizeof(struct xen_dm_op_remote_shutdown), [XEN_DMOP_relocate_memory] = sizeof(struct xen_dm_op_relocate_memory), [XEN_DMOP_pin_memory_cacheattr] = sizeof(struct xen_dm_op_pin_memory_cacheattr), + [XEN_DMOP_set_irq_level] =sizeof (struct xen_dm_op_set_irq_level ), }; rc =rcu_lock_remote_domain_by_id (op_args->domid, &d);xen/include/public/hvm/dm_op.h +0
-0
xen/include/public/hvm/dm_op.h struct xen_dm_op_pin_memory_cacheattr { · line 423
Quoted 7 lines
xen/include/public/hvm/dm_op.h +4
-0@@ -417,6 +417,20 @@ struct xen_dm_op_pin_memory_cacheattr {uint32_t pad; }; +/* +* XEN_DMOP_set_irq_level: Set the logical level of a one of a domain's +* IRQ lines. +* XXX Handle PPIs.
This is a public interface, so it seems a bit strange to leave a TODO in this code.
I wouldn't be surprised if someone will want PPI support soon, but we may be able to defer it if we can easily extend the hypercall.
@Paul, how did you envision to extend DMOP?
Also, is there any plan to add x86 support? If not, then I think we want to document in the interface that this is Arm only.
Quoted 15 lines
xen/include/public/hvm/dm_op.h +10
-0+*/ +#define XEN_DMOP_set_irq_level 19 + +struct xen_dm_op_set_irq_level { +uint32_t irq; +/* IN - Level: 0 -> deasserted, 1 -> asserted */ +uint8_t level; +uint8_t pad[3 ]; +}; +struct xen_dm_op {uint32_t op;uint32_t pad;
xen/include/public/hvm/dm_op.h struct xen_dm_op { · line 450
Quoted 7 lines
xen/include/public/hvm/dm_op.h +1
-0@@ -430,6 +444,7 @@ struct xen_dm_op {struct xen_dm_op_track_dirty_vram track_dirty_vram;struct xen_dm_op_set_pci_intx_level set_pci_intx_level;struct xen_dm_op_set_isa_irq_level set_isa_irq_level; +struct xen_dm_op_set_irq_level set_irq_level;struct xen_dm_op_set_pci_link_route set_pci_link_route;struct xen_dm_op_modified_memory modified_memory;struct xen_dm_op_set_mem_type set_mem_type;
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 12/16] xen/dm: Introduce xendevicemodel_set_irq_level DM op
Quoted 3 lines · Julien Grall
(+ Paul and Andre)
Hi,
Hi Julien
Quoted 7 lines
Adding Paul as the author of DMOP and Andre as this is GIC related.
Quoted 1 line · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
Looking at the PoC I shared with you, this code was originally written by me.
I am sorry, will fix.
Quoted 9 lines
Quoted 7 lines
This patch adds ability to the device emulator to notify otherend (some entity running in the guest) using a SPI and implements Arm specific bits for it. Proposed interface allows emulator to set the logical level of a one of a domain's IRQ lines.
It would be good to explain in the commit message why we can't use the existing DMOP to inject an interrupt.
Agree, will explain why the existing DMOP to inject an interrupt is not suitable for us.
Quoted 82 lines
Quoted 82 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Please note, I left interface untouched since there is still an open discussion what interface to use/what information to pass to the hypervisor. The question whether we should abstract away the state of the line or not.
Changes RFC -> V1:
- check incoming parameters inarch_dm_op()
- add explicit padding to structxen_dm_op_set_irq_level
---
---
tools/libs/devicemodel/core.c | 18 +++++++++++++tools/libs/devicemodel/include/xendevicemodel.h| 4 +++ tools/libs/devicemodel/libxendevicemodel.map | 1 + xen/arch/arm/dm.c | 36
++++++++++++++++++++++++-
xen/common/dm.c | 1 + xen/include/public/hvm/dm_op.h | 15 +++++++++++6 files changed, 74 insertions(+), 1 deletion(-)tools/libs/devicemodel/core.c +0
-0@@ -430,6 +430,24 @@ int xendevicemodel_set_isa_irq_level( return xendevicemodel_op(dmod, domid, 1, &op, sizeof(op)); }+int xendevicemodel_set_irq_level(
+xendevicemodel_handle*dmod,domid_tdomid,uint32_tirq, + unsigned int level)tools/libs/devicemodel/core.c +15
-0+{ + struct xen_dm_op op; + struct xen_dm_op_set_irq_level *data; + + memset(&op, 0, sizeof(op)); + + op.op = XEN_DMOP_set_irq_level; + data = &op.u.set_irq_level; + + data->irq = irq; + data->level = level; + + return xendevicemodel_op(dmod, domid, 1, &op, sizeof(op)); +} +int xendevicemodel_set_pci_link_route(
xendevicemodel_handle*dmod,domid_tdomid,uint8_tlink,uint8_tirq) {tools/libs/devicemodel/include/xendevicemodel.h +0
-0@@ -209,6 +209,10 @@ int xendevicemodel_set_isa_irq_level( xendevicemodel_handle *dmod, domid_t domid, uint8_t irq, unsigned int level);+int xendevicemodel_set_irq_level(
+xendevicemodel_handle*dmod,domid_tdomid, unsigned int irq, + unsigned int level);
+
/**
* This function maps a PCI INTx line to a an IRQ line. *tools/libs/devicemodel/libxendevicemodel.map +0
-0@@ -32,6 +32,7 @@ VERS_1.2 {global:
xendevicemodel_relocate_memory;
xendevicemodel_pin_memory_cacheattr;
+xendevicemodel_set_irq_level;
} VERS_1.1;
VERS_1.3 {xen/arch/arm/dm.c +0
-0
Quoted 8 lines
xen/arch/arm/dm.c line 16
Quoted 6 lines
index eb20344..428ef98 100644
xen/arch/arm/dm.c +0
-0@@ -15,11 +15,45 @@*/ #include <xen/hypercall.h>NIT: newline between <xen/*> and <asm/*> includes.
ok
Quoted 23 lines
Quoted 23 lines
xen/arch/arm/dm.c +17
-1+#include <asm/vgic.h> int arch_dm_op(struct xen_dm_op *op, struct domain *d, const struct dmop_args *op_args, bool *const_op) { - return -EOPNOTSUPP; + int rc; + + switch ( op->op ) + { + case XEN_DMOP_set_irq_level: + { + const struct xen_dm_op_set_irq_level *data = + &op->u.set_irq_level; + + /* Only SPIs are supported */ + if ( (data->irq < NR_LOCAL_IRQS) || (data->irq >=vgic_num_irqs (d)) ) + { + rc = -EINVAL; + break; + } +
Quoted 8 lines
xen/arch/arm/dm.c line 44
Quoted 6 lines
xen/arch/arm/dm.c +6
-0+ if ( data->level != 0 && data->level != 1 ) + { + rc = -EINVAL; + break; + } +I think we want to check the padding is always 0.
ok
Quoted 7 lines
xen/arch/arm/dm.c line 45
Quoted 3 lines
xen/arch/arm/dm.c +2
-0+ + vgic_inject_irq(d, NULL, data->irq, data->level);So, this interface will allow the device emulator to raise/lower the line for an HW mapped interrupt. I think this will mess up with the internal state machine.
It would probably be better if a device emulator can only raise/lower the line for non-allocated interrupts (see
d->arch.vgic.allocated_irqs). Any thoughts?
I think, it really makes sense. Will add a corresponding check.
Quoted 40 lines
Quoted 33 lines
xen/arch/arm/dm.c +10
-0+ rc = 0; + break; + } + + default: + rc = -EOPNOTSUPP; + break; + } + + return rc; } /*xen/common/dm.c +1
-0@@ -47,6 +47,7 @@ static int dm_op(const struct dmop_args *op_args) [XEN_DMOP_remote_shutdown] = sizeof(struct xen_dm_op_remote_shutdown), [XEN_DMOP_relocate_memory] = sizeof(struct xen_dm_op_relocate_memory), [XEN_DMOP_pin_memory_cacheattr] = sizeof(struct xen_dm_op_pin_memory_cacheattr), + [XEN_DMOP_set_irq_level] = sizeof(structxen_dm_op_set_irq_level ), }; rc = rcu_lock_remote_domain_by_id(op_args->domid, &d);xen/include/public/hvm/dm_op.h +0
-0@@ -417,6 +417,20 @@ struct xen_dm_op_pin_memory_cacheattr { uint32_t pad; };Quoted 4 lines
+/*
+ *XEN_DMOP_set_irq_level: Set the logical level of a one of a domain's
+ * IRQ lines.
+ * XXX Handle PPIs.This is a public interface, so it seems a bit strange to leave a TODO in this code.
Quoted 5 lines
I wouldn't be surprised if someone will want PPI support soon, but we may be able to defer it if we can easily extend the hypercall.
@Paul, how did you envision to extend DMOP?
Also, is there any plan to add x86 support? If not, then I think we want to document in the interface that this is Arm only.
I don't have a plan to add x86 support. Will clarify that it is for ARM only.
Quoted 26 lines
Quoted 16 lines
+ */
xen/include/public/hvm/dm_op.h +9
-0+#define XEN_DMOP_set_irq_level 19 + +struct xen_dm_op_set_irq_level { + uint32_t irq; + /* IN - Level: 0 -> deasserted, 1 -> asserted */ + uint8_t level; + uint8_t pad[3]; +}; +struct
xen_dm_op{
uint32_top;
uint32_tpad;xen/include/public/hvm/dm_op.h struct xen_dm_op { · line 450
Quoted 7 lines
xen/include/public/hvm/dm_op.h +1
-0@@ -430,6 +444,7 @@ struct xen_dm_op { struct xen_dm_op_track_dirty_vram track_dirty_vram; struct xen_dm_op_set_pci_intx_level set_pci_intx_level; struct xen_dm_op_set_isa_irq_level set_isa_irq_level; + struct xen_dm_op_set_irq_level set_irq_level; struct xen_dm_op_set_pci_link_route set_pci_link_route; struct xen_dm_op_modified_memory modified_memory; struct xen_dm_op_set_mem_type set_mem_type;Cheers,
Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH 13/16 xen/ioreq: Make x86's invalidate qemu mapcache handling common
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
As the IOREQ is a common feature now and we also need to invalidate qemu mapcache on XENMEM_decrease_reservation on Arm this patch moves this handling to the common code and move per-domain qemu_mapcache_invalidate variable out of the arch sub-struct.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- move send_invalidate_req() to the common code
- update patch subject/description
- move qemu_mapcache_invalidate out of the arch sub-struct, update checks
- remove #if defined(CONFIG_ARM64) from the common code
---
--- xen/arch/arm/traps.c | 6 ++++++ xen/arch/x86/hvm/hypercall.c | 9 ++++----- xen/arch/x86/hvm/io.c | 14 -------------- xen/common/ioreq.c | 14 ++++++++++++++ xen/common/memory.c | 5 +++++ xen/include/asm-x86/hvm/domain.h | 1 - xen/include/asm-x86/hvm/io.h | 1 - xen/include/xen/ioreq.h | 2 ++ xen/include/xen/sched.h | 2 ++ 9 files changed, 33 insertions(+), 21 deletions(-)
xen/arch/arm/traps.c +6 -0
@@ -1490,6 +1490,12 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,/* Ensure the hypercall trap instruction is re-executed. */ if ( current->hcall_preempted ) regs->pc -=4 ;/* re-execute 'hvc #XEN_HYPERCALL_TAG' */ + +#ifdef CONFIG_IOREQ_SERVER +if (unlikely (current->domain->qemu_mapcache_invalidate) && +test_and_clear_bool (current->domain->qemu_mapcache_invalidate) ) +send_invalidate_req (); +#endif }void arch_hypercall_tasklet_result (struct vcpu *v,long res)
xen/arch/x86/hvm/hypercall.c +4 -5
@@ -18,8 +18,10 @@* * Copyright (c) 2017 Citrix Systems Ltd. */ +#include <xen/lib.h> #include <xen/hypercall.h> +#include <xen/ioreq.h> #include <xen/nospec.h> #include <asm/hvm/emulate.h>
@@ -46,9 +48,6 @@ static long hvm_memory_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)else rc =compat_memory_op (cmd, arg); -if ( (cmd &MEMOP_CMD_MASK ) == XENMEM_decrease_reservation ) - curr->domain->arch.hvm.qemu_mapcache_invalidate = true; -return rc; }
@@ -329,8 +328,8 @@ int hvm_hypercall(struct cpu_user_regs *regs)if ( curr->hcall_preempted )return HVM_HCALL_preempted; -if (unlikely (currd->arch.hvm.qemu_mapcache_invalidate) && -test_and_clear_bool (currd->arch.hvm.qemu_mapcache_invalidate) ) +if (unlikely (currd->qemu_mapcache_invalidate) && +test_and_clear_bool (currd->qemu_mapcache_invalidate) )send_invalidate_req ();return HVM_HCALL_completed;
xen/arch/x86/hvm/io.c +0 -14
@@ -64,20 +64,6 @@ void send_timeoffset_req(unsigned long timeoff)gprintk (XENLOG_ERR ,"Unsuccessful timeoffset update\n" ); } -/* Ask ioemu mapcache to invalidate mappings. */ -void send_invalidate_req (void ) -{ -ioreq_t p = { - .type =IOREQ_TYPE_INVALIDATE , - .size =4 , - .dir =IOREQ_WRITE , - .data = ~0UL ,/* flush all */ - }; - -if (hvm_broadcast_ioreq (&p, false) !=0 ) -gprintk (XENLOG_ERR ,"Unsuccessful map-cache invalidate\n" ); -} -bool hvm_emulate_one_insn (hvm_emulate_validate_t *validate,const char *descr) {struct hvm_emulate_ctxt ctxt;
xen/common/ioreq.c +14 -0
@@ -34,6 +34,20 @@#include <public/hvm/ioreq.h> #include <public/hvm/params.h> +/* Ask ioemu mapcache to invalidate mappings. */ +void send_invalidate_req (void ) +{ +ioreq_t p = { + .type =IOREQ_TYPE_INVALIDATE , + .size =4 , + .dir =IOREQ_WRITE , + .data = ~0UL ,/* flush all */ + }; + +if (hvm_broadcast_ioreq (&p, false) !=0 ) +gprintk (XENLOG_ERR ,"Unsuccessful map-cache invalidate\n" ); +} +static void set_ioreq_server (struct domain *d,unsigned int id,struct hvm_ioreq_server *s) {
xen/common/memory.c +5 -0
@@ -1651,6 +1651,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } +#ifdef CONFIG_IOREQ_SERVER +if ( op == XENMEM_decrease_reservation ) + curr_d->qemu_mapcache_invalidate = true; +#endif +return rc; }
xen/include/asm-x86/hvm/domain.h +0 -1
@@ -131,7 +131,6 @@ struct hvm_domain {struct viridian_domain *viridian; -bool_t qemu_mapcache_invalidate;bool_t is_s3_suspended;/*
xen/include/asm-x86/hvm/io.h +0 -1
@@ -97,7 +97,6 @@ bool relocate_portio_handler( unsigned int size);void send_timeoffset_req (unsigned long timeoff); -void send_invalidate_req (void );bool handle_mmio_with_translation (unsigned long gla,unsigned long gpfn,struct npfec );bool handle_pio (uint16_t port,unsigned int size,int dir);
xen/include/xen/ioreq.h +2 -0
@@ -97,6 +97,8 @@ static inline bool hvm_ioreq_needs_completion(const ioreq_t *ioreq) (ioreq->type !=IOREQ_TYPE_PIO || ioreq->dir !=IOREQ_WRITE ); } +void send_invalidate_req (void ); +bool hvm_io_pending (struct vcpu *v);bool handle_hvm_io_completion (struct vcpu *v);bool is_ioreq_server_page (struct domain *d,const struct page_info *page);
xen/include/xen/sched.h +2 -0
@@ -512,6 +512,8 @@ struct domain/* Argo interdomain communication support */ struct argo_domain *argo;#endif + +bool_t qemu_mapcache_invalidate; }; static inline struct page_list_head *page_to_list(
Signature · 1 line
2.7.4
Re: [PATCH V1 13/16] xen/ioreq: Make x86's invalidate qemu mapcache handling common
xen/arch/arm/traps.c static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, · line 1499
Quoted 13 lines · Oleksandr Tyshchenko
xen/arch/arm/traps.c +6
-0@@ -1490,6 +1490,12 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,/* Ensure the hypercall trap instruction is re-executed. */ if ( current->hcall_preempted ) regs->pc -=4 ;/* re-execute 'hvc #XEN_HYPERCALL_TAG' */ + +#ifdef CONFIG_IOREQ_SERVER +if (unlikely (current->domain->qemu_mapcache_invalidate) && +test_and_clear_bool (current->domain->qemu_mapcache_invalidate) ) +send_invalidate_req (); +#endif }
There's a lot of uses of "current" here now, and these don't look to exactly be cheap on Arm either (they aren't on x86), so I wonder whether this is the point where at least "current" wants latching into a local variable here.
xen/arch/x86/hvm/hypercall.c line 25
Quoted 11 lines
xen/arch/x86/hvm/hypercall.c +2
-0@@ -18,8 +18,10 @@* * Copyright (c) 2017 Citrix Systems Ltd. */ +#include <xen/lib.h> #include <xen/hypercall.h> +#include <xen/ioreq.h> #include <xen/nospec.h>
While I don't care much about the presence of absence of the blank line between head comment and #include-s, I don't see why you add one here.
xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1657
Quoted 10 lines
xen/common/memory.c +4
-0@@ -1651,6 +1651,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } +#ifdef CONFIG_IOREQ_SERVER +if ( op == XENMEM_decrease_reservation ) + curr_d->qemu_mapcache_invalidate = true; +#endif
I don't see why you put this right into decrease_reservation(). This isn't just to avoid the extra conditional, but first and foremost to avoid bypassing the earlier return from the function (in the case of preemption). In the context of this I wonder whether the ordering of operations in hvm_hypercall() is actually correct.
I'm also unconvinced curr_d is the right domain in all cases here; while this may be a pre-existing issue in principle, I'm afraid it gets more pronounced by the logic getting moved to common code. Roger - thoughts either way with, in particular, PVH Dom0 in mind?
xen/include/xen/ioreq.h static inline bool hvm_ioreq_needs_completion(const ioreq_t *ioreq) · line 100
Quoted 7 lines
xen/include/xen/ioreq.h +1
-0@@ -97,6 +97,8 @@ static inline bool hvm_ioreq_needs_completion(const ioreq_t *ioreq) (ioreq->type !=IOREQ_TYPE_PIO || ioreq->dir !=IOREQ_WRITE ); } +void send_invalidate_req (void );
Perhaps rename to ioreq_send_invalidate(), ioreq_send_invalidate_req(), or send_invalidate_ioreq() at this occasion?
xen/include/xen/sched.h struct domain · line 516
Quoted 8 lines
xen/include/xen/sched.h +2
-0@@ -512,6 +512,8 @@ struct domain/* Argo interdomain communication support */ struct argo_domain *argo;#endif + +bool_t qemu_mapcache_invalidate;
"bool" please.
Jan
Re: [PATCH V1 13/16] xen/ioreq: Make x86's invalidate qemu mapcache handling common
On 16.09.20 11:50, Jan Beulich wrote:
Hi Jan, Roger
Quoted 10 lines · Oleksandr Tyshchenko
Quoted 9 lines
xen/arch/arm/traps.c +3
-0@@ -1490,6 +1490,12 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,/* Ensure the hypercall trap instruction is re-executed. */ if ( current->hcall_preempted ) regs->pc -=4 ;/* re-execute 'hvc #XEN_HYPERCALL_TAG' */ + +#ifdef CONFIG_IOREQ_SERVER + if ( unlikely(current->domain->qemu_mapcache_invalidate) &&
Quoted 8 lines
xen/arch/arm/traps.c static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, · line 1499
Quoted 4 lines
xen/arch/arm/traps.c +3
-0+ test_and_clear_bool(current->domain->qemu_mapcache_invalidate) ) +send_invalidate_req (); +#endif }There's a lot of uses of "current" here now, and these don't look to exactly be cheap on Arm either (they aren't on x86), so I wonder whether this is the point where at least "current" wants latching into a local variable here.
Sounds reasonable, will use local variable
Quoted 15 lines
xen/arch/x86/hvm/hypercall.c line 25
Quoted 12 lines
xen/arch/x86/hvm/hypercall.c +2
-0@@ -18,8 +18,10 @@* * Copyright (c) 2017 Citrix Systems Ltd. */ +#include <xen/lib.h> #include <xen/hypercall.h> +#include <xen/ioreq.h> #include <xen/nospec.h> While I don't care much about the presence of absence of the blank line between head comment and #include-s, I don't see why you add one here.
Accidentally), will remove.
Quoted 7 lines
Quoted 7 lines
xen/common/memory.c +0
-0@@ -1651,6 +1651,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; }
Quoted 9 lines
xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1657
Quoted 4 lines
xen/common/memory.c +4
-0+#ifdef CONFIG_IOREQ_SERVER +if ( op == XENMEM_decrease_reservation ) + curr_d->qemu_mapcache_invalidate = true; +#endif I don't see why you put this right into
decrease_reservation(). This isn't just to avoid the extra conditional, but first and foremost to avoid bypassing the earlier return from the function (in the case of preemption). In the context of this I wonder whether the ordering of operations inhvm_hypercall()is actually correct.
Good point, indeed we may return earlier in case of preemption, I missed that.
Will move it to decrease_reservation(). But, we may return even earlier in case of error...
Now I am wondering should we move it to the very beginning of command processing or not?
AFAIU before this patch qemu_mapcache_invalidate was always set in hvm_memory_op() if XENMEM_decrease_reservation came despite of possible errors in the command processing.
Quoted 3 lines
I'm also unconvinced
curr_dis the right domain in all cases here; while this may be a pre-existing issue in principle, I'm afraid it gets more pronounced by the logic getting moved to common code.
Sorry I didn't get your concern here.
Quoted 11 lines
Roger - thoughts either way with, in particular, PVH Dom0 in mind?
xen/include/xen/ioreq.h static inline bool hvm_ioreq_needs_completion(const ioreq_t *ioreq) · line 100
Quoted 7 lines
xen/include/xen/ioreq.h +1
-0@@ -97,6 +97,8 @@ static inline bool hvm_ioreq_needs_completion(const ioreq_t *ioreq) (ioreq->type !=IOREQ_TYPE_PIO || ioreq->dir !=IOREQ_WRITE ); } +void send_invalidate_req (void );Perhaps rename to
ioreq_send_invalidate(),ioreq_send_invalidate_req(), orsend_invalidate_ioreq()at this occasion?
I would prefer function with ioreq_ prefix.
Quoted 10 lines
xen/include/xen/sched.h struct domain · line 516
Quoted 9 lines
xen/include/xen/sched.h +2
-0@@ -512,6 +512,8 @@ struct domain/* Argo interdomain communication support */ struct argo_domain *argo;#endif + +bool_t qemu_mapcache_invalidate;"bool" please.
ok
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 13/16] xen/ioreq: Make x86's invalidate qemu mapcache handling common
Quoted 17 lines · Oleksandr
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Oleksandr Tyshchenko
xen/common/memory.c +0
-0@@ -1651,6 +1651,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; }Quoted 9 lines
xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1657
Quoted 4 lines
xen/common/memory.c +4
-0+#ifdef CONFIG_IOREQ_SERVER +if ( op == XENMEM_decrease_reservation ) + curr_d->qemu_mapcache_invalidate = true; +#endif I don't see why you put this right into
decrease_reservation(). This isn't just to avoid the extra conditional, but first and foremost to avoid bypassing the earlier return from the function (in the case of preemption). In the context of this I wonder whether the ordering of operations inhvm_hypercall()is actually correct.
Quoted 6 lines
Good point, indeed we may return earlier in case of preemption, I missed that.
Will move it todecrease_reservation(). But, we may return even earlier in case of error...
Now I am wondering should we move it to the very beginning of command processing or not?
In _this_ series I'd strongly recommend you keep things working as they are. If independently you think you've found a reason to re-order certain operations, then feel free to send a patch with suitable justification.
Quoted 5 lines
Quoted 3 lines
I'm also unconvinced
curr_dis the right domain in all cases here; while this may be a pre-existing issue in principle, I'm afraid it gets more pronounced by the logic getting moved to common code.Sorry I didn't get your concern here.
Well, you need to be concerned whose qemu_mapcache_invalidate flag you set.
Jan
Re: [PATCH V1 13/16] xen/ioreq: Make x86's invalidate qemu mapcache handling common
On 24.09.20 14:16, Jan Beulich wrote:
Hi Jan
Quoted 24 lines · Oleksandr
Quoted 17 lines · Jan Beulich
Quoted 7 lines · Oleksandr Tyshchenko
Quoted 6 lines
xen/common/memory.c +0
-0@@ -1651,6 +1651,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; }Quoted 9 lines
xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1657
Quoted 4 lines
xen/common/memory.c +4
-0+#ifdef CONFIG_IOREQ_SERVER +if ( op == XENMEM_decrease_reservation ) + curr_d->qemu_mapcache_invalidate = true; +#endif I don't see why you put this right into
decrease_reservation(). This isn't just to avoid the extra conditional, but first and foremost to avoid bypassing the earlier return from the function (in the case of preemption). In the context of this I wonder whether the ordering of operations inhvm_hypercall()is actually correct.Quoted 6 lines
Good point, indeed we may return earlier in case of preemption, I missed that.
Will move it todecrease_reservation(). But, we may return even earlier in case of error...
Now I am wondering should we move it to the very beginning of command processing or not?
Quoted 4 lines
In _this_ series I'd strongly recommend you keep things working as they are. If independently you think you've found a reason to re-order certain operations, then feel free to send a patch with suitable justification.
Of course, I will try to retain current behavior.
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
I'm also unconvinced
curr_dis the right domain in all cases here; while this may be a pre-existing issue in principle, I'm afraid it gets more pronounced by the logic getting moved to common code.Sorry I didn't get your concern here.
Well, you need to be concerned whose
qemu_mapcache_invalidateflag you set.
May I ask, in what cases the *curr_d* is the right domain?
We need to make sure that domain is using IOREQ server(s) at least. Hopefully, we have a helper for this which is hvm_domain_has_ioreq_server(). Please clarify, anything else I should taking care of?
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 13/16] xen/ioreq: Make x86's invalidate qemu mapcache handling common
Quoted 37 lines · Oleksandr
On 24.09.20 14:16, Jan Beulich wrote:
Hi Jan
Quoted 24 lines · Oleksandr
Quoted 17 lines · Jan Beulich
Quoted 7 lines · Oleksandr Tyshchenko
Quoted 6 lines
xen/common/memory.c +0
-0@@ -1651,6 +1651,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; }Quoted 9 lines
xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1657
Quoted 4 lines
xen/common/memory.c +4
-0+#ifdef CONFIG_IOREQ_SERVER +if ( op == XENMEM_decrease_reservation ) + curr_d->qemu_mapcache_invalidate = true; +#endif I don't see why you put this right into
decrease_reservation(). This isn't just to avoid the extra conditional, but first and foremost to avoid bypassing the earlier return from the function (in the case of preemption). In the context of this I wonder whether the ordering of operations inhvm_hypercall()is actually correct.Quoted 6 lines
Good point, indeed we may return earlier in case of preemption, I missed that.
Will move it todecrease_reservation(). But, we may return even earlier in case of error...
Now I am wondering should we move it to the very beginning of command processing or not?Quoted 4 lines
In _this_ series I'd strongly recommend you keep things working as they are. If independently you think you've found a reason to re-order certain operations, then feel free to send a patch with suitable justification.
Of course, I will try to retain current behavior.
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
I'm also unconvinced
curr_dis the right domain in all cases here; while this may be a pre-existing issue in principle, I'm afraid it gets more pronounced by the logic getting moved to common code.Sorry I didn't get your concern here.
Well, you need to be concerned whose
qemu_mapcache_invalidateflag you set.May I ask, in what cases the *curr_d* is the right domain?
When a domain does a decrease-reservation on itself. I thought that's obvious. But perhaps your question was rather meant a to whether a->domain ever is _not_ the right one?
Quoted 4 lines
We need to make sure that domain is using IOREQ server(s) at least. Hopefully, we have a helper for this
which ishvm_domain_has_ioreq_server(). Please clarify, anything else I should taking care of?
Nothing I can recall / think of right now, except that the change may want to come under a different title and with a different description. As indicated, I don't think this is correct for PVH Dom0 issuing the request against a HVM DomU, and addressing this will likely want this moved out of hvm_memory_op() anyway. Of course an option is to split this into two patches - the proposed bug fix (perhaps wanting backporting) and then the moving of the field out of arch.hvm. If you feel uneasy about the bug fix part, let me know and I (or maybe Roger) will see to put together a patch.
Jan
Re: [PATCH V1 13/16] xen/ioreq: Make x86's invalidate qemu mapcache handling common
On 25.09.20 10:03, Jan Beulich wrote:
Hi Jan.
Quoted 39 lines · Oleksandr
Quoted 38 lines · Jan Beulich
Hi Jan
Quoted 24 lines · Oleksandr
Quoted 17 lines · Jan Beulich
Quoted 7 lines · Oleksandr Tyshchenko
Quoted 6 lines
xen/common/memory.c +0
-0@@ -1651,6 +1651,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; }Quoted 9 lines
xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1657
Quoted 4 lines
xen/common/memory.c +4
-0+#ifdef CONFIG_IOREQ_SERVER +if ( op == XENMEM_decrease_reservation ) + curr_d->qemu_mapcache_invalidate = true; +#endif I don't see why you put this right into
decrease_reservation(). This isn't just to avoid the extra conditional, but first and foremost to avoid bypassing the earlier return from the function (in the case of preemption). In the context of this I wonder whether the ordering of operations inhvm_hypercall()is actually correct.Quoted 6 lines
Good point, indeed we may return earlier in case of preemption, I missed that.
Will move it todecrease_reservation(). But, we may return even earlier in case of error...
Now I am wondering should we move it to the very beginning of command processing or not?Quoted 4 lines
In _this_ series I'd strongly recommend you keep things working as they are. If independently you think you've found a reason to re-order certain operations, then feel free to send a patch with suitable justification.
Of course, I will try to retain current behavior.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
I'm also unconvinced
curr_dis the right domain in all cases here; while this may be a pre-existing issue in principle, I'm afraid it gets more pronounced by the logic getting moved to common code.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Sorry I didn't get your concern here.
Well, you need to be concerned whose
qemu_mapcache_invalidateflag you set.May I ask, in what cases the *curr_d* is the right domain?
When a domain does a decrease-reservation on itself. I thought that's obvious. But perhaps your question was rather meant a to whether
a->domainever is _not_ the right one?
No, my question was about *curr_d*. I saw your answer
Quoted 1 line
I'm also unconvinced
curr_dis the right domain in all cases here;
and just wanted to clarify these cases. Sorry if I was unclear.
Quoted 5 lines
Quoted 5 lines
We need to make sure that domain is using IOREQ server(s) at least. Hopefully, we have a helper for this
which ishvm_domain_has_ioreq_server(). Please clarify, anything else I should taking care of?
Quoted 10 lines
Nothing I can recall / think of right now, except that the change may want to come under a different title and with a different description.As indicated, I don't think this is correct for PVH Dom0 issuing the request against a HVM DomU, and addressing this will likely want this moved out of
hvm_memory_op()anyway. Of course an option is to split this into two patches - the proposed bug fix (perhaps wanting backporting) and then the moving of the field out of arch.hvm. If you feel uneasy about the bug fix part, let me know and I (or maybe Roger) will see to put together a patch.
Thank you for the clarification.
Yes, it would be really nice if you (or maybe Roger) could create a patch for the bug fix part.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 13/16] xen/ioreq: Make x86's invalidate qemu mapcache handling common
Hi Jan
Quoted 72 lines · Oleksandr
On 25.09.20 10:03, Jan Beulich wrote:
Hi Jan.
Quoted 39 lines · Oleksandr
Quoted 38 lines · Jan Beulich
Hi Jan
Quoted 24 lines · Oleksandr
Quoted 17 lines · Jan Beulich
Quoted 8 lines · Oleksandr Tyshchenko
Quoted 7 lines
xen/common/memory.c +0
-0@@ -1651,6 +1651,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) break; }+#ifdef
CONFIG_IOREQ_SERVERQuoted 8 lines
Quoted 3 lines
+ if ( op ==
XENMEM_decrease_reservation)
+curr_d->qemu_mapcache_invalidate= true;
+#endifI don't see why you put this right into
decrease_reservation(). This isn't just to avoid the extra conditional, but first and foremost to avoid bypassing the earlier return from the function (in the case of preemption). In the context of this I wonder whether the ordering of operations inhvm_hypercall()is actually correct.Quoted 6 lines
Good point, indeed we may return earlier in case of preemption, I missed that.
Will move it todecrease_reservation(). But, we may return even earlier in case of error...
Now I am wondering should we move it to the very beginning of command processing or not?Quoted 4 lines
In _this_ series I'd strongly recommend you keep things working as they are. If independently you think you've found a reason to re-order certain operations, then feel free to send a patch with suitable justification.
Of course, I will try to retain current behavior.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
I'm also unconvinced
curr_dis the right domain in all cases here; while this may be a pre-existing issue in principle, I'm afraid it gets more pronounced by the logic getting moved to common code.Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Sorry I didn't get your concern here.
Well, you need to be concerned whose
qemu_mapcache_invalidateflag you set.May I ask, in what cases the *curr_d* is the right domain?
When a domain does a decrease-reservation on itself. I thought that's obvious. But perhaps your question was rather meant a to whether
a->domainever is _not_ the right one?No, my question was about *curr_d*. I saw your answer
Quoted 1 line
I'm also unconvinced
curr_dis the right domain in all cases here;and just wanted to clarify these cases. Sorry if I was unclear.
Quoted 5 lines
Quoted 5 lines
We need to make sure that domain is using IOREQ server(s) at least. Hopefully, we have a helper for this
which ishvm_domain_has_ioreq_server(). Please clarify, anything else I should taking care of?Quoted 10 lines
Nothing I can recall / think of right now, except that the change may want to come under a different title and with a different description.As indicated, I don't think this is correct for PVH Dom0 issuing the request against a HVM DomU, and addressing this will likely want this moved out of
hvm_memory_op()anyway. Of course an option is to split this into two patches - the proposed bug fix (perhaps wanting backporting) and then the moving of the field out of arch.hvm. If you feel uneasy about the bug fix part, let me know and I (or maybe Roger) will see to put together a patch.
Quoted 3 lines
Thank you for the clarification.
Yes, it would be really nice if you (or maybe Roger) could create a patch for the bug fix part.
Thank you for your patch [1].
If I got it correctly there won't be a suitable common place where to set qemu_mapcache_invalidate flag anymore as XENMEM_decrease_reservation is not a single place we need to make a decision whether to set it
By principle of analogy, on Arm we probably want to do so in guest_physmap_remove_page (or maybe better in p2m_remove_mapping). Julien, what do you think?
I will modify current patch to not alter the common code.
[1] https://patchwork.kernel.org/patch/11803383/
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 13/16] xen/ioreq: Make x86's invalidate qemu mapcache handling common
Hi Oleksandr,
Quoted 4 lines · Oleksandr
If I got it correctly there won't be a suitable common place where to set
qemu_mapcache_invalidateflag anymore asXENMEM_decrease_reservationis not a single place we need to make a decision whether to set it
By principle of analogy, on Arm we probably want to do so inguest_physmap_remove_page(or maybe better inp2m_remove_mapping). Julien, what do you think?
At the moment, the Arm code doesn't explicitely remove the existing mapping before inserting the new mapping. Instead, this is done implicitely by p2m_set_entry().
So I think we want to invalidate the QEMU mapcache in p2m_set_entry() if the old entry is a RAM page *and* the new MFN is different.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 13/16] xen/ioreq: Make x86's invalidate qemu mapcache handling common
Quoted 1 line · Julien Grall
Hi Oleksandr,
Hi Julien.
Quoted 8 lines · Oleksandr
Quoted 4 lines
If I got it correctly there won't be a suitable common place where to set
qemu_mapcache_invalidateflag anymore asXENMEM_decrease_reservationis not a single place we need to make a decision whether to set it
By principle of analogy, on Arm we probably want to do so inguest_physmap_remove_page(or maybe better inp2m_remove_mapping). Julien, what do you think?At the moment, the Arm code doesn't explicitely remove the existing mapping before inserting the new mapping. Instead, this is done implicitely by
p2m_set_entry().
Got it.
Quoted 3 lines
So I think we want to invalidate the QEMU mapcache in
p2m_set_entry()if the old entry is a RAM page *and* the new MFN is different.
Thank you. I hope, the following is close to what was suggested (didn't test yet):
xen/arch/arm/p2m.c +0 -0
@@ -1073,7 +1073,14 @@ static int __p2m_set_entry(struct p2m_domain *p2m,
*/
if ( p2m_is_valid(orig_pte) &&
!mfn_eq(lpae_get_mfn(*entry), lpae_get_mfn(orig_pte)) )
+ {
+#ifdef CONFIG_IOREQ_SERVER
+ if ( domain_has_ioreq_server(p2m->domain) &&
+ (p2m->domain == current->domain) && p2m_is_ram(orig_pte.p2m.type) ) + p2m->domain->qemu_mapcache_invalidate = true;
+#endif
p2m_free_entry(p2m, orig_pte, level);
+ }
out:
unmap_domain_page(table);
But, if I got the review comments correctly [1], the qemu_mapcache_invalidate variable should be per-vcpu instead of per-domain?
[1] https://patchwork.kernel.org/patch/11803383/
Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH 14/16 xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
The cmpxchg() in hvm_send_buffered_ioreq() operates on memory shared with the emulator. In order to be on the safe side we need to switch to guest_cmpxchg64() to prevent a domain to DoS Xen on Arm.
---
Please note, this patch depends on the following patch on a review:
https://patchwork.kernel.org/patch/11715559/
Changes RFC -> V1:
- new patch
---
--- xen/common/ioreq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
xen/common/ioreq.c +3 -1
@@ -30,6 +30,8 @@#include <xen/trace.h> #include <xen/vpci.h> +#include <asm/guest_atomics.h> +#include <public/hvm/dm_op.h> #include <public/hvm/ioreq.h> #include <public/hvm/params.h>
@@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) new.read_pointer = old.read_pointer - n *IOREQ_BUFFER_SLOT_NUM ; new.write_pointer = old.write_pointer - n *IOREQ_BUFFER_SLOT_NUM ; -cmpxchg (&pg->ptrs.full, old.full, new.full); +guest_cmpxchg64 (d, &pg->ptrs.full, old.full, new.full); }notify_via_xen_event_channel (d, s->bufioreq_evtchn);
Signature · 1 line
2.7.4
Re: [PATCH V1 14/16] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
xen/common/ioreq.c static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) · line 1330
Quoted 6 lines · Oleksandr Tyshchenko
xen/common/ioreq.c +1
-1@@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) new.read_pointer = old.read_pointer - n *IOREQ_BUFFER_SLOT_NUM ; new.write_pointer = old.write_pointer - n *IOREQ_BUFFER_SLOT_NUM ; -cmpxchg (&pg->ptrs.full, old.full, new.full); +guest_cmpxchg64 (d, &pg->ptrs.full, old.full, new.full);
But the memory we're updating is shared with s->emulator, not with d, if I'm not mistaken.
Jan
Re: [PATCH V1 14/16] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
Quoted 10 lines · Jan Beulich
xen/common/ioreq.c static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) · line 1330
Quoted 6 lines · Oleksandr Tyshchenko
xen/common/ioreq.c +1
-1@@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) new.read_pointer = old.read_pointer - n *IOREQ_BUFFER_SLOT_NUM ; new.write_pointer = old.write_pointer - n *IOREQ_BUFFER_SLOT_NUM ; -cmpxchg (&pg->ptrs.full, old.full, new.full); +guest_cmpxchg64 (d, &pg->ptrs.full, old.full, new.full);But the memory we're updating is shared with
s->emulator, not with d, if I'm not mistaken.
It is unfortunately shared with both s->emulator and d when using the legacy interface.
For Arm, there is no plan to support the legacy interface, so we should s->emulator and we should be fully protected.
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH V1 14/16] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
Quoted 22 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 16 September 2020 10:07
To: Jan Beulich <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Cc: [email protected]; Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 14/16] xen/ioreq: Useguest_cmpxchg64()instead ofcmpxchg()Quoted 10 lines · Jan Beulich
xen/common/ioreq.c static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) · line 1330
Quoted 6 lines · Oleksandr Tyshchenko
xen/common/ioreq.c +1
-1@@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) new.read_pointer = old.read_pointer - n *IOREQ_BUFFER_SLOT_NUM ; new.write_pointer = old.write_pointer - n *IOREQ_BUFFER_SLOT_NUM ; -cmpxchg (&pg->ptrs.full, old.full, new.full); +guest_cmpxchg64 (d, &pg->ptrs.full, old.full, new.full);But the memory we're updating is shared with
s->emulator, not with d, if I'm not mistaken.
Quoted 2 lines
It is unfortunately shared with both
s->emulatorand d when using the legacy interface.
When using magic pages they should be punched out of the P2M by the time the code gets here, so the memory should not be guest-visible.
Paul
Quoted 8 lines
For Arm, there is no plan to support the legacy interface, so we should
s->emulatorand we should be fully protected.Cheers,
--
Julien Grall
Re: [PATCH V1 14/16] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
Quoted 22 lines · Paul Durrant
Quoted 22 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 16 September 2020 10:07
To: Jan Beulich <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Cc: [email protected]; Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 14/16] xen/ioreq: Useguest_cmpxchg64()instead ofcmpxchg()Quoted 10 lines · Jan Beulich
xen/common/ioreq.c static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) · line 1330
Quoted 6 lines · Oleksandr Tyshchenko
xen/common/ioreq.c +1
-1@@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) new.read_pointer = old.read_pointer - n *IOREQ_BUFFER_SLOT_NUM ; new.write_pointer = old.write_pointer - n *IOREQ_BUFFER_SLOT_NUM ; -cmpxchg (&pg->ptrs.full, old.full, new.full); +guest_cmpxchg64 (d, &pg->ptrs.full, old.full, new.full);But the memory we're updating is shared with
s->emulator, not with d, if I'm not mistaken.
Quoted 4 lines
Quoted 2 lines
It is unfortunately shared with both
s->emulatorand d when using the legacy interface.When using magic pages they should be punched out of the P2M by the time the code gets here, so the memory should not be guest-visible.
Can you point me to the code that doing this?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 14/16] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
On 16.09.20 12:12, Julien Grall wrote:
Hi all.
Quoted 26 lines · Paul Durrant
Quoted 23 lines
Quoted 23 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 16 September 2020 10:07
To: Jan Beulich <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Cc: [email protected]; Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 14/16] xen/ioreq: Useguest_cmpxchg64()instead ofcmpxchg()Quoted 11 lines · Jan Beulich
xen/common/ioreq.c static int hvm_send_buffered_ioreq(struct · line 1331
Quoted 7 lines · Oleksandr Tyshchenko
xen/common/ioreq.c +1
-1@@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) new.read_pointer = old.read_pointer - n * IOREQ_BUFFER_SLOT_NUM; new.write_pointer = old.write_pointer - n * IOREQ_BUFFER_SLOT_NUM; - cmpxchg(&pg->ptrs.full, old.full, new.full); + guest_cmpxchg64(d, &pg->ptrs.full, old.full, new.full);But the memory we're updating is shared with
s->emulator, not with d, if I'm not mistaken.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
It is unfortunately shared with both
s->emulatorand d when using the legacy interface.When using magic pages they should be punched out of the P2M by the time the code gets here, so the memory should not be guest-visible.
Can you point me to the code that doing this?
Cheers,
If we are not going to use legacy interface on Arm we will have a page to be mapped in a single domain at the time.
I will update patch to use "s->emulator" if no objections.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V1 14/16] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
Quoted 34 lines · Oleksandr
On 16.09.20 12:12, Julien Grall wrote:
Hi all.
Quoted 29 lines · Paul Durrant
Quoted 26 lines
Quoted 25 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 16 September 2020 10:07
To: Jan Beulich <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Cc: [email protected]; Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 14/16] xen/ioreq: Useguest_cmpxchg64()instead ofcmpxchg()Quoted 11 lines · Jan Beulich
xen/common/ioreq.c static int hvm_send_buffered_ioreq(struct · line 1331
Quoted 7 lines · Oleksandr Tyshchenko
xen/common/ioreq.c +1
-1@@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) new.read_pointer = old.read_pointer - n * IOREQ_BUFFER_SLOT_NUM; new.write_pointer = old.write_pointer - n * IOREQ_BUFFER_SLOT_NUM; - cmpxchg(&pg->ptrs.full, old.full, new.full); + guest_cmpxchg64(d, &pg->ptrs.full, old.full, new.full);But the memory we're updating is shared with
s->emulator, not with d, if I'm not mistaken.It is unfortunately shared with both
s->emulatorand d when using the legacy interface.
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
When using magic pages they should be punched out of the P2M by the time the code gets here, so the memory should not be guest-visible.
Can you point me to the code that doing this?
Cheers,
If we are not going to use legacy interface on Arm we will have a page to be mapped in a single domain at the time.
Right, but this is common code... You have to think what would be the implication if we are using the legacy interface.
Thankfully the only user of the legacy interface is x86 so far and there is not concern regarding the atomics operations.
If we are happy to consider that the legacy interface will never be used (I am starting to be worry that one will ask it on Arm...) then we should be fine.
I think would be worth documenting in the commit message and the code (hvm_allow_set_param()) that the legacy interface *must* not be used without revisiting the code.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V1 14/16] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
On 23.09.20 21:12, Julien Grall wrote:
Hi Julien
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines · Jan Beulich
Quoted 11 lines · Oleksandr Tyshchenko
Review static int hvm_send_buffered_ioreq(struct · line 1331
Quoted 7 lines
(quoted diff) +1
-1@@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) new.read_pointer = old.read_pointer - n * IOREQ_BUFFER_SLOT_NUM; new.write_pointer = old.write_pointer - n * IOREQ_BUFFER_SLOT_NUM; - cmpxchg(&pg->ptrs.full, old.full, new.full); + guest_cmpxchg64(d, &pg->ptrs.full, old.full, new.full);But the memory we're updating is shared with
s->emulator, not with d, if I'm not mistaken.Quoted 4 lines
Quoted 2 lines
It is unfortunately shared with both
s->emulatorand d when using the legacy interface.When using magic pages they should be punched out of the P2M by the time the code gets here, so the memory should not be guest-visible.
Can you point me to the code that doing this?
Cheers,
Quoted 8 lines
Quoted 1 line
If we are not going to use legacy interface on Arm we will have a page to be mapped in a single domain at the time.
Right, but this is common code... You have to think what would be the implication if we are using the legacy interface.
Thankfully the only user of the legacy interface is x86 so far and there is not concern regarding the atomics operations.
If we are happy to consider that the legacy interface will never be used (I am starting to be worry that one will ask it on Arm...) then we should be fine.
I think would be worth documenting in the commit message and the code (
hvm_allow_set_param()) that the legacy interface *must* not be used without revisiting the code.
Will do.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
RE: [PATCH V1 14/16] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
In reply to Jan BeulichQuoted 12 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 16 September 2020 10:04
To: Oleksandr Tyshchenko <[email protected]>
Cc: [email protected]; Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [PATCH V1 14/16] xen/ioreq: Useguest_cmpxchg64()instead ofcmpxchg()Quoted 2 lines · Oleksandr Tyshchenko
(quoted diff) +0
-0@@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)
Quoted 8 lines
xen/common/ioreq.c static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) · line 1330
Quoted 4 lines
xen/common/ioreq.c +1
-1new.read_pointer = old.read_pointer - n *IOREQ_BUFFER_SLOT_NUM ; new.write_pointer = old.write_pointer - n *IOREQ_BUFFER_SLOT_NUM ; -cmpxchg (&pg->ptrs.full, old.full, new.full); +guest_cmpxchg64 (d, &pg->ptrs.full, old.full, new.full);But the memory we're updating is shared with
s->emulator, not with d, if I'm not mistaken.
You're not mistaken.
Paul
Quoted 1 line
Jan
Re: [PATCH V1 14/16] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()
In reply to Oleksandr TyshchenkoHi Oleksandr,
Quoted 8 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
The
cmpxchg()inhvm_send_buffered_ioreq()operates on memory shared with the emulator. In order to be on the safe side we need to switch toguest_cmpxchg64()to prevent a domain to DoS Xen on Arm.CC Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>
For bisection purpose, we need this series to at least build at every patch. It is fine if the IOREQ feature doesn't work.
So this patch wants to be earlier in the series to avoid breaking arm32 compilation.
Quoted 35 lines
---
Please note, this patch depends on the following patch on a review:
https://patchwork.kernel.org/patch/11715559/Changes RFC -> V1:
- new patch
------ xen/common/ioreq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/common/ioreq.c +3
-1@@ -30,6 +30,8 @@#include <xen/trace.h> #include <xen/vpci.h> +#include <asm/guest_atomics.h> +#include <public/hvm/dm_op.h> #include <public/hvm/ioreq.h> #include <public/hvm/params.h> @@ -1325,7 +1327,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p) new.read_pointer = old.read_pointer - n *IOREQ_BUFFER_SLOT_NUM ; new.write_pointer = old.write_pointer - n *IOREQ_BUFFER_SLOT_NUM ; -cmpxchg (&pg->ptrs.full, old.full, new.full); +guest_cmpxchg64 (d, &pg->ptrs.full, old.full, new.full); }notify_via_xen_event_channel (d, s->bufioreq_evtchn);
Signature · 1 line
Julien Grall
PATCH 15/16 libxl: Introduce basic virtio-mmio support on Arm
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
This patch creates specific device node in the Guest device-tree with allocated MMIO range and SPI interrupt if specific 'virtio' property is present in domain config.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- was squashed with:
"[RFC PATCH V1 09/12] libxl: Handle virtio-mmio irq in more correct way" "[RFC PATCH V1 11/12] libxl: Insert "dma-coherent" property into virtio-mmio device node" "[RFC PATCH V1 12/12] libxl: Fix duplicate memory node in DT"
- move VirtIO MMIO #define-s to xen/include/public/arch-arm.h
---
--- tools/libxl/libxl_arm.c | 58 +++++++++++++++++++++++++++++++++++++++++-- tools/libxl/libxl_types.idl | 1 + tools/xl/xl_parse.c | 1 + xen/include/public/arch-arm.h | 5 ++++ 4 files changed, 63 insertions(+), 2 deletions(-)
tools/libxl/libxl_arm.c +56 -2
@@ -27,8 +27,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, {uint32_t nr_spis =0 ;unsigned int i; -uint32_t vuart_irq; -bool vuart_enabled = false; +uint32_t vuart_irq, virtio_irq; +bool vuart_enabled = false, virtio_enabled = false;/* * If pl011 vuart is enabled then increment the nr_spis to allow allocation
@@ -40,6 +40,17 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, vuart_enabled = true; } +/* +* XXX: Handle properly virtio +* A proper solution would be the toolstack to allocate the interrupts +* used by each virtio backend and let the backend now which one is used +*/ +if (libxl_defbool_val (d_config->b_info.arch_arm.virtio)) { + nr_spis += (GUEST_VIRTIO_MMIO_SPI -32 ) +1 ; + virtio_irq =GUEST_VIRTIO_MMIO_SPI ; + virtio_enabled = true; + } +for (i =0 ; i < d_config->b_info.num_irqs; i++) {uint32_t irq = d_config->b_info.irqs[i];uint32_t spi;
@@ -59,6 +70,12 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,return ERROR_FAIL ; } +/* The same check as for vpl011 */ +if (virtio_enabled && irq == virtio_irq) { +LOG (ERROR ,"Physical IRQ %u conflicting with virtio SPI\n" , irq); +return ERROR_FAIL ; + } +if (irq <32 )continue ;
@@ -659,6 +676,39 @@ static int make_vpl011_uart_node(libxl__gc *gc, void *fdt,return 0 ; } +static int make_virtio_mmio_node (libxl__gc *gc,void *fdt, +uint64_t base,uint32_t irq) +{ +int res; +gic_interrupt intr; +/* Placeholder for virtio@ + a 64-bit number + \0 */ +char buf[24 ]; + +snprintf (buf,sizeof (buf),"virtio@%" PRIx64, base); + res =fdt_begin_node (fdt, buf); +if (res)return res; + + res =fdt_property_compat (gc, fdt,1 ,"virtio,mmio" ); +if (res)return res; + + res =fdt_property_regs (gc, fdt,GUEST_ROOT_ADDRESS_CELLS ,GUEST_ROOT_SIZE_CELLS , +1 , base,GUEST_VIRTIO_MMIO_SIZE ); +if (res)return res; + +set_interrupt (intr, irq,0xf ,DT_IRQ_TYPE_EDGE_RISING ); + res =fdt_property_interrupts (gc, fdt, &intr,1 ); +if (res)return res; + + res =fdt_property (fdt,"dma-coherent" ,NULL ,0 ); +if (res)return res; + + res =fdt_end_node (fdt); +if (res)return res; + +return 0 ; + +} +static const struct arch_info *get_arch_info (libxl__gc *gc,const struct xc_dom_image *dom) {
@@ -962,6 +1012,9 @@ next_resize:if (info->tee ==LIBXL_TEE_TYPE_OPTEE )FDT (make_optee_node (gc, fdt) ); +if (libxl_defbool_val (info->arch_arm.virtio)) +FDT (make_virtio_mmio_node (gc, fdt,GUEST_VIRTIO_MMIO_BASE ,GUEST_VIRTIO_MMIO_SPI ) ); +if (pfdt)FDT (copy_partial_fdt (gc, fdt, pfdt) );
@@ -1179,6 +1232,7 @@ void libxl__arch_domain_build_info_setdefault(libxl__gc *gc, {/* ACPI is disabled by default */ libxl_defbool_setdefault (&b_info->acpi, false); +libxl_defbool_setdefault (&b_info->arch_arm.virtio, false);if (b_info->type !=LIBXL_DOMAIN_TYPE_PV )return ;
tools/libxl/libxl_types.idl +1 -0
@@ -639,6 +639,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), + ("virtio", libxl_defbool), ("vuart", libxl_vuart_type), ])), # Alternate p2m is not bound to any architecture or guest type, as it is
tools/xl/xl_parse.c +1 -0
@@ -2579,6 +2579,7 @@ skip_usbdev: }xlu_cfg_get_defbool (config,"dm_restrict" , &b_info->dm_restrict,0 ); +xlu_cfg_get_defbool (config,"virtio" , &b_info->arch_arm.virtio,0 );if (c_info->type ==LIBXL_DOMAIN_TYPE_HVM ) {if (!xlu_cfg_get_string (config,"vga" , &buf,0 )) {
xen/include/public/arch-arm.h +5 -0
@@ -464,6 +464,11 @@ typedef uint64_t xen_callback_t;#define PSCI_cpu_on 2#define PSCI_migrate 3 +/* VirtIO MMIO definitions */ +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x200) +#define GUEST_VIRTIO_MMIO_SPI 33 +#endif #ifndef __ASSEMBLY__
Signature · 1 line
2.7.4
RFC PATCH 16/16 libxl: Add support for virtio-disk configuration
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Xenstore was chosen as a communication interface for the emulator running in non-toolstack domain to be able to get configuration either by reading Xenstore directly or by receiving command line parameters (an updated 'xl devd' running in the same domain would read Xenstore beforehand and call backend executable with the required arguments).
An example of domain configuration (two disks are assigned to the guest, the latter is in readonly mode):
vdisk = [ 'backend=DomD, disks=rw:/dev/mmcblk0p3;ro:/dev/mmcblk1p3' ]
Where per-disk Xenstore entries are:
- filename and readonly flag (configured via "vdisk" property)
- base and irq (allocated dynamically)
Besides handling 'visible' params described in configuration file, patch also allocates virtio-mmio specific ones for each device and writes them into Xenstore. virtio-mmio params (irq and base) are unique per guest domain, they allocated at the domain creation time and passed through to the emulator. Each VirtIO device has at least one pair of these params.
TODO:
1. An extra "virtio" property could be removed.
2. Update documentation.
---
Changes RFC -> V1:
- no changes
Please note, there is a real concern about VirtIO interrupts allocation. Just copy here what Stefano said in RFC thread.
So, if we end up allocating let's say 6 virtio interrupts for a domain, the chance of a clash with a physical interrupt of a passthrough device is real.
I am not entirely sure how to solve it, but these are a few ideas:
- choosing virtio interrupts that are less likely to conflict (maybe > 1000)
- make the virtio irq (optionally) configurable so that a user could override the default irq and specify one that doesn't conflict
- implementing support for virq != pirq (even the xl interface doesn't allow to specify the virq number for passthrough devices, see "irqs")
---
--- tools/libxl/Makefile | 4 +- tools/libxl/libxl_arm.c | 56 ++++++++++++++--- tools/libxl/libxl_create.c | 1 + tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types.idl | 15 +++++ tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_virtio_disk.c | 109 +++++++++++++++++++++++++++++++++ tools/xl/Makefile | 2 +- tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 15 +++++ tools/xl/xl_parse.c | 115 +++++++++++++++++++++++++++++++++++ tools/xl/xl_virtio_disk.c | 46 ++++++++++++++ 12 files changed, 356 insertions(+), 12 deletions(-) create mode 100644 tools/libxl/libxl_virtio_disk.c create mode 100644 tools/xl/xl_virtio_disk.c
tools/libxl/Makefile +3 -1
@@ -141,7 +141,9 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_vtpm.o libxl_nic.o libxl_disk.o libxl_console.o \ libxl_cpupool.o libxl_mem.o libxl_sched.o libxl_tmem.o \ libxl_9pfs.o libxl_domain.o libxl_vdispl.o \ - libxl_pvcalls.o libxl_vsnd.o libxl_vkb.o $(LIBXL_OBJS-y) + libxl_pvcalls.o libxl_vsnd.o libxl_vkb.o \ + libxl_virtio_disk.o $(LIBXL_OBJS-y) + LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
tools/libxl/libxl_arm.c +46 -10
82 lines not on this page · raw message
tools/libxl/libxl_create.c +1 -0
@@ -1817,6 +1817,7 @@ const libxl__device_type *device_type_tbl[] = { &libxl__dtdev_devtype, &libxl__vdispl_devtype, &libxl__vsnd_devtype, + &libxl__virtio_disk_devtype, NULL };
tools/libxl/libxl_internal.h +1 -0
@@ -3988,6 +3988,7 @@ extern const libxl__device_type libxl__vdispl_devtype;extern const libxl__device_type libxl__p9_devtype;extern const libxl__device_type libxl__pvcallsif_devtype;extern const libxl__device_type libxl__vsnd_devtype; +extern const libxl__device_type libxl__virtio_disk_devtype;extern const libxl__device_type *device_type_tbl[];
tools/libxl/libxl_types.idl +15 -0
@@ -935,6 +935,20 @@ libxl_device_vsnd = Struct("device_vsnd", [ ("pcms", Array(libxl_vsnd_pcm, "num_vsnd_pcms")) ]) +libxl_virtio_disk_param = Struct("virtio_disk_param", [ + ("filename", string), + ("readonly", bool), + ("irq", uint32), + ("base", uint64), + ]) + +libxl_device_virtio_disk = Struct("device_virtio_disk", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("disks", Array(libxl_virtio_disk_param, "num_disks")), + ]) + libxl_domain_config = Struct("domain_config", [ ("c_info", libxl_domain_create_info), ("b_info", libxl_domain_build_info),
@@ -951,6 +965,7 @@ libxl_domain_config = Struct("domain_config", [ ("pvcallsifs", Array(libxl_device_pvcallsif, "num_pvcallsifs")), ("vdispls", Array(libxl_device_vdispl, "num_vdispls")), ("vsnds", Array(libxl_device_vsnd, "num_vsnds")), + ("virtio_disks", Array(libxl_device_virtio_disk, "num_virtio_disks")), # a channel manifests as a console with a name, # see docs/misc/channels.txt ("channels", Array(libxl_device_channel, "num_channels")),
tools/libxl/libxl_types_internal.idl +1 -0
@@ -32,6 +32,7 @@ libxl__device_kind = Enumeration("device_kind", [ (14, "PVCALLS"), (15, "VSND"), (16, "VINPUT"), + (17, "VIRTIO_DISK"), ]) libxl__console_backend = Enumeration("console_backend", [
tools/libxl/libxl_virtio_disk.c new file +109 -0
109 lines not on this page · raw message
tools/xl/Makefile +1 -1
@@ -22,7 +22,7 @@ XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o XL_OBJS += xl_info.o xl_console.o xl_misc.o XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o -XL_OBJS += xl_vdispl.o xl_vsnd.o xl_vkb.o +XL_OBJS += xl_vdispl.o xl_vsnd.o xl_vkb.o xl_virtio_disk.o $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog) $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
tools/xl/xl.h +3 -0
@@ -178,6 +178,9 @@ int main_vsnddetach(int argc, char **argv);int main_vkbattach (int argc,char **argv);int main_vkblist (int argc,char **argv);int main_vkbdetach (int argc,char **argv); +int main_virtio_diskattach (int argc,char **argv); +int main_virtio_disklist (int argc,char **argv); +int main_virtio_diskdetach (int argc,char **argv);int main_usbctrl_attach (int argc,char **argv);int main_usbctrl_detach (int argc,char **argv);int main_usbdev_attach (int argc,char **argv);
tools/xl/xl_cmdtable.c +15 -0
@@ -434,6 +434,21 @@ struct cmd_spec cmd_table[] = {"Destroy a domain's virtual sound device" ,"<Domain> <DevId>" , }, + { "virtio-disk-attach", + &main_virtio_diskattach,1 ,1 , +"Create a new virtio block device" , +" TBD\n" + }, + { "virtio-disk-list", + &main_virtio_disklist,0 ,0 , +"List virtio block devices for a domain" , +"<Domain(s)>" , + }, + { "virtio-disk-detach", + &main_virtio_diskdetach,0 ,1 , +"Destroy a domain's virtio block device" , +"<Domain> <DevId>" , + }, { "uptime", &main_uptime,0 ,0 , "Print uptime for all/some domains",
tools/xl/xl_parse.c +115 -0
127 lines not on this page · raw message
tools/xl/xl_virtio_disk.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.7.4