]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
libxc: fix xc_translate_foreign_address()
authorCristian-Bogdan Sirb <csirb@bitdefender.com>
Wed, 5 Apr 2017 14:53:53 +0000 (17:53 +0300)
committerWei Liu <wei.liu2@citrix.com>
Thu, 6 Apr 2017 09:37:24 +0000 (10:37 +0100)
Currently xc_translate_foreign_address() only checks for the PSE bit on
level 2 entries (that's 2 MB pages on x64 and 32-bit with PAE, and 4 MB
pages on 32-bit). But the Linux kernel sometimes uses 1 GB pages. This
patch fixes that, by checking the PSE bit on level 3 entries if the guest
has 4 translation levels (that means 64-bit guests only).

Signed-off-by: Cristian-Bogdan Sirb <csirb@bitdefender.com>
Signed-off-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Release-acked-by: Julien Grall <julien.grall@arm.com>
tools/libxc/include/xenctrl.h
tools/libxc/xc_pagetab.c

index e2b4cc15fd2c9dc94847f02c3f14814b93f4b300..01f8dfe51365b70bbf7918fa0d3f2fe56bf8d3b4 100644 (file)
@@ -1460,6 +1460,9 @@ int xc_lockprof_query(xc_interface *xch,
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
 
 /**
+ * Avoid using this function, as it does not work for all cases (such
+ * as 4M superpages, or guests using PSE36). Only used for debugging.
+ *
  * Translates a virtual address in the context of a given domain and
  * vcpu returning the GFN containing the address (that is, an MFN for 
  * PV guests, a PFN for HVM guests).  Returns 0 for failure.
index 92eebd6882ae09c4b1a14b226bd3cdb4d9ffa8b4..db25c20247573a3c638d7725c976433221a40141 100644 (file)
@@ -93,7 +93,7 @@ unsigned long xc_translate_foreign_address(xc_interface *xch, uint32_t dom,
             return 0;
         }
         paddr = pte & 0x000ffffffffff000ull;
-        if (level == 2 && (pte & PTE_PSE)) {
+        if ((level == 2 || (level == 3 && pt_levels == 4)) && (pte & PTE_PSE)) {
             mask = ((mask ^ ~-mask) >> 1); /* All bits below first set bit */
             return ((paddr & ~mask) | (virt & mask)) >> PAGE_SHIFT;
         }