Skip to content

Commit c3619a4

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM fixes from Paolo Bonzini: "Bug fixes" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: MMU: record maximum physical address width in kvm_mmu_extended_role kvm: x86: Return LA57 feature based on hardware capability x86/kvm/mmu: fix switch between root and guest MMUs s390: vsie: Use effective CRYCBD.31 to check CRYCBD validity
2 parents c4eb1e1 + de3ccd2 commit c3619a4

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

arch/s390/kvm/vsie.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
297297
scb_s->crycbd = 0;
298298

299299
apie_h = vcpu->arch.sie_block->eca & ECA_APIE;
300-
if (!apie_h && !key_msk)
300+
if (!apie_h && (!key_msk || fmt_o == CRYCB_FORMAT0))
301301
return 0;
302302

303303
if (!crycb_addr)

arch/x86/include/asm/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ union kvm_mmu_extended_role {
299299
unsigned int cr4_smap:1;
300300
unsigned int cr4_smep:1;
301301
unsigned int cr4_la57:1;
302+
unsigned int maxphyaddr:6;
302303
};
303304
};
304305

@@ -397,6 +398,7 @@ struct kvm_mmu {
397398
void (*update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
398399
u64 *spte, const void *pte);
399400
hpa_t root_hpa;
401+
gpa_t root_cr3;
400402
union kvm_mmu_role mmu_role;
401403
u8 root_level;
402404
u8 shadow_root_level;

arch/x86/kvm/cpuid.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
335335
unsigned f_xsaves = kvm_x86_ops->xsaves_supported() ? F(XSAVES) : 0;
336336
unsigned f_umip = kvm_x86_ops->umip_emulated() ? F(UMIP) : 0;
337337
unsigned f_intel_pt = kvm_x86_ops->pt_supported() ? F(INTEL_PT) : 0;
338+
unsigned f_la57 = 0;
338339

339340
/* cpuid 1.edx */
340341
const u32 kvm_cpuid_1_edx_x86_features =
@@ -489,7 +490,10 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
489490
// TSC_ADJUST is emulated
490491
entry->ebx |= F(TSC_ADJUST);
491492
entry->ecx &= kvm_cpuid_7_0_ecx_x86_features;
493+
f_la57 = entry->ecx & F(LA57);
492494
cpuid_mask(&entry->ecx, CPUID_7_ECX);
495+
/* Set LA57 based on hardware capability. */
496+
entry->ecx |= f_la57;
493497
entry->ecx |= f_umip;
494498
/* PKU is not yet implemented for shadow paging. */
495499
if (!tdp_enabled || !boot_cpu_has(X86_FEATURE_OSPKE))

arch/x86/kvm/mmu.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,6 +3555,7 @@ void kvm_mmu_free_roots(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
35553555
&invalid_list);
35563556
mmu->root_hpa = INVALID_PAGE;
35573557
}
3558+
mmu->root_cr3 = 0;
35583559
}
35593560

35603561
kvm_mmu_commit_zap_page(vcpu->kvm, &invalid_list);
@@ -3610,6 +3611,7 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)
36103611
vcpu->arch.mmu->root_hpa = __pa(vcpu->arch.mmu->pae_root);
36113612
} else
36123613
BUG();
3614+
vcpu->arch.mmu->root_cr3 = vcpu->arch.mmu->get_cr3(vcpu);
36133615

36143616
return 0;
36153617
}
@@ -3618,10 +3620,11 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
36183620
{
36193621
struct kvm_mmu_page *sp;
36203622
u64 pdptr, pm_mask;
3621-
gfn_t root_gfn;
3623+
gfn_t root_gfn, root_cr3;
36223624
int i;
36233625

3624-
root_gfn = vcpu->arch.mmu->get_cr3(vcpu) >> PAGE_SHIFT;
3626+
root_cr3 = vcpu->arch.mmu->get_cr3(vcpu);
3627+
root_gfn = root_cr3 >> PAGE_SHIFT;
36253628

36263629
if (mmu_check_root(vcpu, root_gfn))
36273630
return 1;
@@ -3646,7 +3649,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
36463649
++sp->root_count;
36473650
spin_unlock(&vcpu->kvm->mmu_lock);
36483651
vcpu->arch.mmu->root_hpa = root;
3649-
return 0;
3652+
goto set_root_cr3;
36503653
}
36513654

36523655
/*
@@ -3712,6 +3715,9 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
37123715
vcpu->arch.mmu->root_hpa = __pa(vcpu->arch.mmu->lm_root);
37133716
}
37143717

3718+
set_root_cr3:
3719+
vcpu->arch.mmu->root_cr3 = root_cr3;
3720+
37153721
return 0;
37163722
}
37173723

@@ -4163,7 +4169,7 @@ static bool cached_root_available(struct kvm_vcpu *vcpu, gpa_t new_cr3,
41634169
struct kvm_mmu_root_info root;
41644170
struct kvm_mmu *mmu = vcpu->arch.mmu;
41654171

4166-
root.cr3 = mmu->get_cr3(vcpu);
4172+
root.cr3 = mmu->root_cr3;
41674173
root.hpa = mmu->root_hpa;
41684174

41694175
for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++) {
@@ -4176,6 +4182,7 @@ static bool cached_root_available(struct kvm_vcpu *vcpu, gpa_t new_cr3,
41764182
}
41774183

41784184
mmu->root_hpa = root.hpa;
4185+
mmu->root_cr3 = root.cr3;
41794186

41804187
return i < KVM_MMU_NUM_PREV_ROOTS;
41814188
}
@@ -4770,6 +4777,7 @@ static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu)
47704777
ext.cr4_pse = !!is_pse(vcpu);
47714778
ext.cr4_pke = !!kvm_read_cr4_bits(vcpu, X86_CR4_PKE);
47724779
ext.cr4_la57 = !!kvm_read_cr4_bits(vcpu, X86_CR4_LA57);
4780+
ext.maxphyaddr = cpuid_maxphyaddr(vcpu);
47734781

47744782
ext.valid = 1;
47754783

@@ -5516,11 +5524,13 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu)
55165524
vcpu->arch.walk_mmu = &vcpu->arch.root_mmu;
55175525

55185526
vcpu->arch.root_mmu.root_hpa = INVALID_PAGE;
5527+
vcpu->arch.root_mmu.root_cr3 = 0;
55195528
vcpu->arch.root_mmu.translate_gpa = translate_gpa;
55205529
for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++)
55215530
vcpu->arch.root_mmu.prev_roots[i] = KVM_MMU_ROOT_INFO_INVALID;
55225531

55235532
vcpu->arch.guest_mmu.root_hpa = INVALID_PAGE;
5533+
vcpu->arch.guest_mmu.root_cr3 = 0;
55245534
vcpu->arch.guest_mmu.translate_gpa = translate_gpa;
55255535
for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++)
55265536
vcpu->arch.guest_mmu.prev_roots[i] = KVM_MMU_ROOT_INFO_INVALID;

0 commit comments

Comments
 (0)