]> git.proxmox.com Git - mirror_zfs.git/commit - module/os/linux/zfs/zfs_vnops_os.c
Fix buffered/direct/mmap I/O race
authorBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 23 Feb 2023 18:57:24 +0000 (10:57 -0800)
committerGitHub <noreply@github.com>
Thu, 23 Feb 2023 18:57:24 +0000 (10:57 -0800)
commit89cd2197b94986d315b9b1be707b645baf59af4f
tree3d2198d1c946d5c3cedd88f54ff836267979c1c2
parent7cb67d627c0c258a5dedb5b0d1f979469e51c91a
Fix buffered/direct/mmap I/O race

When a page is faulted in for memory mapped I/O the page lock
may be dropped before it has been read and marked up to date.
If a buffered read encounters such a page in mappedread() it
must wait until the page has been updated. Failure to do so
will result in a panic on debug builds and incorrect data on
production builds.

The critical part of this change is in mappedread() where pages
which are not up to date are now handled. Additionally, it
includes the following simplifications.

- zfs_getpage() and zfs_fillpage() could be passed an array of
  pages. This could be more efficient if it was used but in
  practice only a single page was ever provided. These
  interfaces were simplified to acknowledge that.

- update_pages() was modified to correctly set the PG_error bit
  on a page when it cannot be read by dmu_read().

- Setting PG_error and PG_uptodate was moved to zfs_fillpage()
  from zpl_readpage_common(). This is consistent with the
  handling in update_pages() and mappedread().

- Minor additional refactoring to comments and variable
  declarations to improve readability.

- Add a test case to exercise concurrent buffered, direct,
  and mmap IO to the same file.

- Reduce the mmap_sync test case default run time.

Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13608
Closes #14498
include/os/linux/zfs/sys/zfs_vnops_os.h
module/os/linux/zfs/zfs_vnops_os.c
module/os/linux/zfs/zpl_file.c
tests/runfiles/common.run
tests/zfs-tests/cmd/mmap_sync.c
tests/zfs-tests/tests/Makefile.am
tests/zfs-tests/tests/functional/mmap/mmap_mixed.ksh [new file with mode: 0755]