Skip to content

Commit 317fab7

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "As everyone back came back from conferences, here are the pending patches for Linux 6.0. ARM: - Fix for kmemleak with pKVM s390: - Fixes for VFIO with zPCI - smatch fix x86: - Ensure XSAVE-capable hosts always allow FP and SSE state to be saved and restored via KVM_{GET,SET}_XSAVE - Fix broken max_mmu_rmap_size stat - Fix compile error with old glibc that doesn't have gettid()" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: x86: Inject #UD on emulated XSETBV if XSAVES isn't enabled KVM: x86: Always enable legacy FP/SSE in allowed user XFEATURES KVM: x86: Reinstate kvm_vcpu_arch.guest_supported_xcr0 KVM: x86/mmu: add missing update to max_mmu_rmap_size selftests: kvm: Fix a compile error in selftests/kvm/rseq_test.c KVM: s390: pci: register pci hooks without interpretation KVM: s390: pci: fix GAIT physical vs virtual pointers usage KVM: s390: Pass initialized arg even if unused KVM: s390: pci: fix plain integer as NULL pointer warnings KVM: arm64: Use kmemleak_free_part_phys() to unregister hyp_mem_base
2 parents 526e826 + 69604fe commit 317fab7

File tree

12 files changed

+52
-27
lines changed

12 files changed

+52
-27
lines changed

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,7 @@ static int finalize_hyp_mode(void)
21142114
* at, which would end badly once inaccessible.
21152115
*/
21162116
kmemleak_free_part(__hyp_bss_start, __hyp_bss_end - __hyp_bss_start);
2117-
kmemleak_free_part(__va(hyp_mem_base), hyp_mem_size);
2117+
kmemleak_free_part_phys(hyp_mem_base, hyp_mem_size);
21182118
return pkvm_drop_host_privileges();
21192119
}
21202120

arch/s390/kvm/gaccess.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ enum prot_type {
489489
PROT_TYPE_ALC = 2,
490490
PROT_TYPE_DAT = 3,
491491
PROT_TYPE_IEP = 4,
492+
/* Dummy value for passing an initialized value when code != PGM_PROTECTION */
493+
PROT_NONE,
492494
};
493495

494496
static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva, u8 ar,
@@ -504,6 +506,10 @@ static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva,
504506
switch (code) {
505507
case PGM_PROTECTION:
506508
switch (prot) {
509+
case PROT_NONE:
510+
/* We should never get here, acts like termination */
511+
WARN_ON_ONCE(1);
512+
break;
507513
case PROT_TYPE_IEP:
508514
tec->b61 = 1;
509515
fallthrough;
@@ -968,8 +974,10 @@ static int guest_range_to_gpas(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
968974
return rc;
969975
} else {
970976
gpa = kvm_s390_real_to_abs(vcpu, ga);
971-
if (kvm_is_error_gpa(vcpu->kvm, gpa))
977+
if (kvm_is_error_gpa(vcpu->kvm, gpa)) {
972978
rc = PGM_ADDRESSING;
979+
prot = PROT_NONE;
980+
}
973981
}
974982
if (rc)
975983
return trans_exc(vcpu, rc, ga, ar, mode, prot);
@@ -1112,8 +1120,6 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
11121120
if (rc == PGM_PROTECTION && try_storage_prot_override)
11131121
rc = access_guest_page_with_key(vcpu->kvm, mode, gpas[idx],
11141122
data, fragment_len, PAGE_SPO_ACC);
1115-
if (rc == PGM_PROTECTION)
1116-
prot = PROT_TYPE_KEYC;
11171123
if (rc)
11181124
break;
11191125
len -= fragment_len;
@@ -1123,6 +1129,10 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
11231129
if (rc > 0) {
11241130
bool terminate = (mode == GACC_STORE) && (idx > 0);
11251131

1132+
if (rc == PGM_PROTECTION)
1133+
prot = PROT_TYPE_KEYC;
1134+
else
1135+
prot = PROT_NONE;
11261136
rc = trans_exc_ending(vcpu, rc, ga, ar, mode, prot, terminate);
11271137
}
11281138
out_unlock:

arch/s390/kvm/interrupt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3324,7 +3324,7 @@ static void aen_host_forward(unsigned long si)
33243324
if (gaite->count == 0)
33253325
return;
33263326
if (gaite->aisb != 0)
3327-
set_bit_inv(gaite->aisbo, (unsigned long *)gaite->aisb);
3327+
set_bit_inv(gaite->aisbo, phys_to_virt(gaite->aisb));
33283328

33293329
kvm = kvm_s390_pci_si_to_kvm(aift, si);
33303330
if (!kvm)

arch/s390/kvm/kvm-s390.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ int kvm_arch_init(void *opaque)
505505
goto out;
506506
}
507507

508-
if (kvm_s390_pci_interp_allowed()) {
508+
if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) {
509509
rc = kvm_s390_pci_init();
510510
if (rc) {
511511
pr_err("Unable to allocate AIFT for PCI\n");
@@ -527,7 +527,7 @@ int kvm_arch_init(void *opaque)
527527
void kvm_arch_exit(void)
528528
{
529529
kvm_s390_gib_destroy();
530-
if (kvm_s390_pci_interp_allowed())
530+
if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM))
531531
kvm_s390_pci_exit();
532532
debug_unregister(kvm_s390_dbf);
533533
debug_unregister(kvm_s390_dbf_uv);

arch/s390/kvm/pci.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int zpci_setup_aipb(u8 nisc)
5858
if (!zpci_aipb)
5959
return -ENOMEM;
6060

61-
aift->sbv = airq_iv_create(ZPCI_NR_DEVICES, AIRQ_IV_ALLOC, 0);
61+
aift->sbv = airq_iv_create(ZPCI_NR_DEVICES, AIRQ_IV_ALLOC, NULL);
6262
if (!aift->sbv) {
6363
rc = -ENOMEM;
6464
goto free_aipb;
@@ -71,7 +71,7 @@ static int zpci_setup_aipb(u8 nisc)
7171
rc = -ENOMEM;
7272
goto free_sbv;
7373
}
74-
aift->gait = (struct zpci_gaite *)page_to_phys(page);
74+
aift->gait = (struct zpci_gaite *)page_to_virt(page);
7575

7676
zpci_aipb->aipb.faisb = virt_to_phys(aift->sbv->vector);
7777
zpci_aipb->aipb.gait = virt_to_phys(aift->gait);
@@ -373,7 +373,7 @@ static int kvm_s390_pci_aif_disable(struct zpci_dev *zdev, bool force)
373373
gaite->gisc = 0;
374374
gaite->aisbo = 0;
375375
gaite->gisa = 0;
376-
aift->kzdev[zdev->aisb] = 0;
376+
aift->kzdev[zdev->aisb] = NULL;
377377
/* Clear zdev info */
378378
airq_iv_free_bit(aift->sbv, zdev->aisb);
379379
airq_iv_release(zdev->aibv);
@@ -672,23 +672,31 @@ int kvm_s390_pci_zpci_op(struct kvm *kvm, struct kvm_s390_zpci_op *args)
672672

673673
int kvm_s390_pci_init(void)
674674
{
675+
zpci_kvm_hook.kvm_register = kvm_s390_pci_register_kvm;
676+
zpci_kvm_hook.kvm_unregister = kvm_s390_pci_unregister_kvm;
677+
678+
if (!kvm_s390_pci_interp_allowed())
679+
return 0;
680+
675681
aift = kzalloc(sizeof(struct zpci_aift), GFP_KERNEL);
676682
if (!aift)
677683
return -ENOMEM;
678684

679685
spin_lock_init(&aift->gait_lock);
680686
mutex_init(&aift->aift_lock);
681-
zpci_kvm_hook.kvm_register = kvm_s390_pci_register_kvm;
682-
zpci_kvm_hook.kvm_unregister = kvm_s390_pci_unregister_kvm;
683687

684688
return 0;
685689
}
686690

687691
void kvm_s390_pci_exit(void)
688692
{
689-
mutex_destroy(&aift->aift_lock);
690693
zpci_kvm_hook.kvm_register = NULL;
691694
zpci_kvm_hook.kvm_unregister = NULL;
692695

696+
if (!kvm_s390_pci_interp_allowed())
697+
return;
698+
699+
mutex_destroy(&aift->aift_lock);
700+
693701
kfree(aift);
694702
}

arch/s390/kvm/pci.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ extern struct zpci_aift *aift;
4646
static inline struct kvm *kvm_s390_pci_si_to_kvm(struct zpci_aift *aift,
4747
unsigned long si)
4848
{
49-
if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM) || aift->kzdev == 0 ||
50-
aift->kzdev[si] == 0)
51-
return 0;
49+
if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM) || !aift->kzdev ||
50+
!aift->kzdev[si])
51+
return NULL;
5252
return aift->kzdev[si]->kvm;
5353
};
5454

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ struct kvm_vcpu_arch {
729729
struct fpu_guest guest_fpu;
730730

731731
u64 xcr0;
732+
u64 guest_supported_xcr0;
732733

733734
struct kvm_pio_request pio;
734735
void *pio_data;

arch/x86/kvm/cpuid.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
315315
{
316316
struct kvm_lapic *apic = vcpu->arch.apic;
317317
struct kvm_cpuid_entry2 *best;
318-
u64 guest_supported_xcr0;
319318

320319
best = kvm_find_cpuid_entry(vcpu, 1);
321320
if (best && apic) {
@@ -327,10 +326,16 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
327326
kvm_apic_set_version(vcpu);
328327
}
329328

330-
guest_supported_xcr0 =
329+
vcpu->arch.guest_supported_xcr0 =
331330
cpuid_get_supported_xcr0(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent);
332331

333-
vcpu->arch.guest_fpu.fpstate->user_xfeatures = guest_supported_xcr0;
332+
/*
333+
* FP+SSE can always be saved/restored via KVM_{G,S}ET_XSAVE, even if
334+
* XSAVE/XCRO are not exposed to the guest, and even if XSAVE isn't
335+
* supported by the host.
336+
*/
337+
vcpu->arch.guest_fpu.fpstate->user_xfeatures = vcpu->arch.guest_supported_xcr0 |
338+
XFEATURE_MASK_FPSSE;
334339

335340
kvm_update_pv_runtime(vcpu);
336341

arch/x86/kvm/emulate.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4132,6 +4132,9 @@ static int em_xsetbv(struct x86_emulate_ctxt *ctxt)
41324132
{
41334133
u32 eax, ecx, edx;
41344134

4135+
if (!(ctxt->ops->get_cr(ctxt, 4) & X86_CR4_OSXSAVE))
4136+
return emulate_ud(ctxt);
4137+
41354138
eax = reg_read(ctxt, VCPU_REGS_RAX);
41364139
edx = reg_read(ctxt, VCPU_REGS_RDX);
41374140
ecx = reg_read(ctxt, VCPU_REGS_RCX);

arch/x86/kvm/mmu/mmu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,8 @@ static void __rmap_add(struct kvm *kvm,
15961596
rmap_head = gfn_to_rmap(gfn, sp->role.level, slot);
15971597
rmap_count = pte_list_add(cache, spte, rmap_head);
15981598

1599+
if (rmap_count > kvm->stat.max_mmu_rmap_size)
1600+
kvm->stat.max_mmu_rmap_size = rmap_count;
15991601
if (rmap_count > RMAP_RECYCLE_THRESHOLD) {
16001602
kvm_zap_all_rmap_sptes(kvm, rmap_head);
16011603
kvm_flush_remote_tlbs_with_address(

0 commit comments

Comments
 (0)