Thread (21 messages) flat view 21 messages, 3 authors, 2026-02-07
STALE229d

[PATCH net-next 6/9] psp: add core tracked stats for deferred key deletion

From: Daniel Zahka <daniel.zahka@gmail.com>
Date: 2026-02-04 15:20:16
Also in: linux-kselftest
Subsystem: networking [general], psp security protocol, the rest, yaml netlink (ynl) · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Daniel Zahka, Willem de Bruijn, Linus Torvalds, Donald Hunter

It is useful to keep track of two stats related to deferred key
deletion:

- tx_key_cnt: the number of outstanding tx keys from the hw's
  perspective
- grace_periods: the number of grace periods that core has retired for
  this dev.

Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
 Documentation/netlink/specs/psp.yaml | 14 ++++++++++++++
 include/net/psp/types.h              |  4 ++++
 include/uapi/linux/psp.h             |  2 ++
 net/psp/psp_main.c                   |  1 +
 net/psp/psp_nl.c                     |  3 +++
 net/psp/psp_sock.c                   |  9 ++++++++-
 6 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml
index f3a57782d2cf..efaf3f61e37a 100644
--- a/Documentation/netlink/specs/psp.yaml
+++ b/Documentation/netlink/specs/psp.yaml
@@ -153,6 +153,18 @@ attribute-sets:
         doc: |
           Number of PSP packets for transmission with errors.
           Device statistic (from the PSP spec).
+      -
+        name: tx-key-cnt
+        type: sint
+        doc: |
+          Current number of TX keys installed on the device.
+          Kernel statistic.
+      -
+        name: grace-periods
+        type: uint
+        doc: |
+          Number of TX key deletion grace periods completed.
+          Kernel statistic.
 
 operations:
   list:
@@ -267,6 +279,8 @@ operations:
             - dev-id
             - key-rotations
             - stale-events
+            - tx-key-cnt
+            - grace-periods
         pre: psp-device-get-locked
         post: psp-device-unlock
       dump:
diff --git a/include/net/psp/types.h b/include/net/psp/types.h
index 280c7fdc713c..d790efd9d4bc 100644
--- a/include/net/psp/types.h
+++ b/include/net/psp/types.h
@@ -67,6 +67,8 @@ struct psp_dev_config {
  * @stats:	statistics maintained by the core
  * @stats.rotations:	See stats attr key-rotations
  * @stats.stales:	See stats attr stale-events
+ * @stats.tx_key_cnt:	See stats attr tx-key-cnt
+ * @stats.grace_periods:	See stats attr grace-periods
  *
  * @rcu:	RCU head for freeing the structure
  */
@@ -98,6 +100,8 @@ struct psp_dev {
 	struct {
 		unsigned long rotations;
 		unsigned long stales;
+		long tx_key_cnt;
+		unsigned long grace_periods;
 	} stats;
 
 	struct rcu_head rcu;
diff --git a/include/uapi/linux/psp.h b/include/uapi/linux/psp.h
index a3a336488dc3..208ab60e2c88 100644
--- a/include/uapi/linux/psp.h
+++ b/include/uapi/linux/psp.h
@@ -58,6 +58,8 @@ enum {
 	PSP_A_STATS_TX_PACKETS,
 	PSP_A_STATS_TX_BYTES,
 	PSP_A_STATS_TX_ERROR,
+	PSP_A_STATS_TX_KEY_CNT,
+	PSP_A_STATS_GRACE_PERIODS,
 
 	__PSP_A_STATS_MAX,
 	PSP_A_STATS_MAX = (__PSP_A_STATS_MAX - 1)
diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
index 2fb886edc384..4a7b2ffa718e 100644
--- a/net/psp/psp_main.c
+++ b/net/psp/psp_main.c
@@ -215,6 +215,7 @@ static void psp_tx_del_work_fn(struct work_struct *work)
 		}
 
 		psd->tx_grace_active = false;
+		psd->stats.grace_periods++;
 	}
 
 start_grace:
diff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c
index a540a1e77694..f0006d2e85c8 100644
--- a/net/psp/psp_nl.c
+++ b/net/psp/psp_nl.c
@@ -526,6 +526,9 @@ psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp,
 	    nla_put_uint(rsp, PSP_A_STATS_KEY_ROTATIONS,
 			 psd->stats.rotations) ||
 	    nla_put_uint(rsp, PSP_A_STATS_STALE_EVENTS, psd->stats.stales) ||
+	    nla_put_sint(rsp, PSP_A_STATS_TX_KEY_CNT, psd->stats.tx_key_cnt) ||
+	    nla_put_uint(rsp, PSP_A_STATS_GRACE_PERIODS,
+			 psd->stats.grace_periods) ||
 	    nla_put_uint(rsp, PSP_A_STATS_RX_PACKETS, stats.rx_packets) ||
 	    nla_put_uint(rsp, PSP_A_STATS_RX_BYTES, stats.rx_bytes) ||
 	    nla_put_uint(rsp, PSP_A_STATS_RX_AUTH_FAIL, stats.rx_auth_fail) ||
diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c
index d038da122ebb..bf6d089657b6 100644
--- a/net/psp/psp_sock.c
+++ b/net/psp/psp_sock.c
@@ -80,12 +80,19 @@ static struct psp_assoc *psp_assoc_dummy(struct psp_assoc *pas)
 static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,
 			      struct netlink_ext_ack *extack)
 {
-	return psd->ops->tx_key_add(psd, pas, extack);
+	int rc;
+
+	rc = psd->ops->tx_key_add(psd, pas, extack);
+	if (!rc)
+		psd->stats.tx_key_cnt++;
+
+	return rc;
 }
 
 void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas)
 {
 	psd->ops->tx_key_del(psd, pas);
+	psd->stats.tx_key_cnt--;
 }
 
 static bool psp_dev_needs_defer(struct psp_dev *psd)
-- 
2.47.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help