All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] get rid of mmu_only parameter in emulator_write_emulated()
@ 2010-04-13  7:21 Gleb Natapov
  2010-04-13  7:24 ` Avi Kivity
  2010-04-14 17:20 ` Marcelo Tosatti
  0 siblings, 2 replies; 7+ messages in thread
From: Gleb Natapov @ 2010-04-13  7:21 UTC (permalink / raw)
  To: avi; +Cc: kvm, mtosatti

May be I am missing something here, but it seams we can call
kvm_mmu_pte_write() directly from emulator_cmpxchg_emulated()
instead of passing mmu_only down to emulator_write_emulated_onepage()
and call it there.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a4e55ae..8ab30e1 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3327,8 +3327,7 @@ int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
 static int emulator_write_emulated_onepage(unsigned long addr,
 					   const void *val,
 					   unsigned int bytes,
-					   struct kvm_vcpu *vcpu,
-					   bool mmu_only)
+					   struct kvm_vcpu *vcpu)
 {
 	gpa_t                 gpa;
 	u32 error_code;
@@ -3344,10 +3343,6 @@ static int emulator_write_emulated_onepage(unsigned long addr,
 	if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
 		goto mmio;
 
-	if (mmu_only) {
-		kvm_mmu_pte_write(vcpu, gpa, val, bytes, 1);
-		return X86EMUL_CONTINUE;
-	}
 	if (emulator_write_phys(vcpu, gpa, val, bytes))
 		return X86EMUL_CONTINUE;
 
@@ -3368,35 +3363,24 @@ mmio:
 	return X86EMUL_CONTINUE;
 }
 
-int __emulator_write_emulated(unsigned long addr,
-				   const void *val,
-				   unsigned int bytes,
-				   struct kvm_vcpu *vcpu,
-				   bool mmu_only)
+int emulator_write_emulated(unsigned long addr,
+			    const void *val,
+			    unsigned int bytes,
+			    struct kvm_vcpu *vcpu)
 {
 	/* Crossing a page boundary? */
 	if (((addr + bytes - 1) ^ addr) & PAGE_MASK) {
 		int rc, now;
 
 		now = -addr & ~PAGE_MASK;
-		rc = emulator_write_emulated_onepage(addr, val, now, vcpu,
-						     mmu_only);
+		rc = emulator_write_emulated_onepage(addr, val, now, vcpu);
 		if (rc != X86EMUL_CONTINUE)
 			return rc;
 		addr += now;
 		val += now;
 		bytes -= now;
 	}
-	return emulator_write_emulated_onepage(addr, val, bytes, vcpu,
-					       mmu_only);
-}
-
-int emulator_write_emulated(unsigned long addr,
-				   const void *val,
-				   unsigned int bytes,
-				   struct kvm_vcpu *vcpu)
-{
-	return __emulator_write_emulated(addr, val, bytes, vcpu, false);
+	return emulator_write_emulated_onepage(addr, val, bytes, vcpu);
 }
 EXPORT_SYMBOL_GPL(emulator_write_emulated);
 
@@ -3460,7 +3444,9 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
 	if (!exchanged)
 		return X86EMUL_CMPXCHG_FAILED;
 
-	return __emulator_write_emulated(addr, new, bytes, vcpu, true);
+	kvm_mmu_pte_write(vcpu, gpa, new, bytes, 1);
+
+	return X86EMUL_CONTINUE;
 
 emul_write:
 	printk_once(KERN_WARNING "kvm: emulating exchange as write\n");
@@ -4174,7 +4160,7 @@ int kvm_fix_hypercall(struct kvm_vcpu *vcpu)
 
 	kvm_x86_ops->patch_hypercall(vcpu, instruction);
 
-	return __emulator_write_emulated(rip, instruction, 3, vcpu, false);
+	return emulator_write_emulated(rip, instruction, 3, vcpu);
 }
 
 void realmode_lgdt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base)
--
			Gleb.

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

* Re: [PATCH] get rid of mmu_only parameter in emulator_write_emulated()
  2010-04-13  7:21 [PATCH] get rid of mmu_only parameter in emulator_write_emulated() Gleb Natapov
@ 2010-04-13  7:24 ` Avi Kivity
  2010-04-13  7:26   ` Gleb Natapov
  2010-04-14 17:20 ` Marcelo Tosatti
  1 sibling, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2010-04-13  7:24 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kvm, mtosatti

On 04/13/2010 10:21 AM, Gleb Natapov wrote:
> May be I am missing something here, but it seams we can call
> kvm_mmu_pte_write() directly from emulator_cmpxchg_emulated()
> instead of passing mmu_only down to emulator_write_emulated_onepage()
> and call it there.
>
>
> @@ -3460,7 +3444,9 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
>   	if (!exchanged)
>   		return X86EMUL_CMPXCHG_FAILED;
>
> -	return __emulator_write_emulated(addr, new, bytes, vcpu, true);
> +	kvm_mmu_pte_write(vcpu, gpa, new, bytes, 1);
> +
> +	return X86EMUL_CONTINUE;
>
>    

The written range might cross a page boundary, which kvm_mmu_pte_write() 
is not prepared to handle.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


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

* Re: [PATCH] get rid of mmu_only parameter in emulator_write_emulated()
  2010-04-13  7:24 ` Avi Kivity
@ 2010-04-13  7:26   ` Gleb Natapov
  2010-04-13  7:35     ` Avi Kivity
  0 siblings, 1 reply; 7+ messages in thread
From: Gleb Natapov @ 2010-04-13  7:26 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm, mtosatti

On Tue, Apr 13, 2010 at 10:24:40AM +0300, Avi Kivity wrote:
> On 04/13/2010 10:21 AM, Gleb Natapov wrote:
> >May be I am missing something here, but it seams we can call
> >kvm_mmu_pte_write() directly from emulator_cmpxchg_emulated()
> >instead of passing mmu_only down to emulator_write_emulated_onepage()
> >and call it there.
> >
> >
> >@@ -3460,7 +3444,9 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
> >  	if (!exchanged)
> >  		return X86EMUL_CMPXCHG_FAILED;
> >
> >-	return __emulator_write_emulated(addr, new, bytes, vcpu, true);
> >+	kvm_mmu_pte_write(vcpu, gpa, new, bytes, 1);
> >+
> >+	return X86EMUL_CONTINUE;
> >
> 
> The written range might cross a page boundary, which
> kvm_mmu_pte_write() is not prepared to handle.
> 
Don't we emulate exchange as write in this case?

	if (((gpa + bytes - 1) & PAGE_MASK) != (gpa & PAGE_MASK))
		goto emul_write;

--
			Gleb.

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

* Re: [PATCH] get rid of mmu_only parameter in emulator_write_emulated()
  2010-04-13  7:26   ` Gleb Natapov
@ 2010-04-13  7:35     ` Avi Kivity
  2010-04-13  7:40       ` Gleb Natapov
  0 siblings, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2010-04-13  7:35 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kvm, mtosatti

On 04/13/2010 10:26 AM, Gleb Natapov wrote:
> On Tue, Apr 13, 2010 at 10:24:40AM +0300, Avi Kivity wrote:
>    
>> On 04/13/2010 10:21 AM, Gleb Natapov wrote:
>>      
>>> May be I am missing something here, but it seams we can call
>>> kvm_mmu_pte_write() directly from emulator_cmpxchg_emulated()
>>> instead of passing mmu_only down to emulator_write_emulated_onepage()
>>> and call it there.
>>>
>>>
>>> @@ -3460,7 +3444,9 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
>>>   	if (!exchanged)
>>>   		return X86EMUL_CMPXCHG_FAILED;
>>>
>>> -	return __emulator_write_emulated(addr, new, bytes, vcpu, true);
>>> +	kvm_mmu_pte_write(vcpu, gpa, new, bytes, 1);
>>> +
>>> +	return X86EMUL_CONTINUE;
>>>
>>>        
>> The written range might cross a page boundary, which
>> kvm_mmu_pte_write() is not prepared to handle.
>>
>>      
> Don't we emulate exchange as write in this case?
>
> 	if (((gpa + bytes - 1)&  PAGE_MASK) != (gpa&  PAGE_MASK))
> 		goto emul_write;
>    

We do, but that's unrelated.  We still have to invalidate potential ptes 
on both pages

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


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

* Re: [PATCH] get rid of mmu_only parameter in emulator_write_emulated()
  2010-04-13  7:35     ` Avi Kivity
@ 2010-04-13  7:40       ` Gleb Natapov
  2010-04-13  9:21         ` Avi Kivity
  0 siblings, 1 reply; 7+ messages in thread
From: Gleb Natapov @ 2010-04-13  7:40 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm, mtosatti

On Tue, Apr 13, 2010 at 10:35:53AM +0300, Avi Kivity wrote:
> On 04/13/2010 10:26 AM, Gleb Natapov wrote:
> >On Tue, Apr 13, 2010 at 10:24:40AM +0300, Avi Kivity wrote:
> >>On 04/13/2010 10:21 AM, Gleb Natapov wrote:
> >>>May be I am missing something here, but it seams we can call
> >>>kvm_mmu_pte_write() directly from emulator_cmpxchg_emulated()
> >>>instead of passing mmu_only down to emulator_write_emulated_onepage()
> >>>and call it there.
> >>>
> >>>
> >>>@@ -3460,7 +3444,9 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
> >>>  	if (!exchanged)
> >>>  		return X86EMUL_CMPXCHG_FAILED;
> >>>
> >>>-	return __emulator_write_emulated(addr, new, bytes, vcpu, true);
> >>>+	kvm_mmu_pte_write(vcpu, gpa, new, bytes, 1);
> >>>+
> >>>+	return X86EMUL_CONTINUE;
> >>>
> >>The written range might cross a page boundary, which
> >>kvm_mmu_pte_write() is not prepared to handle.
> >>
> >Don't we emulate exchange as write in this case?
> >
> >	if (((gpa + bytes - 1)&  PAGE_MASK) != (gpa&  PAGE_MASK))
> >		goto emul_write;
> 
> We do, but that's unrelated.  We still have to invalidate potential
> ptes on both pages
> 
The code path executed in case of cmpxchg crossing page boundary is not
touched by the patch as far as I can see. In this case
emulator_write_emulated() is executed with mmu_only false and
kvm_mmu_pte_write() is called from emulator_write_phys().

--
			Gleb.

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

* Re: [PATCH] get rid of mmu_only parameter in emulator_write_emulated()
  2010-04-13  7:40       ` Gleb Natapov
@ 2010-04-13  9:21         ` Avi Kivity
  0 siblings, 0 replies; 7+ messages in thread
From: Avi Kivity @ 2010-04-13  9:21 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kvm, mtosatti

On 04/13/2010 10:40 AM, Gleb Natapov wrote:
> The code path executed in case of cmpxchg crossing page boundary is not
> touched by the patch as far as I can see. In this case
> emulator_write_emulated() is executed with mmu_only false and
> kvm_mmu_pte_write() is called from emulator_write_phys().
>
>    

Yes. Patch is correct.

-- 
error compiling committee.c: too many arguments to function


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

* Re: [PATCH] get rid of mmu_only parameter in emulator_write_emulated()
  2010-04-13  7:21 [PATCH] get rid of mmu_only parameter in emulator_write_emulated() Gleb Natapov
  2010-04-13  7:24 ` Avi Kivity
@ 2010-04-14 17:20 ` Marcelo Tosatti
  1 sibling, 0 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2010-04-14 17:20 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: avi, kvm

On Tue, Apr 13, 2010 at 10:21:56AM +0300, Gleb Natapov wrote:
> May be I am missing something here, but it seams we can call
> kvm_mmu_pte_write() directly from emulator_cmpxchg_emulated()
> instead of passing mmu_only down to emulator_write_emulated_onepage()
> and call it there.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>

Applied, thanks.


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

end of thread, other threads:[~2010-04-14 17:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-13  7:21 [PATCH] get rid of mmu_only parameter in emulator_write_emulated() Gleb Natapov
2010-04-13  7:24 ` Avi Kivity
2010-04-13  7:26   ` Gleb Natapov
2010-04-13  7:35     ` Avi Kivity
2010-04-13  7:40       ` Gleb Natapov
2010-04-13  9:21         ` Avi Kivity
2010-04-14 17:20 ` Marcelo Tosatti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.