[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 12/21] libs/guest: allow updating a cpu policy MSR data
- To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
- Date: Tue, 23 Mar 2021 10:58:40 +0100
- 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=/3WiOg86VPd8L28F4qhC0/C6RZk1orVvsRJ5t1bdvfc=; b=nqAC3p/WoP+h5dthD9zobly7JWmH7SJYYPGzR7tjpc6dR6/YVessvhhwB3h38zHJLftDn6pgYGQm1VLStJBfZ8dpwEdUdb61vtPxPnjjv5Ugeoh/xEIf5N8prRJtT4dJ91wLaOcmnaeSoUd7t0k4EuJ7wuG0sMHFhtX7GvHx5wSPLvM3B8I7AvAiFoJmfFoKa23xAbxJM1QY028Mwmr/ycRGMoBZOVMcuqTG0yCHnuppxHdH5mzsI/Xm/TNNQhGWF30M1MVgmbDqwT/H4QklgKutqYxNJCmYwqPt84sPYlBMkvu4RfKvEI6qlcet20nTexWqrqbIi+xTsAqIEwr0wg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WKgRxfXU5qXLkh+zQxN10xz5TtDTH7tVQTa/Qrk6bNTZmvmSyNMUF9SGkr+66nFO25CKms52sgMG0RmBoS6LzMEV7QwIfZ2VvYPx1mMr8ofUVrncT4vWR32Y9PXTWjFRL6PJzAoJj+CTjuGF/VDaWLZLnlr4puiTuPkjhLR+nz6xGXDfT7F8zhSHNxVmGpqv9lKi0+H8wIjNA5IQ238YKEaJXEp6En34B4fXFpKUBSTpp09XxLwRMF9Jc463sRKq0Uoo3HMATjpeMlJz8ji0Isaa4MGKvSdusqfNvYT60HShE5bXvOixvGxSfO61Hf34CvLLhC9RqsANXnMmUmRsMQ==
- Authentication-results: esa5.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, 23 Mar 2021 10:07:51 +0000
- Ironport-hdrordr: A9a23:Sh0DAqtK4HkPV5dJOzZPj0B97skCCYcji2hD6mlwRA09T+WxrO rrtOgH1BPylTYaUGwhn9fFA6WbXXbA7/dOjbU5FYyJGC3ronGhIo0n14vtxDX8Bzbzn9Qx6Y 5JSII7MtH5CDFB5/rSyAOzH888hPyO9661jenTpk0dND1CQYsI1WZEIyycFVB7QxQDIJI/Go aV6MYvnUvZRV08aMOnCn4ZG9XSvtGjruOsXTcqJT4CrDOPgzSh9aLgH3GjtSs2fjtTzd4ZgA 34uiPj4KHLiZ6G4z/ak1Te9pFH3Obmo+EzYvCkrugwBnHShh2zZIJnMofy9gwdhO208l4lnJ 3tjn4bTqBOwkjcdG20vhfhsjOIuAoG0HPsxUSVhnHuu6XCNVUHIvBcjoFUeAax0Sodlex8y6 5C0ia4sJdaHHr77UbAzuXITB1jmw6Ip2Mjm4co/h9ieLYZAYU+kaUvuGduVLsQFiPz744qVM N0CtvH2fpQeVSGK1jEo2hG2rWXLzkONybDZnJHlt2e0jBQknw85VAf3tYjknAJ8494Y4VY5t 7DLr9jmNh1P4MrRJM4IN1Ebdq8C2TLTx6JGnmVO07bGKYOPG+IjJLr/rMv5qWPdIYTxJU/3L TNOWko+lIaSgbLM4mjzZdL+hfCTCGWRjL20PxT4JB/p/nyX7zuPSqfSE0/kseprvkFa/erGs qbCdZzObvOPGHuEYFG00nVQJ9JM0QTV8UTp5I6Vju104L2A7yvktaeXOfYJbLrH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908N7eLj90uPzlfEe0RW0AWNmjxKKXhbN2wO7cc luk2MLgJ054Eo7MFKfPW55bftPxJNfDgc22zgkFF1f4bNWXy9Cy71tAWJws1XBWHTGF2tpBmRS jeLERQjWuvvghdcBw5BCt+NLJTrxrce6SKkkjRDj//jAp0JaNqLGNJSxFLL//EJVYwcMcBDsEa Asuj0Pr3291OjZPSPxDWjP/QrtaTwyRMXPrwmZFuXki3a1W9MjnCwzt+EXYZMK6t2m+K5KOkES NPA=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
Introduce a helper to update the MSR policy using an array of
xen_msr_entry_t entries. Note the MSRs present in the input
xen_msr_entry_t array will replace any existing entries on the
policy.
No user of the interface introduced on this patch.
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
tools/include/xenctrl.h | 2 +
tools/libs/guest/xg_cpuid_x86.c | 65 +++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index 2143478fe4b..46f5026081c 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2616,6 +2616,8 @@ int xc_cpu_policy_get_msr(xc_interface *xch, const
xc_cpu_policy_t policy,
int xc_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_policy_t policy,
const xen_cpuid_leaf_t *leaves,
uint32_t nr);
+int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t policy,
+ const xen_msr_entry_t *msrs, uint32_t nr);
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 13c2972ccd3..07756743e76 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -1033,3 +1033,68 @@ int xc_cpu_policy_update_cpuid(xc_interface *xch,
xc_cpu_policy_t policy,
free(current);
return rc;
}
+
+int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t policy,
+ const xen_msr_entry_t *msrs, uint32_t nr)
+{
+ unsigned int err_msr = -1;
+ unsigned int nr_leaves, nr_msrs, i, j;
+ xen_msr_entry_t *current;
+ int rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs);
+
+ if ( rc )
+ {
+ PERROR("Failed to obtain policy info size");
+ return -1;
+ }
+
+ current = calloc(nr_msrs, sizeof(*current));
+ if ( !current )
+ {
+ PERROR("Failed to allocate resources");
+ errno = ENOMEM;
+ return -1;
+ }
+
+ rc = xc_cpu_policy_serialise(xch, policy, NULL, 0, current, &nr_msrs);
+ if ( rc )
+ goto out;
+
+ for ( i = 0; i < nr; i++ )
+ {
+ const xen_msr_entry_t *update = &msrs[i];
+
+ for ( j = 0; j < nr_msrs; j++ )
+ if ( current[j].idx == update->idx )
+ {
+ /*
+ * NB: cannot use an assignation because of the const vs
+ * non-const difference.
+ */
+ memcpy(¤t[j], update, sizeof(*update));
+ break;
+ }
+
+ if ( j == nr_msrs )
+ {
+ /* Failed to find a matching MSR, append to the end. */
+ current = realloc(current, (nr_msrs + 1) * sizeof(*current));
+ memcpy(¤t[nr_msrs], update, sizeof(*update));
+ nr_msrs++;
+ }
+ }
+
+ rc = x86_msr_copy_from_buffer(policy->msr, current, nr_msrs, &err_msr);
+ if ( rc )
+ {
+ ERROR("Failed to deserialise MSRS (err index %#x) (%d = %s)",
+ err_msr, -rc, strerror(-rc));
+ errno = -rc;
+ rc = -1;
+ }
+
+ out:
+ free(current);
+ return rc;
+
+}
--
2.30.1
|