lkml.org 
[lkml]   [2021]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH MANUALSEL 5.14 1/5] KVM: X86: fix lazy allocation of rmaps
From
On 25/10/21 22:38, Sasha Levin wrote:
> From: Paolo Bonzini <pbonzini@redhat.com>
>
> [ Upstream commit fa13843d1565d4c5b3aeb9be3343b313416bef46 ]
>
> If allocation of rmaps fails, but some of the pointers have already been written,
> those pointers can be cleaned up when the memslot is freed, or even reused later
> for another attempt at allocating the rmaps. Therefore there is no need to
> WARN, as done for example in memslot_rmap_alloc, but the allocation *must* be
> skipped lest KVM will overwrite the previous pointer and will indeed leak memory.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> arch/x86/kvm/x86.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 4b0e866e9f08..60d9aa0ab389 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -11341,7 +11341,8 @@ static int memslot_rmap_alloc(struct kvm_memory_slot *slot,
> int lpages = gfn_to_index(slot->base_gfn + npages - 1,
> slot->base_gfn, level) + 1;
>
> - WARN_ON(slot->arch.rmap[i]);
> + if (slot->arch.rmap[i])
> + continue;
>
> slot->arch.rmap[i] = kvcalloc(lpages, sz, GFP_KERNEL_ACCOUNT);
> if (!slot->arch.rmap[i]) {
>

NACK

There is no lazy allocation of rmaps in 5.14, and any failure to
allocate goes straight to memslot_rmap_free followed by return -ENOMEM.
So the WARN_ON is justified there.

Paolo

\
 
 \ /
  Last update: 2021-10-26 18:14    [W:0.066 / U:0.636 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site