xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v9 06/11] xen: introduce rangeset_consume_ranges
Date: Wed, 14 Mar 2018 14:04:03 +0000	[thread overview]
Message-ID: <20180314140408.40947-7-roger.pau@citrix.com> (raw)
In-Reply-To: <20180314140408.40947-1-roger.pau@citrix.com>

This function allows to iterate over a rangeset while removing the
processed regions.

This will be used in order to split processing of large memory areas
when mapping them into the guest p2m.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Julien Grall <julien.grall@arm.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>
---
Changes since v6:
 - Expand commit message.
 - Add a comment to describe the expected function behavior.
 - Fix indentation.

Changes since v5:
 - New in this version.
---
 xen/common/rangeset.c      | 28 ++++++++++++++++++++++++++++
 xen/include/xen/rangeset.h | 10 ++++++++++
 2 files changed, 38 insertions(+)

diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c
index ade34f6a50..bb68ce62e4 100644
--- a/xen/common/rangeset.c
+++ b/xen/common/rangeset.c
@@ -350,6 +350,34 @@ int rangeset_claim_range(struct rangeset *r, unsigned long size,
     return 0;
 }
 
+int rangeset_consume_ranges(struct rangeset *r,
+                            int (*cb)(unsigned long s, unsigned long e, void *,
+                                      unsigned long *c),
+                            void *ctxt)
+{
+    int rc = 0;
+
+    write_lock(&r->lock);
+    while ( !rangeset_is_empty(r) )
+    {
+        unsigned long consumed = 0;
+        struct range *x = first_range(r);
+
+        rc = cb(x->s, x->e, ctxt, &consumed);
+
+        ASSERT(consumed <= x->e - x->s + 1);
+        x->s += consumed;
+        if ( x->s > x->e )
+            destroy_range(r, x);
+
+        if ( rc )
+            break;
+    }
+    write_unlock(&r->lock);
+
+    return rc;
+}
+
 int rangeset_add_singleton(
     struct rangeset *r, unsigned long s)
 {
diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h
index 1f83b1f44b..583b72bb0c 100644
--- a/xen/include/xen/rangeset.h
+++ b/xen/include/xen/rangeset.h
@@ -70,6 +70,16 @@ int rangeset_report_ranges(
     struct rangeset *r, unsigned long s, unsigned long e,
     int (*cb)(unsigned long s, unsigned long e, void *), void *ctxt);
 
+/*
+ * Note that the consume function can return an error value apart from
+ * -ERESTART, and that no cleanup is performed (ie: the user should call
+ * rangeset_destroy if needed).
+ */
+int rangeset_consume_ranges(struct rangeset *r,
+                            int (*cb)(unsigned long s, unsigned long e,
+                                      void *, unsigned long *c),
+                            void *ctxt);
+
 /* Add/remove/query a single number. */
 int __must_check rangeset_add_singleton(
     struct rangeset *r, unsigned long s);
-- 
2.16.2


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-03-14 14:13 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-14 14:03 [PATCH v9 00/11] vpci: PCI config space emulation Roger Pau Monne
2018-03-14 14:03 ` [PATCH v9 01/11] vpci: introduce basic handlers to trap accesses to the PCI config space Roger Pau Monne
2018-03-14 14:31   ` Jan Beulich
2018-03-15  9:50     ` Roger Pau Monné
2018-03-15 10:23       ` Jan Beulich
2018-03-15 15:21         ` Doug Goldstein
2018-03-14 14:03 ` [PATCH v9 02/11] x86/mmcfg: add handlers for the PVH Dom0 MMCFG areas Roger Pau Monne
2018-03-14 14:04 ` [PATCH v9 03/11] x86/physdev: enable PHYSDEVOP_pci_mmcfg_reserved for PVH Dom0 Roger Pau Monne
2018-03-14 14:04 ` [PATCH v9 04/11] pci: split code to size BARs from pci_add_device Roger Pau Monne
2018-03-14 14:04 ` [PATCH v9 05/11] pci: add support to size ROM BARs to pci_size_mem_bar Roger Pau Monne
2018-03-14 14:04 ` Roger Pau Monne [this message]
2018-03-14 14:04 ` [PATCH v9 07/11] vpci/bars: add handlers to map the BARs Roger Pau Monne
2018-03-14 16:13   ` Jan Beulich
2018-03-15 11:33     ` Roger Pau Monné
2018-03-15 12:41       ` Jan Beulich
2018-03-15 13:59         ` Roger Pau Monné
2018-03-15 14:31           ` Jan Beulich
2018-03-14 14:04 ` [PATCH v9 08/11] x86/pt: mask MSI vectors on unbind Roger Pau Monne
2018-03-14 14:04 ` [PATCH v9 09/11] vpci/msi: add MSI handlers Roger Pau Monne
2018-03-14 16:51   ` Jan Beulich
2018-03-15 11:48     ` Roger Pau Monné
2018-03-15 12:44       ` Jan Beulich
2018-03-15 15:54         ` Roger Pau Monné
2018-03-15 16:19           ` Jan Beulich
2018-03-14 14:04 ` [PATCH v9 10/11] vpci: add a priority parameter to the vPCI register initializer Roger Pau Monne
2018-03-14 14:04 ` [PATCH v9 11/11] vpci/msix: add MSI-X handlers Roger Pau Monne
2018-03-14 17:04   ` Jan Beulich
2018-03-15 12:01     ` Roger Pau Monné
2018-03-15 12:45       ` Jan Beulich
2018-03-15 16:33         ` Roger Pau Monné
2018-03-16  7:36           ` Jan Beulich
2018-03-16 11:03             ` Roger Pau Monné
2018-03-16 11:42               ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180314140408.40947-7-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).