Skip to contentSkip to conversation

RFC: V4V (v3)

PATCH In review Jean Guyader 8 participants 50 messages Aug 3, 2012 – Jun 13, 2013

lore
Share & tools
lore
#0 lore raw

cover RFC: V4V (v3)

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.
- TODO:
- Add libv4v userspace code

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 (4):
xen: add ssize_t
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         |   33 +-
 xen/common/v4v.c                   | 1895 ++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/types.h        |    1 +
 xen/include/asm-x86/guest_access.h |    3 +
 xen/include/asm-x86/types.h        |    6 +
 xen/include/public/v4v.h           |  291 ++++++
 xen/include/public/xen.h           |    3 +-
 xen/include/xen/event.h            |    2 +
 xen/include/xen/sched.h            |    4 +
 xen/include/xen/v4v.h              |  134 +++
 xen/include/xen/v4v_utils.h        |  276 ++++++
 17 files changed, 2665 insertions(+), 12 deletions(-)
 create mode 100644 xen/common/v4v.c
 create mode 100644 xen/include/public/v4v.h
 create mode 100644 xen/include/xen/v4v.h
 create mode 100644 xen/include/xen/v4v_utils.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/5 xen: add ssize_t

---
 xen/include/asm-arm/types.h |    1 +
 xen/include/asm-x86/types.h |    6 ++++++
 2 files changed, 7 insertions(+)
xen/include/asm-arm/types.h +1 -0
index 48864f9..d2c5612 100644
@@ -35,6 +35,7 @@ typedef u64 paddr_t;
 #define PRIpaddr "016llx"
 
 typedef unsigned long size_t;
+typedef long ssize_t;
 
 typedef char bool_t;
 #define test_and_set_bool(b)   xchg(&(b), 1)
xen/include/asm-x86/types.h +6 -0
index 1c4c5d5..bb7ffc2 100644
@@ -59,6 +59,12 @@ typedef char bool_t;
 #define test_and_set_bool(b)   xchg(&(b), 1)
 #define test_and_clear_bool(b) xchg(&(b), 0)
 
+#if defined(__i386__)
+typedef int ssize_t;
+#else /* __x86_64 */
+typedef long ssize_t;
+#endif
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __X86_TYPES_H__ */

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

#11 lore raw

PATCH 2/5 xen: Introduce guest_handle_for_field

In reply to Jean Guyader

This helper turns a field of a GUEST_HANDLE in
a GUEST_HANDLE.

From: Jan Beulich <[email protected]>

---
 xen/include/asm-x86/guest_access.h |    3 +++
 1 file changed, 3 insertions(+)
xen/include/asm-x86/guest_access.h +3 -0
index 2b429c2..e3ac1d6 100644
@@ -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

#12 lore raw

PATCH 3/5 xen: virq, remove VIRQ_XC_RESERVED

In reply to Jean Guyader

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
index b2f6c50..b19425b 100644
@@ -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

#20 lore raw

PATCH 4/5 xen: events, exposes evtchn_alloc_unbound_domain

In reply to Jean Guyader

Exposes evtchn_alloc_unbound_domain to the rest of Xen so we can create allocated unbound evtchn within Xen.

---
 xen/common/event_channel.c |   33 +++++++++++++++++++++++++++------
 xen/include/xen/event.h    |    2 ++
 2 files changed, 29 insertions(+), 6 deletions(-)
xen/common/event_channel.c +27 -6
index 53777f8..067365b 100644
@@ -51,6 +51,8 @@
 
 #define consumer_is_xen(e) (!!(e)->xen_consumer)
 
+static long __evtchn_close(struct domain *d, int port);
+
 /*
  * The function alloc_unbound_xen_event_channel() allows an arbitrary
  * notifier function to be specified. However, very few unique functions
@@ -161,18 +163,18 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 {
     struct evtchn *chn;
     struct domain *d;
-    int            port;
+    evtchn_port_t  port;
     domid_t        dom = alloc->dom;
-    long           rc;
+    int            rc;
 
     rc = rcu_lock_target_domain_by_id(dom, &d);
     if ( rc )
         return rc;
 
-    spin_lock(&d->event_lock);
+    rc = evtchn_alloc_unbound_domain(d, &port);
+    if ( rc )
+        ERROR_EXIT_DOM(rc, d);
 
-    if ( (port = get_free_port(d)) < 0 )
-        ERROR_EXIT_DOM(port, d);
     chn = evtchn_from_port(d, port);
 
     rc = xsm_evtchn_unbound(d, chn, alloc->remote_dom);
@@ -186,12 +188,31 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     alloc->port = port;
 
  out:
-    spin_unlock(&d->event_lock);
     rcu_unlock_domain(d);
 
     return rc;
 }
 
+int evtchn_alloc_unbound_domain(struct domain *d, evtchn_port_t *port)
+{
+    struct evtchn *chn;
+    int            free_port = 0;
+
+    spin_lock(&d->event_lock);
+
+    if ( (free_port = get_free_port(d)) < 0 )
+        goto out;
+    chn = evtchn_from_port(d, free_port);
+    chn->state = ECS_UNBOUND;
+    chn->u.unbound.remote_domid = DOMID_INVALID;
+    *port = free_port;
+    /* Everything is fine, returns 0 */
+    free_port = 0;
+
+ out:
+    spin_unlock(&d->event_lock);
+    return free_port;
+}
 
 static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
 {
xen/include/xen/event.h +2 -0
index 71c3e92..d89b0c1 100644
@@ -69,6 +69,8 @@ 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);
+
 /* 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

#31 lore raw

PATCH 5/5 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             |    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                   | 1895 ++++++++++++++++++++++++++++++++++++
 xen/include/public/v4v.h           |  291 ++++++
 xen/include/public/xen.h           |    2 +-
 xen/include/xen/sched.h            |    4 +
 xen/include/xen/v4v.h              |  134 +++
 xen/include/xen/v4v_utils.h        |  276 ++++++
 12 files changed, 2626 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
 create mode 100644 xen/include/xen/v4v_utils.h
xen/arch/x86/hvm/hvm.c +6 -3
index 22c136b..2671069 100644
@@ -3125,7 +3125,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__) */
@@ -3210,7 +3211,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)                                        \
@@ -3227,7 +3229,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
index 2982679..5b1f55b 100644
@@ -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
index f49ff2d..6b838d3 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 997bc94..e6a7fdd 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 9eba8bc..fe3c72c 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 4c5d241..1600f45 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 init_status = 0;
     int poolid = CPUPOOLID_NONE;
 
@@ -305,6 +306,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:
@@ -313,6 +321,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 )
@@ -466,6 +476,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 +1895 -0

1,895 lines not on this page · raw message

xen/include/public/v4v.h new file +291 -0

291 lines not on this page · raw message

xen/include/public/xen.h +1 -1
index b19425b..868d119 100644
@@ -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
index 53804c8..296de52 100644
@@ -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 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 +134 -0

134 lines not on this page · raw message

xen/include/xen/v4v_utils.h new file +276 -0

276 lines not on this page · raw message

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

#49 lore raw
In reply to Jean Guyader
Quoted 11 lines · Jean Guyader

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

Quoted 8 lines

- 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.

Jean

#2 lore raw

Re: [PATCH 1/5] xen: add ssize_t

In reply to Jean Guyader
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Without finally explaining why you need this type in the first place, I'll continue to NAK this patch. (This is made even worse by the fact taht the two inline functions in patch 5 that make use of the type appear to be unused.)

Jan

#13 lore raw

Re: [PATCH 3/5] xen: virq, remove VIRQ_XC_RESERVED

In reply to Jean Guyader
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

VIRQ_XC_RESERVED was reserved for V4V but we have switched to event channels so this place holder is no longer required.

I'm fine with this change, but is a future re-use of the value indeed not going to cause problems on XenServer (or wherever else this is patch set coming from)?

Jan

Quoted 4 lines
---
 xen/include/public/xen.h |    1 -
 1 file changed, 1 deletion(-)
#21 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

In reply to Jean Guyader

xen/common/event_channel.c line 54

Quoted 8 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/common/event_channel.c +1 -0
@@ -51,6 +51,8 @@
 
 #define consumer_is_xen(e) (!!(e)->xen_consumer)
 
+static long __evtchn_close(struct domain *d, int port);

What is this needed for?

Quoted 38 lines
xen/common/event_channel.c +6 -6
+
 /*
 * The function alloc_unbound_xen_event_channel() allows an arbitrary
 * notifier function to be specified. However, very few unique functions
@@ -161,18 +163,18 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 {
    struct evtchn *chn;
    struct domain *d;
-    int            port;
+    evtchn_port_t  port;
    domid_t        dom = alloc->dom;
-    long           rc;
+    int            rc;
 
    rc = rcu_lock_target_domain_by_id(dom, &d);
    if ( rc )
        return rc;
 
-    spin_lock(&d->event_lock);
+    rc = evtchn_alloc_unbound_domain(d, &port);
+    if ( rc )
+        ERROR_EXIT_DOM(rc, d);
 
-    if ( (port = get_free_port(d)) < 0 )
-        ERROR_EXIT_DOM(port, d);
    chn = evtchn_from_port(d, port);
 
    rc = xsm_evtchn_unbound(d, chn, alloc->remote_dom);
@@ -186,12 +188,31 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
    alloc->port = port;
 
 out:
-    spin_unlock(&d->event_lock);
    rcu_unlock_domain(d);
 
    return rc;
 }
 

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 205

Quoted 10 lines
xen/common/event_channel.c +10 -0
+int evtchn_alloc_unbound_domain(struct domain *d, evtchn_port_t *port)
+{
+    struct evtchn *chn;
+    int            free_port = 0;
+
+    spin_lock(&d->event_lock);
+
+    if ( (free_port = get_free_port(d)) < 0 )
+        goto out;
+    chn = evtchn_from_port(d, free_port);

The code below this is not really a plain breakout from the function above:

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 206

Quoted 1 line
xen/common/event_channel.c +1 -0
+    chn->state = ECS_UNBOUND;

The equivalent to this ought to be removed from the original function as being redundant.

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 207

Quoted 1 line
xen/common/event_channel.c +1 -0
+    chn->u.unbound.remote_domid = DOMID_INVALID;

The single caller here will immediately overwrite this value. It would seem more clean to simply pass in the intended value, and eliminate the corresponding code from the caller too.

Jan

Quoted 11 lines
xen/common/event_channel.c +8 -0
+    *port = free_port;
+    /* Everything is fine, returns 0 */
+    free_port = 0;
+
+ out:
+    spin_unlock(&d->event_lock);
+    return free_port;
+}
 
 static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
 {
#32 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

In reply to Jean Guyader

xen/include/public/v4v.h line 34

Quoted 5 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/include/public/v4v.h new file +1 -0
...
+#define V4V_DOMID_ANY           0x7fffU

I think I asked this before - why not use one of the pre-existing DOMID values? And if there is a good reason, it should be said here in a comment, to avoid the same question being asked later again.

Quoted 2 lines

...
+typedef uint64_t v4v_pfn_t;

We already have xen_pfn_t, so why do you need yet another flavor?

xen/include/public/v4v.h line 115

Quoted 6 lines

...

xen/include/public/v4v.h new file +5 -0
+struct v4v_info
+{
+    uint64_t ring_magic;
+    uint64_t data_magic;
+    evtchn_port_t evtchn;

Missing padding at the end?

xen/include/public/v4v.h line 119

Quoted 4 lines
xen/include/public/v4v.h new file +4 -0
+};
+typedef struct v4v_info v4v_info_t;
+
+#define V4V_ROUNDUP(a) (((a) +0xf ) & ~0xf)

Doesn't seem to belong here. Or is the subsequent comment actually related to this (in which case it should be moved ahead of the definition and made match it).

xen/include/public/v4v.h line 167

Quoted 11 lines
xen/include/public/v4v.h new file +9 -0
+/*
+ * Messages on the ring are padded to 128 bits
+ * Len here refers to the exact length of the data not including the
+ * 128 bit header. The message uses
+ * ((len +0xf) & ~0xf) + sizeof(v4v_ring_message_header) bytes
+ */
...
+/*
+ * HYPERCALLS
+ */
...

In the block below here, please get the naming (do_v4v_op() vs v4v_hypercall()) and the use of newlines (either always one or always two between individual hypercall descriptions) consistent. Hmm, even the descriptions don't seem to always match the definitions (not really obvious because apparently again the descriptions follow the definitions, whereas the opposite is the usual way to arrange things).

Quoted 5 lines
xen/include/xen/v4v_utils.h new file +2 -0
...
+/* Compiler specific hacks */
+#if defined(__GNUC__)

xen/include/xen/v4v_utils.h line 32

Quoted 10 lines
xen/include/xen/v4v_utils.h new file +10 -0
+# define V4V_UNUSED __attribute__ ((unused))
+# ifndef __STRICT_ANSI__
+#  define V4V_INLINE inline
+# else
+#  define V4V_INLINE
+# endif
+#else /* !__GNUC__ */
+# define V4V_UNUSED
+# define V4V_INLINE
+#endif

This suggests the header is really intended to be public?

xen/include/xen/v4v_utils.h line 40

Quoted 3 lines

...

xen/include/xen/v4v_utils.h new file +2 -0
+static V4V_INLINE uint32_t
+v4v_ring_bytes_to_read (volatile struct v4v_ring *r)

No space between function name and opening parenthesis (throughout this file).

Quoted 2 lines

...
+V4V_UNUSED static V4V_INLINE ssize_t

V4V_UNUSED? Doesn't make sense in conjunction with V4V_INLINE, at least as long as you're using GNU extensions anyway (see above as to the disposition of the header).

xen/include/xen/v4v_utils.h line 57

Quoted 2 lines
xen/include/xen/v4v_utils.h new file +2 -0
+v4v_copy_out (struct v4v_ring *r, struct v4v_addr *from, uint32_t * protocol,
+              void *_buf, size_t t, int consume)

Dead functions shouldn't be placed here.

xen/include/xen/v4v_utils.h line 186

Quoted 11 lines

...

xen/include/xen/v4v_utils.h new file +10 -0
+static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip) V4V_UNUSED;
+
+V4V_INLINE static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip)
+{

What's the point of having a declaration followed immediately by a definition? Also, the function is dead too.

Jan

#14 lore raw

Re: [PATCH 3/5] xen: virq, remove VIRQ_XC_RESERVED

In reply to Jan Beulich
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

VIRQ_XC_RESERVED was reserved for V4V but we have switched to event channels so this place holder is no longer required.

I'm fine with this change, but is a future re-use of the value indeed not going to cause problems on XenServer (or wherever else this is patch set coming from)?

That may need to be confirmed but I don't think XenServer is using v4v yet, their plan
is to pick it up from upstream. So removing this VIRQ should be fine.

Jean

#3 lore raw

Re: [PATCH 1/5] xen: add ssize_t

In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Without finally explaining why you need this type in the first place, I'll continue to NAK this patch. (This is made even worse by the fact taht the two inline functions in patch 5 that make use of the type appear to be unused.)

Understood. I'll switch to use long instead of ssize_t in my forthcoming patch serie.

Jean

#15 lore raw

Re: [PATCH 3/5] xen: virq, remove VIRQ_XC_RESERVED

In reply to Jean Guyader
Quoted 8 lines · Jean Guyader
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

VIRQ_XC_RESERVED was reserved for V4V but we have switched to event channels so this place holder is no longer required.

I'm fine with this change, but is a future re-use of the value indeed not going to cause problems on XenServer (or wherever else this is patch set coming from)?

Quoted 5 lines

That may need to be confirmed but I don't think XenServer is using v4v yet, their plan
is to pick it up from upstream. So removing this VIRQ should be fine.

Jean

Yes - we don't use it, but are interested when XenClient can successfully upstream it.

~Andrew

Quoted 5 lines

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

Signature · 2 lines
Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer
T: +44 (0)1223 225 900, http://www.citrix.com
#16 lore raw

Re: [PATCH 3/5] xen: virq, remove VIRQ_XC_RESERVED

In reply to Jean Guyader
Quoted 5 lines · Jean Guyader
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

VIRQ_XC_RESERVED was reserved for V4V but we have switched to event channels so this place holder is no longer required.

Quoted 7 lines
Quoted 4 lines

I'm fine with this change, but is a future re-use of the value indeed not going to cause problems on XenServer (or wherever else this is patch set coming from)?

That may need to be confirmed but I don't think XenServer is using v4v yet

I think Jan probably meant XenClient (i.e. that being the place where v4v is already deployed).

There's no harm in keeping this # reserved indefinitely, with a suitable comment, I think? The only reason not to would be if this address space was limited, but I don't think that is the case with VIRQs

#17 lore raw

Re: [PATCH 3/5] xen: virq, remove VIRQ_XC_RESERVED

Quoted 14 lines · Ian Campbell
Quoted 5 lines · Jean Guyader
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

VIRQ_XC_RESERVED was reserved for V4V but we have switched to event channels so this place holder is no longer required.

Quoted 7 lines
Quoted 4 lines

I'm fine with this change, but is a future re-use of the value indeed not going to cause problems on XenServer (or wherever else this is patch set coming from)?

That may need to be confirmed but I don't think XenServer is using v4v yet

Quoted 8 lines

I think Jan probably meant XenClient (i.e. that being the place where v4v is already deployed).

There's no harm in keeping this # reserved indefinitely, with a suitable comment, I think? The only reason not to would be if this address space was limited, but I don't think that is the case with VIRQs

I think if XenClient rebase to a new version of Xen we will probably use the version of
v4v that comes with it and we will not try to rebase the old code on the newer Xen.

But if you think we should keep it I don't mind.

Jean

#18 lore raw

Re: [PATCH 3/5] xen: virq, remove VIRQ_XC_RESERVED

Quoted 24 lines · Jean Guyader
Quoted 14 lines · Ian Campbell
Quoted 5 lines · Jean Guyader
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

VIRQ_XC_RESERVED was reserved for V4V but we have switched to event channels so this place holder is no longer required.

Quoted 7 lines
Quoted 4 lines

I'm fine with this change, but is a future re-use of the value indeed not going to cause problems on XenServer (or wherever else this is patch set coming from)?

That may need to be confirmed but I don't think XenServer is using v4v yet

Quoted 8 lines

I think Jan probably meant XenClient (i.e. that being the place where v4v is already deployed).

There's no harm in keeping this # reserved indefinitely, with a suitable comment, I think? The only reason not to would be if this address space was limited, but I don't think that is the case with VIRQs

Quoted 4 lines

I think if XenClient rebase to a new version of Xen we will probably use the version of
v4v that comes with it and we will not try to rebase the old code on the newer Xen.

I think Jan's concern was if a current client runs on some future version of Xen which has reused that VIRQ for something else, some sort of weirdness would probably ensue?

Probably not as bad for a VIRQ as reusing a hypercall number...

Quoted 4 lines

But if you think we should keep it I don't mind.

Jean

#19 lore raw

Re: [PATCH 3/5] xen: virq, remove VIRQ_XC_RESERVED

Quoted 26 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 24 lines · Jean Guyader
Quoted 22 lines · Ian Campbell
Quoted 5 lines · Jean Guyader
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

VIRQ_XC_RESERVED was reserved for V4V but we have switched to event channels so this place holder is no longer required.

Quoted 7 lines
Quoted 4 lines

I'm fine with this change, but is a future re-use of the value indeed not going to cause problems on XenServer (or wherever else this is patch set coming from)?

That may need to be confirmed but I don't think XenServer is using v4v yet

I think Jan probably meant XenClient (i.e. that being the place where v4v is already deployed).

There's no harm in keeping this # reserved indefinitely, with a suitable comment, I think? The only reason not to would be if this address space was limited, but I don't think that is the case with VIRQs

Quoted 8 lines
Quoted 4 lines

I think if XenClient rebase to a new version of Xen we will probably use the version of
v4v that comes with it and we will not try to rebase the old code on the newer Xen.

I think Jan's concern was if a current client runs on some future version of Xen which has reused that VIRQ for something else, some sort of weirdness would probably ensue?

That was exactly the point of my inquiry.

Jan

#4 lore raw

Re: [PATCH 1/5] xen: add ssize_t

In reply to Jean Guyader
Quoted 11 lines · Jean Guyader
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Without finally explaining why you need this type in the first place, I'll continue to NAK this patch. (This is made even worse by the fact taht the two inline functions in patch 5 that make use of the type appear to be unused.)

Understood. I'll switch to use long instead of ssize_t in my forthcoming patch serie.

Please use an explicitly 64-bit type - AFAICS you're holding the sum of some 64-bit length fields.

Cheers,

Tim.

#22 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

In reply to Jean Guyader
Quoted 7 lines · Jean Guyader

Exposes evtchn_alloc_unbound_domain to the rest of Xen so we can create allocated unbound evtchn within Xen.

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 168

Quoted 8 lines
xen/common/event_channel.c +2 -2
@@ -161,18 +163,18 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 {
     struct evtchn *chn;
     struct domain *d;
-    int            port;
+    evtchn_port_t  port;
     domid_t        dom = alloc->dom;
-    long           rc;
+    int            rc;

The function returns long; if you're tidying this up to be an int, might as well change the return type too.

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 174

Quoted 7 lines
xen/common/event_channel.c +1 -1
     rc = rcu_lock_target_domain_by_id(dom, &d);
     if ( rc )
         return rc;
 
-    spin_lock(&d->event_lock);
+    rc = evtchn_alloc_unbound_domain(d, &port);

This moves some of the setting of channel state before the xsm hook. Also, the state changes lower down in this function are no longer under the event_lock. :(

Cheers,

Tim.

#5 lore raw

Re: [PATCH 1/5] xen: add ssize_t

In reply to Tim Deegan
Quoted 10 lines · Tim Deegan
Quoted 9 lines · Jean Guyader
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Without finally explaining why you need this type in the first place, I'll continue to NAK this patch. (This is made even worse by the fact taht the two inline functions in patch 5 that make use of the type appear to be unused.)

Quoted 6 lines
Quoted 2 lines

Understood. I'll switch to use long instead of ssize_t in my forthcoming patch serie.

Please use an explicitly 64-bit type - AFAICS you're holding the sum of some 64-bit length fields.

Ok but ssize_t is kind of a funny one. It should accept everything that size_t can accept + negative values.

The linux kernel is defining ssize_t as int for 32b and long for 64b. I could do the same then check for the
size of the copy and if it's bigger than MAX_INT|MAX_LONG return -EMSGSIZE.

http://lxr.free-electrons.com/source/include/asm-generic/posix_types.h#L68
(look for __kernel_ssize_t)

Jean

#23 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

In reply to Tim Deegan
Quoted 7 lines · Tim Deegan
Quoted 5 lines · Jean Guyader

Exposes evtchn_alloc_unbound_domain to the rest of Xen so we can create allocated unbound evtchn within Xen.

Quoted 12 lines

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 168

Quoted 9 lines
xen/common/event_channel.c +2 -2
@@ -161,18 +163,18 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 {
     struct evtchn *chn;
     struct domain *d;
-    int            port;
+    evtchn_port_t  port;
     domid_t        dom = alloc->dom;
-    long           rc;
+    int            rc;

The function returns long; if you're tidying this up to be an int, might as well change the return type too.

I'm not sure if this is relevant but Jan just sent a patch to "make all (native) hypercalls consistently have "long" return type". I think/suspect this rc here turns into the result of the hypercall?

Jan's patch was motivated by something to do with sign extension when a hypercall's int return is written to the long in the multicall arg struct which causes strangeness. Perhaps not totally relevant to evtchn_alloc which is unlikely to be in a MC.

Ian.

#24 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

Quoted 21 lines · Ian Campbell
Quoted 7 lines · Tim Deegan
Quoted 5 lines · Jean Guyader

Exposes evtchn_alloc_unbound_domain to the rest of Xen so we can create allocated unbound evtchn within Xen.

Quoted 12 lines

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 168

Quoted 9 lines
xen/common/event_channel.c +2 -2
@@ -161,18 +163,18 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 {
     struct evtchn *chn;
     struct domain *d;
-    int            port;
+    evtchn_port_t  port;
     domid_t        dom = alloc->dom;
-    long           rc;
+    int            rc;

The function returns long; if you're tidying this up to be an int, might as well change the return type too.

Quoted 8 lines

I'm not sure if this is relevant but Jan just sent a patch to "make all (native) hypercalls consistently have "long" return type". I think/suspect this rc here turns into the result of the hypercall?

Jan's patch was motivated by something to do with sign extension when a hypercall's int return is written to the long in the multicall arg struct which causes strangeness. Perhaps not totally relevant to evtchn_alloc which is unlikely to be in a MC.

Yes, this eventually ends up in a hypercall handler, but s/long/int/ here doesn't cause problems because
- rc is only ever set to an 'int' value here so we can't lose data from the type being too narrow; and
- Those int values get cast up to long (either in here or in the caller) directly, which will sign-extend the.

It really doesn't matter whether this function returns an int or a long, but it's a bit untidy to change it half-way.

Tim.

#44 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

In reply to Jean Guyader

Hi,

This looks pretty good; I think you've addressed almost all my comments except for one, which is really a design decision raether than an implementation one. As I said last time:

] And what about protocol? Protocol seems to have ended up as a bit of a ] second-class citizen in v4v; it's defined, and indeed required, but not ] used for routing or for acccess control, so all traffic to a given port ] _on every protocol_ ends up on the same ring.
]
] This is the inverse of the TCP/IP namespace that you're copying, where ] protocol demux happens before port demux. And I think it will bite ] someone if you ever, for example, want to send ICMP or GRE over a v4v ] channel.

I see Jan has some comments on the detail; all I have to add is this:

xen/common/v4v.c line 46

Quoted 4 lines · Jean Guyader
xen/common/v4v.c new file +4 -0
+
+
+struct list_head viprules = LIST_HEAD_INIT(viprules);
+static DEFINE_RWLOCK(viprules_lock);

Please add comments describing this lock and where it comes in the locking order relative to the locks below -- it looks like it's always taken after any other locks but please make it clear.

xen/include/public/v4v.h line 29

Quoted 6 lines
xen/include/public/v4v.h new file +6 -0
+/*
+ * Structure definitions
+ */
+
+#define V4V_RING_MAGIC          0xA822f72bb0b9d8cc
+#define V4V_RING_DATA_MAGIC	0x45fe852220b801d4

Thanks for getting rid of the #ifdefs here, but you need to keep the 'ULL' suffix so this will compile properly on 32-bit.

Cheers,

Tim.

#6 lore raw

Re: [PATCH 1/5] xen: add ssize_t

In reply to Jean Guyader
Quoted 15 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 13 lines · Tim Deegan
Quoted 11 lines · Jean Guyader
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Without finally explaining why you need this type in the first place, I'll continue to NAK this patch. (This is made even worse by the fact taht the two inline functions in patch 5 that make use of the type appear to be unused.)

Understood. I'll switch to use long instead of ssize_t in my forthcoming patch serie.

Quoted 6 lines
Quoted 3 lines

Please use an explicitly 64-bit type - AFAICS you're holding the sum of some 64-bit length fields.

Ok but ssize_t is kind of a funny one. It should accept everything that size_t can accept + negative values.

No. It's the same relation as between e.g. "signed int" and "unsigned int". Value preserving conversions are only guaranteed for non-negative values fitting both types.

Jan

#25 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

In reply to Tim Deegan
Quoted 38 lines · Tim Deegan
Quoted 21 lines · Ian Campbell
Quoted 7 lines · Tim Deegan
Quoted 5 lines · Jean Guyader

Exposes evtchn_alloc_unbound_domain to the rest of Xen so we can create allocated unbound evtchn within Xen.

Quoted 12 lines

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 168

Quoted 9 lines
xen/common/event_channel.c +2 -2
@@ -161,18 +163,18 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 {
     struct evtchn *chn;
     struct domain *d;
-    int            port;
+    evtchn_port_t  port;
     domid_t        dom = alloc->dom;
-    long           rc;
+    int            rc;

The function returns long; if you're tidying this up to be an int, might as well change the return type too.

Quoted 8 lines

I'm not sure if this is relevant but Jan just sent a patch to "make all (native) hypercalls consistently have "long" return type". I think/suspect this rc here turns into the result of the hypercall?

Jan's patch was motivated by something to do with sign extension when a hypercall's int return is written to the long in the multicall arg struct which causes strangeness. Perhaps not totally relevant to evtchn_alloc which is unlikely to be in a MC.

Yes, this eventually ends up in a hypercall handler, but s/long/int/ here doesn't cause problems because
- rc is only ever set to an 'int' value here so we can't lose data from the type being too narrow; and
- Those int values get cast up to long (either in here or in the caller) directly, which will sign-extend the.

Quoted 3 lines

It really doesn't matter whether this function returns an int or a long, but it's a bit untidy to change it half-way.

The main reason why I changed it only base ERROR_EXIT_DOM expects an int based on the format string. I guess I could cast the long in int for the call to ERROR_EXIT_DOM
but that doesn't really look nice either.

Jean

#7 lore raw

Re: [PATCH 1/5] xen: add ssize_t

In reply to Jan Beulich
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 16 lines · Tim Deegan
Quoted 11 lines · Jean Guyader
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Without finally explaining why you need this type in the first place, I'll continue to NAK this patch. (This is made even worse by the fact taht the two inline functions in patch 5 that make use of the type appear to be unused.)

Understood. I'll switch to use long instead of ssize_t in my forthcoming patch serie.

Please use an explicitly 64-bit type - AFAICS you're holding the sum of some 64-bit length fields.

Quoted 7 lines
Quoted 2 lines

Ok but ssize_t is kind of a funny one. It should accept everything that size_t can accept + negative values.

No. It's the same relation as between e.g. "signed int" and "unsigned int". Value preserving conversions are only guaranteed for non-negative values fitting both types.

ssize_t is a *signed* type, I was wrong by saying that it should accept all the range of a size_t, it allows only
a subset of it. read/write used ssize_t as a return type.

Quoted 1 line

From man 2 read:

If count is zero, read() returns zero and has no other results. If count is greater than SSIZE_MAX, the result is unspecified.

Would it be ok to claim the same thing here? i.e. if count > INT_MAX the result is unspecified.

Jean

#9 lore raw

Re: [PATCH 1/5] xen: add ssize_t

In reply to Jean Guyader
Quoted 14 lines · Jean Guyader
Quoted 13 lines · Tim Deegan
Quoted 11 lines · Jean Guyader
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Without finally explaining why you need this type in the first place, I'll continue to NAK this patch. (This is made even worse by the fact taht the two inline functions in patch 5 that make use of the type appear to be unused.)

Understood. I'll switch to use long instead of ssize_t in my forthcoming patch serie.

Quoted 6 lines
Quoted 3 lines

Please use an explicitly 64-bit type - AFAICS you're holding the sum of some 64-bit length fields.

Ok but ssize_t is kind of a funny one. It should accept everything that size_t can accept + negative values.

Given that you start with user-supplied 64-bit iov lengths, there is no such type. :)

And now that I look at it, your handling of sizes is pretty confused. v4v_ringbuf_insertv() returns a ssize_t, but calculates it internally as an int32_t, which is _smaller_ than the size_t it starts with (which is the sum of some guest-supplied uint64_ts). And then v4v_sendv() puts that ssize_t into an int again before returning it as a size_t, which d_v4v_op() casts as a long to give to the guest. Whee!

Can you please make that lot consistent, and then audit the whole path from user-supplied iovec lists to actual copies and make sure that there are no overflows?

I think that explicitly limiting your sum-of-iovec-lengths to 31 bits would be perfectly reasonable (1 hypercall per 2GB copy), and would avoid a lot of pain here. As long as it was documented in the interface, of course!

Cheers,

Tim.

#10 lore raw

Re: [PATCH 1/5] xen: add ssize_t

Quoted 32 lines · Tim Deegan
Quoted 14 lines · Jean Guyader
Quoted 13 lines · Tim Deegan
Quoted 11 lines · Jean Guyader
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Without finally explaining why you need this type in the first place, I'll continue to NAK this patch. (This is made even worse by the fact taht the two inline functions in patch 5 that make use of the type appear to be unused.)

Understood. I'll switch to use long instead of ssize_t in my forthcoming patch serie.

Quoted 6 lines
Quoted 3 lines

Please use an explicitly 64-bit type - AFAICS you're holding the sum of some 64-bit length fields.

Ok but ssize_t is kind of a funny one. It should accept everything that size_t can accept + negative values.

Given that you start with user-supplied 64-bit iov lengths, there is no such type. :)

And now that I look at it, your handling of sizes is pretty confused. v4v_ringbuf_insertv() returns a ssize_t, but calculates it internally as an int32_t, which is _smaller_ than the size_t it starts with (which is the sum of some guest-supplied uint64_ts). And then v4v_sendv() puts that ssize_t into an int again before returning it as a size_t, which d_v4v_op() casts as a long to give to the guest. Whee!

Quoted 9 lines

Can you please make that lot consistent, and then audit the whole path from user-supplied iovec lists to actual copies and make sure that there are no overflows?

I think that explicitly limiting your sum-of-iovec-lengths to 31 bits would be perfectly reasonable (1 hypercall per 2GB copy), and would avoid a lot of pain here. As long as it was documented in the interface, of course!

Ok fine that works for me. I'll do that for the next version.

Jean

#8 lore raw

Re: [PATCH 1/5] xen: add ssize_t

In reply to Jean Guyader
Quoted 33 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 16 lines · Tim Deegan
Quoted 11 lines · Jean Guyader
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jean Guyader

Without finally explaining why you need this type in the first place, I'll continue to NAK this patch. (This is made even worse by the fact taht the two inline functions in patch 5 that make use of the type appear to be unused.)

Understood. I'll switch to use long instead of ssize_t in my forthcoming patch serie.

Please use an explicitly 64-bit type - AFAICS you're holding the sum of some 64-bit length fields.

Quoted 7 lines
Quoted 2 lines

Ok but ssize_t is kind of a funny one. It should accept everything that size_t can accept + negative values.

No. It's the same relation as between e.g. "signed int" and "unsigned int". Value preserving conversions are only guaranteed for non-negative values fitting both types.

ssize_t is a *signed* type, I was wrong by saying that it should accept all the range of a size_t, it allows only
a subset of it. read/write used ssize_t as a return type.

Quoted 6 lines

From man 2 read:
If count is zero, read() returns zero and has no other results. If count is greater than SSIZE_MAX, the result is unspecified.

Would it be ok to claim the same thing here? i.e. if count > INT_MAX the result is unspecified.

Sure, except that I think you wanted to use long and hence LONG_MAX.

Jan

#26 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

In reply to Jean Guyader
Quoted 39 lines · Jean Guyader
Quoted 38 lines · Tim Deegan
Quoted 21 lines · Ian Campbell
Quoted 7 lines · Tim Deegan
Quoted 5 lines · Jean Guyader

Exposes evtchn_alloc_unbound_domain to the rest of Xen so we can create allocated unbound evtchn within Xen.

Quoted 12 lines

Review static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 168

Quoted 9 lines
(quoted diff) +2 -2
@@ -161,18 +163,18 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 {
     struct evtchn *chn;
     struct domain *d;
-    int            port;
+    evtchn_port_t  port;
     domid_t        dom = alloc->dom;
-    long           rc;
+    int            rc;

The function returns long; if you're tidying this up to be an int, might as well change the return type too.

Quoted 8 lines

I'm not sure if this is relevant but Jan just sent a patch to "make all (native) hypercalls consistently have "long" return type". I think/suspect this rc here turns into the result of the hypercall?

Jan's patch was motivated by something to do with sign extension when a hypercall's int return is written to the long in the multicall arg struct which causes strangeness. Perhaps not totally relevant to evtchn_alloc which is unlikely to be in a MC.

Yes, this eventually ends up in a hypercall handler, but s/long/int/ here doesn't cause problems because
- rc is only ever set to an 'int' value here so we can't lose data from the type being too narrow; and
- Those int values get cast up to long (either in here or in the caller) directly, which will sign-extend the.

Quoted 9 lines
Quoted 3 lines

It really doesn't matter whether this function returns an int or a long, but it's a bit untidy to change it half-way.

The main reason why I changed it only base ERROR_EXIT_DOM expects an int based on the format string. I guess I could cast the long in int for the call to ERROR_EXIT_DOM
but that doesn't really look nice either.

Hi,

Here is a new version that should address the comments from Tim and Jan.

Jean

commit c43dbcee9c4e9d65520f9a562b39e8e6455efc36

Author: Jean Guyader <[email protected]>
Date:   Thu Aug 2 16:19:23 2012 +0100

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 +31 -11
index 53777f8..880395e 100644
@@ -159,9 +159,8 @@ 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;
+    evtchn_port_t  port;
     domid_t        dom = alloc->dom;
     long           rc;
 
@@ -169,26 +168,47 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     if ( rc )
         return rc;
 
+    rc = evtchn_alloc_unbound_domain(d, &port,
+            alloc->remote_dom == DOMID_SELF ? current->domain->domain_id
+                                            : alloc->remote_dom);
+    if ( rc )
+        ERROR_EXIT_DOM((int)rc, d);
+
+    alloc->port = port;
+
+ 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 )
-        chn->u.unbound.remote_domid = current->domain->domain_id;
+    chn->u.unbound.remote_domid = remote_domid;
 
-    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

#27 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

Quoted 15 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/common/event_channel.c +1 -2
@@ -159,9 +159,8 @@ 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;
+    evtchn_port_t  port;
    domid_t        dom = alloc->dom;
    long           rc;
 

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 171

Quoted 4 lines
xen/common/event_channel.c +1 -0
@@ -169,26 +168,47 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
    if ( rc )
        return rc;
 
+    rc = evtchn_alloc_unbound_domain(d, &port,

Any reason you can't pass &alloc->port here directly?

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 173

Quoted 2 lines
xen/common/event_channel.c +2 -0
+            alloc->remote_dom == DOMID_SELF ? current->domain->domain_id
+                                            : alloc->remote_dom);

Any reason this can't/shouldn't be done in the called function?

Jan

#28 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/common/event_channel.c +1 -2
@@ -159,9 +159,8 @@ 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;
+    evtchn_port_t  port;
    domid_t        dom = alloc->dom;
    long           rc;
 
@@ -169,26 +168,47 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
    if ( rc )
        return rc;
 
Quoted 9 lines

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 171

Quoted 1 line
xen/common/event_channel.c +1 -0
+    rc = evtchn_alloc_unbound_domain(d, &port,

Any reason you can't pass &alloc->port here directly?

xen/common/event_channel.c static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) · line 173

Quoted 2 lines
xen/common/event_channel.c +2 -0
+            alloc->remote_dom == DOMID_SELF ? current->domain->domain_id
+                                            : alloc->remote_dom);

Any reason this can't/shouldn't be done in the called function?

No specific reason for both of those thing. Here is a new version based on your comments.

Thanks for reviewing,
Jean

commit 208384d74852df9ae26294236d79e33967a75afa

Author: Jean Guyader <[email protected]>
Date:   Thu Aug 2 16:19:23 2012 +0100

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 +29 -12
index 53777f8..fd626bf 100644
@@ -159,36 +159,53 @@ 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;
+    chn->u.unbound.remote_domid = remote_domid;
+
+    *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

Reviewed-by
#29 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

No specific reason for both of those thing. Here is a new version based on your comments.

#45 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

In reply to Tim Deegan
Quoted 6 lines · Tim Deegan

Hi,

This looks pretty good; I think you've addressed almost all my comments except for one, which is really a design decision raether than an implementation one. As I said last time:

Quoted 10 lines

] And what about protocol? Protocol seems to have ended up as a bit of a ] second-class citizen in v4v; it's defined, and indeed required, but not ] used for routing or for acccess control, so all traffic to a given port ] _on every protocol_ ends up on the same ring.
]
] This is the inverse of the TCP/IP namespace that you're copying, where ] protocol demux happens before port demux. And I think it will bite ] someone if you ever, for example, want to send ICMP or GRE over a v4v ] channel.

The protocol field is used to inform about the type a message on the ring.

Right now we use two protocols in our linux driver: V4V_PROTO_DGRAM and V4V_PROTO_STREAM. In the future that could probably be extended to new protocol like V4V_PROTO_ICMP for instance.

The demultiplexing will happens at the other end, the driver can look at the message and decide what to do with it based on the protocol field.

Jean

#46 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

Quoted 18 lines · Jean Guyader
Quoted 6 lines · Tim Deegan

Hi,

This looks pretty good; I think you've addressed almost all my comments except for one, which is really a design decision raether than an implementation one. As I said last time:

Quoted 10 lines

] And what about protocol? Protocol seems to have ended up as a bit of a ] second-class citizen in v4v; it's defined, and indeed required, but not ] used for routing or for acccess control, so all traffic to a given port ] _on every protocol_ ends up on the same ring.
]
] This is the inverse of the TCP/IP namespace that you're copying, where ] protocol demux happens before port demux. And I think it will bite ] someone if you ever, for example, want to send ICMP or GRE over a v4v ] channel.

Quoted 8 lines

The protocol field is used to inform about the type a message on the ring.

Right now we use two protocols in our linux driver: V4V_PROTO_DGRAM and V4V_PROTO_STREAM. In the future that could probably be extended to new protocol like V4V_PROTO_ICMP for instance.

The demultiplexing will happens at the other end, the driver can look at the message and decide what to do with it based on the protocol field.

Yes, I understand all that - what I'm saying is that it seems like a design flaw to me. The namespace in V4V, as proposed, looks like this:

Protocol
Port
Domain

and it would be more sensible to do (like the IP stack):

Port
Protocol
Domain.

Or at the very least the protocol should be made part of the endpoint address, and not just part of the packet header. As it stands:

- The handlers for port X in _all_ protocols _have_ to share a ring. That seems kind of plausible because the IANA port assignments never give the same port number to different services on TCP and UDP, but will it make sense for every new protocol? Is it sensible to require, say, an L2TP service to make its connection IDs not clash with V4V_PROTO_DGRAM and V4V_PROTO_STREAM users?

It may not even make sense in existing protocols. It's common enough for DNS servers to use different ACLs (and indeed different servers) for TCP and UDP.

- Relatedly, every protocol _has_ to have port numbers. How would you register an ICMP listener, for example? You'd have to do something gross like declare a particular port to be the ICMP port so that you could demux it, or indeed send it in the first place.

You say:

Quoted 2 lines

The demultiplexing will happens at the other end, the driver can look at the message and decide what to do with it based on the protocol field.

I'm willing to accept that argument, but only if we extend it to ports too, get rid of all the namespace and ACL code in Xen and leave each domain with a single RX ring that the (single) guest driver must demux. :P

Cheers,

Tim.

#47 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

Quoted 28 lines · Tim Deegan
Quoted 18 lines · Jean Guyader
Quoted 6 lines · Tim Deegan

Hi,

This looks pretty good; I think you've addressed almost all my comments except for one, which is really a design decision raether than an implementation one. As I said last time:

Quoted 10 lines

] And what about protocol? Protocol seems to have ended up as a bit of a ] second-class citizen in v4v; it's defined, and indeed required, but not ] used for routing or for acccess control, so all traffic to a given port ] _on every protocol_ ends up on the same ring.
]
] This is the inverse of the TCP/IP namespace that you're copying, where ] protocol demux happens before port demux. And I think it will bite ] someone if you ever, for example, want to send ICMP or GRE over a v4v ] channel.

Quoted 8 lines

The protocol field is used to inform about the type a message on the ring.

Right now we use two protocols in our linux driver: V4V_PROTO_DGRAM and V4V_PROTO_STREAM. In the future that could probably be extended to new protocol like V4V_PROTO_ICMP for instance.

The demultiplexing will happens at the other end, the driver can look at the message and decide what to do with it based on the protocol field.

Quoted 7 lines

Yes, I understand all that - what I'm saying is that it seems like a design flaw to me. The namespace in V4V, as proposed, looks like this:

Protocol
Port
Domain

Protocol isn't part of the namespace - I think that's where the confusion arises. The namespace is exclusively Port/Domain. Protocol is there to describe the content of _a particular message_ in the ring. It is included in the hypercalls (rather than, say, being the first n bytes of all messages) to force all senders to use it.

The other key point here is confusion as to what V4V is. V4V is _not_ a tcp or udp clone. V4V exists to provide a mechanism to transfer messages (which are arbitary strings of bytes, labeled with a "protocol") between endpoitns (labeled by a domain and port).

An example use of this facility uses two v4v rings to implement something which looks quite like TCP. In this case to distinguish TCP-a-like messages from other such messages that may or may not be present on the ring, the messages are labeled with a protocol field that indicates what upper layer should handle these messages.

One can easily immagine circumstances where messages of many different protocols are present on the ring. An obvious example might be a message type which implemented some sort of flow control, that quenced or started transmission on a partner ring, regardless of what other messages were being sent on the rings.

Quoted 16 lines

and it would be more sensible to do (like the IP stack):

Port
Protocol
Domain.

Or at the very least the protocol should be made part of the endpoint address, and not just part of the packet header. As it stands:

- The handlers for port X in _all_ protocols _have_ to share a ring. That seems kind of plausible because the IANA port assignments never give the same port number to different services on TCP and UDP, but will it make sense for every new protocol? Is it sensible to require, say, an L2TP service to make its connection IDs not clash with V4V_PROTO_DGRAM and V4V_PROTO_STREAM users?

Quoted 4 lines

It may not even make sense in existing protocols. It's common enough for DNS servers to use different ACLs (and indeed different servers) for TCP and UDP.

V4V isn't IP, but you raise a valid point. We should define two ranges of 16 bit V4V port numbers one which is "well known" for the use of TCP encapsulation, and one which is "well known" for the use of UDP encapsulation. That then makes the concept that you think that protocol should be, be part of the endpoint address, and it leaves the thing I misleadingly called "protocol" free to be the message type label.

Quoted 5 lines

- Relatedly, every protocol _has_ to have port numbers. How would you register an ICMP listener, for example? You'd have to do something gross like declare a particular port to be the ICMP port so that you could demux it, or indeed send it in the first place.

Quoted 9 lines

You say:

Quoted 2 lines

The demultiplexing will happens at the other end, the driver can look at the message and decide what to do with it based on the protocol field.

I'm willing to accept that argument, but only if we extend it to ports too, get rid of all the namespace and ACL code in Xen and leave each domain with a single RX ring that the (single) guest driver must demux. :P

Cheers,
Jean

#48 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

Quoted 4 lines · Jean Guyader

Protocol isn't part of the namespace - I think that's where the confusion arises. The namespace is exclusively Port/Domain. Protocol is there to describe the content of _a particular message_ in the ring.

OK.

In that case, I think the hypervisor shouldn't handle it at all. That can be done in the client drivers, and the V4V_PROTO definitions and maybe packet format stuff can go in documentation.

Quoted 2 lines

It is included in the hypercalls (rather than, say, being the first n bytes of all messages) to force all senders to use it.

I don't think that's very useful. It just forces any V4V user who doesn't need multiple protocols to make up a number for form's sake, and since Xen doesn't do any checking on the field, it doesn't protect the receiver from anything.

I guess what I'm saying is, either 'protocol' (or whatever name you give it) is part of the v4v addressing, in which case it should be treated properly and demuxed before port, or it's not, in which case it needn't be in the interface at all.

Cheers,

Tim.

#33 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

In reply to Jan Beulich
Quoted 92 lines · Jan Beulich

xen/include/public/v4v.h line 34

Quoted 5 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/include/public/v4v.h new file +1 -0
...
+#define V4V_DOMID_ANY           0x7fffU

I think I asked this before - why not use one of the pre-existing DOMID values? And if there is a good reason, it should be said here in a comment, to avoid the same question being asked later again.

Quoted 2 lines

...
+typedef uint64_t v4v_pfn_t;

We already have xen_pfn_t, so why do you need yet another flavor?

xen/include/public/v4v.h line 115

Quoted 6 lines

...

xen/include/public/v4v.h new file +5 -0
+struct v4v_info
+{
+    uint64_t ring_magic;
+    uint64_t data_magic;
+    evtchn_port_t evtchn;

Missing padding at the end?

xen/include/public/v4v.h line 119

Quoted 4 lines
xen/include/public/v4v.h new file +4 -0
+};
+typedef struct v4v_info v4v_info_t;
+
+#define V4V_ROUNDUP(a) (((a) +0xf ) & ~0xf)

Doesn't seem to belong here. Or is the subsequent comment actually related to this (in which case it should be moved ahead of the definition and made match it).

xen/include/public/v4v.h line 167

Quoted 11 lines
xen/include/public/v4v.h new file +9 -0
+/*
+ * Messages on the ring are padded to 128 bits
+ * Len here refers to the exact length of the data not including the
+ * 128 bit header. The message uses
+ * ((len +0xf) & ~0xf) + sizeof(v4v_ring_message_header) bytes
+ */
...
+/*
+ * HYPERCALLS
+ */
...

In the block below here, please get the naming (do_v4v_op() vs v4v_hypercall()) and the use of newlines (either always one or always two between individual hypercall descriptions) consistent. Hmm, even the descriptions don't seem to always match the definitions (not really obvious because apparently again the descriptions follow the definitions, whereas the opposite is the usual way to arrange things).

Quoted 5 lines
xen/include/xen/v4v_utils.h new file +2 -0
...
+/* Compiler specific hacks */
+#if defined(__GNUC__)

xen/include/xen/v4v_utils.h line 32

Quoted 10 lines
xen/include/xen/v4v_utils.h new file +10 -0
+# define V4V_UNUSED __attribute__ ((unused))
+# ifndef __STRICT_ANSI__
+#  define V4V_INLINE inline
+# else
+#  define V4V_INLINE
+# endif
+#else /* !__GNUC__ */
+# define V4V_UNUSED
+# define V4V_INLINE
+#endif

This suggests the header is really intended to be public?

xen/include/xen/v4v_utils.h line 40

Quoted 3 lines

...

xen/include/xen/v4v_utils.h new file +2 -0
+static V4V_INLINE uint32_t
+v4v_ring_bytes_to_read (volatile struct v4v_ring *r)

No space between function name and opening parenthesis (throughout this file).

Quoted 2 lines

...
+V4V_UNUSED static V4V_INLINE ssize_t

V4V_UNUSED? Doesn't make sense in conjunction with V4V_INLINE, at least as long as you're using GNU extensions anyway (see above as to the disposition of the header).

xen/include/xen/v4v_utils.h line 57

Quoted 2 lines
xen/include/xen/v4v_utils.h new file +2 -0
+v4v_copy_out (struct v4v_ring *r, struct v4v_addr *from, uint32_t * protocol,
+              void *_buf, size_t t, int consume)

Dead functions shouldn't be placed here.

Quoted 15 lines

xen/include/xen/v4v_utils.h line 186

Quoted 11 lines

...

xen/include/xen/v4v_utils.h new file +10 -0
+static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip) V4V_UNUSED;
+
+V4V_INLINE static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip)
+{

What's the point of having a declaration followed immediately by a definition? Also, the function is dead too.

This file (v4v_utils.h) has utility that could be used by drivers, we don't use them in Xen but we through it will be convenient to have such function accessible for one to write a v4v driver a v4v driver.

What would be the right place for those?

Thanks,
Jean

#30 lore raw

Re: [PATCH 4/5] xen: events, exposes evtchn_alloc_unbound_domain

In reply to Jan Beulich
Quoted 6 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Jean Guyader

No specific reason for both of those thing. Here is a new version based on your comments.

I have found a copy/paste bug in this patch.

This statement was executed unconditionally, not just inside the if statement. chn->u.unbound.remote_domid = remote_domid;

Attached the fixed version.

Jean

commit 8a33fc898726717879f59f5b911125b87598e78a

Author: Jean Guyader <[email protected]>
Date:   Thu Aug 2 16:19:23 2012 +0100

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 +27 -12
index 53777f8..6a0e342 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

#34 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

In reply to Jean Guyader
Quoted 111 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 80 lines · Jan Beulich

xen/include/public/v4v.h line 34

Quoted 5 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/include/public/v4v.h new file +1 -0
...
+#define V4V_DOMID_ANY           0x7fffU

I think I asked this before - why not use one of the pre-existing DOMID values? And if there is a good reason, it should be said here in a comment, to avoid the same question being asked later again.

Quoted 2 lines

...
+typedef uint64_t v4v_pfn_t;

We already have xen_pfn_t, so why do you need yet another flavor?

xen/include/public/v4v.h line 115

Quoted 6 lines

...

xen/include/public/v4v.h new file +5 -0
+struct v4v_info
+{
+    uint64_t ring_magic;
+    uint64_t data_magic;
+    evtchn_port_t evtchn;

Missing padding at the end?

xen/include/public/v4v.h line 119

Quoted 4 lines
xen/include/public/v4v.h new file +4 -0
+};
+typedef struct v4v_info v4v_info_t;
+
+#define V4V_ROUNDUP(a) (((a) +0xf ) & ~0xf)

Doesn't seem to belong here. Or is the subsequent comment actually related to this (in which case it should be moved ahead of the definition and made match it).

xen/include/public/v4v.h line 167

Quoted 11 lines
xen/include/public/v4v.h new file +9 -0
+/*
+ * Messages on the ring are padded to 128 bits
+ * Len here refers to the exact length of the data not including the
+ * 128 bit header. The message uses
+ * ((len +0xf) & ~0xf) + sizeof(v4v_ring_message_header) bytes
+ */
...
+/*
+ * HYPERCALLS
+ */
...

In the block below here, please get the naming (do_v4v_op() vs v4v_hypercall()) and the use of newlines (either always one or always two between individual hypercall descriptions) consistent. Hmm, even the descriptions don't seem to always match the definitions (not really obvious because apparently again the descriptions follow the definitions, whereas the opposite is the usual way to arrange things).

Quoted 5 lines
xen/include/xen/v4v_utils.h new file +2 -0
...
+/* Compiler specific hacks */
+#if defined(__GNUC__)

xen/include/xen/v4v_utils.h line 32

Quoted 10 lines
xen/include/xen/v4v_utils.h new file +10 -0
+# define V4V_UNUSED __attribute__ ((unused))
+# ifndef __STRICT_ANSI__
+#  define V4V_INLINE inline
+# else
+#  define V4V_INLINE
+# endif
+#else /* !__GNUC__ */
+# define V4V_UNUSED
+# define V4V_INLINE
+#endif

This suggests the header is really intended to be public?

xen/include/xen/v4v_utils.h line 40

Quoted 3 lines

...

xen/include/xen/v4v_utils.h new file +2 -0
+static V4V_INLINE uint32_t
+v4v_ring_bytes_to_read (volatile struct v4v_ring *r)

No space between function name and opening parenthesis (throughout this file).

Quoted 8 lines
Quoted 2 lines

...
+V4V_UNUSED static V4V_INLINE ssize_t

V4V_UNUSED? Doesn't make sense in conjunction with V4V_INLINE, at least as long as you're using GNU extensions anyway (see above as to the disposition of the header).

Quoted 1 line

+v4v_copy_out (struct v4v_ring *r, struct v4v_addr *from, uint32_t *

protocol,

Quoted 4 lines
Quoted 1 line

+ void *_buf, size_t t, int consume)

Dead functions shouldn't be placed here.

Quoted 15 lines

xen/include/xen/v4v_utils.h line 186

Quoted 11 lines

...

xen/include/xen/v4v_utils.h new file +10 -0
+static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip) V4V_UNUSED;
+
+V4V_INLINE static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip)
+{

What's the point of having a declaration followed immediately by a definition? Also, the function is dead too.

Quoted 6 lines

This file (v4v_utils.h) has utility that could be used by drivers, we don't use
them in Xen but we through it will be convenient to have such function accessible for one to write a v4v driver a v4v driver.

What would be the right place for those?

I think public/io/ would be the best matching place, but it's certainly also not ideal. Maybe we ought to introduce public/lib/ or some such for it?

But then again I don't see how this comment of yours relates to the earlier comments I made.

Jan

#36 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

In reply to Jan Beulich
Quoted 11 lines · Jan Beulich

xen/include/public/v4v.h line 34

Quoted 5 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/include/public/v4v.h new file +1 -0
...
+#define V4V_DOMID_ANY           0x7fffU

I think I asked this before - why not use one of the pre-existing DOMID values? And if there is a good reason, it should be said here in a comment, to avoid the same question being asked later again.

I replaced 0x7fffU with DOMID_INVALID.

Quoted 6 lines
Quoted 2 lines

...
+typedef uint64_t v4v_pfn_t;

We already have xen_pfn_t, so why do you need yet another flavor?

No, replaced with xen_pfn_t.

Quoted 9 lines

xen/include/public/v4v.h line 115

Quoted 6 lines

...

xen/include/public/v4v.h new file +5 -0
+struct v4v_info
+{
+    uint64_t ring_magic;
+    uint64_t data_magic;
+    evtchn_port_t evtchn;

Missing padding at the end?

ack.

Quoted 9 lines

xen/include/public/v4v.h line 119

Quoted 4 lines
xen/include/public/v4v.h new file +4 -0
+};
+typedef struct v4v_info v4v_info_t;
+
+#define V4V_ROUNDUP(a) (((a) +0xf ) & ~0xf)

Doesn't seem to belong here. Or is the subsequent comment actually related to this (in which case it should be moved ahead of the definition and made match it).

V4V_ROUNDUP is now in v4v.c and I move the description above the define.

Thanks for the review,
Jean

Quoted 72 lines

xen/include/public/v4v.h line 167

Quoted 11 lines
xen/include/public/v4v.h new file +9 -0
+/*
+ * Messages on the ring are padded to 128 bits
+ * Len here refers to the exact length of the data not including the
+ * 128 bit header. The message uses
+ * ((len +0xf) & ~0xf) + sizeof(v4v_ring_message_header) bytes
+ */
...
+/*
+ * HYPERCALLS
+ */
...

In the block below here, please get the naming (do_v4v_op() vs v4v_hypercall()) and the use of newlines (either always one or always two between individual hypercall descriptions) consistent. Hmm, even the descriptions don't seem to always match the definitions (not really obvious because apparently again the descriptions follow the definitions, whereas the opposite is the usual way to arrange things).

Quoted 5 lines
xen/include/xen/v4v_utils.h new file +2 -0
...
+/* Compiler specific hacks */
+#if defined(__GNUC__)

xen/include/xen/v4v_utils.h line 32

Quoted 10 lines
xen/include/xen/v4v_utils.h new file +10 -0
+# define V4V_UNUSED __attribute__ ((unused))
+# ifndef __STRICT_ANSI__
+#  define V4V_INLINE inline
+# else
+#  define V4V_INLINE
+# endif
+#else /* !__GNUC__ */
+# define V4V_UNUSED
+# define V4V_INLINE
+#endif

This suggests the header is really intended to be public?

xen/include/xen/v4v_utils.h line 40

Quoted 3 lines

...

xen/include/xen/v4v_utils.h new file +2 -0
+static V4V_INLINE uint32_t
+v4v_ring_bytes_to_read (volatile struct v4v_ring *r)

No space between function name and opening parenthesis (throughout this file).

Quoted 2 lines

...
+V4V_UNUSED static V4V_INLINE ssize_t

V4V_UNUSED? Doesn't make sense in conjunction with V4V_INLINE, at least as long as you're using GNU extensions anyway (see above as to the disposition of the header).

xen/include/xen/v4v_utils.h line 57

Quoted 2 lines
xen/include/xen/v4v_utils.h new file +2 -0
+v4v_copy_out (struct v4v_ring *r, struct v4v_addr *from, uint32_t * protocol,
+              void *_buf, size_t t, int consume)

Dead functions shouldn't be placed here.

xen/include/xen/v4v_utils.h line 186

Quoted 11 lines

...

xen/include/xen/v4v_utils.h new file +10 -0
+static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip) V4V_UNUSED;
+
+V4V_INLINE static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip)
+{

What's the point of having a declaration followed immediately by a definition? Also, the function is dead too.

#35 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation

In reply to Jan Beulich
Quoted 116 lines · Jan Beulich
Quoted 116 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 80 lines · Jan Beulich

xen/include/public/v4v.h line 34

Quoted 5 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
xen/include/public/v4v.h new file +1 -0
...
+#define V4V_DOMID_ANY           0x7fffU

I think I asked this before - why not use one of the pre-existing DOMID values? And if there is a good reason, it should be said here in a comment, to avoid the same question being asked later again.

Quoted 2 lines

...
+typedef uint64_t v4v_pfn_t;

We already have xen_pfn_t, so why do you need yet another flavor?

xen/include/public/v4v.h line 115

Quoted 6 lines

...

xen/include/public/v4v.h new file +5 -0
+struct v4v_info
+{
+    uint64_t ring_magic;
+    uint64_t data_magic;
+    evtchn_port_t evtchn;

Missing padding at the end?

xen/include/public/v4v.h line 119

Quoted 4 lines
xen/include/public/v4v.h new file +4 -0
+};
+typedef struct v4v_info v4v_info_t;
+
+#define V4V_ROUNDUP(a) (((a) +0xf ) & ~0xf)

Doesn't seem to belong here. Or is the subsequent comment actually related to this (in which case it should be moved ahead of the definition and made match it).

xen/include/public/v4v.h line 167

Quoted 11 lines
xen/include/public/v4v.h new file +9 -0
+/*
+ * Messages on the ring are padded to 128 bits
+ * Len here refers to the exact length of the data not including the
+ * 128 bit header. The message uses
+ * ((len +0xf) & ~0xf) + sizeof(v4v_ring_message_header) bytes
+ */
...
+/*
+ * HYPERCALLS
+ */
...

In the block below here, please get the naming (do_v4v_op() vs v4v_hypercall()) and the use of newlines (either always one or always two between individual hypercall descriptions) consistent. Hmm, even the descriptions don't seem to always match the definitions (not really obvious because apparently again the descriptions follow the definitions, whereas the opposite is the usual way to arrange things).

Quoted 5 lines
xen/include/xen/v4v_utils.h new file +2 -0
...
+/* Compiler specific hacks */
+#if defined(__GNUC__)

xen/include/xen/v4v_utils.h line 32

Quoted 10 lines
xen/include/xen/v4v_utils.h new file +10 -0
+# define V4V_UNUSED __attribute__ ((unused))
+# ifndef __STRICT_ANSI__
+#  define V4V_INLINE inline
+# else
+#  define V4V_INLINE
+# endif
+#else /* !__GNUC__ */
+# define V4V_UNUSED
+# define V4V_INLINE
+#endif

This suggests the header is really intended to be public?

xen/include/xen/v4v_utils.h line 40

Quoted 3 lines

...

xen/include/xen/v4v_utils.h new file +2 -0
+static V4V_INLINE uint32_t
+v4v_ring_bytes_to_read (volatile struct v4v_ring *r)

No space between function name and opening parenthesis (throughout this file).

Quoted 8 lines
Quoted 2 lines

...
+V4V_UNUSED static V4V_INLINE ssize_t

V4V_UNUSED? Doesn't make sense in conjunction with V4V_INLINE, at least as long as you're using GNU extensions anyway (see above as to the disposition of the header).

Quoted 1 line

+v4v_copy_out (struct v4v_ring *r, struct v4v_addr *from, uint32_t *

protocol,

Quoted 4 lines
Quoted 1 line

+ void *_buf, size_t t, int consume)

Dead functions shouldn't be placed here.

Quoted 15 lines

xen/include/xen/v4v_utils.h line 186

Quoted 11 lines

...

xen/include/xen/v4v_utils.h new file +10 -0
+static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip) V4V_UNUSED;
+
+V4V_INLINE static ssize_t
+v4v_copy_out_offset (struct v4v_ring *r, struct v4v_addr *from,
+                     uint32_t * protocol, void *_buf, size_t t, int consume,
+                     size_t skip)
+{

What's the point of having a declaration followed immediately by a definition? Also, the function is dead too.

This file (v4v_utils.h) has utility that could be used by drivers, we don't use
them in Xen but we through it will be convenient to have such function accessible for one to write a v4v driver a v4v driver.

Quoted 9 lines
Quoted 1 line

What would be the right place for those?

I think public/io/ would be the best matching place, but it's certainly also not ideal. Maybe we ought to introduce public/lib/ or some such for it?

But then again I don't see how this comment of yours relates to the earlier comments I made.

Ok I have removed this file from the patch series, we already have a copy of this file in the Linux driver so those helper functions can be found there.

Thanks,
Jean

#37 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation - padding question

In reply to Jean Guyader
Quoted 11 lines
Quoted 10 lines

xen/include/public/v4v.h line 115

Quoted 7 lines

...

xen/include/public/v4v.h new file +5 -0
+struct v4v_info
+{
+    uint64_t ring_magic;
+    uint64_t data_magic;
+    evtchn_port_t evtchn;

Missing padding at the end?

Quoted 2 lines

ack.

At one point during the review of an earlier version of the V4V patch set, Jan requested that this pad be added to the v4v_info struct. I understand the padding in all the other structs but I don't understand this one. This struct is not included in any other structs and is not followed by any data.

Thanks
Ross

#38 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation - padding question

Quoted 11 lines · Ross Philipson
Quoted 11 lines
Quoted 10 lines

xen/include/public/v4v.h line 115

Quoted 7 lines

...

xen/include/public/v4v.h new file +5 -0
+struct v4v_info
+{
+    uint64_t ring_magic;
+    uint64_t data_magic;
+    evtchn_port_t evtchn;

Missing padding at the end?

Quoted 8 lines
Quoted 2 lines

ack.

At one point during the review of an earlier version of the V4V patch set, Jan requested that this pad be added to the v4v_info struct. I understand the padding in all the other structs but I don't understand this one. This struct is not included in any other structs and is not followed by any data.

64-bit Xen would see this as a 24-byte struct, even without explicit padding. That would surprise a 32-bit guest that allocated what it saw as a 20-byte struct for Xen to copy into.

Tim.

#39 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation - padding question

Quoted 21 lines · Tim Deegan
Quoted 11 lines · Ross Philipson
Quoted 11 lines
Quoted 10 lines

xen/include/public/v4v.h line 115

Quoted 7 lines

...

xen/include/public/v4v.h new file +5 -0
+struct v4v_info
+{
+    uint64_t ring_magic;
+    uint64_t data_magic;
+    evtchn_port_t evtchn;

Missing padding at the end?

Quoted 8 lines
Quoted 2 lines

ack.

At one point during the review of an earlier version of the V4V patch set, Jan requested that this pad be added to the v4v_info struct. I understand the padding in all the other structs but I don't understand this one. This struct is not included in any other structs and is not followed by any data.

Quoted 3 lines

64-bit Xen would see this as a 24-byte struct, even without explicit padding. That would surprise a 32-bit guest that allocated what it saw as a 20-byte struct for Xen to copy into.

Ah yes, of course. Thanks for the quick response.

Ross

Quoted 2 lines

Tim.

#40 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation - padding question

Quoted 22 lines · Ross Philipson
Quoted 21 lines · Tim Deegan
Quoted 19 lines · Ross Philipson
Quoted 11 lines
Quoted 10 lines

xen/include/public/v4v.h line 115

Quoted 7 lines

...

xen/include/public/v4v.h new file +5 -0
+struct v4v_info
+{
+ uint64_t ring_magic;
+ uint64_t data_magic;
+ evtchn_port_t evtchn;

Missing padding at the end?

Quoted 2 lines

ack.

At one point during the review of an earlier version of the V4V patch set, Jan requested that this pad be added to the v4v_info struct. I understand the padding in all the other structs but I don't understand this one. This struct is not included in any other structs and is not followed by any data.

Quoted 7 lines
Quoted 3 lines

64-bit Xen would see this as a 24-byte struct, even without explicit padding. That would surprise a 32-bit guest that allocated what it saw as a 20-byte struct for Xen to copy into.

Ah yes, of course. Thanks for the quick response.

Ross

I guess that means that this struct is unhappy then...

typedef struct v4vtables_rule

{
    v4v_addr_t src;  -- 8b
    v4v_addr_t dst;  -- 8b
    uint32_t accept; -- 4b
} v4vtables_rule_t;
Quoted 9 lines
Quoted 3 lines

Tim.

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

#41 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation - padding question

Quoted 31 lines · Ross Philipson
Quoted 22 lines · Ross Philipson
Quoted 21 lines · Tim Deegan
Quoted 19 lines · Ross Philipson
Quoted 11 lines
Quoted 10 lines

Review

Quoted 7 lines

...

(quoted diff) +5 -0
+struct v4v_info
+{
+ uint64_t ring_magic;
+ uint64_t data_magic;
+ evtchn_port_t evtchn;

Missing padding at the end?

Quoted 2 lines

ack.

At one point during the review of an earlier version of the V4V patch set, Jan requested that this pad be added to the v4v_info struct. I understand the padding in all the other structs but I don't understand this one. This struct is not included in any other structs and is not followed by any data.

Quoted 7 lines
Quoted 3 lines

64-bit Xen would see this as a 24-byte struct, even without explicit padding. That would surprise a 32-bit guest that allocated what it saw as a 20-byte struct for Xen to copy into.

Ah yes, of course. Thanks for the quick response.

Ross

Quoted 8 lines

I guess that means that this struct is unhappy then...

typedef struct v4vtables_rule

{
    v4v_addr_t src;  -- 8b
    v4v_addr_t dst;  -- 8b
    uint32_t accept; -- 4b
} v4vtables_rule_t;

Surprisingly, no: since it contains no 8-byte fields, both x86 architectures will see it as a 20-byte (4-byte-aligned) struct. Not sure about ARM, though.

Tim.

#42 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation - padding question

Quoted 11 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 8 lines · Ross Philipson

I guess that means that this struct is unhappy then...

typedef struct v4vtables_rule

{
    v4v_addr_t src;  -- 8b
    v4v_addr_t dst;  -- 8b
    uint32_t accept; -- 4b
} v4vtables_rule_t;
Quoted 3 lines

Surprisingly, no: since it contains no 8-byte fields, both x86 architectures will see it as a 20-byte (4-byte-aligned) struct. Not sure about ARM, though.

That's why all such structures should go through the public header compat mode checking, so that eventual inconsistencies would be noticed right away rather than at the end of some extended debugging session.

Jan

#43 lore raw

Re: [PATCH 5/5] xen: Add V4V implementation - padding question

In reply to Tim Deegan
Quoted 41 lines · Tim Deegan
Quoted 31 lines · Ross Philipson
Quoted 22 lines · Ross Philipson
Quoted 21 lines · Tim Deegan
Quoted 19 lines · Ross Philipson
Quoted 11 lines
Quoted 10 lines

Review

Quoted 7 lines

...

(quoted diff) +5 -0
+struct v4v_info
+{
+ uint64_t ring_magic;
+ uint64_t data_magic;
+ evtchn_port_t evtchn;

Missing padding at the end?

Quoted 2 lines

ack.

At one point during the review of an earlier version of the V4V patch set, Jan requested that this pad be added to the v4v_info struct. I understand the padding in all the other structs but I don't understand this one. This struct is not included in any other structs and is not followed by any data.

Quoted 7 lines
Quoted 3 lines

64-bit Xen would see this as a 24-byte struct, even without explicit padding. That would surprise a 32-bit guest that allocated what it saw as a 20-byte struct for Xen to copy into.

Ah yes, of course. Thanks for the quick response.

Ross

Quoted 8 lines

I guess that means that this struct is unhappy then...

typedef struct v4vtables_rule

{
    v4v_addr_t src;  -- 8b
    v4v_addr_t dst;  -- 8b
    uint32_t accept; -- 4b
} v4vtables_rule_t;
Quoted 3 lines

Surprisingly, no: since it contains no 8-byte fields, both x86 architectures will see it as a 20-byte (4-byte-aligned) struct. Not sure about ARM, though.

same on ARM and ARM64