]> xenbits.xensource.com Git - pvdrivers/win/xenbus.git/commitdiff
Add support for XENMEM_remove_from_physmap...
authorPaul Durrant <pdurrant@amazon.com>
Wed, 12 Jul 2023 10:05:39 +0000 (11:05 +0100)
committerPaul Durrant <pdurrant@amazon.com>
Wed, 12 Jul 2023 15:45:45 +0000 (16:45 +0100)
... 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@amazon.com>
include/xen.h
src/xen/memory.c
src/xenbus/gnttab.c
src/xenbus/shared_info.c

index 566e7136cf9803c99b7f5b4f40e8718d9add1f1b..132de21c1b62db91512e3362678ec5917eba8de6 100644 (file)
@@ -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
 
index dfee22cffa0252d1e93183575a76084b111022b2..bc12140404765525c047cd197379a8731c8747c2 100644 (file)
@@ -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
index 1e22a363b77d51c3010c3d8cd613a1957c06290e..af562608b40d6cf66b69d8e18059f55828de2f48 100644 (file)
@@ -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
index b1ad2dcfc3c6fa31a13d33fcea8002ee3d68bfe2..f25e12a1c6891a588d72fa419ae9f0b06ac17b1f 100644 (file)
@@ -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