From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5681D3264D8; Sat, 26 Sep 2026 00:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790383852; cv=none; b=iaunzxCz9ULl49KJYHhoiKBGGV/ZJDMiQYSvvo9RE1Wvla6pMJayJTKqRSOfFPu2ZBdnN7qRSvEYctTGZITtD9V7CuuU7qp0Rgpse46yxyQ2Fql3/XzbyqrZehc3AUorUuqn2YdqHdQxnr4oRnrMQMooOsb/8ky0oqtvGd7UD2c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790383852; c=relaxed/simple; bh=21HvTorctO9Ssbh0Oo7al0KxPCcL6KSYRxge9z1lWjI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LIqx7TculLoUi6zF+1GjDYb9/0slLNXoGmK7tS7ueXMn1gHncTJTFGkzRSEa3h9LCCfJ1gVPPzmTehh3El6Vbut1iy4Ix6PKeUM8tZrQWrqIrLtCmR1Qr1AK3SKyusRREUDTSpXGgR3P7NnXbGwzLN4YgvvLtuqxIiFDlut5meQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nT+Xp4PP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nT+Xp4PP" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3280BC2BD00; Sat, 26 Sep 2026 00:50:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1790383852; bh=21HvTorctO9Ssbh0Oo7al0KxPCcL6KSYRxge9z1lWjI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=nT+Xp4PPn7TD0qgto83K2t8IPOLi+ZqTR9UuqPt5672aUH6W+UPrO+22zbdwsgXdk AZNeJJm3SNPuuMgG3HlyLMHDRFuNc4q3/RKd+1hLVPkltnxDOfW2XZXp174+ECz85S lSTn0jbhThJ2JwyG0TNMvsF5nqamUQwios197XH0S0Sv0z/FmWiVoi3N3Q75NJaR0d avaIKb0IbBX29V3pVlPyGO6SnIcPC6T5MbgTyAvsi0tTWje60YS0THvJ7jV902tobq mv4kVtLjawwEPTTWHohKFOirN/Z3luZqGKvq7p0n9UiZliBH83uTqMaDPRELbdO0DI c2GdCdWJtaBqw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E683C98332; Sat, 26 Sep 2026 00:50:52 +0000 (UTC) From: Ackerley Tng via B4 Relay Date: Fri, 25 Sep 2026 17:51:00 -0700 Subject: [PATCH RFC 13/17] KVM: selftests: Test guest_memfd resource pool sharing across instances Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260925-gmem-tmpfs-backend-v1-13-d36159822d18@google.com> References: <20260925-gmem-tmpfs-backend-v1-0-d36159822d18@google.com> In-Reply-To: <20260925-gmem-tmpfs-backend-v1-0-d36159822d18@google.com> To: Hugh Dickins , Baolin Wang , Andrew Morton , Sean Christopherson , Paolo Bonzini , David Hildenbrand , Jonathan Corbet , Shuah Khan , Randy Dunlap , Shuah Khan , vannapurve@google.com, erdemaktas@google.com, jxgao@google.com, rientjes@google.com, fvdl@google.com, jthoughton@google.com, tarunsahu@google.com, pratyush@kernel.org, fuad.tabba@linux.dev, Gregory Price , David Woodhouse , yan.y.zhao@intel.com, michael.roth@amd.com, suzuki.poulose@arm.com, Christian Brauner , Jason Gunthorpe , Nicolin Chen , Xu Yilun , aik@amd.com, aneesh.kumar@kernel.org, Vlastimil Babka Cc: kernel-team@android.com, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Ackerley Tng X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1790383850; l=2284; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=9LO/j7yMhJpTOm28buLLSDSKy7s9Zo30YgKsCsYGTTM=; b=mVJcR7vvGiZtoLCGnt/0t4woHxKz3scYXOvAZ0LmNrLTf100ewNFL1vp2GLk6dll/4KmKlQAu u/BbjIypF/ODnW1Uifc1XQ2DvUviguno+Rtw2F5Iryj6zwEtjtmcb9u X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Endpoint-Received: by B4 Relay for ackerleytng@google.com/20260225 with auth_id=649 X-Original-From: Ackerley Tng Reply-To: ackerleytng@google.com From: Ackerley Tng Test that multiple guest_memfd instances can be created backed by the same tmpfs resource pool descriptor, that each file descriptor reflects its requested size, and that they have distinct inodes. Signed-off-by: Ackerley Tng --- tools/testing/selftests/kvm/guest_memfd_test.c | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c index 94ef64474f2a0..81311be059923 100644 --- a/tools/testing/selftests/kvm/guest_memfd_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_test.c @@ -543,6 +543,41 @@ static void test_resource_fd_tmpfs_huge(struct kvm_vm *vm) close(pool_fd); } +static void test_resource_fd_tmpfs_shared_pool(struct kvm_vm *vm) +{ + int pool_fd, fd1, fd2; + struct stat st1, st2; + + pool_fd = create_tmpfs_pool_fd("never", true, page_size * 2); + if (pool_fd < 0) + TEST_REQUIRE(false); + + fd1 = vm_create_guest_memfd_resource(vm, page_size, + GUEST_MEMFD_FLAG_USE_RESOURCE, + pool_fd); + + fd2 = vm_create_guest_memfd_resource(vm, page_size * 2, + GUEST_MEMFD_FLAG_USE_RESOURCE, + pool_fd); + + TEST_ASSERT(!fstat(fd1, &st1), "fstat on fd1 should succeed"); + TEST_ASSERT(st1.st_size == page_size, + "fd1 st_size (%lu) should match requested size (%lu)", + st1.st_size, page_size); + + TEST_ASSERT(!fstat(fd2, &st2), "fstat on fd2 should succeed"); + TEST_ASSERT(st2.st_size == page_size * 2, + "fd2 st_size (%lu) should match requested size (%lu)", + st2.st_size, page_size * 2); + + TEST_ASSERT(st1.st_ino != st2.st_ino, + "different guest_memfd instances should have distinct inodes"); + + close(fd2); + close(fd1); + close(pool_fd); +} + enum gmem_pool_type { GMEM_POOL_NONE, GMEM_POOL_FSMOUNT, @@ -673,6 +708,7 @@ static void test_guest_memfd(unsigned long vm_type) test_resource_fd_tmpfs_file(vm); test_resource_fd_tmpfs_swap(vm); test_resource_fd_tmpfs_huge(vm); + test_resource_fd_tmpfs_shared_pool(vm); __test_guest_memfd(vm, 0, GMEM_POOL_NONE); __test_guest_memfd(vm, GUEST_MEMFD_FLAG_USE_RESOURCE, GMEM_POOL_FSMOUNT); -- 2.56.0.rc1.315.gc6ed9934b7-goog