[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/3] Add support for XENMEM_remove_from_physmap...



From: Paul Durrant <pdurrant@xxxxxxxxxx>

... and make use of it to remove shared_info and grant table pages from the
P2M when we're closing down. This makes sure we don't leave such pages lying
around in the Xen platform PCI device's BAR.

NOTE: Now that we're making GnttabUnmap() actually do something, tidy up the
      implementation of GnttabMap() so it is aligned.

Signed-off-by: Paul Durrant <pdurrant@xxxxxxxxxx>
---
 include/xen.h            |  7 +++++++
 src/xen/memory.c         | 29 +++++++++++++++++++++++++++++
 src/xenbus/gnttab.c      | 22 ++++++++++++++--------
 src/xenbus/shared_info.c |  5 ++---
 4 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/include/xen.h b/include/xen.h
index 566e7136cf98..132de21c1b62 100644
--- a/include/xen.h
+++ b/include/xen.h
@@ -128,6 +128,13 @@ MemoryAddToPhysmap(
     IN  ULONG_PTR   Offset
     );
 
+__checkReturn
+XEN_API
+NTSTATUS
+MemoryRemoveFromPhysmap(
+    IN  PFN_NUMBER  Pfn
+    );
+
 #define PAGE_ORDER_4K   0
 #define PAGE_ORDER_2M   9
 
diff --git a/src/xen/memory.c b/src/xen/memory.c
index dfee22cffa02..bc1214040476 100644
--- a/src/xen/memory.c
+++ b/src/xen/memory.c
@@ -81,6 +81,35 @@ fail1:
     return status;
 }
 
+__checkReturn
+XEN_API
+NTSTATUS
+MemoryRemoveFromPhysmap(
+    IN  PFN_NUMBER                  Pfn
+    )
+{
+    struct xen_remove_from_physmap  op;
+    LONG_PTR                        rc;
+    NTSTATUS                        status;
+
+    op.domid = DOMID_SELF;
+    op.gpfn = (xen_pfn_t)Pfn;
+
+    rc = MemoryOp(XENMEM_remove_from_physmap, &op);
+
+    if (rc < 0) {
+        ERRNO_TO_STATUS(-rc, status);
+        goto fail1;
+    }
+
+    return STATUS_SUCCESS;
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
+}
+
 __checkReturn
 XEN_API
 ULONG
diff --git a/src/xenbus/gnttab.c b/src/xenbus/gnttab.c
index 1e22a363b77d..af562608b40d 100644
--- a/src/xenbus/gnttab.c
+++ b/src/xenbus/gnttab.c
@@ -163,7 +163,7 @@ GnttabExpand(
 fail3:
     Error("fail3\n");
 
-    // Not clear what to do here
+    (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Address.QuadPart >> 
PAGE_SHIFT));
 
 fail2:
     Error("fail2\n");
@@ -182,12 +182,14 @@ GnttabMap(
     )
 {
     LONG                        Index;
-    PHYSICAL_ADDRESS            Address;
     NTSTATUS                    status;
 
-    Address = Context->Address;
-
     for (Index = 0; Index <= Context->FrameIndex; Index++) {
+        PHYSICAL_ADDRESS    Address;
+
+        Address = Context->Address;
+        Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
+
         status = MemoryAddToPhysmap((PFN_NUMBER)(Address.QuadPart >> 
PAGE_SHIFT),
                                     XENMAPSPACE_grant_table,
                                     Index);
@@ -198,8 +200,6 @@ GnttabMap(
                   Index,
                   Address.HighPart,
                   Address.LowPart);
-
-        Address.QuadPart += PAGE_SIZE;
     }
 }
 
@@ -210,12 +210,18 @@ GnttabUnmap(
 {
     LONG                        Index;
 
-    // Not clear what to do here
+    for (Index = Context->FrameIndex; Index >= 0; --Index) {
+        PHYSICAL_ADDRESS    Address;
+
+        Address = Context->Address;
+        Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
+
+        (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Address.QuadPart >> 
PAGE_SHIFT));
 
-    for (Index = Context->FrameIndex; Index >= 0; --Index)
         LogPrintf(LOG_LEVEL_INFO,
                   "GNTTAB: UNMAP XENMAPSPACE_grant_table[%d]\n",
                   Index);
+    }
 }
 
 static VOID
diff --git a/src/xenbus/shared_info.c b/src/xenbus/shared_info.c
index b1ad2dcfc3c6..f25e12a1c689 100644
--- a/src/xenbus/shared_info.c
+++ b/src/xenbus/shared_info.c
@@ -477,12 +477,11 @@ SharedInfoUnmap(
     IN  PXENBUS_SHARED_INFO_CONTEXT Context
     )
 {
-    UNREFERENCED_PARAMETER(Context);
-
     LogPrintf(LOG_LEVEL_INFO,
               "SHARED_INFO: UNMAP XENMAPSPACE_shared_info\n");
 
-    // Not clear what to do here
+
+    (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Context->Address.QuadPart >> 
PAGE_SHIFT));
 }
 
 static VOID
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.