Skip to content

Commit

Permalink
x86/cpuid: prevent shrinking migrated policies max leaves
Browse files Browse the repository at this point in the history
CPUID policies from guest being migrated shouldn't have the maximum
leaves shrink, as that would be a guest visible change. The hypervisor
has no knowledge on whether a guest has been migrated or is build from
scratch, and hence it must not blindly shrink the CPUID policy in
recalculate_cpuid_policy. Remove the
x86_cpuid_policy_shrink_max_leaves call from recalculate_cpuid_policy.
Removing such call could be seen as a partial revert of 540d911.

Instead let the toolstack shrink the policies for newly created
guests, while keeping the previous values for guests that are migrated
in. Note that guests migrated in without a CPUID policy won't get any
kind of shrinking applied.

Fixes: 540d911 ('x86/CPUID: shrink max_{,sub}leaf fields according to actual leaf contents')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
  • Loading branch information
royger authored and andyhhp committed Nov 12, 2021
1 parent c06e3d8 commit 81da2b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tools/libs/guest/xg_cpuid_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,13 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
}
}

/*
* Do not try to shrink the policy if restoring, as that could cause
* guest visible changes in the maximum leaf fields.
*/
if ( !restore )
x86_cpuid_policy_shrink_max_leaves(p);

rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves);
if ( rc )
{
Expand Down
2 changes: 0 additions & 2 deletions xen/arch/x86/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,6 @@ void recalculate_cpuid_policy(struct domain *d)

if ( !p->extd.page1gb )
p->extd.raw[0x19] = EMPTY_LEAF;

x86_cpuid_policy_shrink_max_leaves(p);
}

int init_domain_cpuid_policy(struct domain *d)
Expand Down

0 comments on commit 81da2b5

Please sign in to comment.