dmop: Add XEN_DMOP_nr_vcpus
PATCH 1/1 dmop: Add XEN_DMOP_nr_vcpus
Curiously absent from the stable API/ABIs is an ability to query the number of vcpus which a domain has. Emulators need to know this information in particular to know how many stuct ioreq's live in the ioreq server mappings.
In practice, this forces all userspace to link against libxenctrl to use xc_domain_getinfo(), which rather defeats the purpose of the stable libraries.
Introduce a DMOP to retrieve this information and surface it in libxendevicemodel to help emulators shed their use of unstable interfaces.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Ian Jackson <[email protected]>
For 4.15. This was a surprise discovery in the massive ABI untangling effort I'm currently doing for XenServer's new build system.
This is one new read-only op to obtain information which isn't otherwise available under a stable API/ABI. As such, its risk for 4.15 is very low, with a very real quality-of-life improvement for downstreams.
I realise this is technically a new feature and we're long past feature freeze, but I'm hoping that "really lets some emulators move off the unstable libraries" is sufficiently convincing argument.
It's not sufficient to let Qemu move off unstable libraries yet - at a minimum, the add_to_phymap hypercalls need stabilising to support PCI Passthrough and BAR remapping.
I'd prefer not to duplicate the op handling between ARM and x86, and if this weren't a release window, I'd submit a prereq patch to dedup the common dmop handling. That can wait to 4.16 at this point. Also, this op ought to work against x86 PV guests, but fixing that up will also need this rearrangement into common code, so needs to wait.
--- tools/include/xendevicemodel.h | 10 ++++++++++ tools/libs/devicemodel/core.c | 15 +++++++++++++++ tools/libs/devicemodel/libxendevicemodel.map | 1 + xen/arch/arm/dm.c | 10 ++++++++++ xen/arch/x86/hvm/dm.c | 11 +++++++++++ xen/include/public/hvm/dm_op.h | 15 +++++++++++++++ xen/include/xlat.lst | 1 + 7 files changed, 63 insertions(+)
tools/include/xendevicemodel.h +10 -0
@@ -358,6 +358,16 @@ int xendevicemodel_pin_memory_cacheattr( uint32_t type);/** +* Query for the number of vCPUs that a domain has. +* @parm dmod a handle to an open devicemodel interface. +* @parm domid the domain id to be serviced. +* @parm vcpus Number of vcpus. +* @return 0 on success and fills @p vcpus, or -1 on failure. +*/ +int xendevicemodel_nr_vcpus ( +xendevicemodel_handle *dmod,domid_t domid,unsigned int *vcpus); + +/** * This function restricts the use of this handle to the specified * domain. *
tools/libs/devicemodel/core.c +15 -0
@@ -630,6 +630,21 @@ int xendevicemodel_pin_memory_cacheattr(return xendevicemodel_op (dmod, domid,1 , &op,sizeof (op)); } +int xendevicemodel_nr_vcpus ( +xendevicemodel_handle *dmod,domid_t domid,unsigned int *vcpus) +{ +struct xen_dm_op op = { + .op = XEN_DMOP_nr_vcpus, + }; + +int rc =xendevicemodel_op (dmod, domid,1 , &op,sizeof (op)); +if ( rc ) +return rc; + + *vcpus = op.u.nr_vcpus.vcpus; +return 0 ; +} +int xendevicemodel_restrict (xendevicemodel_handle *dmod,domid_t domid) {return osdep_xendevicemodel_restrict (dmod, domid);
tools/libs/devicemodel/libxendevicemodel.map +1 -0
@@ -42,4 +42,5 @@ VERS_1.3 { VERS_1.4 { global: xendevicemodel_set_irq_level; + xendevicemodel_nr_vcpus; } VERS_1.3;
xen/arch/arm/dm.c +10 -0
@@ -38,6 +38,7 @@ int dm_op(const struct dmop_args *op_args) [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_set_irq_level] = sizeof(struct xen_dm_op_set_irq_level), + [XEN_DMOP_nr_vcpus] =sizeof (struct xen_dm_op_nr_vcpus ), }; rc =rcu_lock_remote_domain_by_id (op_args->domid, &d);
@@ -122,6 +123,15 @@ int dm_op(const struct dmop_args *op_args)break ; } +case XEN_DMOP_nr_vcpus: + { +struct xen_dm_op_nr_vcpus *data = &op.u.nr_vcpus; + + data->vcpus = d->max_vcpus; + rc =0 ; +break ; + } +default : rc =ioreq_server_dm_op (&op, d, &const_op);break ;
xen/arch/x86/hvm/dm.c +11 -0
@@ -359,6 +359,7 @@ 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_nr_vcpus] =sizeof (struct xen_dm_op_nr_vcpus ), }; rc =rcu_lock_remote_domain_by_id (op_args->domid, &d);
@@ -606,6 +607,15 @@ int dm_op(const struct dmop_args *op_args)break ; } +case XEN_DMOP_nr_vcpus: + { +struct xen_dm_op_nr_vcpus *data = &op.u.nr_vcpus; + + data->vcpus = d->max_vcpus; + rc =0 ; +break ; + } +default : rc =ioreq_server_dm_op (&op, d, &const_op);break ;
@@ -641,6 +651,7 @@ CHECK_dm_op_map_mem_type_to_ioreq_server; CHECK_dm_op_remote_shutdown; CHECK_dm_op_relocate_memory; CHECK_dm_op_pin_memory_cacheattr; +CHECK_dm_op_nr_vcpus; int compat_dm_op(domid_t domid, unsigned int nr_bufs,
xen/include/public/hvm/dm_op.h +15 -0
@@ -449,6 +449,20 @@ struct xen_dm_op_set_irq_level { };typedef struct xen_dm_op_set_irq_level xen_dm_op_set_irq_level_t ; +/* +* XEN_DMOP_nr_vcpus: Query the number of vCPUs a domain has. +* +* The number of vcpus a domain has is fixed from creation time. This bound +* is applicable to e.g. the vcpuid parameter of XEN_DMOP_inject_event, or +* number of struct ioreq objects mapped via XENMEM_acquire_resource. +*/ +#define XEN_DMOP_nr_vcpus 20 + +struct xen_dm_op_nr_vcpus { +uint32_t vcpus;/* OUT */ +}; +typedef struct xen_dm_op_nr_vcpus xen_dm_op_nr_vcpus_t ; +struct xen_dm_op {uint32_t op;uint32_t pad;
@@ -472,6 +486,7 @@ struct xen_dm_op {xen_dm_op_remote_shutdown_t remote_shutdown;xen_dm_op_relocate_memory_t relocate_memory;xen_dm_op_pin_memory_cacheattr_t pin_memory_cacheattr; +xen_dm_op_nr_vcpus_t nr_vcpus; } u; };
xen/include/xlat.lst +1 -0
@@ -107,6 +107,7 @@ ? dm_op_set_pci_intx_level hvm/dm_op.h ? dm_op_set_pci_link_route hvm/dm_op.h ? dm_op_track_dirty_vram hvm/dm_op.h +? dm_op_nr_vcpus hvm/dm_op.h ! hvm_altp2m_set_mem_access_multi hvm/hvm_op.h ? vcpu_hvm_context hvm/hvm_vcpu.h ? vcpu_hvm_x86_32 hvm/hvm_vcpu.h
Signature · 1 line
2.11.0
Andrew Cooper writes ("[PATCH for-4.15] dmop: Add XEN_DMOP_nr_vcpus"):
Quoted 6 lines
Curiously absent from the stable API/ABIs is an ability to query the number of vcpus which a domain has. Emulators need to know this information in particular to know how many stuct ioreq's live in the ioreq server mappings.
In practice, this forces all userspace to link against libxenctrl to use
xc_domain_getinfo(), which rather defeats the purpose of the stable libraries.
Wat
Quoted 2 lines
For 4.15. This was a surprise discovery in the massive ABI untangling effort I'm currently doing for XenServer's new build system.
Given that this is a new feature at a late stage I am going to say this:
I will R-A it subject to it getting *two* independent Reviewed-by.
I will try to one of them myself :-).
...
Quoted 6 lines
+/*
+ *XEN_DMOP_nr_vcpus: Query the number of vCPUs a domain has.
+ *
+ * The number of vcpus a domain has is fixed from creation time. This bound
+ * is applicable to e.g. the vcpuid parameter ofXEN_DMOP_inject_event, or
+ * number of struct ioreq objects mapped viaXENMEM_acquire_resource.
AIUI from the code, the value is the maximum number of vcpus, in the sense that they are not necessarily all online. In which case I think maybe you want to mention that here ?
xen/include/xlat.lst line 113
Quoted 13 lines
xen/include/xlat.lst +1
-0@@ -107,6 +107,7 @@ ? dm_op_set_pci_intx_level hvm/dm_op.h ? dm_op_set_pci_link_route hvm/dm_op.h ? dm_op_track_dirty_vram hvm/dm_op.h +? dm_op_nr_vcpus hvm/dm_op.h ! hvm_altp2m_set_mem_access_multi hvm/hvm_op.h ? vcpu_hvm_context hvm/hvm_vcpu.h ? vcpu_hvm_x86_32 hvm/hvm_vcpu.h
I have no idea what even. I read the comment at the top of the file.
So for *everything except the xlat.lst change*
Thanks,
Ian.
Quoted 8 lines · Ian Jackson
Andrew Cooper writes ("[PATCH for-4.15] dmop: Add
XEN_DMOP_nr_vcpus"):Quoted 6 lines
Curiously absent from the stable API/ABIs is an ability to query the number of vcpus which a domain has. Emulators need to know this information in particular to know how many stuct ioreq's live in the ioreq server mappings.
In practice, this forces all userspace to link against libxenctrl to use
xc_domain_getinfo(), which rather defeats the purpose of the stable libraries.Wat
Yeah... My reaction was similar.
Quoted 18 lines
Quoted 3 lines
For 4.15. This was a surprise discovery in the massive ABI untangling effort I'm currently doing for XenServer's new build system.
Given that this is a new feature at a late stage I am going to say this:
I will R-A it subject to it getting *two* independent Reviewed-by.
I will try to one of them myself :-).
...
Quoted 6 lines
+/*
+ *XEN_DMOP_nr_vcpus: Query the number of vCPUs a domain has.
+ *
+ * The number of vcpus a domain has is fixed from creation time. This bound
+ * is applicable to e.g. the vcpuid parameter ofXEN_DMOP_inject_event, or
+ * number of struct ioreq objects mapped viaXENMEM_acquire_resource.
Quoted 3 lines
AIUI from the code, the value is the maximum number of vcpus, in the sense that they are not necessarily all online. In which case I think maybe you want to mention that here ?
Yeah - there is no guarantee that they're all online, or running.
Emulators tend to attach before the domain starts executing anyway. The important thing they need to do is loop through each struct ioreq in the ioreq_server mapping to read the domid and bind the per-vcpu event channel for notification of work to do.
The totally gross way of not needing this API is to scan through the mapping and identify the first struct ioreq which has 0 listed for an event channel, which is not a construct I wish to promote.
Quoted 16 lines
Quoted 7 lines
xen/include/xlat.lst +0
-0xen/include/xlat.lst line 113
Quoted 7 lines
xen/include/xlat.lst +1
-0@@ -107,6 +107,7 @@ ? dm_op_set_pci_intx_level hvm/dm_op.h ? dm_op_set_pci_link_route hvm/dm_op.h ? dm_op_track_dirty_vram hvm/dm_op.h +? dm_op_nr_vcpus hvm/dm_op.h ! hvm_altp2m_set_mem_access_multi hvm/hvm_op.h ? vcpu_hvm_context hvm/hvm_vcpu.h ? vcpu_hvm_x86_32 hvm/hvm_vcpu.hI have no idea what even. I read the comment at the top of the file.
Quoted 2 lines
So for *everything except the xlat.lst change*
Reviewed-by Ian Jackson <[email protected]>
Thanks.
This is the magic to make this hunk:
@@ -641,6 +651,7 @@ CHECK_dm_op_map_mem_type_to_ioreq_server; CHECK_dm_op_remote_shutdown; CHECK_dm_op_relocate_memory; CHECK_dm_op_pin_memory_cacheattr; +CHECK_dm_op_nr_vcpus;
int compat_dm_op(domid_t domid,
unsigned int nr_bufs,
work, to do a build time check that the structure is identical between 32bit and 64bit builds.
~Andrew
Quoted 11 lines · Andrew Cooper
Curiously absent from the stable API/ABIs is an ability to query the number of vcpus which a domain has. Emulators need to know this information in particular to know how many stuct ioreq's live in the ioreq server mappings.
In practice, this forces all userspace to link against libxenctrl to use
xc_domain_getinfo(), which rather defeats the purpose of the stable libraries.Introduce a DMOP to retrieve this information and surface it in libxendevicemodel to help emulators shed their use of unstable interfaces.
Signed-off-by Andrew Cooper <[email protected]>
Hypervisor part
with one small adjustment:
xen/include/xlat.lst line 110
Quoted 7 lines
xen/include/xlat.lst +1
-0@@ -107,6 +107,7 @@ ? dm_op_set_pci_intx_level hvm/dm_op.h ? dm_op_set_pci_link_route hvm/dm_op.h ? dm_op_track_dirty_vram hvm/dm_op.h +? dm_op_nr_vcpus hvm/dm_op.h
We try to keep these sorted alphabetically, so please move the insertion up a few lines.
Jan