New hypercall for device models
cover New hypercall for device models
Following on from the design submitted by Jennifer Herbert to the list [1] this series provides an implementation of __HYPERCALL_dm_op followed by patches based on Jan Beulich's previous HVMCTL series [2] to convert tools-only HVMOPs used by device models to DMOPs.
[1] https://lists.xenproject.org/archives/html/xen-devel/2016-09/msg01052.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2016-06/msg02433.html
Paul Durrant (8):
public / x86: Introduce __HYPERCALL_dm_op...
dm_op: convert HVMOP_*ioreq_server*
dm_op: convert HVMOP_track_dirty_vram
dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level,
and...
dm_op: convert HVMOP_modified_memory
dm_op: convert HVMOP_set_mem_type
dm_op: convert HVMOP_inject_trap and HVMOP_inject_msi x86/hvm: serialize trap injecting producer and consumer
docs/designs/dmop.markdown | 193 ++++++++++ tools/flask/policy/modules/xen.if | 8 +- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_domain.c | 204 +++++------ tools/libxc/xc_misc.c | 226 ++++-------- tools/libxc/xc_private.c | 70 ++++ tools/libxc/xc_private.h | 2 + xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/dm.c | 501 ++++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 678 +----------------------------------- xen/arch/x86/hvm/ioreq.c | 42 +-- xen/arch/x86/hypercall.c | 2 + xen/arch/x86/mm/hap/hap.c | 2 +- xen/arch/x86/mm/shadow/common.c | 2 +- xen/include/asm-x86/hap.h | 2 +- xen/include/asm-x86/hvm/domain.h | 3 +- xen/include/asm-x86/hvm/hvm.h | 2 + xen/include/asm-x86/shadow.h | 2 +- xen/include/public/hvm/dm_op.h | 360 +++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 70 ++-- xen/include/public/xen-compat.h | 2 +- xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 7 + xen/include/xsm/dummy.h | 36 +- xen/include/xsm/xsm.h | 36 +- xen/xsm/dummy.c | 5 - xen/xsm/flask/hooks.c | 37 +- xen/xsm/flask/policy/access_vectors | 15 +- 28 files changed, 1396 insertions(+), 1114 deletions(-) create mode 100644 docs/designs/dmop.markdown create mode 100644 xen/arch/x86/hvm/dm.c create mode 100644 xen/include/public/hvm/dm_op.h
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/8 public / x86: Introduce __HYPERCALL_dm_op...
...as a set of hypercalls to be used by a device model.
As stated in the new docs/designs/dm_op.markdown:
"The aim of DMOP is to prevent a compromised device model from compromising domains other then the one it is associated with. (And is therefore likely already compromised)."
See that file for further information.
This patch simply adds the boilerplate for the hypercall and bumps __XEN_LATEST_INTERFACE_VERSION__ to 0x0000040900. Subsequent patches will add the individual (sets of) operations.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
--- docs/designs/dmop.markdown | 193 ++++++++++++++++++++++++++++++++++++++ tools/flask/policy/modules/xen.if | 2 +- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_private.c | 70 ++++++++++++++ tools/libxc/xc_private.h | 2 + xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/dm.c | 136 +++++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/hypercall.c | 2 + xen/include/public/hvm/dm_op.h | 70 ++++++++++++++ xen/include/public/xen-compat.h | 2 +- xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 7 ++ xen/include/xsm/dummy.h | 6 ++ xen/include/xsm/xsm.h | 6 ++ xen/xsm/flask/hooks.c | 7 ++ 16 files changed, 505 insertions(+), 2 deletions(-) create mode 100644 docs/designs/dmop.markdown create mode 100644 xen/arch/x86/hvm/dm.c create mode 100644 xen/include/public/hvm/dm_op.h
docs/designs/dmop.markdown new file +193 -0
@@ -0,0 +1,193 @@ +DMOP (multi-buffer variant) +============================ + +Introduction +------------ + +A previous proposal for a 'DMOP' was put forward by Ian Jackson on the 1st +of August. This proposal seem very promising, however a problem was +identified with it, that this proposal addresses. + +The aim of DMOP, as before, is to prevent a compromised device model from +compromising domains other then the one it is associated with. (And is +therefore likely already compromised). + +The previous proposal adds a DMOP hypercall, for use by the device models, +which places the domain ID in a fixed place, within the calling args, +such that the priv driver can always find it, and not need to know any +further details about the particular DMOP in order to validate it against +previously set (vie ioctl) domain. + +The problem occurs when you have a DMOP with references to other user memory +objects, such as with Track dirty VRAM (As used with the VGA buffer). +Is this case, the address of this other user object needs to be vetted, +to ensure it is not within a restricted address ranges, such as kernel +memory. The real problem comes down to how you would vet this address - +the idea place to do this is within the privcmd driver, since it would have +knowledge of the address space involved. However, with a principal goal +of DMOP to allow privcmd to be free from any knowledge of DMOP's sub ops, +it would have no way to identify any user buffer addresses that need +checking. The alternative of allowing the hypervisor to vet the address +is also problematic, since it has no knowledge of the guest memory layout. + + +The Design +---------- + +As with the previous design, we provide a new restriction ioctl, which +takes a domid parameter. After that restriction ioctl is called, the +privcmd driver will permit only DMOP hypercalls, and only with the +specified target domid. + +In the previous design, a DMOP consisted of one buffer, containing all of +the DMOP parameters, which may include further explicit references to +more buffers. In this design, an array of buffers with length is presented, +with the first one containing the DMOP parameters, which could implicitly +reference to further buffers from within in the array. Here, the only +user buffers passed, are that found with the array, and so all can be +audited from privcmd. With the passing of the length of the buffers array, +privcmd does not need to know which DMOP it is to audit them. + +If the hypervisor ends up with the wrong number of buffers, it can reject +the DMOP at that point. + +The following code illustrates this idea: + +struct xen_dm_op { + uint32_t op; +}; + +struct xen_dm_op_buf { + XEN_GUEST_HANDLE(void) h; + uint64_t size; +}; +typedef struct xen_dm_op_buf xen_dm_op_buf_t; + +enum neg_errnoval +HYPERVISOR_dm_op(domid_t domid, + xen_dm_op_buf_t *bufs, + unsigned int nr_bufs) + +@domid is the domain the hypercall operates on. +@bufs points to an array of buffers where @bufs[0] contains a struct +dm_op, describing the specific device model operation and its parameters. +@bufs[1..] may be referenced in the parameters for the purposes of +passing extra information to or from the domain. +@nr_bufs is the number of buffers in the @bufs array. + + +It is forbidden for the above struct (dm_op) to contain any +guest handles - if they are needed, they should instead be in +HYPERVISOR_dm_op->buffers. + +Validation by privcmd driver +------------------------------ + +If the privcmd driver has been restricted to specific domain (using a + new ioctl), when it received an op, it will: + +1. Check hypercall is DMOP. + +2. Check domid == restricted domid. + +3. For each @nr_buffers in @buffers: Check @h and @len give a buffer + wholey in the user space part of the virtual address space. (e.g., + on Linux use access_ok()). + + +Xen Implementation +------------------ + +Since a DMOP sub of may need to copy or return a buffer from the guest, +as well as the DMOP itself to git the initial buffer, functions for doing +this would be written as below. Note that care is taken to prevent +damage from buffer under or over run situations. If the DMOP is called +with insufficient buffers, zeros will be read, while extra is ignored. + +static int dm_op_get_buf(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs, + unsigned int nr_bufs, unsigned int idx, + struct xen_dm_op_buf *buf) +{ + if ( idx >= nr_bufs ) + return -EFAULT; + + return copy_from_guest_offset(buf, bufs, idx, 1); +} + +static int dm_op_copy_buf_from_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs, + unsigned int nr_bufs, void *dst, + unsigned int idx, size_t dst_size) +{ + struct xen_dm_op_buf buf; + size_t size; + int rc; + + memset(dst, 0, dst_size); + + rc = dm_op_get_buf(bufs, nr_bufs, idx, &buf); + if ( rc ) + return -EFAULT; + + size = min(dst_size, buf.size); + + rc = copy_from_guest(dst, buf.h, size); + if ( rc ) + return -EFAULT; + + return 0; +} + +int dm_op_copy_buf_to_guest(...) +{ + /* Similar to the above, except copying the the other + direction. */ +} + +This leaves do_dm_op easy to implement as below: + +long do_dm_op(domid_t domid, + unsigned int nr_bufs, + XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs); + { + struct domain *d; + struct xen_dm_op op; + bool restart; + long rc; + + rc = rcu_lock_remote_domain_by_id(domid, &d); + if ( rc ) + return rc; + + if ( !has_hvm_container_domain(d) ) + goto out; + + rc = xsm_dm_op(XSM_DM_PRIV, d); + if ( rc ) + goto out; + + rc = copy_dm_op_buf_from_guest(bufs, nr_bufs, &op, 0, sizeof(op)); + if ( rc ) + goto out; + + switch ( op.op ) { + default: + rc = -EOPNOTSUPP; + break; + } + + restart = (rc == -ERESTART); + + if ( !restart && rc ) + goto out; + + rc = copy_dm_op_buf_to_guest(bufs, nr_bufs, 0, &op, sizeof(op)); + +out: + rcu_unlock_domain(d); + + if ( restart && !rc ) + rc = hypercall_create_continuation(__HYPERVISOR_dm_op, "iih", + domid, nr_bufs, bufs); + + return rc; +}
tools/flask/policy/modules/xen.if +1 -1
@@ -151,7 +151,7 @@ define(`device_model', ` allow $1 $2_target:domain { getdomaininfo shutdown }; allow $1 $2_target:mmu { map_read map_write adjust physmap target_hack }; - allow $1 $2_target:hvm { getparam setparam trackdirtyvram hvmctl irqlevel pciroute pcilevel cacheattr send_irq }; + allow $1 $2_target:hvm { getparam setparam trackdirtyvram hvmctl irqlevel pciroute pcilevel cacheattr send_irq dm }; ') # make_device_model(priv, dm_dom, hvm_dom)
tools/libxc/include/xenctrl.h +1 -0
@@ -41,6 +41,7 @@#include <xen/sched.h> #include <xen/memory.h> #include <xen/grant_table.h> +#include <xen/hvm/dm_op.h> #include <xen/hvm/params.h> #include <xen/xsm/flask_op.h> #include <xen/tmem.h>
tools/libxc/xc_private.c +70 -0
76 lines not on this page · raw message
tools/libxc/xc_private.h +2 -0
@@ -422,6 +422,8 @@ int xc_vm_event_control(xc_interface *xch, domid_t domain_id, unsigned int op,void *xc_vm_event_enable (xc_interface *xch,domid_t domain_id,int param,uint32_t *port); +int do_dm_op (xc_interface *xch,domid_t domid,unsigned int nr_bufs, ...); +#endif /* __XC_PRIVATE_H__ */ /*
xen/arch/x86/hvm/Makefile +1 -0
@@ -2,6 +2,7 @@ subdir-y += svm subdir-y += vmx obj-y += asid.o +obj-y += dm.o obj-y += emulate.o obj-y += hpet.o obj-y += hvm.o
xen/arch/x86/hvm/dm.c new file +136 -0
136 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +1 -0
@@ -4259,6 +4259,7 @@ static const hypercall_table_t hvm_hypercall_table[] = {COMPAT_CALL (platform_op),COMPAT_CALL (mmuext_op),HYPERCALL (xenpmu_op), +HYPERCALL (dm_op), HYPERCALL(arch_1) };
xen/arch/x86/hypercall.c +2 -0
@@ -66,6 +66,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =ARGS (kexec_op,2 ),ARGS (tmem_op,1 ),ARGS (xenpmu_op,2 ), +ARGS (dm_op,3 ),ARGS (mca,1 ), ARGS(arch_1, 1), };
@@ -128,6 +129,7 @@ static const hypercall_table_t pv_hypercall_table[] = {HYPERCALL (tmem_op), #endifHYPERCALL (xenpmu_op), +HYPERCALL (dm_op),HYPERCALL (mca), HYPERCALL(arch_1), };
xen/include/public/hvm/dm_op.h new file +70 -0
70 lines not on this page · raw message
xen/include/public/xen-compat.h +1 -1
@@ -27,7 +27,7 @@#ifndef __XEN_PUBLIC_XEN_COMPAT_H__#define __XEN_PUBLIC_XEN_COMPAT_H__ -#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040800 +#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040900#if defined(__XEN__) || defined(__XEN_TOOLS__)/* Xen is built with matching headers and implements the latest interface. */
xen/include/public/xen.h +1 -0
@@ -120,6 +120,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define __HYPERVISOR_tmem_op 38#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */ #define __HYPERVISOR_xenpmu_op 40 +#define __HYPERVISOR_dm_op 41/* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/hypercall.h +7 -0
@@ -15,6 +15,7 @@#include <public/tmem.h> #include <public/version.h> #include <public/pmu.h> +#include <public/hvm/dm_op.h> #include <asm/hypercall.h> #include <xsm/xsm.h>
@@ -141,6 +142,12 @@ do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);extern long do_xenpmu_op (unsigned int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg); +extern long +do_dm_op ( +domid_t domid, +unsigned int nr_bufs, +XEN_GUEST_HANDLE_PARAM (xen_dm_op_buf_t) bufs); +#ifdef CONFIG_COMPAT extern int
xen/include/xsm/dummy.h +6 -0
@@ -727,6 +727,12 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int } } +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 */ #include <public/version.h>
xen/include/xsm/xsm.h +6 -0
@@ -184,6 +184,7 @@ 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 (*xen_version) (uint32_t cmd); };
@@ -722,6 +723,11 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int return xsm_ops->pmu_op(d, op); } +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)
xen/xsm/flask/hooks.c +7 -0
@@ -1632,6 +1632,12 @@ static int flask_pmu_op (struct domain *d, unsigned int op) return -EPERM; } } + +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)
@@ -1811,6 +1817,7 @@ 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 .xen_version = flask_xen_version, };
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 1/8] public / x86: Introduce __HYPERCALL_dm_op...
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
This patch simply adds the boilerplate for the hypercall and bumps
__XEN_LATEST_INTERFACE_VERSION__to0x0000040900.
Why the latter?
docs/designs/dmop.markdown line 112
Quoted 6 lines
docs/designs/dmop.markdown new file +6
-0+static int dm_op_get_buf(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs, + unsigned int nr_bufs, unsigned int idx, + struct xen_dm_op_buf *buf) +{ + if ( idx >= nr_bufs ) + return -EFAULT;
There's no fault here. ENOENT, EIO, ENXIO, ...?
Quoted 9 lines
docs/designs/dmop.markdown new file +4
-0+ return copy_from_guest_offset(buf, bufs, idx, 1); +} + +static intdm_op_copy_buf_from_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs,
docs/designs/dmop.markdown new file +4
-0+ unsigned int nr_bufs, void *dst, + unsigned int idx, size_t dst_size) +{ + struct xen_dm_op_buf buf;
docs/designs/dmop.markdown line 131
Quoted 10 lines
docs/designs/dmop.markdown new file +10
-0+ size_t size; + int rc; + + memset(dst, 0, dst_size); + + rc = dm_op_get_buf(bufs, nr_bufs, idx, &buf); + if ( rc ) + return -EFAULT; + + size = min(dst_size, buf.size);
Hmm, the file is x86-specific, so this may indeed build. But formally the two expressions are of different types, which min() doesn't like.
Quoted 10 lines
xen/arch/x86/hvm/dm.c new file +10
-0+static int dm_op_copy_buf_to_guest (XEN_GUEST_HANDLE_PARAM (xen_dm_op_buf_t) bufs, +unsigned int nr_bufs,unsigned int idx, +void *src,size_t src_size) +{ +struct xen_dm_op_buf buf; +size_t size; +int rc; + + rc =dm_op_get_buf (bufs, nr_bufs, idx, &buf); +if ( rc )
xen/arch/x86/hvm/dm.c line 75
Quoted 10 lines
xen/arch/x86/hvm/dm.c new file +10
-0+return -EFAULT ; + + size =min (buf.size, src_size); + + rc =copy_to_guest (buf.h, src, size); +if ( rc ) +return -EFAULT ; + +return 0 ; +}
For copying from guest doing all-or-nothing is probably sufficient, but is that really the case also for copying data back?
Quoted 27 lines
xen/arch/x86/hvm/dm.c new file +27
-0+long do_dm_op (domid_t domid, +unsigned int nr_bufs, +XEN_GUEST_HANDLE_PARAM (xen_dm_op_buf_t) bufs) +{ +struct domain *d; +struct xen_dm_op op; +bool restart; +long rc; + + rc =rcu_lock_remote_domain_by_id (domid, &d); +if ( rc ) +return rc; + + restart = false; + +if ( !has_hvm_container_domain (d) ) + goto out; + + rc =xsm_dm_op (XSM_DM_PRIV , d); +if ( rc ) + goto out; + + rc =dm_op_copy_buf_from_guest (bufs, nr_bufs, &op,0 ,sizeof (op)); +if ( rc ) + goto out; + + switch ( op.op )
xen/arch/x86/hvm/dm.c line 113
Quoted 10 lines
xen/arch/x86/hvm/dm.c new file +10
-0+ { +default : + rc = -EOPNOTSUPP ; +break ; + } + +if ( rc == -ERESTART ) + restart = true; + +if ( !restart && rc )
Is the "restart" variable really necessary?
xen/arch/x86/hvm/dm.c line 118
Quoted 5 lines
xen/arch/x86/hvm/dm.c new file +5
-0+ goto out; + + rc =dm_op_copy_buf_to_guest (bufs, nr_bufs,0 , &op,sizeof (op)); + +out:
A goto over a single statement is certainly too much goto-ery for my taste. In any event - labels indented by at least one space please.
xen/include/public/hvm/dm_op.h line 31
Quoted 8 lines
xen/include/public/hvm/dm_op.h new file +8
-0+#ifndef __XEN_PUBLIC_HVM_DM_OP_H__ +#define __XEN_PUBLIC_HVM_DM_OP_H__ + +#if defined(__XEN__) || defined(__XEN_TOOLS__) + +#include "../xen.h" + +#define DMOP_invalid 0
XEN_DMOP_invalid
Quoted 4 lines
xen/include/public/hvm/dm_op.h new file +4
-0+struct xen_dm_op { +uint32_t op; +}; +
xen/include/public/hvm/dm_op.h line 46
Quoted 10 lines
xen/include/public/hvm/dm_op.h new file +10
-0+struct xen_dm_op_buf { +XEN_GUEST_HANDLE (void ) h; +uint64_t size; +}; +typedef struct xen_dm_op_buf xen_dm_op_buf_t ; +DEFINE_XEN_GUEST_HANDLE (xen_dm_op_buf_t); + +/* ` enum neg_errnoval +* ` HYPERVISOR_dm_op(domid_t domid, +* ` xen_dm_op_buf_t *bufs,
I'd prefer you to use the bufs[] notation here, to emphasize the array nature.
Quoted 6 lines
+ * ` unsigned int
nr_bufs)
+ * `
+ *
+ * @domid is the domain the hypercall operates on.
+ * @bufs points to an array of buffers where @bufs[0] contains a struct
+ *dm_op, describing the specific device model operation and its parameters.
xen_dm_op
xen/include/public/hvm/dm_op.h line 58
Quoted 6 lines
+ * @bufs[1..] may be referenced in the parameters for the purposes of
+ * passing extra information to or from the domain.
+ * @nr_bufs is the number of buffers in the @bufs array.
+ */xen/include/public/hvm/dm_op.h new file +2
-0+ +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
Please omit the two defined() (but retain what's inside the parentheses).
xen/include/xsm/dummy.h static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int · line 730
Quoted 7 lines
xen/include/xsm/dummy.h +1
-0@@ -727,6 +727,12 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int } } +static XSM_INLINE int xsm_dm_op (XSM_DEFAULT_ARG struct domain *d)
Stray blank (many of the XSM routines have this wrong, and this really should be cleaned up eventually).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 1/8] public / x86: Introduce __HYPERCALL_dm_op...
Quoted 10 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 November 2016 15:57
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [PATCH-for-4.9 v1 1/8] public / x86: Introduce__HYPERCALL_dm_op...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
This patch simply adds the boilerplate for the hypercall and bumps
__XEN_LATEST_INTERFACE_VERSION__to0x0000040900.Why the latter?
Do I not need to bump the interface version?
Quoted 11 lines
Quoted 2 lines
+static int
dm_op_get_buf(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs,
docs/designs/dmop.markdown line 112
Quoted 5 lines
docs/designs/dmop.markdown new file +5
-0+ unsigned int nr_bufs, unsigned int idx, + struct xen_dm_op_buf *buf) +{ + if ( idx >= nr_bufs ) + return -EFAULT;There's no fault here. ENOENT, EIO, ENXIO, ...?
True, ENOENT I think.
Quoted 16 lines
docs/designs/dmop.markdown
Quoted 5 lines
docs/designs/dmop.markdown new file +4
-0+ return copy_from_guest_offset(buf, bufs, idx, 1); +} + +static intdm_op_copy_buf_from_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_
buf_t) bufs,Quoted 9 lines
docs/designs/dmop.markdown new file +9
-0+ unsigned int nr_bufs, void *dst, + unsigned int idx, size_t dst_size) +{ + struct xen_dm_op_buf buf; + size_t size; + int rc; + + memset(dst, 0, dst_size); +
Quoted 9 lines
docs/designs/dmop.markdown line 131
Quoted 5 lines
docs/designs/dmop.markdown new file +5
-0+ rc = dm_op_get_buf(bufs, nr_bufs, idx, &buf); + if ( rc ) + return -EFAULT; + + size = min(dst_size, buf.size);Hmm, the file is x86-specific, so this may indeed build. But formally the two expressions are of different types, which
min()doesn't like.
Ok.
Quoted 17 lines
Quoted 1 line
+static int
dm_op_copy_buf_to_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_bu
f_t) bufs,Quoted 14 lines
xen/arch/x86/hvm/dm.c new file +14
-0+ unsigned int nr_bufs, unsigned int idx, + void *src, size_t src_size) +{ + struct xen_dm_op_buf buf; +size_t size; +int rc; + + rc =dm_op_get_buf (bufs, nr_bufs, idx, &buf); +if ( rc ) +return -EFAULT ; + + size =min (buf.size, src_size); + + rc =copy_to_guest (buf.h, src, size);
Quoted 9 lines
docs/designs/dmop.markdown line 138
Quoted 5 lines
docs/designs/dmop.markdown new file +5
-0+ if ( rc ) + return -EFAULT; + + return 0; +}For copying from guest doing all-or-nothing is probably sufficient, but is that really the case also for copying data back?
It is ok for now. It can always be changed later if we want to optimise.
Quoted 40 lines
Quoted 27 lines
xen/arch/x86/hvm/dm.c new file +27
-0+long do_dm_op (domid_t domid, +unsigned int nr_bufs, +XEN_GUEST_HANDLE_PARAM (xen_dm_op_buf_t) bufs) +{ +struct domain *d; +struct xen_dm_op op; +bool restart; +long rc; + + rc =rcu_lock_remote_domain_by_id (domid, &d); +if ( rc ) +return rc; + + restart = false; + +if ( !has_hvm_container_domain (d) ) + goto out; + + rc =xsm_dm_op (XSM_DM_PRIV , d); +if ( rc ) + goto out; + + rc =dm_op_copy_buf_from_guest (bufs, nr_bufs, &op,0 ,sizeof (op)); +if ( rc ) + goto out; + + switch ( op.op )xen/arch/x86/hvm/dm.c line 113
Quoted 10 lines
xen/arch/x86/hvm/dm.c new file +10
-0+ { +default : + rc = -EOPNOTSUPP ; +break ; + } + +if ( rc == -ERESTART ) + restart = true; + +if ( !restart && rc )Is the "restart" variable really necessary?
Quoted 10 lines
xen/arch/x86/hvm/dm.c line 118
Quoted 5 lines
xen/arch/x86/hvm/dm.c new file +5
-0+ goto out; + + rc =dm_op_copy_buf_to_guest (bufs, nr_bufs,0 , &op,sizeof (op)); + +out:A goto over a single statement is certainly too much goto-ery for my taste. In any event - labels indented by at least one space please.
Ok, I'll get rid of the goto despite it making the code look more cumbersome to me.
Quoted 11 lines
xen/include/public/hvm/dm_op.h line 31
Quoted 8 lines
xen/include/public/hvm/dm_op.h new file +8
-0+#ifndef __XEN_PUBLIC_HVM_DM_OP_H__ +#define __XEN_PUBLIC_HVM_DM_OP_H__ + +#if defined(__XEN__) || defined(__XEN_TOOLS__) + +#include "../xen.h" + +#define DMOP_invalid 0
XEN_DMOP_invalid
Yes, indeed.
Quoted 9 lines
Quoted 9 lines
docs/designs/dmop.markdown new file +9
-0+struct xen_dm_op { + uint32_t op; +}; + +struct xen_dm_op_buf { + XEN_GUEST_HANDLE(void) h; + uint64_t size; +}; +typedef struct xen_dm_op_buf xen_dm_op_buf_t;
Quoted 9 lines
xen/include/public/hvm/dm_op.h line 46
Quoted 5 lines
xen/include/public/hvm/dm_op.h new file +5
-0+DEFINE_XEN_GUEST_HANDLE (xen_dm_op_buf_t); + +/* ` enum neg_errnoval +* ` HYPERVISOR_dm_op(domid_t domid, +* ` xen_dm_op_buf_t *bufs, I'd prefer you to use the bufs[] notation here, to emphasize the array nature.
Ok.
Quoted 10 lines
Quoted 6 lines
+ * ` unsigned int
nr_bufs)
+ * `
+ *
+ * @domid is the domain the hypercall operates on.
+ * @bufs points to an array of buffers where @bufs[0] contains a struct
+ *dm_op, describing the specific device model operation and itsparameters.
xen_dm_op
Yep.
Quoted 10 lines
xen/include/public/hvm/dm_op.h line 58
Quoted 6 lines
+ * @bufs[1..] may be referenced in the parameters for the purposes of
+ * passing extra information to or from the domain.
+ * @nr_bufs is the number of buffers in the @bufs array.
+ */xen/include/public/hvm/dm_op.h new file +2
-0+ +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ Please omit the two
defined()(but retain what's inside the parentheses).
Ok.
Quoted 5 lines
xen/include/xsm/dummy.h static XSM_INLINE int xsm_pmu_op
Quoted 4 lines
xen/include/xsm/dummy.h +0
-0@@ -727,6 +727,12 @@ static XSM_INLINE int xsm_pmu_op(
XSM_DEFAULT_ARGstruct domain *d, unsigned int
Quoted 9 lines
xen/include/xsm/dummy.h static XSM_INLINE int xsm_pmu_op · line 730
Quoted 4 lines
xen/include/xsm/dummy.h +1
-0} } +static XSM_INLINE int xsm_dm_op (XSM_DEFAULT_ARG struct domain*d)
Stray blank (many of the XSM routines have this wrong, and this really should be cleaned up eventually).
Ok. I was just going for consistency.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 1/8] public / x86: Introduce __HYPERCALL_dm_op...
Quoted 11 lines
Quoted 11 lines
Quoted 1 line · On 22.11.16 at 17:32, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 November 2016 15:57
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [PATCH-for-4.9 v1 1/8] public / x86: Introduce__HYPERCALL_dm_op...
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
This patch simply adds the boilerplate for the hypercall and bumps
__XEN_LATEST_INTERFACE_VERSION__to0x0000040900.Why the latter?
Do I not need to bump the interface version?
Not for plain additions.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 1/8] public / x86: Introduce __HYPERCALL_dm_op...
Quoted 22 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 November 2016 17:25
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; [email protected]; Daniel DeGraaf <[email protected]>
Subject: RE: [PATCH-for-4.9 v1 1/8] public / x86: Introduce__HYPERCALL_dm_op...Quoted 12 lines
Quoted 12 lines
Quoted 1 line · On 22.11.16 at 17:32, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 November 2016 15:57
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [PATCH-for-4.9 v1 1/8] public / x86: Introduce__HYPERCALL_dm_op...Quoted 1 line
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
This patch simply adds the boilerplate for the hypercall and bumps
__XEN_LATEST_INTERFACE_VERSION__to0x0000040900.Why the latter?
Do I not need to bump the interface version?
Not for plain additions.
Oh, I see. The change is in preparation for later patches which remove HVMOP definitions for newer versions, but I can defer making the change till the first of those if that makes more sense.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 2/8 dm_op: convert HVMOP_*ioreq_server*
In reply to Paul DurrantNOTE: The definitions of HVM_IOREQSRV_BUFIOREQ_*, HVMOP_IO_RANGE_* and
HVMOP_PCI_SBDF have to persist for new interface versions as they are already in use by callers of the libxc interface.
--
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Daniel De Graaf <[email protected]>
--- tools/libxc/xc_domain.c | 204 ++++++++++++++---------------------- xen/arch/x86/hvm/dm.c | 55 ++++++++++ xen/arch/x86/hvm/hvm.c | 221 +-------------------------------------- xen/arch/x86/hvm/ioreq.c | 42 ++++---- xen/include/asm-x86/hvm/domain.h | 3 +- xen/include/public/hvm/dm_op.h | 157 +++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 40 ++++--- xen/include/xsm/dummy.h | 6 -- xen/include/xsm/xsm.h | 6 -- xen/xsm/dummy.c | 1 - xen/xsm/flask/hooks.c | 6 -- 11 files changed, 340 insertions(+), 401 deletions(-)
tools/libxc/xc_domain.c +80 -124
@@ -1417,24 +1417,22 @@ int xc_hvm_create_ioreq_server(xc_interface *xch,int handle_bufioreq, ioservid_t *id) { -DECLARE_HYPERCALL_BUFFER (xen_hvm_create_ioreq_server_t ,arg ); + struct xen_dm_op op; +struct xen_dm_op_create_ioreq_server *data;int rc; - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) -return -1 ; + op.op = DMOP_create_ioreq_server; + data = &op.u.create_ioreq_server; - arg->domid = domid; - arg->handle_bufioreq = handle_bufioreq; + data->handle_bufioreq = handle_bufioreq; - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_create_ioreq_server, -HYPERCALL_BUFFER_AS_ARG (arg)); + rc =do_dm_op (xch, domid,1 , &op,sizeof (op)); +if ( rc ) +return rc; - *id = arg->id; + *id = data->id; -xc_hypercall_buffer_free (xch, arg); -return rc; +return 0 ; } int xc_hvm_get_ioreq_server_info(xc_interface *xch,
@@ -1444,84 +1442,65 @@ int xc_hvm_get_ioreq_server_info(xc_interface *xch, xen_pfn_t *bufioreq_pfn, evtchn_port_t *bufioreq_port) { -DECLARE_HYPERCALL_BUFFER (xen_hvm_get_ioreq_server_info_t, arg); +struct xen_dm_op op; +struct xen_dm_op_get_ioreq_server_info *data;int rc; - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) -return -1 ; + op.op = DMOP_get_ioreq_server_info; + data = &op.u.get_ioreq_server_info; - arg->domid = domid; - arg->id = id; + data->id = id; - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_get_ioreq_server_info, -HYPERCALL_BUFFER_AS_ARG (arg)); -if ( rc !=0 ) - goto done; + rc =do_dm_op (xch, domid,1 , &op,sizeof (op)); +if ( rc ) +return rc;if ( ioreq_pfn ) - *ioreq_pfn = arg->ioreq_pfn; + *ioreq_pfn = data->ioreq_pfn;if ( bufioreq_pfn ) - *bufioreq_pfn = arg->bufioreq_pfn; + *bufioreq_pfn = data->bufioreq_pfn;if ( bufioreq_port ) - *bufioreq_port = arg->bufioreq_port; + *bufioreq_port = data->bufioreq_port; -done: -xc_hypercall_buffer_free (xch, arg); -return rc; +return 0 ; }int xc_hvm_map_io_range_to_ioreq_server (xc_interface *xch,domid_t domid,ioservid_t id,int is_mmio,uint64_t start,uint64_t end) { -DECLARE_HYPERCALL_BUFFER (xen_hvm_io_range_t, arg); -int rc; +struct xen_dm_op op; +struct xen_dm_op_ioreq_server_range *data; - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) -return -1 ; - - arg->domid = domid; - arg->id = id; - arg->type = is_mmio ?HVMOP_IO_RANGE_MEMORY :HVMOP_IO_RANGE_PORT ; - arg->start = start; - arg->end = end; + op.op = DMOP_map_io_range_to_ioreq_server; + data = &op.u.map_io_range_to_ioreq_server; - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_map_io_range_to_ioreq_server, -HYPERCALL_BUFFER_AS_ARG (arg)); + data->id = id; + data->type = is_mmio ?DMOP_IO_RANGE_MEMORY :DMOP_IO_RANGE_PORT ; + data->start = start; + data->end = end; -xc_hypercall_buffer_free (xch, arg); -return rc; +return do_dm_op (xch, domid,1 , &op,sizeof (op)); }int xc_hvm_unmap_io_range_from_ioreq_server (xc_interface *xch,domid_t domid,ioservid_t id,int is_mmio,uint64_t start,uint64_t end) { -DECLARE_HYPERCALL_BUFFER (xen_hvm_io_range_t, arg); -int rc; +struct xen_dm_op op; +struct xen_dm_op_ioreq_server_range *data; - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) -return -1 ; + op.op = DMOP_unmap_io_range_from_ioreq_server; + data = &op.u.unmap_io_range_from_ioreq_server; - arg->domid = domid; - arg->id = id; - arg->type = is_mmio ?HVMOP_IO_RANGE_MEMORY :HVMOP_IO_RANGE_PORT ; - arg->start = start; - arg->end = end; - - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_unmap_io_range_from_ioreq_server, -HYPERCALL_BUFFER_AS_ARG (arg)); + data->id = id; + data->type = is_mmio ?DMOP_IO_RANGE_MEMORY :DMOP_IO_RANGE_PORT ; + data->start = start; + data->end = end; -xc_hypercall_buffer_free (xch, arg); -return rc; +return do_dm_op (xch, domid,1 , &op,sizeof (op)); } int xc_hvm_map_pcidev_to_ioreq_server(xc_interface *xch, domid_t domid,
@@ -1529,37 +1508,30 @@ int xc_hvm_map_pcidev_to_ioreq_server(xc_interface *xch, domid_t domid, uint8_t bus, uint8_t device, uint8_t function) { -DECLARE_HYPERCALL_BUFFER (xen_hvm_io_range_t ,arg ); -int rc; + struct xen_dm_op op; +struct xen_dm_op_ioreq_server_range *data;if (device >0x1f || function >0x7 ) { errno =EINVAL ;return -1 ; } - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) -return -1 ; + op.op = DMOP_map_io_range_to_ioreq_server; + data = &op.u.map_io_range_to_ioreq_server; - arg->domid = domid; - arg->id = id; - arg->type =HVMOP_IO_RANGE_PCI ; + data->id = id; + data->type =DMOP_IO_RANGE_PCI ;/* * The underlying hypercall will deal with ranges of PCI SBDF * but, for simplicity, the API only uses singletons. */ - arg->start = arg->end =HVMOP_PCI_SBDF ((uint64_t )segment, - (uint64_t )bus, - (uint64_t )device, - (uint64_t )function); - - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_map_io_range_to_ioreq_server, -HYPERCALL_BUFFER_AS_ARG (arg)); + data->start = data->end =DMOP_PCI_SBDF ((uint64_t )segment, + (uint64_t )bus, + (uint64_t )device, + (uint64_t )function); -xc_hypercall_buffer_free (xch, arg); -return rc; +return do_dm_op (xch, domid,1 , &op,sizeof (op)); } int xc_hvm_unmap_pcidev_from_ioreq_server(xc_interface *xch, domid_t domid,
@@ -1567,54 +1539,45 @@ int xc_hvm_unmap_pcidev_from_ioreq_server(xc_interface *xch, domid_t domid, uint8_t bus, uint8_t device, uint8_t function) { -DECLARE_HYPERCALL_BUFFER (xen_hvm_io_range_t ,arg ); -int rc; + struct xen_dm_op op; +struct xen_dm_op_ioreq_server_range *data;if (device >0x1f || function >0x7 ) { errno =EINVAL ;return -1 ; } - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) -return -1 ; + op.op = DMOP_unmap_io_range_from_ioreq_server; + data = &op.u.unmap_io_range_from_ioreq_server; - arg->domid = domid; - arg->id = id; - arg->type =HVMOP_IO_RANGE_PCI ; - arg->start = arg->end =HVMOP_PCI_SBDF ((uint64_t )segment, - (uint64_t )bus, - (uint64_t )device, - (uint64_t )function); - - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_unmap_io_range_from_ioreq_server, -HYPERCALL_BUFFER_AS_ARG (arg)); + data->id = id; + data->type =DMOP_IO_RANGE_PCI ; -xc_hypercall_buffer_free (xch, arg); -return rc; +/* +* The underlying hypercall will deal with ranges of PCI SBDF +* but, for simplicity, the API only uses singletons. +*/ + data->start = data->end =DMOP_PCI_SBDF ((uint64_t )segment, + (uint64_t )bus, + (uint64_t )device, + (uint64_t )function); + +return do_dm_op (xch, domid,1 , &op,sizeof (op)); }int xc_hvm_destroy_ioreq_server (xc_interface *xch,domid_t domid,ioservid_t id) { -DECLARE_HYPERCALL_BUFFER (xen_hvm_destroy_ioreq_server_t, arg); -int rc; - - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) -return -1 ; +struct xen_dm_op op; +struct xen_dm_op_destroy_ioreq_server *data; - arg->domid = domid; - arg->id = id; + op.op = DMOP_destroy_ioreq_server; + data = &op.u.destroy_ioreq_server; - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_destroy_ioreq_server, -HYPERCALL_BUFFER_AS_ARG (arg)); + data->id = id; -xc_hypercall_buffer_free (xch, arg); -return rc; +return do_dm_op (xch, domid,1 , &op,sizeof (op)); } int xc_hvm_set_ioreq_server_state(xc_interface *xch,
@@ -1622,23 +1585,16 @@ int xc_hvm_set_ioreq_server_state(xc_interface *xch, ioservid_t id, int enabled) { -DECLARE_HYPERCALL_BUFFER (xen_hvm_set_ioreq_server_state_t ,arg ); -int rc; +struct xen_dm_op op; +struct xen_dm_op_set_ioreq_server_state *data; - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) -return -1 ; + op.op = DMOP_set_ioreq_server_state; + data = &op.u.set_ioreq_server_state; - arg->domid = domid; - arg->id = id; - arg->enabled = !!enabled; + data->id = id; + data->enabled = !!enabled; - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_set_ioreq_server_state, -HYPERCALL_BUFFER_AS_ARG (arg)); - -xc_hypercall_buffer_free (xch, arg); -return rc; +return do_dm_op (xch, domid,1 , &op,sizeof (op)); } int xc_domain_setdebugging(xc_interface *xch,
xen/arch/x86/hvm/dm.c +55 -0
61 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +1 -220
239 lines not on this page · raw message
xen/arch/x86/hvm/ioreq.c +21 -21
104 lines not on this page · raw message
xen/include/asm-x86/hvm/domain.h +2 -1
@@ -33,6 +33,7 @@#include <public/hvm/params.h> #include <public/hvm/save.h> #include <public/hvm/hvm_op.h> +#include <public/hvm/dm_op.h> struct hvm_ioreq_page {unsigned long gmfn;
@@ -47,7 +48,7 @@ struct hvm_ioreq_vcpu {bool_t pending; }; -#define NR_IO_RANGE_TYPES (HVMOP_IO_RANGE_PCI + 1) +#define NR_IO_RANGE_TYPES (DMOP_IO_RANGE_PCI + 1)#define MAX_NR_IO_RANGES 256struct hvm_ioreq_server {
xen/include/public/hvm/dm_op.h +157 -0
168 lines not on this page · raw message
xen/include/public/hvm/hvm_op.h +24 -16
@@ -26,6 +26,7 @@#include "../xen.h" #include "../trace.h" #include "../event_channel.h" +#include "dm_op.h" /* Get/set subcommands: extra argument == pointer to xen_hvm_param struct. */ #define HVMOP_set_param 0
@@ -242,6 +243,8 @@ struct xen_hvm_inject_msi {typedef struct xen_hvm_inject_msi xen_hvm_inject_msi_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_inject_msi_t); +#if __XEN_INTERFACE_VERSION__ <0x00040900 +/* * IOREQ Servers *
@@ -274,13 +277,6 @@ typedef uint16_t ioservid_t;#define HVMOP_create_ioreq_server 17struct xen_hvm_create_ioreq_server {domid_t domid;/* IN - domain to be serviced */ -#define HVM_IOREQSRV_BUFIOREQ_OFF 0 -#define HVM_IOREQSRV_BUFIOREQ_LEGACY 1 -/* -* Use this when read_pointer gets updated atomically and -* the pointer pair gets read atomically: -*/ -#define HVM_IOREQSRV_BUFIOREQ_ATOMIC 2uint8_t handle_bufioreq;/* IN - should server handle buffered ioreqs */ ioservid_t id;/* OUT - server id */ };
@@ -336,20 +332,11 @@ struct xen_hvm_io_range {domid_t domid;/* IN - domain to be serviced */ ioservid_t id;/* IN - server id */ uint32_t type;/* IN - type of range */ -# define HVMOP_IO_RANGE_PORT 0/* I/O port range */ -# define HVMOP_IO_RANGE_MEMORY 1/* MMIO range */ -# define HVMOP_IO_RANGE_PCI 2/* PCI segment/bus/dev/func range */ uint64_aligned_t start, end;/* IN - inclusive start and end of range */ };typedef struct xen_hvm_io_range xen_hvm_io_range_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_io_range_t); -#define HVMOP_PCI_SBDF (s,b,d,f) \ - ((((s) & 0xffff) << 16) | \ - (((b) & 0xff) << 8) | \ - (((d) & 0x1f) << 3) | \ - ((f) & 0x07)) -/* * HVMOP_destroy_ioreq_server: Destroy the IOREQ Server <id> servicing domain * <domid>.
@@ -383,6 +370,27 @@ struct xen_hvm_set_ioreq_server_state {typedef struct xen_hvm_set_ioreq_server_state xen_hvm_set_ioreq_server_state_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_ioreq_server_state_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ + +/* +* Definitions relating to HVMOP/DMOP_create_ioreq_server. +*/ + +#define HVM_IOREQSRV_BUFIOREQ_OFF DMOP_BUFIOREQ_OFF +#define HVM_IOREQSRV_BUFIOREQ_LEGACY DMOP_BUFIOREQ_LEGACY +#define HVM_IOREQSRV_BUFIOREQ_ATOMIC DMOP_BUFIOREQ_ATOMIC + +/* +* Definitions relating to HVMOP/DMOP_map_io_range_to_ioreq_server and +* HVMOP/DMOP_unmap_io_range_from_ioreq_server +*/ + +#define HVMOP_IO_RANGE_PORT DMOP_IO_RANGE_PORT +#define HVMOP_IO_RANGE_MEMORY DMOP_IO_RANGE_MEMORY +#define HVMOP_IO_RANGE_PCI DMOP_IO_RANGE_PCI + +#define HVMOP_PCI_SBDF DMOP_PCI_SBDF +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ #if defined(__i386__) || defined(__x86_64__)
xen/include/xsm/dummy.h +0 -6
@@ -634,12 +634,6 @@ static XSM_INLINE int xsm_hvm_inject_msi(XSM_DEFAULT_ARG struct domain *d)return xsm_default_action (action, current->domain, d); } -static XSM_INLINE int xsm_hvm_ioreq_server(XSM_DEFAULT_ARG struct domain *d, int op) -{ -XSM_ASSERT_ACTION (XSM_DM_PRIV ); -return xsm_default_action (action, current->domain, d); -} - static XSM_INLINE int xsm_mem_sharing_op(XSM_DEFAULT_ARG struct domain *d, struct domain *cd, int op) {XSM_ASSERT_ACTION (XSM_DM_PRIV );
xen/include/xsm/xsm.h +0 -6
@@ -166,7 +166,6 @@ struct xsm_operations {int (*hvm_set_isa_irq_level) (struct domain *d);int (*hvm_set_pci_link_route) (struct domain *d);int (*hvm_inject_msi) (struct domain *d); -int (*hvm_ioreq_server) (struct domain *d,int op);int (*mem_sharing_op) (struct domain *d,struct domain *cd,int op);int (*apic) (struct domain *d,int cmd);int (*memtype) (uint32_t access);
@@ -656,11 +655,6 @@ static inline int xsm_hvm_inject_msi (xsm_default_t def, struct domain *d)return xsm_ops->hvm_inject_msi (d); } -static inline int xsm_hvm_ioreq_server (xsm_default_t def,struct domain *d,int op) -{ -return xsm_ops->hvm_ioreq_server (d, op); -} -static inline int xsm_mem_sharing_op (xsm_default_t def,struct domain *d,struct domain *cd,int op) {return xsm_ops->mem_sharing_op (d, cd, op);
xen/xsm/dummy.c +0 -1
@@ -149,7 +149,6 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, hvm_set_isa_irq_level);set_to_dummy_if_null (ops, hvm_set_pci_link_route);set_to_dummy_if_null (ops, hvm_inject_msi); -set_to_dummy_if_null (ops, hvm_ioreq_server);set_to_dummy_if_null (ops, mem_sharing_op);set_to_dummy_if_null (ops, apic);set_to_dummy_if_null (ops, machine_memory_map);
xen/xsm/flask/hooks.c +0 -6
@@ -1522,11 +1522,6 @@ static int flask_hvm_inject_msi(struct domain *d)return current_has_perm (d,SECCLASS_HVM ,HVM__SEND_IRQ ); } -static int flask_hvm_ioreq_server (struct domain *d,int op) -{ -return current_has_perm (d,SECCLASS_HVM ,HVM__HVMCTL ); -} -static int flask_mem_sharing_op (struct domain *d,struct domain *cd,int op) {int rc =current_has_perm (cd,SECCLASS_HVM ,HVM__MEM_SHARING );
@@ -1805,7 +1800,6 @@ static struct xsm_operations flask_ops = { .hvm_set_isa_irq_level = flask_hvm_set_isa_irq_level, .hvm_set_pci_link_route = flask_hvm_set_pci_link_route, .hvm_inject_msi = flask_hvm_inject_msi, - .hvm_ioreq_server = flask_hvm_ioreq_server, .mem_sharing_op = flask_mem_sharing_op, .apic = flask_apic, .machine_memory_map = flask_machine_memory_map,
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 2/8] dm_op: convert HVMOP_*ioreq_server*
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
NOTE: The definitions of HVM_IOREQSRV_BUFIOREQ_*, HVMOP_IO_RANGE_* and
HVMOP_PCI_SBDFhave to persist for new interface versions as they are already in use by callers of the libxc interface.
Looking back at my original hvmctl patch, I agree with the first, but where did you find uses of the latter two outside of libxc (IOW what did I overlook back then)? The libxc interfaces, after all, are meant to abstract those away.
Quoted 7 lines
xen/arch/x86/hvm/dm.c +1
-0@@ -102,6 +102,61 @@ long do_dm_op(domid_t domid,switch ( op.op ) { +case DMOP_create_ioreq_server:
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 115
Quoted 10 lines
xen/arch/x86/hvm/dm.c +10
-0+ { +struct domain *curr_d = current->domain; +struct xen_dm_op_create_ioreq_server *data = + &op.u.create_ioreq_server; + + rc =hvm_create_ioreq_server (d, curr_d->domain_id,0 , + data->handle_bufioreq, &data->id); +break ; + } +case DMOP_get_ioreq_server_info:
Blank lines between non-fall-through case statements please.
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 123
Quoted 8 lines
xen/arch/x86/hvm/dm.c +8
-0+ { +struct xen_dm_op_get_ioreq_server_info *data = + &op.u.get_ioreq_server_info; + + rc =hvm_get_ioreq_server_info (d, data->id, + &data->ioreq_pfn, + &data->bufioreq_pfn, + &data->bufioreq_port);
Before the call you should check the __pad field to be zero (presumably also elsewhere).
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 158
Quoted 7 lines
xen/arch/x86/hvm/dm.c +7
-0+case DMOP_destroy_ioreq_server: + { +struct xen_dm_op_destroy_ioreq_server *data = + &op.u.destroy_ioreq_server; + + rc =hvm_destroy_ioreq_server (d, data->id); +break ;
When there are multiple uses of "data" I can see the point of using it to help readability, but here I'm unconvinced.
xen/include/public/hvm/hvm_op.h line 29
Quoted 7 lines
xen/include/public/hvm/hvm_op.h +1
-0@@ -26,6 +26,7 @@#include "../xen.h" #include "../trace.h" #include "../event_channel.h" +#include "dm_op.h"
I'd really wish we could avoid that additional dependency, and I seem to have got away without in my hvmctl series.
xen/include/public/hvm/hvm_op.h
Quoted 9 lines
xen/include/public/hvm/hvm_op.h +9
-0+/* +* DMOP_create_ioreq_server: Instantiate a new IOREQ Server for a secondary +* emulator servicing domain <domid>. +* +* The <id> handed back is unique for <domid>. If <handle_bufioreq> is zero +* the buffered ioreq ring will not be allocated and hence all emulation +* requestes to this server will be synchronous. +*/ +#define DMOP_create_ioreq_server 1
Missing XEN_ prefix.
xen/include/public/hvm/hvm_op.h
Quoted 5 lines
xen/include/public/hvm/hvm_op.h +5
-0+struct xen_dm_op_create_ioreq_server { +/* IN - should server handle buffered ioreqs */ +uint8_t handle_bufioreq; +#define DMOP_BUFIOREQ_OFF 0 +#define DMOP_BUFIOREQ_LEGACY 1
Again (and of course more below).
xen/include/public/hvm/hvm_op.h
Quoted 6 lines
xen/include/public/hvm/hvm_op.h +6
-0+struct xen_dm_op_ioreq_server_range { +/* IN - server id */ +ioservid_t id; +uint16_t __pad; +/* IN - type of range */ +uint32_t type;
Any reason for making this 32 bits wide, instead of 16 (and leaving 32 for future use)?
xen/include/public/hvm/hvm_op.h
Quoted 7 lines
xen/include/public/hvm/hvm_op.h +7
-0+struct xen_dm_op_set_ioreq_server_state { +/* IN - server id */ +ioservid_t id; +uint16_t __pad; +/* IN - enabled? */ +uint8_t enabled; +};
Why 16 bits of padding ahead of an 8-bit field, the more that ioservid_t is also just 16 bits?
Quoted 3 lines
struct xen_dm_op { uint32_t op;+ union {
Even if no current structure needs it, I think we should have a 32-bit padding field ahead of the union right away, to cover (current or future) uint64_aligned_t uses inside the union members.
xen/include/public/hvm/hvm_op.h struct xen_hvm_inject_msi { · line 250
Quoted 9 lines
xen/include/public/hvm/hvm_op.h +2
-0@@ -242,6 +243,8 @@ struct xen_hvm_inject_msi {typedef struct xen_hvm_inject_msi xen_hvm_inject_msi_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_inject_msi_t); +#if __XEN_INTERFACE_VERSION__ <0x00040900 +/* * IOREQ Servers *
This lives inside a __XEN__ / __XEN_TOOLS__ only region, so does not need to be guarded (or the contents preserved).
Quoted 14 lines
xen/include/public/hvm/hvm_op.h +10
-0@@ -383,6 +370,27 @@ struct xen_hvm_set_ioreq_server_state {typedef struct xen_hvm_set_ioreq_server_state xen_hvm_set_ioreq_server_state_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_ioreq_server_state_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ + +/* +* Definitions relating to HVMOP/DMOP_create_ioreq_server. +*/ + +#define HVM_IOREQSRV_BUFIOREQ_OFF DMOP_BUFIOREQ_OFF +#define HVM_IOREQSRV_BUFIOREQ_LEGACY DMOP_BUFIOREQ_LEGACY +#define HVM_IOREQSRV_BUFIOREQ_ATOMIC DMOP_BUFIOREQ_ATOMIC +
xen/include/public/hvm/hvm_op.h struct xen_hvm_set_ioreq_server_state { · line 392
Quoted 10 lines
xen/include/public/hvm/hvm_op.h +10
-0+/* +* Definitions relating to HVMOP/DMOP_map_io_range_to_ioreq_server and +* HVMOP/DMOP_unmap_io_range_from_ioreq_server +*/ + +#define HVMOP_IO_RANGE_PORT DMOP_IO_RANGE_PORT +#define HVMOP_IO_RANGE_MEMORY DMOP_IO_RANGE_MEMORY +#define HVMOP_IO_RANGE_PCI DMOP_IO_RANGE_PCI + +#define HVMOP_PCI_SBDF DMOP_PCI_SBDF
Instead these additions (or, as said above, any parts thereof which really need retaining) should then go into an interface version guarded block, as we don't want new code to use them.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 2/8] dm_op: convert HVMOP_*ioreq_server*
Quoted 11 lines
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 123
Quoted 10 lines
Quoted 2 lines · On 24.11.16 at 18:02, <[email protected]> wrote:
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +8
-0+ { +struct xen_dm_op_get_ioreq_server_info *data = + &op.u.get_ioreq_server_info; + + rc =hvm_get_ioreq_server_info (d, data->id, + &data->ioreq_pfn, + &data->bufioreq_pfn, + &data->bufioreq_port);
Quoted 2 lines
Before the call you should check the
__padfield to be zero (presumably also elsewhere).
And please no double underscores at the beginning of those field names; preferably none at all (as field names may collide with file scope object-like macros).
Quoted 7 lines
Quoted 3 lines
struct xen_dm_op { uint32_t op;+ union {
Even if no current structure needs it, I think we should have a 32-bit padding field ahead of the union right away, to cover (current or future)
uint64_aligned_tuses inside the union members.
Actually I did overlook that the few instances of uint64_aligned_t are in direct union members, not in fields referenced, so this isn't just a "should" really.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 2/8] dm_op: convert HVMOP_*ioreq_server*
Quoted 21 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 07:06
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [Xen-devel] [PATCH-for-4.9 v1 2/8]dm_op: convert HVMOP_*ioreq_server*Quoted 11 lines
Quoted 10 lines
Quoted 2 lines · On 24.11.16 at 18:02, <[email protected]> wrote:
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +8
-0+ { +struct xen_dm_op_get_ioreq_server_info *data = + &op.u.get_ioreq_server_info; + + rc =hvm_get_ioreq_server_info (d, data->id, + &data->ioreq_pfn, + &data->bufioreq_pfn, + &data->bufioreq_port);
Quoted 6 lines
Quoted 2 lines
Before the call you should check the
__padfield to be zero (presumably also elsewhere).And please no double underscores at the beginning of those field names; preferably none at all (as field names may collide with file scope object-like macros).
Ok.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
struct xen_dm_op { uint32_t op;+ union {
Quoted 8 lines
Quoted 3 lines
Even if no current structure needs it, I think we should have a 32-bit padding field ahead of the union right away, to cover (current or future)
uint64_aligned_tuses inside the union members.Actually I did overlook that the few instances of
uint64_aligned_tare in direct union members, not in fields referenced, so this isn't just a "should" really.
Ok, I'll go through and check field alignments again.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 2/8] dm_op: convert HVMOP_*ioreq_server*
In reply to Jan BeulichQuoted 12 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 24 November 2016 17:02
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [Xen-devel] [PATCH-for-4.9 v1 2/8]dm_op: convert HVMOP_*ioreq_server*Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
NOTE: The definitions of HVM_IOREQSRV_BUFIOREQ_*,
Quoted 9 lines
HVMOP_IO_RANGE_* and
Quoted 2 lines
HVMOP_PCI_SBDFhave to persist for new interface versions as they are already in use by callers of the libxc interface.Looking back at my original hvmctl patch, I agree with the first, but where did you find uses of the latter two outside of libxc (IOW what did I overlook back then)? The libxc interfaces, after all, are meant to abstract those away.
You are correct. For some reason I thought the encoding was exposed at the libxc level but it isn't so I can keep the definition inside the #ifdef.
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/hvm/dm.c +0
-0@@ -102,6 +102,61 @@ long do_dm_op(domid_t domid,
Quoted 16 lines
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 115
Quoted 13 lines
xen/arch/x86/hvm/dm.c +11
-0switch ( op.op ) { +case DMOP_create_ioreq_server: + { +struct domain *curr_d = current->domain; +struct xen_dm_op_create_ioreq_server *data = + &op.u.create_ioreq_server; + + rc =hvm_create_ioreq_server (d, curr_d->domain_id,0 , + data->handle_bufioreq, &data->id); +break ; + } +case DMOP_get_ioreq_server_info:Blank lines between non-fall-through case statements please.
Even where there are braces?
Quoted 9 lines
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 123
Quoted 8 lines
xen/arch/x86/hvm/dm.c +8
-0+ { +struct xen_dm_op_get_ioreq_server_info *data = + &op.u.get_ioreq_server_info; + + rc =hvm_get_ioreq_server_info (d, data->id, + &data->ioreq_pfn, + &data->bufioreq_pfn, + &data->bufioreq_port);
Quoted 3 lines
Before the call you should check the
__padfield to be zero (presumably also elsewhere).
Yes, I'll go through and check.
Quoted 10 lines
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 158
Quoted 7 lines
xen/arch/x86/hvm/dm.c +7
-0+case DMOP_destroy_ioreq_server: + { +struct xen_dm_op_destroy_ioreq_server *data = + &op.u.destroy_ioreq_server; + + rc =hvm_destroy_ioreq_server (d, data->id); +break ;When there are multiple uses of "data" I can see the point of using it to help readability, but here I'm unconvinced.
Without it the call to hvm_destroy_ioreq_server() looks unwieldy because the union field specifier makes the line longer than 80 chars. It looked neater this way.
Quoted 12 lines
xen/include/public/hvm/hvm_op.h line 29
Quoted 8 lines
xen/include/public/hvm/hvm_op.h +1
-0@@ -26,6 +26,7 @@#include "../xen.h" #include "../trace.h" #include "../event_channel.h" +#include "dm_op.h" I'd really wish we could avoid that additional dependency, and I seem to have got away without in my hvmctl series.
I can do that but it means I need to typedef ioservid_t in both headers, which I thought was less preferable.
Quoted 6 lines
xen/include/public/hvm/hvm_op.h line 31
Quoted 2 lines
xen/include/public/hvm/hvm_op.h +2
-0+/* +* DMOP_create_ioreq_server: Instantiate a new IOREQ Server for a secondary
xen/include/public/hvm/hvm_op.h
Quoted 3 lines
xen/include/public/hvm/hvm_op.h +3
-0+* emulator servicing domain <domid>. +* +* The <id> handed back is unique for <domid>. If <handle_bufioreq> is
Quoted 8 lines
zero
Quoted 4 lines
+ * the buffered ioreq ring will not be allocated and hence all emulation
+ * requestes to this server will be synchronous.
+ */
+#defineDMOP_create_ioreq_server1Missing
XEN_prefix.
Yep.
Quoted 15 lines
xen/include/public/hvm/hvm_op.h
Quoted 5 lines
xen/include/public/hvm/hvm_op.h +5
-0+struct xen_dm_op_create_ioreq_server { +/* IN - should server handle buffered ioreqs */ +uint8_t handle_bufioreq; +#define DMOP_BUFIOREQ_OFF 0 +#define DMOP_BUFIOREQ_LEGACY 1Again (and of course more below).
xen/include/public/hvm/hvm_op.h
Quoted 6 lines
xen/include/public/hvm/hvm_op.h +6
-0+struct xen_dm_op_ioreq_server_range { +/* IN - server id */ +ioservid_t id; +uint16_t __pad; +/* IN - type of range */ +uint32_t type;
Quoted 3 lines
Any reason for making this 32 bits wide, instead of 16 (and leaving 32 for future use)?
Not really. I could probably shrink it to 8.
Quoted 11 lines
xen/include/public/hvm/hvm_op.h
Quoted 7 lines
xen/include/public/hvm/hvm_op.h +7
-0+struct xen_dm_op_set_ioreq_server_state { +/* IN - server id */ +ioservid_t id; +uint16_t __pad; +/* IN - enabled? */ +uint8_t enabled; +};Why 16 bits of padding ahead of an 8-bit field, the more that
ioservid_tis also just 16 bits?
That's a mistake. I'll drop it.
Quoted 12 lines
Quoted 3 lines
struct xen_dm_op { uint32_t op;+ union {
Even if no current structure needs it, I think we should have a 32-bit padding field ahead of the union right away, to cover (current or future)
uint64_aligned_tuses inside the union members.Quoted 4 lines
xen/include/public/hvm/hvm_op.h +0
-0@@ -242,6 +243,8 @@ struct xen_hvm_inject_msi {typedef struct xen_hvm_inject_msi xen_hvm_inject_msi_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_inject_msi_t);
Quoted 9 lines
xen/include/public/hvm/hvm_op.h struct xen_hvm_inject_msi { · line 250
Quoted 5 lines
xen/include/public/hvm/hvm_op.h +2
-0+#if __XEN_INTERFACE_VERSION__ <0x00040900 +/* * IOREQ Servers * This lives inside a
__XEN__/__XEN_TOOLS__only region, so does not need to be guarded (or the contents preserved).
Ok.
Quoted 19 lines
xen/include/public/hvm/hvm_op.h struct xen_hvm_set_ioreq_server_state { · line 370
Quoted 2 lines
xen/include/public/hvm/hvm_op.h +0
-0@@ -383,6 +370,27 @@ struct xen_hvm_set_ioreq_server_state { typedef struct xen_hvm_set_ioreq_server_state
xen_hvm_set_ioreq_server_state_t;xen/include/public/hvm/hvm_op.h struct xen_hvm_set_ioreq_server_state {
Quoted 11 lines
xen/include/public/hvm/hvm_op.h +9
-0DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_ioreq_server_state_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ + +/* +* Definitions relating to HVMOP/DMOP_create_ioreq_server. +*/ + +#define HVM_IOREQSRV_BUFIOREQ_OFF DMOP_BUFIOREQ_OFF +#define HVM_IOREQSRV_BUFIOREQ_LEGACY DMOP_BUFIOREQ_LEGACY +#define HVM_IOREQSRV_BUFIOREQ_ATOMIC
DMOP_BUFIOREQ_ATOMICxen/include/public/hvm/hvm_op.h struct xen_hvm_set_ioreq_server_state { · line 384
Quoted 3 lines
xen/include/public/hvm/hvm_op.h +3
-0+ +/* +* Definitions relating to HVMOP/DMOP_map_io_range_to_ioreq_server and
Quoted 13 lines
xen/include/public/hvm/hvm_op.h struct xen_hvm_set_ioreq_server_state { · line 392
Quoted 8 lines
xen/include/public/hvm/hvm_op.h +8
-0+* HVMOP/DMOP_unmap_io_range_from_ioreq_server +*/ + +#define HVMOP_IO_RANGE_PORT DMOP_IO_RANGE_PORT +#define HVMOP_IO_RANGE_MEMORY DMOP_IO_RANGE_MEMORY +#define HVMOP_IO_RANGE_PCI DMOP_IO_RANGE_PCI + +#define HVMOP_PCI_SBDF DMOP_PCI_SBDFInstead these additions (or, as said above, any parts thereof which really need retaining) should then go into an interface version guarded block, as we don't want new code to use them.
Ok. Like with the SBDF definition, I mistakenly thought the range definitions were being used outside of libxc. Since they were tools-only, I should be able to drop them.
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 2/8] dm_op: convert HVMOP_*ioreq_server*
Quoted 24 lines
Quoted 8 lines
Quoted 1 line · On 25.11.16 at 10:01, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 24 November 2016 17:02Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +0
-0@@ -102,6 +102,61 @@ long do_dm_op(domid_t domid,Quoted 15 lines
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 115
Quoted 13 lines
xen/arch/x86/hvm/dm.c +11
-0switch ( op.op ) { +case DMOP_create_ioreq_server: + { +struct domain *curr_d = current->domain; +struct xen_dm_op_create_ioreq_server *data = + &op.u.create_ioreq_server; + + rc =hvm_create_ioreq_server (d, curr_d->domain_id,0 , + data->handle_bufioreq, &data->id); +break ; + } +case DMOP_get_ioreq_server_info:Blank lines between non-fall-through case statements please.
Quoted 1 line
Even where there are braces?
Yes please, because the closing brace alone is no indication of whether there is fall-through involved here.
Quoted 11 lines
Quoted 10 lines
xen/include/public/hvm/hvm_op.h line 29
Quoted 7 lines
xen/include/public/hvm/hvm_op.h +1
-0@@ -26,6 +26,7 @@#include "../xen.h" #include "../trace.h" #include "../event_channel.h" +#include "dm_op.h" I'd really wish we could avoid that additional dependency, and I seem to have got away without in my hvmctl series.
Quoted 2 lines
I can do that but it means I need to typedef
ioservid_tin both headers, which I thought was less preferable.
Hmm, are there any uses of that type left in this header after you actually removed everything that doesn't need to be here anymore?
Quoted 11 lines
Quoted 9 lines
xen/include/public/hvm/hvm_op.h
Quoted 6 lines
xen/include/public/hvm/hvm_op.h +6
-0+struct xen_dm_op_ioreq_server_range { +/* IN - server id */ +ioservid_t id; +uint16_t __pad; +/* IN - type of range */ +uint32_t type;Any reason for making this 32 bits wide, instead of 16 (and leaving 32 for future use)?
Not really. I could probably shrink it to 8.
I wouldn't go that far, as then you'd need two padding fields.
Quoted 12 lines
Quoted 11 lines
xen/include/public/hvm/hvm_op.h
Quoted 7 lines
xen/include/public/hvm/hvm_op.h +7
-0+struct xen_dm_op_set_ioreq_server_state { +/* IN - server id */ +ioservid_t id; +uint16_t __pad; +/* IN - enabled? */ +uint8_t enabled; +};Why 16 bits of padding ahead of an 8-bit field, the more that
ioservid_tis also just 16 bits?
Quoted 1 line
That's a mistake. I'll drop it.
s/drop/change/ I suppose, as you'll need to add tail padding?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 2/8] dm_op: convert HVMOP_*ioreq_server*
Quoted 50 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 09:28
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: RE: [Xen-devel] [PATCH-for-4.9 v1 2/8]dm_op: convert HVMOP_*ioreq_server*Quoted 24 lines
Quoted 8 lines
Quoted 1 line · On 25.11.16 at 10:01, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 24 November 2016 17:02Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +0
-0@@ -102,6 +102,61 @@ long do_dm_op(domid_t domid,Quoted 15 lines
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 115
Quoted 13 lines
xen/arch/x86/hvm/dm.c +11
-0switch ( op.op ) { +case DMOP_create_ioreq_server: + { +struct domain *curr_d = current->domain; +struct xen_dm_op_create_ioreq_server *data = + &op.u.create_ioreq_server; + + rc =hvm_create_ioreq_server (d, curr_d->domain_id,0 , + data->handle_bufioreq, &data->id); +break ; + } +case DMOP_get_ioreq_server_info:Blank lines between non-fall-through case statements please.
Quoted 1 line
Even where there are braces?
Yes please, because the closing brace alone is no indication of whether there is fall-through involved here.
Quoted 11 lines
Quoted 10 lines
xen/include/public/hvm/hvm_op.h line 29
Quoted 7 lines
xen/include/public/hvm/hvm_op.h +1
-0@@ -26,6 +26,7 @@#include "../xen.h" #include "../trace.h" #include "../event_channel.h" +#include "dm_op.h" I'd really wish we could avoid that additional dependency, and I seem to have got away without in my hvmctl series.
Quoted 6 lines
Quoted 2 lines
I can do that but it means I need to typedef
ioservid_tin both headers, which I thought was less preferable.Hmm, are there any uses of that type left in this header after you actually removed everything that doesn't need to be here anymore?
Ah true. I was still thinking that I needed to keep the old HVMOPs for compatibility but of course I don't so, yes, I can get rid of the inclusion.
Paul
Quoted 26 lines
Quoted 11 lines
Quoted 9 lines
xen/include/public/hvm/hvm_op.h
Quoted 6 lines
xen/include/public/hvm/hvm_op.h +6
-0+struct xen_dm_op_ioreq_server_range { +/* IN - server id */ +ioservid_t id; +uint16_t __pad; +/* IN - type of range */ +uint32_t type;Any reason for making this 32 bits wide, instead of 16 (and leaving 32 for future use)?
Not really. I could probably shrink it to 8.
I wouldn't go that far, as then you'd need two padding fields.
Quoted 12 lines
Quoted 11 lines
xen/include/public/hvm/hvm_op.h
Quoted 7 lines
xen/include/public/hvm/hvm_op.h +7
-0+struct xen_dm_op_set_ioreq_server_state { +/* IN - server id */ +ioservid_t id; +uint16_t __pad; +/* IN - enabled? */ +uint8_t enabled; +};Why 16 bits of padding ahead of an 8-bit field, the more that
ioservid_tis also just 16 bits?
Quoted 5 lines
Quoted 1 line
That's a mistake. I'll drop it.
s/drop/change/ I suppose, as you'll need to add tail padding?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 3/8 dm_op: convert HVMOP_track_dirty_vram
In reply to Paul DurrantThe patch changes the handle type passed to the underlying shadow and hap functions for compatibility with the new hypercall buffer.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Tim Deegan <[email protected]>
--- tools/flask/policy/modules/xen.if | 4 ++-- tools/libxc/xc_misc.c | 31 ++++++++------------------ xen/arch/x86/hvm/dm.c | 43 +++++++++++++++++++++++++++++++++++-- xen/arch/x86/hvm/hvm.c | 41 ----------------------------------- xen/arch/x86/mm/hap/hap.c | 2 +- xen/arch/x86/mm/shadow/common.c | 2 +- xen/include/asm-x86/hap.h | 2 +- xen/include/asm-x86/shadow.h | 2 +- xen/include/public/hvm/dm_op.h | 16 ++++++++++++++ xen/include/public/hvm/hvm_op.h | 4 ++++ xen/xsm/flask/hooks.c | 3 --- xen/xsm/flask/policy/access_vectors | 2 -- 12 files changed, 76 insertions(+), 76 deletions(-)
tools/flask/policy/modules/xen.if +2 -2
@@ -58,7 +58,7 @@ define(`create_domain_common', ` allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp }; allow $1 $2:grant setup; allow $1 $2:hvm { cacheattr getparam hvmctl irqlevel pciroute sethvmc - setparam pcilevel trackdirtyvram nested altp2mhvm altp2mhvm_op }; + setparam pcilevel nested altp2mhvm altp2mhvm_op }; ') # create_domain(priv, target)
@@ -151,7 +151,7 @@ define(`device_model', ` allow $1 $2_target:domain { getdomaininfo shutdown }; allow $1 $2_target:mmu { map_read map_write adjust physmap target_hack }; - allow $1 $2_target:hvm { getparam setparam trackdirtyvram hvmctl irqlevel pciroute pcilevel cacheattr send_irq dm }; + allow $1 $2_target:hvm { getparam setparam hvmctl irqlevel pciroute pcilevel cacheattr send_irq dm }; ') # make_device_model(priv, dm_dom, hvm_dom)
tools/libxc/xc_misc.c +9 -22
@@ -584,31 +584,18 @@ int xc_hvm_track_dirty_vram( uint64_t first_pfn, uint64_t nr, unsigned long *dirty_bitmap) { - DECLARE_HYPERCALL_BOUNCE(dirty_bitmap, (nr+7) / 8, XC_HYPERCALL_BUFFER_BOUNCE_OUT); - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_track_dirty_vram, arg); -int rc; + struct xen_dm_op op; +struct xen_dm_op_track_dirty_vram *data; - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ||xc_hypercall_bounce_pre (xch, dirty_bitmap) ) - { -PERROR ("Could not bounce memory for xc_hvm_track_dirty_vram hypercall" ); - rc =-1 ; - goto out; - } - - arg->domid = dom; - arg->first_pfn = first_pfn; - arg->nr = nr; -set_xen_guest_handle (arg->dirty_bitmap, dirty_bitmap); + op.op = DMOP_track_dirty_vram; + data = &op.u.track_dirty_vram; - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_track_dirty_vram, -HYPERCALL_BUFFER_AS_ARG (arg)); + data->first_pfn = first_pfn; +/* NOTE: The following assignment truncates nr to 32-bits */ + data->nr = nr; -out: -xc_hypercall_buffer_free (xch, arg); -xc_hypercall_bounce_post (xch, dirty_bitmap); -return rc; +return do_dm_op (xch, dom,2 , &op,sizeof (op), + dirty_bitmap, (nr +7 ) /8 ); } int xc_hvm_modified_memory(
xen/arch/x86/hvm/dm.c +41 -2
71 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +0 -41
47 lines not on this page · raw message
xen/arch/x86/mm/hap/hap.c +1 -1
@@ -68,7 +68,7 @@int hap_track_dirty_vram (struct domain *d,unsigned long begin_pfn,unsigned long nr, -XEN_GUEST_HANDLE_64 (uint8) guest_dirty_bitmap) +XEN_GUEST_HANDLE_PARAM (void ) guest_dirty_bitmap) {long rc =0 ;struct sh_dirty_vram *dirty_vram;
xen/arch/x86/mm/shadow/common.c +1 -1
@@ -3677,7 +3677,7 @@ static void sh_clean_dirty_bitmap(struct domain *d)int shadow_track_dirty_vram (struct domain *d,unsigned long begin_pfn,unsigned long nr, -XEN_GUEST_HANDLE_64 (uint8) guest_dirty_bitmap) +XEN_GUEST_HANDLE_PARAM (void ) guest_dirty_bitmap) {int rc =0 ;unsigned long end_pfn = begin_pfn + nr;
xen/include/asm-x86/hap.h +1 -1
@@ -43,7 +43,7 @@ void hap_vcpu_init(struct vcpu *v);int hap_track_dirty_vram (struct domain *d,unsigned long begin_pfn,unsigned long nr, -XEN_GUEST_HANDLE_64 (uint8) dirty_bitmap); +XEN_GUEST_HANDLE_PARAM (void ) dirty_bitmap);extern const struct paging_mode *hap_paging_get_mode (struct vcpu *);void hap_set_alloc_for_pvh_dom0 (struct domain *d,unsigned long num_pages);
xen/include/asm-x86/shadow.h +1 -1
@@ -63,7 +63,7 @@ int shadow_enable(struct domain *d, u32 mode);int shadow_track_dirty_vram (struct domain *d,unsigned long first_pfn,unsigned long nr, -XEN_GUEST_HANDLE_64 (uint8) dirty_bitmap); +XEN_GUEST_HANDLE_PARAM (void ) dirty_bitmap);/* Handler for shadow control ops: operations from user-space to enable * and disable ephemeral shadow modes (test mode and log-dirty mode) and
xen/include/public/hvm/dm_op.h +16 -0
@@ -179,6 +179,21 @@ struct xen_dm_op_destroy_ioreq_server {ioservid_t id; }; +/* +* DMOP_track_dirty_vram: Track modifications to the specified pfn range. +* +* NOTE: The bitmap passed back to the caller is passed in a +* secondary buffer. +*/ +#define DMOP_track_dirty_vram 7 + +struct xen_dm_op_track_dirty_vram { +/* IN - number of pages to be tracked */ +uint32_t nr; +/* IN - first pfn to track */ +uint64_aligned_t first_pfn; +}; +struct xen_dm_op {uint32_t op;union {
@@ -188,6 +203,7 @@ struct xen_dm_op {struct xen_dm_op_ioreq_server_range unmap_io_range_from_ioreq_server;struct xen_dm_op_set_ioreq_server_state set_ioreq_server_state;struct xen_dm_op_destroy_ioreq_server destroy_ioreq_server; +struct xen_dm_op_track_dirty_vram track_dirty_vram; } u; };
xen/include/public/hvm/hvm_op.h +4 -0
@@ -96,6 +96,8 @@ typedef enum {/* Following tools-only interfaces may change in future. */ #if defined(__XEN__) || defined(__XEN_TOOLS__) +#if __XEN_INTERFACE_VERSION__ <0x00040900 +/* Track dirty VRAM. */ #define HVMOP_track_dirty_vram 6 struct xen_hvm_track_dirty_vram {
@@ -112,6 +114,8 @@ struct xen_hvm_track_dirty_vram {typedef struct xen_hvm_track_dirty_vram xen_hvm_track_dirty_vram_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_track_dirty_vram_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ +/* Notify that some pages got modified by the Device Model. */ #define HVMOP_modified_memory 7struct xen_hvm_modified_memory {
xen/xsm/flask/hooks.c +0 -3
@@ -1177,9 +1177,6 @@ static int flask_hvm_param(struct domain *d, unsigned long op)case HVMOP_get_param: perm =HVM__GETPARAM ;break ; -case HVMOP_track_dirty_vram: - perm =HVM__TRACKDIRTYVRAM ; -break ;default : perm =HVM__HVMCTL ; }
xen/xsm/flask/policy/access_vectors +0 -2
@@ -266,8 +266,6 @@ class hvm bind_irq # XEN_DOMCTL_pin_mem_cacheattr cacheattr -# HVMOP_track_dirty_vram - trackdirtyvram # HVMOP_modified_memory, HVMOP_get_mem_type, HVMOP_set_mem_type, # HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying, # HVMOP_inject_trap
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 3/8] dm_op: convert HVMOP_track_dirty_vram
xen/arch/x86/hvm/dm.c static int dm_op_copy_buf_to_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs, · line 81
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +3
-0@@ -74,6 +76,35 @@ static int dm_op_copy_buf_to_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs,return 0 ; } +static int dm_op_track_dirty_vram(struct domain *d, + unsigned int nr_bufs, + XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs,
Wouldn't it be more natural for the caller to pass in a pointer to the already retrieved struct xen_dm_op_buf? The function here has in particular no other use for nr_bufs.
xen/arch/x86/hvm/dm.c static int dm_op_copy_buf_to_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs, · line 87
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+ xen_pfn_t first_pfn, unsigned int nr) +{ +struct xen_dm_op_buf buf; +int rc; + +if ( nr >GB (1 ) >>PAGE_SHIFT )
Please parenthesize the operands of >>.
xen/arch/x86/hvm/dm.c static int dm_op_copy_buf_to_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs, · line 93
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+return -EINVAL ; + +if ( d->is_dying ) +return -ESRCH ; + +if ( d->vcpu ==NULL || d->vcpu[0 ] ==NULL )
I'd appreciate if you used ! in cases like these. Also the left side should check d->max_vcpus, to be more in line with the checking done elsewhere (albeit I agree we're not consistent with this yet).
Quoted 10 lines
xen/arch/x86/hvm/dm.c +6
-0@@ -157,11 +188,19 @@ long do_dm_op(domid_t domid, rc =hvm_destroy_ioreq_server (d, data->id);break ; } +case DMOP_track_dirty_vram: + { +struct xen_dm_op_track_dirty_vram *data = + &op.u.track_dirty_vram; + + rc = dm_op_track_dirty_vram(d, nr_bufs, bufs, data->first_pfn,
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 205
Quoted 10 lines
xen/arch/x86/hvm/dm.c +3
-1+ data->nr); +break ; + }default : rc = -EOPNOTSUPP ;break ; } -if ( rc == -ERESTART ) restart = true;
Stray removal of a (imo useful) blank line.
xen/arch/x86/hvm/dm.c out: · line 220
Quoted 6 lines
xen/arch/x86/hvm/dm.c +1
-1@@ -178,7 +217,7 @@ out: domid, nr_bufs, bufs);return rc; -} + }
???
Quoted 10 lines
xen/include/public/hvm/dm_op.h +4
-0@@ -179,6 +179,21 @@ struct xen_dm_op_destroy_ioreq_server {ioservid_t id; }; +/* +* DMOP_track_dirty_vram: Track modifications to the specified pfn range. +* +* NOTE: The bitmap passed back to the caller is passed in a
xen/include/public/hvm/dm_op.h struct xen_dm_op_destroy_ioreq_server { · line 195
Quoted 10 lines
xen/include/public/hvm/dm_op.h +10
-0+* secondary buffer. +*/ +#define DMOP_track_dirty_vram 7 + +struct xen_dm_op_track_dirty_vram { +/* IN - number of pages to be tracked */ +uint32_t nr; +/* IN - first pfn to track */ +uint64_aligned_t first_pfn; +};
Missing explicit padding (as well as the check for it to be zero).
Quoted 12 lines
xen/include/public/hvm/hvm_op.h +2
-0@@ -96,6 +96,8 @@ typedef enum {/* Following tools-only interfaces may change in future. */ #if defined(__XEN__) || defined(__XEN_TOOLS__) +#if __XEN_INTERFACE_VERSION__ <0x00040900 +/* Track dirty VRAM. */ #define HVMOP_track_dirty_vram 6 struct xen_hvm_track_dirty_vram {
xen/include/public/hvm/hvm_op.h struct xen_hvm_track_dirty_vram { · line 117
Quoted 4 lines
xen/include/public/hvm/hvm_op.h +1
-0@@ -112,6 +114,8 @@ struct xen_hvm_track_dirty_vram {typedef struct xen_hvm_track_dirty_vram xen_hvm_track_dirty_vram_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_track_dirty_vram_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */
Same as in the earlier patch - these don't need to be retained. I guess I'll refrain from mentioning this and the padding thing again, should they re-occur in subsequent patches.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 3/8] dm_op: convert HVMOP_track_dirty_vram
Quoted 18 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 11:26
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; Daniel De Graaf <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: Re: [Xen-devel] [PATCH-for-4.9 v1 3/8]dm_op: convertHVMOP_track_dirty_vramReview static int
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:13, <[email protected]> wrote:
(quoted diff) +0
-0@@ -74,6 +76,35 @@ static intdm_op_copy_buf_to_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_bu
f_t) bufs,Quoted 3 lines
xen/arch/x86/hvm/dm.c +0
-0return 0 ; }
Quoted 7 lines
xen/arch/x86/hvm/dm.c static int dm_op_copy_buf_to_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs, · line 81
Quoted 3 lines
xen/arch/x86/hvm/dm.c +3
-0+static int dm_op_track_dirty_vram(struct domain *d, + unsigned int nr_bufs, + XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs,Wouldn't it be more natural for the caller to pass in a pointer to the already retrieved struct
xen_dm_op_buf? The function here has in particular no other use fornr_bufs.
I could do it that way but I think it makes the switch statement in do_dm_op() more cluttered.
Quoted 10 lines
xen/arch/x86/hvm/dm.c static int dm_op_copy_buf_to_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs, · line 87
Quoted 7 lines
xen/arch/x86/hvm/dm.c +6
-0+ xen_pfn_t first_pfn, unsigned int nr) +{ +struct xen_dm_op_buf buf; +int rc; + +if ( nr >GB (1 ) >>PAGE_SHIFT )Please parenthesize the operands of >>.
Ok.
Quoted 10 lines
xen/arch/x86/hvm/dm.c static int dm_op_copy_buf_to_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs, · line 93
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+return -EINVAL ; + +if ( d->is_dying ) +return -ESRCH ; + +if ( d->vcpu ==NULL || d->vcpu[0 ] ==NULL )I'd appreciate if you used ! in cases like these. Also the left side should check
d->max_vcpus, to be more in line with the checking done elsewhere (albeit I agree we're not consistent with this yet).
Sure.
Quoted 15 lines
Quoted 15 lines
xen/arch/x86/hvm/dm.c +9
-0@@ -157,11 +188,19 @@ long do_dm_op(domid_t domid, rc =hvm_destroy_ioreq_server (d, data->id);break ; } +case DMOP_track_dirty_vram: + { +struct xen_dm_op_track_dirty_vram *data = + &op.u.track_dirty_vram; + + rc =dm_op_track_dirty_vram (d, nr_bufs, bufs, data->first_pfn, + data->nr); +break ; + }default :
Quoted 9 lines
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 205
Quoted 6 lines
xen/arch/x86/hvm/dm.c +0
-1rc = -EOPNOTSUPP ;break ; } -if ( rc == -ERESTART ) restart = true;Stray removal of a (imo useful) blank line.
Yep. That should not have happened.
Quoted 8 lines
xen/arch/x86/hvm/dm.c out: · line 220
Quoted 6 lines
xen/arch/x86/hvm/dm.c +1
-1@@ -178,7 +217,7 @@ out: domid, nr_bufs, bufs);return rc; -} + }???
Yes, weird. Emacs must have decided to indent it for some reason.
Quoted 10 lines
xen/include/public/hvm/dm_op.h struct xen_dm_op_destroy_ioreq_server { · line 183
Quoted 9 lines
xen/include/public/hvm/dm_op.h +2
-0@@ -179,6 +179,21 @@ struct xen_dm_op_destroy_ioreq_server {ioservid_t id; }; +/* +* DMOP_track_dirty_vram: Track modifications to the specified pfn range.
Quoted 14 lines
xen/include/public/hvm/dm_op.h struct xen_dm_op_destroy_ioreq_server { · line 195
Quoted 12 lines
xen/include/public/hvm/dm_op.h +12
-0+* +* NOTE: The bitmap passed back to the caller is passed in a +* secondary buffer. +*/ +#define DMOP_track_dirty_vram 7 + +struct xen_dm_op_track_dirty_vram { +/* IN - number of pages to be tracked */ +uint32_t nr; +/* IN - first pfn to track */ +uint64_aligned_t first_pfn; +};Missing explicit padding (as well as the check for it to be zero).
Ok.
Quoted 16 lines
Quoted 16 lines
xen/include/public/hvm/hvm_op.h +2
-0@@ -96,6 +96,8 @@ typedef enum {/* Following tools-only interfaces may change in future. */ #if defined(__XEN__) || defined(__XEN_TOOLS__) +#if __XEN_INTERFACE_VERSION__ <0x00040900 +/* Track dirty VRAM. */ #define HVMOP_track_dirty_vram 6 struct xen_hvm_track_dirty_vram {@@ -112,6 +114,8 @@ struct xen_hvm_track_dirty_vram {typedef struct xen_hvm_track_dirty_vram xen_hvm_track_dirty_vram_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_track_dirty_vram_t);
Quoted 5 lines
xen/include/public/hvm/hvm_op.h struct xen_hvm_track_dirty_vram { · line 117
Quoted 1 line
xen/include/public/hvm/hvm_op.h +1
-0+#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ Same as in the earlier patch - these don't need to be retained. I guess I'll refrain from mentioning this and the padding thing again, should they re-occur in subsequent patches.
Indeed. I'll check what was and wasn't tools-only and bin anything that wasn't exposed to a guest.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 4/8 dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level, and...
In reply to Paul Durrant... HVMOP_set_pci_link_route
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
--- tools/flask/policy/modules/xen.if | 8 +-- tools/libxc/xc_misc.c | 81 +++++++-------------- xen/arch/x86/hvm/dm.c | 80 +++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 136 ------------------------------------ xen/include/public/hvm/dm_op.h | 42 +++++++++++ xen/include/public/hvm/hvm_op.h | 4 ++ xen/include/xsm/dummy.h | 18 ----- xen/include/xsm/xsm.h | 18 ----- xen/xsm/dummy.c | 3 - xen/xsm/flask/hooks.c | 15 ---- xen/xsm/flask/policy/access_vectors | 6 -- 11 files changed, 154 insertions(+), 257 deletions(-)
tools/flask/policy/modules/xen.if +4 -4
@@ -57,8 +57,8 @@ define(`create_domain_common', ` allow $1 $2:shadow enable; allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp }; allow $1 $2:grant setup; - allow $1 $2:hvm { cacheattr getparam hvmctl irqlevel pciroute sethvmc - setparam pcilevel nested altp2mhvm altp2mhvm_op }; + allow $1 $2:hvm { cacheattr getparam hvmctl sethvmc + setparam nested altp2mhvm altp2mhvm_op }; ') # create_domain(priv, target)
@@ -93,7 +93,7 @@ define(`manage_domain', ` # (inbound migration is the same as domain creation) define(`migrate_domain_out', ` allow $1 domxen_t:mmu map_read; - allow $1 $2:hvm { gethvmc getparam irqlevel }; + allow $1 $2:hvm { gethvmc getparam }; allow $1 $2:mmu { stat pageinfo map_read }; allow $1 $2:domain { getaddrsize getvcpucontext pause destroy }; allow $1 $2:domain2 gettsc;
@@ -151,7 +151,7 @@ define(`device_model', ` allow $1 $2_target:domain { getdomaininfo shutdown }; allow $1 $2_target:mmu { map_read map_write adjust physmap target_hack }; - allow $1 $2_target:hvm { getparam setparam hvmctl irqlevel pciroute pcilevel cacheattr send_irq dm }; + allow $1 $2_target:hvm { getparam setparam hvmctl cacheattr send_irq dm }; ') # make_device_model(priv, dm_dom, hvm_dom)
tools/libxc/xc_misc.c +24 -57
107 lines not on this page · raw message
xen/arch/x86/hvm/dm.c +80 -0
92 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +0 -136
159 lines not on this page · raw message
xen/include/public/hvm/dm_op.h +42 -0
54 lines not on this page · raw message
xen/include/public/hvm/hvm_op.h +4 -0
@@ -39,6 +39,8 @@ struct xen_hvm_param {typedef struct xen_hvm_param xen_hvm_param_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_param_t); +#if __XEN_INTERFACE_VERSION__ <0x00040900 +/* Set the logical level of one of a domain's PCI INTx wires. */ #define HVMOP_set_pci_intx_level 2 struct xen_hvm_set_pci_intx_level {
@@ -77,6 +79,8 @@ struct xen_hvm_set_pci_link_route {typedef struct xen_hvm_set_pci_link_route xen_hvm_set_pci_link_route_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_pci_link_route_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ +/* Flushes all VCPU TLBs: @arg must be NULL. */ #define HVMOP_flush_tlbs 5
xen/include/xsm/dummy.h +0 -18
@@ -610,24 +610,6 @@ static XSM_INLINE int xsm_shadow_control(XSM_DEFAULT_ARG struct domain *d, uint3return xsm_default_action (action, current->domain, d); } -static XSM_INLINE int xsm_hvm_set_pci_intx_level(XSM_DEFAULT_ARG struct domain *d) -{ -XSM_ASSERT_ACTION (XSM_DM_PRIV ); -return xsm_default_action (action, current->domain, d); -} - -static XSM_INLINE int xsm_hvm_set_isa_irq_level(XSM_DEFAULT_ARG struct domain *d) -{ -XSM_ASSERT_ACTION (XSM_DM_PRIV ); -return xsm_default_action (action, current->domain, d); -} - -static XSM_INLINE int xsm_hvm_set_pci_link_route(XSM_DEFAULT_ARG struct domain *d) -{ -XSM_ASSERT_ACTION (XSM_DM_PRIV ); -return xsm_default_action (action, current->domain, d); -} - static XSM_INLINE int xsm_hvm_inject_msi(XSM_DEFAULT_ARG struct domain *d) {XSM_ASSERT_ACTION (XSM_DM_PRIV );
xen/include/xsm/xsm.h +0 -18
@@ -162,9 +162,6 @@ struct xsm_operations {#ifdef CONFIG_X86 int (*do_mca) (void );int (*shadow_control) (struct domain *d,uint32_t op); -int (*hvm_set_pci_intx_level) (struct domain *d); -int (*hvm_set_isa_irq_level) (struct domain *d); -int (*hvm_set_pci_link_route) (struct domain *d);int (*hvm_inject_msi) (struct domain *d);int (*mem_sharing_op) (struct domain *d,struct domain *cd,int op);int (*apic) (struct domain *d,int cmd);
@@ -635,21 +632,6 @@ static inline int xsm_shadow_control (xsm_default_t def, struct domain *d, uint3return xsm_ops->shadow_control (d, op); } -static inline int xsm_hvm_set_pci_intx_level (xsm_default_t def,struct domain *d) -{ -return xsm_ops->hvm_set_pci_intx_level (d); -} - -static inline int xsm_hvm_set_isa_irq_level (xsm_default_t def,struct domain *d) -{ -return xsm_ops->hvm_set_isa_irq_level (d); -} - -static inline int xsm_hvm_set_pci_link_route (xsm_default_t def,struct domain *d) -{ -return xsm_ops->hvm_set_pci_link_route (d); -} -static inline int xsm_hvm_inject_msi (xsm_default_t def,struct domain *d) {return xsm_ops->hvm_inject_msi (d);
xen/xsm/dummy.c +0 -3
@@ -145,9 +145,6 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)#ifdef CONFIG_X86 set_to_dummy_if_null (ops, do_mca);set_to_dummy_if_null (ops, shadow_control); -set_to_dummy_if_null (ops, hvm_set_pci_intx_level); -set_to_dummy_if_null (ops, hvm_set_isa_irq_level); -set_to_dummy_if_null (ops, hvm_set_pci_link_route);set_to_dummy_if_null (ops, hvm_inject_msi);set_to_dummy_if_null (ops, mem_sharing_op);set_to_dummy_if_null (ops, apic);
xen/xsm/flask/hooks.c +0 -15
@@ -1499,21 +1499,6 @@ static int flask_ioport_mapping(struct domain *d, uint32_t start, uint32_t end,return flask_ioport_permission (d, start, end, access); } -static int flask_hvm_set_pci_intx_level (struct domain *d) -{ -return current_has_perm (d,SECCLASS_HVM ,HVM__PCILEVEL ); -} - -static int flask_hvm_set_isa_irq_level (struct domain *d) -{ -return current_has_perm (d,SECCLASS_HVM ,HVM__IRQLEVEL ); -} - -static int flask_hvm_set_pci_link_route (struct domain *d) -{ -return current_has_perm (d,SECCLASS_HVM ,HVM__PCIROUTE ); -} -static int flask_hvm_inject_msi (struct domain *d) {return current_has_perm (d,SECCLASS_HVM ,HVM__SEND_IRQ );
xen/xsm/flask/policy/access_vectors +0 -6
@@ -257,12 +257,6 @@ class hvm setparam # HVMOP_get_param getparam -# HVMOP_set_pci_intx_level (also needs hvmctl) - pcilevel -# HVMOP_set_isa_irq_level - irqlevel -# HVMOP_set_pci_link_route - pciroute bind_irq # XEN_DOMCTL_pin_mem_cacheattr cacheattr
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 4/8] dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level, and...
xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain *d, · line 110
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +3
-0@@ -105,6 +105,60 @@ static int dm_op_track_dirty_vram(struct domain *d,hap_track_dirty_vram (d, first_pfn, nr, buf.h); } +static int dm_op_set_pci_intx_level (struct domain *d,uint8_t domain, +uint8_t bus,uint8_t device, +uint8_t intx,uint8_t level)
Btw., none of these static helper functions have any need to have a dm_op_ prefix. Such disambiguation is needed only for non- static ones.
xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain *d, · line 160
Quoted 10 lines
xen/arch/x86/hvm/dm.c +10
-0+static int dm_op_set_pci_link_route (struct domain *d,uint8_t link, +uint8_t isa_irq) +{ +if ( link >3 || isa_irq >15 ) +return -EINVAL ; + +hvm_set_pci_link_route (d, link, isa_irq); + +return 0 ; +}
In the hvmctl series I did specifically avoid to create this trivial a wrapper for a function with no other callers. Simply move the argument range checks there.
xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain *d, · line 123
Quoted 3 lines
xen/arch/x86/hvm/dm.c +3
-0+struct xen_dm_op_set_pci_intx_level { +/* IN - PCI INTx identification (domain:bus:device:intx) */ +uint8_t domain, bus, device, intx;
I've just now noticed that I did overlook this in the hvmctl series
too: domain should be uint16_t.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 4/8] dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level, and...
Quoted 18 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 11:50
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [Xen-devel] [PATCH-for-4.9 v1 4/8]dm_op: convertHVMOP_set_pci_intx_level,HVMOP_set_isa_irq_level, and...xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +0
-0@@ -105,6 +105,60 @@ static int dm_op_track_dirty_vram(struct domain*d,
Quoted 3 lines
xen/arch/x86/hvm/dm.c +0
-0hap_track_dirty_vram (d, first_pfn, nr, buf.h); }
Quoted 7 lines
xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain *d, · line 110
Quoted 3 lines
xen/arch/x86/hvm/dm.c +3
-0+static int dm_op_set_pci_intx_level (struct domain *d,uint8_t domain, +uint8_t bus,uint8_t device, +uint8_t intx,uint8_t level)Btw., none of these static helper functions have any need to have a
dm_op_prefix. Such disambiguation is needed only for non- static ones.
It make it easier to find them quickly with cscope, but I can drop the prefix if you prefer.
Quoted 16 lines
xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain *d, · line 160
Quoted 11 lines
xen/arch/x86/hvm/dm.c +10
-0+static int dm_op_set_pci_link_route (struct domain *d,uint8_t link, +uint8_t isa_irq) +{ +if ( link >3 || isa_irq >15 ) +return -EINVAL ; + +hvm_set_pci_link_route (d, link, isa_irq); + +return 0 ; +}In the hvmctl series I did specifically avoid to create this trivial a wrapper for a function with no other callers. Simply move the argument range checks there.
Ok, I'll inline in the switch if you prefer that style.
Quoted 7 lines
xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain · line 123
Quoted 3 lines
xen/arch/x86/hvm/dm.c +3
-0+struct xen_dm_op_set_pci_intx_level { +/* IN - PCI INTx identification (domain:bus:device:intx) */ +uint8_t domain, bus, device, intx;I've just now noticed that I did overlook this in the hvmctl series
too: domain should beuint16_t.
Indeed it should.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 4/8] dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level, and...
Quoted 23 lines
Quoted 23 lines
Quoted 1 line · On 25.11.16 at 12:55, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 11:50
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [Xen-devel] [PATCH-for-4.9 v1 4/8]dm_op: convertHVMOP_set_pci_intx_level,HVMOP_set_isa_irq_level, and...xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +0
-0@@ -105,6 +105,60 @@ static int dm_op_track_dirty_vram(struct domain*d,
Quoted 6 lines
xen/arch/x86/hvm/dm.c +3
-0hap_track_dirty_vram (d, first_pfn, nr, buf.h); } +static int dm_op_set_pci_intx_level (struct domain *d,uint8_t domain, +uint8_t bus,uint8_t device, +uint8_t intx,uint8_t level)
Quoted 6 lines
Quoted 3 lines
Btw., none of these static helper functions have any need to have a
dm_op_prefix. Such disambiguation is needed only for non- static ones.It make it easier to find them quickly with cscope, but I can drop the prefix if you prefer.
Thanks.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+static int dm_op_set_pci_link_route (struct domain *d,uint8_t link, +uint8_t isa_irq) +{ +if ( link >3 || isa_irq >15 ) +return -EINVAL ; +Quoted 8 lines
xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain *d, · line 160
Quoted 4 lines
xen/arch/x86/hvm/dm.c +4
-0+hvm_set_pci_link_route (d, link, isa_irq); + +return 0 ; +}In the hvmctl series I did specifically avoid to create this trivial a wrapper for a function with no other callers. Simply move the argument range checks there.
Quoted 1 line
Ok, I'll inline in the switch if you prefer that style.
I didn't mean to inline the above in the case statement, but to move the argument checking to hvm_set_pci_link_route() (and call it directly from the case statement).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 4/8] dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level, and...
Quoted 1 line
-----Original Message-----
[snip]
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
xen/arch/x86/hvm/dm.c static int dm_op_track_dirty_vram(struct domain *d, · line 160
Quoted 10 lines
xen/arch/x86/hvm/dm.c +10
-0+static int dm_op_set_pci_link_route (struct domain *d,uint8_t link, +uint8_t isa_irq) +{ +if ( link >3 || isa_irq >15 ) +return -EINVAL ; + +hvm_set_pci_link_route (d, link, isa_irq); + +return 0 ; +}In the hvmctl series I did specifically avoid to create this trivial a wrapper for a function with no other callers. Simply move the argument range checks there.
Quoted 6 lines
Quoted 1 line
Ok, I'll inline in the switch if you prefer that style.
I didn't mean to inline the above in the case statement, but to move the argument checking to
hvm_set_pci_link_route()(and call it directly from the case statement).
Oh, I see. Yes, that would be much better.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 5/8 dm_op: convert HVMOP_modified_memory
In reply to Paul Durrant---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Daniel De Graaf <[email protected]>
--- tools/libxc/xc_misc.c | 26 +++++----------- xen/arch/x86/hvm/dm.c | 54 +++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 60 ------------------------------------- xen/include/public/hvm/dm_op.h | 14 +++++++++ xen/include/public/hvm/hvm_op.h | 4 +-- xen/xsm/flask/policy/access_vectors | 2 +- 6 files changed, 79 insertions(+), 81 deletions(-)
tools/libxc/xc_misc.c +8 -18
@@ -568,27 +568,17 @@ int xc_hvm_track_dirty_vram(int xc_hvm_modified_memory (xc_interface *xch,domid_t dom,uint64_t first_pfn,uint64_t nr) { - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_modified_memory, arg); -int rc; - - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) - { -PERROR ("Could not allocate memory for xc_hvm_modified_memory hypercall" ); -return -1 ; - } +struct xen_dm_op op; +struct xen_dm_op_modified_memory *data; - arg->domid = dom; - arg->first_pfn = first_pfn; - arg->nr = nr; + op.op = DMOP_modified_memory; + data = &op.u.modified_memory; - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_modified_memory, -HYPERCALL_BUFFER_AS_ARG (arg)); - -xc_hypercall_buffer_free (xch, arg); + data->first_pfn = first_pfn; +/* NOTE: The following assignment truncates nr to 32-bits */ + data->nr = nr; -return rc; +return do_dm_op (xch, dom,1 , &op,sizeof (op)); } int xc_hvm_set_mem_type(
xen/arch/x86/hvm/dm.c +54 -0
72 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +0 -60
72 lines not on this page · raw message
xen/include/public/hvm/dm_op.h +14 -0
@@ -232,6 +232,19 @@ struct xen_dm_op_set_pci_link_route {uint8_t isa_irq; }; +/* +* DMOP_modified_memory: Notify that some pages were modified by an +* emulator. +*/ +#define DMOP_modified_memory 11 + +struct xen_dm_op_modified_memory { +/* IN - number of contiguous pages modified */ +uint32_t nr; +/* IN - first pfn modified */ +uint64_t first_pfn; +}; +struct xen_dm_op {uint32_t op;
@@ -246,6 +259,7 @@ struct xen_dm_op {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_pci_link_route set_pci_link_route; +struct xen_dm_op_modified_memory modified_memory; } u; };
xen/include/public/hvm/hvm_op.h +2 -2
@@ -118,8 +118,6 @@ struct xen_hvm_track_dirty_vram {typedef struct xen_hvm_track_dirty_vram xen_hvm_track_dirty_vram_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_track_dirty_vram_t); -#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ -/* Notify that some pages got modified by the Device Model. */ #define HVMOP_modified_memory 7struct xen_hvm_modified_memory {
@@ -133,6 +131,8 @@ struct xen_hvm_modified_memory {typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_modified_memory_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ +#define HVMOP_set_mem_type 8/* Notify that a region of memory is to be treated in a specific way. */ struct xen_hvm_set_mem_type {
xen/xsm/flask/policy/access_vectors +1 -1
@@ -260,7 +260,7 @@ class hvm bind_irq # XEN_DOMCTL_pin_mem_cacheattr cacheattr -# HVMOP_modified_memory, HVMOP_get_mem_type, HVMOP_set_mem_type, +# HVMOP_get_mem_type, HVMOP_set_mem_type, # HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying, # HVMOP_inject_trap hvmctl
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 5/8] dm_op: convert HVMOP_modified_memory
xen/arch/x86/hvm/dm.c line 20
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +1
-0@@ -17,6 +17,7 @@#include <xen/hypercall.h> #include <xen/guest_access.h> #include <xen/sched.h> +#include <xen/event.h>
I should have notice before, but it's more evident here: May I ask that you sort the xen/ and asm/ subgroups, rather than always appending at the respective one's end? With sorted #include directives the risk of merge conflicts reduces statistically.
Quoted 17 lines
xen/arch/x86/hvm/dm.c +17
-0+static int dm_op_modified_memory (struct domain *d,xen_pfn_t *first_pfn, +unsigned int *nr) +{ +xen_pfn_t last_pfn = *first_pfn + *nr -1 ; +unsigned int iter; +int rc; + +if ( (*first_pfn > last_pfn) || + (last_pfn >domain_get_maximum_gpfn (d)) ) +return -EINVAL ; + +if ( !paging_mode_log_dirty (d) ) +return 0 ; + + iter =0 ; + rc =0 ; +while ( iter < *nr )
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 189
Quoted 10 lines
xen/arch/x86/hvm/dm.c +10
-0+ { +unsigned long pfn = *first_pfn + iter; +struct page_info *page; + + page =get_page_from_gfn (d, pfn,NULL ,P2M_UNSHARE ); +if ( page ) + { +paging_mark_dirty (d,page_to_mfn (page)); +/* These are most probably not page tables any more */ +/* don't take a long time and don't die either */
Please fix the comment style.
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 195
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+sh_remove_shadows (d,_mfn (page_to_mfn (page)),1 ,0 ); +put_page (page); + } + +/* Check for continuation if it's not the last interation */ +if ( (++iter < *nr) &&hypercall_preempt_check () )
Please avoid checking on every iteration. In the hvmctl series I did so every 256th one.
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 203
Quoted 8 lines
xen/arch/x86/hvm/dm.c +8
-0+ { + rc = -ERESTART ; +break ; + } + } + + *first_pfn += iter; + *nr -= iter;
So this is not the standard way we handle continuations: We try hard to avoid modifying interface structures. This being a new interface, I don't mind deviation (as it simplifies the implementation), but this needs to be spelled out prominently in the header, to avoid people assuming IN fields won't get modified.
xen/arch/x86/hvm/dm.c
Quoted 5 lines
xen/arch/x86/hvm/dm.c +5
-0+struct xen_dm_op_modified_memory { +/* IN - number of contiguous pages modified */ +uint32_t nr; +/* IN - first pfn modified */ +uint64_t first_pfn;
Alignment missing. (At this point I can't resist to state that it probably wouldn't have hurt if you had taken a little more of that original series, as a number of comments I find myself making are a result of comparing your code with my original.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 5/8] dm_op: convert HVMOP_modified_memory
Quoted 11 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 13:25
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [Xen-devel] [PATCH-for-4.9 v1 5/8]dm_op: convertHVMOP_modified_memoryQuoted 1 line
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
Quoted 13 lines
xen/arch/x86/hvm/dm.c line 20
Quoted 7 lines
xen/arch/x86/hvm/dm.c +1
-0@@ -17,6 +17,7 @@#include <xen/hypercall.h> #include <xen/guest_access.h> #include <xen/sched.h> +#include <xen/event.h> I should have notice before, but it's more evident here: May I ask that you sort the xen/ and asm/ subgroups, rather than always appending at the respective one's end? With sorted #include directives the risk of merge conflicts reduces statistically.
Sure.
Quoted 22 lines
xen/arch/x86/hvm/dm.c line 21
Quoted 1 line
xen/arch/x86/hvm/dm.c +1
-0+static int dm_op_modified_memory(struct domain *d, xen_pfn_t
*first_pfn,Quoted 20 lines
xen/arch/x86/hvm/dm.c +20
-0+ unsigned int *nr) +{ +xen_pfn_t last_pfn = *first_pfn + *nr -1 ; +unsigned int iter; +int rc; + +if ( (*first_pfn > last_pfn) || + (last_pfn >domain_get_maximum_gpfn (d)) ) +return -EINVAL ; + +if ( !paging_mode_log_dirty (d) ) +return 0 ; + + iter =0 ; + rc =0 ; +while ( iter < *nr ) + { +unsigned long pfn = *first_pfn + iter; +struct page_info *page; +
Quoted 9 lines
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 189
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+ page =get_page_from_gfn (d, pfn,NULL ,P2M_UNSHARE ); +if ( page ) + { +paging_mark_dirty (d,page_to_mfn (page)); +/* These are most probably not page tables any more */ +/* don't take a long time and don't die either */ Please fix the comment style.
Yes, I'll do that.
Quoted 10 lines
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 195
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+sh_remove_shadows (d,_mfn (page_to_mfn (page)),1 ,0 ); +put_page (page); + } + +/* Check for continuation if it's not the last interation */ +if ( (++iter < *nr) &&hypercall_preempt_check () )Please avoid checking on every iteration. In the hvmctl series I did so every 256th one.
Ok.
Quoted 9 lines
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 203
Quoted 8 lines
xen/arch/x86/hvm/dm.c +8
-0+ { + rc = -ERESTART ; +break ; + } + } + + *first_pfn += iter; + *nr -= iter;
Quoted 6 lines
So this is not the standard way we handle continuations: We try hard to avoid modifying interface structures. This being a new interface, I don't mind deviation (as it simplifies the implementation), but this needs to be spelled out prominently in the header, to avoid people assuming IN fields won't get modified.
OK, I'll add an explanatory note somewhere about how to deal with -ERESTART for this and type setting.
Quoted 11 lines
xen/arch/x86/hvm/dm.c
Quoted 5 lines
xen/arch/x86/hvm/dm.c +5
-0+struct xen_dm_op_modified_memory { +/* IN - number of contiguous pages modified */ +uint32_t nr; +/* IN - first pfn modified */ +uint64_t first_pfn;Alignment missing. (At this point I can't resist to state that it probably wouldn't have hurt if you had taken a little more of that original series, as a number of comments I find myself making are a result of comparing your code with my original.)
OK. I was pulling across from hvm_op in the same tree rather than your patches (as I didn't have them in on the same machine as it happened). I'll cross-check the op definitions.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 5/8] dm_op: convert HVMOP_modified_memory
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 25.11.16 at 14:31, <[email protected]> wrote:
OK. I was pulling across from
hvm_opin the same tree rather than your patches (as I didn't have them in on the same machine as it happened). I'll cross-check the op definitions.
Oh, so you've re-done everything instead of evolving it. Interesting.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 6/8 dm_op: convert HVMOP_set_mem_type
In reply to Paul DurrantThis patch also removes the need for handling HVMOP restarts, so that infrastructure is also removed.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Daniel De Graaf <[email protected]>
--- tools/libxc/xc_misc.c | 28 +++----- xen/arch/x86/hvm/dm.c | 92 ++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 136 +----------------------------------- xen/include/public/hvm/dm_op.h | 16 +++++ xen/include/public/hvm/hvm_op.h | 4 +- xen/xsm/flask/policy/access_vectors | 2 +- 6 files changed, 121 insertions(+), 157 deletions(-)
tools/libxc/xc_misc.c +9 -19
@@ -584,28 +584,18 @@ int xc_hvm_modified_memory(int xc_hvm_set_mem_type (xc_interface *xch,domid_t dom,hvmmem_type_t mem_type,uint64_t first_pfn,uint64_t nr) { - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_mem_type, arg); -int rc; - - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) - { -PERROR ("Could not allocate memory for xc_hvm_set_mem_type hypercall" ); -return -1 ; - } +struct xen_dm_op op; +struct xen_dm_op_set_mem_type *data; - arg->domid = dom; - arg->hvmmem_type = mem_type; - arg->first_pfn = first_pfn; - arg->nr = nr; + op.op = DMOP_set_mem_type; + data = &op.u.set_mem_type; - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_set_mem_type, -HYPERCALL_BUFFER_AS_ARG (arg)); - -xc_hypercall_buffer_free (xch, arg); + data->mem_type = mem_type; + data->first_pfn = first_pfn; +/* NOTE: The following assignment truncates nr to 32-bits */ + data->nr = nr; -return rc; +return do_dm_op (xch, dom,1 , &op,sizeof (op)); } int xc_hvm_inject_trap(
xen/arch/x86/hvm/dm.c +92 -0
110 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +1 -135
158 lines not on this page · raw message
xen/include/public/hvm/dm_op.h +16 -0
@@ -245,6 +245,21 @@ struct xen_dm_op_modified_memory {uint64_t first_pfn; }; +/* +* DMOP_set_mem_type: Notify that a region of memory is to be treated in a +* specific way. (See definition of hvmmem_type_t). +*/ +#define DMOP_set_mem_type 12 + +struct xen_dm_op_set_mem_type { +/* IN - number of contiguous pages */ +uint32_t nr; +/* IN - first pfn in region */ +uint64_t first_pfn; +/* IN - new hvmmem_type_t of region */ +uint16_t mem_type; +}; +struct xen_dm_op {uint32_t op;
@@ -260,6 +275,7 @@ struct xen_dm_op {struct xen_dm_op_set_isa_irq_level set_isa_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; } u; };
xen/include/public/hvm/hvm_op.h +2 -2
@@ -131,8 +131,6 @@ struct xen_hvm_modified_memory {typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_modified_memory_t); -#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ -#define HVMOP_set_mem_type 8/* Notify that a region of memory is to be treated in a specific way. */ struct xen_hvm_set_mem_type {
@@ -148,6 +146,8 @@ struct xen_hvm_set_mem_type {typedef struct xen_hvm_set_mem_type xen_hvm_set_mem_type_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_mem_type_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ /* Hint from PV drivers for pagetable destruction. */
xen/xsm/flask/policy/access_vectors +1 -1
@@ -260,7 +260,7 @@ class hvm bind_irq # XEN_DOMCTL_pin_mem_cacheattr cacheattr -# HVMOP_get_mem_type, HVMOP_set_mem_type, +# HVMOP_get_mem_type, # HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying, # HVMOP_inject_trap hvmctl
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 6/8] dm_op: convert HVMOP_set_mem_type
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
tools/libxc/xc_misc.c +4
-13@@ -584,28 +584,18 @@ int xc_hvm_modified_memory( int xc_hvm_set_mem_type( xc_interface *xch, domid_t dom, hvmmem_type_t mem_type, uint64_t first_pfn, uint64_t nr) { -DECLARE_HYPERCALL_BUFFER (struct xen_hvm_set_mem_type ,arg ); -int rc; - - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) - { -PERROR ("Could not allocate memory for xc_hvm_set_mem_type hypercall" ); -return -1 ; - } + struct xen_dm_op op; +struct xen_dm_op_set_mem_type *data; - arg->domid = dom; - arg->hvmmem_type = mem_type; - arg->first_pfn = first_pfn; - arg->nr = nr; + op.op = DMOP_set_mem_type; + data = &op.u.set_mem_type;
tools/libxc/xc_misc.c int xc_hvm_modified_memory( int xc_hvm_set_mem_type( · line 595
Quoted 10 lines
tools/libxc/xc_misc.c +4
-5- rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_set_mem_type, -HYPERCALL_BUFFER_AS_ARG (arg)); - -xc_hypercall_buffer_free (xch, arg); + data->mem_type = mem_type; + data->first_pfn = first_pfn; +/* NOTE: The following assignment truncates nr to 32-bits */ + data->nr = nr;
What strange a comment. Why don't you - again as done in the hvmctl series - simply correct the function's parameter type? (Same for xc_hvm_track_dirty_vram() and xc_hvm_modified_memory() then.)
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 163
Quoted 7 lines
xen/arch/x86/hvm/dm.c +1
-0@@ -160,6 +160,16 @@ static int dm_op_set_pci_link_route(struct domain *d, uint8_t link,return 0 ; } +static bool_t dm_op_allow_p2m_type_change (p2m_type_t old,p2m_type_t new)
bool
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 168
Quoted 5 lines
xen/arch/x86/hvm/dm.c +5
-0+{ +if (p2m_is_ram (old) || + (p2m_is_hole (old) && new == p2m_mmio_dm) || + (old == p2m_ioreq_server && new == p2m_ram_rw) ) +return 1 ;
true
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 170
Quoted 2 lines
xen/arch/x86/hvm/dm.c +2
-0+ +return 0 ;
false (or perhaps even better a simple return statement, and perhaps you can by now guess where I could refer you)
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 173
Quoted 3 lines
xen/arch/x86/hvm/dm.c +2
-0+} + static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn,
Any reason of putting it here rather than ...
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn, · line 220
Quoted 7 lines
xen/arch/x86/hvm/dm.c +3
-0@@ -205,6 +215,79 @@ static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn,return rc; } + +static int dm_op_set_mem_type (struct domain *d,hvmmem_type_t mem_type, +xen_pfn_t *first_pfn,unsigned int *nr)
... right before this one (the helper of which it is)?
Also please don't add a second blank line above the function.
Quoted 20 lines
xen/arch/x86/hvm/dm.c +20
-0+{ +xen_pfn_t last_pfn = *first_pfn + *nr -1 ; +unsigned int iter; +int rc; + +/* Interface types to internal p2m types */ +static const p2m_type_t memtype[] = { + [HVMMEM_ram_rw] = p2m_ram_rw, + [HVMMEM_ram_ro] = p2m_ram_ro, + [HVMMEM_mmio_dm] = p2m_mmio_dm, + [HVMMEM_unused] = p2m_invalid, + [HVMMEM_ioreq_server] = p2m_ioreq_server + }; + +if ( (*first_pfn > last_pfn) || + (last_pfn >domain_get_maximum_gpfn (d)) ) +return -EINVAL ; + +if ( mem_type >=ARRAY_SIZE (memtype) || +unlikely (mem_type == HVMMEM_unused) )
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn, · line 250
Quoted 10 lines
xen/arch/x86/hvm/dm.c +10
-0+return -EINVAL ; + + iter =0 ; + rc =0 ; +while ( iter < *nr ) + { +unsigned long pfn = *first_pfn + iter; +p2m_type_t t; + +get_gfn_unshare (d, pfn, &t);
Note the disagreement between function and parameter names.
Quoted 9 lines
xen/arch/x86/hvm/dm.c +9
-0+if (p2m_is_paging (t) ) + { +put_gfn (d, pfn); +p2m_mem_paging_populate (d, pfn); + rc = -EAGAIN ; +break ; + } +if (p2m_is_shared (t) ) + {
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn, · line 269
Quoted 10 lines
xen/arch/x86/hvm/dm.c +10
-0+put_gfn (d, pfn); + rc = -EAGAIN ; +break ; + } +if ( !dm_op_allow_p2m_type_change (t, memtype[mem_type]) ) + { +put_gfn (d, pfn); + rc = -EINVAL ; +break ; + }
Why can't all of these simply be return statements?
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn, · line 275
Quoted 5 lines
xen/arch/x86/hvm/dm.c +5
-0+ rc =p2m_change_type_one (d, pfn, t, memtype[mem_type]); +put_gfn (d, pfn); + +if ( rc ) +break ;
Or, again as done you know where, fold some of those redundant put_gfn()s as well, by using if/else-if.
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn, · line 282
Quoted 8 lines
xen/arch/x86/hvm/dm.c +8
-0+struct xen_dm_op_set_mem_type { +/* IN - number of contiguous pages */ +uint32_t nr; +/* IN - first pfn in region */ +uint64_t first_pfn; +/* IN - new hvmmem_type_t of region */ +uint16_t mem_type; +};
mem_type should be moved up, first_pfn be aligned, and explicit padding be inserted.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 6/8] dm_op: convert HVMOP_set_mem_type
Quoted 48 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 13:51
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [Xen-devel] [PATCH-for-4.9 v1 6/8]dm_op: convertHVMOP_set_mem_typetools/libxc/xc_misc.c int xc_hvm_modified_memory( int
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
tools/libxc/xc_misc.c +0
-0@@ -584,28 +584,18 @@ int xc_hvm_modified_memory( intxc_hvm_set_mem_type(
tools/libxc/xc_misc.c int xc_hvm_modified_memory( int · line 584
Quoted 1 line
tools/libxc/xc_misc.c +0
-0xc_interface *xch, domid_t dom, hvmmem_type_t mem_type, uint64_t
first_pfn,uint64_tnr)tools/libxc/xc_misc.c int xc_hvm_modified_memory(
Quoted 8 lines
tools/libxc/xc_misc.c +0
-7{ - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_mem_type, arg); -int rc; - - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) - { - PERROR("Could not allocate memory for xc_hvm_set_mem_typehypercall");
Quoted 11 lines
tools/libxc/xc_misc.c +4
-6-return -1 ; - } +struct xen_dm_op op; +struct xen_dm_op_set_mem_type *data; - arg->domid = dom; - arg->hvmmem_type = mem_type; - arg->first_pfn = first_pfn; - arg->nr = nr; + op.op = DMOP_set_mem_type; + data = &op.u.set_mem_type;tools/libxc/xc_misc.c int xc_hvm_modified_memory( · line 596
Quoted 10 lines
tools/libxc/xc_misc.c +4
-5- rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_set_mem_type, -HYPERCALL_BUFFER_AS_ARG (arg)); - -xc_hypercall_buffer_free (xch, arg); + data->mem_type = mem_type; + data->first_pfn = first_pfn; +/* NOTE: The following assignment truncates nr to 32-bits */ + data->nr = nr;
Quoted 4 lines
What strange a comment. Why don't you - again as done in the hvmctl series - simply correct the function's parameter type? (Same for
xc_hvm_track_dirty_vram()andxc_hvm_modified_memory()then.)
Because that may cause compiler warnings in clients when they grab the new version of the header. I didn't want to have any adverse effect so just commenting that the value was being truncated (as it always has been) seemed like the best thing to do.
Quoted 5 lines
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain
Quoted 4 lines
xen/arch/x86/hvm/dm.c +0
-0@@ -160,6 +160,16 @@ static int dm_op_set_pci_link_route(struct domain*d,
uint8_tlink,
Quoted 8 lines
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link,
Quoted 4 lines
xen/arch/x86/hvm/dm.c +1
-0return 0 ; } +static bool_t dm_op_allow_p2m_type_change(p2m_type_t old,
p2m_type_tnew)bool
Ok.
Quoted 26 lines
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 168
Quoted 5 lines
xen/arch/x86/hvm/dm.c +5
-0+{ +if (p2m_is_ram (old) || + (p2m_is_hole (old) && new == p2m_mmio_dm) || + (old == p2m_ioreq_server && new == p2m_ram_rw) ) +return 1 ;true
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link, · line 170
Quoted 2 lines
xen/arch/x86/hvm/dm.c +2
-0+ +return 0 ;false (or perhaps even better a simple return statement, and perhaps you can by now guess where I could refer you)
xen/arch/x86/hvm/dm.c static int dm_op_set_pci_link_route(struct domain *d, uint8_t link,
Quoted 3 lines
xen/arch/x86/hvm/dm.c +2
-0+} + static int dm_op_modified_memory(struct domain *d, xen_pfn_t
*first_pfn,Any reason of putting it here rather than ...
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain
Quoted 1 line
xen/arch/x86/hvm/dm.c +0
-0@@ -205,6 +215,79 @@ static int dm_op_modified_memory(struct domain*d,
xen_pfn_t*first_pfn,Quoted 3 lines
xen/arch/x86/hvm/dm.c +0
-0return rc; }
Quoted 7 lines
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain · line 219
Quoted 2 lines
xen/arch/x86/hvm/dm.c +2
-0+ +static int dm_op_set_mem_type(struct domain *d, hvmmem_type_t
mem_type,xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn, · line 220
Quoted 1 line
xen/arch/x86/hvm/dm.c +1
-0+ xen_pfn_t *first_pfn, unsigned int *nr)... right before this one (the helper of which it is)?
No, I can move it.
Quoted 2 lines
Also please don't add a second blank line above the function.
Yes, that's a mistake.
Quoted 24 lines
Quoted 24 lines
xen/arch/x86/hvm/dm.c +24
-0+{ +xen_pfn_t last_pfn = *first_pfn + *nr -1 ; +unsigned int iter; +int rc; + +/* Interface types to internal p2m types */ +static const p2m_type_t memtype[] = { + [HVMMEM_ram_rw] = p2m_ram_rw, + [HVMMEM_ram_ro] = p2m_ram_ro, + [HVMMEM_mmio_dm] = p2m_mmio_dm, + [HVMMEM_unused] = p2m_invalid, + [HVMMEM_ioreq_server] = p2m_ioreq_server + }; + +if ( (*first_pfn > last_pfn) || + (last_pfn >domain_get_maximum_gpfn (d)) ) +return -EINVAL ; + +if ( mem_type >=ARRAY_SIZE (memtype) || +unlikely (mem_type == HVMMEM_unused) ) +return -EINVAL ; + + iter =0 ; + rc =0 ;
Quoted 9 lines
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn, · line 250
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+while ( iter < *nr ) + { +unsigned long pfn = *first_pfn + iter; +p2m_type_t t; + +get_gfn_unshare (d, pfn, &t);Note the disagreement between function and parameter names.
It was inherited but I'll correct it.
Quoted 22 lines
Quoted 9 lines
xen/arch/x86/hvm/dm.c +9
-0+if (p2m_is_paging (t) ) + { +put_gfn (d, pfn); +p2m_mem_paging_populate (d, pfn); + rc = -EAGAIN ; +break ; + } +if (p2m_is_shared (t) ) + {xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn, · line 269
Quoted 10 lines
xen/arch/x86/hvm/dm.c +10
-0+put_gfn (d, pfn); + rc = -EAGAIN ; +break ; + } +if ( !dm_op_allow_p2m_type_change (t, memtype[mem_type]) ) + { +put_gfn (d, pfn); + rc = -EINVAL ; +break ; + }Why can't all of these simply be return statements?
Quoted 8 lines
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain *d, xen_pfn_t *first_pfn, · line 275
Quoted 5 lines
xen/arch/x86/hvm/dm.c +5
-0+ rc =p2m_change_type_one (d, pfn, t, memtype[mem_type]); +put_gfn (d, pfn); + +if ( rc ) +break ;Or, again as done you know where, fold some of those redundant put_gfn()s as well, by using if/else-if.
That would be neater.
Quoted 12 lines
xen/arch/x86/hvm/dm.c static int dm_op_modified_memory(struct domain · line 282
Quoted 9 lines
xen/arch/x86/hvm/dm.c +8
-0+struct xen_dm_op_set_mem_type { +/* IN - number of contiguous pages */ +uint32_t nr; +/* IN - first pfn in region */ +uint64_t first_pfn; +/* IN - new hvmmem_type_t of region */ +uint16_t mem_type; +};
mem_typeshould be moved up,first_pfnbe aligned, and explicit padding be inserted.
OK.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 6/8] dm_op: convert HVMOP_set_mem_type
Quoted 46 lines
Quoted 41 lines
Quoted 1 line · On 25.11.16 at 15:00, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 13:51tools/libxc/xc_misc.c int xc_hvm_modified_memory( int
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
tools/libxc/xc_misc.c +0
-0@@ -584,28 +584,18 @@ int xc_hvm_modified_memory( intxc_hvm_set_mem_type(
tools/libxc/xc_misc.c int xc_hvm_modified_memory( int · line 584
Quoted 1 line
tools/libxc/xc_misc.c +0
-0xc_interface *xch, domid_t dom, hvmmem_type_t mem_type, uint64_t
first_pfn,uint64_tnr)tools/libxc/xc_misc.c int xc_hvm_modified_memory(
Quoted 8 lines
tools/libxc/xc_misc.c +0
-7{ - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_mem_type, arg); -int rc; - - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) - { - PERROR("Could not allocate memory for xc_hvm_set_mem_typehypercall");
Quoted 11 lines
tools/libxc/xc_misc.c +4
-6-return -1 ; - } +struct xen_dm_op op; +struct xen_dm_op_set_mem_type *data; - arg->domid = dom; - arg->hvmmem_type = mem_type; - arg->first_pfn = first_pfn; - arg->nr = nr; + op.op = DMOP_set_mem_type; + data = &op.u.set_mem_type;tools/libxc/xc_misc.c int xc_hvm_modified_memory( · line 596
Quoted 10 lines
tools/libxc/xc_misc.c +4
-5- rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_set_mem_type, -HYPERCALL_BUFFER_AS_ARG (arg)); - -xc_hypercall_buffer_free (xch, arg); + data->mem_type = mem_type; + data->first_pfn = first_pfn; +/* NOTE: The following assignment truncates nr to 32-bits */ + data->nr = nr;Quoted 4 lines
What strange a comment. Why don't you - again as done in the hvmctl series - simply correct the function's parameter type? (Same for
xc_hvm_track_dirty_vram()andxc_hvm_modified_memory()then.)
Quoted 4 lines
Because that may cause compiler warnings in clients when they grab the new version of the header. I didn't want to have any adverse effect so just commenting that the value was being truncated (as it always has been) seemed like the best thing to do.
Well, maybe the tool stack maintainers think differently now, but for those libxc interface changes I had Wei's R-b already back then. In any case the present choice of types is plain wrong, and I think it's better if consumers of the API get warned about the possible truncation by compilers than silently truncating inside the library.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 6/8] dm_op: convert HVMOP_set_mem_type
Quoted 63 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 14:16
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: RE: [Xen-devel] [PATCH-for-4.9 v1 6/8]dm_op: convertHVMOP_set_mem_typeQuoted 9 lines
Quoted 9 lines
Quoted 1 line · On 25.11.16 at 15:00, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 13:51tools/libxc/xc_misc.c int xc_hvm_modified_memory( int
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
tools/libxc/xc_misc.c +0
-0@@ -584,28 +584,18 @@ int xc_hvm_modified_memory( intxc_hvm_set_mem_type(
Quoted 1 line
tools/libxc/xc_misc.c +0
-0xc_interface *xch, domid_t dom, hvmmem_type_t mem_type,
uint64_tQuoted 3 lines
Quoted 3 lines
first_pfn,uint64_tnr)Quoted 2 lines
tools/libxc/xc_misc.c +0
-1{ - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_mem_type,arg);
Quoted 29 lines
Quoted 29 lines
tools/libxc/xc_misc.c int xc_hvm_modified_memory(
Quoted 6 lines
tools/libxc/xc_misc.c +0
-6-int rc; - - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) - { - PERROR("Could not allocate memory for xc_hvm_set_mem_typehypercall");
Quoted 21 lines
tools/libxc/xc_misc.c +8
-11-return -1 ; - } +struct xen_dm_op op; +struct xen_dm_op_set_mem_type *data; - arg->domid = dom; - arg->hvmmem_type = mem_type; - arg->first_pfn = first_pfn; - arg->nr = nr; + op.op = DMOP_set_mem_type; + data = &op.u.set_mem_type; - rc =xencall2 (xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_set_mem_type, -HYPERCALL_BUFFER_AS_ARG (arg)); - -xc_hypercall_buffer_free (xch, arg); + data->mem_type = mem_type; + data->first_pfn = first_pfn; +/* NOTE: The following assignment truncates nr to 32-bits */ + data->nr = nr;Quoted 6 lines
Quoted 4 lines
What strange a comment. Why don't you - again as done in the hvmctl series - simply correct the function's parameter type? (Same for
xc_hvm_track_dirty_vram()andxc_hvm_modified_memory()then.)Because that may cause compiler warnings in clients when they grab the
new
Quoted 2 lines
version of the header. I didn't want to have any adverse effect so just commenting that the value was being truncated (as it always has been)
seemed
Quoted 9 lines
Quoted 1 line
like the best thing to do.
Well, maybe the tool stack maintainers think differently now, but for those libxc interface changes I had Wei's R-b already back then. In any case the present choice of types is plain wrong, and I think it's better if consumers of the API get warned about the possible truncation by compilers than silently truncating inside the library.
Ok, if you already had agreement from a toolstack maintainer then I'll change the header.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 6/8] dm_op: convert HVMOP_set_mem_type
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 25.11.16 at 15:20, <[email protected]> wrote:
Ok, if you already had agreement from a toolstack maintainer then I'll change the header.
Well, I had handed you the hvmctl patches, which I'm pretty sure had all the relevant tags accumulated.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 6/8] dm_op: convert HVMOP_set_mem_type
Quoted 10 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 14:47
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]; Daniel DeGraaf <[email protected]>
Subject: RE: [Xen-devel] [PATCH-for-4.9 v1 6/8]dm_op: convertHVMOP_set_mem_type
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 25.11.16 at 15:20, <[email protected]> wrote:
Ok, if you already had agreement from a toolstack maintainer then I'll change the header.
Well, I had handed you the hvmctl patches, which I'm pretty sure had all the relevant tags accumulated.
Oh. They must have got stripped when I attempted to git am the patches onto my branch and had to manually fix-up.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 7/8 dm_op: convert HVMOP_inject_trap and HVMOP_inject_msi
In reply to Paul DurrantNOTE: The definitions of HVMOP_TRAP_* have to persist for new interface
versions as they are already in use by callers of the libxc interface.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
--- tools/flask/policy/modules/xen.if | 2 +- tools/libxc/xc_misc.c | 60 ++++++++++------------------- xen/arch/x86/hvm/dm.c | 44 ++++++++++++++++++++- xen/arch/x86/hvm/hvm.c | 76 ------------------------------------- xen/include/public/hvm/dm_op.h | 45 ++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 26 ++++++++----- xen/include/xsm/dummy.h | 6 --- xen/include/xsm/xsm.h | 6 --- xen/xsm/dummy.c | 1 - xen/xsm/flask/hooks.c | 6 --- xen/xsm/flask/policy/access_vectors | 5 +-- 11 files changed, 126 insertions(+), 151 deletions(-)
tools/flask/policy/modules/xen.if +1 -1
@@ -151,7 +151,7 @@ define(`device_model', ` allow $1 $2_target:domain { getdomaininfo shutdown }; allow $1 $2_target:mmu { map_read map_write adjust physmap target_hack }; - allow $1 $2_target:hvm { getparam setparam hvmctl cacheattr send_irq dm }; + allow $1 $2_target:hvm { getparam setparam hvmctl cacheattr dm }; ') # make_device_model(priv, dm_dom, hvm_dom)
tools/libxc/xc_misc.c +19 -41
79 lines not on this page · raw message
xen/arch/x86/hvm/dm.c +43 -1
62 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +0 -76
94 lines not on this page · raw message
xen/include/public/hvm/dm_op.h +45 -0
57 lines not on this page · raw message
xen/include/public/hvm/hvm_op.h +17 -9
@@ -187,6 +187,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_xentrace_t);/* Deprecated by XENMEM_access_op_get_access */ #define HVMOP_get_mem_access 13 +#if __XEN_INTERFACE_VERSION__ <0x00040900 +#define HVMOP_inject_trap 14/* Inject a trap into a VCPU, which will get taken up on the next * scheduling of it. Note that the caller should know enough of the
@@ -202,13 +204,6 @@ struct xen_hvm_inject_trap {uint32_t vector;/* Trap type (HVMOP_TRAP_*) */ uint32_t type; -/* NB. This enumeration precisely matches hvm.h:X86_EVENTTYPE_* */ -# define HVMOP_TRAP_ext_int 0/* external interrupt */ -# define HVMOP_TRAP_nmi 2/* nmi */ -# define HVMOP_TRAP_hw_exc 3/* hardware exception */ -# define HVMOP_TRAP_sw_int 4/* software interrupt (CD nn) */ -# define HVMOP_TRAP_pri_sw_exc 5/* ICEBP (F1) */ -# define HVMOP_TRAP_sw_exc 6/* INT3 (CC), INTO (CE) */ /* Error code, or ~0u to skip */ uint32_t error_code;/* Intruction length */
@@ -219,6 +214,19 @@ struct xen_hvm_inject_trap {typedef struct xen_hvm_inject_trap xen_hvm_inject_trap_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_inject_trap_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ + +/* +* Definitions relating to HVMOP/DMOP_inject_trap. +*/ + +# define HVMOP_TRAP_ext_int DMOP_TRAP_ext_int +# define HVMOP_TRAP_nmi DMOP_TRAP_nmi +# define HVMOP_TRAP_hw_exc DMOP_TRAP_hw_exc +# define HVMOP_TRAP_sw_int DMOP_TRAP_sw_int +# define HVMOP_TRAP_pri_sw_exc DMOP_TRAP_pri_sw_exc +# define HVMOP_TRAP_sw_exc DMOP_TRAP_sw_exc +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ #define HVMOP_get_mem_type 15
@@ -238,6 +246,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_mem_type_t);/* Following tools-only interfaces may change in future. */ #if defined(__XEN__) || defined(__XEN_TOOLS__) +#if __XEN_INTERFACE_VERSION__ <0x00040900 +/* MSI injection for emulated devices */ #define HVMOP_inject_msi 16 struct xen_hvm_inject_msi {
@@ -251,8 +261,6 @@ struct xen_hvm_inject_msi {typedef struct xen_hvm_inject_msi xen_hvm_inject_msi_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_inject_msi_t); -#if __XEN_INTERFACE_VERSION__ <0x00040900 -/* * IOREQ Servers *
xen/include/xsm/dummy.h +0 -6
@@ -610,12 +610,6 @@ static XSM_INLINE int xsm_shadow_control(XSM_DEFAULT_ARG struct domain *d, uint3return xsm_default_action (action, current->domain, d); } -static XSM_INLINE int xsm_hvm_inject_msi(XSM_DEFAULT_ARG struct domain *d) -{ -XSM_ASSERT_ACTION (XSM_DM_PRIV ); -return xsm_default_action (action, current->domain, d); -} - static XSM_INLINE int xsm_mem_sharing_op(XSM_DEFAULT_ARG struct domain *d, struct domain *cd, int op) {XSM_ASSERT_ACTION (XSM_DM_PRIV );
xen/include/xsm/xsm.h +0 -6
@@ -162,7 +162,6 @@ struct xsm_operations {#ifdef CONFIG_X86 int (*do_mca) (void );int (*shadow_control) (struct domain *d,uint32_t op); -int (*hvm_inject_msi) (struct domain *d);int (*mem_sharing_op) (struct domain *d,struct domain *cd,int op);int (*apic) (struct domain *d,int cmd);int (*memtype) (uint32_t access);
@@ -632,11 +631,6 @@ static inline int xsm_shadow_control (xsm_default_t def, struct domain *d, uint3return xsm_ops->shadow_control (d, op); } -static inline int xsm_hvm_inject_msi (xsm_default_t def,struct domain *d) -{ -return xsm_ops->hvm_inject_msi (d); -} -static inline int xsm_mem_sharing_op (xsm_default_t def,struct domain *d,struct domain *cd,int op) {return xsm_ops->mem_sharing_op (d, cd, op);
xen/xsm/dummy.c +0 -1
@@ -145,7 +145,6 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)#ifdef CONFIG_X86 set_to_dummy_if_null (ops, do_mca);set_to_dummy_if_null (ops, shadow_control); -set_to_dummy_if_null (ops, hvm_inject_msi);set_to_dummy_if_null (ops, mem_sharing_op);set_to_dummy_if_null (ops, apic);set_to_dummy_if_null (ops, machine_memory_map);
xen/xsm/flask/hooks.c +0 -6
@@ -1499,11 +1499,6 @@ static int flask_ioport_mapping(struct domain *d, uint32_t start, uint32_t end,return flask_ioport_permission (d, start, end, access); } -static int flask_hvm_inject_msi (struct domain *d) -{ -return current_has_perm (d,SECCLASS_HVM ,HVM__SEND_IRQ ); -} -static int flask_mem_sharing_op (struct domain *d,struct domain *cd,int op) {int rc =current_has_perm (cd,SECCLASS_HVM ,HVM__MEM_SHARING );
@@ -1781,7 +1776,6 @@ static struct xsm_operations flask_ops = { .hvm_set_pci_intx_level = flask_hvm_set_pci_intx_level, .hvm_set_isa_irq_level = flask_hvm_set_isa_irq_level, .hvm_set_pci_link_route = flask_hvm_set_pci_link_route, - .hvm_inject_msi = flask_hvm_inject_msi, .mem_sharing_op = flask_mem_sharing_op, .apic = flask_apic, .machine_memory_map = flask_machine_memory_map,
xen/xsm/flask/policy/access_vectors +1 -4
@@ -261,8 +261,7 @@ class hvm # XEN_DOMCTL_pin_mem_cacheattr cacheattr # HVMOP_get_mem_type, -# HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying, -# HVMOP_inject_trap +# HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying hvmctl # XEN_DOMCTL_mem_sharing_op and XENMEM_sharing_op_{share,add_physmap} with: # source = the domain making the hypercall
@@ -270,8 +269,6 @@ class hvm mem_sharing # XEN_DOMCTL_audit_p2m audit_p2m -# HVMOP_inject_msi - send_irq # checked in XENMEM_sharing_op_{share,add_physmap} with: # source = domain whose memory is being shared # target = client domain
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 7/8] dm_op: convert HVMOP_inject_trap and HVMOP_inject_msi
xen/arch/x86/hvm/dm.c static int dm_op_set_mem_type(struct domain *d, hvmmem_type_t mem_type, · line 298
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +9
-0+static int dm_op_inject_trap (struct domain *d,unsigned int vcpuid, +uint16_t vector,uint8_t type, +uint8_t insn_len,uint32_t error_code, +unsigned long cr2) +{ +struct vcpu *v; + +if ( vector >INT16_MAX ) +return -EINVAL ;
Please limit vector to uint8_t and delete this strange (architecturally wrong) check.
xen/arch/x86/hvm/dm.c static int dm_op_set_mem_type(struct domain *d, hvmmem_type_t mem_type, · line 301
Quoted 2 lines
xen/arch/x86/hvm/dm.c +2
-0+if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) ==NULL ) +return -EINVAL ;
ENOENT (to make error reasons distinguishable for the caller)?
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 465
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+case DMOP_inject_msi: + { +struct xen_dm_op_inject_msi *data = + &op.u.inject_msi; + + rc =hvm_inject_msi (d, data->addr, data->data);
Line length clearly is not an issue here, but if you want to keep the helper variable, then please constify it (which I guess would apply to some of the earlier patches too).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 7/8] dm_op: convert HVMOP_inject_trap and HVMOP_inject_msi
Quoted 11 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 November 2016 14:08
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [Xen-devel] [PATCH-for-4.9 v1 7/8]dm_op: convertHVMOP_inject_trapandHVMOP_inject_msiQuoted 1 line
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
Quoted 12 lines
xen/arch/x86/hvm/dm.c static int dm_op_set_mem_type(struct domain *d, hvmmem_type_t mem_type, · line 298
Quoted 9 lines
xen/arch/x86/hvm/dm.c +9
-0+static int dm_op_inject_trap (struct domain *d,unsigned int vcpuid, +uint16_t vector,uint8_t type, +uint8_t insn_len,uint32_t error_code, +unsigned long cr2) +{ +struct vcpu *v; + +if ( vector >INT16_MAX ) +return -EINVAL ;Please limit vector to
uint8_tand delete this strange (architecturally wrong) check.
This check is only meant to check that the field assignment below it doesn't overflow. IIRC the old code didn't even do that. I'll limit to uint8_t as you suggest though.
Quoted 6 lines
xen/arch/x86/hvm/dm.c static int dm_op_set_mem_type(struct domain *d, hvmmem_type_t mem_type, · line 301
Quoted 3 lines
xen/arch/x86/hvm/dm.c +2
-0+if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) ==NULL ) +return -EINVAL ;ENOENT (to make error reasons distinguishable for the caller)?
Ok.
Quoted 10 lines
xen/arch/x86/hvm/dm.c long do_dm_op(domid_t domid, · line 465
Quoted 6 lines
xen/arch/x86/hvm/dm.c +6
-0+case DMOP_inject_msi: + { +struct xen_dm_op_inject_msi *data = + &op.u.inject_msi; + + rc =hvm_inject_msi (d, data->addr, data->data);Line length clearly is not an issue here, but if you want to keep the helper variable, then please constify it (which I guess would apply to some of the earlier patches too).
Ok. I'll try to const everything that can't be subject to a continuation.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 8/8 x86/hvm: serialize trap injecting producer and consumer
In reply to Paul DurrantSince injection works on a remote vCPU, and since there's no enforcement of the subject vCPU being paused, there's a potential race between the producing and consuming sides. Fix this by leveraging the vector field as synchronization variable.
---
Cc: Andrew Cooper <[email protected]>
--- xen/arch/x86/hvm/dm.c | 5 ++++- xen/arch/x86/hvm/hvm.c | 7 ++++--- xen/include/asm-x86/hvm/hvm.h | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/dm.c +4 -1
@@ -300,13 +300,16 @@ static int dm_op_inject_trap(struct domain *d, unsigned int vcpuid,if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) ==NULL )return -EINVAL ; -if ( v->arch.hvm_vcpu.inject_trap.vector !=-1 ) +if (cmpxchg (&v->arch.hvm_vcpu.inject_trap.vector, +HVM_TRAP_VECTOR_UNSET ,HVM_TRAP_VECTOR_UPDATING ) != +HVM_TRAP_VECTOR_UNSET )return -EBUSY ; v->arch.hvm_vcpu.inject_trap.type = type; v->arch.hvm_vcpu.inject_trap.insn_len = insn_len; v->arch.hvm_vcpu.inject_trap.error_code = error_code; v->arch.hvm_vcpu.inject_trap.cr2 = cr2; +smp_wmb (); v->arch.hvm_vcpu.inject_trap.vector = vector;return 0 ;
xen/arch/x86/hvm/hvm.c +4 -3
@@ -533,10 +533,11 @@ void hvm_do_resume(struct vcpu *v) }/* Inject pending hw/sw trap */ -if ( v->arch.hvm_vcpu.inject_trap.vector !=-1 ) +if ( v->arch.hvm_vcpu.inject_trap.vector >=0 ) { +smp_rmb ();hvm_inject_trap (&v->arch.hvm_vcpu.inject_trap); - v->arch.hvm_vcpu.inject_trap.vector =-1 ; + v->arch.hvm_vcpu.inject_trap.vector =HVM_TRAP_VECTOR_UNSET ; } }
@@ -1548,7 +1549,7 @@ int hvm_vcpu_initialise(struct vcpu *v) (void (*)(unsigned long ))hvm_assert_evtchn_irq, (unsigned long)v); - v->arch.hvm_vcpu.inject_trap.vector =-1 ; + v->arch.hvm_vcpu.inject_trap.vector =HVM_TRAP_VECTOR_UNSET ;if (is_pvh_domain (d) ) {
xen/include/asm-x86/hvm/hvm.h +2 -0
@@ -78,6 +78,8 @@ enum hvm_intblk {#define HVM_HAP_SUPERPAGE_1GB 0x00000002struct hvm_trap { +#define HVM_TRAP_VECTOR_UNSET (-1) +#define HVM_TRAP_VECTOR_UPDATING (-2)int16_t vector;uint8_t type;/* X86_EVENTTYPE_* */ uint8_t insn_len;/* Instruction length */
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 8/8] x86/hvm: serialize trap injecting producer and consumer
Quoted 45 lines · Paul Durrant
Since injection works on a remote vCPU, and since there's no enforcement of the subject vCPU being paused, there's a potential race between the producing and consuming sides. Fix this by leveraging the vector field as synchronization variable.
Signed-off-by Jan Beulich <[email protected]>[re-based]Signed-off-by Paul Durrant <[email protected]>---
Cc: Andrew Cooper <[email protected]>--- xen/arch/x86/hvm/dm.c | 5 ++++- xen/arch/x86/hvm/hvm.c | 7 ++++--- xen/include/asm-x86/hvm/hvm.h | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-)xen/arch/x86/hvm/dm.c +4
-1@@ -300,13 +300,16 @@ static int dm_op_inject_trap(struct domain *d, unsigned int vcpuid,if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) ==NULL )return -EINVAL ; -if ( v->arch.hvm_vcpu.inject_trap.vector !=-1 ) +if (cmpxchg (&v->arch.hvm_vcpu.inject_trap.vector, +HVM_TRAP_VECTOR_UNSET ,HVM_TRAP_VECTOR_UPDATING ) != +HVM_TRAP_VECTOR_UNSET )return -EBUSY ; v->arch.hvm_vcpu.inject_trap.type = type; v->arch.hvm_vcpu.inject_trap.insn_len = insn_len; v->arch.hvm_vcpu.inject_trap.error_code = error_code; v->arch.hvm_vcpu.inject_trap.cr2 = cr2; +smp_wmb (); v->arch.hvm_vcpu.inject_trap.vector = vector;return 0 ;xen/arch/x86/hvm/hvm.c +0
-0@@ -533,10 +533,11 @@ void hvm_do_resume(struct vcpu *v) }
xen/arch/x86/hvm/hvm.c void hvm_do_resume(struct vcpu *v) · line 542
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +3
-2/* Inject pending hw/sw trap */ -if ( v->arch.hvm_vcpu.inject_trap.vector !=-1 ) +if ( v->arch.hvm_vcpu.inject_trap.vector >=0 ) { +smp_rmb ();hvm_inject_trap (&v->arch.hvm_vcpu.inject_trap); - v->arch.hvm_vcpu.inject_trap.vector =-1 ; + v->arch.hvm_vcpu.inject_trap.vector =HVM_TRAP_VECTOR_UNSET ; } }
Does this mean I should rebase my vm_event patch?
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 8/8] x86/hvm: serialize trap injecting producer and consumer
In reply to Paul DurrantQuoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
Since injection works on a remote vCPU, and since there's no enforcement of the subject vCPU being paused, there's a potential race between the producing and consuming sides. Fix this by leveraging the vector field as synchronization variable.
Signed-off-by Jan Beulich <[email protected]>[re-based]Signed-off-by Paul Durrant <[email protected]>
At least this patch of the series should remain "From:" me; I haven't looked at the others yet, but I have to admit I'm puzzled that I haven't been Cc-ed on other than the one here and patch 1.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH-for-4.9 v1 8/8] x86/hvm: serialize trap injecting producer and consumer
Quoted 15 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 21 November 2016 07:54
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH-for-4.9 v1 8/8] x86/hvm: serialize trap injecting producer and consumerQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 18.11.16 at 18:14, <[email protected]> wrote:
Since injection works on a remote vCPU, and since there's no enforcement of the subject vCPU being paused, there's a potential race between the producing and consuming sides. Fix this by leveraging the vector field as synchronization variable.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Jan Beulich <[email protected]>[re-based]Signed-off-by Paul Durrant <[email protected]>At least this patch of the series should remain "From:" me; I haven't looked at the others yet, but I have to admit I'm puzzled that I haven't been Cc-ed on other than the one here and patch 1.
I'm puzzled as well because most patches are 'suggested-by' you. I guess it means that git-send-email doesn't consider that worthy of a cc... I'll manually add you to the cc list for future versions.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel