Skip to contentSkip to conversation

This patch just changes indentation, to make the next patch easier to review.

PATCH In review Julian Vetter 2 participants 8 messages Mar 5 – Mar 11

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 This patch just changes indentation, to make the next patch easier to review.

---
Changes in v4:
- No changes to this patch

---
 xen/arch/x86/hvm/ioreq.c | 58 ++++++++++++++++---------------
 xen/common/ioreq.c       | 74 +++++++++++++++++++++-------------------
 2 files changed, 70 insertions(+), 62 deletions(-)
xen/arch/x86/hvm/ioreq.c +31 -27
index a5fa97e149..355b2ba12c 100644
@@ -125,14 +125,16 @@ static void hvm_unmap_ioreq_gfn(struct ioreq_server *s, bool buf)
 {
     struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
 
-    if ( gfn_eq(iorp->gfn, INVALID_GFN) )
-        return;
+    {
+        if ( gfn_eq(iorp->gfn, INVALID_GFN) )
+            return;
 
-    destroy_ring_for_helper(&iorp->va, iorp->page);
-    iorp->page = NULL;
+        destroy_ring_for_helper(&iorp->va, iorp->page);
+        iorp->page = NULL;
 
-    hvm_free_ioreq_gfn(s, iorp->gfn);
-    iorp->gfn = INVALID_GFN;
+        hvm_free_ioreq_gfn(s, iorp->gfn);
+        iorp->gfn = INVALID_GFN;
+    }
 }
 
 static int hvm_map_ioreq_gfn(struct ioreq_server *s, bool buf)
@@ -141,34 +143,36 @@ static int hvm_map_ioreq_gfn(struct ioreq_server *s, bool buf)
     struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
     int rc;
 
-    if ( iorp->page )
     {
-        /*
-         * If a page has already been allocated (which will happen on
-         * demand if ioreq_server_get_frame() is called), then
-         * mapping a guest frame is not permitted.
-         */
-        if ( gfn_eq(iorp->gfn, INVALID_GFN) )
-            return -EPERM;
-
-        return 0;
-    }
+        if ( iorp->page )
+        {
+            /*
+             * If a page has already been allocated (which will happen on
+             * demand if ioreq_server_get_frame() is called), then
+             * mapping a guest frame is not permitted.
+             */
+            if ( gfn_eq(iorp->gfn, INVALID_GFN) )
+                return -EPERM;
+
+            return 0;
+        }
 
-    if ( d->is_dying )
-        return -EINVAL;
+        if ( d->is_dying )
+            return -EINVAL;
 
-    iorp->gfn = hvm_alloc_ioreq_gfn(s);
+        iorp->gfn = hvm_alloc_ioreq_gfn(s);
 
-    if ( gfn_eq(iorp->gfn, INVALID_GFN) )
-        return -ENOMEM;
+        if ( gfn_eq(iorp->gfn, INVALID_GFN) )
+            return -ENOMEM;
 
-    rc = prepare_ring_for_helper(d, gfn_x(iorp->gfn), &iorp->page,
-                                 &iorp->va);
+        rc = prepare_ring_for_helper(d, gfn_x(iorp->gfn), &iorp->page,
+                                     &iorp->va);
 
-    if ( rc )
-        hvm_unmap_ioreq_gfn(s, buf);
+        if ( rc )
+            hvm_unmap_ioreq_gfn(s, buf);
 
-    return rc;
+        return rc;
+    }
 }
 
 static void hvm_remove_ioreq_gfn(struct ioreq_server *s, bool buf)
xen/common/ioreq.c +39 -35

96 lines not on this page · raw message

Signature · 10 lines
2.51.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#1 lore raw

PATCH v4 2/2 x86/ioreq: Extend ioreq server to support multiple ioreq pages

A single shared ioreq page provides PAGE_SIZE/sizeof(ioreq_t) = 128 slots, limiting HVM guests to 128 vCPUs. To support more vCPUs, the single struct ioreq_page in the ioreq_server is replaced with an ioreq_t pointer backed by a dynamically sized allocation.
For the resource mapping path (XENMEM_acquire_resource), the common ioreq_server_alloc_mfn() allocates nr_ioreq_pages(d) domain heap pages with MEMF_no_refcount and writable type references, then maps them as a single contiguous VA via vmap(). Teardown recovers the pages from the vmap address via vmap_size() and vmap_to_page().
The legacy GFN-mapped path continues to support only a single ioreq page. For domains whose vCPU count exceeds PAGE_SIZE/sizeof(ioreq_t), hvm_map_ioreq_gfn() returns -EOPNOTSUPP. Those domains need to use the resource mapping interface. This also avoids fragmentation when allocating multiple slots from the GFN pool. The GFN path uses vmap() for the Xen-side mapping, consistent with ioreq_server_alloc_mfn(), allowing vmap_to_page() to recover the page during teardown.

---
Changes in v4:
- Dropped the multi-page support for the legacy GFN-mapped path
- When 'nr_ioreq_pages(d) > 1' -> -EOPNOTSUPP
- But now also use vmap(), same as in resource mapping path, so new

    s->ioreq pointer is used in either case

- Mirror exactly what prepare_ring_for_helper/destroy_ring_for_helper is doing except the __map_domain_page_global (replaced by vmap/vunmap)
- Replaced xvzalloc_array() by xvmalloc_array() -> No need to have mfns array zero'ed
- Inverted logic in ioreq_server_alloc_mfn() and ioreq_server_free_mfn() to check for 'if (buf)' (same as in the GFN-mapped path)
- Fixed ioreq_server_alloc_mfn -> Correctly call alloc_domheap_page + get_page_and_type
- Fixed error handling and teardown path to correctly call put_page_alloc_ref + put_page_and_type just like for the bufioreq
- Kept shared_iopage_t so QEMU, varstored, etc. can just reference into it via p->ioreq[cpu_id] -> No modification needed

---
 xen/arch/x86/hvm/ioreq.c | 153 ++++++++++++++++++++++++++++++++----
 xen/common/ioreq.c       | 166 ++++++++++++++++++++++++++++++++-------
 xen/include/xen/ioreq.h  |  10 ++-
 3 files changed, 286 insertions(+), 43 deletions(-)
xen/arch/x86/hvm/ioreq.c +139 -14
index 355b2ba12c..ec4f210768 100644
@@ -15,6 +15,7 @@
 #include <xen/sched.h>
 #include <xen/softirq.h>
 #include <xen/trace.h>
+#include <xen/vmap.h>
 #include <xen/vpci.h>
 
 #include <asm/hvm/emulate.h>
@@ -123,9 +124,10 @@ static void hvm_free_ioreq_gfn(struct ioreq_server *s, gfn_t gfn)
 
 static void hvm_unmap_ioreq_gfn(struct ioreq_server *s, bool buf)
 {
-    struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
-
+    if ( buf )
     {
+        struct ioreq_page *iorp = &s->bufioreq;
+
         if ( gfn_eq(iorp->gfn, INVALID_GFN) )
             return;
 
@@ -134,16 +136,33 @@ static void hvm_unmap_ioreq_gfn(struct ioreq_server *s, bool buf)
 
         hvm_free_ioreq_gfn(s, iorp->gfn);
         iorp->gfn = INVALID_GFN;
+        return;
     }
+
+    if ( gfn_eq(s->ioreq_gfn, INVALID_GFN) )
+        return;
+
+    put_page_and_type(vmap_to_page((void *)s->ioreq));
+    vunmap(s->ioreq);
+    s->ioreq = NULL;
+
+    hvm_free_ioreq_gfn(s, s->ioreq_gfn);
+    s->ioreq_gfn = INVALID_GFN;
 }
 
 static int hvm_map_ioreq_gfn(struct ioreq_server *s, bool buf)
 {
     struct domain *d = s->target;
-    struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
+    gfn_t base_gfn;
+    struct page_info *pg;
+    p2m_type_t p2mt;
+    mfn_t mfn;
     int rc;
 
+    if ( buf )
     {
+        struct ioreq_page *iorp = &s->bufioreq;
+
         if ( iorp->page )
         {
             /*
@@ -173,35 +192,141 @@ static int hvm_map_ioreq_gfn(struct ioreq_server *s, bool buf)
 
         return rc;
     }
+
+    if ( s->ioreq )
+    {
+        /*
+         * If pages have already been allocated (which will happen on
+         * demand if ioreq_server_get_frame() is called), then
+         * mapping a guest frame is not permitted.
+         */
+        if ( gfn_eq(s->ioreq_gfn, INVALID_GFN) )
+            return -EPERM;
+        return 0;
+    }
+
+    /*
+     * The legacy GFN path supports only a single ioreq page. Guests requiring
+     * more ioreq slots must use the resource mapping interface
+     * (XENMEM_acquire_resource).
+     */
+    if ( nr_ioreq_pages(d) > 1 )
+        return -EOPNOTSUPP;
+
+    if ( d->is_dying )
+        return -EINVAL;
+
+    base_gfn = hvm_alloc_ioreq_gfn(s);
+
+    if ( gfn_eq(base_gfn, INVALID_GFN) )
+        return -ENOMEM;
+
+    /*
+     * The page management is the same as prepare_ring_for_helper(), but vmap()
+     * is used instead of __map_domain_page_global() to be consistent with
+     * ioreq_server_alloc_mfn(), which uses vmap() to map potentially multiple
+     * pages. This also allows vmap_to_page() to recover the struct page_info *
+     * from s->ioreq during teardown.
+     */
+    rc = check_get_page_from_gfn(d, base_gfn, false, &p2mt, &pg);
+    if ( rc )
+    {
+        if ( rc == -EAGAIN )
+            rc = -ENOENT;
+        goto fail;
+    }
+
+    if ( !get_page_type(pg, PGT_writable_page) )
+    {
+        put_page(pg);
+        rc = -EINVAL;
+        goto fail;
+    }
+
+    mfn = page_to_mfn(pg);
+    s->ioreq = vmap(&mfn, 1);
+    if ( !s->ioreq )
+    {
+        put_page_and_type(pg);
+        rc = -ENOMEM;
+        goto fail;
+    }
+
+    s->ioreq_gfn = base_gfn;
+    return 0;
+
+ fail:
+    hvm_free_ioreq_gfn(s, base_gfn);
+    return rc;
 }
 
 static void hvm_remove_ioreq_gfn(struct ioreq_server *s, bool buf)
 {
     struct domain *d = s->target;
-    struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
+    struct page_info *pg;
+    void *va;
+    gfn_t gfn;
 
-    if ( gfn_eq(iorp->gfn, INVALID_GFN) )
-        return;
+    if ( buf )
+    {
+        struct ioreq_page *iorp = &s->bufioreq;
+
+        if ( gfn_eq(iorp->gfn, INVALID_GFN) )
+            return;
+
+        gfn = iorp->gfn;
+        pg = iorp->page;
+        va = iorp->va;
+    }
+    else
+    {
+        if ( gfn_eq(s->ioreq_gfn, INVALID_GFN) )
+            return;
 
-    if ( p2m_remove_page(d, iorp->gfn, page_to_mfn(iorp->page), 0) )
+        gfn = s->ioreq_gfn;
+        pg = vmap_to_page(s->ioreq);
+        va = s->ioreq;
+    }
+
+    if ( p2m_remove_page(d, gfn, page_to_mfn(pg), 0) )
         domain_crash(d);
-    clear_page(iorp->va);
+    clear_page(va);
 }
 
 static int hvm_add_ioreq_gfn(struct ioreq_server *s, bool buf)
 {
     struct domain *d = s->target;
-    struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
+    struct page_info *pg;
+    void *va;
+    gfn_t gfn;
     int rc;
 
-    if ( gfn_eq(iorp->gfn, INVALID_GFN) )
-        return 0;
+    if ( buf )
+    {
+        struct ioreq_page *iorp = &s->bufioreq;
+
+        if ( gfn_eq(iorp->gfn, INVALID_GFN) )
+            return 0;
+
+        gfn = iorp->gfn;
+        pg = iorp->page;
+        va = iorp->va;
+    }
+    else
+    {
+        if ( gfn_eq(s->ioreq_gfn, INVALID_GFN) )
+            return 0;
+
+        gfn = s->ioreq_gfn;
+        pg = vmap_to_page(s->ioreq);
+        va = s->ioreq;
+    }
 
-    clear_page(iorp->va);
+    clear_page(va);
 
-    rc = p2m_add_page(d, iorp->gfn, page_to_mfn(iorp->page), 0, p2m_ram_rw);
+    rc = p2m_add_page(d, gfn, page_to_mfn(pg), 0, p2m_ram_rw);
     if ( rc == 0 )
-        paging_mark_pfn_dirty(d, _pfn(gfn_x(iorp->gfn)));
+        paging_mark_pfn_dirty(d, _pfn(gfn_x(gfn)));
 
     return rc;
 }
xen/common/ioreq.c +138 -28

256 lines not on this page · raw message

xen/include/xen/ioreq.h +9 -1
index e86f0869fa..41650a59ca 100644
@@ -19,9 +19,16 @@
 #ifndef __XEN_IOREQ_H__
 #define __XEN_IOREQ_H__
 
+#include <xen/macros.h>
 #include <xen/sched.h>
 
 #include <public/hvm/dm_op.h>
+#include <public/hvm/ioreq.h>
+
+static inline unsigned int nr_ioreq_pages(const struct domain *d)
+{
+    return DIV_ROUND_UP(d->max_vcpus, PAGE_SIZE / sizeof(ioreq_t));
+}
 
 struct ioreq_page {
     gfn_t gfn;
@@ -45,7 +52,8 @@ struct ioreq_server {
     /* Lock to serialize toolstack modifications */
     spinlock_t             lock;
 
-    struct ioreq_page      ioreq;
+    ioreq_t                *ioreq;
+    gfn_t                  ioreq_gfn;
     struct list_head       ioreq_vcpu_list;
     struct ioreq_page      bufioreq;
 
Signature · 10 lines
2.51.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#2 lore raw

Re: [PATCH v4 2/2] x86/ioreq: Extend ioreq server to support multiple ioreq pages

xen/include/xen/ioreq.h struct ioreq_server { · line 58

Quoted 9 lines · Julian Vetter
xen/include/xen/ioreq.h +2 -1
@@ -45,7 +52,8 @@ struct ioreq_server {
     /* Lock to serialize toolstack modifications */
     spinlock_t             lock;
 
-    struct ioreq_page      ioreq;
+    ioreq_t                *ioreq;
+    gfn_t                  ioreq_gfn;
     struct list_head       ioreq_vcpu_list;
     struct ioreq_page      bufioreq;

This change in data arrangement should in principle be independent of the step to supporting multiple pages. Hence it should be possible to separate out. Problem being that just by looking here and at hvm_{,un}map_ioreq_gfn() I can't conclude how you get away without the "page" field that struct ioreq_page had. If you can get away without, it's not quite clear why the field exists in the first place. If it's not needed, dropping it would be yet another separate, prereq change. At which point the remaining pair of fields could continue to be used, i.e. the change above then wouldn't be needed; va could be renamed if need be, and its type changed.

And if the "page" field is still needed, then even more so you would imo want to retain the present data layout.

In any event, if at all possible a goal imo ought to be to avoid duplication of logic, like what is happening in the two named functions. I.e. preferably the bufio case would continue to be as similar as possible, just known to be single-page.

Jan

#3 lore raw

Re: [PATCH v4 2/2] x86/ioreq: Extend ioreq server to support multiple ioreq pages

Quoted 5 lines · Jan Beulich
Quoted 4 lines · Julian Vetter
xen/include/xen/ioreq.h +0 -0
@@ -45,7 +52,8 @@ struct ioreq_server {
      /* Lock to serialize toolstack modifications */
      spinlock_t             lock;
 
Quoted 16 lines

xen/include/xen/ioreq.h struct ioreq_server { · line 58

Quoted 5 lines
xen/include/xen/ioreq.h +2 -1
-    struct ioreq_page      ioreq;
+    ioreq_t                *ioreq;
+    gfn_t                  ioreq_gfn;
      struct list_head       ioreq_vcpu_list;
      struct ioreq_page      bufioreq;

This change in data arrangement should in principle be independent of the step to supporting multiple pages. Hence it should be possible to separate out. Problem being that just by looking here and at hvm_{,un}map_ioreq_gfn() I can't conclude how you get away without the "page" field that struct ioreq_page had. If you can get away without, it's not quite clear why the field exists in the first place. If it's not needed, dropping it would be yet another separate, prereq change. At which point the remaining pair of fields could continue to be used, i.e. the change above then wouldn't be needed; va could be renamed if need be, and its type changed.

Thank you again Jan for your feedback! I don't need the page anymore. When I use vmap(), I don't need to keep track of it, because during teardown, I can recover it via vmap_to_page(). Currently it's necessary because in destroy_ring_for_helper we need the page, to be destroyed. But I see now, on X86 the map_domain_page_global called from prepare_ring_for_helper actually does vmap(&mfn, 1). So the page is also from the vmap range. So for the teardown I assume a vmap_to_page() could be used as well. But I also see there is a special case, if NDEBUG=1, map_domain_page_global short-circuits to mfn_to_virt() for low MFNs (putting the VA in the directmap range) and bypassing vmap. In that case

vmap_to_page() would not work. So, this would be really messy. I would rather switch the bufioreq also to an explicitly vmap()'ed page, then we could remove the page pointer and both cases would be aligned again.

Quoted 7 lines

And if the "page" field is still needed, then even more so you would imo want to retain the present data layout.

In any event, if at all possible a goal imo ought to be to avoid duplication of logic, like what is happening in the two named functions. I.e. preferably the bufio case would continue to be as similar as possible, just known to be single-page.

Yes, I agree. Thank you for you insight. I will have a look again how I could align them as much as possible.

Julian

Quoted 2 lines

Jan

--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#4 lore raw

Re: [PATCH v4 2/2] x86/ioreq: Extend ioreq server to support multiple ioreq pages

Quoted 33 lines · Julian Vetter
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Julian Vetter
xen/include/xen/ioreq.h +0 -0
@@ -45,7 +52,8 @@ struct ioreq_server {
      /* Lock to serialize toolstack modifications */
      spinlock_t             lock;
 
Quoted 15 lines

xen/include/xen/ioreq.h struct ioreq_server { · line 58

Quoted 5 lines
xen/include/xen/ioreq.h +2 -1
-    struct ioreq_page      ioreq;
+    ioreq_t                *ioreq;
+    gfn_t                  ioreq_gfn;
      struct list_head       ioreq_vcpu_list;
      struct ioreq_page      bufioreq;

This change in data arrangement should in principle be independent of the step to supporting multiple pages. Hence it should be possible to separate out. Problem being that just by looking here and at hvm_{,un}map_ioreq_gfn() I can't conclude how you get away without the "page" field that struct ioreq_page had. If you can get away without, it's not quite clear why the field exists in the first place. If it's not needed, dropping it would be yet another separate, prereq change. At which point the remaining pair of fields could continue to be used, i.e. the change above then wouldn't be needed; va could be renamed if need be, and its type changed.

Thank you again Jan for your feedback! I don't need the page anymore. When I use vmap(), I don't need to keep track of it, because during teardown, I can recover it via vmap_to_page(). Currently it's necessary because in destroy_ring_for_helper we need the page, to be destroyed. But I see now, on X86 the map_domain_page_global called from prepare_ring_for_helper actually does vmap(&mfn, 1). So the page is also from the vmap range. So for the teardown I assume a vmap_to_page() could be used as well. But I also see there is a special case, if NDEBUG=1, map_domain_page_global short-circuits to mfn_to_virt() for low MFNs (putting the VA in the directmap range) and bypassing vmap. In that case

Quoted 3 lines

vmap_to_page() would not work. So, this would be really messy. I would rather switch the bufioreq also to an explicitly vmap()'ed page, then we could remove the page pointer and both cases would be aligned again.

That's an option. Yet are you aware of domain_page_map_to_mfn()? Perhaps that's what you want to switch to using in the patch removing the "page" field. To then, conditionally or uniformly, switch to vmap_to_{mfn,page}() when doing the multi-page work in the subsequent patch.

Jan

#5 lore raw

Re: [PATCH v4 2/2] x86/ioreq: Extend ioreq server to support multiple ioreq pages

Quoted 34 lines · Jan Beulich
Quoted 33 lines · Julian Vetter
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Julian Vetter
xen/include/xen/ioreq.h +0 -0
@@ -45,7 +52,8 @@ struct ioreq_server {
       /* Lock to serialize toolstack modifications */
       spinlock_t             lock;
 
Quoted 15 lines

xen/include/xen/ioreq.h struct ioreq_server { · line 58

Quoted 5 lines
xen/include/xen/ioreq.h +2 -1
-    struct ioreq_page      ioreq;
+    ioreq_t                *ioreq;
+    gfn_t                  ioreq_gfn;
       struct list_head       ioreq_vcpu_list;
       struct ioreq_page      bufioreq;

This change in data arrangement should in principle be independent of the step to supporting multiple pages. Hence it should be possible to separate out. Problem being that just by looking here and at hvm_{,un}map_ioreq_gfn() I can't conclude how you get away without the "page" field that struct ioreq_page had. If you can get away without, it's not quite clear why the field exists in the first place. If it's not needed, dropping it would be yet another separate, prereq change. At which point the remaining pair of fields could continue to be used, i.e. the change above then wouldn't be needed; va could be renamed if need be, and its type changed.

Thank you again Jan for your feedback! I don't need the page anymore. When I use vmap(), I don't need to keep track of it, because during teardown, I can recover it via vmap_to_page(). Currently it's necessary because in destroy_ring_for_helper we need the page, to be destroyed. But I see now, on X86 the map_domain_page_global called from prepare_ring_for_helper actually does vmap(&mfn, 1). So the page is also from the vmap range. So for the teardown I assume a vmap_to_page() could be used as well. But I also see there is a special case, if NDEBUG=1, map_domain_page_global short-circuits to mfn_to_virt() for low MFNs (putting the VA in the directmap range) and bypassing vmap. In that case

Quoted 8 lines
Quoted 3 lines

vmap_to_page() would not work. So, this would be really messy. I would rather switch the bufioreq also to an explicitly vmap()'ed page, then we could remove the page pointer and both cases would be aligned again.

That's an option. Yet are you aware of domain_page_map_to_mfn()? Perhaps that's what you want to switch to using in the patch removing the "page" field. To then, conditionally or uniformly, switch to vmap_to_{mfn,page}() when doing the multi-page work in the subsequent patch.

Yes, thank you. I saw this function, but I was wondering whether it's a good idea to wrap the va in two translation functions like:

struct page_info *page = mfn_to_page(domain_page_map_to_mfn(va));

and then calling destroy_ring_for_helper() with it. But I will have a look, and this way we would be again aligned between the two cases. So, maybe it's the cleanest way.

Julian

Quoted 2 lines

Jan

--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#6 lore raw

Re: [PATCH v4 2/2] x86/ioreq: Extend ioreq server to support multiple ioreq pages

Quoted 44 lines · Julian Vetter
Quoted 34 lines · Jan Beulich
Quoted 33 lines · Julian Vetter
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Julian Vetter
xen/include/xen/ioreq.h +0 -0
@@ -45,7 +52,8 @@ struct ioreq_server {
       /* Lock to serialize toolstack modifications */
       spinlock_t             lock;
 
Quoted 15 lines

xen/include/xen/ioreq.h struct ioreq_server { · line 58

Quoted 5 lines
xen/include/xen/ioreq.h +2 -1
-    struct ioreq_page      ioreq;
+    ioreq_t                *ioreq;
+    gfn_t                  ioreq_gfn;
       struct list_head       ioreq_vcpu_list;
       struct ioreq_page      bufioreq;

This change in data arrangement should in principle be independent of the step to supporting multiple pages. Hence it should be possible to separate out. Problem being that just by looking here and at hvm_{,un}map_ioreq_gfn() I can't conclude how you get away without the "page" field that struct ioreq_page had. If you can get away without, it's not quite clear why the field exists in the first place. If it's not needed, dropping it would be yet another separate, prereq change. At which point the remaining pair of fields could continue to be used, i.e. the change above then wouldn't be needed; va could be renamed if need be, and its type changed.

Thank you again Jan for your feedback! I don't need the page anymore. When I use vmap(), I don't need to keep track of it, because during teardown, I can recover it via vmap_to_page(). Currently it's necessary because in destroy_ring_for_helper we need the page, to be destroyed. But I see now, on X86 the map_domain_page_global called from prepare_ring_for_helper actually does vmap(&mfn, 1). So the page is also from the vmap range. So for the teardown I assume a vmap_to_page() could be used as well. But I also see there is a special case, if NDEBUG=1, map_domain_page_global short-circuits to mfn_to_virt() for low MFNs (putting the VA in the directmap range) and bypassing vmap. In that case

Quoted 8 lines
Quoted 3 lines

vmap_to_page() would not work. So, this would be really messy. I would rather switch the bufioreq also to an explicitly vmap()'ed page, then we could remove the page pointer and both cases would be aligned again.

That's an option. Yet are you aware of domain_page_map_to_mfn()? Perhaps that's what you want to switch to using in the patch removing the "page" field. To then, conditionally or uniformly, switch to vmap_to_{mfn,page}() when doing the multi-page work in the subsequent patch.

Quoted 4 lines

Yes, thank you. I saw this function, but I was wondering whether it's a good idea to wrap the va in two translation functions like:

struct page_info *page = mfn_to_page(domain_page_map_to_mfn(va));

There's no fundamental problem with that (we have similar constructs elsewhere, I think), but ...

Quoted 3 lines

and then calling destroy_ring_for_helper() with it. But I will have a look, and this way we would be again aligned between the two cases. So, maybe it's the cleanest way.

... does destroy_ring_for_helper() actually need to have the page passed in? It's prepare_ring_for_helper() which calls __map_domain_page_global(), so destroy_ring_for_helper() could well obtain the MFN / page itself (using the above construct). VM event and vPL011 code also only ever use the page pointer supplied by prepare_ring_for_helper() to pass into destroy_ring_for_helper().

Jan