Skip to contentSkip to conversation

Rangeset generalisation

RFC In review Andrii Anisov 4 participants 26 messages Feb 16, 2017

lore
Share & tools
lore
#0 lore raw

cover Rangeset generalisation

From: Andrii Anisov <[email protected]>

Rangesets in XEN seems to be a pretty generic thing slightly poisoned with. domain specific funtionality in initialization and deinitialization code.

So make the rangeset code generic with moving domain specific code to common/domain.c

Andrii Anisov (6):
rangeset_new() refactoring
rangeset_destroy() refactoring
Drop rangeset_domain_initialise()
rangeset_domain_destroy() refactoring
rangeset_domain_printk() refactoring
Drop domain remains from rangeset

 xen/arch/x86/domain.c      |  2 +-
 xen/arch/x86/hvm/ioreq.c   |  6 ++---
 xen/arch/x86/mm/p2m.c      |  6 ++---
 xen/arch/x86/setup.c       |  4 +--
 xen/common/domain.c        | 48 +++++++++++++++++++++++++++++++----
 xen/common/keyhandler.c    |  2 +-
 xen/common/rangeset.c      | 63 +++++++++++++++-------------------------------
 xen/include/xen/domain.h   |  9 +++++++
 xen/include/xen/rangeset.h | 42 +++++++++++++++----------------
 9 files changed, 102 insertions(+), 80 deletions(-)
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

RFC 1/6 rangeset_new() refactoring

From: Andrii Anisov <[email protected]>

rangeset_new is made domain agnostic. The domain specific code is moved to common/domain.c:domain_rangeset_new().

It is still left a rangesets list functionality: rangeset_new() is returning its list head if requested. This would be reconsidered further.

---
 xen/arch/x86/domain.c      |  2 +-
 xen/arch/x86/hvm/ioreq.c   |  4 ++--
 xen/arch/x86/mm/p2m.c      |  4 ++--
 xen/arch/x86/setup.c       |  4 ++--
 xen/common/domain.c        | 22 ++++++++++++++++++++--
 xen/common/rangeset.c      | 12 ++++--------
 xen/include/xen/domain.h   |  3 +++
 xen/include/xen/rangeset.h | 19 +++++++++++--------
 8 files changed, 45 insertions(+), 25 deletions(-)
xen/arch/x86/domain.c +1 -1
index eae643f..93f18d7 100644
@@ -630,7 +630,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
         d->arch.x86_model  = boot_cpu_data.x86_model;
 
         d->arch.ioport_caps = 
-            rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex);
+            domain_rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex);
         rc = -ENOMEM;
         if ( d->arch.ioport_caps == NULL )
             goto fail;
xen/arch/x86/hvm/ioreq.c +2 -2
index 88071ab..6df191d 100644
@@ -520,8 +520,8 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,
         if ( rc )
             goto fail;
 
-        s->range[i] = rangeset_new(s->domain, name,
-                                   RANGESETF_prettyprint_hex);
+        s->range[i] = domain_rangeset_new(s->domain, name,
+                                          RANGESETF_prettyprint_hex);
 
         xfree(name);
 
xen/arch/x86/mm/p2m.c +2 -2
index 6a45185..46301ad 100644
@@ -122,8 +122,8 @@ static int p2m_init_hostp2m(struct domain *d)
 
     if ( p2m )
     {
-        p2m->logdirty_ranges = rangeset_new(d, "log-dirty",
-                                            RANGESETF_prettyprint_hex);
+        p2m->logdirty_ranges = domain_rangeset_new(d, "log-dirty",
+                                                   RANGESETF_prettyprint_hex);
         if ( p2m->logdirty_ranges )
         {
             d->arch.p2m = p2m;
xen/arch/x86/setup.c +2 -2
index b130671..69a961c 100644
@@ -1419,8 +1419,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     /* Low mappings were only needed for some BIOS table parsing. */
     zap_low_mappings();
 
-    mmio_ro_ranges = rangeset_new(NULL, "r/o mmio ranges",
-                                  RANGESETF_prettyprint_hex);
+    mmio_ro_ranges = rangeset_new("r/o mmio ranges",
+                                  RANGESETF_prettyprint_hex, NULL);
 
     init_apic_mappings();
 
xen/common/domain.c +20 -2
index 3abaca9..1b9bc3c 100644
@@ -329,8 +329,8 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
     rangeset_domain_initialise(d);
     init_status |= INIT_rangeset;
 
-    d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex);
-    d->irq_caps   = rangeset_new(d, "Interrupts", 0);
+    d->iomem_caps = domain_rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex);
+    d->irq_caps   = domain_rangeset_new(d, "Interrupts", 0);
     if ( (d->iomem_caps == NULL) || (d->irq_caps == NULL) )
         goto fail;
 
@@ -1537,6 +1537,24 @@ int continue_hypercall_on_cpu(
     return 0;
 }
 
+struct rangeset *domain_rangeset_new(struct domain *d, char *name,
+                                     unsigned int flags)
+{
+    struct list_head *head;
+    struct rangeset *r = rangeset_new(name, flags, &head);
+
+    if ( d != NULL )
+    {
+        spin_lock(&d->rangesets_lock);
+        list_add(head, &d->rangesets);
+        spin_unlock(&d->rangesets_lock);
+    }
+
+    return r;
+}
+
+
+
 /*
  * Local variables:
  * mode: C
xen/common/rangeset.c +4 -8
index 6c6293c..478d232 100644
@@ -322,8 +322,8 @@ bool_t rangeset_is_empty(
     return ((r == NULL) || list_empty(&r->range_list));
 }
 
-struct rangeset *rangeset_new(
-    struct domain *d, char *name, unsigned int flags)
+struct rangeset *rangeset_new(char *name, unsigned int flags,
+                              struct list_head **head)
 {
     struct rangeset *r;
 
@@ -347,12 +347,8 @@ struct rangeset *rangeset_new(
         snprintf(r->name, sizeof(r->name), "(no name)");
     }
 
-    if ( (r->domain = d) != NULL )
-    {
-        spin_lock(&d->rangesets_lock);
-        list_add(&r->rangeset_list, &d->rangesets);
-        spin_unlock(&d->rangesets_lock);
-    }
+    if (head)
+        *head = &r->rangeset_list;
 
     return r;
 }
xen/include/xen/domain.h +3 -0
index bce0ea1..cd62e6e 100644
@@ -108,4 +108,7 @@ struct vnuma_info {
 
 void vnuma_destroy(struct vnuma_info *vnuma);
 
+struct rangeset *domain_rangeset_new(struct domain *d, char *name,
+                                     unsigned int flags);
+
 #endif /* __XEN_DOMAIN_H__ */
xen/include/xen/rangeset.h +11 -8
index aa64082..395ba62 100644
@@ -13,6 +13,7 @@
 #include <xen/types.h>
 
 struct domain;
+struct list_head;
 struct rangeset;
 
 /*
@@ -28,15 +29,17 @@ void rangeset_domain_destroy(
     struct domain *d);
 
 /*
- * Create/destroy a rangeset. Optionally attach to specified domain @d for
- * auto-destruction when the domain dies. A name may be specified, for use
- * in debug pretty-printing, and various RANGESETF flags (defined below).
- * 
- * It is invalid to perform any operation on a rangeset @r after calling
- * rangeset_destroy(r).
+ * Create a rangeset. Optionally attach to a specified list @head.
+ * A name may be specified, for use in debug pretty-printing, and various
+ * RANGESETF flags (defined below).
+ */
+struct rangeset *rangeset_new(char *name, unsigned int flags,
+                              struct list_head **head);
+
+/*
+ * Destroy a rangeset. It is invalid to perform any operation on a rangeset @r
+ * after calling rangeset_destroy(r).
  */
-struct rangeset *rangeset_new(
-    struct domain *d, char *name, unsigned int flags);
 void rangeset_destroy(
     struct rangeset *r);
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [RFC 1/6] rangeset_new() refactoring

Quoted 113 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 12:03
To: [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; Paul Durrant <[email protected]>; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: [RFC 1/6] rangeset_new() refactoring

From: Andrii Anisov <[email protected]>

rangeset_new is made domain agnostic. The domain specific code is moved to common/domain.c:domain_rangeset_new().

It is still left a rangesets list functionality: rangeset_new() is returning its list head if requested. This would be reconsidered further.

---
 xen/arch/x86/domain.c      |  2 +-
 xen/arch/x86/hvm/ioreq.c   |  4 ++--
 xen/arch/x86/mm/p2m.c      |  4 ++--
 xen/arch/x86/setup.c       |  4 ++--
 xen/common/domain.c        | 22 ++++++++++++++++++++--
 xen/common/rangeset.c      | 12 ++++--------
 xen/include/xen/domain.h   |  3 +++
 xen/include/xen/rangeset.h | 19 +++++++++++--------
 8 files changed, 45 insertions(+), 25 deletions(-)
xen/arch/x86/domain.c +1 -1
index eae643f..93f18d7 100644
@@ -630,7 +630,7 @@ int arch_domain_create(struct domain *d, unsigned
 int domcr_flags,
         d->arch.x86_model  = boot_cpu_data.x86_model;
 
         d->arch.ioport_caps =
-            rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex);
+            domain_rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex);
         rc = -ENOMEM;
         if ( d->arch.ioport_caps == NULL )
             goto fail;
xen/arch/x86/hvm/ioreq.c +2 -2
index 88071ab..6df191d 100644
@@ -520,8 +520,8 @@ static int hvm_ioreq_server_alloc_rangesets(struct
 hvm_ioreq_server *s,
         if ( rc )
             goto fail;
 
-        s->range[i] = rangeset_new(s->domain, name,
-                                   RANGESETF_prettyprint_hex);
+        s->range[i] = domain_rangeset_new(s->domain, name,
+                                          RANGESETF_prettyprint_hex);
 
         xfree(name);
xen/arch/x86/mm/p2m.c +2 -2
index 6a45185..46301ad 100644
@@ -122,8 +122,8 @@ static int p2m_init_hostp2m(struct domain *d)
 
     if ( p2m )
     {
-        p2m->logdirty_ranges = rangeset_new(d, "log-dirty",
-                                            RANGESETF_prettyprint_hex);
+        p2m->logdirty_ranges = domain_rangeset_new(d, "log-dirty",
+                                                   RANGESETF_prettyprint_hex);
         if ( p2m->logdirty_ranges )
         {
             d->arch.p2m = p2m;
xen/arch/x86/setup.c +2 -2
index b130671..69a961c 100644
@@ -1419,8 +1419,8 @@ void __init noreturn __start_xen(unsigned long
 mbi_p)
     /* Low mappings were only needed for some BIOS table parsing. */
     zap_low_mappings();
 
-    mmio_ro_ranges = rangeset_new(NULL, "r/o mmio ranges",
-                                  RANGESETF_prettyprint_hex);
+    mmio_ro_ranges = rangeset_new("r/o mmio ranges",
+                                  RANGESETF_prettyprint_hex, NULL);
 
     init_apic_mappings();
xen/common/domain.c +2 -2
index 3abaca9..1b9bc3c 100644
@@ -329,8 +329,8 @@ struct domain *domain_create(domid_t domid,
 unsigned int domcr_flags,
     rangeset_domain_initialise(d);
     init_status |= INIT_rangeset;
 
-    d->iomem_caps = rangeset_new(d, "I/O Memory",
 RANGESETF_prettyprint_hex);
-    d->irq_caps   = rangeset_new(d, "Interrupts", 0);
+    d->iomem_caps = domain_rangeset_new(d, "I/O Memory",
 RANGESETF_prettyprint_hex);
+    d->irq_caps   = domain_rangeset_new(d, "Interrupts", 0);
     if ( (d->iomem_caps == NULL) || (d->irq_caps == NULL) )
         goto fail;

xen/common/domain.c int continue_hypercall_on_cpu( · line 1546

Quoted 10 lines
xen/common/domain.c +7 -0
@@ -1537,6 +1537,24 @@ int continue_hypercall_on_cpu(
     return 0;
 }
 
+struct rangeset *domain_rangeset_new(struct domain *d, char *name,
+                                     unsigned int flags)
+{
+    struct list_head *head;
+    struct rangeset *r = rangeset_new(name, flags, &head);
+
+    if ( d != NULL )

Shouldn't d == NULL be a hard error now, in which you could pass d->rangesets directly into rangeset_new() (under lock).

Paul

Quoted 97 lines
xen/common/domain.c +11 -0
+    {
+        spin_lock(&d->rangesets_lock);
+        list_add(head, &d->rangesets);
+        spin_unlock(&d->rangesets_lock);
+    }
+
+    return r;
+}
+
+
+
 /*
  * Local variables:
  * mode: C
xen/common/rangeset.c +4 -8
index 6c6293c..478d232 100644
@@ -322,8 +322,8 @@ bool_t rangeset_is_empty(
     return ((r == NULL) || list_empty(&r->range_list));
 }
 
-struct rangeset *rangeset_new(
-    struct domain *d, char *name, unsigned int flags)
+struct rangeset *rangeset_new(char *name, unsigned int flags,
+                              struct list_head **head)
 {
     struct rangeset *r;
 
@@ -347,12 +347,8 @@ struct rangeset *rangeset_new(
         snprintf(r->name, sizeof(r->name), "(no name)");
     }
 
-    if ( (r->domain = d) != NULL )
-    {
-        spin_lock(&d->rangesets_lock);
-        list_add(&r->rangeset_list, &d->rangesets);
-        spin_unlock(&d->rangesets_lock);
-    }
+    if (head)
+        *head = &r->rangeset_list;
 
     return r;
 }
xen/include/xen/domain.h +3 -0
index bce0ea1..cd62e6e 100644
@@ -108,4 +108,7 @@ struct vnuma_info {
 
 void vnuma_destroy(struct vnuma_info *vnuma);
 
+struct rangeset *domain_rangeset_new(struct domain *d, char *name,
+                                     unsigned int flags);
+
 #endif /* __XEN_DOMAIN_H__ */
xen/include/xen/rangeset.h +1 -2
index aa64082..395ba62 100644
@@ -13,6 +13,7 @@
 #include <xen/types.h>
 
 struct domain;
+struct list_head;
 struct rangeset;
 
 /*
@@ -28,15 +29,17 @@ void rangeset_domain_destroy(
     struct domain *d);
 
 /*
- * Create/destroy a rangeset. Optionally attach to specified domain @d for
- * auto-destruction when the domain dies. A name may be specified, for

use
- * in debug pretty-printing, and various RANGESETF flags (defined below).
- *
- * It is invalid to perform any operation on a rangeset @r after calling
- * rangeset_destroy(r).
+ * Create a rangeset. Optionally attach to a specified list @head.
+ * A name may be specified, for use in debug pretty-printing, and various
+ * RANGESETF flags (defined below).
+ */

xen/include/xen/rangeset.h +5 -0
+struct rangeset *rangeset_new(char *name, unsigned int flags,
+                              struct list_head **head);
+
+/*
+ * Destroy a rangeset. It is invalid to perform any operation on a rangeset

@r
+ * after calling rangeset_destroy(r).
*/

xen/include/xen/rangeset.h +0 -3
-struct rangeset *rangeset_new(
-    struct domain *d, char *name, unsigned int flags);
 void rangeset_destroy(
     struct rangeset *r);
 
--
Quoted 1 line

2.7.4

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

#3 lore raw

Re: [RFC 1/6] rangeset_new() refactoring

Quoted 3 lines
Quoted 1 line

+ if ( d != NULL )

Shouldn't d == NULL be a hard error now, in which you could pass d->rangesets directly into rangeset_new() (under lock).

It definitely should. Because this is a domain specific code.

Sincerely,
Andrii Anisov.

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

#4 lore raw

RFC 2/6 rangeset_destroy() refactoring

In reply to Andrii Anisov

From: Andrii Anisov <[email protected]>

rangeset_destroy is made domain agnostic. The domain specific code is moved to common/domain.c:domain_rangeset_destroy().

It is still left a rangesets list functionality: rangeset_destroy() will remove itself from a list. If a spinlock is provided it will be held for list deletion operation. This would be reconsidered further.

---
 xen/arch/x86/hvm/ioreq.c   |  2 +-
 xen/arch/x86/mm/p2m.c      |  2 +-
 xen/common/domain.c        |  5 +++++
 xen/common/rangeset.c      | 15 ++++++++-------
 xen/include/xen/domain.h   |  3 +++
 xen/include/xen/rangeset.h |  9 ++++++---
 6 files changed, 24 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/ioreq.c +1 -1
index 6df191d..6ae5921 100644
@@ -496,7 +496,7 @@ static void hvm_ioreq_server_free_rangesets(struct hvm_ioreq_server *s,
         return;
 
     for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
-        rangeset_destroy(s->range[i]);
+        domain_rangeset_destroy(s->range[i], s->domain);
 }
 
 static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,
xen/arch/x86/mm/p2m.c +1 -1
index 46301ad..d39c093 100644
@@ -141,7 +141,7 @@ static void p2m_teardown_hostp2m(struct domain *d)
 
     if ( p2m )
     {
-        rangeset_destroy(p2m->logdirty_ranges);
+        domain_rangeset_destroy(p2m->logdirty_ranges, d);
         p2m_free_one(p2m);
         d->arch.p2m = NULL;
     }
xen/common/domain.c +5 -0
index 1b9bc3c..f03a032 100644
@@ -1553,6 +1553,11 @@ struct rangeset *domain_rangeset_new(struct domain *d, char *name,
     return r;
 }
 
+void domain_rangeset_destroy(struct domain *d,
+    struct rangeset *r)
+{
+    rangeset_destroy(r, &d->rangesets_lock);
+}
 
 
 /*
xen/common/rangeset.c +8 -7
index 478d232..1172950 100644
@@ -354,19 +354,20 @@ struct rangeset *rangeset_new(char *name, unsigned int flags,
 }
 
 void rangeset_destroy(
-    struct rangeset *r)
+    struct rangeset *r, spinlock_t *lock)
 {
     struct range *x;
 
     if ( r == NULL )
         return;
 
-    if ( r->domain != NULL )
-    {
-        spin_lock(&r->domain->rangesets_lock);
-        list_del(&r->rangeset_list);
-        spin_unlock(&r->domain->rangesets_lock);
-    }
+    if ( lock )
+        spin_lock(lock);
+
+    list_del(&r->rangeset_list);
+
+    if ( lock )
+        spin_unlock(lock);
 
     while ( (x = first_range(r)) != NULL )
         destroy_range(r, x);
xen/include/xen/domain.h +3 -0
index cd62e6e..3d9c652 100644
@@ -111,4 +111,7 @@ void vnuma_destroy(struct vnuma_info *vnuma);
 struct rangeset *domain_rangeset_new(struct domain *d, char *name,
                                      unsigned int flags);
 
+void domain_rangeset_destroy(struct domain *d,
+    struct rangeset *r);
+
 #endif /* __XEN_DOMAIN_H__ */
xen/include/xen/rangeset.h +6 -3
index 395ba62..deed54d 100644
@@ -14,6 +14,7 @@
 
 struct domain;
 struct list_head;
+struct spinlock;
 struct rangeset;
 
 /*
@@ -37,11 +38,13 @@ struct rangeset *rangeset_new(char *name, unsigned int flags,
                               struct list_head **head);
 
 /*
- * Destroy a rangeset. It is invalid to perform any operation on a rangeset @r
+ * Destroy a rangeset. Rangeset will take an action to remove itself from a
+ * list. If a spinlock is provided it will be held during list deletion
+ * operation.
+ * It is invalid to perform any operation on a rangeset @r
  * after calling rangeset_destroy(r).
  */
-void rangeset_destroy(
-    struct rangeset *r);
+void rangeset_destroy(struct rangeset *r, struct spinlock *lock);
 
 /*
  * Set a limit on the number of ranges that may exist in set @r.
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw

Re: [RFC 2/6] rangeset_destroy() refactoring

Quoted 12 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 12:03
To: [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; Paul Durrant <[email protected]>; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: [RFC 2/6] rangeset_destroy() refactoring

Quoted 9 lines

From: Andrii Anisov <[email protected]>

rangeset_destroy is made domain agnostic. The domain specific code is moved to common/domain.c:domain_rangeset_destroy().

It is still left a rangesets list functionality: rangeset_destroy() will remove itself from a list. If a spinlock is provided it will be held for list deletion operation. This would be reconsidered further.

Maybe use the same scheme in patch #1 then and pass the lock, as well as the list_head, into rangeset_new().

Paul

Quoted 129 lines
---
 xen/arch/x86/hvm/ioreq.c   |  2 +-
 xen/arch/x86/mm/p2m.c      |  2 +-
 xen/common/domain.c        |  5 +++++
 xen/common/rangeset.c      | 15 ++++++++-------
 xen/include/xen/domain.h   |  3 +++
 xen/include/xen/rangeset.h |  9 ++++++---
 6 files changed, 24 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/ioreq.c +1 -1
index 6df191d..6ae5921 100644
@@ -496,7 +496,7 @@ static void hvm_ioreq_server_free_rangesets(struct
 hvm_ioreq_server *s,
         return;
 
     for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
-        rangeset_destroy(s->range[i]);
+        domain_rangeset_destroy(s->range[i], s->domain);
 }
 

static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,

xen/arch/x86/mm/p2m.c +1 -1
index 46301ad..d39c093 100644
@@ -141,7 +141,7 @@ static void p2m_teardown_hostp2m(struct domain
 *d)
 
     if ( p2m )
     {
-        rangeset_destroy(p2m->logdirty_ranges);
+        domain_rangeset_destroy(p2m->logdirty_ranges, d);
         p2m_free_one(p2m);
         d->arch.p2m = NULL;
     }
xen/common/domain.c +5 -0
index 1b9bc3c..f03a032 100644
@@ -1553,6 +1553,11 @@ struct rangeset *domain_rangeset_new(struct
 domain *d, char *name,
     return r;
 }
 
+void domain_rangeset_destroy(struct domain *d,
+    struct rangeset *r)
+{
+    rangeset_destroy(r, &d->rangesets_lock);
+}
 
 

/*

xen/common/rangeset.c +8 -7
index 478d232..1172950 100644
@@ -354,19 +354,20 @@ struct rangeset *rangeset_new(char *name,
 unsigned int flags,
 }
 
 void rangeset_destroy(
-    struct rangeset *r)
+    struct rangeset *r, spinlock_t *lock)
 {
     struct range *x;
 
     if ( r == NULL )
         return;
 
-    if ( r->domain != NULL )
-    {
-        spin_lock(&r->domain->rangesets_lock);
-        list_del(&r->rangeset_list);
-        spin_unlock(&r->domain->rangesets_lock);
-    }
+    if ( lock )
+        spin_lock(lock);
+
+    list_del(&r->rangeset_list);
+
+    if ( lock )
+        spin_unlock(lock);
 
     while ( (x = first_range(r)) != NULL )
         destroy_range(r, x);
xen/include/xen/domain.h +3 -0
index cd62e6e..3d9c652 100644
@@ -111,4 +111,7 @@ void vnuma_destroy(struct vnuma_info *vnuma);
 struct rangeset *domain_rangeset_new(struct domain *d, char *name,
                                      unsigned int flags);
 
+void domain_rangeset_destroy(struct domain *d,
+    struct rangeset *r);
+
 #endif /* __XEN_DOMAIN_H__ */
xen/include/xen/rangeset.h +6 -3
index 395ba62..deed54d 100644
@@ -14,6 +14,7 @@
 
 struct domain;
 struct list_head;
+struct spinlock;
 struct rangeset;
 
 /*
@@ -37,11 +38,13 @@ struct rangeset *rangeset_new(char *name,
 unsigned int flags,
                               struct list_head **head);
 
 /*
- * Destroy a rangeset. It is invalid to perform any operation on a rangeset @r
+ * Destroy a rangeset. Rangeset will take an action to remove itself from a
+ * list. If a spinlock is provided it will be held during list deletion
+ * operation.
+ * It is invalid to perform any operation on a rangeset @r
  * after calling rangeset_destroy(r).
  */
-void rangeset_destroy(
-    struct rangeset *r);
+void rangeset_destroy(struct rangeset *r, struct spinlock *lock);
 
 /*
Quoted 3 lines

* Set a limit on the number of ranges that may exist in set @r.
--
2.7.4

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

#6 lore raw

Re: [RFC 2/6] rangeset_destroy() refactoring

Dear Paul,

Quoted 6 lines
Quoted 4 lines

It is still left a rangesets list functionality: rangeset_destroy() will remove itself from a list. If a spinlock is provided it will be held for list deletion operation. This would be reconsidered further.

Maybe use the same scheme in patch #1 then and pass the lock, as well as the list_head, into rangeset_new().

Initialized list head in patch#1 is provided by rangeset to user if user needs it to link to some list. So user should do the locking on tree insert if it needs. Here rangeset user can not acquire the tree head even if it has a rangeset itself, because struct rangeset is not exposed via header file. So rangeset_destroy() should take care of tree head remove and spinlock locking if needed.

I still have concerns why rangeset list keeping should be inside rangeset itself.

Sincerely,
Andrii Anisov.

2017-02-16 14:26 GMT+02:00 Paul Durrant <[email protected]>:

Quoted 154 lines
Quoted 12 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 12:03
To: [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; Paul Durrant <[email protected]>; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: [RFC 2/6] rangeset_destroy() refactoring

Quoted 9 lines

From: Andrii Anisov <[email protected]>

rangeset_destroy is made domain agnostic. The domain specific code is moved to common/domain.c:domain_rangeset_destroy().

It is still left a rangesets list functionality: rangeset_destroy() will remove itself from a list. If a spinlock is provided it will be held for list deletion operation. This would be reconsidered further.

Maybe use the same scheme in patch #1 then and pass the lock, as well as the list_head, into rangeset_new().

Paul

Quoted 128 lines
---
 xen/arch/x86/hvm/ioreq.c   |  2 +-
 xen/arch/x86/mm/p2m.c      |  2 +-
 xen/common/domain.c        |  5 +++++
 xen/common/rangeset.c      | 15 ++++++++-------
 xen/include/xen/domain.h   |  3 +++
 xen/include/xen/rangeset.h |  9 ++++++---
 6 files changed, 24 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/ioreq.c +1 -1
index 6df191d..6ae5921 100644
@@ -496,7 +496,7 @@ static void hvm_ioreq_server_free_rangesets(struct
 hvm_ioreq_server *s,
         return;
 
     for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
-        rangeset_destroy(s->range[i]);
+        domain_rangeset_destroy(s->range[i], s->domain);
 }
 

static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,

xen/arch/x86/mm/p2m.c +1 -1
index 46301ad..d39c093 100644
@@ -141,7 +141,7 @@ static void p2m_teardown_hostp2m(struct domain
 *d)
 
     if ( p2m )
     {
-        rangeset_destroy(p2m->logdirty_ranges);
+        domain_rangeset_destroy(p2m->logdirty_ranges, d);
         p2m_free_one(p2m);
         d->arch.p2m = NULL;
     }
xen/common/domain.c +5 -0
index 1b9bc3c..f03a032 100644
@@ -1553,6 +1553,11 @@ struct rangeset *domain_rangeset_new(struct
 domain *d, char *name,
     return r;
 }
 
+void domain_rangeset_destroy(struct domain *d,
+    struct rangeset *r)
+{
+    rangeset_destroy(r, &d->rangesets_lock);
+}
 
 

/*

xen/common/rangeset.c +8 -7
index 478d232..1172950 100644
@@ -354,19 +354,20 @@ struct rangeset *rangeset_new(char *name,
 unsigned int flags,
 }
 
 void rangeset_destroy(
-    struct rangeset *r)
+    struct rangeset *r, spinlock_t *lock)
 {
     struct range *x;
 
     if ( r == NULL )
         return;
 
-    if ( r->domain != NULL )
-    {
-        spin_lock(&r->domain->rangesets_lock);
-        list_del(&r->rangeset_list);
-        spin_unlock(&r->domain->rangesets_lock);
-    }
+    if ( lock )
+        spin_lock(lock);
+
+    list_del(&r->rangeset_list);
+
+    if ( lock )
+        spin_unlock(lock);
 
     while ( (x = first_range(r)) != NULL )
         destroy_range(r, x);
xen/include/xen/domain.h +3 -0
index cd62e6e..3d9c652 100644
@@ -111,4 +111,7 @@ void vnuma_destroy(struct vnuma_info *vnuma);
 struct rangeset *domain_rangeset_new(struct domain *d, char *name,
                                      unsigned int flags);
 
+void domain_rangeset_destroy(struct domain *d,
+    struct rangeset *r);
+
 #endif /* __XEN_DOMAIN_H__ */
xen/include/xen/rangeset.h +6 -3
index 395ba62..deed54d 100644
@@ -14,6 +14,7 @@
 
 struct domain;
 struct list_head;
+struct spinlock;
 struct rangeset;
 
 /*
@@ -37,11 +38,13 @@ struct rangeset *rangeset_new(char *name,
 unsigned int flags,
                               struct list_head **head);
 
 /*
- * Destroy a rangeset. It is invalid to perform any operation on a rangeset @r
+ * Destroy a rangeset. Rangeset will take an action to remove itself from a
+ * list. If a spinlock is provided it will be held during list deletion
+ * operation.
+ * It is invalid to perform any operation on a rangeset @r
  * after calling rangeset_destroy(r).
  */
-void rangeset_destroy(
-    struct rangeset *r);
+void rangeset_destroy(struct rangeset *r, struct spinlock *lock);
 
Quoted 5 lines
Quoted 4 lines
xen/include/xen/rangeset.h +0 -0
 /*

* Set a limit on the number of ranges that may exist in set @r.
--
2.7.4

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

#7 lore raw

Re: [RFC 2/6] rangeset_destroy() refactoring

Quoted 27 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 14:26
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [RFC 2/6] rangeset_destroy() refactoring

Dear Paul,

Quoted 6 lines
Quoted 4 lines

It is still left a rangesets list functionality: rangeset_destroy() will remove itself from a list. If a spinlock is provided it will be held for list deletion operation. This would be reconsidered further.

Maybe use the same scheme in patch #1 then and pass the lock, as well as

the list_head, into rangeset_new().
Initialized list head in patch#1 is provided by rangeset to user if user needs it to link to some list. So user should do the locking on tree insert if it needs. Here rangeset user can not acquire the tree head even if it has a rangeset itself, because struct rangeset is not exposed via header file. So rangeset_destroy() should take care of tree head remove and spinlock locking if needed.

Quoted 2 lines

I still have concerns why rangeset list keeping should be inside rangeset itself.

What use are rangesets if the implementation doesn't control the list/tree? How on earth would you implement an allocation function otherwise?

Paul

Quoted 151 lines

Sincerely,
Andrii Anisov.

2017-02-16 14:26 GMT+02:00 Paul Durrant <[email protected]>:

Quoted 17 lines
Quoted 17 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 12:03
To: [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; Paul Durrant <[email protected]>; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: [RFC 2/6] rangeset_destroy() refactoring

From: Andrii Anisov <[email protected]>

rangeset_destroy is made domain agnostic. The domain specific code is moved to common/domain.c:domain_rangeset_destroy().

Quoted 6 lines
Quoted 4 lines

It is still left a rangesets list functionality: rangeset_destroy() will remove itself from a list. If a spinlock is provided it will be held for list deletion operation. This would be reconsidered further.

Maybe use the same scheme in patch #1 then and pass the lock, as well as

the list_head, into rangeset_new().

Quoted 13 lines

Paul

Quoted 10 lines
---
 xen/arch/x86/hvm/ioreq.c   |  2 +-
 xen/arch/x86/mm/p2m.c      |  2 +-
 xen/common/domain.c        |  5 +++++
 xen/common/rangeset.c      | 15 ++++++++-------
 xen/include/xen/domain.h   |  3 +++
 xen/include/xen/rangeset.h |  9 ++++++---
 6 files changed, 24 insertions(+), 12 deletions(-)
Quoted 5 lines

xen/arch/x86/hvm/ioreq.c static void

Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +0 -0
index 6df191d..6ae5921 100644
@@ -496,7 +496,7 @@ static void

hvm_ioreq_server_free_rangesets(struct

Quoted 9 lines
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c +1 -1
 hvm_ioreq_server *s,
         return;
 
     for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
-        rangeset_destroy(s->range[i]);
+        domain_rangeset_destroy(s->range[i], s->domain);
 }
 

static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server

*s,

Quoted 92 lines
Quoted 92 lines
xen/arch/x86/mm/p2m.c +1 -1
index 46301ad..d39c093 100644
@@ -141,7 +141,7 @@ static void p2m_teardown_hostp2m(struct domain
 *d)
 
     if ( p2m )
     {
-        rangeset_destroy(p2m->logdirty_ranges);
+        domain_rangeset_destroy(p2m->logdirty_ranges, d);
         p2m_free_one(p2m);
         d->arch.p2m = NULL;
     }
xen/common/domain.c +5 -0
index 1b9bc3c..f03a032 100644
@@ -1553,6 +1553,11 @@ struct rangeset *domain_rangeset_new(struct
 domain *d, char *name,
     return r;
 }
 
+void domain_rangeset_destroy(struct domain *d,
+    struct rangeset *r)
+{
+    rangeset_destroy(r, &d->rangesets_lock);
+}
 
 

/*

xen/common/rangeset.c +8 -7
index 478d232..1172950 100644
@@ -354,19 +354,20 @@ struct rangeset *rangeset_new(char *name,
 unsigned int flags,
 }
 
 void rangeset_destroy(
-    struct rangeset *r)
+    struct rangeset *r, spinlock_t *lock)
 {
     struct range *x;
 
     if ( r == NULL )
         return;
 
-    if ( r->domain != NULL )
-    {
-        spin_lock(&r->domain->rangesets_lock);
-        list_del(&r->rangeset_list);
-        spin_unlock(&r->domain->rangesets_lock);
-    }
+    if ( lock )
+        spin_lock(lock);
+
+    list_del(&r->rangeset_list);
+
+    if ( lock )
+        spin_unlock(lock);
 
     while ( (x = first_range(r)) != NULL )
         destroy_range(r, x);
xen/include/xen/domain.h +3 -0
index cd62e6e..3d9c652 100644
@@ -111,4 +111,7 @@ void vnuma_destroy(struct vnuma_info *vnuma);
 struct rangeset *domain_rangeset_new(struct domain *d, char *name,
                                      unsigned int flags);
 
+void domain_rangeset_destroy(struct domain *d,
+    struct rangeset *r);
+
 #endif /* __XEN_DOMAIN_H__ */
xen/include/xen/rangeset.h +1 -0
index 395ba62..deed54d 100644
@@ -14,6 +14,7 @@
 
 struct domain;
 struct list_head;
+struct spinlock;
 struct rangeset;
 
 /*
@@ -37,11 +38,13 @@ struct rangeset *rangeset_new(char *name,
 unsigned int flags,
                               struct list_head **head);
 
Quoted 19 lines
Quoted 2 lines

xen/include/xen/rangeset.h struct rangeset *rangeset_new(char *name, · line 41

Quoted 2 lines
xen/include/xen/rangeset.h +0 -1
 /*
- * Destroy a rangeset. It is invalid to perform any operation on a rangeset

@r

Quoted 1 line

xen/include/xen/rangeset.h struct rangeset *rangeset_new(char *name, · line 42

Quoted 1 line
xen/include/xen/rangeset.h +1 -0
+ * Destroy a rangeset. Rangeset will take an action to remove itself from

a

Quoted 14 lines
Quoted 13 lines
xen/include/xen/rangeset.h +4 -2
+ * list. If a spinlock is provided it will be held during list deletion
+ * operation.
+ * It is invalid to perform any operation on a rangeset @r
  * after calling rangeset_destroy(r).
  */
-void rangeset_destroy(
-    struct rangeset *r);
+void rangeset_destroy(struct rangeset *r, struct spinlock *lock);
 
 /*

* Set a limit on the number of ranges that may exist in set @r.
--
2.7.4

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

#8 lore raw

Re: [RFC 2/6] rangeset_destroy() refactoring

Quoted 1 line

What use are rangesets if the implementation doesn't control the list/tree? How on earth would you implement an allocation function otherwise?

Just to be on the same page, my understanding of the rangesets is as following:

- Currently the struct rangeset is a list of ranges. This list
head is a range_list of struct rangeset. Currently range_list manipulations are not protected by any locks. IMO this is the core functionality of the rangeset.

- Also there is another list head rangeset_list inside `struct
rangeset`. It is used to link a rangeset to an external list of rangesets. This is protected by spinlocks now. IMO this functionality is odd to the rangeset itself.

Sincerely,
Andrii Anisov.

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

#9 lore raw

Re: [RFC 2/6] rangeset_destroy() refactoring

Quoted 21 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 16:22
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [RFC 2/6] rangeset_destroy() refactoring

Quoted 1 line

What use are rangesets if the implementation doesn't control the list/tree?

How on earth would you implement an allocation function otherwise? Just to be on the same page, my understanding of the rangesets is as following:

- Currently the struct rangeset is a list of ranges. This list
head is a range_list of struct rangeset. Currently range_list manipulations are not protected by any locks. IMO this is the core functionality of the rangeset.

Quoted 4 lines

- Also there is another list head rangeset_list inside `struct
rangeset`. It is used to link a rangeset to an external list of rangesets. This is protected by spinlocks now. IMO this functionality is odd to the rangeset itself.

Ok. Thanks for the clarification. Yes, that second list_head does not strictly belong inside the rangeset structure itself. I guess it could live in a 'domain_rangeset' wrapper structure.

Paul

Quoted 3 lines

Sincerely,
Andrii Anisov.

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

#10 lore raw

RFC 3/6 Drop rangeset_domain_initialise()

In reply to Andrii Anisov

From: Andrii Anisov <[email protected]>

The rangeset_domain_initialise() does nothing rangeset specific. Even keeping it specific to domain looks not reasonable. So drop it.

---
 xen/common/domain.c        | 3 ++-
 xen/common/rangeset.c      | 7 -------
 xen/include/xen/rangeset.h | 4 +---
 3 files changed, 3 insertions(+), 11 deletions(-)
xen/common/domain.c +2 -1
index f03a032..7fe69c6 100644
@@ -326,7 +326,8 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
         d->disable_migrate = 1;
     }
 
-    rangeset_domain_initialise(d);
+    INIT_LIST_HEAD(&d->rangesets);
+    spin_lock_init(&d->rangesets_lock);
     init_status |= INIT_rangeset;
 
     d->iomem_caps = domain_rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex);
xen/common/rangeset.c +0 -7
index 1172950..1a13a32 100644
@@ -381,13 +381,6 @@ void rangeset_limit(
     r->nr_ranges = limit;
 }
 
-void rangeset_domain_initialise(
-    struct domain *d)
-{
-    INIT_LIST_HEAD(&d->rangesets);
-    spin_lock_init(&d->rangesets_lock);
-}
-
 void rangeset_domain_destroy(
     struct domain *d)
 {
xen/include/xen/rangeset.h +1 -3
index deed54d..e8244a0 100644
@@ -18,14 +18,12 @@ struct spinlock;
 struct rangeset;
 
 /*
- * Initialise/destroy per-domain rangeset information.
+ * Destroy per-domain rangeset information.
  * 
  * It is invalid to create or destroy a rangeset belonging to a domain @d
  * before rangeset_domain_initialise(d) returns or after calling
  * rangeset_domain_destroy(d).
  */
-void rangeset_domain_initialise(
-    struct domain *d);
 void rangeset_domain_destroy(
     struct domain *d);
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#11 lore raw

RFC 4/6 rangeset_domain_destroy() refactoring

In reply to Andrii Anisov

From: Andrii Anisov <[email protected]>

rangeset_domain_destroy() is rather rangeset list helper and does nothing really domain specific. So replace it with rangeset_list_destroy() helper.

---
 xen/common/domain.c        |  4 ++--
 xen/common/rangeset.c      | 11 ++++-------
 xen/include/xen/rangeset.h |  9 ++-------
 3 files changed, 8 insertions(+), 16 deletions(-)
xen/common/domain.c +2 -2
index 7fe69c6..47c45f2 100644
@@ -420,7 +420,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
         radix_tree_destroy(&d->pirq_tree, free_pirq_struct);
     }
     if ( init_status & INIT_rangeset )
-        rangeset_domain_destroy(d);
+        rangeset_list_destroy(&d->rangesets);
     if ( init_status & INIT_watchdog )
         watchdog_domain_destroy(d);
     if ( init_status & INIT_xsm )
@@ -815,7 +815,7 @@ static void complete_domain_destroy(struct rcu_head *head)
 
     watchdog_domain_destroy(d);
 
-    rangeset_domain_destroy(d);
+    rangeset_list_destroy(&d->rangesets);
 
     sched_destroy_domain(d);
 
xen/common/rangeset.c +4 -7
index 1a13a32..a8b5a5d 100644
@@ -381,20 +381,17 @@ void rangeset_limit(
     r->nr_ranges = limit;
 }
 
-void rangeset_domain_destroy(
-    struct domain *d)
+void rangeset_list_destroy(struct list_head *list)
 {
     struct rangeset *r;
 
-    while ( !list_empty(&d->rangesets) )
+    while ( !list_empty(list) )
     {
-        r = list_entry(d->rangesets.next, struct rangeset, rangeset_list);
+        r = list_entry(list->next, struct rangeset, rangeset_list);
 
-        BUG_ON(r->domain != d);
-        r->domain = NULL;
         list_del(&r->rangeset_list);
 
-        rangeset_destroy(r);
+        rangeset_destroy(r, NULL);
     }
 }
 
xen/include/xen/rangeset.h +2 -7
index e8244a0..cc795d1 100644
@@ -18,14 +18,9 @@ struct spinlock;
 struct rangeset;
 
 /*
- * Destroy per-domain rangeset information.
- * 
- * It is invalid to create or destroy a rangeset belonging to a domain @d
- * before rangeset_domain_initialise(d) returns or after calling
- * rangeset_domain_destroy(d).
+ * Destroy a list of rangesets.
  */
-void rangeset_domain_destroy(
-    struct domain *d);
+void rangeset_list_destroy(struct list_head *list);
 
 /*
  * Create a rangeset. Optionally attach to a specified list @head.
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw

RFC 5/6 rangeset_domain_printk() refactoring

In reply to Andrii Anisov

From: Andrii Anisov <[email protected]>

rangeset_domain_printk() is split into generic rangeset_list_printk() function and domain specific common/domain.c:domain_rangeset_printk().

---
 xen/common/domain.c        | 14 ++++++++++++++
 xen/common/keyhandler.c    |  2 +-
 xen/common/rangeset.c      | 15 +++------------
 xen/include/xen/domain.h   |  3 +++
 xen/include/xen/rangeset.h |  4 ++--
 5 files changed, 23 insertions(+), 15 deletions(-)
xen/common/domain.c +14 -0
index 47c45f2..9b68e2f 100644
@@ -1560,6 +1560,20 @@ void domain_rangeset_destroy(struct domain *d,
     rangeset_destroy(r, &d->rangesets_lock);
 }
 
+void domain_rangeset_printk(
+    struct domain *d)
+{
+    printk("Rangesets belonging to domain %u:\n", d->domain_id);
+
+    spin_lock(&d->rangesets_lock);
+
+    if ( list_empty(&d->rangesets) )
+        printk("    None\n");
+
+    rangeset_list_printk(&d->rangesets);
+
+    spin_unlock(&d->rangesets_lock);
+}
 
 /*
  * Local variables:
xen/common/keyhandler.c +1 -1
index 16de6e8..4f237f0 100644
@@ -320,7 +320,7 @@ static void dump_domains(unsigned char key)
 
         arch_dump_domain_info(d);
 
-        rangeset_domain_printk(d);
+        domain_rangeset_printk(d);
 
         dump_pageframe_info(d);
 
xen/common/rangeset.c +3 -12
index a8b5a5d..c18fb21 100644
@@ -455,26 +455,17 @@ void rangeset_printk(
     read_unlock(&r->lock);
 }
 
-void rangeset_domain_printk(
-    struct domain *d)
+void rangeset_list_printk(
+    struct list_head *list)
 {
     struct rangeset *r;
 
-    printk("Rangesets belonging to domain %u:\n", d->domain_id);
-
-    spin_lock(&d->rangesets_lock);
-
-    if ( list_empty(&d->rangesets) )
-        printk("    None\n");
-
-    list_for_each_entry ( r, &d->rangesets, rangeset_list )
+    list_for_each_entry ( r, list, rangeset_list )
     {
         printk("    ");
         rangeset_printk(r);
         printk("\n");
     }
-
-    spin_unlock(&d->rangesets_lock);
 }
 
 /*
xen/include/xen/domain.h +3 -0
index 3d9c652..b2dca15 100644
@@ -114,4 +114,7 @@ struct rangeset *domain_rangeset_new(struct domain *d, char *name,
 void domain_rangeset_destroy(struct domain *d,
     struct rangeset *r);
 
+void domain_rangeset_printk(
+    struct domain *d);
+
 #endif /* __XEN_DOMAIN_H__ */
xen/include/xen/rangeset.h +2 -2
index cc795d1..8fd8164 100644
@@ -81,8 +81,8 @@ void rangeset_swap(struct rangeset *a, struct rangeset *b);
 /* Rangeset pretty printing. */
 void rangeset_printk(
     struct rangeset *r);
-void rangeset_domain_printk(
-    struct domain *d);
+void rangeset_list_printk(
+    struct list_head *list);
 
 #endif /* __XEN_RANGESET_H__ */
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#13 lore raw

RFC 6/6 Drop domain remains from rangeset

In reply to Andrii Anisov

From: Andrii Anisov <[email protected]>

---
 xen/common/rangeset.c      | 3 +--
 xen/include/xen/rangeset.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)
xen/common/rangeset.c +1 -2
index c18fb21..857615b 100644
@@ -19,9 +19,8 @@ struct range {
 };
 
 struct rangeset {
-    /* Owning domain and threaded list of rangesets. */
+    /* threaded list of rangesets. */
     struct list_head rangeset_list;
-    struct domain   *domain;
 
     /* Ordered list of ranges contained in this set, and protecting lock. */
     struct list_head range_list;
xen/include/xen/rangeset.h +0 -1
index 8fd8164..8462071 100644
@@ -12,7 +12,6 @@
 
 #include <xen/types.h>
 
-struct domain;
 struct list_head;
 struct spinlock;
 struct rangeset;
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#14 lore raw
In reply to Andrii Anisov
Quoted 12 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 12:03
To: [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; Paul Durrant <[email protected]>; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: [RFC 0/6] Rangeset generalisation

Quoted 7 lines

From: Andrii Anisov <[email protected]>

Rangesets in XEN seems to be a pretty generic thing slightly poisoned with. domain specific funtionality in initialization and deinitialization code.

So make the rangeset code generic with moving domain specific code to common/domain.c

Any particular reason this series is RFC? The cleanup seems a good thing to do to me.

Paul

Quoted 21 lines

Andrii Anisov (6):
rangeset_new() refactoring
rangeset_destroy() refactoring
Drop rangeset_domain_initialise()
rangeset_domain_destroy() refactoring
rangeset_domain_printk() refactoring
Drop domain remains from rangeset

 xen/arch/x86/domain.c      |  2 +-
 xen/arch/x86/hvm/ioreq.c   |  6 ++---
 xen/arch/x86/mm/p2m.c      |  6 ++---
 xen/arch/x86/setup.c       |  4 +--
 xen/common/domain.c        | 48 +++++++++++++++++++++++++++++++----
 xen/common/keyhandler.c    |  2 +-
 xen/common/rangeset.c      | 63 +++++++++++++++-----------------------------
--
 xen/include/xen/domain.h   |  9 +++++++
 xen/include/xen/rangeset.h | 42 +++++++++++++++----------------
 9 files changed, 102 insertions(+), 80 deletions(-)
Quoted 2 lines

--
2.7.4

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

#15 lore raw

Dear Paul,

Quoted 1 line

The cleanup seems a good thing to do to me.

So I would collect comments, rebase it to latest master and push the second version without RFC.

Quoted 1 line

Any particular reason this series is RFC?

The reason to make this series was an intention to use rangesets to manage mmio ranges in our shared coprocessor framework. It was planned to extend range with void* priv to extend functionality. Unfortunately the rangeset feature to merge ranges makes it unusable for our needs. Also linked list, even sorted, is not really good in search.
Another concern was how community react on the change into generic code.

Sincerely,
Andrii Anisov.

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

#16 lore raw
Quoted 20 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 12:46
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [RFC 0/6] Rangeset generalisation

Dear Paul,

Quoted 1 line

The cleanup seems a good thing to do to me.

So I would collect comments, rebase it to latest master and push the second version without RFC.

Quoted 1 line

Any particular reason this series is RFC?

Quoted 7 lines

The reason to make this series was an intention to use rangesets to manage mmio ranges in our shared coprocessor framework. It was planned to extend range with void* priv to extend functionality. Unfortunately the rangeset feature to merge ranges makes it unusable for our needs. Also linked list, even sorted, is not really good in search.
Another concern was how community react on the change into generic code.

Many moons ago there were patches to use rbtree for rangesets. Perhaps it would be worth reviving that idea?

Paul

Quoted 3 lines

Sincerely,
Andrii Anisov.

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

#17 lore raw

Dear Paul,

Quoted 1 line

Many moons ago there were patches to use rbtree for rangesets. Perhaps it would be worth reviving that idea?

rbtree is a thing I think of now for our needs.
Even more, currently I think of refactoring ARM mmio ranges managing to use rbtree one day. Currently there is a static array of 16 ranges maximum with sort on insert and bsearch there. With introducing of shared coprocessor framework system would need more mmio ranges, and dynamic data structure fast search capable looks good to fit their needs.
I assume Julien did not consider rangesets for ARM mmio managing due to no range priv data for r/w handlers, linked list search slowness and ranges merging capabilities.

Sincerely,
Andrii Anisov.

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

#19 lore raw
Quoted 11 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 13:24
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [RFC 0/6] Rangeset generalisation

Quoted 5 lines

Paul,

Quoted 1 line

Many moons ago there were patches to use rbtree for rangesets. Perhaps

it would be worth reviving that idea?
Do you have a link to look at those patches?

The relevant patch is:

https://lists.xenproject.org/archives/html/xen-devel/2015-12/msg01619.html

Paul

Quoted 3 lines

Sincerely,
Andrii Anisov.

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

#20 lore raw
Quoted 3 lines

The relevant patch is:

https://lists.xenproject.org/archives/html/xen-devel/2015-12/msg01619.html

Thank you for the link.
I would try to realize why it is left unmerged.

Sincerely,
Andrii Anisov.

2017-02-16 16:02 GMT+02:00 Paul Durrant <[email protected]>:

Quoted 14 lines
Quoted 14 lines

-----Original Message-----
From: Andrii Anisov [mailto:[email protected]]
Sent: 16 February 2017 13:24
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; [email protected]; [email protected]; [email protected]; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [RFC 0/6] Rangeset generalisation

Paul,

Quoted 1 line

Many moons ago there were patches to use rbtree for rangesets. Perhaps

Quoted 12 lines
Quoted 2 lines

it would be worth reviving that idea?
Do you have a link to look at those patches?

The relevant patch is:

https://lists.xenproject.org/archives/html/xen-devel/2015-12/msg01619.html

Paul

Quoted 3 lines

Sincerely,
Andrii Anisov.

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

#21 lore raw
In reply to Andrii Anisov
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 16.02.17 at 13:45, <[email protected]> wrote:

Dear Paul,

Quoted 1 line

The cleanup seems a good thing to do to me.

Quoted 7 lines

So I would collect comments, rebase it to latest master and push the second version without RFC.

Quoted 1 line

Any particular reason this series is RFC?

The reason to make this series was an intention to use rangesets to manage mmio ranges in our shared coprocessor framework.

If this is meant to be per-domain management - how many such ranges do you expect to be necessary for any one domain? We've had attempts before to (ab)use rangesets for such a purpose.

Quoted 5 lines

It was planned
to extend range with void* priv to extend functionality. Unfortunately the rangeset feature to merge ranges makes it unusable for our needs. Also linked list, even sorted, is not really good in search.

This concern makes me assume there might be quite many of them, which then makes this a no-go for unprivileged domains.

Jan

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

#22 lore raw

Dear Jan,

Quoted 3 lines

If this is meant to be per-domain management - how many such ranges do you expect to be necessary for any one domain? We've had attempts before to (ab)use rangesets for such a purpose.

It is meant to be the per-domain management. To handle per-domain vcoproc register access emulation described here [1] in terms of shared coproc framework [2].

[1] https://lists.xenproject.org/archives/html/xen-devel/2016-11/msg01935.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2016-10/msg01966.html

Sincerely,
Andrii Anisov.

2017-02-16 15:25 GMT+02:00 Jan Beulich <[email protected]>:

Quoted 23 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 16.02.17 at 13:45, <[email protected]> wrote:

Dear Paul,

Quoted 1 line

The cleanup seems a good thing to do to me.

Quoted 7 lines

So I would collect comments, rebase it to latest master and push the second version without RFC.

Quoted 1 line

Any particular reason this series is RFC?

The reason to make this series was an intention to use rangesets to manage mmio ranges in our shared coprocessor framework.

If this is meant to be per-domain management - how many such ranges do you expect to be necessary for any one domain? We've had attempts before to (ab)use rangesets for such a purpose.

Quoted 5 lines

It was planned
to extend range with void* priv to extend functionality. Unfortunately the rangeset feature to merge ranges makes it unusable for our needs. Also linked list, even sorted, is not really good in search.

Quoted 5 lines

This concern makes me assume there might be quite many of them, which then makes this a no-go for unprivileged domains.

Jan

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

#24 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 16.02.17 at 14:42, <[email protected]> wrote:

I'm really sorry, but I did not get your point here:

Quoted 2 lines

This concern makes me assume there might be quite many of them, which then makes this a no-go for unprivileged domains.

Could you please provide wider explanation.

Well, as it had been discussed before, I thought you would have found it the latest along with Paul having pointed you at the patches. The issue is with resource consumption: We can't allow a guest to consume basically arbitrary amounts of memory in the rangeset control structures. Iirc this was in the context of the now stuck persistent memory support series as well as around Intel's graphics virtualization one.

Jan

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

#25 lore raw
Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 16.02.17 at 14:42, <[email protected]> wrote:

I'm really sorry, but I did not get your point here:

Quoted 2 lines

This concern makes me assume there might be quite many of them, which then makes this a no-go for unprivileged domains.

Could you please provide wider explanation.

Quoted 7 lines

Well, as it had been discussed before, I thought you would have found it the latest along with Paul having pointed you at the patches. The issue is with resource consumption: We can't allow a guest to consume basically arbitrary amounts of memory in the rangeset control structures. Iirc this was in the context of the now stuck persistent memory support series as well as around Intel's graphics virtualization one.

I'm not sure it's reasonable to expect people to wade through all the discussions of previous threads, complete with style nitpicks and what-not, when it could be summarized in a sentence or two. :-)

I think the key thing with the graphics virtualization one, anyway, was that the guest could *provoke* the devicemodel into creating arbitrary numbers of "ranges" by using them in the GPT tables. If the number of ranges is large but bounded, that's less of an issue.

Andrii, could you describe a bit more how you had thought of using the rangesets?

-George

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