From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B403C606A32E for ; Wed, 11 Nov 2026 15:21:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=GvUo/oFV; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=B1KyA7Kg DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=LS22Ygw4td6cYP7DxbERi9ddUHoq6vQVTmOxe4Gax9E=; b=GvUo/oFV+dZR/U xB6MRcyLLCxEqsih/mahvqBBnq8qTpM+sAB0XZgP+1p9XaZScUKrFpA8SGDSqihg2xwnckU51nexP PzmtFEzVMKbgvoZONSsvRBoZ+CIfXR/xbafFW54PcLycXdU7clBwKJFfN/SP60myLBzhi8skhl38R 5J9PvQ4ttyOQ0K9fcduPAVliH/d7DsVcILPLt3EryoyTqaZQMvk5/nYP1is19Qffbkgvrznr0l3w7 5ALG6hDFAHmsKOy35VL2qRiWk4HvMnjm0KXu9AMJuG+1q4On9yG+aQwUW/ON67xsYvnwGt+t+lb2U xY9QpGTH6mmJZgixQGJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xRA8P-000000074YT-0UrW; Wed, 11 Nov 2026 15:21:13 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xRA8N-000000074Y8-1UYo for linux-arm-kernel@lists.infradead.org; Wed, 11 Nov 2026 15:21:12 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4A1831576; Wed, 11 Nov 2026 07:21:07 -0800 (PST) Received: from [10.2.197.99] (ewhatever.cambridge.arm.com [10.2.197.99]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5EAA83F632; Wed, 11 Nov 2026 07:21:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1794410470; bh=DmAs+HkipAZuaZn8YrcV1VGdsx0DsSHBMvKZ5WRURDE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=B1KyA7Kgss5vCsVOUwiYdwJToTKixvHpOMmrCnzlwf8ErGjQhgtBbGyav0GClivkZ lp//gb99/8oKdkwlD95FPXsCE80n++pFolGayiV6aRyTe92skXFv/ZLH0ilvIkCfQ4 M6OOgcFofaLnBKsdKA4qQ/dtT8uB26RdhGQ8SVMw= Message-ID: Date: Wed, 11 Nov 2026 15:21:05 +0000 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 02/12] KVM: arm64: guest_memfd: Check mmap support when preparing memslot To: Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" , Emi Kisanuki , Vishal Annapurve , WeiLin.Chang@arm.com, Lorenzo Pieralisi , Kohei Enju References: <20261111145758.217946-1-steven.price@arm.com> <20261111145758.217946-3-steven.price@arm.com> Content-Language: en-US From: Suzuki K Poulose In-Reply-To: <20261111145758.217946-3-steven.price@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261111_072111_554724_D7AF1220 X-CRM114-Status: GOOD ( 21.99 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 11/11/2026 14:57, Steven Price 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. > Please could you explain why we need this ? Why not rely on kvm_memslot_is_gmem_only(), which already tells kvm_gmem_supports_mmap() ? With inplace conversion support gmem supports mmap. > Signed-off-by: Steven Price > > --- > Changes since v1: > - New patch in v2. Check the guest_memfd backing file rather than the > memslot flag when deciding whether arm64 can map the backing memory. > --- > arch/arm64/kvm/mmu.c | 7 ++++--- > include/linux/kvm_host.h | 1 + > virt/kvm/guest_memfd.c | 6 ++++++ > 3 files changed, 11 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 1db10d8d6db7..a146f6cde3d0 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -2839,10 +2839,11 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, > return -EFAULT; > > /* > - * Only support guest_memfd backed memslots with mappable memory, since > - * there aren't any CoCo VMs that support only private memory on arm64. > + * Protected VMs currently require guest_memfd backed memslots with > + * mappable memory to support shared mappings. > */ > - if (kvm_slot_has_gmem(new) && !kvm_memslot_is_gmem_only(new)) > + if (kvm_arch_has_private_mem(kvm) && kvm_slot_has_gmem(new) && > + !kvm_gmem_slot_supports_mmap(new)) > return -EINVAL; > > /* guest_memfd is incompatible with MTE. */ > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index e7fc94e2910a..f65728a713ec 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -2614,6 +2614,7 @@ static inline bool kvm_is_private_gfn(struct kvm *kvm, gfn_t gfn) > > #ifdef CONFIG_KVM_GUEST_MEMFD > bool kvm_gmem_is_private_gfn(struct kvm *kvm, gfn_t gfn); > +bool kvm_gmem_slot_supports_mmap(const struct kvm_memory_slot *slot); > bool kvm_arch_supports_gmem_init_shared(struct kvm *kvm); > > static inline u64 kvm_gmem_get_supported_flags(struct kvm *kvm) > diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c > index 8c97a69b16dc..3dd8d227bebb 100644 > --- a/virt/kvm/guest_memfd.c > +++ b/virt/kvm/guest_memfd.c > @@ -442,6 +442,12 @@ static bool kvm_gmem_supports_mmap(struct inode *inode) > return GMEM_I(inode)->flags & GUEST_MEMFD_FLAG_MMAP; > } > > +bool kvm_gmem_slot_supports_mmap(const struct kvm_memory_slot *slot) > +{ > + /* The guest_memfd file is pinned while preparing a new memslot. */ We should gate this on kvm_slot_has_gmem() and how do we ensure that the call comes after it is prepared ? > + return kvm_gmem_supports_mmap(file_inode(slot->gmem.file)); > +} > + > static vm_fault_t kvm_gmem_fault_user_mapping(struct vm_fault *vmf) > { > struct inode *inode = file_inode(vmf->vma->vm_file); Cheers Suzuki