* [PATCH v3 0/2] NFS: fix RCU and tracing pointer safety
@ 2026-04-19 16:31 Sean Chang
2026-04-19 16:31 ` [PATCH v3 1/2] NFS: remove redundant __private attribute from nfs_page_class Sean Chang
2026-04-19 16:31 ` [PATCH v3 2/2] NFS: Fix RCU dereference of cl_xprt in nfs_compare_super_address Sean Chang
0 siblings, 2 replies; 3+ messages in thread
From: Sean Chang @ 2026-04-19 16:31 UTC (permalink / raw)
To: Benjamin Coddington
Cc: Jeff Layton, trondmy, anna, linux-nfs, linux-kernel, Sean Chang
This series addresses two Sparse static analysis warnings in the NFS
client related to RCU safety and pointer attributes.
The first patch resolves a "dereferencing noderef expression" warning
within the nfs_page_class tracepoint by removing a redundant __private
attribute that was causing Sparse to complain during trace-buffer
assignments.
The second patch fixes an RCU-unsafe dereference in nfs_compare_super_address.
It wraps cl_xprt access with rcu_read_lock() and rcu_dereference().
Following reviewer feedback, the RCU critical section is kept minimal,
covering only the transport and network namespace checks.
v3:
- Patch 2: Removed the redundant XPRT_CONNECTED and pointer existence
checks as suggested by Benjamin Coddington. Since the comparison is
performed while holding sb_lock, the transport's existence is guaranteed,
and its connection state does not affect the server's identity.
v2:
- Patch 1: Instead of changing the 'req' field type to unsigned long (as in v1),
simply remove the redundant __private attribute. This resolves the
Sparse warning while preserving the original pointer type.
- Patch 2: Reduced RCU read-side critical section scope to cover only
the necessary transport/net-ns checks, as suggested by reviewers.
Sean Chang (2):
NFS: remove redundant __private attribute from nfs_page_class
NFS: Fix RCU dereference of cl_xprt in nfs_compare_super_address
fs/nfs/nfstrace.h | 2 +-
fs/nfs/super.c | 16 +++++++++++++---
2 files changed, 14 insertions(+), 4 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 1/2] NFS: remove redundant __private attribute from nfs_page_class
2026-04-19 16:31 [PATCH v3 0/2] NFS: fix RCU and tracing pointer safety Sean Chang
@ 2026-04-19 16:31 ` Sean Chang
2026-04-19 16:31 ` [PATCH v3 2/2] NFS: Fix RCU dereference of cl_xprt in nfs_compare_super_address Sean Chang
1 sibling, 0 replies; 3+ messages in thread
From: Sean Chang @ 2026-04-19 16:31 UTC (permalink / raw)
To: Benjamin Coddington
Cc: Jeff Layton, trondmy, anna, linux-nfs, linux-kernel, Sean Chang,
Benjamin Coddington
The nfs_page_class tracepoint uses a pointer for the 'req' field marked
with the __private attribute. This causes Sparse to complain about
dereferencing a private pointer within the trace ring buffer context,
specifically during the TP_fast_assign() operation.
This fixes a Sparse warning introduced in commit b6ef079fd984 ("nfs:
more in-depth tracing of writepage events") by removing the redundant
__private attribute from the 'req' field.
Reviewed-by: Benjamin Coddington <bcodding@hammerspace.com>
Signed-off-by: Sean Chang <seanwascoding@gmail.com>
---
fs/nfs/nfstrace.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/nfs/nfstrace.h b/fs/nfs/nfstrace.h
index 9f9ce4a565ea..ff467959f733 100644
--- a/fs/nfs/nfstrace.h
+++ b/fs/nfs/nfstrace.h
@@ -1496,7 +1496,7 @@ DECLARE_EVENT_CLASS(nfs_page_class,
__field(dev_t, dev)
__field(u32, fhandle)
__field(u64, fileid)
- __field(const struct nfs_page *__private, req)
+ __field(const struct nfs_page *, req)
__field(loff_t, offset)
__field(unsigned int, count)
__field(unsigned long, flags)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 2/2] NFS: Fix RCU dereference of cl_xprt in nfs_compare_super_address
2026-04-19 16:31 [PATCH v3 0/2] NFS: fix RCU and tracing pointer safety Sean Chang
2026-04-19 16:31 ` [PATCH v3 1/2] NFS: remove redundant __private attribute from nfs_page_class Sean Chang
@ 2026-04-19 16:31 ` Sean Chang
1 sibling, 0 replies; 3+ messages in thread
From: Sean Chang @ 2026-04-19 16:31 UTC (permalink / raw)
To: Benjamin Coddington
Cc: Jeff Layton, trondmy, anna, linux-nfs, linux-kernel, Sean Chang
The cl_xprt pointer in struct rpc_clnt is marked as __rcu. Accessing
it directly in nfs_compare_super_address() is unsafe and triggers
Sparse warnings.
Fix this by using rcu_dereference() within an RCU read-side critical
section to retrieve the transport pointer. This addresses the sparse
warning and ensures atomic access to the pointer, as the transport
can be updated via transport switching even while the superblock
remains active under sb_lock.
Fixes: 7e3fcf61abde ("nfs: don't share mounts between network namespaces")
Signed-off-by: Sean Chang <seanwascoding@gmail.com>
---
fs/nfs/super.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 7a318581f85b..4cd420b14ce3 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -1166,12 +1166,18 @@ static int nfs_set_super(struct super_block *s, struct fs_context *fc)
static int nfs_compare_super_address(struct nfs_server *server1,
struct nfs_server *server2)
{
+ struct rpc_xprt *xprt1, *xprt2;
struct sockaddr *sap1, *sap2;
- struct rpc_xprt *xprt1 = server1->client->cl_xprt;
- struct rpc_xprt *xprt2 = server2->client->cl_xprt;
+
+ rcu_read_lock();
+
+ xprt1 = rcu_dereference(server1->client->cl_xprt);
+ xprt2 = rcu_dereference(server2->client->cl_xprt);
if (!net_eq(xprt1->xprt_net, xprt2->xprt_net))
- return 0;
+ goto out_unlock;
+
+ rcu_read_unlock();
sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
@@ -1203,6 +1209,10 @@ static int nfs_compare_super_address(struct nfs_server *server1,
}
return 1;
+
+out_unlock:
+ rcu_read_unlock();
+ return 0;
}
static int nfs_compare_userns(const struct nfs_server *old,
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-19 16:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-19 16:31 [PATCH v3 0/2] NFS: fix RCU and tracing pointer safety Sean Chang
2026-04-19 16:31 ` [PATCH v3 1/2] NFS: remove redundant __private attribute from nfs_page_class Sean Chang
2026-04-19 16:31 ` [PATCH v3 2/2] NFS: Fix RCU dereference of cl_xprt in nfs_compare_super_address Sean Chang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox