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

[PATCH 11/21] libs/guest: allow updating a cpu policy CPUID data


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Tue, 23 Mar 2021 10:58:39 +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=VUfWBdInOKZs5Um38UoLo/Lo9GJ2byqnYqx1gF9ZJ6M=; b=cGabuRCSEPAl9Cb7vL/2OQNC264wpsjMAIhDowdVM0jHXuNGO152K7Gw3w8GKNmaV0tcPk9qJHovMXgn/5G6oSma3aE7t7eYFNLrU/uJ8K2q12G3rj/YDTHCfSjFjlXm+fheAk0GvcHI15daiQzdSQr4uCPUq7k9n9TDg7vPI8drk+KL84vStfn9HTbmAEocwtdA+/iZdfr7svNXmOBAJCIpcqhbpZkKa406m2dMvIyp2jz7F7FB82jdEYDx87mMoQDZf9/W4Yw2+igZNR/j17cTdkzh5OJ1IfOaaVYUinTfD9bTUr/3m8m+UGzz57jSFyVZHDjT51NE5vlvM7cl6Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZivyjKQBEOwHlLooMKDAqf6CUffsvfee104m6wGtNCfkSaHOBnXm7NvueKuDLRHoHqMo6KO2nEHUMkQYt/2Y/57s08y+ng65fsgiCsFqt2PV31l6xUL387kf6PPyFexF9xunIbmFFKAL9yAo8T3DTmsw191O0bVPf9SkUB2BaIbMCavnanFnzWxZS8Iah4fIwpDBCQiKSxFuYMRI8g+PzqEn9WuY5+vGOCeJwFMt2ZXRhJM81sBA9RV+gVfaQs0JOoShT6LF8WqD6z9+2yllMhj3GV0zu0tCobVbNxEv45o6mK2N/PuV2PjCrWWL9/doUDCiS5ldO5rszj784G6k1Q==
  • 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: Tue, 23 Mar 2021 10:07:59 +0000
  • Ironport-hdrordr: A9a23:j8F96K59ymp6XOSSWgPXwbeFI+orLtY04lQ7vn1ZYSd+NuSFis Gjm+ka3xfoiDAXHEotg8yEJbPoex/h3LZPy800Ma25VAfr/FGpIoZr8Jf4z1TbdhHW3tV2kZ 1te60WMrfNJHBxh8ri/U2cG9Ev3NGI/MmT9J7j5l1GJDsKV4hL6QBlBgGHVmh/QwdbDZQ0fa DsnvZvjTymZHgRc4CHFmAINtKz7OHjubDHRVo9BxAh4BSTlj/A0tXHOjWRwxt2aUIr/Z4M6m 7A+jaX2oyCtLWBxgbYxyvv6f1t6b3c4/9iIODJtcQPMDXrjW+TFc5ccpmPpio8ru3qyHtCqq ipnz4aM85+62zccwiOyHPQ8jLt3zo053jpxUXwuwqFneXCWDk4B8Bd7Lg4TjLl6lEttNw58K VH03Pxjes0MTr8nT/w79WNahdylkDcmwtArccviRVkP7c2Wft0l8gy7UlVGJAPEGbR84Y8Ct RjC8na+bJ/bU6aR2qxhBgj/PWcGlAIWjuWSEkLvcKYlxJMmmpi8kcezMsD2l8d6ZMGTYVe7e isCNUlqJh+CustKY5tDuYIRsW6TkbXRwjXDW6UKVP7UIYKJmzKsJyyxLku/umldNgpwfIJ6d v8eWIdkVR3V1PlCMWI0pEO2AvKWn+BUTPkzdwb6IN+vrH6Wbr3ISyOQF0jiKKb0rQiK/yef8 z2FINdAvflI2erM51OxRfCV55bLmRbUMB9gKd6Z3u+5ubwbqH6vO3Sd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6x2T+jpUbtQFhyFRt+iSK5o6PJZ7S58iQEVQDCrJTTA1BDYj 7KE4NoXI/oqrilMuhHKqneXeeLXzRruCgWWUG4WV63q0uCqdCMUdstcjQOjEkT3RfiKKKOCKu0 Xixx6GdxvYNJyAnNG18PoFOae2OGTrpBmrHJD5hPiPSlplJg4tMS3CiwCv1dH0XT4fmANW4ylg 92gMtR+2Zf9dBrMMznmIYNyHdhJrSmMYDaok57u3QtXukM0RyieJl2OAfSX+XkX3cwMYz6EgXW eyI=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Introduce a helper to update the CPUID policy using an array of
xen_cpuid_leaf_t entries. Note the leaves present in the input
xen_cpuid_leaf_t array will replace any existing leaves 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         |  3 ++
 tools/libs/guest/xg_cpuid_x86.c | 67 +++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index ab34df1dc98..2143478fe4b 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2613,6 +2613,9 @@ int xc_cpu_policy_get_cpuid(xc_interface *xch, const 
xc_cpu_policy_t policy,
                             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_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_policy_t policy,
+                               const xen_cpuid_leaf_t *leaves,
+                               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 091aeb70c9c..13c2972ccd3 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -966,3 +966,70 @@ int xc_cpu_policy_get_msr(xc_interface *xch, const 
xc_cpu_policy_t policy,
     free(msrs);
     return rc;
 }
+
+int xc_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_policy_t policy,
+                               const xen_cpuid_leaf_t *leaves,
+                               uint32_t nr)
+{
+    unsigned int err_leaf = -1, err_subleaf = -1;
+    unsigned int nr_leaves, nr_msrs, i, j;
+    xen_cpuid_leaf_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_leaves, sizeof(*current));
+    if ( !current )
+    {
+        PERROR("Failed to allocate resources");
+        errno = ENOMEM;
+        return -1;
+    }
+
+    rc = xc_cpu_policy_serialise(xch, policy, current, &nr_leaves, NULL, 0);
+    if ( rc )
+        goto out;
+
+    for ( i = 0; i < nr; i++ )
+    {
+        const xen_cpuid_leaf_t *update = &leaves[i];
+
+        for ( j = 0; j < nr_leaves; j++ )
+            if ( current[j].leaf == update->leaf &&
+                 current[j].subleaf == update->subleaf )
+            {
+                /*
+                 * NB: cannot use an assignation because of the const vs
+                 * non-const difference.
+                 */
+                memcpy(&current[j], update, sizeof(*update));
+                break;
+            }
+
+        if ( j == nr_leaves )
+        {
+            /* Failed to find a matching leaf, append to the end. */
+            current = realloc(current, (nr_leaves + 1) * sizeof(*current));
+            memcpy(&current[nr_leaves], update, sizeof(*update));
+            nr_leaves++;
+        }
+    }
+
+    rc = x86_cpuid_copy_from_buffer(policy->cpuid, current, nr_leaves,
+                                    &err_leaf, &err_subleaf);
+    if ( rc )
+    {
+        ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d = 
%s)",
+              err_leaf, err_subleaf, -rc, strerror(-rc));
+        errno = -rc;
+        rc = -1;
+    }
+
+ out:
+    free(current);
+    return rc;
+}
-- 
2.30.1




 


Rackspace

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