lkml.org 
[lkml]   [2021]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v5.5 20/30] KVM: x86: Use nr_memslot_pages to avoid traversing the memslots array
Date
On 04.11.2021 01:25, Sean Christopherson wrote:
> From: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
>
> There is no point in recalculating from scratch the total number of pages
> in all memslots each time a memslot is created or deleted. Use KVM's
> cached nr_memslot_pages to compute the default max number of MMU pages.
>
> Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
> [sean: use common KVM field and rework changelog accordingly]
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/include/asm/kvm_host.h | 1 -
> arch/x86/kvm/mmu/mmu.c | 24 ------------------------
> arch/x86/kvm/x86.c | 11 ++++++++---
> 3 files changed, 8 insertions(+), 28 deletions(-)
>
(..)
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -11837,9 +11837,14 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
> enum kvm_mr_change change)
> {
> if (!kvm->arch.n_requested_mmu_pages &&
> - (change == KVM_MR_CREATE || change == KVM_MR_DELETE))
> - kvm_mmu_change_mmu_pages(kvm,
> - kvm_mmu_calculate_default_mmu_pages(kvm));
> + (change == KVM_MR_CREATE || change == KVM_MR_DELETE)) {
> + unsigned long nr_mmu_pages;
> +
> + nr_mmu_pages = kvm->nr_memslot_pages * KVM_PERMILLE_MMU_PAGES;

Unfortunately, even if kvm->nr_memslot_pages is capped at ULONG_MAX then
this value multiplied by 20 can still overflow an unsigned long variable.

Thanks,
Maciej

\
 
 \ /
  Last update: 2021-11-09 01:43    [W:0.540 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site