mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KVM/MMU: Combine flushing remote tlb in mmu_set_spte()
@ 2018-07-24  8:17 Tianyu Lan
  2018-07-24 14:35 ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Tianyu Lan @ 2018-07-24  8:17 UTC (permalink / raw)
  Cc: Tianyu Lan, pbonzini, rkrcmar, tglx, mingo, hpa, x86, kvm, linux-kernel

mmu_set_spte() flushes remote tlbs for drop_parent_pte/drop_spte()
and set_spte() separately. This may introduce redundant flush. This
patch is to combine these flushes and check flush request after
calling set_spte().

Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
---
 arch/x86/kvm/mmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 22a7984..8f21632 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2901,6 +2901,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
 	int rmap_count;
 	int set_spte_ret;
 	int ret = RET_PF_RETRY;
+	bool flush = false;
 
 	pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__,
 		 *sptep, write_fault, gfn);
@@ -2917,12 +2918,12 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
 
 			child = page_header(pte & PT64_BASE_ADDR_MASK);
 			drop_parent_pte(child, sptep);
-			kvm_flush_remote_tlbs(vcpu->kvm);
+			flush = true;
 		} else if (pfn != spte_to_pfn(*sptep)) {
 			pgprintk("hfn old %llx new %llx\n",
 				 spte_to_pfn(*sptep), pfn);
 			drop_spte(vcpu->kvm, sptep);
-			kvm_flush_remote_tlbs(vcpu->kvm);
+			flush = true;
 		} else
 			was_rmapped = 1;
 	}
@@ -2934,7 +2935,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
 			ret = RET_PF_EMULATE;
 		kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
 	}
-	if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH)
+	if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH || flush)
 		kvm_flush_remote_tlbs(vcpu->kvm);
 
 	if (unlikely(is_mmio_spte(*sptep)))
-- 
2.7.4

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

* Re: [PATCH] KVM/MMU: Combine flushing remote tlb in mmu_set_spte()
  2018-07-24  8:17 [PATCH] KVM/MMU: Combine flushing remote tlb in mmu_set_spte() Tianyu Lan
@ 2018-07-24 14:35 ` Paolo Bonzini
  2018-07-25  2:26   ` Junaid Shahid
  2018-07-25  6:22   ` Xiao Guangrong
  0 siblings, 2 replies; 5+ messages in thread
From: Paolo Bonzini @ 2018-07-24 14:35 UTC (permalink / raw)
  To: Tianyu Lan
  Cc: rkrcmar, tglx, mingo, hpa, x86, kvm, linux-kernel,
	Xiao Guangrong, Junaid Shahid

On 24/07/2018 10:17, Tianyu Lan wrote:
> mmu_set_spte() flushes remote tlbs for drop_parent_pte/drop_spte()
> and set_spte() separately. This may introduce redundant flush. This
> patch is to combine these flushes and check flush request after
> calling set_spte().
> 
> Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>

Looks good, but I'd like a second opinion.  Guangrong, Junaid, can you
review this?

Thanks,

Paolo

> ---
>  arch/x86/kvm/mmu.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 22a7984..8f21632 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -2901,6 +2901,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
>  	int rmap_count;
>  	int set_spte_ret;
>  	int ret = RET_PF_RETRY;
> +	bool flush = false;
>  
>  	pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__,
>  		 *sptep, write_fault, gfn);
> @@ -2917,12 +2918,12 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
>  
>  			child = page_header(pte & PT64_BASE_ADDR_MASK);
>  			drop_parent_pte(child, sptep);
> -			kvm_flush_remote_tlbs(vcpu->kvm);
> +			flush = true;
>  		} else if (pfn != spte_to_pfn(*sptep)) {
>  			pgprintk("hfn old %llx new %llx\n",
>  				 spte_to_pfn(*sptep), pfn);
>  			drop_spte(vcpu->kvm, sptep);
> -			kvm_flush_remote_tlbs(vcpu->kvm);
> +			flush = true;
>  		} else
>  			was_rmapped = 1;
>  	}
> @@ -2934,7 +2935,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
>  			ret = RET_PF_EMULATE;
>  		kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
>  	}
> -	if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH)
> +	if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH || flush)
>  		kvm_flush_remote_tlbs(vcpu->kvm);
>  
>  	if (unlikely(is_mmio_spte(*sptep)))
> 


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

* Re: [PATCH] KVM/MMU: Combine flushing remote tlb in mmu_set_spte()
  2018-07-24 14:35 ` Paolo Bonzini
@ 2018-07-25  2:26   ` Junaid Shahid
  2018-07-25  2:35     ` Tianyu Lan
  2018-07-25  6:22   ` Xiao Guangrong
  1 sibling, 1 reply; 5+ messages in thread
From: Junaid Shahid @ 2018-07-25  2:26 UTC (permalink / raw)
  To: Paolo Bonzini, Tianyu Lan
  Cc: rkrcmar, tglx, mingo, hpa, x86, kvm, linux-kernel, Xiao Guangrong

On 07/24/2018 07:35 AM, Paolo Bonzini wrote:
> On 24/07/2018 10:17, Tianyu Lan wrote:
>> mmu_set_spte() flushes remote tlbs for drop_parent_pte/drop_spte()
>> and set_spte() separately. This may introduce redundant flush. This
>> patch is to combine these flushes and check flush request after
>> calling set_spte().
>>
>> Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
> 
> Looks good, but I'd like a second opinion.  Guangrong, Junaid, can you
> review this?
> 
> Thanks,
> 
> Paolo
> 
>> ---
>>  arch/x86/kvm/mmu.c | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
>> index 22a7984..8f21632 100644
>> --- a/arch/x86/kvm/mmu.c
>> +++ b/arch/x86/kvm/mmu.c
>> @@ -2901,6 +2901,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
>>  	int rmap_count;
>>  	int set_spte_ret;
>>  	int ret = RET_PF_RETRY;
>> +	bool flush = false;
>>  
>>  	pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__,
>>  		 *sptep, write_fault, gfn);
>> @@ -2917,12 +2918,12 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
>>  
>>  			child = page_header(pte & PT64_BASE_ADDR_MASK);
>>  			drop_parent_pte(child, sptep);
>> -			kvm_flush_remote_tlbs(vcpu->kvm);
>> +			flush = true;
>>  		} else if (pfn != spte_to_pfn(*sptep)) {
>>  			pgprintk("hfn old %llx new %llx\n",
>>  				 spte_to_pfn(*sptep), pfn);
>>  			drop_spte(vcpu->kvm, sptep);
>> -			kvm_flush_remote_tlbs(vcpu->kvm);
>> +			flush = true;
>>  		} else
>>  			was_rmapped = 1;
>>  	}
>> @@ -2934,7 +2935,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
>>  			ret = RET_PF_EMULATE;
>>  		kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
>>  	}
>> -	if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH)
>> +	if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH || flush)
>>  		kvm_flush_remote_tlbs(vcpu->kvm);
>>  
>>  	if (unlikely(is_mmio_spte(*sptep)))
>>
> 

Reviewed-by: Junaid Shahid <junaids@google.com>

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

* Re: [PATCH] KVM/MMU: Combine flushing remote tlb in mmu_set_spte()
  2018-07-25  2:26   ` Junaid Shahid
@ 2018-07-25  2:35     ` Tianyu Lan
  0 siblings, 0 replies; 5+ messages in thread
From: Tianyu Lan @ 2018-07-25  2:35 UTC (permalink / raw)
  To: Junaid Shahid, Paolo Bonzini, Tianyu Lan
  Cc: rkrcmar, tglx, mingo, hpa, x86, kvm, linux-kernel, Xiao Guangrong

Hi Junaid:
	Thanks for your review.

On 7/25/2018 10:26 AM, Junaid Shahid wrote:
> On 07/24/2018 07:35 AM, Paolo Bonzini wrote:
>> On 24/07/2018 10:17, Tianyu Lan wrote:
>>> mmu_set_spte() flushes remote tlbs for drop_parent_pte/drop_spte()
>>> and set_spte() separately. This may introduce redundant flush. This
>>> patch is to combine these flushes and check flush request after
>>> calling set_spte().
>>>
>>> Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
>>
>> Looks good, but I'd like a second opinion.  Guangrong, Junaid, can you
>> review this?
>>
>> Thanks,
>>
>> Paolo
>>
>>> ---
>>>   arch/x86/kvm/mmu.c | 7 ++++---
>>>   1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
>>> index 22a7984..8f21632 100644
>>> --- a/arch/x86/kvm/mmu.c
>>> +++ b/arch/x86/kvm/mmu.c
>>> @@ -2901,6 +2901,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
>>>   	int rmap_count;
>>>   	int set_spte_ret;
>>>   	int ret = RET_PF_RETRY;
>>> +	bool flush = false;
>>>   
>>>   	pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__,
>>>   		 *sptep, write_fault, gfn);
>>> @@ -2917,12 +2918,12 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
>>>   
>>>   			child = page_header(pte & PT64_BASE_ADDR_MASK);
>>>   			drop_parent_pte(child, sptep);
>>> -			kvm_flush_remote_tlbs(vcpu->kvm);
>>> +			flush = true;
>>>   		} else if (pfn != spte_to_pfn(*sptep)) {
>>>   			pgprintk("hfn old %llx new %llx\n",
>>>   				 spte_to_pfn(*sptep), pfn);
>>>   			drop_spte(vcpu->kvm, sptep);
>>> -			kvm_flush_remote_tlbs(vcpu->kvm);
>>> +			flush = true;
>>>   		} else
>>>   			was_rmapped = 1;
>>>   	}
>>> @@ -2934,7 +2935,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
>>>   			ret = RET_PF_EMULATE;
>>>   		kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
>>>   	}
>>> -	if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH)
>>> +	if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH || flush)
>>>   		kvm_flush_remote_tlbs(vcpu->kvm);
>>>   
>>>   	if (unlikely(is_mmio_spte(*sptep)))
>>>
>>
> 
> Reviewed-by: Junaid Shahid <junaids@google.com>
> 

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

* Re: [PATCH] KVM/MMU: Combine flushing remote tlb in mmu_set_spte()
  2018-07-24 14:35 ` Paolo Bonzini
  2018-07-25  2:26   ` Junaid Shahid
@ 2018-07-25  6:22   ` Xiao Guangrong
  1 sibling, 0 replies; 5+ messages in thread
From: Xiao Guangrong @ 2018-07-25  6:22 UTC (permalink / raw)
  To: Paolo Bonzini, Tianyu Lan
  Cc: rkrcmar, tglx, mingo, hpa, x86, kvm, linux-kernel,
	Xiao Guangrong, Junaid Shahid



On 07/24/2018 10:35 PM, Paolo Bonzini wrote:
> On 24/07/2018 10:17, Tianyu Lan wrote:
>> mmu_set_spte() flushes remote tlbs for drop_parent_pte/drop_spte()
>> and set_spte() separately. This may introduce redundant flush. This
>> patch is to combine these flushes and check flush request after
>> calling set_spte().
>>
>> Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
> 
> Looks good, but I'd like a second opinion.  Guangrong, Junaid, can you
> review this?
> 

It looks good to me.

Reviewed-by: Xiao Guangrong <xiaoguangrong@tencent.com>

BTW, the @intel box is not accessible to me now. ;)

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

end of thread, other threads:[~2018-07-25  6:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-24  8:17 [PATCH] KVM/MMU: Combine flushing remote tlb in mmu_set_spte() Tianyu Lan
2018-07-24 14:35 ` Paolo Bonzini
2018-07-25  2:26   ` Junaid Shahid
2018-07-25  2:35     ` Tianyu Lan
2018-07-25  6:22   ` Xiao Guangrong

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

all inboxes | Powered by JetHome®