All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xen-devel] [PATCH v1] x86/altp2m: Add hypercall to create a new view and set sve bits
@ 2019-09-02  8:11 Alexandru Stefan ISAILA
  2019-09-03 15:52 ` Jan Beulich
  2019-09-05  8:02 ` Julien Grall
  0 siblings, 2 replies; 14+ messages in thread
From: Alexandru Stefan ISAILA @ 2019-09-02  8:11 UTC (permalink / raw)
  To: xen-devel
  Cc: kevin.tian, sstabellini, jun.nakajima, wl, konrad.wilk,
	george.dunlap, andrew.cooper3, ian.jackson, tim, julien.grall,
	jbeulich, Alexandru Stefan ISAILA, roger.pau

By default the sve bits are not set.
This patch adds the option of setting the sve bits upon creating a new
altp2m view.

Signed-off-by: Alexandru Isaila <aisaila@bitdefender.com>
---
 tools/libxc/include/xenctrl.h     |  3 +++
 tools/libxc/xc_altp2m.c           | 28 ++++++++++++++++++++++++++++
 xen/arch/x86/hvm/hvm.c            |  3 ++-
 xen/arch/x86/mm/p2m-ept.c         | 19 ++++++++++++++++++-
 xen/arch/x86/mm/p2m.c             | 10 +++++-----
 xen/include/asm-x86/hvm/vmx/vmx.h |  2 +-
 xen/include/asm-x86/p2m.h         |  2 +-
 xen/include/public/hvm/hvm_op.h   |  1 +
 8 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 0ff6ed9e70..86702e5df8 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -1925,6 +1925,9 @@ int xc_altp2m_set_vcpu_disable_notify(xc_interface *handle, uint32_t domid,
                                       uint32_t vcpuid);
 int xc_altp2m_create_view(xc_interface *handle, uint32_t domid,
                           xenmem_access_t default_access, uint16_t *view_id);
+int xc_altp2m_create_view_set_sve(xc_interface *handle, uint32_t domid,
+                                  xenmem_access_t default_access,
+                                  uint16_t *view_id, bool set_sve);
 int xc_altp2m_destroy_view(xc_interface *handle, uint32_t domid,
                            uint16_t view_id);
 /* Switch all vCPUs of the domain to the specified altp2m view */
diff --git a/tools/libxc/xc_altp2m.c b/tools/libxc/xc_altp2m.c
index a86520c232..aeb9f36ea0 100644
--- a/tools/libxc/xc_altp2m.c
+++ b/tools/libxc/xc_altp2m.c
@@ -139,6 +139,34 @@ int xc_altp2m_create_view(xc_interface *handle, uint32_t domid,
     return rc;
 }
 
+int xc_altp2m_create_view_set_sve(xc_interface *handle, uint32_t domid,
+                                  xenmem_access_t default_access,
+                                  uint16_t *view_id, bool set_sve)
+{
+    int rc;
+    DECLARE_HYPERCALL_BUFFER(xen_hvm_altp2m_op_t, arg);
+
+    arg = xc_hypercall_buffer_alloc(handle, arg, sizeof(*arg));
+    if ( arg == NULL )
+        return -1;
+
+    arg->version = HVMOP_ALTP2M_INTERFACE_VERSION;
+    arg->cmd = HVMOP_altp2m_create_p2m;
+    arg->domain = domid;
+    arg->u.view.view = -1;
+    arg->u.view.hvmmem_default_access = default_access;
+    arg->u.view.set_sve = set_sve;
+
+    rc = xencall2(handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m,
+                  HYPERCALL_BUFFER_AS_ARG(arg));
+
+    if ( !rc )
+        *view_id = arg->u.view.view;
+
+    xc_hypercall_buffer_free(handle, arg);
+    return rc;
+}
+
 int xc_altp2m_destroy_view(xc_interface *handle, uint32_t domid,
                            uint16_t view_id)
 {
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 029eea3b85..95d382b114 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -4627,7 +4627,8 @@ static int do_altp2m_op(
     }
 
     case HVMOP_altp2m_create_p2m:
-        if ( !(rc = p2m_init_next_altp2m(d, &a.u.view.view)) )
+        if ( !(rc = p2m_init_next_altp2m(d, &a.u.view.view,
+                                         a.u.view.set_sve)) )
             rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0;
         break;
 
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index 6b8468c793..255ed97734 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -1339,7 +1339,7 @@ void setup_ept_dump(void)
     register_keyhandler('D', ept_dump_p2m_table, "dump VT-x EPT tables", 0);
 }
 
-void p2m_init_altp2m_ept(struct domain *d, unsigned int i)
+void p2m_init_altp2m_ept(struct domain *d, unsigned int i, bool set_sve)
 {
     struct p2m_domain *p2m = d->arch.altp2m_p2m[i];
     struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
@@ -1355,6 +1355,23 @@ void p2m_init_altp2m_ept(struct domain *d, unsigned int i)
     ept = &p2m->ept;
     ept->mfn = pagetable_get_pfn(p2m_get_pagetable(p2m));
     d->arch.altp2m_eptp[i] = ept->eptp;
+
+    if ( set_sve )
+    {
+        unsigned long gfn = 0, max_gpfn = domain_get_maximum_gpfn(d);
+
+        for( ; gfn < max_gpfn; ++gfn )
+        {
+            mfn_t mfn;
+            p2m_access_t a;
+            p2m_type_t t;
+
+            altp2m_get_effective_entry(p2m, _gfn(gfn), &mfn, &t, &a,
+                                       AP2MGET_query);
+            p2m->set_entry(p2m, _gfn(gfn), mfn, PAGE_ORDER_4K, t, a, true);
+
+        }
+    }
 }
 
 unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp)
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index 8a5229ee21..4ec61740f6 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -2528,7 +2528,7 @@ void p2m_flush_altp2m(struct domain *d)
     altp2m_list_unlock(d);
 }
 
-static int p2m_activate_altp2m(struct domain *d, unsigned int idx)
+static int p2m_activate_altp2m(struct domain *d, unsigned int idx, bool set_sve)
 {
     struct p2m_domain *hostp2m, *p2m;
     int rc;
@@ -2554,7 +2554,7 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx)
         goto out;
     }
 
-    p2m_init_altp2m_ept(d, idx);
+    p2m_init_altp2m_ept(d, idx, set_sve);
 
  out:
     p2m_unlock(p2m);
@@ -2572,13 +2572,13 @@ int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx)
     altp2m_list_lock(d);
 
     if ( d->arch.altp2m_eptp[idx] == mfn_x(INVALID_MFN) )
-        rc = p2m_activate_altp2m(d, idx);
+        rc = p2m_activate_altp2m(d, idx, false);
 
     altp2m_list_unlock(d);
     return rc;
 }
 
-int p2m_init_next_altp2m(struct domain *d, uint16_t *idx)
+int p2m_init_next_altp2m(struct domain *d, uint16_t *idx, bool set_sve)
 {
     int rc = -EINVAL;
     unsigned int i;
@@ -2590,7 +2590,7 @@ int p2m_init_next_altp2m(struct domain *d, uint16_t *idx)
         if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
             continue;
 
-        rc = p2m_activate_altp2m(d, i);
+        rc = p2m_activate_altp2m(d, i, set_sve);
 
         if ( !rc )
             *idx = i;
diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h
index ebaa74449b..7707f1768f 100644
--- a/xen/include/asm-x86/hvm/vmx/vmx.h
+++ b/xen/include/asm-x86/hvm/vmx/vmx.h
@@ -598,7 +598,7 @@ void ept_p2m_uninit(struct p2m_domain *p2m);
 void ept_walk_table(struct domain *d, unsigned long gfn);
 bool_t ept_handle_misconfig(uint64_t gpa);
 void setup_ept_dump(void);
-void p2m_init_altp2m_ept(struct domain *d, unsigned int i);
+void p2m_init_altp2m_ept(struct domain *d, unsigned int i, bool set_sve);
 /* Locate an alternate p2m by its EPTP */
 unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp);
 
diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h
index 94285db1b4..c85c91819e 100644
--- a/xen/include/asm-x86/p2m.h
+++ b/xen/include/asm-x86/p2m.h
@@ -884,7 +884,7 @@ bool p2m_altp2m_get_or_propagate(struct p2m_domain *ap2m, unsigned long gfn_l,
 int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx);
 
 /* Find an available alternate p2m and make it valid */
-int p2m_init_next_altp2m(struct domain *d, uint16_t *idx);
+int p2m_init_next_altp2m(struct domain *d, uint16_t *idx, bool set_sve);
 
 /* Make a specific alternate p2m invalid */
 int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int idx);
diff --git a/xen/include/public/hvm/hvm_op.h b/xen/include/public/hvm/hvm_op.h
index c6cd12f596..924d947e78 100644
--- a/xen/include/public/hvm/hvm_op.h
+++ b/xen/include/public/hvm/hvm_op.h
@@ -244,6 +244,7 @@ struct xen_hvm_altp2m_view {
     /* Create view only: default access type
      * NOTE: currently ignored */
     uint16_t hvmmem_default_access; /* xenmem_access_t */
+    uint8_t set_sve; /* bool value */
 };
 typedef struct xen_hvm_altp2m_view xen_hvm_altp2m_view_t;
 DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_view_t);
-- 
2.17.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-10-25 14:40 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-02  8:11 [Xen-devel] [PATCH v1] x86/altp2m: Add hypercall to create a new view and set sve bits Alexandru Stefan ISAILA
2019-09-03 15:52 ` Jan Beulich
2019-09-03 17:24   ` Tamas K Lengyel
2019-10-23  9:11     ` Alexandru Stefan ISAILA
2019-10-23 11:58       ` Roger Pau Monné
2019-10-25 14:36         ` Alexandru Stefan ISAILA
2019-10-25 14:40           ` Alexandru Stefan ISAILA
2019-09-04 11:51   ` Alexandru Stefan ISAILA
2019-09-04 12:14     ` Jan Beulich
2019-09-04 13:04       ` Alexandru Stefan ISAILA
2019-09-04 13:17         ` Jan Beulich
2019-09-04 14:14           ` Alexandru Stefan ISAILA
2019-09-04 14:26             ` Jan Beulich
2019-09-05  8:02 ` Julien Grall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.