Skip to content

Commit fc5375d

Browse files
committed
KVM: x86: Make kvm_get_dr() return a value, not use an out parameter
Convert kvm_get_dr()'s output parameter to a return value, and clean up most of the mess that was created by forcing callers to provide a pointer. No functional change intended. Acked-by: Mathias Krause <[email protected]> Reviewed-by: Mathias Krause <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 64435aa commit fc5375d

File tree

8 files changed

+21
-49
lines changed

8 files changed

+21
-49
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,7 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3);
20452045
int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
20462046
int kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8);
20472047
int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val);
2048-
void kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val);
2048+
unsigned long kvm_get_dr(struct kvm_vcpu *vcpu, int dr);
20492049
unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu);
20502050
void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
20512051
int kvm_emulate_xsetbv(struct kvm_vcpu *vcpu);

arch/x86/kvm/emulate.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,7 +3013,7 @@ static int emulator_do_task_switch(struct x86_emulate_ctxt *ctxt,
30133013
ret = em_push(ctxt);
30143014
}
30153015

3016-
ops->get_dr(ctxt, 7, &dr7);
3016+
dr7 = ops->get_dr(ctxt, 7);
30173017
ops->set_dr(ctxt, 7, dr7 & ~(DR_LOCAL_ENABLE_MASK | DR_LOCAL_SLOWDOWN));
30183018

30193019
return ret;
@@ -3868,15 +3868,6 @@ static int check_cr_access(struct x86_emulate_ctxt *ctxt)
38683868
return X86EMUL_CONTINUE;
38693869
}
38703870

3871-
static int check_dr7_gd(struct x86_emulate_ctxt *ctxt)
3872-
{
3873-
unsigned long dr7;
3874-
3875-
ctxt->ops->get_dr(ctxt, 7, &dr7);
3876-
3877-
return dr7 & DR7_GD;
3878-
}
3879-
38803871
static int check_dr_read(struct x86_emulate_ctxt *ctxt)
38813872
{
38823873
int dr = ctxt->modrm_reg;
@@ -3889,10 +3880,10 @@ static int check_dr_read(struct x86_emulate_ctxt *ctxt)
38893880
if ((cr4 & X86_CR4_DE) && (dr == 4 || dr == 5))
38903881
return emulate_ud(ctxt);
38913882

3892-
if (check_dr7_gd(ctxt)) {
3883+
if (ctxt->ops->get_dr(ctxt, 7) & DR7_GD) {
38933884
ulong dr6;
38943885

3895-
ctxt->ops->get_dr(ctxt, 6, &dr6);
3886+
dr6 = ctxt->ops->get_dr(ctxt, 6);
38963887
dr6 &= ~DR_TRAP_BITS;
38973888
dr6 |= DR6_BD | DR6_ACTIVE_LOW;
38983889
ctxt->ops->set_dr(ctxt, 6, dr6);
@@ -5451,7 +5442,7 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
54515442
ctxt->dst.val = ops->get_cr(ctxt, ctxt->modrm_reg);
54525443
break;
54535444
case 0x21: /* mov from dr to reg */
5454-
ops->get_dr(ctxt, ctxt->modrm_reg, &ctxt->dst.val);
5445+
ctxt->dst.val = ops->get_dr(ctxt, ctxt->modrm_reg);
54555446
break;
54565447
case 0x40 ... 0x4f: /* cmov */
54575448
if (test_cc(ctxt->b, ctxt->eflags))

arch/x86/kvm/kvm_emulate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct x86_emulate_ops {
203203
ulong (*get_cr)(struct x86_emulate_ctxt *ctxt, int cr);
204204
int (*set_cr)(struct x86_emulate_ctxt *ctxt, int cr, ulong val);
205205
int (*cpl)(struct x86_emulate_ctxt *ctxt);
206-
void (*get_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong *dest);
206+
ulong (*get_dr)(struct x86_emulate_ctxt *ctxt, int dr);
207207
int (*set_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong value);
208208
int (*set_msr_with_filter)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 data);
209209
int (*get_msr_with_filter)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 *pdata);

arch/x86/kvm/smm.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ static void enter_smm_save_state_32(struct kvm_vcpu *vcpu,
184184
struct kvm_smram_state_32 *smram)
185185
{
186186
struct desc_ptr dt;
187-
unsigned long val;
188187
int i;
189188

190189
smram->cr0 = kvm_read_cr0(vcpu);
@@ -195,10 +194,8 @@ static void enter_smm_save_state_32(struct kvm_vcpu *vcpu,
195194
for (i = 0; i < 8; i++)
196195
smram->gprs[i] = kvm_register_read_raw(vcpu, i);
197196

198-
kvm_get_dr(vcpu, 6, &val);
199-
smram->dr6 = (u32)val;
200-
kvm_get_dr(vcpu, 7, &val);
201-
smram->dr7 = (u32)val;
197+
smram->dr6 = (u32)kvm_get_dr(vcpu, 6);
198+
smram->dr7 = (u32)kvm_get_dr(vcpu, 7);
202199

203200
enter_smm_save_seg_32(vcpu, &smram->tr, &smram->tr_sel, VCPU_SREG_TR);
204201
enter_smm_save_seg_32(vcpu, &smram->ldtr, &smram->ldtr_sel, VCPU_SREG_LDTR);
@@ -231,7 +228,6 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu,
231228
struct kvm_smram_state_64 *smram)
232229
{
233230
struct desc_ptr dt;
234-
unsigned long val;
235231
int i;
236232

237233
for (i = 0; i < 16; i++)
@@ -240,11 +236,8 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu,
240236
smram->rip = kvm_rip_read(vcpu);
241237
smram->rflags = kvm_get_rflags(vcpu);
242238

243-
244-
kvm_get_dr(vcpu, 6, &val);
245-
smram->dr6 = val;
246-
kvm_get_dr(vcpu, 7, &val);
247-
smram->dr7 = val;
239+
smram->dr6 = kvm_get_dr(vcpu, 6);
240+
smram->dr7 = kvm_get_dr(vcpu, 7);
248241

249242
smram->cr0 = kvm_read_cr0(vcpu);
250243
smram->cr3 = kvm_read_cr3(vcpu);

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,7 +2735,6 @@ static int dr_interception(struct kvm_vcpu *vcpu)
27352735
{
27362736
struct vcpu_svm *svm = to_svm(vcpu);
27372737
int reg, dr;
2738-
unsigned long val;
27392738
int err = 0;
27402739

27412740
/*
@@ -2763,11 +2762,9 @@ static int dr_interception(struct kvm_vcpu *vcpu)
27632762
dr = svm->vmcb->control.exit_code - SVM_EXIT_READ_DR0;
27642763
if (dr >= 16) { /* mov to DRn */
27652764
dr -= 16;
2766-
val = kvm_register_read(vcpu, reg);
2767-
err = kvm_set_dr(vcpu, dr, val);
2765+
err = kvm_set_dr(vcpu, dr, kvm_register_read(vcpu, reg));
27682766
} else {
2769-
kvm_get_dr(vcpu, dr, &val);
2770-
kvm_register_write(vcpu, reg, val);
2767+
kvm_register_write(vcpu, reg, kvm_get_dr(vcpu, dr));
27712768
}
27722769

27732770
return kvm_complete_insn_gp(vcpu, err);

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-
kvm_get_dr(vcpu, 7, (unsigned long *)&vmcs12->guest_dr7);
4436+
vmcs12->guest_dr7 = kvm_get_dr(vcpu, 7);
44374437

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

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5566,10 +5566,7 @@ static int handle_dr(struct kvm_vcpu *vcpu)
55665566

55675567
reg = DEBUG_REG_ACCESS_REG(exit_qualification);
55685568
if (exit_qualification & TYPE_MOV_FROM_DR) {
5569-
unsigned long val;
5570-
5571-
kvm_get_dr(vcpu, dr, &val);
5572-
kvm_register_write(vcpu, reg, val);
5569+
kvm_register_write(vcpu, reg, kvm_get_dr(vcpu, dr));
55735570
err = 0;
55745571
} else {
55755572
err = kvm_set_dr(vcpu, dr, kvm_register_read(vcpu, reg));

arch/x86/kvm/x86.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,22 +1399,19 @@ int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val)
13991399
}
14001400
EXPORT_SYMBOL_GPL(kvm_set_dr);
14011401

1402-
void kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val)
1402+
unsigned long kvm_get_dr(struct kvm_vcpu *vcpu, int dr)
14031403
{
14041404
size_t size = ARRAY_SIZE(vcpu->arch.db);
14051405

14061406
switch (dr) {
14071407
case 0 ... 3:
1408-
*val = vcpu->arch.db[array_index_nospec(dr, size)];
1409-
break;
1408+
return vcpu->arch.db[array_index_nospec(dr, size)];
14101409
case 4:
14111410
case 6:
1412-
*val = vcpu->arch.dr6;
1413-
break;
1411+
return vcpu->arch.dr6;
14141412
case 5:
14151413
default: /* 7 */
1416-
*val = vcpu->arch.dr7;
1417-
break;
1414+
return vcpu->arch.dr7;
14181415
}
14191416
}
14201417
EXPORT_SYMBOL_GPL(kvm_get_dr);
@@ -5509,7 +5506,6 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
55095506
static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
55105507
struct kvm_debugregs *dbgregs)
55115508
{
5512-
unsigned long val;
55135509
unsigned int i;
55145510

55155511
memset(dbgregs, 0, sizeof(*dbgregs));
@@ -5518,8 +5514,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
55185514
for (i = 0; i < ARRAY_SIZE(vcpu->arch.db); i++)
55195515
dbgregs->db[i] = vcpu->arch.db[i];
55205516

5521-
kvm_get_dr(vcpu, 6, &val);
5522-
dbgregs->dr6 = val;
5517+
dbgregs->dr6 = kvm_get_dr(vcpu, 6);
55235518
dbgregs->dr7 = vcpu->arch.dr7;
55245519
}
55255520

@@ -8173,10 +8168,9 @@ static void emulator_wbinvd(struct x86_emulate_ctxt *ctxt)
81738168
kvm_emulate_wbinvd_noskip(emul_to_vcpu(ctxt));
81748169
}
81758170

8176-
static void emulator_get_dr(struct x86_emulate_ctxt *ctxt, int dr,
8177-
unsigned long *dest)
8171+
static unsigned long emulator_get_dr(struct x86_emulate_ctxt *ctxt, int dr)
81788172
{
8179-
kvm_get_dr(emul_to_vcpu(ctxt), dr, dest);
8173+
return kvm_get_dr(emul_to_vcpu(ctxt), dr);
81808174
}
81818175

81828176
static int emulator_set_dr(struct x86_emulate_ctxt *ctxt, int dr,

0 commit comments

Comments
 (0)