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

[PATCH v3 6/6] libxl: add support for parsing MSR features


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Thu, 20 Jul 2023 10:25:40 +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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QaCpjdHP+ibZJJJugwXJB87F7i53rlocJEgAzu7noVg=; b=m6zIfmosf83sMkJG5g3C/yFv+vC4ZMHeHu6aAIaiUEs42yeDvREBPxHl3VtSSN76X94rEOoRXxOZFKPwivRY0WmqD+3HxyCvVOHH1pjEG97PdC9e7N3x9O3FnhlDEgDPtFDeRxFId+TAigIlet0FqNmhgLp68CDQ+6Luesd0lggxnKCXd7JJSrqfDDbdkpn57OaMAUtvnQ7a8j134vbxtFjhtcZOApt6ZJUupsfXcgl0QNqJn/TzrpY2sIxJ2JPEviS3ILQBNMhaOEEcKoWM6L7I0Bf32OB3wCafo+id0EXkufVP4egpXZGMa+mFJbGXznBHlI8F23iREaydOR4/lQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K9lJFxO167n6DDG/X+8W77o03XjdwMfTH25MsP1ItfzF9bYR8/jxXfahRXYzZfK2ytHJmkQPP6cJNBG2TNKiUjauzrjYVVE+AXLZPP7Li7A8nAOdIbV8sdQ5TNsOnhJEaYv+DC2GfHILr8kRFJbqLS4Hc1LQlm9B9A9ZDBXLWI6BjxDL3l92SmRxzc6ev2N5wWo0BjHJoJVuQCf73HtPAeOY+u1L6exZqd+BWJJkk9kYzjBFlxCb/kLML+V5bVRp2DIcx8IqCck92g5wzhkiVo6mzGGcxtohjoz807mVlqUIBNO6mUXD1Tvptg8zHnWJtd7YAA8eAWUN56yyBiFu8g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Thu, 20 Jul 2023 08:27:33 +0000
  • Ironport-data: A9a23:4UlgYa0HFF2en3nz3fbD5fdwkn2cJEfYwER7XKvMYLTBsI5bp2MDy WpKUDyCOfmCMGTzc9Anbt6/px8D7JXQyd5kTARopC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefTAOK6ULWeUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8teTb8XuDgNyo4GlD5gNkPagS1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfHWd32 sA1GB00SQmOv9nm3quZZfkxr5F2RCXrFNt3VnBI6xj8VK9jareaBqLA6JlfwSs6gd1IEbDGf c0FZDFzbRPGJRpSJlMQD5F4l+Ct7pX9W2QA9BTJ+uxqvS6Kk1UZPLvFabI5fvSQQspYhACAr 3/u9GXlGBAKcteYzFJp91r137KSxnKjAtx6+LuQxuFJmU/Nx2IvCxQIZVeEq9qojkSRYocKQ 6AT0m90xUQoz2S7Q9+4UxCmrXqsuh8HR8EWA+A88BuKyKff/0CeHGdsZiFFQMwrsokxXzNC/ l2GhdTyHhR0raaYD3ma89+pQSiaPCEUKSoJYnYCRA5cut37+ths11TIU8ppF7OzgpvtAzbsz juWrS84wbIOkcoM0Kb99lfC696xmqX0oscOzl2/dgqYAslRPuZJu6TABYDn0Mt9
  • Ironport-hdrordr: A9a23:fL1lFKshDPKuy0WyK92XRQr37skDddV00zEX/kB9WHVpmwKj5q eTdZUgpHnJYVMqMk3I9urwW5VoLUm9yXcX2+gs1NWZLWvbUQKTRekI0WKI+UyEJ8SRzJ846U 6iScRD4R/LYGSSQfyU3OBwKbgd/OU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Introduce support for handling MSR features in
libxl_cpuid_parse_config().  The MSR policies are added to the
libxl_cpuid_policy like the CPUID one, which gets passed to
xc_cpuid_apply_policy().

This allows existing users of libxl to provide MSR related features as
key=value pairs to libxl_cpuid_parse_config() without requiring the
usage of a different API.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Acked-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
Changes since v2:
 - Add some braces.
---
 tools/libs/light/libxl_cpuid.c | 64 +++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)

diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c
index f8b2e45ee681..15fac03a9046 100644
--- a/tools/libs/light/libxl_cpuid.c
+++ b/tools/libs/light/libxl_cpuid.c
@@ -157,6 +157,60 @@ static int cpuid_add(libxl_cpuid_policy_list *policy,
     return 0;
 }
 
+static struct xc_msr *msr_find_match(libxl_cpuid_policy_list *pl, uint32_t 
index)
+{
+    unsigned int i = 0;
+    libxl_cpuid_policy_list policy = *pl;
+
+    if (policy == NULL)
+        policy = *pl = calloc(1, sizeof(*policy));
+
+    if (policy->msr != NULL) {
+        for (i = 0; policy->msr[i].index != XC_MSR_INPUT_UNUSED; i++) {
+            if (policy->msr[i].index == index) {
+                return &policy->msr[i];
+            }
+        }
+    }
+
+    policy->msr = realloc(policy->msr, sizeof(struct xc_msr) * (i + 2));
+    policy->msr[i].index = index;
+    memset(policy->msr[i].policy, 'x', ARRAY_SIZE(policy->msr[0].policy) - 1);
+    policy->msr[i].policy[ARRAY_SIZE(policy->msr[0].policy) - 1] = '\0';
+    policy->msr[i + 1].index = XC_MSR_INPUT_UNUSED;
+
+    return &policy->msr[i];
+}
+
+static int msr_add(libxl_cpuid_policy_list *policy, uint32_t index, unsigned 
int bit,
+                   const char *val)
+{
+    struct xc_msr *entry = msr_find_match(policy, index);
+
+    /* Only allow options taking a character for MSRs, no values allowed. */
+    if (strlen(val) != 1)
+        return 3;
+
+    switch (val[0]) {
+    case '0':
+    case '1':
+    case 'x':
+    case 'k':
+        entry->policy[63 - bit] = val[0];
+        break;
+
+    case 's':
+        /* Translate s -> k as xc_msr doesn't support the deprecated 's'. */
+        entry->policy[63 - bit] = 'k';
+        break;
+
+    default:
+        return 3;
+    }
+
+    return 0;
+}
+
 struct feature_name {
     const char *name;
     unsigned int bit;
@@ -336,7 +390,15 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list 
*policy, const char* str)
     }
 
     case FEAT_MSR:
-        return 2;
+    {
+        unsigned int bit = feat->bit % 32;
+
+        if (feature_to_policy[feat->bit / 32].msr.reg == CPUID_REG_EDX)
+            bit += 32;
+
+        return msr_add(policy, feature_to_policy[feat->bit / 32].msr.index,
+                       bit, val);
+    }
     }
 
     return 2;
-- 
2.41.0




 


Rackspace

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