public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset
@ 2024-06-13 12:28 Bibo Mao
  2024-06-13 16:43 ` Sean Christopherson
  2024-06-20 21:20 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Bibo Mao @ 2024-06-13 12:28 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, linux-kernel

Function kvm_reset_dirty_gfn may be called with parameters cur_slot /
cur_offset / mask are all zero, it does not represent real dirty page.
It is not necessary to clear dirty page in this condition. Also return
value of macro __fls() is undefined if mask is zero which is called in
funciton kvm_reset_dirty_gfn(). Here just discard it.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 virt/kvm/dirty_ring.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
index 86d267db87bb..05f4c1c40cc7 100644
--- a/virt/kvm/dirty_ring.c
+++ b/virt/kvm/dirty_ring.c
@@ -147,14 +147,16 @@ int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring)
 				continue;
 			}
 		}
-		kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
+		if (mask)
+			kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
 		cur_slot = next_slot;
 		cur_offset = next_offset;
 		mask = 1;
 		first_round = false;
 	}
 
-	kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
+	if (mask)
+		kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
 
 	/*
 	 * The request KVM_REQ_DIRTY_RING_SOFT_FULL will be cleared

base-commit: 83a7eefedc9b56fe7bfeff13b6c7356688ffa670
-- 
2.39.3


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

* Re: [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset
  2024-06-13 12:28 [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset Bibo Mao
@ 2024-06-13 16:43 ` Sean Christopherson
  2024-06-14  2:58   ` maobibo
  2024-06-20 21:20 ` Paolo Bonzini
  1 sibling, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2024-06-13 16:43 UTC (permalink / raw)
  To: Bibo Mao; +Cc: Paolo Bonzini, kvm, linux-kernel

On Thu, Jun 13, 2024, Bibo Mao wrote:
> Function kvm_reset_dirty_gfn may be called with parameters cur_slot /
> cur_offset / mask are all zero, it does not represent real dirty page.
> It is not necessary to clear dirty page in this condition. Also return
> value of macro __fls() is undefined if mask is zero which is called in
> funciton kvm_reset_dirty_gfn(). Here just discard it.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>  virt/kvm/dirty_ring.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
> index 86d267db87bb..05f4c1c40cc7 100644
> --- a/virt/kvm/dirty_ring.c
> +++ b/virt/kvm/dirty_ring.c
> @@ -147,14 +147,16 @@ int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring)
>  				continue;
>  			}
>  		}
> -		kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
> +		if (mask)
> +			kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
>  		cur_slot = next_slot;
>  		cur_offset = next_offset;
>  		mask = 1;
>  		first_round = false;
>  	}
>  
> -	kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
> +	if (mask)
> +		kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);

Given that mask must be checked before __fls(), just do:

diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
index 86d267db87bb..7bc74969a819 100644
--- a/virt/kvm/dirty_ring.c
+++ b/virt/kvm/dirty_ring.c
@@ -55,6 +55,9 @@ static void kvm_reset_dirty_gfn(struct kvm *kvm, u32 slot, u64 offset, u64 mask)
        struct kvm_memory_slot *memslot;
        int as_id, id;
 
+       if (!mask)
+               return;
+
        as_id = slot >> 16;
        id = (u16)slot;

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

* Re: [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset
  2024-06-13 16:43 ` Sean Christopherson
@ 2024-06-14  2:58   ` maobibo
  0 siblings, 0 replies; 4+ messages in thread
From: maobibo @ 2024-06-14  2:58 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: Paolo Bonzini, kvm, linux-kernel



On 2024/6/14 上午12:43, Sean Christopherson wrote:
> On Thu, Jun 13, 2024, Bibo Mao wrote:
>> Function kvm_reset_dirty_gfn may be called with parameters cur_slot /
>> cur_offset / mask are all zero, it does not represent real dirty page.
>> It is not necessary to clear dirty page in this condition. Also return
>> value of macro __fls() is undefined if mask is zero which is called in
>> funciton kvm_reset_dirty_gfn(). Here just discard it.
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
>> ---
>>   virt/kvm/dirty_ring.c | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
>> index 86d267db87bb..05f4c1c40cc7 100644
>> --- a/virt/kvm/dirty_ring.c
>> +++ b/virt/kvm/dirty_ring.c
>> @@ -147,14 +147,16 @@ int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring)
>>   				continue;
>>   			}
>>   		}
>> -		kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
>> +		if (mask)
>> +			kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
>>   		cur_slot = next_slot;
>>   		cur_offset = next_offset;
>>   		mask = 1;
>>   		first_round = false;
>>   	}
>>   
>> -	kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
>> +	if (mask)
>> +		kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask);
> 
> Given that mask must be checked before __fls(), just do:
That is ok for me. To be frankly I am not familiar with kvm common code,
I submit this patch just when I look through the migration source code.

Regards
Bibo Mao
> 
> diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
> index 86d267db87bb..7bc74969a819 100644
> --- a/virt/kvm/dirty_ring.c
> +++ b/virt/kvm/dirty_ring.c
> @@ -55,6 +55,9 @@ static void kvm_reset_dirty_gfn(struct kvm *kvm, u32 slot, u64 offset, u64 mask)
>          struct kvm_memory_slot *memslot;
>          int as_id, id;
>   
> +       if (!mask)
> +               return;
> +
>          as_id = slot >> 16;
>          id = (u16)slot;
> 


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

* Re: [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset
  2024-06-13 12:28 [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset Bibo Mao
  2024-06-13 16:43 ` Sean Christopherson
@ 2024-06-20 21:20 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2024-06-20 21:20 UTC (permalink / raw)
  To: Bibo Mao; +Cc: kvm, linux-kernel

Queued the alternative patch that returns early from kvm_reset_dirty_gfn,
thanks.

Paolo



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

end of thread, other threads:[~2024-06-20 21:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13 12:28 [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset Bibo Mao
2024-06-13 16:43 ` Sean Christopherson
2024-06-14  2:58   ` maobibo
2024-06-20 21:20 ` Paolo Bonzini

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