Skip to content

Commit 2a5f091

Browse files
committed
KVM: x86: Open code all direct reads to guest DR6 and DR7
Bite the bullet, and open code all direct reads of DR6 and DR7. KVM currently has a mix of open coded accesses and calls to kvm_get_dr(), which is confusing and ugly because there's no rhyme or reason as to why any particular chunk of code uses kvm_get_dr(). The obvious alternative is to force all accesses through kvm_get_dr(), but it's not at all clear that doing so would be a net positive, e.g. even if KVM ends up wanting/needing to force all reads through a common helper, e.g. to play caching games, the cost of reverting this change is likely lower than the ongoing cost of maintaining weird, arbitrary code. No functional change intended. Cc: Mathias Krause <minipli@grsecurity.net> Reviewed-by: Mathias Krause <minipli@grsecurity.net> Link: https://lore.kernel.org/r/20240209220752.388160-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent fc5375d commit 2a5f091

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

arch/x86/kvm/smm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ static void enter_smm_save_state_32(struct kvm_vcpu *vcpu,
194194
for (i = 0; i < 8; i++)
195195
smram->gprs[i] = kvm_register_read_raw(vcpu, i);
196196

197-
smram->dr6 = (u32)kvm_get_dr(vcpu, 6);
198-
smram->dr7 = (u32)kvm_get_dr(vcpu, 7);
197+
smram->dr6 = (u32)vcpu->arch.dr6;
198+
smram->dr7 = (u32)vcpu->arch.dr7;
199199

200200
enter_smm_save_seg_32(vcpu, &smram->tr, &smram->tr_sel, VCPU_SREG_TR);
201201
enter_smm_save_seg_32(vcpu, &smram->ldtr, &smram->ldtr_sel, VCPU_SREG_LDTR);
@@ -236,8 +236,8 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu,
236236
smram->rip = kvm_rip_read(vcpu);
237237
smram->rflags = kvm_get_rflags(vcpu);
238238

239-
smram->dr6 = kvm_get_dr(vcpu, 6);
240-
smram->dr7 = kvm_get_dr(vcpu, 7);
239+
smram->dr6 = vcpu->arch.dr6;
240+
smram->dr7 = vcpu->arch.dr7;
241241

242242
smram->cr0 = kvm_read_cr0(vcpu);
243243
smram->cr3 = kvm_read_cr3(vcpu);

arch/x86/kvm/vmx/nested.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4433,7 +4433,7 @@ static void sync_vmcs02_to_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
44334433
(vm_entry_controls_get(to_vmx(vcpu)) & VM_ENTRY_IA32E_MODE);
44344434

44354435
if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_DEBUG_CONTROLS)
4436-
vmcs12->guest_dr7 = kvm_get_dr(vcpu, 7);
4436+
vmcs12->guest_dr7 = vcpu->arch.dr7;
44374437

44384438
if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_IA32_EFER)
44394439
vmcs12->guest_ia32_efer = vcpu->arch.efer;

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5514,7 +5514,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
55145514
for (i = 0; i < ARRAY_SIZE(vcpu->arch.db); i++)
55155515
dbgregs->db[i] = vcpu->arch.db[i];
55165516

5517-
dbgregs->dr6 = kvm_get_dr(vcpu, 6);
5517+
dbgregs->dr6 = vcpu->arch.dr6;
55185518
dbgregs->dr7 = vcpu->arch.dr7;
55195519
}
55205520

0 commit comments

Comments
 (0)