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

[PATCH v2 11/21] libs/guest: allow fetching a specific MSR entry from a cpu policy


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Tue, 13 Apr 2021 16:01:29 +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=hKIl+cZikbO/4WJIAGz+bxYAoaTNWAIK2jf+mYY0UCM=; b=OWJQpY6jCTciNieYCrLfl7LWvYD+ngeTTrArie6Jhj1UY5e9i0pskFgwDE4ZFJ9UCdvXYTzTYNWPBexneu78R6WGo6jUqktex5TZnRrSEwcSEluwMNqJuzDU6cNv79zu63IJW6eM56NpXJDZaVJKSm64WdUkn5peZNwYn91fHpYgc2LuQPOz/BBcn43rxYUBVYo6Sm/qkijnXsYVV6bCiGnjASC2XCTIPlrov2RGsdH1vGVetxGBRN8tXkCx6AZVK/ko+sko6eoJRmkWulnFVQuidhCKcSB3r9z0NnYhr8/BfXJ9xn7+IbWtdAz56whI/hxZ+b7bMNe2d3vOLFogvA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ndQWx12gb9xkL2GKqeL3NpeARs48k7hLbpNcwk5sEAnOrAH/6CNEiqgHWJ2JKBwrocnNULp4An71EFLVvdDE2xFfUejnZfjfT5qFbZXySOZ3ib+nWehsDf8dVnE4Dk8oHoBKF8gel+IyXcdhfus9rvpnV9Q41JySXvKU9+BJ4B+Ij8lch92rcsmRwaQVaklCLdiKUfV0GJzE2q7Thx8fT+ZvZhNYGKwPEv7TTAMBLoPuhyRpFWAo1D+M4q8MZGDPb0kh2c5CR4ThcDRdWYjrnKGMzZgrSvckBc6398bwhsnh17RffNCRo5host+px5DDiiwVpPQVehTi8vYiq409NQ==
  • Authentication-results: esa4.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: Tue, 13 Apr 2021 14:03:02 +0000
  • Ironport-hdrordr: A9a23:T0IZcKhMHAzHEeHXjV0CZE9l83BQX19w3DAbvn1ZSRFFG/Gwv/ uF2NwGyB75jysQUnk8mdaGfJKNW2/Y6IQd2+YsFJ+Ydk3DtHGzJI9vqbHjzTrpBjHk+odmuZ tIW5NVTOf9BV0St6vHySGlDtctx8SG+qi0heHYi0xgVx1udrsI1WZEIyywe3cGIDVuL5w/CZ aa+457vDKmY3sadYCWAXMCUujFqbTw5e7bSDQBAAMq7xTLsCOw5NfBYmWl9zo9cxcK+7ct9m DZjxf0j5/Mj9iXwgLRvlWjiah+t8DmzrJ4da6xo+gTbg7hkwO5ILlmMofyxwwdhMGKxBIUnM LXoxEmVv4Dm0/5Wm2uuxPi103B/V8Vmgbf4GSVi3fivsD1LQhSY6Eq5fM7A2nkwnEts91m3K VA03jxjessMTr6kDng/N+Nbhl2lyOP0AsfuNQOhH9SW5Z2Us43kaUj+ipuYfI9NRO/woUmHO 5yNdrb9fZbfHiLBkqpwFVH8ZiCWG8+EQyBRVVHksuJ0yJOlHQ89EcAwtcD901wuK4Vet1h3a DpI65onLZBQos/ar98Pv4IRY+SBnbWSRzBHWqOKT3cZe46EkOIj6SyzKQ+5emsdpBN5oA1go 79XFRRsnN3U17yCOWVtac7sizlcSGYZ3DA28te7592tvnXX7zwKxCOT1gojo+Jv+gfOMvGQP y+UagmQsPLHC/LI8Jkzgf+U55dJT01S8sOoOs2XFqIv4blMYvvmu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drojmwBMzby3vmHSAE9JG8LQSIvT/jBUdp7 lxhhDl6DmoIPkEhrb/brB/3bsvlOPCz3zH1pyoPVHx58AZyFm/HkU21yre+2ouxEdpewNlJnCC Mh9M+7lcodjEk8p9sZgJ1odEwSEtNCbQqOfpjr9OtD/rnqb/5o0iGbC6U48X6ucK78O8Ax0A59 +8M=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Introduce an interface that returns a specific MSR entry from a cpu
policy in xen_msr_entry_t format. Provide a helper to perform a binary
search against an array of MSR entries.

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.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Changes since v1:
 - Introduce a helper to perform a binary search of the MSR entries
   array.
---
 tools/include/xenctrl.h         |  2 ++
 tools/libs/guest/xg_cpuid_x86.c | 42 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index cbca7209e34..605c632cf30 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2611,6 +2611,8 @@ int xc_cpu_policy_serialise(xc_interface *xch, const 
xc_cpu_policy_t policy,
 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_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t policy,
+                          uint32_t msr, xen_msr_entry_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 d146c5bbc99..a4307d50ddb 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -845,3 +845,45 @@ int xc_cpu_policy_get_cpuid(xc_interface *xch, const 
xc_cpu_policy_t policy,
     *out = *tmp;
     return 0;
 }
+
+static int compare_entries(const void *l, const void *r)
+{
+    const xen_msr_entry_t *lhs = l;
+    const xen_msr_entry_t *rhs = r;
+
+    if ( lhs->idx == rhs->idx )
+        return 0;
+    return lhs->idx < rhs->idx ? -1 : 1;
+}
+
+static xen_msr_entry_t *find_entry(xen_msr_entry_t *entries,
+                                   unsigned int nr_entries, unsigned int index)
+{
+    const xen_msr_entry_t key = { index };
+
+    return bsearch(&key, entries, nr_entries, sizeof(*entries), 
compare_entries);
+}
+
+int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t policy,
+                          uint32_t msr, xen_msr_entry_t *out)
+{
+    unsigned int nr_entries = ARRAY_SIZE(policy->entries);
+    xen_msr_entry_t *tmp;
+    int rc;
+
+    rc = xc_cpu_policy_serialise(xch, policy, NULL, 0,
+                                 policy->entries, &nr_entries);
+    if ( rc )
+        return rc;
+
+    tmp = find_entry(policy->entries, nr_entries, msr);
+    if ( !tmp )
+    {
+        /* Unable to find a matching MSR. */
+        errno = ENOENT;
+        return -1;
+    }
+
+    *out = *tmp;
+    return 0;
+}
-- 
2.30.1




 


Rackspace

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