Skip to contentSkip to conversation

x86/mm: Add mem access rights to NPT

PATCH Superseded Alexandru Isaila 5 participants 21 messages May 11, 2018 – Jul 5, 2018

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 x86/mm: Add mem access rights to NPT

From: Isaila Alexandru <[email protected]>

This patch adds access rights for the NPT pages. The access rights are saved in bits 59:56 of pte that are manipulated through p2m_set_access() and p2m_get_access() functions.
The patch follows the ept logic.

Note: It was tested with xen-access write

---
 xen/arch/x86/mm/mem_access.c      |  4 +-
 xen/arch/x86/mm/p2m-pt.c          | 85 ++++++++++++++++++++++++++++++++-------
 xen/include/asm-x86/mem_access.h  |  2 +-
 xen/include/asm-x86/x86_64/page.h |  9 +++++
 4 files changed, 84 insertions(+), 16 deletions(-)
xen/arch/x86/mm/mem_access.c +3 -1
index c0cd017..6fb7809 100644
@@ -221,7 +221,9 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,
         {
             req->u.mem_access.flags |= MEM_ACCESS_GLA_VALID;
             req->u.mem_access.gla = gla;
-
+        }
+        if ( npfec.gla_valid || cpu_has_svm )
+        {
             if ( npfec.kind == npfec_kind_with_gla )
                 req->u.mem_access.flags |= MEM_ACCESS_FAULT_WITH_GLA;
             else if ( npfec.kind == npfec_kind_in_gpt )
xen/arch/x86/mm/p2m-pt.c +71 -14

205 lines not on this page · raw message

xen/include/asm-x86/mem_access.h +1 -1
index 4043c9f..34f2c07 100644
@@ -46,7 +46,7 @@ bool p2m_mem_access_emulate_check(struct vcpu *v,
 /* Sanity check for mem_access hardware support */
 static inline bool p2m_mem_access_sanity_check(struct domain *d)
 {
-    return is_hvm_domain(d) && cpu_has_vmx && hap_enabled(d);
+    return is_hvm_domain(d) && hap_enabled(d);
 }
 
 #endif /*__ASM_X86_MEM_ACCESS_H__ */
xen/include/asm-x86/x86_64/page.h +9 -0
index 05a0334..d5f5418 100644
@@ -159,6 +159,15 @@ static inline intpte_t put_pte_flags(unsigned int x)
  */
 #define _PAGE_GUEST_KERNEL (1U<<12)
 
+/*
+ * Bits 19:16 of a 24-bit flag mask are used to store p2m_access_t.
+ * This corresponds to bits 59:56 of a pte
+ */
+#define PAGE_ACCESS_START          59
+#define PAGE_ACCESS_LEN            4
+#define PAGE_ACCESS_MASK           ((1UL << PAGE_ACCESS_LEN) - 1)
+#define PAGE_ACCESS_BITFIELD_MASK  (PAGE_ACCESS_MASK << PAGE_ACCESS_START)
+
 #define PAGE_HYPERVISOR_RO      (__PAGE_HYPERVISOR_RO      | _PAGE_GLOBAL)
 #define PAGE_HYPERVISOR_RW      (__PAGE_HYPERVISOR_RW      | _PAGE_GLOBAL)
 #define PAGE_HYPERVISOR_RX      (__PAGE_HYPERVISOR_RX      | _PAGE_GLOBAL)
Signature · 7 lines
2.7.4


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

PATCH 2/2 hvm/svm: Enable EMUL_UNIMPLEMENTED events on svm

---
 xen/include/asm-x86/monitor.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
xen/include/asm-x86/monitor.h +5 -8
index c5a86d1..7ef2aa2 100644
@@ -83,16 +83,13 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
                     (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
-                    (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG));
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG) |
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED));
 
-    if ( cpu_has_vmx )
-    {
-        capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED);
 
-        /* Since we know this is on VMX, we can just call the hvm func */
-        if ( hvm_is_singlestep_supported() )
-            capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);
-    }
+     /* Check if we are on VMX and then we can just call the hvm func */
+    if ( cpu_has_vmx && hvm_is_singlestep_supported() )
+        capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);
 
     if ( hvm_funcs.set_descriptor_access_exiting )
         capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS);
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] hvm/svm: Enable EMUL_UNIMPLEMENTED events on svm

Quoted 1 line · Alexandru Isaila
Quoted 31 lines
---
 xen/include/asm-x86/monitor.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
xen/include/asm-x86/monitor.h +5 -9
index c5a86d1..7ef2aa2 100644
@@ -83,16 +83,13 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
                     (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
-                    (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG));
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG) |
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED));
 
-    if ( cpu_has_vmx )
-    {
-        capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED);
 
-        /* Since we know this is on VMX, we can just call the hvm func */
-        if ( hvm_is_singlestep_supported() )
-            capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);
-    }
+     /* Check if we are on VMX and then we can just call the hvm func */
+    if ( cpu_has_vmx && hvm_is_singlestep_supported() )
+        capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);
 
     if ( hvm_funcs.set_descriptor_access_exiting )
         capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS);
--
Quoted 1 line

2.7.4

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

#3 lore raw

Re: [PATCH v1 2/2] hvm/svm: Enable EMUL_UNIMPLEMENTED events on svm

In reply to Alexandru Isaila
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 13:11, <[email protected]> wrote:

It would be helpful to know whether this patch depends on patch 1 in any way. If it doesn't, with Tamas'es ack this could go in independent of the other one. For conveying such information a cover letter is usually helpful.

Jan

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

#4 lore raw

Re: [PATCH v1 2/2] hvm/svm: Enable EMUL_UNIMPLEMENTED events on svm

Quoted 6 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 13:11, <[email protected]> wrote:

It would be helpful to know whether this patch depends on patch 1 in any way. If it doesn't, with Tamas'es ack this could go in independent of the other one. For conveying such information a cover letter is usually helpful.

The two types of events are independent, you can trigger emulation without mem_access restrictions, although that is the one mostly used.

Tamas

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

#5 lore raw

Re: [PATCH v1 2/2] hvm/svm: Enable EMUL_UNIMPLEMENTED events on svm

Quoted 10 lines · Tamas K Lengyel
Quoted 6 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 13:11, <[email protected]> wrote:

It would be helpful to know whether this patch depends on patch 1 in any way. If it doesn't, with Tamas'es ack this could go in independent of the other one. For conveying such information a cover letter is usually helpful.

The two types of events are independent, you can trigger emulation without mem_access restrictions, although that is the one mostly used.

Indeed, it usually only makes sense to emulate an instruction that has caused a page fault vm_event (something that's accessing a restricted page), but it is possible to set the emulate flag when replying to a CR or MSR write event.

We've waited this long to send this patch out because at least our use cases always only involve emulating as a response to page fault events (for MSR and CR writes we are only interested in being able to deny the write) - but functionally there's no reason why this patch needs to wait for the mem_access one.

Thanks,
Razvan

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

#6 lore raw

Re: [PATCH v1 2/2] hvm/svm: Enable EMUL_UNIMPLEMENTED events on svm

In reply to Alexandru Isaila
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 13:11, <[email protected]> wrote:
xen/include/asm-x86/monitor.h +2 -2
@@ -83,16 +83,13 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
                     (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
-                    (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG));
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG) |
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED));
 
-    if ( cpu_has_vmx )

xen/include/asm-x86/monitor.h static inline uint32_t arch_monitor_get_capabilities(struct domain *d) · line 92

Quoted 10 lines
xen/include/asm-x86/monitor.h +3 -6
-    {
-        capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED);
 
-        /* Since we know this is on VMX, we can just call the hvm func */
-        if ( hvm_is_singlestep_supported() )
-            capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);
-    }
+     /* Check if we are on VMX and then we can just call the hvm func */
+    if ( cpu_has_vmx && hvm_is_singlestep_supported() )
+        capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);

I was about to apply this when I noticed the seemingly unnecessary cpu_has_vmx here: hvm_is_singlestep_supported() is precisely the abstraction to make such extra checking unnecessary. If you agree, I can drop it while applying.

Jan

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

#7 lore raw

Re: [PATCH v1 2/2] hvm/svm: Enable EMUL_UNIMPLEMENTED events on svm

Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 4 lines
Quoted 4 lines · On 11.05.18 at 13:11, <[email protected]> wrote:
xen/include/asm-x86/monitor.h +0 -0
@@ -83,16 +83,13 @@ static inline uint32_t
 arch_monitor_get_capabilities(struct domain *d)
                     (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
                     (1U <<

XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
- (1U <<
XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG));
+ (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG)
|
+ (1U <<
XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED));

xen/include/asm-x86/monitor.h +0 -3
-    if ( cpu_has_vmx )
-    {
-        capabilities |= (1U <<

XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED);

Quoted 16 lines
Quoted 11 lines

- /* Since we know this is on VMX, we can just call the hvm
func */

xen/include/asm-x86/monitor.h +0 -2
-        if ( hvm_is_singlestep_supported() )
-            capabilities |= (1U <<

XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);

xen/include/asm-x86/monitor.h +1 -1
-    }
+     /* Check if we are on VMX and then we can just call the hvm

func */

xen/include/asm-x86/monitor.h +2 -0
+    if ( cpu_has_vmx && hvm_is_singlestep_supported() )
+        capabilities |= (1U <<

XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);

I was about to apply this when I noticed the seemingly unnecessary cpu_has_vmx here: hvm_is_singlestep_supported() is precisely the abstraction to make such extra checking unnecessary. If you agree, I can drop it while applying.

Yes I agree with this and it is ok to drop it.

Thanks,
Alex

________________________
This email was scanned by Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#8 lore raw

Re: [PATCH v1 2/2] hvm/svm: Enable EMUL_UNIMPLEMENTED events on svm

In reply to Alexandru Isaila
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 13:11, <[email protected]> wrote:
---
 xen/include/asm-x86/monitor.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
xen/include/asm-x86/monitor.h +0 -1
index c5a86d1..7ef2aa2 100644
@@ -83,16 +83,13 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
                     (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
-                    (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG));

xen/include/asm-x86/monitor.h static inline uint32_t arch_monitor_get_capabilities(struct domain *d) · line 94

Quoted 10 lines
xen/include/asm-x86/monitor.h +2 -6
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG) |
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED));
 
-    if ( cpu_has_vmx )
-    {
-        capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED);
 
-        /* Since we know this is on VMX, we can just call the hvm func */
-        if ( hvm_is_singlestep_supported() )
-            capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);

After applying I've noticed the double blank lines this change leaves. I've corrected this for you, but please pay attention yourself in the future.

Jan

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

#9 lore raw
In reply to Alexandru Isaila
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 13:11, <[email protected]> wrote:

This patch adds access rights for the NPT pages. The access rights are saved in bits 59:56 of pte that are manipulated through p2m_set_access() and p2m_get_access() functions.

You don't give any rationale for the choice of bits. Right now p2m-pt.c still assumes that CPU and IOMMU page tables might be shared, despite amd_iommu_init() unconditionally turning this functionality off. As long as the option for that mode hasn't been removed from p2m-pt.c, I think bits used by the IOMMU (here: bit 59) should not be used for software purposes. The alternative therefore is for you to supply a prereq patch purging the sharing functionality from p2m-pt.c and preferably also from the AMD IOMMU code. That's of course only an option if we don't foresee any means by which this mode may become usable again.

Quoted 4 lines
xen/include/asm-x86/x86_64/page.h +0 -0
@@ -159,6 +159,15 @@ static inline intpte_t put_pte_flags(unsigned int x)
  */

xen/include/asm-x86/x86_64/page.h static inline intpte_t put_pte_flags(unsigned int x) · line 169

Quoted 10 lines
xen/include/asm-x86/x86_64/page.h +8 -0
 #define _PAGE_GUEST_KERNEL (1U<<12)
 
+/*
+ * Bits 19:16 of a 24-bit flag mask are used to store p2m_access_t.
+ * This corresponds to bits 59:56 of a pte
+ */
+#define PAGE_ACCESS_START          59
+#define PAGE_ACCESS_LEN            4
+#define PAGE_ACCESS_MASK           ((1UL << PAGE_ACCESS_LEN) - 1)
+#define PAGE_ACCESS_BITFIELD_MASK  (PAGE_ACCESS_MASK << PAGE_ACCESS_START)

Afaics you don't need these outside of p2m-pt.c, in which case I would think it's better to confine their visibility to that file. That'll avoid the possibly misleading comment about bits 19:16 here (you never convert the flags to that form).

Additionally I'd prefer if you defined just a single constant instead of 4 of them, and if you then used MASK_EXTR() / MASK_INSR() as appropriate.

Jan

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

#10 lore raw
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 13:11, <[email protected]> wrote:

This patch adds access rights for the NPT pages. The access rights are saved in bits 59:56 of pte that are manipulated through p2m_set_access() and p2m_get_access() functions.

Quoted 9 lines

You don't give any rationale for the choice of bits. Right now p2m-pt.c still assumes that CPU and IOMMU page tables might be shared, despite amd_iommu_init() unconditionally turning this functionality off. As long as the option for that mode hasn't been removed from p2m-pt.c, I think bits used by the IOMMU (here: bit 59) should not be used for software purposes. The alternative therefore is for you to supply a prereq patch purging the sharing functionality from p2m-pt.c and preferably also from the AMD IOMMU code. That's of course only an option if we don't foresee any means by which this mode may become usable again.

The choice of bits was our interpretation of Andrew's reply here:

https://lists.xenproject.org/archives/html/xen-devel/2018-05/msg00573.html

Have we misread it?

We've also thought about putting the information in a new field of struct page_info. Would that perhaps be preferable?

Thanks,
Razvan

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

#11 lore raw
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 18.05.18 at 20:30, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 13:11, <[email protected]> wrote:

This patch adds access rights for the NPT pages. The access rights are saved in bits 59:56 of pte that are manipulated through p2m_set_access() and p2m_get_access() functions.

Quoted 9 lines

You don't give any rationale for the choice of bits. Right now p2m-pt.c still assumes that CPU and IOMMU page tables might be shared, despite amd_iommu_init() unconditionally turning this functionality off. As long as the option for that mode hasn't been removed from p2m-pt.c, I think bits used by the IOMMU (here: bit 59) should not be used for software purposes. The alternative therefore is for you to supply a prereq patch purging the sharing functionality from p2m-pt.c and preferably also from the AMD IOMMU code. That's of course only an option if we don't foresee any means by which this mode may become usable again.

Quoted 5 lines

The choice of bits was our interpretation of Andrew's reply here:

https://lists.xenproject.org/archives/html/xen-devel/2018-05/msg00573.html

Have we misread it?

I don't think you have, but what Andrew has described was only the CPU side of considerations to make. Plus of course the patch description should explain whatever choice you make.

Quoted 2 lines

We've also thought about putting the information in a new field of struct page_info. Would that perhaps be preferable?

I don't view this as a page property, but a mapping property. As such it can't validly go into struct page_info.

Jan

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

#12 lore raw
Quoted 44 lines · Jan Beulich
Quoted 31 lines
Quoted 4 lines
Quoted 4 lines · On 18.05.18 at 20:30, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines · On 11.05.18 at 13:11, <[email protected]> wrote:

This patch adds access rights for the NPT pages. The access rights are
saved in bits 59:56 of pte that are manipulated through p2m_set_access()
and p2m_get_access() functions.

Quoted 16 lines

You don't give any rationale for the choice of bits. Right now p2m-pt.c still
assumes that CPU and IOMMU page tables might be shared, despite amd_iommu_init() unconditionally turning this functionality off. As long as the
option for that mode hasn't been removed from p2m-pt.c, I think bits used
by the IOMMU (here: bit 59) should not be used for software purposes. The
alternative therefore is for you to supply a prereq patch purging the sharing
functionality from p2m-pt.c and preferably also from the AMD IOMMU code.
That's of course only an option if we don't foresee any means by which this
mode may become usable again.

Quoted 6 lines

The choice of bits was our interpretation of Andrew's reply here:

https://lists.xenproject.org/archives/html/xen-devel/2018-05/msg005
73.html

Have we misread it?

I don't think you have, but what Andrew has described was only the CPU side
of considerations to make. Plus of course the patch description should explain
whatever choice you make.

Quoted 1 line
Quoted 4 lines
Quoted 2 lines

We've also thought about putting the information in a new field of struct page_info. Would that perhaps be preferable?

I don't view this as a page property, but a mapping property. As such it can't validly go into struct page_info.

I will add the information in the patch description. Can you tell us what structure is best to use for the access rights?

Thanks,
Alex

________________________
This email was scanned by Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#13 lore raw
Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 22.05.18 at 15:35, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 18.05.18 at 20:30, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 13:11, <[email protected]> wrote:

This patch adds access rights for the NPT pages. The access rights are
saved in bits 59:56 of pte that are manipulated through p2m_set_access()
and p2m_get_access() functions.

Quoted 16 lines

You don't give any rationale for the choice of bits. Right now p2m-pt.c still
assumes that CPU and IOMMU page tables might be shared, despite amd_iommu_init() unconditionally turning this functionality off. As long as the
option for that mode hasn't been removed from p2m-pt.c, I think bits used
by the IOMMU (here: bit 59) should not be used for software purposes. The
alternative therefore is for you to supply a prereq patch purging the sharing
functionality from p2m-pt.c and preferably also from the AMD IOMMU code.
That's of course only an option if we don't foresee any means by which this
mode may become usable again.

Quoted 6 lines

The choice of bits was our interpretation of Andrew's reply here:

https://lists.xenproject.org/archives/html/xen-devel/2018-05/msg005
73.html

Have we misread it?

I don't think you have, but what Andrew has described was only the CPU side
of considerations to make. Plus of course the patch description should explain
whatever choice you make.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

We've also thought about putting the information in a new field of struct page_info. Would that perhaps be preferable?

I don't view this as a page property, but a mapping property. As such it can't validly go into struct page_info.

I will add the information in the patch description. Can you tell us what structure is best to use for the access rights?

I may not correctly understand the question: I think everybody agrees on the bits to go into an _unused_ portion of the p2m entry.

Jan

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

#14 lore raw
Quoted 63 lines · Jan Beulich
Quoted 63 lines
Quoted 4 lines
Quoted 4 lines · On 22.05.18 at 15:35, <[email protected]> wrote:
Quoted 58 lines · Jan Beulich
Quoted 38 lines
Quoted 5 lines
Quoted 5 lines · On 18.05.18 at 20:30, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines · On 11.05.18 at 13:11, <[email protected]> wrote:

This patch adds access rights for the NPT pages. The access rights are
saved in bits 59:56 of pte that are manipulated through p2m_set_access()
and p2m_get_access() functions.

You don't give any rationale for the choice of bits. Right now
p2m-pt.c still
assumes that CPU and IOMMU page tables might be shared, despite
amd_iommu_init() unconditionally turning this functionality off.
As long as the
option for that mode hasn't been removed from p2m-pt.c, I think
bits used
by the IOMMU (here: bit 59) should not be used for software purposes. The
alternative therefore is for you to supply a prereq patch

Quoted 8 lines

purging
the sharing
functionality from p2m-pt.c and preferably also from the AMD IOMMU code.
That's of course only an option if we don't foresee any means by
which this
mode may become usable again.

Quoted 8 lines

The choice of bits was our interpretation of Andrew's reply here:

https://lists.xenproject.org/archives/html/xen-devel/2018-05/ms
g005
73.html

Have we misread it?

I don't think you have, but what Andrew has described was only the
CPU side
of considerations to make. Plus of course the patch description should explain
whatever choice you make.

Quoted 5 lines

We've also thought about putting the information in a new field of
struct page_info. Would that perhaps be preferable?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I don't view this as a page property, but a mapping property. As such
it can't validly go into struct page_info.

I will add the information in the patch description. Can you tell us
what structure is best to use for the access rights?

I may not correctly understand the question: I think everybody agrees on the bits to go into an _unused_ portion of the p2m entry.

Sorry for the misunderstanding, I wanted to clarify if the 59:56 bits are fully ok to be used or if not then where should I use 4 bits to store the mem access info?

Any thoughts on this matter are appreciated.

Thanks,
Alex

________________________
This email was scanned by Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#15 lore raw
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 30.05.18 at 11:04, <[email protected]> wrote:

Sorry for the misunderstanding, I wanted to clarify if the 59:56 bits are fully ok to be used or if not then where should I use 4 bits to store the mem access info?

I thought I had sufficiently explained this - you have two options:
1) Make sure (via some prereq patch(es)) bit 59 has no other use, and then use 59:56.
2) Use another range that's provably having no other use, e.g. 58:55.

Jan

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

#16 lore raw
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines · On 30.05.18 at 11:04, <[email protected]> wrote:

Sorry for the misunderstanding, I wanted to clarify if the 59:56 bits
are fully ok to be used or if not then where should I use 4 bits to store the mem access info?

Quoted 5 lines

I thought I had sufficiently explained this - you have two options:
1) Make sure (via some prereq patch(es)) bit 59 has no other use, and then use 59:56.
2) Use another range that's provably having no other use, e.g. 58:55.

I've checked and bits 40:52 are defined in asm/page.h for page flags. I've tried bits 53:56 and there where some problems with the guest not starting or the image freezing, bits 62 and 63 are not free so 59:56 is the only space to be used for this purpose and is seems to function correctly. Is there any test I should run?

Thanks,
Alex

________________________
This email was scanned by Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#17 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.05.18 at 13:20, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines · On 30.05.18 at 11:04, <[email protected]> wrote:

Sorry for the misunderstanding, I wanted to clarify if the 59:56 bits
are fully ok to be used or if not then where should I use 4 bits to store the mem access info?

Quoted 6 lines
Quoted 5 lines

I thought I had sufficiently explained this - you have two options:
1) Make sure (via some prereq patch(es)) bit 59 has no other use, and then use 59:56.
2) Use another range that's provably having no other use, e.g. 58:55.

I've checked and bits 40:52 are defined in asm/page.h for page flags.

40:52? Hardly.

Quoted 2 lines

I've tried bits 53:56 and there where some problems with the guest not starting or the image freezing,

Well, you'll have to explain this (perhaps just to yourself).

Quoted 3 lines

bits 62 and 63 are not free so 59:56 is
the only space to be used for this purpose and is seems to function correctly.

Well - as said before, bit 59 is not available for use without some prereq work.

Jan

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

#18 lore raw
Quoted 17 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 30.05.18 at 13:20, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 30.05.18 at 11:04, <[email protected]> wrote:

Sorry for the misunderstanding, I wanted to clarify if the 59:56 bits
are fully ok to be used or if not then where should I use 4 bits to store the mem access info?

Quoted 6 lines
Quoted 5 lines

I thought I had sufficiently explained this - you have two options:
1) Make sure (via some prereq patch(es)) bit 59 has no other use, and then use 59:56.
2) Use another range that's provably having no other use, e.g. 58:55.

I've checked and bits 40:52 are defined in asm/page.h for page flags.

40:52? Hardly.

Quoted 2 lines

I've tried bits 53:56 and there where some problems with the guest not starting or the image freezing,

Quoted 7 lines

Well, you'll have to explain this (perhaps just to yourself).

Quoted 3 lines

bits 62 and 63 are not free so 59:56 is
the only space to be used for this purpose and is seems to function correctly.

Well - as said before, bit 59 is not available for use without some prereq work.

There are no software available bits in the top of an AMD IOMMU PTE. Bits 59:62 are defined, while bits 52:58 are strictly reserved and fault if used.

I'm also not convinced of the safety of our current uses of bits 9:11 which are software available in the regular pagetables, but have specific meaning in the IOMMU entries.

If the code IOMMU code disables page sharing, then lets go one small step further and prohibit its use entirely.  There is no point trying to maintain compatibility for an option which isn't used, especially if it gets in the way of improvements like this in the SVM code.

~Andrew

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

#19 lore raw
Quoted 51 lines · Andrew Cooper
Quoted 35 lines · Jan Beulich
Quoted 24 lines
Quoted 5 lines
Quoted 5 lines · On 30.05.18 at 13:20, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 5 lines
Quoted 5 lines · On 30.05.18 at 11:04, <[email protected]> wrote:

Sorry for the misunderstanding, I wanted to clarify if the 59:56
bits
are fully ok to be used or if not then where should I use 4 bits to
store the mem access info?

Quoted 7 lines

I thought I had sufficiently explained this - you have two options:
1) Make sure (via some prereq patch(es)) bit 59 has no other use, and
then use 59:56.
2) Use another range that's provably having no other use, e.g. 58:55.

Quoted 2 lines

I've checked and bits 40:52 are defined in asm/page.h for page flags.

40:52? Hardly.

Quoted 4 lines

I've tried bits 53:56 and there where some problems with the guest not
starting or the image freezing,

Well, you'll have to explain this (perhaps just to yourself).

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

bits 62 and 63 are not free so 59:56 is
the only space to be used for this purpose and is seems to function
correctly.

Well - as said before, bit 59 is not available for use without some prereq work.

There are no software available bits in the top of an AMD IOMMU PTE. Bits 59:62 are defined, while bits 52:58 are strictly reserved and fault
if used.

I'm also not convinced of the safety of our current uses of bits 9:11 which are software available in the regular pagetables, but have specific meaning in the IOMMU entries.

Quoted 7 lines

If the code IOMMU code disables page sharing, then lets go one small step further and prohibit its use entirely. There is no point trying to
maintain compatibility for an option which isn't used, especially if it
gets in the way of improvements like this in the SVM code.

Another idea is to save the mem access info in a radix tree like on the ARM side and we can store the radix tree root in the p2m_domain.

I think that this is the fastest and cleanest way to solve the free bits problem.

Is this a suitable way to go?

Thanks,
Alex

________________________
This email was scanned by Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#20 lore raw
Quoted 60 lines
Quoted 1 line
Quoted 1 line · On 05.06.18 at 16:45, <[email protected]> wrote:
Quoted 51 lines · Andrew Cooper
Quoted 35 lines · Jan Beulich
Quoted 24 lines
Quoted 5 lines
Quoted 5 lines · On 30.05.18 at 13:20, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 5 lines
Quoted 5 lines · On 30.05.18 at 11:04, <[email protected]> wrote:

Sorry for the misunderstanding, I wanted to clarify if the 59:56
bits
are fully ok to be used or if not then where should I use 4 bits to
store the mem access info?

Quoted 7 lines

I thought I had sufficiently explained this - you have two options:
1) Make sure (via some prereq patch(es)) bit 59 has no other use, and
then use 59:56.
2) Use another range that's provably having no other use, e.g. 58:55.

Quoted 2 lines

I've checked and bits 40:52 are defined in asm/page.h for page flags.

40:52? Hardly.

Quoted 4 lines

I've tried bits 53:56 and there where some problems with the guest not
starting or the image freezing,

Well, you'll have to explain this (perhaps just to yourself).

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

bits 62 and 63 are not free so 59:56 is
the only space to be used for this purpose and is seems to function
correctly.

Well - as said before, bit 59 is not available for use without some prereq work.

There are no software available bits in the top of an AMD IOMMU PTE. Bits 59:62 are defined, while bits 52:58 are strictly reserved and fault
if used.

I'm also not convinced of the safety of our current uses of bits 9:11 which are software available in the regular pagetables, but have specific meaning in the IOMMU entries.

Quoted 7 lines

If the code IOMMU code disables page sharing, then lets go one small step further and prohibit its use entirely. There is no point trying to
maintain compatibility for an option which isn't used, especially if it
gets in the way of improvements like this in the SVM code.

Quoted 5 lines

Another idea is to save the mem access info in a radix tree like on the ARM side and we can store the radix tree root in the p2m_domain.

I think that this is the fastest and cleanest way to solve the free bits problem.

But it adds extra (memory, lookup time) overhead.

Quoted 1 line

Is this a suitable way to go?

If no other option exists - perhaps. But that's more a question to be answered by George.

Jan

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