2023-01-19 22:04:10

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH v2 17/18] NFS: Improve tracing of nfs_wb_folio()

From: Trond Myklebust <[email protected]>

Include info about which folio is being traced.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfstrace.h | 5 +++--
fs/nfs/write.c | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/nfstrace.h b/fs/nfs/nfstrace.h
index d3aa330fef36..a778713343df 100644
--- a/fs/nfs/nfstrace.h
+++ b/fs/nfs/nfstrace.h
@@ -152,8 +152,6 @@ DEFINE_NFS_INODE_EVENT(nfs_getattr_enter);
DEFINE_NFS_INODE_EVENT_DONE(nfs_getattr_exit);
DEFINE_NFS_INODE_EVENT(nfs_setattr_enter);
DEFINE_NFS_INODE_EVENT_DONE(nfs_setattr_exit);
-DEFINE_NFS_INODE_EVENT(nfs_writeback_page_enter);
-DEFINE_NFS_INODE_EVENT_DONE(nfs_writeback_page_exit);
DEFINE_NFS_INODE_EVENT(nfs_writeback_inode_enter);
DEFINE_NFS_INODE_EVENT_DONE(nfs_writeback_inode_exit);
DEFINE_NFS_INODE_EVENT(nfs_fsync_enter);
@@ -1032,6 +1030,9 @@ DECLARE_EVENT_CLASS(nfs_folio_event_done,
DEFINE_NFS_FOLIO_EVENT(nfs_aop_readpage);
DEFINE_NFS_FOLIO_EVENT_DONE(nfs_aop_readpage_done);

+DEFINE_NFS_FOLIO_EVENT(nfs_writeback_folio);
+DEFINE_NFS_FOLIO_EVENT_DONE(nfs_writeback_folio_done);
+
DEFINE_NFS_FOLIO_EVENT(nfs_invalidate_folio);
DEFINE_NFS_FOLIO_EVENT_DONE(nfs_launder_folio_done);

diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 77e6c033ca95..78cacaaded64 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -2093,7 +2093,7 @@ int nfs_wb_folio(struct inode *inode, struct folio *folio)
};
int ret;

- trace_nfs_writeback_page_enter(inode);
+ trace_nfs_writeback_folio(inode, folio);

for (;;) {
folio_wait_writeback(folio);
@@ -2111,7 +2111,7 @@ int nfs_wb_folio(struct inode *inode, struct folio *folio)
goto out_error;
}
out_error:
- trace_nfs_writeback_page_exit(inode, ret);
+ trace_nfs_writeback_folio_done(inode, folio, ret);
return ret;
}

--
2.39.0


2023-01-19 22:04:35

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH v2 18/18] NFS: Remove unnecessary check in nfs_read_folio()

From: Trond Myklebust <[email protected]>

All the callers are expected to supply a valid struct file argument, so
there is no need for the NULL check.

Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/read.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index bf4154f9b48c..c380cff4108e 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -355,13 +355,7 @@ int nfs_read_folio(struct file *file, struct folio *folio)
if (NFS_STALE(inode))
goto out_unlock;

- if (file == NULL) {
- ret = -EBADF;
- desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
- if (desc.ctx == NULL)
- goto out_unlock;
- } else
- desc.ctx = get_nfs_open_context(nfs_file_open_context(file));
+ desc.ctx = get_nfs_open_context(nfs_file_open_context(file));

xchg(&desc.ctx->error, 0);
nfs_pageio_init_read(&desc.pgio, inode, false,
--
2.39.0

2023-02-23 13:23:04

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH v2 18/18] NFS: Remove unnecessary check in nfs_read_folio()

On Thu, Jan 19, 2023 at 04:33:51PM -0500, [email protected] wrote:
> From: Trond Myklebust <[email protected]>
>
> All the callers are expected to supply a valid struct file argument, so
> there is no need for the NULL check.

Ummm. Not sure that's true. Look at this path:

mapping_read_folio_gfp(mapping, index, gfp)
do_read_cache_folio(mapping, index, NULL, NULL, gfp)
filemap_read_folio(NULL, mapping->a_ops->read_folio, folio)

It could well be that nobody does this to an NFS file! The places where
I see this called tend to be filesystems doing it to block devices,
or filesystems doing it to their own files (eg reading a journal file
or quota file)

But I'm suspicious of static match tools claiming it can't ever happen,
and I'd like more details please. I can't find the original report.
Also, it would have been nice to be cc'd on the folio conversion patches.

> Reported-by: kernel test robot <[email protected]>
> Reported-by: Dan Carpenter <[email protected]>
> Signed-off-by: Trond Myklebust <[email protected]>
> ---
> fs/nfs/read.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/fs/nfs/read.c b/fs/nfs/read.c
> index bf4154f9b48c..c380cff4108e 100644
> --- a/fs/nfs/read.c
> +++ b/fs/nfs/read.c
> @@ -355,13 +355,7 @@ int nfs_read_folio(struct file *file, struct folio *folio)
> if (NFS_STALE(inode))
> goto out_unlock;
>
> - if (file == NULL) {
> - ret = -EBADF;
> - desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
> - if (desc.ctx == NULL)
> - goto out_unlock;
> - } else
> - desc.ctx = get_nfs_open_context(nfs_file_open_context(file));
> + desc.ctx = get_nfs_open_context(nfs_file_open_context(file));
>
> xchg(&desc.ctx->error, 0);
> nfs_pageio_init_read(&desc.pgio, inode, false,
> --
> 2.39.0
>

2023-02-23 13:43:49

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v2 18/18] NFS: Remove unnecessary check in nfs_read_folio()

On Thu, Feb 23, 2023 at 01:22:54PM +0000, Matthew Wilcox wrote:
> But I'm suspicious of static match tools claiming it can't ever happen,
> and I'd like more details please. I can't find the original report.

I would never write a warning like that... However at the time when
I reported the bug then Smatch did say that all the callers passed a
non-NULL file pointer. I've reviewed my logs and that was true when I
said it but it's not true now. :( Now Smatch says there are three
callers and nfs_write_begin() passes a valid pointer, read_pages()
passes either a valid pointer or a NULL and filemap_read_folio() passes
an unknown pointer.

https://lore.kernel.org/all/Y77+n9MyHgx%2FalA4@kadam/

The issue here is that the pointer was already derefernced on the lines
before the check for NULL.

struct inode *inode = file_inode(file);

So either the dereference or the check was wrong.

regards,
dan carpenter