Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Claudio Imbrenda" <imbrenda@linux.ibm.com>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
	kvm@vger.kernel.org, linux-s390@vger.kernel.org,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v3 04/10] KVM: s390: cmma: Fix dirty tracking when removing memslot
Date: Mon, 27 Jul 2026 16:03:35 +0000	[thread overview]
Message-ID: <20260727160336.022F81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727150254.236021-5-imbrenda@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Critical] Unconditional NULL pointer dereference of the `old` memslot during `KVM_MR_CREATE` when migration mode is active.
- [Low] Build failure due to `goto` jumping over a `guard()` declaration, violating C cleanup attribute semantics.

Pre-existing issues:
- [High] Memory exhaustion and guest memory corruption during `KVM_MR_MOVE` due to shared MMU cache.
--

--- Patch [4]: [PATCH v3 04/10] KVM: s390: cmma: Fix dirty tracking when removing memslot ---
commit bf34c670340b7779837adadb9e6857c53511481a
Author: Claudio Imbrenda <imbrenda@linux.ibm.com>

KVM: s390: cmma: Fix dirty tracking when removing memslot

This patch updates CMMA dirty tracking to decrement the counter when a
memslot is removed. It walks the memslot's GFN range during 
kvm_arch_commit_memory_region to clear the dirty count.

> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index e154a8ad6c735..0a44351722702 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
[ ... ]
> @@ -5817,7 +5825,15 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
>  		goto out;
>  	}

[Severity: Low]
Will this compile correctly? The goto statement here jumps over the guard()
declaration below, which typically causes a compiler error since C
restricts jumping past the initialization of __attribute__((cleanup))
variables.

>  
> +	guard(mutex)(&kvm->slots_arch_lock);
> +
>  	scoped_guard(write_lock, &kvm->mmu_lock) {
> +		if (kvm->arch.migration_mode && kvm->arch.use_cmma) {
> +			_dat_walk_gfn_range(old->base_gfn, old->base_gfn + old->npages,

[Severity: Critical]
Can this code trigger a NULL pointer dereference when a new memory slot is 
created? 

If change == KVM_MR_CREATE, the old memslot pointer is NULL, but this 
block unconditionally dereferences old->base_gfn and old->npages before 
the switch statement checks the change type.

> +					    kvm->arch.gmap->asce, &ops, DAT_WALK_IGN_HOLES,
> +					    &kvm->arch.cmma_dirty_pages);
> +		}
> +
>  		switch (change) {
>  		case KVM_MR_DELETE:
>  			rc = dat_delete_slot(mc, kvm->arch.gmap->asce, old->base_gfn, old->npages);

[Severity: High]
This is a pre-existing issue, but could this lead to memory exhaustion and 
guest memory corruption during KVM_MR_MOVE? 

Looking at the KVM_MR_MOVE case below this in kvm_arch_commit_memory_region():

		case KVM_MR_MOVE:
			rc = dat_delete_slot(mc, kvm->arch.gmap->asce, old->base_gfn, old->npages);
			if (rc)
				break;
			fallthrough;
		case KVM_MR_CREATE:
			rc = dat_create_slot(mc, kvm->arch.gmap->asce, new->base_gfn, new->npages);

The code falls through from dat_delete_slot() to dat_create_slot() and 
shares the single kvm_s390_mmu_cache (mc). If the cache runs out of space 
for the second operation, it will fail midway, leaving the DAT tables out 
of sync with the memslots since this function cannot return an error to 
userspace.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260727150254.236021-1-imbrenda@linux.ibm.com?part=4

  reply	other threads:[~2026-07-27 16:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 15:02 [PATCH v3 00/10] KVM: s390: Misc fixes Claudio Imbrenda
2026-07-27 15:02 ` [PATCH v3 01/10] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
2026-07-27 15:24   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 02/10] KVM: s390: Fix leaking of PGM_ADDRESSING to userspace Claudio Imbrenda
2026-07-27 15:33   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 03/10] KVM: s390: Fix race in __do_essa() Claudio Imbrenda
2026-07-27 15:43   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 04/10] KVM: s390: cmma: Fix dirty tracking when removing memslot Claudio Imbrenda
2026-07-27 16:03   ` sashiko-bot [this message]
2026-07-27 15:02 ` [PATCH v3 05/10] KVM: s390: ucontrol: Add missing locking around gmap_remove_child() Claudio Imbrenda
2026-07-27 16:14   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 06/10] KVM: s390: Fix overclearing ESCA in case of error Claudio Imbrenda
2026-07-27 16:33   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 07/10] KVM: s390: Return -EINTR if a signal was pending while faulting-in Claudio Imbrenda
2026-07-27 16:59   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 08/10] KVM: s390: Free the mmu cache when kvm_arch_vcpu_create() fails Claudio Imbrenda
2026-07-27 17:06   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 09/10] KVM: s390: Fix ordering when adding to SCA Claudio Imbrenda
2026-07-27 17:12   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 10/10] KVM: s390: Fix cleanup in kvm_s390_pv_create_cpu() Claudio Imbrenda
2026-07-27 17:18   ` sashiko-bot

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=20260727160336.022F81F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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