WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] xc_map_foreign_pages(), a convenient alte

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xc_map_foreign_pages(), a convenient alternative to xc_map_foreign_batch()
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 07 Sep 2007 09:14:03 -0700
Delivery-date: Fri, 07 Sep 2007 09:22:26 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1189161550 -3600
# Node ID 9071521d48646d247efafcf230ea0a4a2b6f0efa
# Parent  0c14d0bf369eca202a4b35af8c9b23f47a2f1fec
xc_map_foreign_pages(), a convenient alternative to xc_map_foreign_batch()

xc_map_foreign_batch() can succeed partially.  It is awkward to use
when you're only interested in complete success.  Provide new
xc_map_foreign_pages() convenience function for that kind of use.
Also convert two obvious calls to use it.

Signed-off-by: Markus Armbruster <armbru@xxxxxxxxxx>
---
 tools/ioemu/hw/cirrus_vga.c |    2 +-
 tools/ioemu/vl.c            |    2 +-
 tools/libxc/xc_misc.c       |   33 +++++++++++++++++++++++++++++++++
 tools/libxc/xenctrl.h       |    8 ++++++++
 tools/xenfb/xenfb.c         |   10 ++--------
 5 files changed, 45 insertions(+), 10 deletions(-)

diff -r 0c14d0bf369e -r 9071521d4864 tools/ioemu/hw/cirrus_vga.c
--- a/tools/ioemu/hw/cirrus_vga.c       Fri Sep 07 11:30:18 2007 +0100
+++ b/tools/ioemu/hw/cirrus_vga.c       Fri Sep 07 11:39:10 2007 +0100
@@ -2565,7 +2565,7 @@ static void *set_vram_mapping(unsigned l
         return NULL;
     }
 
-    vram_pointer = xc_map_foreign_batch(xc_handle, domid,
+    vram_pointer = xc_map_foreign_pages(xc_handle, domid,
                                         PROT_READ|PROT_WRITE,
                                         extent_start, nr_extents);
     if (vram_pointer == NULL) {
diff -r 0c14d0bf369e -r 9071521d4864 tools/ioemu/vl.c
--- a/tools/ioemu/vl.c  Fri Sep 07 11:30:18 2007 +0100
+++ b/tools/ioemu/vl.c  Fri Sep 07 11:39:10 2007 +0100
@@ -6948,7 +6948,7 @@ static void qemu_remap_bucket(struct map
         j = ((i + BITS_PER_LONG) > (MCACHE_BUCKET_SIZE >> PAGE_SHIFT)) ?
             (MCACHE_BUCKET_SIZE >> PAGE_SHIFT) % BITS_PER_LONG : BITS_PER_LONG;
         while (j > 0)
-            word = (word << 1) | !(pfns[i + --j] & 0xF0000000UL);
+            word = (word << 1) | (((pfns[i + --j] >> 28) & 0xf) != 0xf);
         entry->valid_mapping[i / BITS_PER_LONG] = word;
     }
 }
diff -r 0c14d0bf369e -r 9071521d4864 tools/libxc/xc_misc.c
--- a/tools/libxc/xc_misc.c     Fri Sep 07 11:30:18 2007 +0100
+++ b/tools/libxc/xc_misc.c     Fri Sep 07 11:39:10 2007 +0100
@@ -224,6 +224,39 @@ int xc_hvm_set_pci_link_route(
     unlock_pages(&arg, sizeof(arg));
 
     return rc;
+}
+
+void *xc_map_foreign_pages(int xc_handle, uint32_t dom, int prot,
+                           const xen_pfn_t *arr, int num)
+{
+    xen_pfn_t *pfn;
+    void *res;
+    int i;
+
+    pfn = malloc(num * sizeof(*pfn));
+    if (!pfn)
+        return NULL;
+    memcpy(pfn, arr, num * sizeof(*pfn));
+
+    res = xc_map_foreign_batch(xc_handle, dom, prot, pfn, num);
+    if (res) {
+        for (i = 0; i < num; i++) {
+            if ((pfn[i] & 0xF0000000UL) == 0xF0000000UL) {
+                /*
+                 * xc_map_foreign_batch() doesn't give us an error
+                 * code, so we have to make one up.  May not be the
+                 * appropriate one.
+                 */
+                errno = EINVAL;
+                munmap(res, num * PAGE_SIZE);
+                res = NULL;
+                break;
+            }
+        }
+    }
+
+    free(pfn);
+    return res;
 }
 
 /*
diff -r 0c14d0bf369e -r 9071521d4864 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h     Fri Sep 07 11:30:18 2007 +0100
+++ b/tools/libxc/xenctrl.h     Fri Sep 07 11:39:10 2007 +0100
@@ -646,6 +646,14 @@ void *xc_map_foreign_range(int xc_handle
                             int size, int prot,
                             unsigned long mfn );
 
+void *xc_map_foreign_pages(int xc_handle, uint32_t dom, int prot,
+                           const xen_pfn_t *arr, int num );
+
+/**
+ * Like xc_map_foreign_pages(), except it can succeeed partially.
+ * When a page cannot be mapped, its PFN in @arr is or'ed with
+ * 0xF0000000 to indicate the error.
+ */
 void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
                            xen_pfn_t *arr, int num );
 
diff -r 0c14d0bf369e -r 9071521d4864 tools/xenfb/xenfb.c
--- a/tools/xenfb/xenfb.c       Fri Sep 07 11:30:18 2007 +0100
+++ b/tools/xenfb/xenfb.c       Fri Sep 07 11:39:10 2007 +0100
@@ -398,21 +398,15 @@ static int xenfb_map_fb(struct xenfb_pri
        if (!pgmfns || !fbmfns)
                goto out;
 
-       /*
-        * Bug alert: xc_map_foreign_batch() can fail partly and
-        * return a non-null value.  This is a design flaw.  When it
-        * happens, we happily continue here, and later crash on
-        * access.
-        */
        xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
-       map = xc_map_foreign_batch(xenfb->xc, domid,
+       map = xc_map_foreign_pages(xenfb->xc, domid,
                                   PROT_READ, pgmfns, n_fbdirs);
        if (map == NULL)
                goto out;
        xenfb_copy_mfns(mode, n_fbmfns, fbmfns, map);
        munmap(map, n_fbdirs * XC_PAGE_SIZE);
 
-       xenfb->pub.pixels = xc_map_foreign_batch(xenfb->xc, domid,
+       xenfb->pub.pixels = xc_map_foreign_pages(xenfb->xc, domid,
                                PROT_READ | PROT_WRITE, fbmfns, n_fbmfns);
        if (xenfb->pub.pixels == NULL)
                goto out;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xc_map_foreign_pages(), a convenient alternative to xc_map_foreign_batch(), Xen patchbot-unstable <=