Add V4V to Xen
cover Add V4V to Xen
v4 changes:
- Stop using ssize_t, use long instead
- Return -MSGSIZE for message bigger than 2GB
- Fixup size handling
- Rename protocol with message_type to avoid the confusion with the IP protocol flag
- Replaced V4V_DOMID_ANY value with DOMID_INVALID
- Replaced v4v_pfn_t with xen_pfn_t
- Add padding to struct v4v_info
- Fixup hypercall documentation
- Move V4V_ROUNDUP to v4v.c
- Remove v4v_utils.h (we could potentially add it later).
v3 changes:
- Switch to event channel
- Allocated a unbound event channel
per domain.
- Add a new v4v call to share the
event channel port.
- Public headers with actual type definition
- Align all the v4v type to 64 bits
- Modify v4v MAGIC numbers because we won't
but backward compatible anymore
- Merge insert and insertv
- Merge send and sendv
- Turn all the lock prerequisite from comment
to ASSERT()
- Make use or write_atomic instead of volatile pointers
- Merge v4v_memcpy_to_guest_ring and v4v_memcpy_to_guest_ring_from_guest
- Introduce copy_from_guest_maybe that can take a void * and a handle as src address.
- Replace 6 arguments hypercalls with 5 arguments hypercalls.
v2 changes:
- Cleanup plugin header
- Include basic access control
- Use guest_handle_for_field
Jan Beulich (1):
xen: Introduce guest_handle_for_field
Jean Guyader (3):
xen: virq, remove VIRQ_XC_RESERVED
xen: events, exposes evtchn_alloc_unbound_domain
xen: Add V4V implementation
xen/arch/x86/hvm/hvm.c | 9 +- xen/arch/x86/x86_32/entry.S | 2 + xen/arch/x86/x86_64/compat/entry.S | 2 + xen/arch/x86/x86_64/entry.S | 2 + xen/common/Makefile | 1 + xen/common/domain.c | 13 +- xen/common/event_channel.c | 39 +- xen/common/v4v.c | 1907 ++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/guest_access.h | 3 + xen/include/public/v4v.h | 305 ++++++ xen/include/public/xen.h | 3 +- xen/include/xen/event.h | 3 + xen/include/xen/sched.h | 4 + xen/include/xen/v4v.h | 133 +++ 14 files changed, 2408 insertions(+), 18 deletions(-) create mode 100644 xen/common/v4v.c create mode 100644 xen/include/public/v4v.h create mode 100644 xen/include/xen/v4v.h
Signature · 1 line
1.7.9.5
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 1/4 xen: Introduce guest_handle_for_field
This helper turns a field of a GUEST_HANDLE in
a GUEST_HANDLE.
--- xen/include/asm-x86/guest_access.h | 3 +++ 1 file changed, 3 insertions(+)
xen/include/asm-x86/guest_access.h +3 -0
@@ -51,6 +51,9 @@ (XEN_GUEST_HANDLE (type )) { _x }; \ }) +#define guest_handle_for_field (hnd, type, fld) \ + ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld }) +#define guest_handle_from_ptr (ptr, type) \ ((XEN_GUEST_HANDLE(type)) { (type *)ptr })#define const_guest_handle_from_ptr (ptr, type) \
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 2/4 xen: virq, remove VIRQ_XC_RESERVED
In reply to Jean GuyaderVIRQ_XC_RESERVED was reserved for V4V but we have switched to event channels so this place holder is no longer required.
--- xen/include/public/xen.h | 1 - 1 file changed, 1 deletion(-)
xen/include/public/xen.h +0 -1
@@ -157,7 +157,6 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);#define VIRQ_CON_RING 8/* G. (DOM0) Bytes received on console */ #define VIRQ_PCPU_STATE 9/* G. (DOM0) PCPU state changed */ #define VIRQ_MEM_EVENT 10/* G. (DOM0) A memory event has occured */ -#define VIRQ_XC_RESERVED 11/* G. Reserved for XenClient */ #define VIRQ_ENOMEM 12/* G. (DOM0) Low on heap memory */ /* Architecture-specific VIRQ definitions. */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 3/4 xen: events, exposes evtchn_alloc_unbound_domain
In reply to Jean GuyaderExposes evtchn_alloc_unbound_domain to the rest of Xen so we can create allocated unbound evtchn within Xen.
--- xen/common/event_channel.c | 39 +++++++++++++++++++++++++++------------ xen/include/xen/event.h | 3 +++ 2 files changed, 30 insertions(+), 12 deletions(-)
xen/common/event_channel.c +27 -12
@@ -159,36 +159,51 @@ static int get_free_port(struct domain *d)static long evtchn_alloc_unbound (evtchn_alloc_unbound_t *alloc) { -struct evtchn *chn;struct domain *d; -int port; -domid_t dom = alloc->dom;long rc; - rc =rcu_lock_target_domain_by_id (dom, &d); + rc =rcu_lock_target_domain_by_id (alloc->dom, &d);if ( rc )return rc; + rc =evtchn_alloc_unbound_domain (d, &alloc->port, alloc->remote_dom); +if ( rc ) +ERROR_EXIT_DOM ((int )rc, d); + + out: +rcu_unlock_domain (d); + +return rc; +} + +int evtchn_alloc_unbound_domain (struct domain *d,evtchn_port_t *port, +domid_t remote_domid) +{ +struct evtchn *chn; +int rc; +int free_port; +spin_lock (&d->event_lock); -if ( (port =get_free_port (d)) <0 ) -ERROR_EXIT_DOM (port, d); - chn =evtchn_from_port (d, port); + rc = free_port =get_free_port (d); +if ( free_port <0 ) + goto out; - rc =xsm_evtchn_unbound (d, chn, alloc->remote_dom); + chn =evtchn_from_port (d, free_port); + rc =xsm_evtchn_unbound (d, chn, remote_domid);if ( rc ) goto out; chn->state =ECS_UNBOUND ; -if ( (chn->u.unbound.remote_domid = alloc->remote_dom) ==DOMID_SELF ) +if ( (chn->u.unbound.remote_domid = remote_domid) ==DOMID_SELF ) chn->u.unbound.remote_domid = current->domain->domain_id; - alloc->port = port; + *port = free_port; +/* Everything is fine, returns 0 */ + rc =0 ; out:spin_unlock (&d->event_lock); -rcu_unlock_domain (d); -return rc; }
xen/include/xen/event.h +3 -0
@@ -69,6 +69,9 @@ int guest_enabled_event(struct vcpu *v, uint32_t virq);/* Notify remote end of a Xen-attached event channel.*/ void notify_via_xen_event_channel (struct domain *ld,int lport); +int evtchn_alloc_unbound_domain (struct domain *d,evtchn_port_t *port, +domid_t remote_domid); +/* Internal event channel object accessors */ #define bucket_from_port (d,p) \ ((d)->evtchn[(p)/EVTCHNS_PER_BUCKET])
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 4/4 xen: Add V4V implementation
In reply to Jean GuyaderSetup of v4v domains a domain gets created and cleanup when a domain die. Wire up the v4v hypercall.
Include v4v internal and public headers.
--- xen/arch/x86/hvm/hvm.c | 9 +- xen/arch/x86/x86_32/entry.S | 2 + xen/arch/x86/x86_64/compat/entry.S | 2 + xen/arch/x86/x86_64/entry.S | 2 + xen/common/Makefile | 1 + xen/common/domain.c | 13 +- xen/common/v4v.c | 1907 ++++++++++++++++++++++++++++++++++++ xen/include/public/v4v.h | 305 ++++++ xen/include/public/xen.h | 2 +- xen/include/xen/sched.h | 4 + xen/include/xen/v4v.h | 133 +++ 11 files changed, 2375 insertions(+), 5 deletions(-) create mode 100644 xen/common/v4v.c create mode 100644 xen/include/public/v4v.h create mode 100644 xen/include/xen/v4v.h
xen/arch/x86/hvm/hvm.c +6 -3
@@ -3134,7 +3134,8 @@ static hvm_hypercall_t *hvm_hypercall32_table[NR_hypercalls] = {HYPERCALL (set_timer_op),HYPERCALL (hvm_op),HYPERCALL (sysctl), -HYPERCALL (tmem_op) +HYPERCALL (tmem_op), +HYPERCALL (v4v_op) };#else /* defined(__x86_64__) */
@@ -3219,7 +3220,8 @@ static hvm_hypercall_t *hvm_hypercall64_table[NR_hypercalls] = {HYPERCALL (set_timer_op),HYPERCALL (hvm_op),HYPERCALL (sysctl), - HYPERCALL(tmem_op) +HYPERCALL (tmem_op), + HYPERCALL(v4v_op) };#define COMPAT_CALL (x) \
@@ -3236,7 +3238,8 @@ static hvm_hypercall_t *hvm_hypercall32_table[NR_hypercalls] = {COMPAT_CALL (set_timer_op),HYPERCALL (hvm_op),HYPERCALL (sysctl), -HYPERCALL (tmem_op) +HYPERCALL (tmem_op), +HYPERCALL (v4v_op) };#endif /* defined(__x86_64__) */
xen/arch/x86/x86_32/entry.S +2 -0
@@ -700,6 +700,7 @@ ENTRY(hypercall_table) .long do_domctl .long do_kexec_op .long do_tmem_op + .long do_v4v_op .rept __HYPERVISOR_arch_0-((.-hypercall_table)/4) .long do_ni_hypercall .endr
@@ -748,6 +749,7 @@ ENTRY(hypercall_args_table) .byte 1 /* do_domctl */ .byte 2 /* do_kexec_op */ .byte 1 /* do_tmem_op */ + .byte 5 /* do_v4v_op */ .rept __HYPERVISOR_arch_0-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr
xen/arch/x86/x86_64/compat/entry.S +2 -0
@@ -414,6 +414,7 @@ ENTRY(compat_hypercall_table) .quad do_domctl .quad compat_kexec_op .quad do_tmem_op + .quad do_v4v_op .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8) .quad compat_ni_hypercall .endr
@@ -462,6 +463,7 @@ ENTRY(compat_hypercall_args_table) .byte 1 /* do_domctl */ .byte 2 /* compat_kexec_op */ .byte 1 /* do_tmem_op */ + .byte 5 /* do_v4v_op */ .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table) .byte 0 /* compat_ni_hypercall */ .endr
xen/arch/x86/x86_64/entry.S +2 -0
@@ -707,6 +707,7 @@ ENTRY(hypercall_table) .quad do_domctl .quad do_kexec_op .quad do_tmem_op + .quad do_v4v_op .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8) .quad do_ni_hypercall .endr
@@ -755,6 +756,7 @@ ENTRY(hypercall_args_table) .byte 1 /* do_domctl */ .byte 2 /* do_kexec */ .byte 1 /* do_tmem_op */ + .byte 5 /* do_v4v_op */ .rept __HYPERVISOR_arch_0-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr
xen/common/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-y += tmem_xen.o obj-y += radix-tree.o obj-y += rbtree.o obj-y += lzo.o +obj-y += v4v.o obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo,$(n).init.o)
xen/common/domain.c +12 -1
@@ -195,7 +195,8 @@ struct domain *domain_create( {struct domain *d, **pd;enum { INIT_xsm =1u <<0 , INIT_watchdog =1u <<1 , INIT_rangeset =1u <<2 , - INIT_evtchn =1u <<3 , INIT_gnttab =1u <<4 , INIT_arch =1u <<5 }; + INIT_evtchn =1u <<3 , INIT_gnttab =1u <<4 , INIT_arch =1u <<5 , + INIT_v4v =1u <<6 };int err, init_status =0 ;int poolid =CPUPOOLID_NONE ;
@@ -307,6 +308,13 @@ struct domain *domain_create(spin_unlock (&domlist_update_lock); } +if ( !is_idle_domain (d) ) + { +if (v4v_init (d) !=0 ) + goto fail; + init_status |= INIT_v4v; + } +return d; fail:
@@ -315,6 +323,8 @@ struct domain *domain_create(xfree (d->mem_event);if ( init_status & INIT_arch )arch_domain_destroy (d); +if ( init_status & INIT_v4v ) +v4v_destroy (d);if ( init_status & INIT_gnttab )grant_table_destroy (d);if ( init_status & INIT_evtchn )
@@ -468,6 +478,7 @@ int domain_kill(struct domain *d)domain_pause (d); d->is_dying = DOMDYING_dying;spin_barrier (&d->domain_lock); +v4v_destroy (d);evtchn_destroy (d);gnttab_release_mappings (d);tmem_destroy (d->tmem);
xen/common/v4v.c new file +1907 -0
1,907 lines not on this page · raw message
xen/include/public/v4v.h new file +305 -0
305 lines not on this page · raw message
xen/include/public/xen.h +1 -1
@@ -99,7 +99,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);#define __HYPERVISOR_domctl 36#define __HYPERVISOR_kexec_op 37#define __HYPERVISOR_tmem_op 38 -#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */ +#define __HYPERVISOR_v4v_op 39/* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/sched.h +4 -0
@@ -23,6 +23,7 @@#include <public/sysctl.h> #include <public/vcpu.h> #include <public/mem_event.h> +#include <xen/v4v.h> #ifdef CONFIG_COMPAT #include <compat/vcpu.h>
@@ -350,6 +351,9 @@ struct domainnodemask_t node_affinity;unsigned int last_alloc_node;spinlock_t node_affinity_lock; + +/* v4v */ +struct v4v_domain *v4v; };struct domain_setup_info
xen/include/xen/v4v.h new file +133 -0
133 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/4] xen: Introduce guest_handle_for_field
In reply to Jean GuyaderQuoted 5 lines · Jean Guyader
This helper turns a field of a
GUEST_HANDLEin
aGUEST_HANDLE.Signed-off-by Jean Guyader <[email protected]>
This patch is from Jan, sorry about that.
Jean
Re: [PATCH 4/4] xen: Add V4V implementation
In reply to Jean Guyaderxen/include/public/v4v.h line 41
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/include/public/v4v.h new file +5
-0+typedef struct v4v_iov +{ +uint64_t iov_base; +uint32_t iov_len; +}v4v_iov_t ;
Lost padding here?
xen/include/public/v4v.h line 80
Quoted 10 lines
xen/include/public/v4v.h new file +10
-0+struct v4v_ring +{ +uint64_t magic; +v4v_ring_id_t id; +uint32_t len; +uint32_t rx_ptr; +uint32_t tx_ptr; +uint8_t reserved[32 ]; +uint8_t ring[0 ]; +};
Zero-sized arrays are not standard C (not even C11 iirc), this is purely a GNU extension. This appears again elsewhere in this file.
xen/include/public/v4v.h line 98
Quoted 8 lines
xen/include/public/v4v.h new file +8
-0+typedef struct v4v_ring_data_ent +{ +v4v_addr_t ring; +uint16_t flags; +uint16_t pad; +uint32_t space_required; +uint32_t max_message_size; +}v4v_ring_data_ent_t ;
For me, this sums up to 20 bytes.
xen/include/public/v4v.h line 107
Quoted 8 lines
xen/include/public/v4v.h new file +8
-0+typedef struct v4v_ring_data +{ +uint64_t magic; +uint32_t nent; +uint32_t pad; +uint64_t reserved[4 ]; +v4v_ring_data_ent_t data[0 ]; +}v4v_ring_data_t ;
Consequently, sizeof(v4v_ring_data_t) will differ for 32- and 64-bit x86 guests. I can't tell whether that would matter though (due to the intended, but again wrongly done, trailing variable size array).
Quoted 1 line
+ *
V4VOP_register_ring
This conflicts with ...
Quoted 6 lines
+ *
+ * Registers a ring with Xen, if a ring with the samev4v_ring_idexists,
+ * this ring takes its place, registration will not changetx_ptr
+ * unless it is invalid
+ *
+ * do_v4v_op(V4VOP_unregister_ring,
... this.
Quoted 1 line
+ *
v4v_ring,XEN_GUEST_HANDLE(xen_pfn_t),
Missing indirection here? I doubt you want a structure passed by value... (Again reoccurs further down.)
Quoted 1 line
+ *
V4VOP_unregister_ring
Again conflicting with ...
Quoted 4 lines
+ *
+ * Unregister a ring.
+ *
+ *do_v4v_op(V4VOP_send, v4v_ring, NULL, 0, 0)
... this.
Quoted 3 lines
+ * do_v4v_op(V4VOP_send,
+ *v4v_send_addr_taddr,
+ * void* buf,
XEN_GUEST_HANDLE(void) or, given this is a send, probably rather XEN_GUEST_HANDLE(const_void). But then again this would conflict with the real do_v4v_op() declaration.
Jan