fuse: Fix missing FOLL_PIN for direct-io
authorLei Huang <lei.huang@linux.intel.com>
Tue, 29 Aug 2023 18:36:33 +0000 (14:36 -0400)
committerMiklos Szeredi <mszeredi@redhat.com>
Wed, 6 Mar 2024 10:07:35 +0000 (11:07 +0100)
commit738adade96b2ec414a44f3b1ed891fec3e0c03dd
tree82f5f0f9fc001515d8a532e8e948c154f5c1dd68
parent8a5fb186431326886ccc7b71d40aaf5e53b5d91a
fuse: Fix missing FOLL_PIN for direct-io

Our user space filesystem relies on fuse to provide POSIX interface.
In our test, a known string is written into a file and the content
is read back later to verify correct data returned. We observed wrong
data returned in read buffer in rare cases although correct data are
stored in our filesystem.

Fuse kernel module calls iov_iter_get_pages2() to get the physical
pages of the user-space read buffer passed in read(). The pages are
not pinned to avoid page migration. When page migration occurs, the
consequence are two-folds.

1) Applications do not receive correct data in read buffer.
2) fuse kernel writes data into a wrong place.

Using iov_iter_extract_pages() to pin pages fixes the issue in our
test.

An auxiliary variable "struct page **pt_pages" is used in the patch
to prepare the 2nd parameter for iov_iter_extract_pages() since
iov_iter_get_pages2() uses a different type for the 2nd parameter.

[SzM] add iov_iter_extract_will_pin(ii) and unpin only if true.

Signed-off-by: Lei Huang <lei.huang@linux.intel.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/file.c
fs/fuse/fuse_i.h