[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 03/13] libs/guest: allow fetching a specific MSR entry from a cpu policy
- To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
- Date: Fri, 30 Apr 2021 17:52:01 +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=ReYtIhfneceED5ekYrJYnGrommG0WKr3NQgh92cs/8w=; b=icTsCbe+UVNYdBLCQTWMeQKJm0/psLBXHZEaeNYx49KVLkZ9ButF0GYANcvuASYmSuy1S9YVb9oVo0nyA4d7G8ncdkQJ2DNcxJEzJCoQZ6QtK5K7uPFzxW3DLz39vfuICKIctSDZdJnmQdRQoH9xIqSNcsQD7AXIegFNZwAq0sg9m2AeAyMHq7XRfw+sH9irRtbN+CB7JINZ1v52L8QkdhnvUGYqEss7mJYM1UH8g0w/OjExwn+C+6iqNxC7R1pUgjAs8Qmnz0GcCMy7ldJjqOIatHVOaBm6ZhiRcqEfzs7BYziOKGoGP0s4xmsv+PxYY1pMWooATMaMBvO8WGiZpA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gx8PbYQeGFznCJLGvd1TDRysETJAgN+yBr/NvxucF2bquHkGsB1zocYjqwEVGWfnu5wu1XC2y5JsnB0AM6L66yNKAyjPFH6O/XErj1aj/xDyIcyhhEKd1LsqnL/2tsWEpuSnHVL/Spb6q9CaLqewvQzDpqWywemkCKreitEe8eqxeAeqOQzbaGkUGmOkHhazEfeTk/p/shypTxCzcFXaJAUTuvCeOTlqbr7rJh9THMTnlvfYysXvyXHZWrICC+9N1lgGHyDVcwhLUFRPMgICZZfrawI+OKG4K8hqL/N+L/rr3XYSfM+37SDHahkclrZJzE388C3PX7sLtUlSC8C10A==
- Authentication-results: esa1.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:54 +0000
- Ironport-hdrordr: A9a23:4mjqk6zUzNbHoIIWf9mMKrPxvu4kLtp033Aq2lEZdDV8Sebdv9 yynfgdyB//gCsQXnZlotybJKycWxrnmKJdybI6eZOvRhPvtmftFoFt6oP+3ybtcheVysd07o 0lSaR3DbTLZmRSpczx7BCkV/Mpx9ea+K6l7N2utktFZwdsdq1m8kNdAgGUDkV5SGB9dOIEPb Cb4ddKoCflRGQPYq2AdzI4dsXKutGjruOCXTcoHBgigTPhsRqJ7/rAHwGczlMiVVp0sNEf2E zktyC82am5qfG8zXbnpiXuxrBbgsHoxNcGJOHksLlwFhzWhgylZJtsVtS51VhYz92H01oknM LBpB0tJa1ImhTsV1uoqhjg0RSI6lYTwkLi0lORjD/CpsH0VVsBeqh8rL9ZaRfQ5g4cush92s twrgGknqdQZCmgoA3No/zzEz16nEu9pnQv1cQJiWZEbIcYYLhN6aQC4UJ8Cv47bW7HwbFiNN MrINDX5f5Qf1/fRWvepHNTzNulWWl2NguaQ3IFptee31Ft7T9E5npd4PZasmYL9Zo7RZUBzf /DKL5UmLZHSdJTSq5hGuEbQ4+SBnbWSRzBdEKeSG6XWp0vCjbokdra8b817OaldNgj150pgq nMV1teqCo8YETrBcqS3IBa8xzETWmnNA6div121txcgPnRVbDrOSqMRBQFiM27ucgSBcXdRr KyNfttcrzeBFqrPbwM8xz1WpFUJ3VbetYSoMwHV1WHpd+OLoXrs+fcYevCPbaFK0dnZkrPRl 84GBTjLsRJ6U6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ReFMODiZYVYwOqhw9DrxCSMoLi0o97IvNPm0KtNXATeu y0aZ5dVT+T+SBab/yPAy8oO9CeTW7mh/vAX6gc3ghWbbP3BI3d53eZZ9fXq05+cS5x93womncf t2A=
- 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 de27826f415..9e83daca0e6 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -850,3 +850,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.31.1
|