OSDN Git Service

Merge tag 'kvm-s390-master-6.0-2' of https://git.kernel.org/pub/scm/linux/kernel...
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 23 Sep 2022 14:06:08 +0000 (10:06 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 23 Sep 2022 14:06:08 +0000 (10:06 -0400)
More pci fixes
Fix for a code analyser warning

arch/arm64/kvm/arm.c
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/cpuid.c
arch/x86/kvm/emulate.c
arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/x86.c
tools/testing/selftests/kvm/rseq_test.c

index 2ff0ef6..917086b 100644 (file)
@@ -2114,7 +2114,7 @@ static int finalize_hyp_mode(void)
         * at, which would end badly once inaccessible.
         */
        kmemleak_free_part(__hyp_bss_start, __hyp_bss_end - __hyp_bss_start);
-       kmemleak_free_part(__va(hyp_mem_base), hyp_mem_size);
+       kmemleak_free_part_phys(hyp_mem_base, hyp_mem_size);
        return pkvm_drop_host_privileges();
 }
 
index 2c96c43..aa381ab 100644 (file)
@@ -729,6 +729,7 @@ struct kvm_vcpu_arch {
        struct fpu_guest guest_fpu;
 
        u64 xcr0;
+       u64 guest_supported_xcr0;
 
        struct kvm_pio_request pio;
        void *pio_data;
index 75dcf7a..4c1c2c0 100644 (file)
@@ -315,7 +315,6 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
 {
        struct kvm_lapic *apic = vcpu->arch.apic;
        struct kvm_cpuid_entry2 *best;
-       u64 guest_supported_xcr0;
 
        best = kvm_find_cpuid_entry(vcpu, 1);
        if (best && apic) {
@@ -327,10 +326,16 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
                kvm_apic_set_version(vcpu);
        }
 
-       guest_supported_xcr0 =
+       vcpu->arch.guest_supported_xcr0 =
                cpuid_get_supported_xcr0(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent);
 
-       vcpu->arch.guest_fpu.fpstate->user_xfeatures = guest_supported_xcr0;
+       /*
+        * FP+SSE can always be saved/restored via KVM_{G,S}ET_XSAVE, even if
+        * XSAVE/XCRO are not exposed to the guest, and even if XSAVE isn't
+        * supported by the host.
+        */
+       vcpu->arch.guest_fpu.fpstate->user_xfeatures = vcpu->arch.guest_supported_xcr0 |
+                                                      XFEATURE_MASK_FPSSE;
 
        kvm_update_pv_runtime(vcpu);
 
index d5ec3a2..aacb28c 100644 (file)
@@ -4132,6 +4132,9 @@ static int em_xsetbv(struct x86_emulate_ctxt *ctxt)
 {
        u32 eax, ecx, edx;
 
+       if (!(ctxt->ops->get_cr(ctxt, 4) & X86_CR4_OSXSAVE))
+               return emulate_ud(ctxt);
+
        eax = reg_read(ctxt, VCPU_REGS_RAX);
        edx = reg_read(ctxt, VCPU_REGS_RDX);
        ecx = reg_read(ctxt, VCPU_REGS_RCX);
index e418ef3..3552e6a 100644 (file)
@@ -1596,6 +1596,8 @@ static void __rmap_add(struct kvm *kvm,
        rmap_head = gfn_to_rmap(gfn, sp->role.level, slot);
        rmap_count = pte_list_add(cache, spte, rmap_head);
 
+       if (rmap_count > kvm->stat.max_mmu_rmap_size)
+               kvm->stat.max_mmu_rmap_size = rmap_count;
        if (rmap_count > RMAP_RECYCLE_THRESHOLD) {
                kvm_zap_all_rmap_sptes(kvm, rmap_head);
                kvm_flush_remote_tlbs_with_address(
index 43a6a7e..b0c47b4 100644 (file)
@@ -1011,15 +1011,10 @@ void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvm_load_host_xsave_state);
 
-static inline u64 kvm_guest_supported_xcr0(struct kvm_vcpu *vcpu)
-{
-       return vcpu->arch.guest_fpu.fpstate->user_xfeatures;
-}
-
 #ifdef CONFIG_X86_64
 static inline u64 kvm_guest_supported_xfd(struct kvm_vcpu *vcpu)
 {
-       return kvm_guest_supported_xcr0(vcpu) & XFEATURE_MASK_USER_DYNAMIC;
+       return vcpu->arch.guest_supported_xcr0 & XFEATURE_MASK_USER_DYNAMIC;
 }
 #endif
 
@@ -1042,7 +1037,7 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
         * saving.  However, xcr0 bit 0 is always set, even if the
         * emulated CPU does not support XSAVE (see kvm_vcpu_reset()).
         */
-       valid_bits = kvm_guest_supported_xcr0(vcpu) | XFEATURE_MASK_FP;
+       valid_bits = vcpu->arch.guest_supported_xcr0 | XFEATURE_MASK_FP;
        if (xcr0 & ~valid_bits)
                return 1;
 
@@ -1070,6 +1065,7 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
 
 int kvm_emulate_xsetbv(struct kvm_vcpu *vcpu)
 {
+       /* Note, #UD due to CR4.OSXSAVE=0 has priority over the intercept. */
        if (static_call(kvm_x86_get_cpl)(vcpu) != 0 ||
            __kvm_set_xcr(vcpu, kvm_rcx_read(vcpu), kvm_read_edx_eax(vcpu))) {
                kvm_inject_gp(vcpu, 0);
index fac248a..6f88da7 100644 (file)
@@ -227,7 +227,7 @@ int main(int argc, char *argv[])
        ucall_init(vm, NULL);
 
        pthread_create(&migration_thread, NULL, migration_worker,
-                      (void *)(unsigned long)gettid());
+                      (void *)(unsigned long)syscall(SYS_gettid));
 
        for (i = 0; !done; i++) {
                vcpu_run(vcpu);