public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86: svm: use kvm_register_write()/read()
@ 2015-02-20 22:02 Joel Schopp
  2015-02-20 23:21 ` Borislav Petkov
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Schopp @ 2015-02-20 22:02 UTC (permalink / raw)
  To: Gleb Natapov, Paolo Bonzini, kvm
  Cc: Joerg Roedel, Borislav Petkov, linux-kernel, David Kaplan

From: David Kaplan <david.kaplan@amd.com>

KVM has nice wrappers to access the register values, clean up a few places
that should use them but currently do not.

Signed-off-by: David Kaplan <david.kaplan@amd.com>
[forward port and testing]
Signed-off-by: Joel Schopp <joel.schopp@amd.com>
---
 arch/x86/kvm/svm.c |   19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index d319e0c..a7d88e4 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -2757,11 +2757,11 @@ static int invlpga_interception(struct vcpu_svm *svm)
 {
 	struct kvm_vcpu *vcpu = &svm->vcpu;
 
-	trace_kvm_invlpga(svm->vmcb->save.rip, vcpu->arch.regs[VCPU_REGS_RCX],
-			  vcpu->arch.regs[VCPU_REGS_RAX]);
+	trace_kvm_invlpga(svm->vmcb->save.rip, kvm_register_read(&svm->vcpu, VCPU_REGS_RCX),
+			  kvm_register_read(&svm->vcpu, VCPU_REGS_RAX));
 
 	/* Let's treat INVLPGA the same as INVLPG (can be optimized!) */
-	kvm_mmu_invlpg(vcpu, vcpu->arch.regs[VCPU_REGS_RAX]);
+	kvm_mmu_invlpg(vcpu, kvm_register_read(&svm->vcpu, VCPU_REGS_RAX));
 
 	svm->next_rip = kvm_rip_read(&svm->vcpu) + 3;
 	skip_emulated_instruction(&svm->vcpu);
@@ -2770,7 +2770,7 @@ static int invlpga_interception(struct vcpu_svm *svm)
 
 static int skinit_interception(struct vcpu_svm *svm)
 {
-	trace_kvm_skinit(svm->vmcb->save.rip, svm->vcpu.arch.regs[VCPU_REGS_RAX]);
+	trace_kvm_skinit(svm->vmcb->save.rip, kvm_register_read(&svm->vcpu, VCPU_REGS_RAX));
 
 	kvm_queue_exception(&svm->vcpu, UD_VECTOR);
 	return 1;
@@ -3133,7 +3133,7 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
 
 static int rdmsr_interception(struct vcpu_svm *svm)
 {
-	u32 ecx = svm->vcpu.arch.regs[VCPU_REGS_RCX];
+	u32 ecx = kvm_register_read(&svm->vcpu, VCPU_REGS_RCX);
 	u64 data;
 
 	if (svm_get_msr(&svm->vcpu, ecx, &data)) {
@@ -3142,8 +3142,8 @@ static int rdmsr_interception(struct vcpu_svm *svm)
 	} else {
 		trace_kvm_msr_read(ecx, data);
 
-		svm->vcpu.arch.regs[VCPU_REGS_RAX] = data & 0xffffffff;
-		svm->vcpu.arch.regs[VCPU_REGS_RDX] = data >> 32;
+		kvm_register_write(&svm->vcpu, VCPU_REGS_RAX, data & 0xffffffff);
+		kvm_register_write(&svm->vcpu, VCPU_REGS_RDX, data >> 32);
 		svm->next_rip = kvm_rip_read(&svm->vcpu) + 2;
 		skip_emulated_instruction(&svm->vcpu);
 	}
@@ -3246,9 +3246,8 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
 static int wrmsr_interception(struct vcpu_svm *svm)
 {
 	struct msr_data msr;
-	u32 ecx = svm->vcpu.arch.regs[VCPU_REGS_RCX];
-	u64 data = (svm->vcpu.arch.regs[VCPU_REGS_RAX] & -1u)
-		| ((u64)(svm->vcpu.arch.regs[VCPU_REGS_RDX] & -1u) << 32);
+	u32 ecx = kvm_register_read(&svm->vcpu, VCPU_REGS_RCX);
+	u64 data = kvm_read_edx_eax(&svm->vcpu);
 
 	msr.data = data;
 	msr.index = ecx;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] x86: svm: use kvm_register_write()/read()
  2015-02-20 22:02 [PATCH v2] x86: svm: use kvm_register_write()/read() Joel Schopp
@ 2015-02-20 23:21 ` Borislav Petkov
  2015-02-25 22:26   ` Marcelo Tosatti
  0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2015-02-20 23:21 UTC (permalink / raw)
  To: Joel Schopp
  Cc: Gleb Natapov, Paolo Bonzini, kvm, Joerg Roedel, linux-kernel,
	David Kaplan

On Fri, Feb 20, 2015 at 04:02:10PM -0600, Joel Schopp wrote:
> From: David Kaplan <david.kaplan@amd.com>
> 
> KVM has nice wrappers to access the register values, clean up a few places
> that should use them but currently do not.
> 
> Signed-off-by: David Kaplan <david.kaplan@amd.com>
> [forward port and testing]
> Signed-off-by: Joel Schopp <joel.schopp@amd.com>

Looks good.

Acked-by: Borislav Petkov <bp@suse.de>

> ---
>  arch/x86/kvm/svm.c |   19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index d319e0c..a7d88e4 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c

...

> @@ -3142,8 +3142,8 @@ static int rdmsr_interception(struct vcpu_svm *svm)
>  	} else {
>  		trace_kvm_msr_read(ecx, data);
>  
> -		svm->vcpu.arch.regs[VCPU_REGS_RAX] = data & 0xffffffff;
> -		svm->vcpu.arch.regs[VCPU_REGS_RDX] = data >> 32;
> +		kvm_register_write(&svm->vcpu, VCPU_REGS_RAX, data & 0xffffffff);
> +		kvm_register_write(&svm->vcpu, VCPU_REGS_RDX, data >> 32);

Right, kvm is missing kvm_write_edx_eax() in addition to the read
variant. Someone might want to do a patch and such, ^^hint hint^^...

:-)

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] x86: svm: use kvm_register_write()/read()
  2015-02-20 23:21 ` Borislav Petkov
@ 2015-02-25 22:26   ` Marcelo Tosatti
  0 siblings, 0 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2015-02-25 22:26 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Joel Schopp, Gleb Natapov, Paolo Bonzini, kvm, Joerg Roedel,
	linux-kernel, David Kaplan

On Sat, Feb 21, 2015 at 12:21:16AM +0100, Borislav Petkov wrote:
> On Fri, Feb 20, 2015 at 04:02:10PM -0600, Joel Schopp wrote:
> > From: David Kaplan <david.kaplan@amd.com>
> > 
> > KVM has nice wrappers to access the register values, clean up a few places
> > that should use them but currently do not.
> > 
> > Signed-off-by: David Kaplan <david.kaplan@amd.com>
> > [forward port and testing]
> > Signed-off-by: Joel Schopp <joel.schopp@amd.com>
> 
> Looks good.
> 
> Acked-by: Borislav Petkov <bp@suse.de>

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-25 22:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-20 22:02 [PATCH v2] x86: svm: use kvm_register_write()/read() Joel Schopp
2015-02-20 23:21 ` Borislav Petkov
2015-02-25 22:26   ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox