Re: [PATCH 5/4] 9p: pass the correct prototype to read_cache_page

From: William Kucharski
Date: Thu May 02 2019 - 02:09:04 EST


1) You need to pass "filp" rather than "filp->private_data" to read_cache_pages()
in v9fs_fid_readpage().

The patched code passes "filp->private_data" as the "data" parameter to
read_cache_pages(), which would generate a call to:

filler(data, page)

which would become a call to:

static int v9fs_vfs_readpage(struct file *filp, struct page *page)
{
return v9fs_fid_readpage(filp->private_data, page);
}

which would then effectively become:

v9fs_fid_readpage(filp->private_data->private_data, page)

Which isn't correct; because data is a void *, no error is thrown when
v9fs_vfs_readpages treats filp->private_data as if it is filp.


2) I'd also like to see an explicit comment in do_read_cache_page() along
the lines of:

/*
* If a custom page filler was passed in use it, otherwise use the
* standard readpage() routine defined for the address_space.
*
*/

3) Patch 5/4?

Otherwise it looks good.

Reviewed-by: William Kucharski <william.kucharski@xxxxxxxxxx>

> On May 1, 2019, at 11:34 AM, Christoph Hellwig <hch@xxxxxx> wrote:
>
> Fix the callback 9p passes to read_cache_page to actually have the
> proper type expected. Casting around function pointers can easily
> hide typing bugs, and defeats control flow protection.
>
> Signed-off-by: Christoph Hellwig <hch@xxxxxx>
> ---
> fs/9p/vfs_addr.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
> index 0bcbcc20f769..02e0fc51401e 100644
> --- a/fs/9p/vfs_addr.c
> +++ b/fs/9p/vfs_addr.c
> @@ -50,8 +50,9 @@
> * @page: structure to page
> *
> */
> -static int v9fs_fid_readpage(struct p9_fid *fid, struct page *page)
> +static int v9fs_fid_readpage(void *data, struct page *page)
> {
> + struct p9_fid *fid = data;
> struct inode *inode = page->mapping->host;
> struct bio_vec bvec = {.bv_page = page, .bv_len = PAGE_SIZE};
> struct iov_iter to;
> @@ -122,7 +123,8 @@ static int v9fs_vfs_readpages(struct file *filp, struct address_space *mapping,
> if (ret == 0)
> return ret;
>
> - ret = read_cache_pages(mapping, pages, (void *)v9fs_vfs_readpage, filp);
> + ret = read_cache_pages(mapping, pages, v9fs_fid_readpage,
> + filp->private_data);
> p9_debug(P9_DEBUG_VFS, " = %d\n", ret);
> return ret;
> }