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 64-bit identifier from a global sequential counter in svc_xprt_init(). The counter does not wrap, so two transports never share an identifier and a consumer needs no release when the transport is freed. The NFSD duplicate reply cache is the first consumer. Reviewed-by: NeilBrown Link: https://patch.msgid.link/20260921-duplicate-reply-cache-v6-3-db5e13fd9944@kernel.org Signed-off-by: Chuck Lever --- 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..52082d8ea6dd 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; + u64 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..77efe63d2c14 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(u64, 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=%llu 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 bcc867592f2d..15c14d75ec12 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 atomic64_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); @@ -191,9 +193,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 never reused: the 64-bit counter behind it does + * not wrap. + * + * 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) @@ -211,6 +221,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 = atomic64_inc_return(&svc_xprt_id_seq); } EXPORT_SYMBOL_GPL(svc_xprt_init); -- 2.56.0