Skip to contentSkip to conversation

x86/altp2m: Allow setting the #VE info page for an arbitrary VCPU

PATCH Superseded Adrian Pop 5 participants 10 messages Jul 25, 2018 – Aug 27, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Adrian Pop

author
#0 lore raw

PATCH 1/1 x86/altp2m: Allow setting the #VE info page for an arbitrary VCPU

The intended use-case of this patch is to allow either Dom0 or a control domain to activate #VE for an introspected guest, and not having to do this necessarily from an in-guest agent.

---
 tools/libxc/xc_altp2m.c |  1 -
 xen/arch/x86/hvm/hvm.c  | 47 +++++++++++++++++++++++++++++++++--------
 2 files changed, 38 insertions(+), 10 deletions(-)
tools/libxc/xc_altp2m.c +0 -1
index 1c9b572e2b..be5bfd28ed 100644
@@ -68,7 +68,6 @@ int xc_altp2m_set_domain_state(xc_interface *handle, uint32_t dom, bool state)
     return rc;
 }
 
-/* This is a bit odd to me that it acts on current.. */
 int xc_altp2m_set_vcpu_enable_notify(xc_interface *handle, uint32_t domid,
                                      uint32_t vcpuid, xen_pfn_t gfn)
 {
xen/arch/x86/hvm/hvm.c +38 -9

78 lines not on this page · raw message

Signature · 7 lines
2.17.0


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

xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4474

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 25.07.18 at 13:49, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +5 -0
@@ -4467,6 +4467,30 @@ static int hvmop_get_param(
     return rc;
 }
 
+/*
+ * Find the struct vcpu given a dom_id and vcpu_id.
+ * Return NULL if not found.
+ */
+static struct vcpu *__get_vcpu(domid_t domain_id, uint32_t vcpu_id)

No double leading underscores please, and avoid the use of fixed width types when you don't really need it (unsigned int is fine here).

xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4476

Quoted 2 lines
xen/arch/x86/hvm/hvm.c +2 -0
+{
+    struct domain *dom;

We commonly call this just d.

xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4488

Quoted 12 lines
xen/arch/x86/hvm/hvm.c +12 -0
+    struct vcpu *v;
+
+    dom = rcu_lock_domain_by_id(domain_id);
+
+    for_each_vcpu( dom, v )
+    {
+        if ( vcpu_id == v->vcpu_id )
+        {
+            rcu_unlock_domain(dom);
+            return v;
+        }
+    }

for_each_vcpu() looks excessive here - all you need is a bounds check and an access into d->vcpus[]. Together with the fact that your caller has already identified and locked d I wonder whether this helper is needed in the first place.

Quoted 12 lines
xen/arch/x86/hvm/hvm.c +2 -3
@@ -4576,26 +4599,32 @@ static int do_altp2m_op(
 
     case HVMOP_altp2m_vcpu_enable_notify:
     {
-        struct vcpu *curr = current;
+        struct vcpu *v;
         p2m_type_t p2mt;
 
-        if ( a.u.enable_notify.pad || a.domain != DOMID_SELF ||
-             a.u.enable_notify.vcpu_id != curr->vcpu_id )
+        if ( a.u.enable_notify.pad )
         {

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4614

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +4 -2
             rc = -EINVAL;
             break;
         }
 
-        if ( !gfn_eq(vcpu_altp2m(curr).veinfo_gfn, INVALID_GFN) ||
-             mfn_eq(get_gfn_query_unlocked(curr->domain,
+        v = __get_vcpu(a.domain, a.u.enable_notify.vcpu_id);
+        if ( !v )
+        {
+            rc = -EFAULT;

Hardly an appropriate error indicator for the condition.

Quoted 5 lines
xen/arch/x86/hvm/hvm.c +5 -0
+            break;
+        }
+
+        if ( !gfn_eq(vcpu_altp2m(v).veinfo_gfn, INVALID_GFN) ||
+             mfn_eq(get_gfn_query_unlocked(v->domain,

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4627

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +2 -2
                     a.u.enable_notify.gfn, &p2mt), INVALID_MFN) )
         {
             rc = -EINVAL;
             break;
         }
 
-        vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
-        altp2m_vcpu_update_vmfunc_ve(curr);
+        vcpu_altp2m(v).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
+        altp2m_vcpu_update_vmfunc_ve(v);

I'd like you to outline in the description how you mean an external agent to coordinate the use of this GFN with the guest (and in particular without in-guest agent).

Jan

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

#2 lore raw
Quoted 76 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4474

Quoted 13 lines
Quoted 2 lines
Quoted 2 lines · On 25.07.18 at 13:49, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +5 -0
@@ -4467,6 +4467,30 @@ static int hvmop_get_param(
     return rc;
 }
 
+/*
+ * Find the struct vcpu given a dom_id and vcpu_id.
+ * Return NULL if not found.
+ */
+static struct vcpu *__get_vcpu(domid_t domain_id, uint32_t vcpu_id)

No double leading underscores please, and avoid the use of fixed width types when you don't really need it (unsigned int is fine here).

xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4476

Quoted 2 lines
xen/arch/x86/hvm/hvm.c +2 -0
+{
+    struct domain *dom;

We commonly call this just d.

xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4488

Quoted 12 lines
xen/arch/x86/hvm/hvm.c +12 -0
+    struct vcpu *v;
+
+    dom = rcu_lock_domain_by_id(domain_id);
+
+    for_each_vcpu( dom, v )
+    {
+        if ( vcpu_id == v->vcpu_id )
+        {
+            rcu_unlock_domain(dom);
+            return v;
+        }
+    }

for_each_vcpu() looks excessive here - all you need is a bounds check and an access into d->vcpus[]. Together with the fact that your caller has already identified and locked d I wonder whether this helper is needed in the first place.

Quoted 12 lines
xen/arch/x86/hvm/hvm.c +2 -3
@@ -4576,26 +4599,32 @@ static int do_altp2m_op(
 
     case HVMOP_altp2m_vcpu_enable_notify:
     {
-        struct vcpu *curr = current;
+        struct vcpu *v;
         p2m_type_t p2mt;
 
-        if ( a.u.enable_notify.pad || a.domain != DOMID_SELF ||
-             a.u.enable_notify.vcpu_id != curr->vcpu_id )
+        if ( a.u.enable_notify.pad )
         {

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4614

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +4 -2
             rc = -EINVAL;
             break;
         }
 
-        if ( !gfn_eq(vcpu_altp2m(curr).veinfo_gfn, INVALID_GFN) ||
-             mfn_eq(get_gfn_query_unlocked(curr->domain,
+        v = __get_vcpu(a.domain, a.u.enable_notify.vcpu_id);
+        if ( !v )
+        {
+            rc = -EFAULT;

Hardly an appropriate error indicator for the condition.

Quoted 11 lines
xen/arch/x86/hvm/hvm.c +5 -0
+            break;
+        }
+
+        if ( !gfn_eq(vcpu_altp2m(v).veinfo_gfn, INVALID_GFN) ||
+             mfn_eq(get_gfn_query_unlocked(v->domain,
                     a.u.enable_notify.gfn, &p2mt), INVALID_MFN) )
         {
             rc = -EINVAL;
             break;
         }
 
Quoted 8 lines

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4627

Quoted 4 lines
xen/arch/x86/hvm/hvm.c +2 -2
-        vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
-        altp2m_vcpu_update_vmfunc_ve(curr);
+        vcpu_altp2m(v).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
+        altp2m_vcpu_update_vmfunc_ve(v);

I'd like you to outline in the description how you mean an external agent to coordinate the use of this GFN with the guest (and in particular without in-guest agent).

Using #VE without an in-guest agent isn't really possible so this is really just about designating the page from dom0 instead of doing it with the in-guest agent. Something has to be present in the guest to handle the new interrupts coming from #VE after all. I could image a number of ways to coordinate that dom0 agent now setting this page with the guest, my immediate guess is that it would be done through the vm_event guest request channel. But it could also be done through xenstore or even ssh.

Tamas

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

#3 lore raw
Quoted 5 lines · Tamas K Lengyel
Quoted 3 lines · Jan Beulich

I'd like you to outline in the description how you mean an external agent to coordinate the use of this GFN with the guest (and in particular without in-guest agent).

Quoted 8 lines

Using #VE without an in-guest agent isn't really possible so this is really just about designating the page from dom0 instead of doing it with the in-guest agent. Something has to be present in the guest to handle the new interrupts coming from #VE after all. I could image a number of ways to coordinate that dom0 agent now setting this page with the guest, my immediate guess is that it would be done through the vm_event guest request channel. But it could also be done through xenstore or even ssh.

That's exactly what happens - they coordinate via the guest-request vm_event. There's a #VE driver in the guest.

Thanks,
Razvan

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

#4 lore raw
In reply to Tamas K Lengyel
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 31.07.18 at 19:19, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 25.07.18 at 13:49, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2 -2
-        vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
-        altp2m_vcpu_update_vmfunc_ve(curr);
+        vcpu_altp2m(v).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
+        altp2m_vcpu_update_vmfunc_ve(v);
Quoted 8 lines
Quoted 3 lines

I'd like you to outline in the description how you mean an external agent to coordinate the use of this GFN with the guest (and in particular without in-guest agent).

Using #VE without an in-guest agent isn't really possible so this is really just about designating the page from dom0 instead of doing it with the in-guest agent. Something has to be present in the guest to handle the new interrupts coming from #VE after all.

Not necessarily - the exception could also be intercepted, and the external agent be informed, with it taking appropriate action.

Anyway - if such a dependency continues to exist, I think it would be desirable to mention it in the description.

Jan

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

#5 lore raw
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 31.07.18 at 19:19, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4627

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 25.07.18 at 13:49, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2 -2
-        vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
-        altp2m_vcpu_update_vmfunc_ve(curr);
+        vcpu_altp2m(v).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
+        altp2m_vcpu_update_vmfunc_ve(v);

I'd like you to outline in the description how you mean an external agent to coordinate the use of this GFN with the guest (and in particular without in-guest agent).

Quoted 7 lines
Quoted 4 lines

Using #VE without an in-guest agent isn't really possible so this is really just about designating the page from dom0 instead of doing it with the in-guest agent. Something has to be present in the guest to handle the new interrupts coming from #VE after all.

Not necessarily - the exception could also be intercepted, and the external agent be informed, with it taking appropriate action.

Right, but the main attraction of a hypervisor-level agent is that it can't be manipulated at all from within the guest, unlike traditional solutions.

With that in mind, the in-guest agent should be an optimization-only tool, and not allowed to make its own decisions about the core introspection logic.

Thanks,
Razvan

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

#6 lore raw
In reply to Jan Beulich
Quoted 14 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 31.07.18 at 19:19, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 25.07.18 at 13:49, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2 -2
-        vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
-        altp2m_vcpu_update_vmfunc_ve(curr);
+        vcpu_altp2m(v).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
+        altp2m_vcpu_update_vmfunc_ve(v);
Quoted 7 lines
Quoted 3 lines

I'd like you to outline in the description how you mean an external agent to coordinate the use of this GFN with the guest (and in particular without in-guest agent).

Using #VE without an in-guest agent isn't really possible so this is really just about designating the page from dom0 instead of doing it with the in-guest agent. Something has to be present in the guest to handle the new interrupts coming from #VE after all.

Quoted 5 lines

Not necessarily - the exception could also be intercepted, and the external agent be informed, with it taking appropriate action.

Anyway - if such a dependency continues to exist, I think it would be desirable to mention it in the description.

Any setup which intercepts #VE defeats the entire purpose of using #VE in the first place.

We'll eventually have to cope with this situation because its not one we can architecturally rule out (especially with nested virt in the mix), but intercepting #VE is not something we should make available as a user-available option.

~Andrew

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

#7 lore raw
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 01.08.18 at 10:38, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 31.07.18 at 19:19, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4627

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 25.07.18 at 13:49, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2 -2
-        vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
-        altp2m_vcpu_update_vmfunc_ve(curr);
+        vcpu_altp2m(v).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
+        altp2m_vcpu_update_vmfunc_ve(v);

I'd like you to outline in the description how you mean an external agent to coordinate the use of this GFN with the guest (and in particular without in-guest agent).

Using #VE without an in-guest agent isn't really possible so this is really just about designating the page from dom0 instead of doing it with the in-guest agent. Something has to be present in the guest to handle the new interrupts coming from #VE after all.

Quoted 8 lines
Quoted 5 lines

Not necessarily - the exception could also be intercepted, and the external agent be informed, with it taking appropriate action.

Anyway - if such a dependency continues to exist, I think it would be desirable to mention it in the description.

Any setup which intercepts #VE defeats the entire purpose of using #VE in the first place.

Mostly, I agree, but "entire"? You never know how creative people get, and how seeing #VE might better fit their purpose than other "notification" mechanisms.

Jan

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

#8 lore raw
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 01.08.18 at 10:38, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 31.07.18 at 19:19, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 25.07.18 at 13:49, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2 -2
-        vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
-        altp2m_vcpu_update_vmfunc_ve(curr);
+        vcpu_altp2m(v).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
+        altp2m_vcpu_update_vmfunc_ve(v);
Quoted 7 lines
Quoted 3 lines

I'd like you to outline in the description how you mean an external agent to coordinate the use of this GFN with the guest (and in particular without in-guest agent).

Using #VE without an in-guest agent isn't really possible so this is really just about designating the page from dom0 instead of doing it with the in-guest agent. Something has to be present in the guest to handle the new interrupts coming from #VE after all.

Not necessarily - the exception could also be intercepted, and the external agent be informed, with it taking appropriate action.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Anyway - if such a dependency continues to exist, I think it would be desirable to mention it in the description.

Any setup which intercepts #VE defeats the entire purpose of using #VE in the first place.

Mostly, I agree, but "entire"? You never know how creative people get, and how seeing #VE might better fit their purpose than other "notification" mechanisms.

It is either #VE, or EPT_VIOLATION (as that is literally the definition of how #VE gets raised).

With the latter, you get several VMCS fields filled in for you.  For the former, you've got to find the guest physical address which the processor dumped the same information into.

I think I'll safely stick with my "entire" here.

~Andrew

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

author
#9 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich
Quoted 9 lines
xen/arch/x86/hvm/hvm.c +9 -0
+    struct vcpu *v;
+
+    dom = rcu_lock_domain_by_id(domain_id);
+
+    for_each_vcpu( dom, v )
+    {
+        if ( vcpu_id == v->vcpu_id )
+        {
+            rcu_unlock_domain(dom);
Quoted 8 lines

xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4488

Quoted 3 lines
xen/arch/x86/hvm/hvm.c +3 -0
+            return v;
+        }
+    }

for_each_vcpu() looks excessive here - all you need is a bounds check and an access into d->vcpus[]. Together with the fact that your caller has already identified and locked d I wonder whether this helper is needed in the first place.

All right. I'll remove it altogether.

Quoted 16 lines
Quoted 16 lines
xen/arch/x86/hvm/hvm.c +2 -3
@@ -4576,26 +4599,32 @@ static int do_altp2m_op(
 
     case HVMOP_altp2m_vcpu_enable_notify:
     {
-        struct vcpu *curr = current;
+        struct vcpu *v;
         p2m_type_t p2mt;
 
-        if ( a.u.enable_notify.pad || a.domain != DOMID_SELF ||
-             a.u.enable_notify.vcpu_id != curr->vcpu_id )
+        if ( a.u.enable_notify.pad )
         {
             rc = -EINVAL;
             break;
         }
 
Quoted 8 lines

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4614

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +4 -2
-        if ( !gfn_eq(vcpu_altp2m(curr).veinfo_gfn, INVALID_GFN) ||
-             mfn_eq(get_gfn_query_unlocked(curr->domain,
+        v = __get_vcpu(a.domain, a.u.enable_notify.vcpu_id);
+        if ( !v )
+        {
+            rc = -EFAULT;

Hardly an appropriate error indicator for the condition.

I'll change it to -EINVAL.

Quoted 11 lines
Quoted 11 lines
xen/arch/x86/hvm/hvm.c +5 -0
+            break;
+        }
+
+        if ( !gfn_eq(vcpu_altp2m(v).veinfo_gfn, INVALID_GFN) ||
+             mfn_eq(get_gfn_query_unlocked(v->domain,
                     a.u.enable_notify.gfn, &p2mt), INVALID_MFN) )
         {
             rc = -EINVAL;
             break;
         }
 
Quoted 8 lines

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4627

Quoted 4 lines
xen/arch/x86/hvm/hvm.c +2 -2
-        vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
-        altp2m_vcpu_update_vmfunc_ve(curr);
+        vcpu_altp2m(v).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
+        altp2m_vcpu_update_vmfunc_ve(v);

I'd like you to outline in the description how you mean an external agent to coordinate the use of this GFN with the guest (and in particular without in-guest agent).

I'll try to clarify this.

Thank you!

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