Add V4V to Xen (v7)
cover Add V4V to Xen (v7)
v7 changes:
- Remove v4v_send from the API (v4v_sendv should be used instead).
- Remove internal_v4v_iov
- Remove useless padding
- Switch back to use uint64_t for the pfn list instead of xen_pfn_t (to avoid some compat code)
- Rename v4v_iptable to v4v_table.
- Use __copy_to/from_guest when possible
v6 changes:
- Check compiler before using [0] or [].
v5 changes:
- Fix prototypes in v4v.h for do_v4v_op
- Add padding to make sure all the structures are 64 bits aligned
- Replace [0] with []
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
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 | 6 +- 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 | 1848 ++++++++++++++++++++++++++++++++++++ xen/include/public/v4v.h | 308 ++++++ xen/include/public/xen.h | 3 +- xen/include/xen/event.h | 3 + xen/include/xen/sched.h | 4 + xen/include/xen/v4v.h | 134 +++ 12 files changed, 2346 insertions(+), 17 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/3 xen: virq, remove VIRQ_XC_RESERVED
VIRQ_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
@@ -158,7 +158,6 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_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
Re: [PATCH 1/3] xen: virq, remove VIRQ_XC_RESERVED
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
VIRQ_XC_RESERVEDwas reserved for V4V but we have switched to event channels so this place holder is no longer required.
I don't recall what we settled on in earlier discussions here: Is it certain that re-use of this vIRQ won't cause problems when a guest trying to use it for another purpose would be run on a host having the supposed old meaning of it in use? If not, it may need to remain permanently reserved.
Jan
Re: [PATCH 1/3] xen: virq, remove VIRQ_XC_RESERVED
Quoted 10 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
VIRQ_XC_RESERVEDwas reserved for V4V but we have switched to event channels so this place holder is no longer required.I don't recall what we settled on in earlier discussions here: Is it certain that re-use of this vIRQ won't cause problems when a guest trying to use it for another purpose would be run on a host having the supposed old meaning of it in use? If not, it may need to remain permanently reserved.
Ok. I'll remove this patch from the next series.
That can be done later down the road.
Jean
PATCH 2/3 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
Re: [PATCH 2/3] xen: events, exposes evtchn_alloc_unbound_domain
Quoted 10 lines · Jean Guyader
Exposes
evtchn_alloc_unbound_domainto the rest of Xen so we can create allocated unbound evtchn within Xen.Signed-off-by Jean Guyader <[email protected]>--- xen/common/event_channel.c | 39 +++++++++++++++++++++++++++------------ xen/include/xen/event.h | 3 +++ 2 files changed, 30 insertions(+), 12 deletions(-)
I think this patch could be applied on its own. That will make the next v4v round
one patch smaller.
Jean
PATCH 3/3 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 | 6 +- 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 | 1848 ++++++++++++++++++++++++++++++++++++ xen/include/public/v4v.h | 308 ++++++ xen/include/public/xen.h | 2 +- xen/include/xen/sched.h | 4 + xen/include/xen/v4v.h | 134 +++ 10 files changed, 2316 insertions(+), 4 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 +4 -2
@@ -3242,7 +3242,8 @@ static hvm_hypercall_t *const 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) \
@@ -3259,7 +3260,8 @@ static hvm_hypercall_t *const hvm_hypercall32_table[NR_hypercalls] = {COMPAT_CALL (set_timer_op),HYPERCALL (hvm_op),HYPERCALL (sysctl), - HYPERCALL(tmem_op) +HYPERCALL (tmem_op), + HYPERCALL(v4v_op) };int hvm_do_hypercall (struct cpu_user_regs *regs)
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 )
@@ -489,6 +499,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 +1848 -0
1,848 lines not on this page · raw message
xen/include/public/v4v.h new file +308 -0
308 lines not on this page · raw message
xen/include/public/xen.h +1 -1
@@ -100,7 +100,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_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
@@ -24,6 +24,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>
@@ -363,6 +364,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 +134 -0
134 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] xen: Add V4V implementation
xen/include/public/v4v.h line 101
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/include/public/v4v.h new file +4
-0+typedef struct v4v_ring_data_ent +{ + v4v_addr_t ring; + uint16_t flags;
Missing padding here?
xen/include/public/v4v.h line 159
Quoted 10 lines
xen/include/public/v4v.h new file +9
-0+uint32_t space_required; +uint32_t max_message_size; +} v4v_ring_data_ent_t; +typedef struct v4vtables_rule +{ + v4v_addr_t src; + v4v_addr_t dst; + uint32_t accept; + uint32_t pad;
Pointless padding here?
xen/include/xen/v4v.h line 45
Quoted 13 lines
xen/include/xen/v4v.h new file +12
-0+} v4vtables_rule_t; +DEFINE_XEN_GUEST_HANDLE (v4v_iov_t); +DEFINE_XEN_GUEST_HANDLE (v4v_addr_t); +DEFINE_XEN_GUEST_HANDLE (v4v_send_addr_t); +DEFINE_XEN_GUEST_HANDLE (v4v_ring_t); +DEFINE_XEN_GUEST_HANDLE (v4v_ring_data_ent_t); +DEFINE_XEN_GUEST_HANDLE (v4v_ring_data_t); +DEFINE_XEN_GUEST_HANDLE (v4v_info_t); +DEFINE_XEN_GUEST_HANDLE (v4v_pfn_t); + +DEFINE_XEN_GUEST_HANDLE (v4vtables_rule_t); +DEFINE_XEN_GUEST_HANDLE (v4vtables_list_t);
Extra blanks before opening parens (also elsewhere).
xen/include/xen/v4v.h line 53
Quoted 7 lines
xen/include/xen/v4v.h new file +7
-0+/* +* Helper functions +*/ + +static inline uint16_t +v4v_hash_fn (v4v_ring_id_t *id) +{
These and the types further down make sense to be put in a globally visible header only if they are expected to be used from more than one source file.
Jan