All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Steffen Eiden" <seiden@linux.ibm.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 24/27] KVM: s390: arm64: Implement vm/vcpu create destroy.
Date: Sat, 30 May 2026 08:57:11 +0000	[thread overview]
Message-ID: <20260530085711.D26C01F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260529155050.2902245-25-seiden@linux.ibm.com>

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

New issues:
- [High] In `kvm_arch_init_vm`, `kvm->arch.mem_limit` is improperly set to the inclusive hardware limit (`kvm_max_guest_address()`) instead of the VM's requested IPA size (`kvm->arch.guest_phys_size`). This causes `gmap_prepare_memory_region` to incorrectly reject perfectly sized memslots (because it compares an exclusive memslot size against an inclusive limit) and allows userspace to map memslots far beyond the VM's requested address space. These out-of-bounds memslots are then silently ignored during the commit phase by `_dat_walk_gfn_range` (due to `DAT_WALK_IGN_HOLES`), creating a fatal desynchronization between KVM's memslots and the hardware DAT tables.
- [High] `gmap_commit_memory_region` performs a fallible memory allocation (`kvm_s390_new_mmu_cache()`) during the KVM memslot commit phase, which is architecturally required to be non-failable (it returns `void`). If this allocation fails, the function aborts and silently skips updating the gmap DAT tables.

Pre-existing issues:
- [High] `gmap_get_dirty_log()` uses a non-atomic `memset()` to clear the memory slot's `dirty_bitmap` after copying it to userspace via `kvm_get_dirty_log()`. This introduces a severe race condition against concurrent callers of `mark_page_dirty()` (e.g., from interrupt injection in `s390/kvm/s390/interrupt.c` or nested virtualization), which use atomic bit operations (`set_bit_le`).
--

commit 001e0a58ea811dbd19411f46d5babaaf3bbbbc47
Author: Steffen Eiden <seiden@linux.ibm.com>

KVM: s390: arm64: Implement vm/vcpu create destroy.

Implement init and destroy IOCTLS for vcpu and vm.
Implement arch vm IOCTL. Use s390 gmap.

> diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
> index 591e2e874891a..79ce6570fa031 100644
> --- a/arch/s390/kvm/arm64/arm.c
> +++ b/arch/s390/kvm/arm64/arm.c
> @@ -45,6 +48,61 @@ static u64 kvm_max_guest_address(void)
>  	return ALIGN_DOWN(max_addr + 1, 1 << 30) - 1;
>  }

[ ... ]

> +int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
> +{

[ ... ]

> +	ret = kvm_gmap_init(kvm);
> +	if (ret)
> +		goto out_err;
> +	kvm->arch.mem_limit = kvm_max_guest_address();

[Severity: High]
Does setting kvm->arch.mem_limit to the inclusive hardware limit
kvm_max_guest_address() instead of kvm->arch.guest_phys_size cause
memslot validation issues?

When gmap_prepare_memory_region() validates the memory slots:

arch/s390/kvm/gmap/mmu.c:gmap_prepare_memory_region() {
        ...
        if ((new->base_gfn + new->npages) * PAGE_SIZE > kvm->arch.mem_limit)
                return -EINVAL;
        ...
}

It compares an exclusive size against this inclusive limit. Could this
incorrectly reject perfectly sized memslots?

Additionally, since it uses the maximum host physical capacity instead of
the VM's requested IPA size, could it allow userspace to map memslots beyond
the VM's address space, resulting in a desynchronization between KVM and
the hardware DAT tables?

[ ... ]

> @@ -107,6 +201,52 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
>  	return 0;
>  }
>  
> +int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
> +			       struct kvm_dirty_log *log)
> +{
> +	return gmap_get_dirty_log(kvm, log);
> +}

[Severity: High]
This is a pre-existing issue, but is it safe to use gmap_get_dirty_log()
here given how it clears the dirty bitmap?

In the underlying implementation:

arch/s390/kvm/gmap/mmu.c:gmap_get_dirty_log() {
        ...
        if (is_dirty) {
                n = kvm_dirty_bitmap_bytes(memslot);
                memset(memslot->dirty_bitmap, 0, n);
        }
        ...
}

The memset() is non-atomic. Could this permanently clobber concurrently set
dirty bits from mark_page_dirty(), which uses atomic bit operations? Any
dirty bits set concurrently during or immediately before the memset could
be lost.

[ ... ]

> +void kvm_arch_commit_memory_region(struct kvm *kvm,
> +				   struct kvm_memory_slot *old,
> +				   const struct kvm_memory_slot *new,
> +				   enum kvm_mr_change change)
> +{
> +	gmap_commit_memory_region(kvm, old, new, change);
> +}

[Severity: High]
Is it safe to rely on a fallible allocation inside the void
kvm_arch_commit_memory_region() phase?

Calling gmap_commit_memory_region() here triggers a memory allocation:

arch/s390/kvm/gmap/mmu.c:gmap_commit_memory_region() {
        ...
        mc = kvm_s390_new_mmu_cache();
        if (!mc) {
                rc = -ENOMEM;
                goto out;
        }
        ...
}

Since the commit phase returns void and cannot fail to userspace, if this
allocation fails under memory pressure, it will silently skip updating
the gmap DAT tables. Could this cause KVM's generic memslots to become
permanently desynchronized from the hardware gmap state?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260529155050.2902245-1-seiden@linux.ibm.com?part=24

  reply	other threads:[~2026-05-30  8:57 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29 15:50 [PATCH v3 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
2026-05-29 15:50 ` [PATCH v3 01/27] VFIO: take reference to the KVM module Steffen Eiden
2026-05-29 16:49   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 02/27] KVM, vfio: remove symbol_get(kvm_get_kvm_safe) from vfio Steffen Eiden
2026-05-29 16:39   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 03/27] KVM, vfio: remove symbol_get(kvm_put_kvm) " Steffen Eiden
2026-05-29 17:22   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 04/27] uapi: KVM: Provide arm64 UAPI for other host architectures Steffen Eiden
2026-05-29 17:10   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 05/27] arm64: Extract sysreg definitions Steffen Eiden
2026-05-29 17:22   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 06/27] arm64: Provide arm64 API for non-native architectures Steffen Eiden
2026-05-29 17:41   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 07/27] KVM: arm64: Provide arm64 KVM " Steffen Eiden
2026-05-29 17:45   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 08/27] arm64: Extract pstate definitions from ptrace Steffen Eiden
2026-05-29 15:50 ` [PATCH v3 09/27] KVM: arm64: Share kvm_emulate definitions Steffen Eiden
2026-05-29 18:13   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 10/27] KVM: arm64: Make some arm64 KVM code shareable Steffen Eiden
2026-05-29 19:15   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 11/27] KVM: arm64: Access elements of vcpu_gp_regs individually Steffen Eiden
2026-05-29 15:50 ` [PATCH v3 12/27] KVM: arm64: Share reset general register code Steffen Eiden
2026-05-29 15:50 ` [PATCH v3 13/27] KVM: arm64: Extract & share ipa size shift calculation Steffen Eiden
2026-05-29 15:50 ` [PATCH v3 14/27] KVM: s390: Move s390 kvm code into a subdirectory Steffen Eiden
2026-05-30  6:46   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 15/27] KVM: S390: Refactor gmap Steffen Eiden
2026-05-30  6:56   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 16/27] KVM: Make device name configurable Steffen Eiden
2026-05-30  7:12   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 17/27] KVM: Remove KVM_MMIO as config option Steffen Eiden
2026-05-30  7:23   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 18/27] KVM: s390: Prepare kvm-s390 for a second kvm module Steffen Eiden
2026-05-29 15:50 ` [PATCH v3 19/27] s390: Introduce Start Arm Execution instruction Steffen Eiden
2026-05-29 15:50 ` [PATCH v3 20/27] KVM: s390: arm64: Introduce host definitions Steffen Eiden
2026-05-30  8:07   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 21/27] s390/hwcaps: Report SAE support as hwcap Steffen Eiden
2026-05-29 15:50 ` [PATCH v3 22/27] KVM: s390: Add basic arm64 kvm module Steffen Eiden
2026-05-30  8:23   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 23/27] KVM: s390: arm64: Implement required functions Steffen Eiden
2026-05-29 15:50 ` [PATCH v3 24/27] KVM: s390: arm64: Implement vm/vcpu create destroy Steffen Eiden
2026-05-30  8:57   ` sashiko-bot [this message]
2026-05-29 15:50 ` [PATCH v3 25/27] KVM: s390: arm64: Implement vCPU IOCTLs Steffen Eiden
2026-05-30  9:09   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 26/27] KVM: s390: arm64: Implement basic page fault handler Steffen Eiden
2026-05-30  9:22   ` sashiko-bot
2026-05-29 15:50 ` [PATCH v3 27/27] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild Steffen Eiden
2026-05-30  9:37   ` 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=20260530085711.D26C01F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seiden@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.