From: Sean Christopherson <seanjc@google.com>
To: Nikita Kalyazin <kalyazin@amazon.co.uk>
Cc: "pbonzini@redhat.com" <pbonzini@redhat.com>,
"shuah@kernel.org" <shuah@kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"david@kernel.org" <david@kernel.org>,
"jthoughton@google.com" <jthoughton@google.com>,
"ackerleytng@google.com" <ackerleytng@google.com>,
"vannapurve@google.com" <vannapurve@google.com>,
"jackmanb@google.com" <jackmanb@google.com>,
"patrick.roy@linux.dev" <patrick.roy@linux.dev>,
Jack Thomson <jackabt@amazon.co.uk>,
Takahiro Itazuri <itazur@amazon.co.uk>,
Derek Manwaring <derekmn@amazon.com>,
Marco Cali <xmarcalx@amazon.co.uk>
Subject: Re: [PATCH v7 2/2] KVM: selftests: update guest_memfd write tests
Date: Wed, 11 Mar 2026 17:55:18 -0700 [thread overview]
Message-ID: <abIO9teJUlGMj16T@google.com> (raw)
In-Reply-To: <20251114151828.98165-3-kalyazin@amazon.com>
On Fri, Nov 14, 2025, Nikita Kalyazin wrote:
> +static void test_write_supported(int fd, size_t total_size)
> +{
> + size_t page_size = getpagesize();
> + void *buf = NULL;
> + int ret;
> +
> + ret = posix_memalign(&buf, page_size, total_size);
> + TEST_ASSERT_EQ(ret, 0);
> +
> + ret = pwrite(fd, buf, page_size, total_size);
> + TEST_ASSERT(ret == -1, "writing past the file size on a guest_mem fd should fail");
> + TEST_ASSERT_EQ(errno, EINVAL);
> +
> + ret = pwrite(fd, buf, 1, 0);
> + TEST_ASSERT(ret == -1, "writing an unaligned count a guest_mem fd should fail");
> + TEST_ASSERT_EQ(errno, EINVAL);
> +
> + ret = pwrite(fd, buf, page_size, 1);
> + TEST_ASSERT(ret == -1, "writing to an unaligned offset a guest_mem fd should fail");
> + TEST_ASSERT_EQ(errno, EINVAL);
> +
> + ret = pwrite(fd, buf, page_size, 0);
> + TEST_ASSERT(ret == page_size, "write on a guest_mem fd should succeed");
This write should actually verify a given pattern is written, not just that the
write() returned success. There should also be testcases for writes that fail,
e.g. on the first page and also on the nth page.
In a perfect world, there would also be testcases for partial writes, but I'm not
entirely sure how to make that happen, e.g. I'm not sure if an munmap() can pull
the rug out from under __copy_from_iter(). If we go with the -EFAULT behavior,
the test can map two pages, then use a separate helper thread to munmap() the pages
after a delay. Then in the pwrite() thread, verify all bytes are written on success?
I'm not sure that's interesting enought to warrant the development cost and effort
though, e.g. it doesn't seem wildly different than the deterministic "entire page
failed" case.
next prev parent reply other threads:[~2026-03-12 0:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 15:18 [PATCH v7 0/2] KVM: guest_memfd: use write for population Kalyazin, Nikita
2025-11-14 15:18 ` [PATCH v7 1/2] KVM: guest_memfd: add generic population via write Kalyazin, Nikita
2026-03-12 0:46 ` Sean Christopherson
2025-11-14 15:18 ` [PATCH v7 2/2] KVM: selftests: update guest_memfd write tests Kalyazin, Nikita
2026-03-12 0:55 ` Sean Christopherson [this message]
2025-11-14 15:23 ` [PATCH v7 0/2] KVM: guest_memfd: use write for population Nikita Kalyazin
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=abIO9teJUlGMj16T@google.com \
--to=seanjc@google.com \
--cc=ackerleytng@google.com \
--cc=david@kernel.org \
--cc=derekmn@amazon.com \
--cc=itazur@amazon.co.uk \
--cc=jackabt@amazon.co.uk \
--cc=jackmanb@google.com \
--cc=jthoughton@google.com \
--cc=kalyazin@amazon.co.uk \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=patrick.roy@linux.dev \
--cc=pbonzini@redhat.com \
--cc=shuah@kernel.org \
--cc=vannapurve@google.com \
--cc=xmarcalx@amazon.co.uk \
/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