Skip to content

Commit cfb1edb

Browse files
bonziniSomasundaram Krishnasamy
authored andcommitted
KVM: x86: introduce is_pae_paging
Checking for 32-bit PAE is quite common around code that fiddles with the PDPTRs. Add a function to compress all checks into a single invocation. Reviewed-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit bf03d4f) Orabug: 31699256 Conflicts: arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c These two files were created later as a split of arch/x86/kvm/vmx.c. Signed-off-by: Maciej S. Szmigiero <[email protected]> Reviewed-by: David Edmondson <[email protected]> Reviewed-by: Mihai Carabas <[email protected]> Signed-off-by: Somasundaram Krishnasamy <[email protected]>
1 parent 5a40a9c commit cfb1edb

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

arch/x86/kvm/vmx.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5235,7 +5235,7 @@ static void ept_load_pdptrs(struct kvm_vcpu *vcpu)
52355235
(unsigned long *)&vcpu->arch.regs_dirty))
52365236
return;
52375237

5238-
if (is_paging(vcpu) && is_pae(vcpu) && !is_long_mode(vcpu)) {
5238+
if (is_pae_paging(vcpu)) {
52395239
vmcs_write64(GUEST_PDPTR0, mmu->pdptrs[0]);
52405240
vmcs_write64(GUEST_PDPTR1, mmu->pdptrs[1]);
52415241
vmcs_write64(GUEST_PDPTR2, mmu->pdptrs[2]);
@@ -5247,7 +5247,7 @@ static void ept_save_pdptrs(struct kvm_vcpu *vcpu)
52475247
{
52485248
struct kvm_mmu *mmu = vcpu->arch.walk_mmu;
52495249

5250-
if (is_paging(vcpu) && is_pae(vcpu) && !is_long_mode(vcpu)) {
5250+
if (is_pae_paging(vcpu)) {
52515251
mmu->pdptrs[0] = vmcs_read64(GUEST_PDPTR0);
52525252
mmu->pdptrs[1] = vmcs_read64(GUEST_PDPTR1);
52535253
mmu->pdptrs[2] = vmcs_read64(GUEST_PDPTR2);
@@ -12055,8 +12055,7 @@ static int nested_vmx_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3, bool ne
1205512055
* If PAE paging and EPT are both on, CR3 is not used by the CPU and
1205612056
* must not be dereferenced.
1205712057
*/
12058-
if (!is_long_mode(vcpu) && is_pae(vcpu) && is_paging(vcpu) &&
12059-
!nested_ept) {
12058+
if (is_pae_paging(vcpu) && !nested_ept) {
1206012059
if (!load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) {
1206112060
*entry_failure_code = ENTRY_FAIL_PDPTE;
1206212061
return 1;

arch/x86/kvm/x86.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ bool pdptrs_changed(struct kvm_vcpu *vcpu)
631631
gfn_t gfn;
632632
int r;
633633

634-
if (is_long_mode(vcpu) || !is_pae(vcpu) || !is_paging(vcpu))
634+
if (!is_pae_paging(vcpu))
635635
return false;
636636

637637
if (!test_bit(VCPU_EXREG_PDPTR,
@@ -872,8 +872,8 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
872872
if (is_long_mode(vcpu) &&
873873
(cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 63)))
874874
return 1;
875-
else if (is_pae(vcpu) && is_paging(vcpu) &&
876-
!load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3))
875+
else if (is_pae_paging(vcpu) &&
876+
!load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3))
877877
return 1;
878878

879879
kvm_mmu_new_cr3(vcpu, cr3, skip_tlb_flush);
@@ -8285,7 +8285,7 @@ static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
82858285
kvm_update_cpuid(vcpu);
82868286

82878287
idx = srcu_read_lock(&vcpu->kvm->srcu);
8288-
if (!is_long_mode(vcpu) && is_pae(vcpu) && is_paging(vcpu)) {
8288+
if (is_pae_paging(vcpu)) {
82898289
load_pdptrs(vcpu, vcpu->arch.walk_mmu, kvm_read_cr3(vcpu));
82908290
mmu_reset_needed = 1;
82918291
}

arch/x86/kvm/x86.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ static inline int is_paging(struct kvm_vcpu *vcpu)
139139
return likely(kvm_read_cr0_bits(vcpu, X86_CR0_PG));
140140
}
141141

142+
static inline bool is_pae_paging(struct kvm_vcpu *vcpu)
143+
{
144+
return !is_long_mode(vcpu) && is_pae(vcpu) && is_paging(vcpu);
145+
}
146+
142147
static inline u32 bit(int bitno)
143148
{
144149
return 1 << (bitno & 31);

0 commit comments

Comments
 (0)