Skip to contentSkip to conversation

Add V4V to Xen (v8)

PATCH In review Jean Guyader 3 participants 6 messages Oct 25, 2012 – Dec 21, 2012

lore
Share & tools
lore
#0 lore raw

cover Add V4V to Xen (v8)

v8 changes:
- Move v4v private structures to v4v.c
- fix padding
- Fix some coding style issues
- Drop the VIRQ_XC_RESERVED patch

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 (2):
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                   | 1922 ++++++++++++++++++++++++++++++++++++
 xen/include/public/v4v.h           |  308 ++++++
 xen/include/public/xen.h           |    2 +-
 xen/include/xen/event.h            |    3 +
 xen/include/xen/sched.h            |    4 +
 xen/include/xen/v4v.h              |   49 +
 12 files changed, 2335 insertions(+), 16 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

#1 lore raw

PATCH 1/2 xen: events, exposes evtchn_alloc_unbound_domain

Exposes 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
index a80a0d1..a868b89 100644
@@ -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
index 71c3e92..1a0c832 100644
@@ -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

#2 lore raw

PATCH 2/2 xen: Add V4V implementation

In reply to Jean Guyader

Setup 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                   | 1922 ++++++++++++++++++++++++++++++++++++
 xen/include/public/v4v.h           |  308 ++++++
 xen/include/public/xen.h           |    2 +-
 xen/include/xen/sched.h            |    4 +
 xen/include/xen/v4v.h              |   49 +
 10 files changed, 2305 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
index 34da2f5..e5237f9 100644
@@ -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
index e6b52f3..4902c4f 100644
@@ -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
index ffb9314..78006cf 100644
@@ -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
index c1c100f..ba63cec 100644
@@ -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
index 0e3e36a..60cd8e3 100644
@@ -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 +1922 -0

1,922 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
index 7352d1e..66a3605 100644
@@ -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
index 6c55039..2fd9313 100644
@@ -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 domain
     nodemask_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 +49 -0

49 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
In reply to Jean Guyader
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

v8 changes:
- Move v4v private structures to v4v.c
- fix padding

I still spotted at least one bogus padding field (in struct v4v_ring_message_header, where no field is more than 4-byte aligned afaict). Did you really carefully walk through all of them?

Also, to validate the structures are really compatible between native and compat mode guests, I'd strongly recommend adding the leaf ones to xen/include/xlat.lst.

Further I don't think you sync-ed up your patches with the XEN_GUEST_HANDLE_PARAM() changes done for ARM, yet you also didn't mention that the patch set is against other than the tip of unstable.

Quoted 1 line

- Fix some coding style issues

There appear to be plenty left (space between function name and opening parenthesis, indentation inside switch statement, missing parenthesization of macro expansion, missing newline between declarations and statements are which I noticed without specifically looking for them).

Jan

Quoted 1 line

- Drop the VIRQ_XC_RESERVED patch

#4 lore raw
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

v8 changes:
- Move v4v private structures to v4v.c
- fix padding

I still spotted at least one bogus padding field (in struct v4v_ring_message_header, where no field is more than 4-byte aligned afaict). Did you really carefully walk through all of them?

Hi Jan,
I am going to try and pilot this home, as I believe JeanG will not.

I just had a couple of questions about your comments that I hope you could help me with.

Quoted 3 lines

Also, to validate the structures are really compatible between native and compat mode guests, I'd strongly recommend adding the leaf ones to xen/include/xlat.lst.

I'm sorry I don't understand. What is xlat.lst ? And how does it help ?

Quoted 4 lines

Further I don't think you sync-ed up your patches with the XEN_GUEST_HANDLE_PARAM() changes done for ARM, yet you also didn't mention that the patch set is against other than the tip of unstable.

Sorry, again I'm confused. I thought all the Xen ARM changes went into xen-unstable.
What other branches/trees do you think I need to post the v4v patch set against ?

Quoted 8 lines

There appear to be plenty left (space between function name and opening parenthesis, indentation inside switch statement, missing parenthesization of macro expansion, missing newline between declarations and statements are which I noticed without specifically looking for them).

OK. This I can do.
dom

#5 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · dom
Quoted 4 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Also, to validate the structures are really compatible between native and compat mode guests, I'd strongly recommend adding the leaf ones to xen/include/xlat.lst.

I'm sorry I don't understand. What is xlat.lst ? And how does it help ?

This lists types that need either translation or verification that no translation is needed (i.e. structure layouts and type sizes being identical) for compatibility mode guest support.

Quoted 9 lines
Quoted 4 lines

Further I don't think you sync-ed up your patches with the XEN_GUEST_HANDLE_PARAM() changes done for ARM, yet you also didn't mention that the patch set is against other than the tip of unstable.

Sorry, again I'm confused. I thought all the Xen ARM changes went into xen-unstable.
What other branches/trees do you think I need to post the v4v patch set against ?

That's my point: The ARM changes went in, yet this patch didn't get sync-ed up accordingly (it ought to use the _PARAM() variant in all relevant places).

Jan