From: Ackerley Tng <ackerleytng@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Shuah Khan <shuah@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
seanjc@google.com, rientjes@google.com,
rick.p.edgecombe@intel.com, yan.y.zhao@intel.com,
fvdl@google.com, jthoughton@google.com, vannapurve@google.com,
shivankg@amd.com, michael.roth@amd.com, pratyush@kernel.org,
pasha.tatashin@soleen.com, kalyazin@amazon.com,
tabba@google.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org,
Ackerley Tng <ackerleytng@google.com>
Subject: [PATCH RFC v2 5/6] KVM: selftests: Wrap fstat() to assert success
Date: Wed, 25 Feb 2026 07:20:40 +0000 [thread overview]
Message-ID: <20260225-gmem-st-blocks-v2-5-87d7098119a9@google.com> (raw)
In-Reply-To: <20260225-gmem-st-blocks-v2-0-87d7098119a9@google.com>
Extend kvm_syscalls.h to wrap fstat() to assert success. This will be used
in the next patch.
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
tools/testing/selftests/kvm/guest_memfd_test.c | 15 +++++----------
tools/testing/selftests/kvm/include/kvm_syscalls.h | 2 ++
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
index 618c937f3c90f..81387f06e770a 100644
--- a/tools/testing/selftests/kvm/guest_memfd_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_test.c
@@ -212,10 +212,8 @@ static void test_mmap_not_supported(int fd, size_t total_size)
static void test_file_size(int fd, size_t total_size)
{
struct stat sb;
- int ret;
- ret = fstat(fd, &sb);
- TEST_ASSERT(!ret, "fstat should succeed");
+ kvm_fstat(fd, &sb);
TEST_ASSERT_EQ(sb.st_size, total_size);
TEST_ASSERT_EQ(sb.st_blksize, page_size);
}
@@ -303,25 +301,22 @@ static void test_create_guest_memfd_invalid_sizes(struct kvm_vm *vm,
static void test_create_guest_memfd_multiple(struct kvm_vm *vm)
{
- int fd1, fd2, ret;
+ int fd1, fd2;
struct stat st1, st2;
fd1 = __vm_create_guest_memfd(vm, page_size, 0);
TEST_ASSERT(fd1 != -1, "memfd creation should succeed");
- ret = fstat(fd1, &st1);
- TEST_ASSERT(ret != -1, "memfd fstat should succeed");
+ kvm_fstat(fd1, &st1);
TEST_ASSERT(st1.st_size == page_size, "memfd st_size should match requested size");
fd2 = __vm_create_guest_memfd(vm, page_size * 2, 0);
TEST_ASSERT(fd2 != -1, "memfd creation should succeed");
- ret = fstat(fd2, &st2);
- TEST_ASSERT(ret != -1, "memfd fstat should succeed");
+ kvm_fstat(fd2, &st2);
TEST_ASSERT(st2.st_size == page_size * 2, "second memfd st_size should match requested size");
- ret = fstat(fd1, &st1);
- TEST_ASSERT(ret != -1, "memfd fstat should succeed");
+ kvm_fstat(fd1, &st1);
TEST_ASSERT(st1.st_size == page_size, "first memfd st_size should still match requested size");
TEST_ASSERT(st1.st_ino != st2.st_ino, "different memfd should have different inode numbers");
diff --git a/tools/testing/selftests/kvm/include/kvm_syscalls.h b/tools/testing/selftests/kvm/include/kvm_syscalls.h
index d4e613162bba9..3f039c34e12e0 100644
--- a/tools/testing/selftests/kvm/include/kvm_syscalls.h
+++ b/tools/testing/selftests/kvm/include/kvm_syscalls.h
@@ -2,6 +2,7 @@
#ifndef SELFTEST_KVM_SYSCALLS_H
#define SELFTEST_KVM_SYSCALLS_H
+#include <sys/stat.h>
#include <sys/syscall.h>
#define MAP_ARGS0(m,...)
@@ -77,5 +78,6 @@ __KVM_SYSCALL_DEFINE(munmap, 2, void *, mem, size_t, size);
__KVM_SYSCALL_DEFINE(close, 1, int, fd);
__KVM_SYSCALL_DEFINE(fallocate, 4, int, fd, int, mode, loff_t, offset, loff_t, len);
__KVM_SYSCALL_DEFINE(ftruncate, 2, unsigned int, fd, off_t, length);
+__KVM_SYSCALL_DEFINE(fstat, 2, int, fd, struct stat *, buf);
#endif /* SELFTEST_KVM_SYSCALLS_H */
--
2.53.0.414.gf7e9f6c205-goog
next prev parent reply other threads:[~2026-02-25 7:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 7:20 [PATCH RFC v2 0/6] guest_memfd: Track amount of memory allocated on inode Ackerley Tng
2026-02-25 7:20 ` [PATCH RFC v2 1/6] KVM: guest_memfd: Don't set FGP_ACCESSED when getting folios Ackerley Tng
2026-02-25 7:20 ` [PATCH RFC v2 2/6] KVM: guest_memfd: Directly allocate folios with filemap_alloc_folio() Ackerley Tng
2026-02-25 7:20 ` [PATCH RFC v2 3/6] fs: Add .unaccount_folio callback Ackerley Tng
2026-02-25 7:20 ` [PATCH RFC v2 4/6] KVM: guest_memfd: Track amount of memory allocated on inode Ackerley Tng
2026-02-25 7:20 ` Ackerley Tng [this message]
2026-02-25 7:20 ` [PATCH RFC v2 6/6] KVM: selftests: Test that st_blocks is updated on allocation Ackerley Tng
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=20260225-gmem-st-blocks-v2-5-87d7098119a9@google.com \
--to=ackerleytng@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=fvdl@google.com \
--cc=jack@suse.cz \
--cc=jthoughton@google.com \
--cc=kalyazin@amazon.com \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=michael.roth@amd.com \
--cc=pasha.tatashin@soleen.com \
--cc=pbonzini@redhat.com \
--cc=pratyush@kernel.org \
--cc=rick.p.edgecombe@intel.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=seanjc@google.com \
--cc=shivankg@amd.com \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=tabba@google.com \
--cc=vannapurve@google.com \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
--cc=yan.y.zhao@intel.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