Skip to contentSkip to conversation

xen/altp2m: set access_required properly for all altp2ms

PATCH Superseded Razvan Cojocaru 2 participants 5 messages Jun 11, 2018 – Jun 12, 2018

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/altp2m: set access_required properly for all altp2ms

For the hostp2m, access_required starts off as 0, then it can be set with xc_domain_set_access_required(). However, all the altp2ms set it to 1 on init, and ignore both the hostp2m and the hypercall. This patch sets access_required to the value from the hostp2m on altp2m init, and propagates the values received via hypecall too all the active altp2ms, when applicable.

---
 xen/arch/arm/domain.c    |  4 ++++
 xen/arch/x86/domain.c    | 17 +++++++++++++++++
 xen/arch/x86/mm/p2m.c    |  3 ++-
 xen/common/domctl.c      |  2 ++
 xen/include/xen/domain.h |  2 ++
 5 files changed, 27 insertions(+), 1 deletion(-)
xen/arch/arm/domain.c +4 -0
index ec0f042..1c7d068 100644
@@ -729,6 +729,10 @@ int arch_domain_soft_reset(struct domain *d)
     return -ENOSYS;
 }
 
+void arch_domain_set_access_required(struct domain *d, bool access_required)
+{
+}
+
 static int is_guest_pv32_psr(uint32_t psr)
 {
     switch (psr & PSR_MODE_MASK)
xen/arch/x86/domain.c +17 -0
index 0ca820a..1744b98 100644
@@ -38,6 +38,7 @@
 #include <xen/livepatch.h>
 #include <public/sysctl.h>
 #include <public/hvm/hvm_vcpu.h>
+#include <asm/altp2m.h>
 #include <asm/regs.h>
 #include <asm/mc146818rtc.h>
 #include <asm/system.h>
@@ -719,6 +720,22 @@ int arch_domain_soft_reset(struct domain *d)
     return ret;
 }
 
+void arch_domain_set_access_required(struct domain *d, bool access_required)
+{
+    unsigned int i;
+
+    if ( !altp2m_active(d) )
+	    return;
+
+    for ( i = 0; i < MAX_ALTP2M; i++ )
+    {
+        if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
+            continue;
+
+        d->arch.altp2m_p2m[i]->access_required = access_required;
+    }
+}
+
 /*
  * These are the masks of CR4 bits (subject to hardware availability) which a
  * PV guest may not legitimiately attempt to modify.
xen/arch/x86/mm/p2m.c +2 -1
index c53cab4..8e9fbb5 100644
@@ -199,6 +199,7 @@ static int p2m_init_altp2m(struct domain *d)
 {
     unsigned int i;
     struct p2m_domain *p2m;
+    struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
 
     mm_lock_init(&d->arch.altp2m_list_lock);
     for ( i = 0; i < MAX_ALTP2M; i++ )
@@ -210,7 +211,7 @@ static int p2m_init_altp2m(struct domain *d)
             return -ENOMEM;
         }
         p2m->p2m_class = p2m_alternate;
-        p2m->access_required = 1;
+        p2m->access_required = hostp2m->access_required;
         _atomic_set(&p2m->active_vcpus, 0);
     }
 
xen/common/domctl.c +2 -0
index 9b7bc08..3ed7708 100644
@@ -1094,6 +1094,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             domain_pause(d);
             p2m_get_hostp2m(d)->access_required =
                 op->u.access_required.access_required;
+            arch_domain_set_access_required(d,
+                op->u.access_required.access_required);
             domain_unpause(d);
         }
         break;
xen/include/xen/domain.h +2 -0
index 177cb35..9df53a6 100644
@@ -66,6 +66,8 @@ void arch_domain_unpause(struct domain *d);
 
 int arch_domain_soft_reset(struct domain *d);
 
+void arch_domain_set_access_required(struct domain *d, bool access_required);
+
 int arch_set_info_guest(struct vcpu *, vcpu_guest_context_u);
 void arch_get_info_guest(struct vcpu *, vcpu_guest_context_u);
 
Signature · 7 lines
2.7.4


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

xen/arch/x86/domain.c line 41

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.06.18 at 17:12, <[email protected]> wrote:
xen/arch/x86/domain.c +1 -0
@@ -38,6 +38,7 @@
 #include <xen/livepatch.h>
 #include <public/sysctl.h>
 #include <public/hvm/hvm_vcpu.h>
+#include <asm/altp2m.h>

Not the least to avoid this I think ...

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 723

Quoted 5 lines
xen/arch/x86/domain.c +1 -0
@@ -719,6 +720,22 @@ int arch_domain_soft_reset(struct domain *d)
     return ret;
 }
 
+void arch_domain_set_access_required(struct domain *d, bool access_required)

... this belongs somewhere in x86/mm/.

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 728

Quoted 5 lines
xen/arch/x86/domain.c +5 -0
+{
+    unsigned int i;
+
+    if ( !altp2m_active(d) )
+	    return;

Hard tab.

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 733

Quoted 4 lines
xen/arch/x86/domain.c +4 -0
+    for ( i = 0; i < MAX_ALTP2M; i++ )
+    {
+        if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
+            continue;

Yet another EPT-specific check outside of EPT code. Why can't you check the pointer you use ...

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 735

Quoted 1 line
xen/arch/x86/domain.c +1 -0
+        d->arch.altp2m_p2m[i]->access_required = access_required;

... here against NULL, and otherwise do the store irrespective of the value of d->arch.altp2m_eptp[i]?

xen/arch/x86/domain.c static int p2m_init_altp2m(struct domain *d) · line 214

Quoted 6 lines
xen/arch/x86/domain.c +1 -1
@@ -210,7 +211,7 @@ static int p2m_init_altp2m(struct domain *d)
             return -ENOMEM;
         }
         p2m->p2m_class = p2m_alternate;
-        p2m->access_required = 1;
+        p2m->access_required = hostp2m->access_required;

There must have been a reason to have it start out as 1. You mention the fact in the description, but not why it is okay (or even necessary) to change it.

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 1098

Quoted 8 lines
xen/common/domctl.c +2 -0
@@ -1094,6 +1094,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             domain_pause(d);
             p2m_get_hostp2m(d)->access_required =
                 op->u.access_required.access_required;
+            arch_domain_set_access_required(d,
+                op->u.access_required.access_required);

Perhaps the setting of the host p2m field should move into that function as well?

Jan

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

#2 lore raw

Thanks for the review!

Quoted 11 lines · Jan Beulich

xen/arch/x86/domain.c line 41

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.06.18 at 17:12, <[email protected]> wrote:
xen/arch/x86/domain.c +1 -0
@@ -38,6 +38,7 @@
 #include <xen/livepatch.h>
 #include <public/sysctl.h>
 #include <public/hvm/hvm_vcpu.h>
+#include <asm/altp2m.h>

Not the least to avoid this I think ...

Quoted 7 lines

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 723

Quoted 5 lines
xen/arch/x86/domain.c +1 -0
@@ -719,6 +720,22 @@ int arch_domain_soft_reset(struct domain *d)
     return ret;
 }
 
+void arch_domain_set_access_required(struct domain *d, bool access_required)

... this belongs somewhere in x86/mm/.

No problem, I'll move it there.

Quoted 7 lines

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 728

Quoted 5 lines
xen/arch/x86/domain.c +5 -0
+{
+    unsigned int i;
+
+    if ( !altp2m_active(d) )
+	    return;

Hard tab.

Sorry for missing that.

Quoted 5 lines

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 733

Quoted 4 lines
xen/arch/x86/domain.c +4 -0
+    for ( i = 0; i < MAX_ALTP2M; i++ )
+    {
+        if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
+            continue;
Quoted 7 lines

Yet another EPT-specific check outside of EPT code. Why can't you check the pointer you use ...

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 735

Quoted 1 line
xen/arch/x86/domain.c +1 -0
+        d->arch.altp2m_p2m[i]->access_required = access_required;

... here against NULL, and otherwise do the store irrespective of the value of d->arch.altp2m_eptp[i]?

No reason, it'll have the same effect. I thought I'd only take care of the active altp2ms, but the extra effort doesn't buy much indeed.

Quoted 10 lines

xen/arch/x86/domain.c static int p2m_init_altp2m(struct domain *d) · line 214

Quoted 6 lines
xen/arch/x86/domain.c +1 -1
@@ -210,7 +211,7 @@ static int p2m_init_altp2m(struct domain *d)
             return -ENOMEM;
         }
         p2m->p2m_class = p2m_alternate;
-        p2m->access_required = 1;
+        p2m->access_required = hostp2m->access_required;

There must have been a reason to have it start out as 1. You mention the fact in the description, but not why it is okay (or even necessary) to change it.

If there was one, I can't see what it was. It in any case make altp2ms behave differently than the hostp2m. The mem_access system has been designed so that the user can say "this domain should now no longer be able to continue if there are EPT violatios and there's no vm_event subscriber attached".

Our application, for one, explicitly _disables_ access_required - so that it is able to detach from the domain and reattach later. Hence the surprise when an altp2m-enabled domain crashed when the introspection agent detached.

Basically, the altp2m behaviour can't be controlled at all here. Maybe Tamas remembers / knows more about why access_required ended up being 1 always, but it was probably just the quickest way to write the original patch.

Quoted 11 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 1098

Quoted 8 lines
xen/common/domctl.c +2 -0
@@ -1094,6 +1094,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             domain_pause(d);
             p2m_get_hostp2m(d)->access_required =
                 op->u.access_required.access_required;
+            arch_domain_set_access_required(d,
+                op->u.access_required.access_required);

Perhaps the setting of the host p2m field should move into that function as well?

No objection, but should in that case the logic still live in common/domctl.c (if the only thing the case does is call arch_domain_set_access_required())?

I thought the common part (setting p2m_get_hostp2m(d)->access_required) justifies the code remaining in the common/ source file.

Thanks,
Razvan

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

#3 lore raw
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 12.06.18 at 14:35, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 1098

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 11.06.18 at 17:12, <[email protected]> wrote:
xen/common/domctl.c +2 -0
@@ -1094,6 +1094,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             domain_pause(d);
             p2m_get_hostp2m(d)->access_required =
                 op->u.access_required.access_required;
+            arch_domain_set_access_required(d,
+                op->u.access_required.access_required);

Perhaps the setting of the host p2m field should move into that function as well?

Quoted 6 lines

No objection, but should in that case the logic still live in common/domctl.c (if the only thing the case does is call arch_domain_set_access_required())?

I thought the common part (setting p2m_get_hostp2m(d)->access_required) justifies the code remaining in the common/ source file.

Keeping it there has advantages, and moving it would have advantages too. I'm fine either way, I think.

Jan

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

#4 lore raw
In reply to Razvan Cojocaru
Quoted 20 lines · Razvan Cojocaru
Quoted 9 lines

xen/arch/x86/mm/p2m.c static int p2m_init_altp2m(struct domain *d) · line 214

Quoted 6 lines
xen/arch/x86/mm/p2m.c +1 -1
@@ -210,7 +211,7 @@ static int p2m_init_altp2m(struct domain *d)
             return -ENOMEM;
         }
         p2m->p2m_class = p2m_alternate;
-        p2m->access_required = 1;
+        p2m->access_required = hostp2m->access_required;

There must have been a reason to have it start out as 1. You mention the fact in the description, but not why it is okay (or even necessary) to change it.

If there was one, I can't see what it was. It in any case make altp2ms behave differently than the hostp2m. The mem_access system has been designed so that the user can say "this domain should now no longer be able to continue if there are EPT violatios and there's no vm_event subscriber attached".

Our application, for one, explicitly _disables_ access_required - so that it is able to detach from the domain and reattach later. Hence the surprise when an altp2m-enabled domain crashed when the introspection agent detached.

Quoted 4 lines

Basically, the altp2m behaviour can't be controlled at all here. Maybe Tamas remembers / knows more about why access_required ended up being 1 always, but it was probably just the quickest way to write the original patch.

CCd Tamas.

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