[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 19/21] libs/guest: apply a featureset into a cpu policy
Pull out the code from xc_cpuid_apply_policy that applies a featureset to a cpu policy and place it on it's own standalone function that's part of the public interface. No functional change intended. Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> --- tools/include/xenctrl.h | 5 ++ tools/libs/guest/xg_cpuid_x86.c | 94 ++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 07b8bfc08aa..a830fac1d12 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2639,6 +2639,11 @@ int xc_cpu_policy_topology(xc_interface *xch, xc_cpu_policy_t policy, int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t policy, const struct xc_xend_cpuid *cpuid, bool hvm); +/* Apply a featureset to the policy. */ +int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t policy, + const uint32_t *featureset, + unsigned int nr_features); + int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, uint32_t *nr_features, uint32_t *featureset); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index ce4a4a1a436..96b969342fa 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -450,46 +450,14 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, if ( featureset ) { - uint32_t disabled_features[FEATURESET_NR_ENTRIES], - feat[FEATURESET_NR_ENTRIES] = {}; - static const uint32_t deep_features[] = INIT_DEEP_FEATURES; - unsigned int i, b; - - /* - * The user supplied featureset may be shorter or longer than - * FEATURESET_NR_ENTRIES. Shorter is fine, and we will zero-extend. - * Longer is fine, so long as it only padded with zeros. - */ - unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features); - - /* Check for truncated set bits. */ - rc = -EOPNOTSUPP; - for ( i = user_len; i < nr_features; ++i ) - if ( featureset[i] != 0 ) - goto out; - - memcpy(feat, featureset, sizeof(*featureset) * user_len); - - /* Disable deep dependencies of disabled features. */ - for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) - disabled_features[i] = ~feat[i] & deep_features[i]; - - for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) + policy.cpuid = p; + rc = xc_cpu_policy_apply_featureset(xch, &policy, featureset, + nr_features); + if ( rc ) { - const uint32_t *dfs; - - if ( !test_bit(b, disabled_features) || - !(dfs = x86_cpuid_lookup_deep_deps(b)) ) - continue; - - for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) - { - feat[i] &= ~dfs[i]; - disabled_features[i] &= ~dfs[i]; - } + ERROR("Failed to apply featureset to policy"); + goto out; } - - cpuid_featureset_to_policy(feat, p); } else { @@ -1230,3 +1198,53 @@ int xc_cpu_policy_topology(xc_interface *xch, xc_cpu_policy_t policy, return 0; } + +int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t policy, + const uint32_t *featureset, + unsigned int nr_features) +{ + uint32_t disabled_features[FEATURESET_NR_ENTRIES], + feat[FEATURESET_NR_ENTRIES] = {}; + static const uint32_t deep_features[] = INIT_DEEP_FEATURES; + unsigned int i, b; + + /* + * The user supplied featureset may be shorter or longer than + * FEATURESET_NR_ENTRIES. Shorter is fine, and we will zero-extend. + * Longer is fine, so long as it only padded with zeros. + */ + unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features); + + /* Check for truncated set bits. */ + for ( i = user_len; i < nr_features; ++i ) + if ( featureset[i] != 0 ) + { + errno = EOPNOTSUPP; + return -1; + } + + memcpy(feat, featureset, sizeof(*featureset) * user_len); + + /* Disable deep dependencies of disabled features. */ + for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) + disabled_features[i] = ~feat[i] & deep_features[i]; + + for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) + { + const uint32_t *dfs; + + if ( !test_bit(b, disabled_features) || + !(dfs = x86_cpuid_lookup_deep_deps(b)) ) + continue; + + for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) + { + feat[i] &= ~dfs[i]; + disabled_features[i] &= ~dfs[i]; + } + } + + cpuid_featureset_to_policy(feat, policy->cpuid); + + return 0; +} -- 2.30.1
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |