From: Pratyush Yadav <pratyush@kernel.org>
To: Mike Rapoport <rppt@kernel.org>
Cc: Pratyush Yadav <pratyush@kernel.org>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Shuah Khan <shuah@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH 2/6] selftests/liveupdate: add helper functions for memfd tests
Date: Tue, 17 Mar 2026 12:21:00 +0000 [thread overview]
Message-ID: <2vxzfr5yd4ur.fsf@kernel.org> (raw)
In-Reply-To: <abk0ke1wAiHMYnGs@kernel.org> (Mike Rapoport's message of "Tue, 17 Mar 2026 13:01:37 +0200")
On Tue, Mar 17 2026, Mike Rapoport wrote:
> On Mon, Mar 09, 2026 at 11:54:35AM +0000, Pratyush Yadav wrote:
>> From: "Pratyush Yadav (Google)" <pratyush@kernel.org>
>>
>> Add some helper functions that will be used by memfd tests. This moves
>> some of the complexity out of the test itself, which results in better
>> test readability and less code duplication.
>>
>> Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
>> Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
>> ---
>> .../selftests/liveupdate/luo_test_utils.c | 175 +++++++++++++++++-
>> .../selftests/liveupdate/luo_test_utils.h | 9 +
>> 2 files changed, 183 insertions(+), 1 deletion(-)
>
> Some review comments from an LLM that make sense to me as well :)
>
>> diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.c b/tools/testing/selftests/liveupdate/luo_test_utils.c
>> --- a/tools/testing/selftests/liveupdate/luo_test_utils.c
>> +++ b/tools/testing/selftests/liveupdate/luo_test_utils.c
>
> [ ... ]
>
>> +/* Read exactly specified size from fd. Any less results in error. */
>> +int read_size(int fd, char *buffer, size_t size)
>> +{
>> + size_t remain = size;
>> + ssize_t bytes_read;
>> +
>> + while (remain) {
>> + bytes_read = read(fd, buffer, remain);
>> + if (bytes_read == 0)
>> + return -ENODATA;
>> + if (bytes_read < 0)
>> + return -errno;
>> +
>> + remain -= bytes_read;
>> + }
>
> Should the buffer pointer be advanced after each read()? As written,
> if read() returns a partial result, the next iteration reads into the
> same position, overwriting the data just read. Something like
> buffer += bytes_read after remain -= bytes_read seems to be missing.
>
> This is exercised by generate_random_data() which reads from
> /dev/urandom, where partial reads are possible for large requests.
>
>> +/* Write exactly specified size from fd. Any less results in error. */
>> +int write_size(int fd, const char *buffer, size_t size)
>> +{
>> + size_t remain = size;
>> + ssize_t written;
>> +
>> + while (remain) {
>> + written = write(fd, buffer, remain);
>> + if (written == 0)
>> + return -EIO;
>> + if (written < 0)
>> + return -errno;
>> +
>> + remain -= written;
>> + }
>
> Same issue here: buffer is not advanced after each write(), so on a
> partial write the same initial bytes would be re-sent instead of
> continuing from where the previous write left off.
Yeah, good catch on both. Will fix.
--
Regards,
Pratyush Yadav
next prev parent reply other threads:[~2026-03-17 12:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 11:54 [PATCH 0/6] selftests/liveupdate: add memfd tests Pratyush Yadav
2026-03-09 11:54 ` [PATCH 1/6] selftests/liveupdate: add framework for " Pratyush Yadav
2026-03-10 11:08 ` Usama Arif
2026-03-13 10:05 ` Pratyush Yadav
2026-03-18 7:15 ` Mike Rapoport
2026-03-09 11:54 ` [PATCH 2/6] selftests/liveupdate: add helper functions " Pratyush Yadav
2026-03-17 11:01 ` Mike Rapoport
2026-03-17 12:21 ` Pratyush Yadav [this message]
2026-03-18 7:20 ` Mike Rapoport
2026-03-09 11:54 ` [PATCH 3/6] selftests/liveupdate: add test for memfd content preservation Pratyush Yadav
2026-03-18 7:31 ` Mike Rapoport
2026-03-09 11:54 ` [PATCH 4/6] selftests/liveupdate: add test for zero-size memfd preservation Pratyush Yadav
2026-03-18 7:35 ` Mike Rapoport
2026-03-09 11:54 ` [PATCH 5/6] selftests/liveupdate: add test for operations on a preserved memfd Pratyush Yadav
2026-03-18 7:38 ` Mike Rapoport
2026-03-09 11:54 ` [PATCH 6/6] selftests/liveupdate: add fallocate test for memfd Pratyush Yadav
2026-03-18 7:43 ` Mike Rapoport
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=2vxzfr5yd4ur.fsf@kernel.org \
--to=pratyush@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.