From: Chuck Lever <cel@kernel.org>
To: Jeff Layton <jlayton@kernel.org>, NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: Rick Macklem <rmacklem@uoguelph.ca>,
linux-nfs@vger.kernel.org, Chuck Lever <cel@kernel.org>
Subject: [PATCH v4 01/11] SUNRPC: Assign a unique identifier to each svc_xprt
Date: Mon, 14 Sep 2026 10:45:31 -0400 [thread overview]
Message-ID: <20260914-duplicate-reply-cache-v4-1-bcf9d2628a94@kernel.org> (raw)
In-Reply-To: <20260914-duplicate-reply-cache-v4-0-bcf9d2628a94@kernel.org>
A consumer that associates state with a transport without holding a
reference cannot detect ABA collisions: once a transport is freed,
SLUB may hand out a new svc_xprt at the same address.
Assign each transport a 32-bit identifier from a global sequential
counter in svc_xprt_init(). An identifier is reused only after 2^32
further transports have been created, so a consumer whose
association is shorter-lived than that needs no release when the
transport is freed. The NFSD duplicate reply cache is the first
consumer. A 32-bit value fits the padding in its cache entry, and a
cache entry is retained for two minutes, not for 2^32 connections.
Assisted-by: LLM
Signed-off-by: Chuck Lever <cel@kernel.org>
---
include/linux/sunrpc/svc_xprt.h | 1 +
include/trace/events/sunrpc.h | 8 ++++++--
net/sunrpc/svc_xprt.c | 17 ++++++++++++++---
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/svc_xprt.h
index 2af222f3ea2c..9f940c892eca 100644
--- a/include/linux/sunrpc/svc_xprt.h
+++ b/include/linux/sunrpc/svc_xprt.h
@@ -56,6 +56,7 @@ struct svc_xprt {
struct svc_xprt_class *xpt_class;
const struct svc_xprt_ops *xpt_ops;
struct kref xpt_ref;
+ u32 xpt_id;
ktime_t xpt_qtime;
struct list_head xpt_list;
struct lwq_node xpt_ready;
diff --git a/include/trace/events/sunrpc.h b/include/trace/events/sunrpc.h
index ff855197880d..30d5fbb07e0a 100644
--- a/include/trace/events/sunrpc.h
+++ b/include/trace/events/sunrpc.h
@@ -1986,7 +1986,8 @@ TRACE_EVENT(svc_xprt_create_err,
__sockaddr(server, (x)->xpt_locallen) \
__sockaddr(client, (x)->xpt_remotelen) \
__field(unsigned long, flags) \
- __field(unsigned int, netns_ino)
+ __field(unsigned int, netns_ino) \
+ __field(u32, xpt_id)
#define SVC_XPRT_ENDPOINT_ASSIGNMENTS(x) \
do { \
@@ -1996,13 +1997,15 @@ TRACE_EVENT(svc_xprt_create_err,
(x)->xpt_remotelen); \
__entry->flags = (x)->xpt_flags; \
__entry->netns_ino = (x)->xpt_net->ns.inum; \
+ __entry->xpt_id = (x)->xpt_id; \
} while (0)
#define SVC_XPRT_ENDPOINT_FORMAT \
- "server=%pISpc client=%pISpc flags=%s"
+ "server=%pISpc client=%pISpc xpt_id=%u flags=%s"
#define SVC_XPRT_ENDPOINT_VARARGS \
__get_sockaddr(server), __get_sockaddr(client), \
+ __entry->xpt_id, \
show_svc_xprt_flags(__entry->flags)
TRACE_EVENT(svc_xprt_enqueue,
@@ -2024,6 +2027,7 @@ TRACE_EVENT(svc_xprt_enqueue,
xprt->xpt_remotelen);
__entry->flags = flags;
__entry->netns_ino = xprt->xpt_net->ns.inum;
+ __entry->xpt_id = xprt->xpt_id;
),
TP_printk(SVC_XPRT_ENDPOINT_FORMAT, SVC_XPRT_ENDPOINT_VARARGS)
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index d5634dd6d6cc..f836a7aebd64 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -26,6 +26,8 @@
static unsigned int svc_rpc_per_connection_limit __read_mostly;
module_param(svc_rpc_per_connection_limit, uint, 0644);
+static atomic_t svc_xprt_id_seq;
+
static struct svc_deferred_req *svc_deferred_dequeue(struct svc_xprt *xprt);
static int svc_deferred_recv(struct svc_rqst *rqstp);
@@ -190,9 +192,17 @@ void svc_xprt_put(struct svc_xprt *xprt)
}
EXPORT_SYMBOL_GPL(svc_xprt_put);
-/*
- * Called by transport drivers to initialize the transport independent
- * portion of the transport instance.
+/**
+ * svc_xprt_init - initialize transport-independent portion of a transport
+ * @net: network namespace in which the transport operates
+ * @xcl: transport class providing operations and metadata
+ * @xprt: svc_xprt to initialize
+ * @serv: RPC service that owns this transport
+ *
+ * @xprt->xpt_id is reused only after 2^32 further transports have
+ * been initialized.
+ *
+ * Context: Process context. May sleep.
*/
void svc_xprt_init(struct net *net, struct svc_xprt_class *xcl,
struct svc_xprt *xprt, struct svc_serv *serv)
@@ -210,6 +220,7 @@ void svc_xprt_init(struct net *net, struct svc_xprt_class *xcl,
set_bit(XPT_BUSY, &xprt->xpt_flags);
xprt->xpt_net = get_net_track(net, &xprt->ns_tracker, GFP_ATOMIC);
strcpy(xprt->xpt_remotebuf, "uninitialized");
+ xprt->xpt_id = atomic_inc_return(&svc_xprt_id_seq);
}
EXPORT_SYMBOL_GPL(svc_xprt_init);
--
2.55.0
next prev parent reply other threads:[~2026-09-14 14:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 14:45 [PATCH v4 00/11] Improve the scalability of NFSD's classic DRC Chuck Lever
2026-09-14 14:45 ` Chuck Lever [this message]
2026-09-14 14:45 ` [PATCH v4 02/11] NFSD: Track transport in DRC entries Chuck Lever
2026-09-14 14:45 ` [PATCH v4 03/11] NFSD: Prepare bucket pruning for out-of-order eviction Chuck Lever
2026-09-14 14:45 ` [PATCH v4 04/11] NFSD: Add tracepoints for DRC entry eviction Chuck Lever
2026-09-14 14:45 ` [PATCH v4 05/11] NFSD: Record DRC population in lookup tracepoints Chuck Lever
2026-09-14 14:45 ` [PATCH v4 06/11] SUNRPC: Publish reply positions for upper-layer consumers Chuck Lever
2026-09-14 14:45 ` [PATCH v4 07/11] SUNRPC: Publish TCP reply positions Chuck Lever
2026-09-14 14:45 ` [PATCH v4 08/11] svcrdma: Publish RDMA " Chuck Lever
2026-09-14 14:45 ` [PATCH v4 09/11] NFSD: Evict acknowledged DRC entries Chuck Lever
2026-09-14 14:45 ` [PATCH v4 10/11] NFSD: Remove DRC checksum and payload_misses stat Chuck Lever
2026-09-14 14:45 ` [PATCH v4 11/11] NFSD: Remove hard cap on duplicate reply cache size Chuck Lever
2026-09-15 5:13 ` [PATCH v4 00/11] Improve the scalability of NFSD's classic DRC NeilBrown
2026-09-15 23:56 ` Chuck Lever
2026-09-15 6:25 ` NeilBrown
2026-09-16 0:02 ` Chuck Lever
2026-09-16 22:47 ` NeilBrown
2026-09-17 15:04 ` Chuck Lever
2026-09-17 21:46 ` NeilBrown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260914-duplicate-reply-cache-v4-1-bcf9d2628a94@kernel.org \
--to=cel@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=rmacklem@uoguelph.ca \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.