diff mbox series

[v3] KVM: x86/mmu: fix counting of rmap entries in pte_list_add

Message ID 1601196297-24104-1-git-send-email-lirongqing@baidu.com (mailing list archive)
State New, archived
Headers show
Series [v3] KVM: x86/mmu: fix counting of rmap entries in pte_list_add | expand

Commit Message

Li RongQing Sept. 27, 2020, 8:44 a.m. UTC
Fix an off-by-one style bug in pte_list_add() where it failed to
account the last full set of SPTEs, i.e. when desc->sptes is full
and desc->more is NULL.

Merge the two "PTE_LIST_EXT-1" checks as part of the fix to avoid
an extra comparison.

Signed-off-by: Li RongQing <lirongqing@baidu.com>
Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
v2: Sean suggest to merge the two "PTE_LIST_EXT-1" checks
v3: Sean suggest to rewrite commit header

 arch/x86/kvm/mmu/mmu.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Li RongQing Oct. 23, 2020, 1:57 a.m. UTC | #1
> -----Original Message-----
> From: Li,Rongqing
> Sent: Sunday, September 27, 2020 4:45 PM
> To: Li,Rongqing <lirongqing@baidu.com>; kvm@vger.kernel.org;
> x86@kernel.org; sean.j.christopherson@intel.com
> Subject: [PATCH][v3] KVM: x86/mmu: fix counting of rmap entries in
> pte_list_add
> 
> Fix an off-by-one style bug in pte_list_add() where it failed to account the last
> full set of SPTEs, i.e. when desc->sptes is full and desc->more is NULL.
> 
> Merge the two "PTE_LIST_EXT-1" checks as part of the fix to avoid an extra
> comparison.
> 
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>


Ping 


Thanks

-Li
Paolo Bonzini Nov. 6, 2020, 11:56 a.m. UTC | #2
On 23/10/20 03:57, Li,Rongqing wrote:
> 
> 
>> -----Original Message-----
>> From: Li,Rongqing
>> Sent: Sunday, September 27, 2020 4:45 PM
>> To: Li,Rongqing <lirongqing@baidu.com>; kvm@vger.kernel.org;
>> x86@kernel.org; sean.j.christopherson@intel.com
>> Subject: [PATCH][v3] KVM: x86/mmu: fix counting of rmap entries in
>> pte_list_add
>>
>> Fix an off-by-one style bug in pte_list_add() where it failed to account the last
>> full set of SPTEs, i.e. when desc->sptes is full and desc->more is NULL.
>>
>> Merge the two "PTE_LIST_EXT-1" checks as part of the fix to avoid an extra
>> comparison.
>>
>> Signed-off-by: Li RongQing <lirongqing@baidu.com>
>> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> 
> Ping
> 
> 
> Thanks
> 
> -Li
> 

Queued, thanks.

Paolo
diff mbox series

Patch

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index a5d0207e7189..c4068be6bb3f 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -1273,12 +1273,14 @@  static int pte_list_add(struct kvm_vcpu *vcpu, u64 *spte,
 	} else {
 		rmap_printk("pte_list_add: %p %llx many->many\n", spte, *spte);
 		desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
-		while (desc->sptes[PTE_LIST_EXT-1] && desc->more) {
-			desc = desc->more;
+		while (desc->sptes[PTE_LIST_EXT-1]) {
 			count += PTE_LIST_EXT;
-		}
-		if (desc->sptes[PTE_LIST_EXT-1]) {
-			desc->more = mmu_alloc_pte_list_desc(vcpu);
+
+			if (!desc->more) {
+				desc->more = mmu_alloc_pte_list_desc(vcpu);
+				desc = desc->more;
+				break;
+			}
 			desc = desc->more;
 		}
 		for (i = 0; desc->sptes[i]; ++i)