Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zeng Chi" <zeng_chi911@163.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: Release reserved xarray entries if reserving memory attributes fails
Date: Thu, 27 Aug 2026 11:17:05 +0000	[thread overview]
Message-ID: <20260827111705.860791F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260827110558.457891-1-zeng_chi911@163.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The error cleanup loop in `kvm_vm_set_mem_attributes` lacks a `cond_resched()` call, which can cause CPU soft lockups when reverting a massive memory range.
--

commit 628b8d791b455e8fdc196cf53b9e1f82e2d7fdb6
Author: Zeng Chi <zengchi@kylinos.cn>

KVM: Release reserved xarray entries if reserving memory attributes fails

This commit fixes a memory leak in kvm_vm_set_mem_attributes() where previously
reserved xarray entries were left behind if a subsequent reservation failed. It
adds a backward loop to release the successfully reserved entries before bailing
out on the error path.

> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2575,8 +2575,11 @@ static int kvm_vm_set_mem_attributes(struct kvm *kvm, gfn_t start, gfn_t end,
>  	 */
>  	for (i = start; i < end; i++) {
>  		r = xa_reserve(&kvm->mem_attr_array, i, GFP_KERNEL_ACCOUNT);
> -		if (r)
> +		if (r) {
> +			while (i-- > start)
> +				xa_release(&kvm->mem_attr_array, i);

[Severity: High]
Can this backward cleanup loop cause CPU soft lockups if a massive memory
range was requested?

The forward loop correctly yields the CPU via cond_resched() to handle large
ranges, but the unwinding error path does not. 

If userspace invokes KVM_SET_MEMORY_ATTRIBUTES on a massive range and
xa_reserve() eventually fails, this loop will continuously process potentially
millions of entries. On kernels with CONFIG_PREEMPT_VOLUNTARY or
CONFIG_PREEMPT_NONE, could this block scheduling long enough to trigger the
soft lockup watchdog?

>  			goto out_unlock;
> +		}
>  
>  		cond_resched();
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260827110558.457891-1-zeng_chi911@163.com?part=1

  reply	other threads:[~2026-08-27 11:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 11:05 [PATCH] KVM: Release reserved xarray entries if reserving memory attributes fails Zeng Chi
2026-08-27 11:17 ` sashiko-bot [this message]
2026-08-27 18:37 ` Sean Christopherson
2026-08-28 10:27   ` [PATCH v2] KVM: Don't treat reserved xarray entries as having memory attributes Zeng Chi
2026-08-28 10:41     ` sashiko-bot
2026-08-28 17:15     ` Sean Christopherson
2026-08-28 18:17       ` Sean Christopherson
2026-08-28 10:51   ` [PATCH] KVM: Release reserved xarray entries if reserving memory attributes fails Zeng Chi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260827111705.860791F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zeng_chi911@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox