[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 02/13] libs/guest: allow fetching a specific CPUID leaf from a cpu policy


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Fri, 30 Apr 2021 17:52:00 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KyuIaS7BuF4VGyvgnC9lay8BjM2lepDtuERfKu+QpZI=; b=Ho9w5l4D05LOQBrKs2JJrJgvOcRfpYogmO7GKcFcmPTkAv7G3SbI9H1YbYozvqDzKVhdAVwq2UMcW0Drsol2YbUywN6vqV4dnSD88a2Wl7Y+sDOSMB8CE5bkJREl4i9qI+D19bfA1VF4o9l9ODr0fnWbKYNVtmUcFx2Di/Sjw3BuHqOcEJat1xloOwv88KI1e9DyL/fOhrLhL1lS5o0wVgZNm1UnGc4+9W/fzHqVu2i4fnAxdV4ZW01Smn7nswFyeGz7WOMdJ+U+05qdRDiZ8Ipq8hK/rfow/e7qIr1Y21lzwCoK3wOhk4kVwVlXFzvG6xT60zEPK8jBE7D+JyIw6g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JkvwYiCWizhVRJhxjAXQcWx10lPZGXM73BL/g6Iu+E9o2Cy26PmXbKkq63W5wWhvb1/x1dg9Ll2MnHkZ51FVN0oB9WjqO25lOiS8zB2GDXj/w8CWR6rud1uG0f5ovJPRATwit7c4mA60jBrj0v/c0VuLPEZFFl/MfFl5Ca3HZu6pMowIspQVJ/1vclJDWl1YKjR1jwmO2kowXYh4BHcDeFDo4vFdrWZf6Bzcv4mL2Swmxbi4N4jEYSbWE+WPHRoMXKgYFiPuTO29teBDJyiObcQPKORdAgdfgrlIe3pSBDDfB5xiTAltphAy+JSveL3EBW87t1LlNavBKj3hqHpm2g==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 30 Apr 2021 15:53:53 +0000
  • Ironport-hdrordr: A9a23:6mjpAqiS7RJv/QE8O2Enh51B/3BQXiUji2hD6mlwRA09T+Wzkc eykPMHkSLlkTp5Yh0dsP2jGI3Fe3PT8pZp/ZIcVI3IYCDKsHalRbsM0aLM2DvlcheRysd42b 17e6ZzTP3cZGIK7vrSxAm9H5IezMKc8Kau7N2+815XQQtna75t4m5CY27wf3FefhVMBpYyCf Onl6h6jgenEE52Uu2LQlUDQujft5nqufvdEHo7Li9i0ifLoROEgYSKdiSl4g==
  • Ironport-sdr: q8NT5IUDhpvBjtZh+pb8MBXK9/TJdmwxRNo+2fz1mnU96RaPnIR2pzn7HTUxjLuBIytJ+hpXsI GMVW1rxcqOakF9BEdEBu9oSG6zWhdyxubWdIKHzkAMYg/Js1ToIhbkKXBWlH0uU3djZ5F28SEV oJv3QDpfzaDSVoX6X6QjHzEDQMWJa3MsvSgJI6VCUPCjxfxBbwsbJCaqBys7yTi+2ux5jlX3yW DIhhCbT74zpoeD8MlZK//GulgnfTm9LqYu/Zkd0+i5BHo/jwlIaqgSnsfxxld5Zmww56VQsLTI qw8=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Introduce an interface that returns a specific leaf/subleaf from a cpu
policy in xen_cpuid_leaf_t format.

This is useful to callers can peek data from the opaque
xc_cpu_policy_t type.

No caller of the interface introduced on this patch.

Note that callers of find_leaf need to be slightly adjusted to use the
new helper parameters.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Changes since v1:
 - Use find leaf.
---
 tools/include/xenctrl.h         |  3 +++
 tools/libs/guest/xg_cpuid_x86.c | 38 ++++++++++++++++++++++++++++-----
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index 27cec1b93ff..cbca7209e34 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2608,6 +2608,9 @@ int xc_cpu_policy_set_domain(xc_interface *xch, uint32_t 
domid,
 int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t policy,
                             xen_cpuid_leaf_t *leaves, uint32_t *nr_leaves,
                             xen_msr_entry_t *msrs, uint32_t *nr_msrs);
+int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t policy,
+                            uint32_t leaf, uint32_t subleaf,
+                            xen_cpuid_leaf_t *out);
 
 int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);
 int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index 0c9b3a960f0..de27826f415 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -280,9 +280,9 @@ static int compare_leaves(const void *l, const void *r)
 
 static xen_cpuid_leaf_t *find_leaf(
     xen_cpuid_leaf_t *leaves, unsigned int nr_leaves,
-    const struct xc_xend_cpuid *xend)
+    unsigned int leaf, unsigned int subleaf)
 {
-    const xen_cpuid_leaf_t key = { xend->leaf, xend->subleaf };
+    const xen_cpuid_leaf_t key = { leaf, subleaf };
 
     return bsearch(&key, leaves, nr_leaves, sizeof(*leaves), compare_leaves);
 }
@@ -365,9 +365,12 @@ static int xc_cpuid_xend_policy(
     rc = -EINVAL;
     for ( ; xend->leaf != XEN_CPUID_INPUT_UNUSED; ++xend )
     {
-        xen_cpuid_leaf_t *cur_leaf = find_leaf(cur, nr_cur, xend);
-        const xen_cpuid_leaf_t *def_leaf = find_leaf(def, nr_def, xend);
-        const xen_cpuid_leaf_t *host_leaf = find_leaf(host, nr_host, xend);
+        xen_cpuid_leaf_t *cur_leaf = find_leaf(cur, nr_cur,
+                                               xend->leaf, xend->subleaf);
+        const xen_cpuid_leaf_t *def_leaf = find_leaf(def, nr_def,
+                                                     xend->leaf, 
xend->subleaf);
+        const xen_cpuid_leaf_t *host_leaf = find_leaf(host, nr_host, 
xend->leaf,
+                                                      xend->subleaf);
 
         if ( cur_leaf == NULL || def_leaf == NULL || host_leaf == NULL )
         {
@@ -822,3 +825,28 @@ int xc_cpu_policy_serialise(xc_interface *xch, const 
xc_cpu_policy_t p,
     errno = 0;
     return 0;
 }
+
+int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t policy,
+                            uint32_t leaf, uint32_t subleaf,
+                            xen_cpuid_leaf_t *out)
+{
+    unsigned int nr_leaves = ARRAY_SIZE(policy->leaves);
+    xen_cpuid_leaf_t *tmp;
+    int rc;
+
+    rc = xc_cpu_policy_serialise(xch, policy, policy->leaves, &nr_leaves,
+                                 NULL, 0);
+    if ( rc )
+        return rc;
+
+    tmp = find_leaf(policy->leaves, nr_leaves, leaf, subleaf);
+    if ( !tmp )
+    {
+        /* Unable to find a matching leaf. */
+        errno = ENOENT;
+        return -1;
+    }
+
+    *out = *tmp;
+    return 0;
+}
-- 
2.31.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.