Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Price <steven.price@arm.com>
To: Suzuki K Poulose <suzuki.poulose@arm.com>, Fuad Tabba <tabba@google.com>
Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev,
	Catalin Marinas <catalin.marinas@arm.com>,
	Marc Zyngier <maz@kernel.org>, Will Deacon <will@kernel.org>,
	James Morse <james.morse@arm.com>,
	Oliver Upton <oliver.upton@linux.dev>,
	Zenghui Yu <yuzenghui@huawei.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Joey Gouly <joey.gouly@arm.com>,
	Alexandru Elisei <alexandru.elisei@arm.com>,
	Christoffer Dall <christoffer.dall@arm.com>,
	linux-coco@lists.linux.dev,
	Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>,
	Gavin Shan <gshan@redhat.com>,
	Shanker Donthineni <sdonthineni@nvidia.com>,
	Alper Gun <alpergun@google.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@kernel.org>,
	Emi Kisanuki <fj0570is@fujitsu.com>,
	Vishal Annapurve <vannapurve@google.com>,
	WeiLin.Chang@arm.com, Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Kohei Enju <enju.kohei@fujitsu.com>
Subject: Re: [PATCH v3 01/11] KVM: arm64: guest_memfd: Check mmap support when preparing memslot
Date: Wed, 18 Nov 2026 15:18:35 +0000	[thread overview]
Message-ID: <cc27e6a8-6bfa-4c82-92a7-33175baf6803@arm.com> (raw)
In-Reply-To: <8a095a42-662a-416d-a5d7-79e10161201c@arm.com>

[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]

On 18/11/2026 12:04, Suzuki K Poulose wrote:
> On 18/11/2026 11:14, Steven Price wrote:
>> On 18/11/2026 10:34, Suzuki K Poulose wrote:
>>> Hi Steven
>>>
>>> On 17/11/2026 14:05, Fuad Tabba wrote:
>>>> Hi Steven,
>>>>
>>>> On Mon, 16 Nov 2026 16:43:47 +0000, Steven Price
>>>> <steven.price@arm.com> wrote:
>>>>> Check the guest_memfd backing file when deciding whether an arm64
>>>>> memslot has mappable memory rather than checking whether the slot is
>>>>> gmem only. A public helper function is added to be able to reuse the
>>>>> static kvm_gmem_supports_mmap() function.
>>>>
>>>> nit: could the message say why this is needed? It's a no-op until
>>>> patch 8 defines kvm_arch_has_private_mem(), which makes every
>>>> guest_memfd slot gmem-only.
>>>
>>> I still don't understand why this is needed. For arm64 we have always
>>> prevented guest_memfd without MMAP, in kvm_arch_prepare_memory_region().
>>
>> Fuad is correct, this isn't really needed until patch 8. Patch 8 defines
>> kvm_arch_has_private_mem() - that means that gmem_in_place_conversion
>> becomes true (see include/linux/kvm_host.h). That in turn means that
> 
>> every guest_memfd slot is KVM_MEMSLOT_GMEM_ONLY including slots backed
>> by a file without mmap support.
> 
> But we dont support slots without MMAP anyways even without this series.
>  So, does it really matter for arm64 ?

So ChatGPT produced the attached test. It creates a non-mappable gmem
and tries to add it to a normal (non-realm/non-pkvm) VM. With v7.4-rc1
it is rejected. However without this patch it succeeds.

The issue is that gmem_in_place_conversion changes the behaviour for
normal VMs.

Thanks,
Steve


[-- Attachment #2: guest_memfd_nommap_repro.c --]
[-- Type: text/x-csrc, Size: 1575 bytes --]

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Reproduce the non-Realm guest_memfd memslot regression.
 * Build from the kernel root with:
 * cc -Wall -Wextra -O2 -Itools/include -Itools/include/uapi \
 *    tools/testing/selftests/kvm/arm64/guest_memfd_nommap_repro.c -o /tmp/gmem-repro
 */
#include <errno.h>
#include <fcntl.h>
#include <linux/kvm.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>

int main(void)
{
	long size = sysconf(_SC_PAGESIZE);
	struct kvm_create_guest_memfd gmem = { .size = size };
	struct kvm_userspace_memory_region2 region = {
		.flags = KVM_MEM_GUEST_MEMFD,
		.memory_size = size,
	};
	int kvm, vm, fd, ret, error;
	void *hva;

	if (size <= 0)
		return 1;
	kvm = open("/dev/kvm", O_RDWR | O_CLOEXEC);
	if (kvm < 0) {
		perror("open /dev/kvm");
		return 1;
	}
	vm = ioctl(kvm, KVM_CREATE_VM, 0);
	if (vm < 0) {
		perror("KVM_CREATE_VM");
		return 1;
	}
	fd = ioctl(vm, KVM_CREATE_GUEST_MEMFD, &gmem);
	if (fd < 0) {
		perror("KVM_CREATE_GUEST_MEMFD");
		return 1;
	}
	hva = mmap(NULL, size, PROT_READ | PROT_WRITE,
		   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	if (hva == MAP_FAILED) {
		perror("mmap");
		return 1;
	}
	region.userspace_addr = (uintptr_t)hva;
	region.guest_memfd = fd;
	ret = ioctl(vm, KVM_SET_USER_MEMORY_REGION2, &region);
	error = errno;
	if (ret == -1 && error == EINVAL) {
		puts("PASS: non-mappable guest_memfd memslot rejected");
		return 0;
	}
	fprintf(stderr, "FAIL: KVM_SET_USER_MEMORY_REGION2 returned %d (errno %d)\n",
		ret, ret < 0 ? error : 0);
	return 1;
}

  reply	other threads:[~2026-11-18 15:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:43 [PATCH v3 00/11] KVM: arm64: CCA: Prepare Realm memory management Steven Price
2026-11-16 16:43 ` [PATCH v3 01/11] KVM: arm64: guest_memfd: Check mmap support when preparing memslot Steven Price
2026-11-17 14:05   ` Fuad Tabba
2026-11-18 10:34     ` Suzuki K Poulose
2026-11-18 11:14       ` Steven Price
2026-11-18 12:04         ` Suzuki K Poulose
2026-11-18 15:18           ` Steven Price [this message]
2026-11-16 16:43 ` [PATCH v3 02/11] KVM: arm64: CCA: Introduce Realms Steven Price
2026-11-17 14:07   ` Fuad Tabba
2026-11-18 16:12     ` Steven Price
2026-11-16 16:43 ` [PATCH v3 03/11] KVM: arm64: Handle attributes in stage2_unmap_range Steven Price
2026-11-17 14:16   ` Fuad Tabba
2026-11-18 16:12     ` Steven Price
2026-11-16 16:43 ` [PATCH v3 04/11] KVM: arm64: CCA: Add basic infrastructure for creating a realm Steven Price
2026-11-16 16:43 ` [PATCH v3 05/11] KVM: arm64: CCA: Tear down RTTs Steven Price
2026-11-16 16:43 ` [PATCH v3 06/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers Steven Price
2026-11-16 16:43 ` [PATCH v3 07/11] KVM: Allow architectures to reject memslot changes before invalidation Steven Price
2026-11-17 14:31   ` Fuad Tabba
2026-11-18 16:44     ` Steven Price
2026-11-16 16:43 ` [PATCH v3 08/11] KVM: arm64: CCA: Prevent memslot modifications after Realm creation Steven Price
2026-11-17 14:42   ` Fuad Tabba
2026-11-18 16:49     ` Steven Price
2026-11-16 16:43 ` [PATCH v3 09/11] KVM: arm64: CCA: Support runtime faulting of memory Steven Price
2026-11-16 16:43 ` [PATCH v3 10/11] KVM: arm64: Dispatch stage-2 destruction by VM flavor Steven Price
2026-11-17 15:02   ` Fuad Tabba
2026-11-18 17:04     ` Steven Price
2026-11-16 16:43 ` [PATCH v3 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations Steven Price

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=cc27e6a8-6bfa-4c82-92a7-33175baf6803@arm.com \
    --to=steven.price@arm.com \
    --cc=WeiLin.Chang@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=alpergun@google.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=christoffer.dall@arm.com \
    --cc=enju.kohei@fujitsu.com \
    --cc=fj0570is@fujitsu.com \
    --cc=gankulkarni@os.amperecomputing.com \
    --cc=gshan@redhat.com \
    --cc=james.morse@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=sdonthineni@nvidia.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --cc=vannapurve@google.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.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