Skip to contentSkip to conversation

mem_access: Fix npfec.kind propagation

RFC PATCH In review George Dunlap 7 participants 16 messages Sep 26, 2018 – Jun 17, 2019

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 mem_access: Fix npfec.kind propagation

The name of the "with_gla" flag is confusing; it has nothing to do with the existence or lack thereof of a faulting GLA, but rather where the fault originated. The npfec.kind value is always valid, and should thus be propagated, regardless of whether gla_valid is set or not.

In particular, gla_valid will never be set on AMD systems; but npfec.kind will still be valid and should still be propagated.

---
CC: Andrew Cooper <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Tamas K Lengyel <[email protected]>
CC: Razvan Cojocaru <[email protected]>

---
 xen/arch/x86/mm/mem_access.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
xen/arch/x86/mm/mem_access.c +5 -5
index d9e64fcbb9..699a315076 100644
@@ -232,12 +232,12 @@ 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.kind == npfec_kind_with_gla )
-                req->u.mem_access.flags |= MEM_ACCESS_FAULT_WITH_GLA;
-            else if ( npfec.kind == npfec_kind_in_gpt )
-                req->u.mem_access.flags |= MEM_ACCESS_FAULT_IN_GPT;
         }
+
+        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 )
+            req->u.mem_access.flags |= MEM_ACCESS_FAULT_IN_GPT;
         req->u.mem_access.flags |= npfec.read_access    ? MEM_ACCESS_R : 0;
         req->u.mem_access.flags |= npfec.write_access   ? MEM_ACCESS_W : 0;
         req->u.mem_access.flags |= npfec.insn_fetch     ? MEM_ACCESS_X : 0;
Signature · 7 lines
2.19.0


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

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

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m table, so we add a radix tree to store extra information.

For efficiency:
- Only allocate this radix tree when we first store "non-default" extra information

- Remove entires which match the default extra information rather than continuing to store them

- For superpages, only store an entry for the first gfn in the superpage. Use the order of the p2m entry being read to determine the proper place to look in the radix table.

Modify p2m_type_to_flags() to accept and interpret an access value, parallel to the ept code.

Add a set_default_access() method to the p2m-pt and p2m-ept versions of the p2m rather than setting it directly, to deal with different default permitted access values.

---
NB, this is compile-tested only.

cc'ing Paul because this is functionality he may want at some point in the future.

I'm not sure why we only allow 'int' to be stored in the radix tree, but that throws away 30-some bits we could otherwise use. We might consider revising this if we run out of bits here.

CC Andrew Cooper <[email protected]>
CC Jan Beulich <[email protected]>
CC Tim Deegan <[email protected]>
CC Tamas K Lengyel <[email protected]>
CC Paul Durrant <[email protected]>
CC Razvan Cojocaru <[email protected]>
---
 xen/arch/x86/mm/mem_access.c     |   5 +-
 xen/arch/x86/mm/p2m-ept.c        |   9 ++
 xen/arch/x86/mm/p2m-pt.c         | 173 ++++++++++++++++++++++++++++---
 xen/arch/x86/mm/p2m.c            |   6 ++
 xen/arch/x86/monitor.c           |   1 +
 xen/include/asm-x86/mem_access.h |   2 +-
 xen/include/asm-x86/p2m.h        |  18 ++++
 7 files changed, 192 insertions(+), 22 deletions(-)
xen/arch/x86/mm/mem_access.c +1 -4
index 699a315076..0f96c43f88 100644
@@ -389,10 +389,7 @@ long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
 
     /* If request to set default access. */
     if ( gfn_eq(gfn, INVALID_GFN) )
-    {
-        p2m->default_access = a;
-        return 0;
-    }
+        return p2m->set_default_access(p2m, a);
 
     p2m_lock(p2m);
     if ( ap2m )
xen/arch/x86/mm/p2m-ept.c +9 -0
index 1ff4f14ae4..37bdbcf186 100644
@@ -667,6 +667,14 @@ bool_t ept_handle_misconfig(uint64_t gpa)
     return spurious ? (rc >= 0) : (rc > 0);
 }
 
+int ept_set_default_access(struct p2m_domain *p2m, p2m_access_t p2ma)
+{
+    /* All access is permitted */
+    p2m->default_access = p2ma;
+    
+    return 0;
+}
+
 /*
  * ept_set_entry() computes 'need_modify_vtd_table' for itself,
  * by observing whether any gfn->mfn translations are modified.
@@ -1255,6 +1263,7 @@ int ept_p2m_init(struct p2m_domain *p2m)
     p2m->change_entry_type_global = ept_change_entry_type_global;
     p2m->change_entry_type_range = ept_change_entry_type_range;
     p2m->memory_type_changed = ept_memory_type_changed;
+    p2m->set_default_access = ept_set_default_access;
     p2m->audit_p2m = NULL;
     p2m->tlb_flush = ept_tlb_flush;
 
xen/arch/x86/mm/p2m-pt.c +156 -17

302 lines not on this page · raw message

xen/arch/x86/mm/p2m.c +6 -0
index ed2e8daf58..706a8ec8bb 100644
@@ -682,6 +682,12 @@ void p2m_teardown(struct p2m_domain *p2m)
 
     d = p2m->domain;
 
+    if ( p2m->extra )
+    {
+        radix_tree_destroy(p2m->extra, NULL);
+        xfree(p2m->extra);
+    }
+
     p2m_lock(p2m);
     ASSERT(atomic_read(&d->shr_pages) == 0);
     p2m->phys_table = pagetable_null();
xen/arch/x86/monitor.c +1 -0
index 3c42e21906..2e6b1e75e4 100644
@@ -20,6 +20,7 @@
  */
 
 #include <asm/monitor.h>
+#include <asm/p2m.h>
 #include <public/vm_event.h>
 
 int arch_monitor_init_domain(struct domain *d)
xen/include/asm-x86/mem_access.h +1 -1
index 4043c9fb4d..34f2c07088 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/p2m.h +18 -0
index be3b6fcaf0..a5e1193dcc 100644
@@ -185,6 +185,16 @@ typedef enum {
     p2m_alternate,
 } p2m_class_t;
 
+typedef union {
+    struct {
+        u32  access      :   4,  /* p2m_access_t */
+            _available   :  25,
+            _reserved    :   3;  /* Upper two bits reserved */
+    };
+    int extra;
+} p2m_extra_t;
+
+
 /* Per-p2m-table state */
 struct p2m_domain {
     /* Lock that protects updates to the p2m */
@@ -270,6 +280,8 @@ struct p2m_domain {
                                           unsigned long gfn, l1_pgentry_t *p,
                                           l1_pgentry_t new, unsigned int level);
     long               (*audit_p2m)(struct p2m_domain *p2m);
+    int                (*set_default_access)(struct p2m_domain *p2m,
+                                             p2m_access_t p2ma);
 
     /*
      * P2M updates may require TLBs to be flushed (invalidated).
@@ -292,6 +304,12 @@ struct p2m_domain {
      * retyped get this access type.  See definition of p2m_access_t. */
     p2m_access_t default_access;
 
+    /*
+     * Radix tree to store extra information which doesn't fit in the
+     * p2m's PTE
+     */
+    struct radix_tree_root *extra;
+
     /* If true, and an access fault comes in and there is no vm_event listener, 
      * pause domain.  Otherwise, remove access restrictions. */
     bool_t       access_required;
Signature · 7 lines
2.19.0


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

Re: [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

Quoted 6 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m table, so we add a radix tree to store extra information.

I'm sorry to re-open this argument, but why?

ISTR there being some argument based on pagetable sharing with the IOMMU, but that doesn't work at the moment and can't reasonably be made to work.  For one, attempting to use pt sharing will break as soon as you try and DMA to a mapped grant.

I'm disinclined to let a broken vestigial feature get in the way of real improvements.

Beyond that, an NPT PTE has basically the same number of software available bits as an EPT PTE.

Am I missing anything?

Quoted 24 lines

For efficiency:
- Only allocate this radix tree when we first store "non-default" extra information

- Remove entires which match the default extra information rather than continuing to store them

- For superpages, only store an entry for the first gfn in the superpage. Use the order of the p2m entry being read to determine the proper place to look in the radix table.

Modify p2m_type_to_flags() to accept and interpret an access value, parallel to the ept code.

Add a set_default_access() method to the p2m-pt and p2m-ept versions of the p2m rather than setting it directly, to deal with different default permitted access values.

---
NB, this is compile-tested only.

Quoted 6 lines

cc'ing Paul because this is functionality he may want at some point in the future.

I'm not sure why we only allow 'int' to be stored in the radix tree, but that throws away 30-some bits we could otherwise use. We might consider revising this if we run out of bits here.

Probably because we have a old fork of the Linux radix tree functionality, rather than any specific reason to waste 30-some bits.

~Andrew

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

#3 lore raw

Re: [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

Quoted 15 lines · Andrew Cooper
Quoted 6 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m table, so we add a radix tree to store extra information.

I'm sorry to re-open this argument, but why?

ISTR there being some argument based on pagetable sharing with the IOMMU, but that doesn't work at the moment and can't reasonably be made to work.  For one, attempting to use pt sharing will break as soon as you try and DMA to a mapped grant.

Quoted 7 lines

I'm disinclined to let a broken vestigial feature get in the way of real improvements.

Beyond that, an NPT PTE has basically the same number of software available bits as an EPT PTE.

Am I missing anything?

Wow -- looks like IOMMU/p2m sharing has been disabled unconditionally since 2014. If nobody has complained since then, that seems like a good enough reason to me to rip it out.

Suravee / Brian / Boris -- any opinions?

The main reason to go with the 'extra bits' solution rather than the 'rip out iommu/p2m sharing' solution is because people have been prognosticating for years that we would be running out of bits and need more at some point in the future. I thought Paul, for instance, might have a use for the extra bits. But I'm happy to wait until such time as we need it and then fish this patch out of the mail archives.

-George

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

#4 lore raw

Re: [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

Quoted 42 lines

-----Original Message-----
From: George Dunlap [mailto:[email protected]]
Sent: 27 September 2018 11:38
To: Andrew Cooper <[email protected]>; xen- [email protected]
Cc: Isaila Alexandru <[email protected]>; Jan Beulich <[email protected]>; Tim (Xen.org) <[email protected]>; Tamas K Lengyel <[email protected]>; Paul Durrant <[email protected]>; Razvan Cojocaru <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>; Boris Ostrovsky <[email protected]>
Subject: Re: [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

Quoted 6 lines · Andrew Cooper
Quoted 5 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT

p2m

Quoted 9 lines
Quoted 1 line

table, so we add a radix tree to store extra information.

I'm sorry to re-open this argument, but why?

ISTR there being some argument based on pagetable sharing with the IOMMU, but that doesn't work at the moment and can't reasonably be made to work.  For one, attempting to use pt sharing will break as soon as you try and DMA to a mapped grant.

Quoted 7 lines

I'm disinclined to let a broken vestigial feature get in the way of real improvements.

Beyond that, an NPT PTE has basically the same number of software available bits as an EPT PTE.

Am I missing anything?

Wow -- looks like IOMMU/p2m sharing has been disabled unconditionally since 2014. If nobody has complained since then, that seems like a good enough reason to me to rip it out.

Quoted 9 lines

Suravee / Brian / Boris -- any opinions?

The main reason to go with the 'extra bits' solution rather than the 'rip out iommu/p2m sharing' solution is because people have been prognosticating for years that we would be running out of bits and need more at some point in the future. I thought Paul, for instance, might have a use for the extra bits. But I'm happy to wait until such time as we need it and then fish this patch out of the mail archives.

The main angle I had was to have a more generic page-to-type mapping such that it would be suitable to allow steering of accesses to certain pages to distinct IOREQ servers.

Paul

Quoted 1 line

-George

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

#5 lore raw

Re: [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

In reply to George Dunlap

Ping

Suravee / Brian / Boris any ideas on this topic are appreciated.

Regards,
Alex

Quoted 30 lines · George Dunlap
Quoted 15 lines · Andrew Cooper
Quoted 6 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m table, so we add a radix tree to store extra information.

I'm sorry to re-open this argument, but why?

ISTR there being some argument based on pagetable sharing with the IOMMU, but that doesn't work at the moment and can't reasonably be made to work.  For one, attempting to use pt sharing will break as soon as you try and DMA to a mapped grant.

Quoted 7 lines

I'm disinclined to let a broken vestigial feature get in the way of real improvements.

Beyond that, an NPT PTE has basically the same number of software available bits as an EPT PTE.

Am I missing anything?

Wow -- looks like IOMMU/p2m sharing has been disabled unconditionally since 2014. If nobody has complained since then, that seems like a good enough reason to me to rip it out.

Suravee / Brian / Boris -- any opinions?

Quoted 9 lines

The main reason to go with the 'extra bits' solution rather than the 'rip out iommu/p2m sharing' solution is because people have been prognosticating for years that we would be running out of bits and need more at some point in the future. I thought Paul, for instance, might have a use for the extra bits. But I'm happy to wait until such time as we need it and then fish this patch out of the mail archives.

-George

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

#6 lore raw

Re: [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

In reply to George Dunlap
Quoted 22 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m
table, so we add a radix tree to store extra information.

For efficiency:
- Only allocate this radix tree when we first store "non-default" extra information

- Remove entires which match the default extra information rather than continuing to store them

- For superpages, only store an entry for the first gfn in the superpage. Use the order of the p2m entry being read to determine the proper place to look in the radix table.

Modify p2m_type_to_flags() to accept and interpret an access value, parallel to the ept code.

Quoted 8 lines

Add a set_default_access() method to the p2m-pt and p2m-ept versions of the p2m rather than setting it directly, to deal with different default permitted access values.

---
NB, this is compile-tested only.

I've tested this with xen-access and it works as expected

xen/arch/x86/monitor.c line 23

Quoted 10 lines
xen/arch/x86/monitor.c +1 -0
index 3c42e21906..2e6b1e75e4 100644
@@ -20,6 +20,7 @@
  */
 
 #include <asm/monitor.h>
+#include <asm/p2m.h>

Is this intended?

Regards,
Alex

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

#7 lore raw

Re: [Xen-devel] [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

In reply to George Dunlap
Quoted 37 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m table, so we add a radix tree to store extra information.

For efficiency:
- Only allocate this radix tree when we first store "non-default" extra information

- Remove entires which match the default extra information rather than continuing to store them

- For superpages, only store an entry for the first gfn in the superpage. Use the order of the p2m entry being read to determine the proper place to look in the radix table.

Modify p2m_type_to_flags() to accept and interpret an access value, parallel to the ept code.

Add a set_default_access() method to the p2m-pt and p2m-ept versions of the p2m rather than setting it directly, to deal with different default permitted access values.

---
NB, this is compile-tested only.

cc'ing Paul because this is functionality he may want at some point in the future.

I'm not sure why we only allow 'int' to be stored in the radix tree, but that throws away 30-some bits we could otherwise use. We might consider revising this if we run out of bits here.

Quoted 6 lines
CC Andrew Cooper <[email protected]>
CC Jan Beulich <[email protected]>
CC Tim Deegan <[email protected]>
CC Tamas K Lengyel <[email protected]>
CC Paul Durrant <[email protected]>
CC Razvan Cojocaru <[email protected]>

Hi all,

I know it's been some time from the start of this patch but can this move forward? Any thoughts or acks are appreciated.

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

#8 lore raw

Re: [Xen-devel] [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

Quoted 47 lines · Alexandru Stefan ISAILA
Quoted 37 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m table, so we add a radix tree to store extra information.

For efficiency:
- Only allocate this radix tree when we first store "non-default" extra information

- Remove entires which match the default extra information rather than continuing to store them

- For superpages, only store an entry for the first gfn in the superpage. Use the order of the p2m entry being read to determine the proper place to look in the radix table.

Modify p2m_type_to_flags() to accept and interpret an access value, parallel to the ept code.

Add a set_default_access() method to the p2m-pt and p2m-ept versions of the p2m rather than setting it directly, to deal with different default permitted access values.

---
NB, this is compile-tested only.

cc'ing Paul because this is functionality he may want at some point in the future.

I'm not sure why we only allow 'int' to be stored in the radix tree, but that throws away 30-some bits we could otherwise use. We might consider revising this if we run out of bits here.

Quoted 6 lines
CC Andrew Cooper <[email protected]>
CC Jan Beulich <[email protected]>
CC Tim Deegan <[email protected]>
CC Tamas K Lengyel <[email protected]>
CC Paul Durrant <[email protected]>
CC Razvan Cojocaru <[email protected]>
Quoted 4 lines

Hi all,

I know it's been some time from the start of this patch but can this move forward? Any thoughts or acks are appreciated.

Right, well where we left this, the situation was that on AMD hardware with IOMMU / p2m sharing, there aren't enough bits.

The two general fixes we have so far are:
1. Add a parallel tree for extra bits (this patch)
2. Rip out IOMMU / p2m sharing for AMD.

#2 has the advantage that we don't need an entirely separate tree, as well as getting rid of code that has (apparently) been completely dead for 5 years. #1 has the advantage that we're set up for having a much larger number of IOREQ servers in the future.

Nobody objected to #2. Without looking deeply into it, it seems like it might be a good idea, but I can't be sure without seeing what it would actually look like.

The easiest way to press the point then would be to post a patch series ripping it out.

-George

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

#9 lore raw

Re: [Xen-devel] [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

Quoted 62 lines · George Dunlap
Quoted 45 lines · Alexandru Stefan ISAILA
Quoted 37 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m table, so we add a radix tree to store extra information.

For efficiency:
- Only allocate this radix tree when we first store "non-default" extra information

- Remove entires which match the default extra information rather than continuing to store them

- For superpages, only store an entry for the first gfn in the superpage. Use the order of the p2m entry being read to determine the proper place to look in the radix table.

Modify p2m_type_to_flags() to accept and interpret an access value, parallel to the ept code.

Add a set_default_access() method to the p2m-pt and p2m-ept versions of the p2m rather than setting it directly, to deal with different default permitted access values.

---
NB, this is compile-tested only.

cc'ing Paul because this is functionality he may want at some point in the future.

I'm not sure why we only allow 'int' to be stored in the radix tree, but that throws away 30-some bits we could otherwise use. We might consider revising this if we run out of bits here.

Quoted 6 lines
CC Andrew Cooper <[email protected]>
CC Jan Beulich <[email protected]>
CC Tim Deegan <[email protected]>
CC Tamas K Lengyel <[email protected]>
CC Paul Durrant <[email protected]>
CC Razvan Cojocaru <[email protected]>
Quoted 4 lines

Hi all,

I know it's been some time from the start of this patch but can this move forward? Any thoughts or acks are appreciated.

Right, well where we left this, the situation was that on AMD hardware with IOMMU / p2m sharing, there aren't enough bits.

The two general fixes we have so far are:
1. Add a parallel tree for extra bits (this patch)
2. Rip out IOMMU / p2m sharing for AMD.

#2 has the advantage that we don't need an entirely separate tree, as well as getting rid of code that has (apparently) been completely dead for 5 years. #1 has the advantage that we're set up for having a much larger number of IOREQ servers in the future.

Quoted 6 lines

Nobody objected to #2. Without looking deeply into it, it seems like it might be a good idea, but I can't be sure without seeing what it would actually look like.

The easiest way to press the point then would be to post a patch series ripping it out.

IOMMU / p2m sharing on AMD doesn't work, and isn't available any more (despite the code looking suspiciously like it is usable).

There was a bugfix to allow DMA mapping of granted pages, which is a prerequisite for PVH support, which requires using a nonzero p2m type, and is therefore incompatible with IOMMU/p2m sharing.

I don't see any feasible way to bring p2m-sharing back into a working state on AMD.

As a result, we'd be much better ripping out the dead code and more formally acknowledging that it is a dead feature, after which the existing p2m type/access infrastructure should work compatibly with the Intel implementation.

~Andrew

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

Acked-by Tamas K Lengyel on v1 2/2
#10 lore raw

Re: [Xen-devel] [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

In reply to George Dunlap
Quoted 22 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m table, so we add a radix tree to store extra information.

For efficiency:
- Only allocate this radix tree when we first store "non-default" extra information

- Remove entires which match the default extra information rather than continuing to store them

- For superpages, only store an entry for the first gfn in the superpage. Use the order of the p2m entry being read to determine the proper place to look in the radix table.

Modify p2m_type_to_flags() to accept and interpret an access value, parallel to the ept code.

Quoted 6 lines

Add a set_default_access() method to the p2m-pt and p2m-ept versions of the p2m rather than setting it directly, to deal with different default permitted access values.

The mem_access/monitor bits are fairly trivial:

Quoted 2 lines

---
NB, this is compile-tested only.

Are you planning to do some actual testing? I would highly recommend that we see real test results before this is merged to verify functionality.

Thanks,
Tamas

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

#11 lore raw

Re: [Xen-devel] [RFC PATCH 2/2] x86/mm: Add mem access rights to NPT

Quoted 32 lines · Tamas Lengyel
Quoted 22 lines · George Dunlap

From: Isaila Alexandru <[email protected]>

This patch adds access control for NPT mode.

There aren’t enough extra bits to store the access rights in the NPT p2m table, so we add a radix tree to store extra information.

For efficiency:
- Only allocate this radix tree when we first store "non-default" extra information

- Remove entires which match the default extra information rather than continuing to store them

- For superpages, only store an entry for the first gfn in the superpage. Use the order of the p2m entry being read to determine the proper place to look in the radix table.

Modify p2m_type_to_flags() to accept and interpret an access value, parallel to the ept code.

Quoted 6 lines

Add a set_default_access() method to the p2m-pt and p2m-ept versions of the p2m rather than setting it directly, to deal with different default permitted access values.

The mem_access/monitor bits are fairly trivial:

Quoted 8 lines
Quoted 2 lines

---
NB, this is compile-tested only.

Are you planning to do some actual testing? I would highly recommend that we see real test results before this is merged to verify functionality.

We did do some testing with xen-access at the time, but limited testing with the actual full-blown introspection agent (because not all the needed pieces align yet).

Things did appear to work as intended.

Thanks,
Razvan

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

Acked-by Tamas K Lengyel on v1 1/2
#12 lore raw
In reply to George Dunlap
Quoted 7 lines · George Dunlap

The name of the "with_gla" flag is confusing; it has nothing to do with the existence or lack thereof of a faulting GLA, but rather where the fault originated. The npfec.kind value is always valid, and should thus be propagated, regardless of whether gla_valid is set or not.

Quoted 5 lines

In particular, gla_valid will never be set on AMD systems; but npfec.kind will still be valid and should still be propagated.

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

#13 lore raw
In reply to George Dunlap
Quoted 30 lines · George Dunlap

The name of the "with_gla" flag is confusing; it has nothing to do with the existence or lack thereof of a faulting GLA, but rather where the fault originated. The npfec.kind value is always valid, and should thus be propagated, regardless of whether gla_valid is set or not.

In particular, gla_valid will never be set on AMD systems; but npfec.kind will still be valid and should still be propagated.

---
CC: Andrew Cooper <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Tamas K Lengyel <[email protected]>
CC: Razvan Cojocaru <[email protected]>

---
 xen/arch/x86/mm/mem_access.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
xen/arch/x86/mm/mem_access.c +0 -1
index d9e64fcbb9..699a315076 100644
@@ -232,12 +232,12 @@ 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;
-

xen/arch/x86/mm/mem_access.c bool p2m_mem_access_check(paddr_t gpa, unsigned long gla, · line 240

Quoted 10 lines
xen/arch/x86/mm/mem_access.c +5 -4
-            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 )
-                req->u.mem_access.flags |= MEM_ACCESS_FAULT_IN_GPT;
         }
+
+        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 )
+            req->u.mem_access.flags |= MEM_ACCESS_FAULT_IN_GPT;

Nit.  Newline here please, as it is not logically related with the block below.

~Andrew

xen/arch/x86/mm/mem_access.c bool p2m_mem_access_check(paddr_t gpa, unsigned long gla, · line 243

Quoted 3 lines
xen/arch/x86/mm/mem_access.c +0 -0
         req->u.mem_access.flags |= npfec.read_access    ? MEM_ACCESS_R : 0;
         req->u.mem_access.flags |= npfec.write_access   ? MEM_ACCESS_W : 0;
         req->u.mem_access.flags |= npfec.insn_fetch     ? MEM_ACCESS_X : 0;

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

#14 lore raw
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 26.09.18 at 19:00, <[email protected]> wrote:
Quoted 12 lines · George Dunlap
xen/arch/x86/mm/mem_access.c +0 -5
@@ -232,12 +232,12 @@ 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.kind == npfec_kind_with_gla )
-                req->u.mem_access.flags |= MEM_ACCESS_FAULT_WITH_GLA;
-            else if ( npfec.kind == npfec_kind_in_gpt )
-                req->u.mem_access.flags |= MEM_ACCESS_FAULT_IN_GPT;
         }
Quoted 8 lines

xen/arch/x86/mm/mem_access.c bool p2m_mem_access_check(paddr_t gpa, unsigned long gla, · line 240

Quoted 5 lines
xen/arch/x86/mm/mem_access.c +5 -0
+
+        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 )
+            req->u.mem_access.flags |= MEM_ACCESS_FAULT_IN_GPT;

Nit. Newline here please, as it is not logically related with the block below.

And, despite it being just two comparisons, perhaps better to make it a switch() at the same time?

Jan

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

#15 lore raw
Quoted 23 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 26.09.18 at 19:00, <[email protected]> wrote:
Quoted 12 lines · George Dunlap
xen/arch/x86/mm/mem_access.c +0 -5
@@ -232,12 +232,12 @@ 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.kind == npfec_kind_with_gla )
-                req->u.mem_access.flags |= MEM_ACCESS_FAULT_WITH_GLA;
-            else if ( npfec.kind == npfec_kind_in_gpt )
-                req->u.mem_access.flags |= MEM_ACCESS_FAULT_IN_GPT;
         }
Quoted 8 lines

xen/arch/x86/mm/mem_access.c bool p2m_mem_access_check(paddr_t gpa, unsigned long gla, · line 240

Quoted 5 lines
xen/arch/x86/mm/mem_access.c +5 -0
+
+        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 )
+            req->u.mem_access.flags |= MEM_ACCESS_FAULT_IN_GPT;

Nit. Newline here please, as it is not logically related with the block below.

Quoted 2 lines

And, despite it being just two comparisons, perhaps better to make it a switch() at the same time?

Sure -- this is logically separate from the follow-up patch, so I'll re-send it as a singleton with the comments.

-George

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