Whamcloud - gitweb
LU-16412 llite: check read page past requested 23/49723/8
authorQian Yingjin <qian@ddn.com>
Fri, 20 Jan 2023 17:30:27 +0000 (12:30 -0500)
committerPatrick Farrell <pfarrell@whamcloud.com>
Fri, 27 Jan 2023 15:23:40 +0000 (15:23 +0000)
commitebfe62b8e8f4db0555a7a39ce5c764059422a260
tree9fc259379861c7795ae7d45a70ff20819a709c07
parent4d3f6c052d78a771797a37a3d08dc6bbf0b323f1
LU-16412 llite: check read page past requested

Due to a kernel bug introduced in 5.12 in commit:
cbd59c48ae2bcadc4a7599c29cf32fd3f9b78251
("mm/filemap: use head pages in generic_file_buffered_read")
if the page immediately after the current read is in cache,
the kernel will try to read it.

This attempts to read a page past the end of requested
read from userspace, and so has not been safely locked by
Lustre.

For a page after the end of the current read, check wether
it is under the protection of a DLM lock. If so, we take a
reference on the DLM lock until the page read has finished
and then release the reference.  If the page is not covered
by a DLM lock, then we are racing with the page being
removed from Lustre.  In that case, we return
AOP_TRUNCATED_PAGE, which makes the kernel release its
reference on the page and retry the page read.  This allows
the page to be removed from cache, so the kernel will not
find it and incorrectly attempt to read it again.

NB: Earlier versions of this description refer to stripe
boundaries, but the locking issue can occur whether or
not the page is on a stripe boundary, because dlmlocks
can cover part of a stripe.  (This is rare, but is
allowed.)

Change-Id: Ib93bd0624fda0ed1c2b89f609d15208c86e21c29
Signed-off-by: Qian Yingjin <qian@ddn.com>
Signed-off-by: Patrick Farrell <pfarrell@whamcloud.com>
lustre/llite/llite_internal.h
lustre/llite/rw.c
lustre/llite/vvp_io.c