Skip to content

Commit 744e699

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: x86: Move gpa_val and gpa_available into the emulator context
Move the GPA tracking into the emulator context now that the context is guaranteed to be initialized via __init_emulate_ctxt() prior to dereferencing gpa_{available,val}, i.e. now that seeing a stale gpa_available will also trigger a WARN due to an invalid context. Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 92daa48 commit 744e699

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

arch/x86/include/asm/kvm_emulate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ struct x86_emulate_ctxt {
319319
bool have_exception;
320320
struct x86_exception exception;
321321

322+
/* GPA available */
323+
bool gpa_available;
324+
gpa_t gpa_val;
325+
322326
/*
323327
* decode cache
324328
*/

arch/x86/include/asm/kvm_host.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,6 @@ struct kvm_vcpu_arch {
808808
int pending_ioapic_eoi;
809809
int pending_external_vector;
810810

811-
/* GPA available */
812-
bool gpa_available;
813-
gpa_t gpa_val;
814-
815811
/* be preempted when it's in kernel-mode(cpl=0) */
816812
bool preempted_in_kernel;
817813

arch/x86/kvm/x86.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5745,10 +5745,9 @@ static int emulator_read_write_onepage(unsigned long addr, void *val,
57455745
* operation using rep will only have the initial GPA from the NPF
57465746
* occurred.
57475747
*/
5748-
if (vcpu->arch.gpa_available &&
5749-
emulator_can_use_gpa(ctxt) &&
5750-
(addr & ~PAGE_MASK) == (vcpu->arch.gpa_val & ~PAGE_MASK)) {
5751-
gpa = vcpu->arch.gpa_val;
5748+
if (ctxt->gpa_available && emulator_can_use_gpa(ctxt) &&
5749+
(addr & ~PAGE_MASK) == (ctxt->gpa_val & ~PAGE_MASK)) {
5750+
gpa = ctxt->gpa_val;
57525751
ret = vcpu_is_mmio_gpa(vcpu, addr, gpa, write);
57535752
} else {
57545753
ret = vcpu_mmio_gva_to_gpa(vcpu, addr, &gpa, exception, write);
@@ -6417,6 +6416,7 @@ static void init_emulate_ctxt(struct kvm_vcpu *vcpu)
64176416

64186417
kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
64196418

6419+
ctxt->gpa_available = false;
64206420
ctxt->eflags = kvm_get_rflags(vcpu);
64216421
ctxt->tf = (ctxt->eflags & X86_EFLAGS_TF) != 0;
64226422

@@ -6847,8 +6847,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
68476847

68486848
/* With shadow page tables, cr2 contains a GVA or nGPA. */
68496849
if (vcpu->arch.mmu->direct_map) {
6850-
vcpu->arch.gpa_available = true;
6851-
vcpu->arch.gpa_val = cr2_or_gpa;
6850+
ctxt->gpa_available = true;
6851+
ctxt->gpa_val = cr2_or_gpa;
68526852
}
68536853
} else {
68546854
/* Sanitize the address out of an abundance of paranoia. */
@@ -8454,7 +8454,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
84548454
if (vcpu->arch.apic_attention)
84558455
kvm_lapic_sync_from_vapic(vcpu);
84568456

8457-
vcpu->arch.gpa_available = false;
84588457
r = kvm_x86_ops->handle_exit(vcpu, exit_fastpath);
84598458
return r;
84608459

0 commit comments

Comments
 (0)