Subject: linux-next: manual merge of the kvm tree with the tip tree

From: Stephen Rothwell <[email-masked]>
Date: Mon, 25 Oct 2021 16:11:31 +1100

Hi all,

Today's linux-next merge of the kvm tree got a conflict in:

  arch/x86/kvm/x86.c

between commits:

  d69c1382e1b7 ("x86/kvm: Convert FPU handling to a single swap buffer")
  126fe0401883 ("x86/fpu: Cleanup xstate xcomp_bv initialization")

from the tip tree and commits:

  e8f65b9bb483 ("KVM: x86: Remove defunct setting of XCR0 for guest during vCPU create")
  583d369b36a9 ("KVM: x86: Fold fx_init() into kvm_arch_vcpu_create()")

from the kvm tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc arch/x86/kvm/x86.c
index 5f1fc8224414,ac83d873d65b..000000000000
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@@ -10477,16 -10869,15 +10722,6 @@@ static int sync_regs(struct kvm_vcpu *v
  	return 0;
  }
  
- static void fx_init(struct kvm_vcpu *vcpu)
 -void kvm_free_guest_fpu(struct kvm_vcpu *vcpu)
--{
- 	/*
- 	 * Ensure guest xcr0 is valid for loading
- 	 */
- 	vcpu->arch.xcr0 = XFEATURE_MASK_FP;
- 
- 	vcpu->arch.cr0 |= X86_CR0_ET;
 -	if (vcpu->arch.guest_fpu) {
 -		kmem_cache_free(x86_fpu_cache, vcpu->arch.guest_fpu);
 -		vcpu->arch.guest_fpu = NULL;
 -	}
--}
 -EXPORT_SYMBOL_GPL(kvm_free_guest_fpu);
--
  int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
  {
  	if (kvm_check_tsc_unstable() && atomic_read(&kvm->online_vcpus) != 0)
@@@ -10543,13 -10934,24 +10778,11 @@@ int kvm_arch_vcpu_create(struct kvm_vcp
  	if (!alloc_emulate_ctxt(vcpu))
  		goto free_wbinvd_dirty_mask;
  
 -	vcpu->arch.user_fpu = kmem_cache_zalloc(x86_fpu_cache,
 -						GFP_KERNEL_ACCOUNT);
 -	if (!vcpu->arch.user_fpu) {
 -		pr_err("kvm: failed to allocate userspace's fpu\n");
 -		goto free_emulate_ctxt;
 -	}
 -
 -	vcpu->arch.guest_fpu = kmem_cache_zalloc(x86_fpu_cache,
 -						 GFP_KERNEL_ACCOUNT);
 -	if (!vcpu->arch.guest_fpu) {
 +	if (!fpu_alloc_guest_fpstate(&vcpu->arch.guest_fpu)) {
  		pr_err("kvm: failed to allocate vcpu's fpu\n");
 -		goto free_user_fpu;
 +		goto free_emulate_ctxt;
  	}
 -	fpstate_init(&vcpu->arch.guest_fpu->state);
 -	if (boot_cpu_has(X86_FEATURE_XSAVES))
 -		vcpu->arch.guest_fpu->state.xsave.header.xcomp_bv =
 -			host_xcr0 | XSTATE_COMPACTION_ENABLED;
  
- 	fx_init(vcpu);
- 
  	vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
  	vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu);