[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 6/6] libxl: add support for parsing MSR features
- To: xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
- Date: Tue, 11 Jul 2023 11:22:30 +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=4uHuVNwA5xpYjOyrRWFL+DwpVoS0En8vtpwS2o709gg=; b=BH4W3RvOsH3yoJlC6r1zDDrqUt3uZ8ltUeSw3uB6hPVAvL41hki+pw3y07nHz2Jegbd5ZamZZyFOTUAq7Spk6fPIy7n1paqibw/zBkX2s4AD57yJ2Z86Y5nyP/Mi/3uZFNZTzVEFq55n/2H0KyuZhRf7MYGctQvpsugsDU2uDIruBjVRMwWB6kXMerI+8bZueIY0Qmkg2TCBCT9SmkvWuUzus28+MzvGit3vCccBP+KIQfCFGE1Ms3su8EoBfG7nV/e5d8iI68dM4ILwpMAuswQU05JUeeYKjUYTOQb+MgZf+mdfAcXniwMt568tfZDsHf8oYSoY5IoEUpsxtd3q3Q==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V9je+inFL8aJOQP1MpEy2u8Nulzg2ND7kkchoNN5ipebuf0nsrNqUWsYhWe6bajWTEoQ8s7X7SZ5G1hIJ4wK5+B3YLhahIf1+KhlOmhV9/Jb+GS9L/Hiu7H5MqTW3OK3eBEXXvmvXdaOXz3EoA6+PqQEVMHhm38Hd9MBYxZLLRzh/MKQjvFDA0xw4rdetVlVhIZDry+vHjz99fu5QgcrLsmyBJRZ+BjkA3gKtAk2hPeeB9IZQZAFgW+skx0zorfItoSHQV9Zo8bvkBJ5vUResYUHbodVHWXHGFhw5sByC1x4Z1PuCkXUKA5jFm5DG+yajvvceASPUZQYWl/Xro4www==
- 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: Tue, 11 Jul 2023 09:25:32 +0000
- Ironport-data: A9a23:q5fHUqrrbsD6+qZYj579XtTjZAVeBmI8ZBIvgKrLsJaIsI4StFCzt garIBnVPPreNmPzeo1za4u+oE4O6MPTyoViQVY5+ywxH3kSoJuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpA1c/Ek/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKq04GpwUmAWP6gR5weBziBNVfrzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXAB0rUi2hgMmv/LGYVsR33soIEZf7GrpK7xmMzRmBZRonabbqZvyQoPN9gnI3jM0IGuvCb c0EbzYpdA7HfxBEJlYQDtQ5gfusgX78NTZfrTp5p4JuuzSVkFM3jemraYWOEjCJbZw9ckKwv GXJ8n6/GhgHHNee1SCE4jSngeqncSbTAdtCT+3jrKc16LGV7lRNORw5CmH4msGWqGu+XNMPK Q852SV7+MDe82TuFLERRSaQsHOC+xIRRddUO+k78x2WjLrZ5R6DAWoJRSIHb8Yp3OcpQRQ62 1nPmMnmbRRtv6eSUmm17aqPoHW5Pi19EIMZTSoNTA9A79y9pog210jLVow6T/XzicDpEzbtx TzMtDI5m7gYkc8M0eO84EzDhDWv4JPOS2bZ+znqY45s1SshDKbNWmBiwQGzASpoRGpBcmS8g Q==
- Ironport-hdrordr: A9a23:y/H3N6NsVOvdT8BcTjejsMiBIKoaSvp037BK7S1MoNJuEvBw9v re+sjzsCWftN9/Yh4dcLy7VpVoBEmsl6KdgrNhWotKPjOW21dARbsKheffKn/bakjDH4Zmvp uIGJIObOEYY2IasS77ijPIbOrJwrO8gd6VbTG19QYdceloAZsQnzuQEmygYzRLrJEtP+tFKH KbjPA33waISDAsQemQIGIKZOTHr82jruObXfZXbyRXkzVnlFmTmcTHLyQ=
- 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>
---
tools/libs/light/libxl_cpuid.c | 61 +++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c
index b1c4f8f2f45b..86a08f29a19c 100644
--- a/tools/libs/light/libxl_cpuid.c
+++ b/tools/libs/light/libxl_cpuid.c
@@ -158,6 +158,57 @@ 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;
@@ -337,7 +388,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
|