Skip to contentSkip to conversation

libxc: fix xc_translate_foreign_address()

PATCH In review Razvan Cojocaru 3 participants 8 messages Apr 5, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libxc: fix xc_translate_foreign_address()

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).

---
Changes since V1:
- Added header comment.

---
 tools/libxc/include/xenctrl.h | 3 +++
 tools/libxc/xc_pagetab.c      | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +3 -0
index 2d97d36..ca4bb6c 100644
@@ -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.
tools/libxc/xc_pagetab.c +1 -1
index 92eebd6..db25c20 100644
@@ -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;
         }
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

Hi Razvan,

Quoted 7 lines · Razvan Cojocaru

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).

He is the author of the patch, correct? If so, he should be the author as well (e.g From: ...).

Also, you may want to add your signed-off-by here.

Cheers,

Quoted 36 lines

---
Changes since V1:
- Added header comment.

---
 tools/libxc/include/xenctrl.h | 3 +++
 tools/libxc/xc_pagetab.c      | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +3 -0
index 2d97d36..ca4bb6c 100644
@@ -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.
tools/libxc/xc_pagetab.c +1 -1
index 92eebd6..db25c20 100644
@@ -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;
         }
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Hello Julien,

Quoted 7 lines · Razvan Cojocaru
Quoted 6 lines

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).

Quoted 6 lines
Quoted 1 line

He is the author of the patch, correct? If so, he should be the author as well (e.g From: ...).

Also, you may want to add your signed-off-by here.

Alright, I can add my Signed-off for the comment (though it's not much work, hence my initial reluctance :) ) in which case I suppose it's alright to resend V3 from my address.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by
#3 lore raw
In reply to Julien Grall
Quoted 9 lines · Julien Grall

Hi Razvan,

Quoted 6 lines · Razvan Cojocaru

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).

Quoted 7 lines
Quoted 1 line

He is the author of the patch, correct? If so, he should be the author as well (e.g From: ...).

Also, you may want to add your signed-off-by here.

Julien, if you agree to let this patch go in 4.9. I can fix those up.

Razvan, please tell me what you want me to do.

Code-wise:

Quoted 30 lines

Cheers,

Quoted 28 lines

---
Changes since V1:
- Added header comment.

---
 tools/libxc/include/xenctrl.h | 3 +++
 tools/libxc/xc_pagetab.c      | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +3 -0
index 2d97d36..ca4bb6c 100644
@@ -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.
tools/libxc/xc_pagetab.c +0 -0
index 92eebd6..db25c20 100644
@@ -93,7 +93,7 @@ unsigned long xc_translate_foreign_address(xc_interface *xch, uint32_t dom,
             return 0;
Quoted 11 lines
Quoted 8 lines
tools/libxc/xc_pagetab.c +1 -1
         }
         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;
         }
Signature · 1 line
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 18 lines · Wei Liu
Quoted 9 lines · Julien Grall

Hi Razvan,

Quoted 6 lines · Razvan Cojocaru

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).

Quoted 7 lines
Quoted 1 line

He is the author of the patch, correct? If so, he should be the author as well (e.g From: ...).

Also, you may want to add your signed-off-by here.

Quoted 7 lines

Julien, if you agree to let this patch go in 4.9. I can fix those up.

Razvan, please tell me what you want me to do.

Code-wise:

Whatever you'd like is fine with me. I don't care about my Signed-off-by either way, but if the header comment header I've added justifies it then please feel free to add:

in which case I suppose you won't need to also modify the From:.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 25 lines · Razvan Cojocaru
Quoted 24 lines · Wei Liu
Quoted 9 lines · Julien Grall

Hi Razvan,

Quoted 6 lines · Razvan Cojocaru

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).

Quoted 7 lines
Quoted 1 line

He is the author of the patch, correct? If so, he should be the author as well (e.g From: ...).

Also, you may want to add your signed-off-by here.

Julien, if you agree to let this patch go in 4.9. I can fix those up.

Razvan, please tell me what you want me to do.

Code-wise:

Quoted 8 lines
Quoted 1 line

Whatever you'd like is fine with me. I don't care about my Signed-off-by either way, but if the header comment header I've added justifies it then please feel free to add:

Yes.

Quoted 2 lines

in which case I suppose you won't need to also modify the From:.

Who should be the author of this patch? I can't make a decision on your behalf...

Wei.

Quoted 3 lines

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw
Quoted 35 lines · Wei Liu
Quoted 25 lines · Razvan Cojocaru
Quoted 24 lines · Wei Liu
Quoted 9 lines · Julien Grall

Hi Razvan,

Quoted 6 lines · Razvan Cojocaru

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).

Quoted 7 lines
Quoted 1 line

He is the author of the patch, correct? If so, he should be the author as well (e.g From: ...).

Also, you may want to add your signed-off-by here.

Julien, if you agree to let this patch go in 4.9. I can fix those up.

Razvan, please tell me what you want me to do.

Code-wise:

Quoted 8 lines
Quoted 1 line

Whatever you'd like is fine with me. I don't care about my Signed-off-by either way, but if the header comment header I've added justifies it then please feel free to add:

Quoted 7 lines

Yes.

Quoted 2 lines

in which case I suppose you won't need to also modify the From:.

Who should be the author of this patch? I can't make a decision on your behalf...

Sorry, the author should definitely be Cristian-Bogdan Sirb <[email protected]>. He discovered and fixed the issue, I merely added the header comment.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw
In reply to Wei Liu
Quoted 12 lines · Wei Liu
Quoted 11 lines · Julien Grall

Hi Razvan,

Quoted 7 lines · Razvan Cojocaru

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).

Quoted 7 lines
Quoted 5 lines

He is the author of the patch, correct? If so, he should be the author as well (e.g From: ...).

Also, you may want to add your signed-off-by here.

Julien, if you agree to let this patch go in 4.9. I can fix those up.

Cheers,

Quoted 49 lines

Razvan, please tell me what you want me to do.

Code-wise:

Quoted 41 lines

Cheers,

Quoted 28 lines

---
Changes since V1:
- Added header comment.

---
 tools/libxc/include/xenctrl.h | 3 +++
 tools/libxc/xc_pagetab.c      | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +3 -0
index 2d97d36..ca4bb6c 100644
@@ -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.
tools/libxc/xc_pagetab.c +0 -0
index 92eebd6..db25c20 100644

tools/libxc/xc_pagetab.c unsigned long xc_translate_foreign_address(xc_interface *xch, uint32_t dom, · line 99

Quoted 8 lines
tools/libxc/xc_pagetab.c +1 -1
@@ -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;
         }

--
Julien Grall

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel