From: "Darrick J. Wong" <djwong@kernel.org>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: patches@lists.linux.dev, fstests@vger.kernel.org,
linux-xfs@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org,
ziy@nvidia.com, vbabka@suse.cz, seanjc@google.com,
willy@infradead.org, david@redhat.com, hughd@google.com,
linmiaohe@huawei.com, muchun.song@linux.dev, osalvador@suse.de,
p.raghav@samsung.com, da.gomez@samsung.com, hare@suse.de,
john.g.garry@oracle.com
Subject: Re: [PATCH 2/5] fstests: add mmap page boundary tests
Date: Tue, 11 Jun 2024 11:46:03 -0700 [thread overview]
Message-ID: <20240611184603.GA52987@frogsfrogsfrogs> (raw)
In-Reply-To: <ZmiTBZLQ8uOGS5i8@bombadil.infradead.org>
On Tue, Jun 11, 2024 at 11:10:13AM -0700, Luis Chamberlain wrote:
> On Tue, Jun 11, 2024 at 09:48:11AM -0700, Darrick J. Wong wrote:
> > On Mon, Jun 10, 2024 at 08:01:59PM -0700, Luis Chamberlain wrote:
> > > +# As per POSIX NOTES mmap(2) maps multiples of the system page size, but if the
> > > +# data mapped is not multiples of the page size the remaining bytes are zeroed
> > > +# out when mapped and modifications to that region are not written to the file.
> > > +# On Linux when you write data to such partial page after the end of the
> > > +# object, the data stays in the page cache even after the file is closed and
> > > +# unmapped and even though the data is never written to the file itself,
> > > +# subsequent mappings may see the modified content. If you go *beyond* this
> >
> > Does this happen (mwrite data beyond eof sticks around) with large
> > folios as well?
>
> That corner case of checking to see if it stays is not tested by this
> test, but we could / should extend this test later for that. But then
> the question becomes, what is right, given we are in grey area, if we
> don't have any defined standard for it, it seems odd to test for it.
>
> So the test currently only tests for correctness of what we expect for
> POSIX and what we all have agreed for Linux.
>
> Hurding everyone to follow suit for the other corner cases is something
> perhaps we should do. Do we have a "strict fail" ? So that perhaps we can
> later add a test case for it and so that onnce and if we get consensus
> on what we do we can enable say a "strict-Linux" mode where we are
> pedantic about a new world order?
I doubt there's an easy way to guarantee more than "initialized to zero,
contents may stay around in memory but will not be written to disk".
You could do asinine things like fault on every access and manually
inject zero bytes, but ... yuck.
That said -- let's say you have a 33k file, and a space mapping for
0-63k (e.g. it was preallocated). Can the pagecache grab (say) a 64k
folio for the EOF part of the pagecache? And can you mmap that whole
region? And see even more grey area mmapping? Or does mmap always cut
off the mapping at roundup(i_size_read(), PAGE_SIZE) ?
(I feel like I've asked this before, and forgotten the answer. :()
> > > + rm -rf "${SCRATCH_MNT:?}"/*
> >
> > rm -f $SCRATCH_MNT/file ?
>
> Sure.
>
> > > + # A couple of mmap() tests:
> > > + #
> > > + # We are allowed to mmap() up to the boundary of the page size of a
> > > + # data object, but there a few rules to follow we must check for:
> > > + #
> > > + # a) zero-fill test for the data: POSIX says we should zero fill any
> > > + # partial page after the end of the object. Verify zero-fill.
> > > + # b) do not write this bogus data to disk: on Linux, if we write data
> > > + # to a partially filled page, it will stay in the page cache even
> > > + # after the file is closed and unmapped even if it never reaches the
> > > + # file. Subsequent mappings *may* see the modified content, but it
> > > + # also can get other data. Since the data read after the actual
> >
> > What other data?
>
> Beats me, got that from the man page bible on mmap. I think its homework
> for us to find out who is spewing that out, which gives a bit more value
> to the idea of that strict-linux thing. How else will we find out?
Oh, ok. I couldn't tell if *you* had seen "other" data emerging from
the murk, or if that was merely what a spec says. Please cite the
particular bible you were reading. ;)
> > > + # object data can vary we just verify the filesize does not change.
> > > + if [[ $map_len -gt $new_filelen ]]; then
> > > + zero_filled_data_len=$((map_len - new_filelen))
> > > + _scratch_cycle_mount
> > > + expected_zero_data="00"
> > > + zero_filled_data=$($XFS_IO_PROG -r $test_file \
> > > + -c "mmap -r 0 $map_len" \
> > > + -c "mread -v $new_filelen $zero_filled_data_len" \
> > > + -c "munmap" | \
> > > + filter_xfs_io_data_unique)
> > > + if [[ "$zero_filled_data" != "$expected_zero_data" ]]; then
> > > + echo "Expected data: $expected_zero_data"
> > > + echo " Actual data: $zero_filled_data"
> > > + _fail "Zero-fill expectations with mmap() not respected"
> > > + fi
> > > +
> > > + _scratch_cycle_mount
> > > + $XFS_IO_PROG $test_file \
> > > + -c "mmap -w 0 $map_len" \
> > > + -c "mwrite $new_filelen $zero_filled_data_len" \
> > > + -c "munmap"
> > > + sync
> > > + csum_post="$(_md5_checksum $test_file)"
> > > + if [[ "$csum_orig" != "$csum_post" ]]; then
> > > + echo "Expected csum: $csum_orig"
> > > + echo " Actual csum: $csum_post"
> > > + _fail "mmap() write up to page boundary should not change actual file contents"
> >
> > Do you really want to stop the test immediately? Or keep going and see
> > what other errors fall out? (i.e. s/_fail/echo/ here)
>
> Good point. We could go on, I'll change on the next v2.
>
> Thanks!
NP.
--D
>
> Luis
>
next prev parent reply other threads:[~2024-06-11 18:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-11 3:01 [PATCH 0/5] fstests: add some new LBS inspired tests Luis Chamberlain
2024-06-11 3:01 ` [PATCH 1/5] common: move mread() to generic helper _mread() Luis Chamberlain
2024-06-11 14:28 ` Darrick J. Wong
2024-06-11 3:01 ` [PATCH 2/5] fstests: add mmap page boundary tests Luis Chamberlain
2024-06-11 16:48 ` Darrick J. Wong
2024-06-11 18:10 ` Luis Chamberlain
2024-06-11 18:46 ` Darrick J. Wong [this message]
2024-06-11 20:29 ` Luis Chamberlain
2024-06-12 8:06 ` Zorro Lang
2024-06-13 21:05 ` Luis Chamberlain
2024-06-11 3:02 ` [PATCH 3/5] fstests: add fsstress + compaction test Luis Chamberlain
2024-06-11 14:48 ` Darrick J. Wong
2024-06-12 8:00 ` Zorro Lang
2024-06-13 21:10 ` Luis Chamberlain
2024-06-11 3:02 ` [PATCH 4/5] _require_debugfs(): simplify and fix for debian Luis Chamberlain
2024-06-11 14:35 ` Darrick J. Wong
2024-06-12 7:51 ` Zorro Lang
2024-06-11 3:02 ` [PATCH 5/5] fstests: add stress truncation + writeback test Luis Chamberlain
2024-06-11 14:45 ` Darrick J. Wong
2024-06-11 18:15 ` Luis Chamberlain
2024-06-11 18:29 ` Darrick J. Wong
2024-06-11 18:59 ` Luis Chamberlain
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=20240611184603.GA52987@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=da.gomez@samsung.com \
--cc=david@redhat.com \
--cc=fstests@vger.kernel.org \
--cc=hare@suse.de \
--cc=hughd@google.com \
--cc=john.g.garry@oracle.com \
--cc=linmiaohe@huawei.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=p.raghav@samsung.com \
--cc=patches@lists.linux.dev \
--cc=seanjc@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=ziy@nvidia.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;
as well as URLs for NNTP newsgroup(s).