AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/10/09 23:06 flow patch-triage
5m Args:
null

Results:
{
  "EnableConfigs": [
    "INET_PSP",
    "NETDEVSIM",
    "BQL"
  ],
  "FocusSymbols": [
    "psp_sock_assoc_set_rx",
    "psp_sock_assoc_set_tx",
    "psp_sock_rx_rekey",
    "psp_sock_tx_rekey",
    "psp_assocs_key_rotated",
    "psp_dev_tx_key_del",
    "psp_deferred_del_queue",
    "psp_deferred_del_work",
    "psp_tx_grace_done"
  ],
  "KMSANReasoning": "The patch implements PSP in-place rekeying and deferred Tx key deletion based on Byte Queue Limits (BQL).\n\n1. Memory initialization: All new or modified data structures (such as `struct psp_txq_state` and `struct psp_assoc`) are allocated with zeroing allocators (`kvzalloc_flex`, `kzalloc_flex`, `bitmap_zalloc`). All fields (including `prev_spi`, `prev_generation`, and `flags`) are either explicitly initialized or zero-filled upon creation.\n2. Kernel-to-userspace communication: The patch adds one netlink attribute (`PSP_A_STATS_TX_KEY_COUNT`) to `psp_nl_stats_fill()`. This exports a scalar `unsigned long` (`tx_key_cnt`), which is zero-initialized at `psp_dev` creation and incremented/decremented upon key addition/deletion. No structs with padding or uninitialized memory buffers are copied to user space.\n3. Bug profile: The patch touches concurrency, list operations, delayed work execution, and object lifetimes/reference counting across RCU and mutex critical sections. Any memory issues arising from these changes (e.g. use-after-free, double free, refcount leaks, out-of-bounds access, locking deadlocks) fall under KASAN, LOCKDEP, and standard sanitizer checks.\n\nBecause there are no uninitialized memory read risks or info-leaks, a dedicated KMSAN fuzzing session is not justified.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch adds connection in-place rekeying support and deferred Tx key deletion using BQL accounting to the PSP (PSP Security Protocol) subsystem in net/psp/. It modifies association lifecycle management, reference counts, socket association assignment, packet acceptance checks, and introduces new WARN and WARN_ON_ONCE checks. The code is reachable in standard virtualized environments via simulated networking devices (netdevsim), generic netlink, and standard TCP sockets.",
  "WorthFuzzing": true
}

1/1 2026/10/09 23:06 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 9ecf5c48c0d9147c72e7843af57f7e4710b29694\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Fri Oct 9 23:06:29 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml\nindex f3266763c3253..d14c11d098914 100644\n--- a/Documentation/netlink/specs/psp.yaml\n+++ b/Documentation/netlink/specs/psp.yaml\n@@ -190,6 +190,13 @@ attribute-sets:\n         doc: |\n           Number of PSP packets for transmission with errors.\n           Device statistic (from the PSP spec).\n+      -\n+        name: tx-key-count\n+        type: uint\n+        doc: |\n+          Current number of Tx keys installed on the device.\n+          Only visible if the driver stores keys on device.\n+          Kernel statistic.\n \n operations:\n   list:\n@@ -316,6 +323,7 @@ operations:\n             - tx-packets\n             - tx-bytes\n             - tx-error\n+            - tx-key-count\n         pre: psp-device-get-locked\n         post: psp-device-unlock\n       dump:\ndiff --git a/Documentation/networking/psp.rst b/Documentation/networking/psp.rst\nindex 0f9b6b73f2447..769c7b21045ce 100644\n--- a/Documentation/networking/psp.rst\n+++ b/Documentation/networking/psp.rst\n@@ -140,14 +140,36 @@ The PSP assoc state of a socket is not reset when the connection is\n torn down. ``connect()`` on a socket that has PSP assoc state will\n return ``-EINVAL``.\n \n+Rekeying\n+--------\n+\n+A connection which has completed the exchange described above and is\n+in the \"PSP Full\" state can be rekeyed in place without being torn\n+down. The Tx and Rx directions are rekeyed separately using the same\n+netlink calls as in connection setup.\n+\n+``rx-assoc`` allocates a new Rx key and SPI, which should be passed\n+to the peer exactly as during the initial exchange. The SPI which was\n+in use before the rekey remains acceptable on the socket until the\n+next Rx rekey, so packets the peer sent before it learned the new SPI\n+are still received.\n+\n+``tx-assoc`` installs a new Tx key, which takes effect immediately.\n+The peer will accept data encrypted from the old and new SPI.\n+\n+A rekey is rejected with ``-EINVAL`` if it would change the PSP device\n+or the PSP version of the association. It is rejected with ``-EBUSY``\n+if the socket has not completed its initial exchange in both\n+directions.\n+\n Rotation notifications\n ----------------------\n \n The rotations of device key happen asynchronously and are usually\n performed by management daemons, not under application control.\n The PSP netlink family will generate a notification whenever keys\n-are rotated. The applications are expected to re-establish connections\n-before keys are rotated again.\n+are rotated. Applications are expected to rekey their connections,\n+as described above, before device keys are rotated again.\n \n Kernel implementation\n =====================\n@@ -180,6 +202,44 @@ Drivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload\n was requested for given skb. On Rx drivers should allocate and populate\n the ``SKB_EXT_PSP`` skb extension, and set the skb-\u003edecrypted bit to 1.\n \n+Deferred Tx key deletion\n+~~~~~~~~~~~~~~~~~~~~~~~~\n+\n+Drivers which implement ``tx_key_add`` and ``tx_key_del`` may hold key\n+references in their Tx rings, so PSP core waits until descriptors\n+containing these references are completed before removing the key from\n+the underlying device. PSP core uses accounting based on Byte Queue Limits\n+(BQL) to wait for a suitable grace period before asking the driver to\n+remove the key.\n+\n+Drivers which implement the Tx key callbacks must meet the following\n+requirements:\n+\n+* The driver must be \"ops locked\"\n+  (see Documentation/networking/netdevices.rst).\n+* A PSP skb accepted by ``ndo_start_xmit()`` must remain socket-owned until\n+  every Tx descriptor referencing its PSP key has been completed or otherwise\n+  made incapable of using the key. The driver must not orphan the skb before\n+  that point. Otherwise, the socket destructor may free the Tx key while key\n+  references remain in the Tx ring.\n+* Every PSP packet accepted by ``ndo_start_xmit()`` must be included in BQL\n+  queued bytecount before the function returns.\n+* Completion bytecounts must exactly match enqueue bytecounts and preserve\n+  queue order. A later packet must not be reported as completed while an earlier\n+  packet can still reference its key.\n+* Before calling ``dql_reset()`` on a queue, the driver must ensure that all\n+  outstanding descriptors containing key references have been completed or\n+  discarded. If called under the netdev instance lock, then descriptors can\n+  remain outstanding after the reset as long as they are completed or\n+  discarded before the instance lock is released.\n+* When decreasing ``real_num_tx_queues``, the driver must ensure that every\n+  outstanding descriptor on the queues at or above the new Tx queue count\n+  has been completed or otherwise made incapable of using its PSP key\n+  before the netdev instance lock is released.\n+* The BQL state of a queue below ``real_num_tx_queues`` must reflect all\n+  bytes completed or be reset after the queue has been quiesced. Failure to\n+  do so will stall the grace period algorithm.\n+\n Kernel implementation notes\n ---------------------------\n \ndiff --git a/include/net/psp/functions.h b/include/net/psp/functions.h\nindex b23c30898389c..fb80e15e43681 100644\n--- a/include/net/psp/functions.h\n+++ b/include/net/psp/functions.h\n@@ -77,10 +77,12 @@ psp_is_allowed_nondata(struct sk_buff *skb, struct psp_assoc *pas)\n static inline bool\n psp_pse_matches_pas(struct psp_skb_ext *pse, struct psp_assoc *pas)\n {\n-\treturn pse \u0026\u0026 pas-\u003erx.spi == pse-\u003espi \u0026\u0026\n-\t       pas-\u003egeneration == pse-\u003egeneration \u0026\u0026\n-\t       pas-\u003eversion == pse-\u003eversion \u0026\u0026\n-\t       pas-\u003edev_id == pse-\u003edev_id;\n+\treturn pse \u0026\u0026 pas-\u003eversion == pse-\u003eversion \u0026\u0026\n+\t       pas-\u003edev_id == pse-\u003edev_id \u0026\u0026\n+\t       ((pas-\u003erx.spi == pse-\u003espi \u0026\u0026\n+\t\t pas-\u003egeneration == pse-\u003egeneration) ||\n+\t\t(pas-\u003eprev_spi \u0026\u0026 pas-\u003eprev_spi == pse-\u003espi \u0026\u0026\n+\t\t pas-\u003eprev_generation == pse-\u003egeneration));\n }\n \n static inline enum skb_drop_reason\ndiff --git a/include/net/psp/types.h b/include/net/psp/types.h\nindex b8905efbd604e..970801cb65026 100644\n--- a/include/net/psp/types.h\n+++ b/include/net/psp/types.h\n@@ -3,8 +3,10 @@\n #ifndef __NET_PSP_H\n #define __NET_PSP_H\n \n+#include \u003clinux/bits.h\u003e\n #include \u003clinux/mutex.h\u003e\n #include \u003clinux/refcount.h\u003e\n+#include \u003clinux/workqueue.h\u003e\n #include \u003cnet/net_trackers.h\u003e\n \n struct netlink_ext_ack;\n@@ -79,10 +81,16 @@ struct psp_assoc_dev {\n  * @prev_assocs:\tassociations which use old (but still usable)\n  *\t\t\tdevice key\n  * @stale_assocs:\tassociations which use a rotated out key\n+ * @tx_del:\t\tdeferred TX key deletion state\n+ * @tx_del.active:\tTX keys to be deleted after the current grace period\n+ * @tx_del.next:\tTX keys queued for deletion during current grace period\n+ * @tx_del.work:\tdelayed work item for periodic grace period checking\n+ * @tx_del.txq_state:\tTX queue state for deferred deletion grace periods\n  *\n  * @stats:\tstatistics maintained by the core\n  * @stats.rotations:\tSee stats attr key-rotations\n  * @stats.stales:\tSee stats attr stale-events\n+ * @stats.tx_key_cnt:\tSee stats attr tx-key-count\n  *\n  * @rcu:\tRCU head for freeing the structure\n  */\n@@ -108,9 +116,17 @@ struct psp_dev {\n \tstruct list_head prev_assocs;\n \tstruct list_head stale_assocs;\n \n+\tstruct {\n+\t\tstruct list_head active;\n+\t\tstruct list_head next;\n+\t\tstruct delayed_work work;\n+\t\tstruct psp_txq_state *txq_state;\n+\t} tx_del;\n+\n \tstruct {\n \t\tunsigned long rotations;\n \t\tunsigned long stales;\n+\t\tunsigned long tx_key_cnt;\n \t} stats;\n \n \tstruct rcu_head rcu;\n@@ -152,6 +168,20 @@ struct psp_key_parsed {\n \tu8 key[PSP_MAX_KEY];\n };\n \n+/**\n+ * enum psp_assoc_flags - flags of struct psp_assoc\n+ * @PSP_ASSOC_SKIP_TX_KEY_DEL: Do not delete Tx key from psp_dev. It was\n+ *\tcopied to a newer psp_assoc during an Rx rekey.\n+ * @PSP_ASSOC_DEFER_TX_KEY_DEL: Send Tx key to psp_dev's deferred deletion\n+ *\tqueue. This psp_assoc was detached from its socket during a Tx rekey\n+ *\tand requires device descriptor state referencing this key to be\n+ *\tdrained.\n+ */\n+enum psp_assoc_flags {\n+\tPSP_ASSOC_SKIP_TX_KEY_DEL\t= BIT(0),\n+\tPSP_ASSOC_DEFER_TX_KEY_DEL\t= BIT(1),\n+};\n+\n struct psp_assoc {\n \tstruct psp_dev *psd;\n \n@@ -159,6 +189,10 @@ struct psp_assoc {\n \tu8 generation;\n \tu8 version;\n \tu8 peer_tx;\n+\tu8 prev_generation;\n+\tu8 flags; /* Slow path, protected by psd-\u003elock */\n+\n+\t__be32 prev_spi;\n \n \tu32 upgrade_seq;\n \ndiff --git a/include/uapi/linux/psp.h b/include/uapi/linux/psp.h\nindex 1c8899cd4da5e..21810e8a72299 100644\n--- a/include/uapi/linux/psp.h\n+++ b/include/uapi/linux/psp.h\n@@ -69,6 +69,7 @@ enum {\n \tPSP_A_STATS_TX_PACKETS,\n \tPSP_A_STATS_TX_BYTES,\n \tPSP_A_STATS_TX_ERROR,\n+\tPSP_A_STATS_TX_KEY_COUNT,\n \n \t__PSP_A_STATS_MAX,\n \tPSP_A_STATS_MAX = (__PSP_A_STATS_MAX - 1)\ndiff --git a/net/psp/Kconfig b/net/psp/Kconfig\nindex 84d6b0f254606..36c12493784fd 100644\n--- a/net/psp/Kconfig\n+++ b/net/psp/Kconfig\n@@ -5,6 +5,7 @@\n config INET_PSP\n \tbool \"PSP Security Protocol support\"\n \tdepends on INET\n+\tdepends on BQL\n \tselect SKB_DECRYPTED\n \tselect SKB_EXTENSIONS\n \tselect SOCK_VALIDATE_XMIT\ndiff --git a/net/psp/Makefile b/net/psp/Makefile\nindex eb5ff3c5bfb2a..40decd8fe0500 100644\n--- a/net/psp/Makefile\n+++ b/net/psp/Makefile\n@@ -2,4 +2,4 @@\n \n obj-$(CONFIG_INET_PSP) += psp.o\n \n-psp-y := psp_main.o psp_nl.o psp_sock.o psp-nl-gen.o\n+psp-y := psp_main.o psp_nl.o psp_sock.o psp_deferred_del.o psp-nl-gen.o\ndiff --git a/net/psp/psp.h b/net/psp/psp.h\nindex b123c24279050..0cfc82c6c7110 100644\n--- a/net/psp/psp.h\n+++ b/net/psp/psp.h\n@@ -18,6 +18,11 @@ int psp_dev_check_access(struct psp_dev *psd, struct net *net, bool admin);\n bool psp_has_assoc_dev_in_ns(struct psp_dev *psd, struct net *net);\n int psp_attach_netdev_notifier(void);\n \n+int psp_deferred_del_init(struct psp_dev *psd);\n+void psp_deferred_del_stop(struct psp_dev *psd);\n+void psp_deferred_del_uninit(struct psp_dev *psd, bool unpublished);\n+void psp_deferred_del_queue(struct psp_dev *psd, struct psp_assoc *pas);\n+\n void psp_nl_notify_dev(struct psp_dev *psd, u32 cmd);\n void psp_nl_notify_disassoc(struct psp_dev *psd, struct net *net);\n \n@@ -63,7 +68,8 @@ static inline bool psp_dev_has_sadb(struct psp_dev *psd)\n static inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas)\n {\n \tlockdep_assert_held(\u0026pas-\u003epsd-\u003elock);\n-\treturn psp_dev_has_sadb(pas-\u003epsd) \u0026\u0026 pas-\u003etx.spi;\n+\treturn psp_dev_has_sadb(pas-\u003epsd) \u0026\u0026 pas-\u003etx.spi \u0026\u0026\n+\t       !(pas-\u003eflags \u0026 PSP_ASSOC_SKIP_TX_KEY_DEL);\n }\n \n #endif /* __PSP_PSP_H */\ndiff --git a/net/psp/psp_deferred_del.c b/net/psp/psp_deferred_del.c\nnew file mode 100644\nindex 0000000000000..cfbac72577e96\n--- /dev/null\n+++ b/net/psp/psp_deferred_del.c\n@@ -0,0 +1,231 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+\n+#include \u003clinux/bitmap.h\u003e\n+#include \u003clinux/jiffies.h\u003e\n+#include \u003clinux/list.h\u003e\n+#include \u003clinux/netdevice.h\u003e\n+#include \u003clinux/slab.h\u003e\n+#include \u003cnet/netdev_lock.h\u003e\n+#include \u003cnet/psp.h\u003e\n+\n+#include \"psp.h\"\n+\n+#define PSP_TX_GRACE_POLL_MS\t1000\n+\n+struct psp_txq_state {\n+\tunsigned int num_tx_queues;\n+\tunsigned long *drained_queues;\n+\tunsigned int to_complete[];\n+};\n+\n+static void psp_txq_state_free(struct psp_txq_state *state)\n+{\n+\tif (!state)\n+\t\treturn;\n+\n+\tbitmap_free(state-\u003edrained_queues);\n+\tkvfree(state);\n+}\n+\n+static struct psp_txq_state *\n+psp_txq_state_alloc(unsigned int max_tx_queues)\n+{\n+\tstruct psp_txq_state *state;\n+\n+\tstate = kvzalloc_flex(*state, to_complete, max_tx_queues);\n+\tif (!state)\n+\t\treturn NULL;\n+\n+\tstate-\u003edrained_queues = bitmap_zalloc(max_tx_queues, GFP_KERNEL);\n+\tif (!state-\u003edrained_queues) {\n+\t\tpsp_txq_state_free(state);\n+\t\treturn NULL;\n+\t}\n+\n+\treturn state;\n+}\n+\n+static void psp_tx_grace_start(struct psp_dev *psd)\n+{\n+\tstruct psp_txq_state *state = psd-\u003etx_del.txq_state;\n+\tstruct net_device *dev = psd-\u003emain_netdev;\n+\tunsigned int i;\n+\n+\tnetdev_assert_locked(dev);\n+\n+\t/* Any instances of ndo_start_xmit() that observed these keys through\n+\t * psp_skb_get_assoc_rcu() must already be accounted in BQL's queued\n+\t * byte count. ndo_start_xmit() runs with BHs disabled, which forms an\n+\t * implicit RCU read-side critical section, and we are now at least one\n+\t * grace period after any of these psp_assocs have been cleared from\n+\t * sk-\u003epsp_assoc.\n+\t */\n+\tstate-\u003enum_tx_queues = dev-\u003ereal_num_tx_queues;\n+\tbitmap_zero(state-\u003edrained_queues, state-\u003enum_tx_queues);\n+\tfor (i = 0; i \u003c state-\u003enum_tx_queues; i++) {\n+\t\tstruct netdev_queue *txq = netdev_get_tx_queue(dev, i);\n+\n+\t\tstate-\u003eto_complete[i] = READ_ONCE(txq-\u003edql.num_queued);\n+\t}\n+}\n+\n+static bool psp_tx_grace_done(struct psp_dev *psd)\n+{\n+\tstruct psp_txq_state *state = psd-\u003etx_del.txq_state;\n+\tstruct net_device *dev = psd-\u003emain_netdev;\n+\tbool all_completed = true;\n+\tunsigned int i;\n+\n+\tnetdev_assert_locked(dev);\n+\n+\tif (dev-\u003ereal_num_tx_queues \u003c state-\u003enum_tx_queues)\n+\t\tstate-\u003enum_tx_queues = dev-\u003ereal_num_tx_queues;\n+\n+\tfor (i = 0; i \u003c state-\u003enum_tx_queues; i++) {\n+\t\tstruct netdev_queue *txq = netdev_get_tx_queue(dev, i);\n+\t\tunsigned int completed;\n+\t\tunsigned int queued;\n+\n+\t\tif (test_bit(i, state-\u003edrained_queues))\n+\t\t\tcontinue;\n+\n+\t\t/* Drivers must meet the requirements documented in\n+\t\t * Documentation/networking/psp.rst to guarantee forward\n+\t\t * progress and avoid ending the grace period prematurely.\n+\t\t *\n+\t\t * We snapshotted num_queued in psp_tx_grace_start() and need\n+\t\t * to determine whether num_completed has since reached or\n+\t\t * passed that mark. For a given queue, we can consider first\n+\t\t * whether or not dql_reset() was called at any point between\n+\t\t * when we read num_queued until we read num_completed and\n+\t\t * num_queued here and then separate the space of possible\n+\t\t * states based on that.\n+\t\t *\n+\t\t * Not reset: num_queued and num_completed only increase, and\n+\t\t * dql keeps num_queued - num_completed \u003c= INT_MAX at all\n+\t\t * times. We can form three exhaustive sub cases:\n+\t\t *\n+\t\t * (int)(to_complete - completed) \u003c= 0: completion reached or\n+\t\t * passed the mark. At the time to_complete was read,\n+\t\t * completed was in [to_complete - INT_MAX, to_complete].\n+\t\t *\n+\t\t * (int)(to_complete - queued) \u003e 0: to_complete and queued are\n+\t\t * both snapshots of num_queued, so queued has advanced more\n+\t\t * than INT_MAX + 1 past to_complete. num_completed lags\n+\t\t * queued by at most INT_MAX, so num_completed must have\n+\t\t * crossed to_complete.\n+\t\t *\n+\t\t * Otherwise the mark may still be in flight, so poll again.\n+\t\t *\n+\t\t * Reset: By the driver conditions laid out in\n+\t\t * Documentation/networking/psp.rst, if a dql_reset()\n+\t\t * occurred, and we are holding the instance lock, then we\n+\t\t * know the actual state of the queue is drained. The check\n+\t\t * below is then conservative because there is no risk of\n+\t\t * falsely declaring the queue drained. As long as dql makes\n+\t\t * forward progress the check should eventually report\n+\t\t * drained.\n+\t\t */\n+\t\tcompleted = READ_ONCE(txq-\u003edql.num_completed);\n+\t\tqueued = READ_ONCE(txq-\u003edql.num_queued);\n+\n+\t\tif ((int)(state-\u003eto_complete[i] - completed) \u003c= 0 ||\n+\t\t    (int)(state-\u003eto_complete[i] - queued) \u003e 0)\n+\t\t\t__set_bit(i, state-\u003edrained_queues);\n+\t\telse\n+\t\t\tall_completed = false;\n+\t}\n+\n+\treturn all_completed;\n+}\n+\n+static bool psp_tx_grace_active(struct psp_dev *psd)\n+{\n+\treturn !list_empty(\u0026psd-\u003etx_del.active);\n+}\n+\n+static void psp_deferred_del_work(struct work_struct *work)\n+{\n+\tstruct delayed_work *dwork = to_delayed_work(work);\n+\tstruct psp_assoc *pas, *tmp;\n+\tbool need_reschedule;\n+\tstruct psp_dev *psd;\n+\tLIST_HEAD(to_free);\n+\n+\tpsd = container_of(dwork, struct psp_dev, tx_del.work);\n+\n+\tmutex_lock(\u0026psd-\u003elock);\n+\tnetdev_lock(psd-\u003emain_netdev);\n+\n+\tif (psp_tx_grace_active(psd) \u0026\u0026 psp_tx_grace_done(psd))\n+\t\tlist_splice_init(\u0026psd-\u003etx_del.active, \u0026to_free);\n+\n+\tif (!psp_tx_grace_active(psd) \u0026\u0026 !list_empty(\u0026psd-\u003etx_del.next)) {\n+\t\tpsp_tx_grace_start(psd);\n+\t\tlist_splice_init(\u0026psd-\u003etx_del.next, \u0026psd-\u003etx_del.active);\n+\t}\n+\n+\tnetdev_unlock(psd-\u003emain_netdev);\n+\n+\tlist_for_each_entry(pas, \u0026to_free, assocs_list)\n+\t\tpsp_dev_tx_key_del(psd, pas);\n+\n+\tneed_reschedule = psp_tx_grace_active(psd);\n+\tmutex_unlock(\u0026psd-\u003elock);\n+\n+\tif (need_reschedule)\n+\t\tmod_delayed_work(system_percpu_wq, \u0026psd-\u003etx_del.work,\n+\t\t\t\t msecs_to_jiffies(PSP_TX_GRACE_POLL_MS));\n+\n+\tlist_for_each_entry_safe(pas, tmp, \u0026to_free, assocs_list) {\n+\t\tlist_del(\u0026pas-\u003eassocs_list);\n+\t\tpsp_dev_put(psd);\n+\t\tkfree(pas);\n+\t}\n+}\n+\n+int psp_deferred_del_init(struct psp_dev *psd)\n+{\n+\tINIT_LIST_HEAD(\u0026psd-\u003etx_del.active);\n+\tINIT_LIST_HEAD(\u0026psd-\u003etx_del.next);\n+\tINIT_DELAYED_WORK(\u0026psd-\u003etx_del.work, psp_deferred_del_work);\n+\n+\tif (!psd-\u003eops-\u003etx_key_del)\n+\t\treturn 0;\n+\n+\tpsd-\u003etx_del.txq_state =\n+\t\tpsp_txq_state_alloc(psd-\u003emain_netdev-\u003enum_tx_queues);\n+\n+\treturn psd-\u003etx_del.txq_state ? 0 : -ENOMEM;\n+}\n+\n+void psp_deferred_del_stop(struct psp_dev *psd)\n+{\n+\tdisable_delayed_work_sync(\u0026psd-\u003etx_del.work);\n+}\n+\n+void psp_deferred_del_uninit(struct psp_dev *psd, bool unpublished)\n+{\n+\tstruct psp_assoc *pas, *next;\n+\n+\tlockdep_assert(unpublished || lockdep_is_held(\u0026psd-\u003elock));\n+\n+\tpsp_txq_state_free(psd-\u003etx_del.txq_state);\n+\tpsd-\u003etx_del.txq_state = NULL;\n+\n+\tlist_splice_init(\u0026psd-\u003etx_del.active, \u0026psd-\u003etx_del.next);\n+\tlist_for_each_entry_safe(pas, next, \u0026psd-\u003etx_del.next, assocs_list) {\n+\t\tlist_del(\u0026pas-\u003eassocs_list);\n+\t\tpsp_dev_tx_key_del(psd, pas);\n+\t\tpsp_dev_put(psd);\n+\t\tkfree(pas);\n+\t}\n+}\n+\n+void psp_deferred_del_queue(struct psp_dev *psd, struct psp_assoc *pas)\n+{\n+\tlockdep_assert_held(\u0026psd-\u003elock);\n+\n+\tlist_move_tail(\u0026pas-\u003eassocs_list, \u0026psd-\u003etx_del.next);\n+\tschedule_delayed_work(\u0026psd-\u003etx_del.work, 0);\n+}\ndiff --git a/net/psp/psp_main.c b/net/psp/psp_main.c\nindex 273b010d2355c..9f256157d88bf 100644\n--- a/net/psp/psp_main.c\n+++ b/net/psp/psp_main.c\n@@ -3,8 +3,10 @@\n #include \u003clinux/bitfield.h\u003e\n #include \u003clinux/list.h\u003e\n #include \u003clinux/netdevice.h\u003e\n+#include \u003clinux/slab.h\u003e\n #include \u003clinux/xarray.h\u003e\n #include \u003cnet/net_namespace.h\u003e\n+#include \u003cnet/netdev_lock.h\u003e\n #include \u003cnet/psp.h\u003e\n #include \u003cnet/udp.h\u003e\n \n@@ -70,7 +72,8 @@ psp_dev_create(struct net_device *netdev,\n \t\t    !psd_ops-\u003erx_spi_alloc ||\n \t\t    !psd_ops-\u003eget_stats ||\n \t\t    (!psd_ops-\u003etx_key_add != !psd_ops-\u003etx_key_del) ||\n-\t\t    (psd_caps-\u003eassoc_drv_spc \u0026\u0026 !psd_ops-\u003etx_key_add)))\n+\t\t    (psd_caps-\u003eassoc_drv_spc \u0026\u0026 !psd_ops-\u003etx_key_add) ||\n+\t\t    (psd_ops-\u003etx_key_add \u0026\u0026 !netdev_need_ops_lock(netdev))))\n \t\treturn ERR_PTR(-EINVAL);\n \n \tpsd = kzalloc_obj(*psd);\n@@ -89,13 +92,16 @@ psp_dev_create(struct net_device *netdev,\n \tINIT_LIST_HEAD(\u0026psd-\u003estale_assocs);\n \trefcount_set(\u0026psd-\u003erefcnt, 1);\n \n+\terr = psp_deferred_del_init(psd);\n+\tif (err)\n+\t\tgoto err_free_psd;\n+\n \tmutex_lock(\u0026psp_devs_lock);\n \terr = xa_alloc_cyclic(\u0026psp_devs, \u0026psd-\u003eid, psd, xa_limit_16b,\n \t\t\t      \u0026last_id, GFP_KERNEL);\n \tif (err) {\n \t\tmutex_unlock(\u0026psp_devs_lock);\n-\t\tkfree(psd);\n-\t\treturn ERR_PTR(err);\n+\t\tgoto err_uninit_deferred_del;\n \t}\n \tmutex_lock(\u0026psd-\u003elock);\n \tmutex_unlock(\u0026psp_devs_lock);\n@@ -111,6 +117,12 @@ psp_dev_create(struct net_device *netdev,\n \tmutex_unlock(\u0026psd-\u003elock);\n \n \treturn psd;\n+\n+err_uninit_deferred_del:\n+\tpsp_deferred_del_uninit(psd, true);\n+err_free_psd:\n+\tkfree(psd);\n+\treturn ERR_PTR(err);\n }\n EXPORT_SYMBOL(psp_dev_create);\n \n@@ -133,6 +145,8 @@ void psp_dev_unregister(struct psp_dev *psd)\n \tstruct psp_assoc_dev *entry, *entry_tmp;\n \tstruct psp_assoc *pas, *next;\n \n+\tpsp_deferred_del_stop(psd);\n+\n \tmutex_lock(\u0026psp_devs_lock);\n \tmutex_lock(\u0026psd-\u003elock);\n \n@@ -145,6 +159,8 @@ void psp_dev_unregister(struct psp_dev *psd)\n \txa_store(\u0026psp_devs, psd-\u003eid, NULL, GFP_KERNEL);\n \tmutex_unlock(\u0026psp_devs_lock);\n \n+\tpsp_deferred_del_uninit(psd, false);\n+\n \tlist_splice_init(\u0026psd-\u003eactive_assocs, \u0026psd-\u003eprev_assocs);\n \tlist_splice_init(\u0026psd-\u003eprev_assocs, \u0026psd-\u003estale_assocs);\n \tlist_for_each_entry_safe(pas, next, \u0026psd-\u003estale_assocs, assocs_list) {\n@@ -153,6 +169,9 @@ void psp_dev_unregister(struct psp_dev *psd)\n \t\tlist_del(\u0026pas-\u003eassocs_list);\n \t}\n \n+\tWARN(psd-\u003estats.tx_key_cnt, \"psp: %s: %lu Tx keys still installed\\n\",\n+\t     netdev_name(psd-\u003emain_netdev), psd-\u003estats.tx_key_cnt);\n+\n \tlist_for_each_entry_safe(entry, entry_tmp, \u0026psd-\u003eassoc_dev_list,\n \t\t\t\t dev_list) {\n \t\tlist_del(\u0026entry-\u003edev_list);\ndiff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c\nindex cdfc2d72fb390..494022ab5a718 100644\n--- a/net/psp/psp_nl.c\n+++ b/net/psp/psp_nl.c\n@@ -934,6 +934,10 @@ psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp,\n \t    nla_put_uint(rsp, PSP_A_STATS_TX_ERROR, stats.tx_error))\n \t\tgoto err_cancel_msg;\n \n+\tif (psp_dev_has_sadb(psd) \u0026\u0026\n+\t    nla_put_uint(rsp, PSP_A_STATS_TX_KEY_COUNT, psd-\u003estats.tx_key_cnt))\n+\t\tgoto err_cancel_msg;\n+\n \tgenlmsg_end(rsp, hdr);\n \treturn 0;\n \ndiff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c\nindex a6b1c42dd626f..c458bc551b4b9 100644\n--- a/net/psp/psp_sock.c\n+++ b/net/psp/psp_sock.c\n@@ -94,9 +94,11 @@ static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,\n \n \tmemcpy(\u0026dummy-\u003etx, key, sizeof(*key));\n \terr = psd-\u003eops-\u003etx_key_add(psd, dummy, extack);\n-\tif (!err)\n+\tif (!err) {\n+\t\tpsd-\u003estats.tx_key_cnt++;\n \t\tmemcpy(pas-\u003edrv_data, dummy-\u003edrv_data,\n \t\t       psd-\u003ecaps-\u003eassoc_drv_spc);\n+\t}\n \n \tkfree(dummy);\n \treturn err;\n@@ -105,6 +107,8 @@ static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,\n void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas)\n {\n \tpsd-\u003eops-\u003etx_key_del(psd, pas);\n+\tif (!WARN_ON_ONCE(!psd-\u003estats.tx_key_cnt))\n+\t\tpsd-\u003estats.tx_key_cnt--;\n }\n \n static void psp_assoc_free(struct work_struct *work)\n@@ -114,8 +118,14 @@ static void psp_assoc_free(struct work_struct *work)\n \n \tmutex_lock(\u0026psd-\u003elock);\n \tif (psp_dev_is_registered(psd)) {\n-\t\tif (psp_assoc_needs_tx_key_del(pas))\n+\t\tif (psp_assoc_needs_tx_key_del(pas)) {\n+\t\t\tif (pas-\u003eflags \u0026 PSP_ASSOC_DEFER_TX_KEY_DEL) {\n+\t\t\t\tpsp_deferred_del_queue(psd, pas);\n+\t\t\t\tmutex_unlock(\u0026psd-\u003elock);\n+\t\t\t\treturn;\n+\t\t\t}\n \t\t\tpsp_dev_tx_key_del(psd, pas);\n+\t\t}\n \t\tlist_del(\u0026pas-\u003eassocs_list);\n \t}\n \tmutex_unlock(\u0026psd-\u003elock);\n@@ -149,10 +159,42 @@ void psp_sk_assoc_free(struct sock *sk)\n \tpsp_assoc_put(pas);\n }\n \n+static int psp_sock_rx_rekey(struct psp_assoc *pas, struct psp_assoc *prev,\n+\t\t\t     struct netlink_ext_ack *extack)\n+{\n+\tif (pas-\u003epsd != prev-\u003epsd) {\n+\t\tNL_SET_ERR_MSG(extack, \"PSP device mismatch with existing state\");\n+\t\treturn -EINVAL;\n+\t}\n+\tif (pas-\u003eversion != prev-\u003eversion) {\n+\t\tNL_SET_ERR_MSG(extack, \"PSP version mismatch with existing state\");\n+\t\treturn -EINVAL;\n+\t}\n+\tif (!prev-\u003etx.spi || !prev-\u003epeer_tx) {\n+\t\tNL_SET_ERR_MSG(extack, \"Socket PSP state is not fully established\");\n+\t\treturn -EBUSY;\n+\t}\n+\tif (!((pas-\u003erx.spi ^ prev-\u003erx.spi) \u0026 cpu_to_be32(PSP_SPI_KEY_PHASE))) {\n+\t\tNL_SET_ERR_MSG(extack, \"New and prev SPI have same phase bit\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tpas-\u003epeer_tx = 1;\n+\tpas-\u003eprev_spi = prev-\u003erx.spi;\n+\tpas-\u003eprev_generation = prev-\u003egeneration;\n+\n+\tmemcpy(\u0026pas-\u003etx, \u0026prev-\u003etx, sizeof(pas-\u003etx));\n+\tmemcpy(pas-\u003edrv_data, prev-\u003edrv_data, pas-\u003epsd-\u003ecaps-\u003eassoc_drv_spc);\n+\tprev-\u003eflags |= PSP_ASSOC_SKIP_TX_KEY_DEL;\n+\n+\treturn 0;\n+}\n+\n int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,\n \t\t\t  struct psp_key_parsed *key,\n \t\t\t  struct netlink_ext_ack *extack)\n {\n+\tstruct psp_assoc *prev;\n \tint err;\n \n \tmemcpy(\u0026pas-\u003erx, key, sizeof(*key));\n@@ -165,10 +207,11 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,\n \t\tgoto exit_unlock;\n \t}\n \n-\tif (psp_sk_assoc(sk)) {\n-\t\tNL_SET_ERR_MSG(extack, \"Socket already has PSP state\");\n-\t\terr = -EBUSY;\n-\t\tgoto exit_unlock;\n+\tprev = psp_sk_assoc(sk);\n+\tif (prev) {\n+\t\terr = psp_sock_rx_rekey(pas, prev, extack);\n+\t\tif (err)\n+\t\t\tgoto exit_unlock;\n \t} else if (sk_has_decrypt_user(sk)) {\n \t\tNL_SET_ERR_MSG(extack, \"Socket has incompatible state\");\n \t\terr = -EINVAL;\n@@ -177,6 +220,7 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,\n \n \trefcount_inc(\u0026pas-\u003erefcnt);\n \trcu_assign_pointer(sk-\u003epsp_assoc, pas);\n+\tpsp_assoc_put(prev);\n \terr = 0;\n \n exit_unlock:\n@@ -249,6 +293,49 @@ psp_sock_set_tx_key(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,\n \treturn err;\n }\n \n+static int\n+psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,\n+\t\t  struct psp_key_parsed *key, struct netlink_ext_ack *extack)\n+{\n+\tstruct psp_assoc *new;\n+\tint err;\n+\n+\tif (!pas-\u003epeer_tx) {\n+\t\tNL_SET_ERR_MSG(extack, \"Socket PSP state is not fully established\");\n+\t\treturn -EBUSY;\n+\t}\n+\n+\tnew = kzalloc_flex(*new, drv_data, psd-\u003ecaps-\u003eassoc_drv_spc,\n+\t\t\t   GFP_KERNEL_ACCOUNT);\n+\tif (!new)\n+\t\treturn -ENOMEM;\n+\n+\tnew-\u003epsd             = pas-\u003epsd;\n+\tnew-\u003edev_id          = pas-\u003edev_id;\n+\tnew-\u003egeneration      = pas-\u003egeneration;\n+\tnew-\u003eversion         = pas-\u003eversion;\n+\tnew-\u003epeer_tx         = 1;\n+\tnew-\u003eprev_spi        = pas-\u003eprev_spi;\n+\tnew-\u003eprev_generation = pas-\u003eprev_generation;\n+\trefcount_set(\u0026new-\u003erefcnt, 1);\n+\tmemcpy(\u0026new-\u003erx, \u0026pas-\u003erx, sizeof(new-\u003erx));\n+\n+\terr = psp_assoc_set_tx(psd, new, key, extack);\n+\tif (err) {\n+\t\tkfree(new);\n+\t\treturn err;\n+\t}\n+\n+\tpsp_dev_get(new-\u003epsd);\n+\tlist_add(\u0026new-\u003eassocs_list, \u0026pas-\u003eassocs_list);\n+\n+\trcu_assign_pointer(sk-\u003epsp_assoc, new);\n+\tpas-\u003eflags |= PSP_ASSOC_DEFER_TX_KEY_DEL;\n+\tpsp_assoc_put(pas);\n+\n+\treturn 0;\n+}\n+\n int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,\n \t\t\t  u32 version, struct psp_key_parsed *key,\n \t\t\t  struct netlink_ext_ack *extack)\n@@ -281,13 +368,11 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,\n \t\terr = -EINVAL;\n \t\tgoto exit_unlock;\n \t}\n-\tif (pas-\u003etx.spi) {\n-\t\tNL_SET_ERR_MSG(extack, \"Tx key already set\");\n-\t\terr = -EBUSY;\n-\t\tgoto exit_unlock;\n-\t}\n+\tif (pas-\u003etx.spi)\n+\t\terr = psp_sock_tx_rekey(sk, psd, pas, key, extack);\n+\telse\n+\t\terr = psp_sock_set_tx_key(sk, psd, pas, key, extack);\n \n-\terr = psp_sock_set_tx_key(sk, psd, pas, key, extack);\n exit_unlock:\n \trelease_sock(sk);\n \treturn err;\n@@ -304,6 +389,10 @@ void psp_assocs_key_rotated(struct psp_dev *psd)\n \t\tpas-\u003egeneration |= ~PSP_GEN_VALID_MASK;\n \t\tpsd-\u003estats.stales++;\n \t}\n+\n+\tlist_for_each_entry(pas, \u0026psd-\u003eactive_assocs, assocs_list)\n+\t\tpas-\u003eprev_generation |= ~PSP_GEN_VALID_MASK;\n+\n \tlist_splice_init(\u0026psd-\u003eprev_assocs, \u0026psd-\u003estale_assocs);\n \tlist_splice_init(\u0026psd-\u003eactive_assocs, \u0026psd-\u003eprev_assocs);\n \ndiff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py\nindex 473500901879b..b22891b7f5ce8 100755\n--- a/tools/testing/selftests/drivers/net/psp.py\n+++ b/tools/testing/selftests/drivers/net/psp.py\n@@ -15,7 +15,7 @@ from contextlib import contextmanager\n \n from lib.py import defer\n from lib.py import ksft_run, ksft_exit, ksft_pr\n-from lib.py import ksft_true, ksft_eq, ksft_ne, ksft_gt, ksft_raises\n+from lib.py import ksft_true, ksft_eq, ksft_ne, ksft_ge, ksft_gt, ksft_raises\n from lib.py import ksft_not_none\n from lib.py import ksft_variants, KsftNamedVariant\n from lib.py import KsftSkipEx, KsftFailEx\n@@ -28,6 +28,12 @@ from lib.py import ip\n TCP_ULP = 31\n \n \n+_PSP_MAX_KEY_LEN = 32\n+_PSP_ASSOC_MSG = f'!IB3x{_PSP_MAX_KEY_LEN}s'\n+_TX_REKEY_ROUNDS = 20\n+_TX_KEY_DRAIN_TIMEOUT = 5\n+\n+\n def _get_outq(s):\n     one = b'\\0' * 4\n     outq = fcntl.ioctl(s.fileno(), termios.TIOCOUTQ, one)\n@@ -80,6 +86,36 @@ def _close_psp_conn(cfg, s):\n     _close_conn(cfg, s)\n \n \n+def _recv_all(s, target):\n+    data = b''\n+    while len(data) \u003c target:\n+        chunk = s.recv(target - len(data))\n+        if not chunk:\n+            raise KsftFailEx(f\"peer closed after {len(data)} of {target} bytes\")\n+        data += chunk\n+    return data\n+\n+\n+def _psp_key_len(version):\n+    return 16 if version in (0, 2) else 32\n+\n+\n+def _remote_rx_assoc(cfg):\n+    _send_with_ack(cfg, b'rx assoc\\0')\n+    msg = _recv_all(cfg.comm_sock, struct.calcsize(_PSP_ASSOC_MSG))\n+    spi, version, key = struct.unpack(_PSP_ASSOC_MSG, msg)\n+    return version, {'spi': spi, 'key': key[:_psp_key_len(version)]}\n+\n+\n+def _remote_tx_assoc(cfg, version, rx):\n+    msg = struct.pack(_PSP_ASSOC_MSG, rx['spi'], version, rx['key'])\n+    _send_with_ack(cfg, b'tx assoc\\0' + msg)\n+\n+\n+def _remote_key_rotate(cfg):\n+    _send_with_ack(cfg, b'key rotate\\0')\n+\n+\n def _spi_xchg(s, rx):\n     s.send(struct.pack('I', rx['spi']) + rx['key'])\n     tx = s.recv(4 + len(rx['key']))\n@@ -130,9 +166,57 @@ def _check_data_outq(s, exp_len, force_wait=False):\n     ksft_eq(outq, exp_len)\n \n \n+def _recv_careful(s, target, timeout=2):\n+    \"\"\"Read exactly target bytes, tolerating short reads\"\"\"\n+    data = b''\n+    end = time.monotonic() + timeout\n+    while time.monotonic() \u003c end:\n+        try:\n+            data += s.recv(target - len(data), socket.MSG_DONTWAIT)\n+            if len(data) == target:\n+                return data\n+        except BlockingIOError:\n+            time.sleep(0.001)\n+    raise KsftFailEx(f\"short read, got {len(data)} of {target} bytes\")\n+\n+\n+def _req_echo(cfg, s):\n+    \"\"\"Ask the peer to echo, and check the reply arrives intact\"\"\"\n+    _send_with_ack(cfg, b'data echo\\0')\n+    ksft_eq(_recv_careful(s, 5), b'echo\\0')\n+\n+\n+def _psp_txrx(cfg, s, rounds, sent=0):\n+    \"\"\"Send data both ways, and return the total bytes sent to the peer\"\"\"\n+    sent += _send_careful(cfg, s, rounds)\n+    _check_data_rx(cfg, sent)\n+    _req_echo(cfg, s)\n+    return sent\n+\n+\n+def _require_version(cfg, version):\n+    \"\"\"Skip the test unless the device supports the given PSP version\"\"\"\n+    name = cfg.pspnl.consts[\"version\"].entries_by_val[version].name\n+    if name not in cfg.psp_info['psp-versions-cap']:\n+        raise KsftSkipEx(\"PSP version not supported\", name)\n+\n+\n def _get_stat(cfg, key):\n     return cfg.pspnl.get_stats({'dev-id': cfg.psp_dev_id})[key]\n \n+\n+def _get_tx_key_count(cfg):\n+    return cfg.pspnl.get_stats({'dev-id': cfg.psp_dev_id}).get('tx-key-count')\n+\n+\n+def _wait_tx_key_drain(cfg, base):\n+    cnt = _get_tx_key_count(cfg)\n+    end = time.monotonic() + _TX_KEY_DRAIN_TIMEOUT\n+    while cnt \u003e base and time.monotonic() \u003c end:\n+        time.sleep(0.1)\n+        cnt = _get_tx_key_count(cfg)\n+    ksft_ge(base, cnt, comment=\"tx keys not removed from device after rekey\")\n+\n #\n # Test case boiler plate\n #\n@@ -447,10 +531,11 @@ def assoc_twice(cfg):\n             ksft_eq(len(tx), 0)\n \n \n-def _data_basic_send(cfg, version, ipver):\n-    \"\"\" Test basic data send \"\"\"\n-    _init_psp_dev(cfg)\n+def _establish_psp_conn(cfg, version, ipver=None):\n+    \"\"\"Establish a PSP connection and return after key exchange\n \n+    Requires _init_psp_dev() to have been called first.\n+    \"\"\"\n     # Version 0 is required by spec, don't let it skip\n     if version:\n         name = cfg.pspnl.consts[\"version\"].entries_by_val[version].name\n@@ -475,12 +560,238 @@ def _data_basic_send(cfg, version, ipver):\n                         \"version\": version,\n                         \"tx-key\": tx,\n                         \"sock-fd\": s.fileno()})\n+    return s\n \n+\n+def _data_basic_send(cfg, version, ipver):\n+    \"\"\" Test basic data send \"\"\"\n+    _init_psp_dev(cfg)\n+\n+    s = _establish_psp_conn(cfg, version, ipver)\n     data_len = _send_careful(cfg, s, 100)\n     _check_data_rx(cfg, data_len)\n     _close_psp_conn(cfg, s)\n \n \n+def _rekey_rx(cfg, s, version, sent):\n+    \"\"\"Rekey the Rx direction, running traffic after each step\"\"\"\n+    rx_assoc = cfg.pspnl.rx_assoc({\"version\": version,\n+                                   \"dev-id\": cfg.psp_dev_id,\n+                                   \"sock-fd\": s.fileno()})\n+    sent = _psp_txrx(cfg, s, 1, sent)\n+\n+    _remote_tx_assoc(cfg, version, rx_assoc['rx-key'])\n+    return _psp_txrx(cfg, s, 1, sent)\n+\n+\n+def _rekey_tx(cfg, s, sent):\n+    \"\"\"Rekey the Tx direction, running traffic after each step\"\"\"\n+    version, tx = _remote_rx_assoc(cfg)\n+    sent = _psp_txrx(cfg, s, 1, sent)\n+\n+    cfg.pspnl.tx_assoc({\"dev-id\": cfg.psp_dev_id,\n+                        \"version\": version,\n+                        \"tx-key\": tx,\n+                        \"sock-fd\": s.fileno()})\n+    return _psp_txrx(cfg, s, 1, sent)\n+\n+\n+def rekey_rx_incomplete(cfg):\n+    \"\"\"Test rejecting Rx rekey until the PSP connection is established\"\"\"\n+    psp_ver = 0\n+    _init_psp_dev(cfg)\n+\n+    with _make_lo_conn() as s:\n+        assoc = cfg.pspnl.rx_assoc({\"version\": psp_ver,\n+                                    \"dev-id\": cfg.psp_dev_id,\n+                                    \"sock-fd\": s.fileno()})\n+\n+        # Reject rekey before Tx state is configured.\n+        with ksft_raises(NlError) as cm:\n+            cfg.pspnl.rx_assoc({\"version\": psp_ver,\n+                                \"dev-id\": cfg.psp_dev_id,\n+                                \"sock-fd\": s.fileno()})\n+        ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY)\n+\n+        cfg.pspnl.tx_assoc({\"dev-id\": cfg.psp_dev_id,\n+                            \"version\": psp_ver,\n+                            \"tx-key\": assoc['rx-key'],\n+                            \"sock-fd\": s.fileno()})\n+\n+        # Reject rekey until authenticated PSP traffic has been received.\n+        with ksft_raises(NlError) as cm:\n+            cfg.pspnl.rx_assoc({\"version\": psp_ver,\n+                                \"dev-id\": cfg.psp_dev_id,\n+                                \"sock-fd\": s.fileno()})\n+        ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY)\n+\n+\n+def rekey_tx_incomplete(cfg):\n+    \"\"\"Test rejecting Tx rekey until the PSP connection is established\"\"\"\n+    psp_ver = 0\n+    _init_psp_dev(cfg)\n+\n+    with _make_lo_conn() as s:\n+        assoc = cfg.pspnl.rx_assoc({\"version\": psp_ver,\n+                                    \"dev-id\": cfg.psp_dev_id,\n+                                    \"sock-fd\": s.fileno()})\n+\n+        cfg.pspnl.tx_assoc({\"dev-id\": cfg.psp_dev_id,\n+                            \"version\": psp_ver,\n+                            \"tx-key\": assoc['rx-key'],\n+                            \"sock-fd\": s.fileno()})\n+\n+        # Reject rekey until authenticated PSP traffic has been received.\n+        with ksft_raises(NlError) as cm:\n+            cfg.pspnl.tx_assoc({\"dev-id\": cfg.psp_dev_id,\n+                                \"version\": psp_ver,\n+                                \"tx-key\": assoc['rx-key'],\n+                                \"sock-fd\": s.fileno()})\n+        ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY)\n+\n+\n+def rekey_rx_same_gen(cfg):\n+    \"\"\"Test rejecting an Rx rekey without an intervening key rotation\"\"\"\n+    _init_psp_dev(cfg)\n+\n+    s = _establish_psp_conn(cfg, 0)\n+    try:\n+        _psp_txrx(cfg, s, 1)\n+\n+        with ksft_raises(NlError) as cm:\n+            cfg.pspnl.rx_assoc({\"version\": 0,\n+                                \"dev-id\": cfg.psp_dev_id,\n+                                \"sock-fd\": s.fileno()})\n+        ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL)\n+\n+        cfg.pspnl.key_rotate({\"id\": cfg.psp_dev_id})\n+        cfg.pspnl.rx_assoc({\"version\": 0,\n+                            \"dev-id\": cfg.psp_dev_id,\n+                            \"sock-fd\": s.fileno()})\n+    finally:\n+        _close_psp_conn(cfg, s)\n+\n+\n+def rekey_rx_version_mismatch(cfg):\n+    \"\"\"Test rejecting an Rx rekey whose version does not match socket state\"\"\"\n+    _init_psp_dev(cfg)\n+    _require_version(cfg, 1)\n+\n+    s = _establish_psp_conn(cfg, 0)\n+    try:\n+        _psp_txrx(cfg, s, 1)\n+\n+        cfg.pspnl.key_rotate({\"id\": cfg.psp_dev_id})\n+\n+        with ksft_raises(NlError) as cm:\n+            cfg.pspnl.rx_assoc({\"dev-id\": cfg.psp_dev_id,\n+                                \"version\": 1,\n+                                \"sock-fd\": s.fileno()})\n+        ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL)\n+    finally:\n+        _close_psp_conn(cfg, s)\n+\n+\n+def rekey_tx_version_mismatch(cfg):\n+    \"\"\"Test rejecting a Tx rekey whose version does not match socket state\"\"\"\n+    _init_psp_dev(cfg)\n+    _require_version(cfg, 1)\n+\n+    s = _establish_psp_conn(cfg, 0)\n+    try:\n+        _psp_txrx(cfg, s, 1)\n+\n+        with ksft_raises(NlError) as cm:\n+            cfg.pspnl.tx_assoc({\"dev-id\": cfg.psp_dev_id,\n+                                \"version\": 1,\n+                                \"tx-key\": {'spi': 0x12345678,\n+                                           'key': b'\\xa5' * 32},\n+                                \"sock-fd\": s.fileno()})\n+        ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL)\n+    finally:\n+        _close_psp_conn(cfg, s)\n+\n+\n+def _get_psp_ver_variants():\n+    for ver in range(4):\n+        yield KsftNamedVariant(f\"v{ver}\", ver)\n+\n+\n+@ksft_variants(_get_psp_ver_variants())\n+def rekey_rx_basic(cfg, version):\n+    \"\"\"Test rekeying the Rx key of an established connection\"\"\"\n+    _init_psp_dev(cfg)\n+\n+    s = _establish_psp_conn(cfg, version)\n+    try:\n+        data_len = _psp_txrx(cfg, s, 10)\n+        cfg.pspnl.key_rotate({\"id\": cfg.psp_dev_id})\n+        _rekey_rx(cfg, s, version, data_len)\n+    finally:\n+        _close_psp_conn(cfg, s)\n+\n+\n+@ksft_variants(_get_psp_ver_variants())\n+def rekey_tx_basic(cfg, version):\n+    \"\"\"Test rekeying the Tx key of an established connection\"\"\"\n+    _init_psp_dev(cfg)\n+\n+    s = _establish_psp_conn(cfg, version)\n+    try:\n+        data_len = _psp_txrx(cfg, s, 10)\n+        _remote_key_rotate(cfg)\n+        _rekey_tx(cfg, s, data_len)\n+    finally:\n+        _close_psp_conn(cfg, s)\n+\n+\n+def rekey_tx_drain(cfg):\n+    \"\"\"Test that Tx rekeys do not leak keys on the device\"\"\"\n+    _init_psp_dev(cfg)\n+\n+    if _get_tx_key_count(cfg) is None:\n+        raise KsftSkipEx(\"Device does not track Tx keys\")\n+\n+    s = _establish_psp_conn(cfg, 0)\n+    try:\n+        data_len = _psp_txrx(cfg, s, 1)\n+        base = _get_tx_key_count(cfg)\n+\n+        for _ in range(_TX_REKEY_ROUNDS):\n+            _remote_key_rotate(cfg)\n+            data_len = _rekey_tx(cfg, s, data_len)\n+\n+        _wait_tx_key_drain(cfg, base)\n+    finally:\n+        _close_psp_conn(cfg, s)\n+\n+\n+@ksft_variants(_get_psp_ver_variants())\n+def rekey_both_sides(cfg, version):\n+    \"\"\"Test rekeying both directions\"\"\"\n+    _init_psp_dev(cfg)\n+\n+    s = _establish_psp_conn(cfg, version)\n+    try:\n+        data_len = _psp_txrx(cfg, s, 10)\n+\n+        cfg.pspnl.key_rotate({\"id\": cfg.psp_dev_id})\n+        _remote_key_rotate(cfg)\n+\n+        # first, rx then tx\n+        data_len = _rekey_rx(cfg, s, version, data_len)\n+        data_len = _rekey_tx(cfg, s, data_len)\n+\n+        cfg.pspnl.key_rotate({\"id\": cfg.psp_dev_id})\n+        _remote_key_rotate(cfg)\n+\n+        # now, tx then rx\n+        data_len = _rekey_tx(cfg, s, data_len)\n+        _rekey_rx(cfg, s, version, data_len)\n+    finally:\n+        _close_psp_conn(cfg, s)\n+\n+\n def __bad_xfer_do(cfg, s, tx, version='hdr0-aes-gcm-128'):\n     # Make sure we accept the ACK for the SPI before we seal with the bad assoc\n     _check_data_outq(s, 0)\n@@ -1173,7 +1484,8 @@ def main() -\u003e None:\n                                                           cfg.comm_port),\n                                                          timeout=1)\n \n-                cases = [data_basic_send, data_mss_adjust]\n+                cases = [data_basic_send, data_mss_adjust,\n+                         rekey_rx_basic, rekey_tx_basic, rekey_both_sides]\n \n                 if has_cont:\n                     cases += [\n@@ -1189,7 +1501,8 @@ def main() -\u003e None:\n                     ]\n \n                 ksft_run(cases=cases, globs=globals(),\n-                         case_pfx={\"dev_\", \"data_\", \"assoc_\", \"removal_\"},\n+                         case_pfx={\"dev_\", \"data_\", \"assoc_\", \"rekey_\",\n+                                   \"removal_\"},\n                          args=(cfg, ))\n \n                 cfg.comm_sock.send(b\"exit\\0\")\ndiff --git a/tools/testing/selftests/drivers/net/psp_responder.c b/tools/testing/selftests/drivers/net/psp_responder.c\nindex a26e7628bbb13..b3e0fe6d69750 100644\n--- a/tools/testing/selftests/drivers/net/psp_responder.c\n+++ b/tools/testing/selftests/drivers/net/psp_responder.c\n@@ -5,6 +5,7 @@\n #include \u003csys/poll.h\u003e\n #include \u003csys/socket.h\u003e\n #include \u003csys/time.h\u003e\n+#include \u003carpa/inet.h\u003e\n #include \u003cnetinet/in.h\u003e\n #include \u003cunistd.h\u003e\n \n@@ -23,6 +24,7 @@ static bool should_quit;\n struct opts {\n \tint port;\n \tint ifindex;\n+\tint devid;\n \tbool verbose;\n };\n \n@@ -37,20 +39,24 @@ static struct {\n \tunsigned char rx;\n } psp_vers;\n \n-static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)\n+static unsigned int psp_key_len(unsigned char version)\n {\n+\tswitch (version) {\n+\tcase PSP_VERSION_HDR0_AES_GCM_256:\n+\tcase PSP_VERSION_HDR0_AES_GMAC_256:\n+\t\treturn 32;\n+\tdefault:\n+\t\treturn 16;\n+\t}\n+}\n+\n+static int\n+rx_assoc(struct ynl_sock *ys, __u32 *spi, char *key, int data_sock)\n+{\n+\tunsigned int key_len = psp_key_len(psp_vers.rx);\n \tstruct psp_rx_assoc_rsp *rsp;\n \tstruct psp_rx_assoc_req *req;\n-\tstruct psp_tx_assoc_rsp *tsp;\n-\tstruct psp_tx_assoc_req *teq;\n-\tchar info[300];\n-\tint key_len;\n-\tssize_t sz;\n-\t__u32 spi;\n \n-\tdbg(\"create PSP connection\\n\");\n-\n-\t// Rx assoc alloc\n \treq = psp_rx_assoc_req_alloc();\n \n \tpsp_rx_assoc_req_set_sock_fd(req, data_sock);\n@@ -64,29 +70,34 @@ static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)\n \t\treturn -1;\n \t}\n \n-\t// SPI exchange\n-\tkey_len = rsp-\u003erx_key._len.key;\n-\tmemcpy(info, \u0026rsp-\u003erx_key.spi, sizeof(spi));\n-\tmemcpy(\u0026info[sizeof(spi)], rsp-\u003erx_key.key, key_len);\n-\tsz = sizeof(spi) + key_len;\n+\tif (rsp-\u003erx_key._len.key != key_len) {\n+\t\tfprintf(stderr, \"ERROR: unexpected Rx key length %u\\n\",\n+\t\t\trsp-\u003erx_key._len.key);\n+\t\tpsp_rx_assoc_rsp_free(rsp);\n+\t\treturn -1;\n+\t}\n+\n+\tmemcpy(spi, \u0026rsp-\u003erx_key.spi, sizeof(*spi));\n+\tmemcpy(key, rsp-\u003erx_key.key, key_len);\n \n-\tsend(data_sock, info, sz, MSG_WAITALL);\n \tpsp_rx_assoc_rsp_free(rsp);\n \n-\tsz = recv(data_sock, info, sz, MSG_WAITALL);\n-\tif (sz \u003c 0) {\n-\t\tperror(\"ERROR: failed to read PSP key from sock\");\n-\t\treturn -1;\n-\t}\n-\tmemcpy(\u0026spi, info, sizeof(spi));\n+\treturn 0;\n+}\n+\n+static int\n+tx_assoc(struct ynl_sock *ys, __u8 version, __u32 spi, char *key,\n+\t int data_sock)\n+{\n+\tstruct psp_tx_assoc_rsp *tsp;\n+\tstruct psp_tx_assoc_req *teq;\n \n-\t// Setup Tx assoc\n \tteq = psp_tx_assoc_req_alloc();\n \n \tpsp_tx_assoc_req_set_sock_fd(teq, data_sock);\n-\tpsp_tx_assoc_req_set_version(teq, psp_vers.tx);\n+\tpsp_tx_assoc_req_set_version(teq, version);\n \tpsp_tx_assoc_req_set_tx_key_spi(teq, spi);\n-\tpsp_tx_assoc_req_set_tx_key_key(teq, \u0026info[sizeof(spi)], key_len);\n+\tpsp_tx_assoc_req_set_tx_key_key(teq, key, psp_key_len(version));\n \n \ttsp = psp_tx_assoc(ys, teq);\n \tpsp_tx_assoc_req_free(teq);\n@@ -99,6 +110,34 @@ static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)\n \treturn 0;\n }\n \n+static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)\n+{\n+\tunsigned int key_len = psp_key_len(psp_vers.rx);\n+\tchar info[300];\n+\tssize_t sz;\n+\t__u32 spi;\n+\n+\tdbg(\"create PSP connection\\n\");\n+\n+\tif (rx_assoc(ys, \u0026spi, \u0026info[sizeof(spi)], data_sock))\n+\t\treturn -1;\n+\n+\t// SPI exchange\n+\tmemcpy(info, \u0026spi, sizeof(spi));\n+\tsz = sizeof(spi) + key_len;\n+\n+\tsend(data_sock, info, sz, MSG_WAITALL);\n+\n+\tsz = recv(data_sock, info, sz, MSG_WAITALL);\n+\tif (sz \u003c 0) {\n+\t\tperror(\"ERROR: failed to read PSP key from sock\");\n+\t\treturn -1;\n+\t}\n+\tmemcpy(\u0026spi, info, sizeof(spi));\n+\n+\treturn tx_assoc(ys, psp_vers.tx, spi, \u0026info[sizeof(spi)], data_sock);\n+}\n+\n static void send_ack(int sock)\n {\n \tsend(sock, \"ack\", 4, MSG_WAITALL);\n@@ -118,6 +157,100 @@ static void send_str(int sock, int value)\n \tsend(sock, buf, ret + 1, MSG_WAITALL);\n }\n \n+#define PSP_MAX_KEY_LEN\t\t32\n+\n+struct assoc_msg {\n+\t__be32 spi;\n+\t__u8 version;\n+\t__u8 pad[3];\n+\tchar key[PSP_MAX_KEY_LEN];\n+};\n+\n+static void\n+handle_rx_assoc(struct ynl_sock *ys, int data_sock, int comm_sock)\n+{\n+\tstruct assoc_msg msg = {};\n+\t__u32 spi;\n+\n+\tif (data_sock \u003c 0) {\n+\t\tfprintf(stderr, \"WARN: rx assoc but no data sock\\n\");\n+\t\tsend_err(comm_sock);\n+\t\treturn;\n+\t}\n+\n+\tif (rx_assoc(ys, \u0026spi, msg.key, data_sock)) {\n+\t\tfprintf(stderr, \"ERROR: rx_assoc() failed\\n\");\n+\t\tsend_err(comm_sock);\n+\t\treturn;\n+\t}\n+\n+\tmsg.spi = htonl(spi);\n+\tmsg.version = psp_vers.rx;\n+\tsend_ack(comm_sock);\n+\tsend(comm_sock, \u0026msg, sizeof(msg), MSG_WAITALL);\n+}\n+\n+static void\n+handle_tx_assoc(struct ynl_sock *ys, char *data, int data_sock, int comm_sock)\n+{\n+\tstruct assoc_msg msg;\n+\n+\tif (data_sock \u003c 0) {\n+\t\tfprintf(stderr, \"WARN: tx assoc but no data sock\\n\");\n+\t\tsend_err(comm_sock);\n+\t\treturn;\n+\t}\n+\n+\tmemcpy(\u0026msg, data, sizeof(msg));\n+\tif (tx_assoc(ys, msg.version, ntohl(msg.spi), msg.key, data_sock)) {\n+\t\tfprintf(stderr, \"ERROR: tx_assoc() failed!\\n\");\n+\t\tsend_err(comm_sock);\n+\t\treturn;\n+\t}\n+\n+\tsend_ack(comm_sock);\n+}\n+\n+static int rotate_key(struct ynl_sock *ys, int devid)\n+{\n+\tstruct psp_key_rotate_rsp *rsp;\n+\tstruct psp_key_rotate_req *req;\n+\n+\treq = psp_key_rotate_req_alloc();\n+\n+\tpsp_key_rotate_req_set_id(req, devid);\n+\n+\trsp = psp_key_rotate(ys, req);\n+\tpsp_key_rotate_req_free(req);\n+\n+\tif (!rsp) {\n+\t\tperror(\"ERROR: failed to rotate key\");\n+\t\treturn -1;\n+\t}\n+\n+\tpsp_key_rotate_rsp_free(rsp);\n+\n+\treturn 0;\n+}\n+\n+static void\n+handle_key_rotate(struct ynl_sock *ys, struct opts *opts, int comm_sock)\n+{\n+\tif (opts-\u003edevid \u003c 0) {\n+\t\tfprintf(stderr, \"WARN: key rotate but no PSP device\\n\");\n+\t\tsend_err(comm_sock);\n+\t\treturn;\n+\t}\n+\n+\tif (rotate_key(ys, opts-\u003edevid)) {\n+\t\tfprintf(stderr, \"ERROR: rotate_key() failed\\n\");\n+\t\tsend_err(comm_sock);\n+\t\treturn;\n+\t}\n+\n+\tsend_ack(comm_sock);\n+}\n+\n static void\n run_session(struct ynl_sock *ys, struct opts *opts,\n \t    int server_sock, int comm_sock)\n@@ -210,6 +343,9 @@ run_session(struct ynl_sock *ys, struct opts *opts,\n \t\t\tmatch;\t\t\t\t\t\t\\\n \t\t})\n \n+#define cmd_w_msg(_name, _type)\t\t\t\t\t\t\\\n+\t\t(off \u003e= sizeof(_name) + sizeof(_type) \u0026\u0026 cmd(_name))\n+\n \t\t\tdo {\n \t\t\t\tconsumed = false;\n \n@@ -224,6 +360,16 @@ run_session(struct ynl_sock *ys, struct opts *opts,\n \t\t\t\t\t\tfprintf(stderr, \"WARN: echo but no data sock\\n\");\n \t\t\t\t\tsend_ack(comm_sock);\n \t\t\t\t}\n+\t\t\t\tif (cmd(\"rx assoc\"))\n+\t\t\t\t\thandle_rx_assoc(ys, data_sock,\n+\t\t\t\t\t\t\tcomm_sock);\n+\t\t\t\tif (cmd_w_msg(\"tx assoc\", struct assoc_msg)) {\n+\t\t\t\t\thandle_tx_assoc(ys, buf, data_sock,\n+\t\t\t\t\t\t\tcomm_sock);\n+\t\t\t\t\t__consume(sizeof(struct assoc_msg));\n+\t\t\t\t}\n+\t\t\t\tif (cmd(\"key rotate\"))\n+\t\t\t\t\thandle_key_rotate(ys, opts, comm_sock);\n \t\t\t\tif (cmd(\"data close\")) {\n \t\t\t\t\tif (data_sock \u003e= 0) {\n \t\t\t\t\t\tclose(data_sock);\n@@ -254,6 +400,7 @@ run_session(struct ynl_sock *ys, struct opts *opts,\n \t\t\t\t}\n \t\t\t\tif (cmd(\"exit\"))\n \t\t\t\t\tshould_quit = true;\n+#undef cmd_w_msg\n #undef cmd\n \n \t\t\t\tif (!consumed) {\n@@ -449,6 +596,7 @@ int main(int argc, char **argv)\n \t\t}\n \t}\n \tpsp_dev_get_list_free(dev_list);\n+\topts.devid = devid;\n \n \tif (opts.ifindex \u0026\u0026 devid \u003c 0)\n \t\tfprintf(stderr,\n"
}

2/1 2026/10/09 23:06 agent patch-evaluator
4m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "INET_PSP",
    "NETDEVSIM",
    "BQL"
  ],
  "FocusSymbols": [
    "psp_sock_assoc_set_rx",
    "psp_sock_assoc_set_tx",
    "psp_sock_rx_rekey",
    "psp_sock_tx_rekey",
    "psp_assocs_key_rotated",
    "psp_dev_tx_key_del",
    "psp_deferred_del_queue",
    "psp_deferred_del_work",
    "psp_tx_grace_done"
  ],
  "Reasoning": "The patch adds connection in-place rekeying support and deferred Tx key deletion using BQL accounting to the PSP (PSP Security Protocol) subsystem in net/psp/. It modifies association lifecycle management, reference counts, socket association assignment, packet acceptance checks, and introduces new WARN and WARN_ON_ONCE checks. The code is reachable in standard virtualized environments via simulated networking devices (netdevsim), generic netlink, and standard TCP sockets.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 9ecf5c48c0d9147c72e7843af57f7e4710b29694
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Oct 9 23:06:29 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml
index f3266763c3253..d14c11d098914 100644
--- a/Documentation/netlink/specs/psp.yaml
+++ b/Documentation/netlink/specs/psp.yaml
@@ -190,6 +190,13 @@ attribute-sets:
         doc: |
           Number of PSP packets for transmission with errors.
           Device statistic (from the PSP spec).
+      -
+        name: tx-key-count
+        type: uint
+        doc: |
+          Current number of Tx keys installed on the device.
+          Only visible if the driver stores keys on device.
+          Kernel statistic.
 
 operations:
   list:
@@ -316,6 +323,7 @@ operations:
             - tx-packets
             - tx-bytes
             - tx-error
+            - tx-key-count
         pre: psp-device-get-locked
         post: psp-device-unlock
       dump:
diff --git a/Documentation/networking/psp.rst b/Documentation/networking/psp.rst
index 0f9b6b73f2447..769c7b21045ce 100644
--- a/Documentation/networking/psp.rst
+++ b/Documentation/networking/psp.rst
@@ -140,14 +140,36 @@ The PSP assoc state of a socket is not reset when the connection is
 torn down. ``connect()`` on a socket that has PSP assoc state will
 return ``-EINVAL``.
 
+Rekeying
+--------
+
+A connection which has completed the exchange described above and is
+in the "PSP Full" state can be rekeyed in place without being torn
+down. The Tx and Rx directions are rekeyed separately using the same
+netlink calls as in connection setup.
+
+``rx-assoc`` allocates a new Rx key and SPI, which should be passed
+to the peer exactly as during the initial exchange. The SPI which was
+in use before the rekey remains acceptable on the socket until the
+next Rx rekey, so packets the peer sent before it learned the new SPI
+are still received.
+
+``tx-assoc`` installs a new Tx key, which takes effect immediately.
+The peer will accept data encrypted from the old and new SPI.
+
+A rekey is rejected with ``-EINVAL`` if it would change the PSP device
+or the PSP version of the association. It is rejected with ``-EBUSY``
+if the socket has not completed its initial exchange in both
+directions.
+
 Rotation notifications
 ----------------------
 
 The rotations of device key happen asynchronously and are usually
 performed by management daemons, not under application control.
 The PSP netlink family will generate a notification whenever keys
-are rotated. The applications are expected to re-establish connections
-before keys are rotated again.
+are rotated. Applications are expected to rekey their connections,
+as described above, before device keys are rotated again.
 
 Kernel implementation
 =====================
@@ -180,6 +202,44 @@ Drivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload
 was requested for given skb. On Rx drivers should allocate and populate
 the ``SKB_EXT_PSP`` skb extension, and set the skb->decrypted bit to 1.
 
+Deferred Tx key deletion
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Drivers which implement ``tx_key_add`` and ``tx_key_del`` may hold key
+references in their Tx rings, so PSP core waits until descriptors
+containing these references are completed before removing the key from
+the underlying device. PSP core uses accounting based on Byte Queue Limits
+(BQL) to wait for a suitable grace period before asking the driver to
+remove the key.
+
+Drivers which implement the Tx key callbacks must meet the following
+requirements:
+
+* The driver must be "ops locked"
+  (see Documentation/networking/netdevices.rst).
+* A PSP skb accepted by ``ndo_start_xmit()`` must remain socket-owned until
+  every Tx descriptor referencing its PSP key has been completed or otherwise
+  made incapable of using the key. The driver must not orphan the skb before
+  that point. Otherwise, the socket destructor may free the Tx key while key
+  references remain in the Tx ring.
+* Every PSP packet accepted by ``ndo_start_xmit()`` must be included in BQL
+  queued bytecount before the function returns.
+* Completion bytecounts must exactly match enqueue bytecounts and preserve
+  queue order. A later packet must not be reported as completed while an earlier
+  packet can still reference its key.
+* Before calling ``dql_reset()`` on a queue, the driver must ensure that all
+  outstanding descriptors containing key references have been completed or
+  discarded. If called under the netdev instance lock, then descriptors can
+  remain outstanding after the reset as long as they are completed or
+  discarded before the instance lock is released.
+* When decreasing ``real_num_tx_queues``, the driver must ensure that every
+  outstanding descriptor on the queues at or above the new Tx queue count
+  has been completed or otherwise made incapable of using its PSP key
+  before the netdev instance lock is released.
+* The BQL state of a queue below ``real_num_tx_queues`` must reflect all
+  bytes completed or be reset after the queue has been quiesced. Failure to
+  do so will stall the grace period algorithm.
+
 Kernel implementation notes
 ---------------------------
 
diff --git a/include/net/psp/functions.h b/include/net/psp/functions.h
index b23c30898389c..fb80e15e43681 100644
--- a/include/net/psp/functions.h
+++ b/include/net/psp/functions.h
@@ -77,10 +77,12 @@ psp_is_allowed_nondata(struct sk_buff *skb, struct psp_assoc *pas)
 static inline bool
 psp_pse_matches_pas(struct psp_skb_ext *pse, struct psp_assoc *pas)
 {
-	return pse && pas->rx.spi == pse->spi &&
-	       pas->generation == pse->generation &&
-	       pas->version == pse->version &&
-	       pas->dev_id == pse->dev_id;
+	return pse && pas->version == pse->version &&
+	       pas->dev_id == pse->dev_id &&
+	       ((pas->rx.spi == pse->spi &&
+		 pas->generation == pse->generation) ||
+		(pas->prev_spi && pas->prev_spi == pse->spi &&
+		 pas->prev_generation == pse->generation));
 }
 
 static inline enum skb_drop_reason
diff --git a/include/net/psp/types.h b/include/net/psp/types.h
index b8905efbd604e..970801cb65026 100644
--- a/include/net/psp/types.h
+++ b/include/net/psp/types.h
@@ -3,8 +3,10 @@
 #ifndef __NET_PSP_H
 #define __NET_PSP_H
 
+#include <linux/bits.h>
 #include <linux/mutex.h>
 #include <linux/refcount.h>
+#include <linux/workqueue.h>
 #include <net/net_trackers.h>
 
 struct netlink_ext_ack;
@@ -79,10 +81,16 @@ struct psp_assoc_dev {
  * @prev_assocs:	associations which use old (but still usable)
  *			device key
  * @stale_assocs:	associations which use a rotated out key
+ * @tx_del:		deferred TX key deletion state
+ * @tx_del.active:	TX keys to be deleted after the current grace period
+ * @tx_del.next:	TX keys queued for deletion during current grace period
+ * @tx_del.work:	delayed work item for periodic grace period checking
+ * @tx_del.txq_state:	TX queue state for deferred deletion grace periods
  *
  * @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-count
  *
  * @rcu:	RCU head for freeing the structure
  */
@@ -108,9 +116,17 @@ struct psp_dev {
 	struct list_head prev_assocs;
 	struct list_head stale_assocs;
 
+	struct {
+		struct list_head active;
+		struct list_head next;
+		struct delayed_work work;
+		struct psp_txq_state *txq_state;
+	} tx_del;
+
 	struct {
 		unsigned long rotations;
 		unsigned long stales;
+		unsigned long tx_key_cnt;
 	} stats;
 
 	struct rcu_head rcu;
@@ -152,6 +168,20 @@ struct psp_key_parsed {
 	u8 key[PSP_MAX_KEY];
 };
 
+/**
+ * enum psp_assoc_flags - flags of struct psp_assoc
+ * @PSP_ASSOC_SKIP_TX_KEY_DEL: Do not delete Tx key from psp_dev. It was
+ *	copied to a newer psp_assoc during an Rx rekey.
+ * @PSP_ASSOC_DEFER_TX_KEY_DEL: Send Tx key to psp_dev's deferred deletion
+ *	queue. This psp_assoc was detached from its socket during a Tx rekey
+ *	and requires device descriptor state referencing this key to be
+ *	drained.
+ */
+enum psp_assoc_flags {
+	PSP_ASSOC_SKIP_TX_KEY_DEL	= BIT(0),
+	PSP_ASSOC_DEFER_TX_KEY_DEL	= BIT(1),
+};
+
 struct psp_assoc {
 	struct psp_dev *psd;
 
@@ -159,6 +189,10 @@ struct psp_assoc {
 	u8 generation;
 	u8 version;
 	u8 peer_tx;
+	u8 prev_generation;
+	u8 flags; /* Slow path, protected by psd->lock */
+
+	__be32 prev_spi;
 
 	u32 upgrade_seq;
 
diff --git a/include/uapi/linux/psp.h b/include/uapi/linux/psp.h
index 1c8899cd4da5e..21810e8a72299 100644
--- a/include/uapi/linux/psp.h
+++ b/include/uapi/linux/psp.h
@@ -69,6 +69,7 @@ enum {
 	PSP_A_STATS_TX_PACKETS,
 	PSP_A_STATS_TX_BYTES,
 	PSP_A_STATS_TX_ERROR,
+	PSP_A_STATS_TX_KEY_COUNT,
 
 	__PSP_A_STATS_MAX,
 	PSP_A_STATS_MAX = (__PSP_A_STATS_MAX - 1)
diff --git a/net/psp/Kconfig b/net/psp/Kconfig
index 84d6b0f254606..36c12493784fd 100644
--- a/net/psp/Kconfig
+++ b/net/psp/Kconfig
@@ -5,6 +5,7 @@
 config INET_PSP
 	bool "PSP Security Protocol support"
 	depends on INET
+	depends on BQL
 	select SKB_DECRYPTED
 	select SKB_EXTENSIONS
 	select SOCK_VALIDATE_XMIT
diff --git a/net/psp/Makefile b/net/psp/Makefile
index eb5ff3c5bfb2a..40decd8fe0500 100644
--- a/net/psp/Makefile
+++ b/net/psp/Makefile
@@ -2,4 +2,4 @@
 
 obj-$(CONFIG_INET_PSP) += psp.o
 
-psp-y := psp_main.o psp_nl.o psp_sock.o psp-nl-gen.o
+psp-y := psp_main.o psp_nl.o psp_sock.o psp_deferred_del.o psp-nl-gen.o
diff --git a/net/psp/psp.h b/net/psp/psp.h
index b123c24279050..0cfc82c6c7110 100644
--- a/net/psp/psp.h
+++ b/net/psp/psp.h
@@ -18,6 +18,11 @@ int psp_dev_check_access(struct psp_dev *psd, struct net *net, bool admin);
 bool psp_has_assoc_dev_in_ns(struct psp_dev *psd, struct net *net);
 int psp_attach_netdev_notifier(void);
 
+int psp_deferred_del_init(struct psp_dev *psd);
+void psp_deferred_del_stop(struct psp_dev *psd);
+void psp_deferred_del_uninit(struct psp_dev *psd, bool unpublished);
+void psp_deferred_del_queue(struct psp_dev *psd, struct psp_assoc *pas);
+
 void psp_nl_notify_dev(struct psp_dev *psd, u32 cmd);
 void psp_nl_notify_disassoc(struct psp_dev *psd, struct net *net);
 
@@ -63,7 +68,8 @@ static inline bool psp_dev_has_sadb(struct psp_dev *psd)
 static inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas)
 {
 	lockdep_assert_held(&pas->psd->lock);
-	return psp_dev_has_sadb(pas->psd) && pas->tx.spi;
+	return psp_dev_has_sadb(pas->psd) && pas->tx.spi &&
+	       !(pas->flags & PSP_ASSOC_SKIP_TX_KEY_DEL);
 }
 
 #endif /* __PSP_PSP_H */
diff --git a/net/psp/psp_deferred_del.c b/net/psp/psp_deferred_del.c
new file mode 100644
index 0000000000000..cfbac72577e96
--- /dev/null
+++ b/net/psp/psp_deferred_del.c
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/bitmap.h>
+#include <linux/jiffies.h>
+#include <linux/list.h>
+#include <linux/netdevice.h>
+#include <linux/slab.h>
+#include <net/netdev_lock.h>
+#include <net/psp.h>
+
+#include "psp.h"
+
+#define PSP_TX_GRACE_POLL_MS	1000
+
+struct psp_txq_state {
+	unsigned int num_tx_queues;
+	unsigned long *drained_queues;
+	unsigned int to_complete[];
+};
+
+static void psp_txq_state_free(struct psp_txq_state *state)
+{
+	if (!state)
+		return;
+
+	bitmap_free(state->drained_queues);
+	kvfree(state);
+}
+
+static struct psp_txq_state *
+psp_txq_state_alloc(unsigned int max_tx_queues)
+{
+	struct psp_txq_state *state;
+
+	state = kvzalloc_flex(*state, to_complete, max_tx_queues);
+	if (!state)
+		return NULL;
+
+	state->drained_queues = bitmap_zalloc(max_tx_queues, GFP_KERNEL);
+	if (!state->drained_queues) {
+		psp_txq_state_free(state);
+		return NULL;
+	}
+
+	return state;
+}
+
+static void psp_tx_grace_start(struct psp_dev *psd)
+{
+	struct psp_txq_state *state = psd->tx_del.txq_state;
+	struct net_device *dev = psd->main_netdev;
+	unsigned int i;
+
+	netdev_assert_locked(dev);
+
+	/* Any instances of ndo_start_xmit() that observed these keys through
+	 * psp_skb_get_assoc_rcu() must already be accounted in BQL's queued
+	 * byte count. ndo_start_xmit() runs with BHs disabled, which forms an
+	 * implicit RCU read-side critical section, and we are now at least one
+	 * grace period after any of these psp_assocs have been cleared from
+	 * sk->psp_assoc.
+	 */
+	state->num_tx_queues = dev->real_num_tx_queues;
+	bitmap_zero(state->drained_queues, state->num_tx_queues);
+	for (i = 0; i < state->num_tx_queues; i++) {
+		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
+
+		state->to_complete[i] = READ_ONCE(txq->dql.num_queued);
+	}
+}
+
+static bool psp_tx_grace_done(struct psp_dev *psd)
+{
+	struct psp_txq_state *state = psd->tx_del.txq_state;
+	struct net_device *dev = psd->main_netdev;
+	bool all_completed = true;
+	unsigned int i;
+
+	netdev_assert_locked(dev);
+
+	if (dev->real_num_tx_queues < state->num_tx_queues)
+		state->num_tx_queues = dev->real_num_tx_queues;
+
+	for (i = 0; i < state->num_tx_queues; i++) {
+		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
+		unsigned int completed;
+		unsigned int queued;
+
+		if (test_bit(i, state->drained_queues))
+			continue;
+
+		/* Drivers must meet the requirements documented in
+		 * Documentation/networking/psp.rst to guarantee forward
+		 * progress and avoid ending the grace period prematurely.
+		 *
+		 * We snapshotted num_queued in psp_tx_grace_start() and need
+		 * to determine whether num_completed has since reached or
+		 * passed that mark. For a given queue, we can consider first
+		 * whether or not dql_reset() was called at any point between
+		 * when we read num_queued until we read num_completed and
+		 * num_queued here and then separate the space of possible
+		 * states based on that.
+		 *
+		 * Not reset: num_queued and num_completed only increase, and
+		 * dql keeps num_queued - num_completed <= INT_MAX at all
+		 * times. We can form three exhaustive sub cases:
+		 *
+		 * (int)(to_complete - completed) <= 0: completion reached or
+		 * passed the mark. At the time to_complete was read,
+		 * completed was in [to_complete - INT_MAX, to_complete].
+		 *
+		 * (int)(to_complete - queued) > 0: to_complete and queued are
+		 * both snapshots of num_queued, so queued has advanced more
+		 * than INT_MAX + 1 past to_complete. num_completed lags
+		 * queued by at most INT_MAX, so num_completed must have
+		 * crossed to_complete.
+		 *
+		 * Otherwise the mark may still be in flight, so poll again.
+		 *
+		 * Reset: By the driver conditions laid out in
+		 * Documentation/networking/psp.rst, if a dql_reset()
+		 * occurred, and we are holding the instance lock, then we
+		 * know the actual state of the queue is drained. The check
+		 * below is then conservative because there is no risk of
+		 * falsely declaring the queue drained. As long as dql makes
+		 * forward progress the check should eventually report
+		 * drained.
+		 */
+		completed = READ_ONCE(txq->dql.num_completed);
+		queued = READ_ONCE(txq->dql.num_queued);
+
+		if ((int)(state->to_complete[i] - completed) <= 0 ||
+		    (int)(state->to_complete[i] - queued) > 0)
+			__set_bit(i, state->drained_queues);
+		else
+			all_completed = false;
+	}
+
+	return all_completed;
+}
+
+static bool psp_tx_grace_active(struct psp_dev *psd)
+{
+	return !list_empty(&psd->tx_del.active);
+}
+
+static void psp_deferred_del_work(struct work_struct *work)
+{
+	struct delayed_work *dwork = to_delayed_work(work);
+	struct psp_assoc *pas, *tmp;
+	bool need_reschedule;
+	struct psp_dev *psd;
+	LIST_HEAD(to_free);
+
+	psd = container_of(dwork, struct psp_dev, tx_del.work);
+
+	mutex_lock(&psd->lock);
+	netdev_lock(psd->main_netdev);
+
+	if (psp_tx_grace_active(psd) && psp_tx_grace_done(psd))
+		list_splice_init(&psd->tx_del.active, &to_free);
+
+	if (!psp_tx_grace_active(psd) && !list_empty(&psd->tx_del.next)) {
+		psp_tx_grace_start(psd);
+		list_splice_init(&psd->tx_del.next, &psd->tx_del.active);
+	}
+
+	netdev_unlock(psd->main_netdev);
+
+	list_for_each_entry(pas, &to_free, assocs_list)
+		psp_dev_tx_key_del(psd, pas);
+
+	need_reschedule = psp_tx_grace_active(psd);
+	mutex_unlock(&psd->lock);
+
+	if (need_reschedule)
+		mod_delayed_work(system_percpu_wq, &psd->tx_del.work,
+				 msecs_to_jiffies(PSP_TX_GRACE_POLL_MS));
+
+	list_for_each_entry_safe(pas, tmp, &to_free, assocs_list) {
+		list_del(&pas->assocs_list);
+		psp_dev_put(psd);
+		kfree(pas);
+	}
+}
+
+int psp_deferred_del_init(struct psp_dev *psd)
+{
+	INIT_LIST_HEAD(&psd->tx_del.active);
+	INIT_LIST_HEAD(&psd->tx_del.next);
+	INIT_DELAYED_WORK(&psd->tx_del.work, psp_deferred_del_work);
+
+	if (!psd->ops->tx_key_del)
+		return 0;
+
+	psd->tx_del.txq_state =
+		psp_txq_state_alloc(psd->main_netdev->num_tx_queues);
+
+	return psd->tx_del.txq_state ? 0 : -ENOMEM;
+}
+
+void psp_deferred_del_stop(struct psp_dev *psd)
+{
+	disable_delayed_work_sync(&psd->tx_del.work);
+}
+
+void psp_deferred_del_uninit(struct psp_dev *psd, bool unpublished)
+{
+	struct psp_assoc *pas, *next;
+
+	lockdep_assert(unpublished || lockdep_is_held(&psd->lock));
+
+	psp_txq_state_free(psd->tx_del.txq_state);
+	psd->tx_del.txq_state = NULL;
+
+	list_splice_init(&psd->tx_del.active, &psd->tx_del.next);
+	list_for_each_entry_safe(pas, next, &psd->tx_del.next, assocs_list) {
+		list_del(&pas->assocs_list);
+		psp_dev_tx_key_del(psd, pas);
+		psp_dev_put(psd);
+		kfree(pas);
+	}
+}
+
+void psp_deferred_del_queue(struct psp_dev *psd, struct psp_assoc *pas)
+{
+	lockdep_assert_held(&psd->lock);
+
+	list_move_tail(&pas->assocs_list, &psd->tx_del.next);
+	schedule_delayed_work(&psd->tx_del.work, 0);
+}
diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
index 273b010d2355c..9f256157d88bf 100644
--- a/net/psp/psp_main.c
+++ b/net/psp/psp_main.c
@@ -3,8 +3,10 @@
 #include <linux/bitfield.h>
 #include <linux/list.h>
 #include <linux/netdevice.h>
+#include <linux/slab.h>
 #include <linux/xarray.h>
 #include <net/net_namespace.h>
+#include <net/netdev_lock.h>
 #include <net/psp.h>
 #include <net/udp.h>
 
@@ -70,7 +72,8 @@ psp_dev_create(struct net_device *netdev,
 		    !psd_ops->rx_spi_alloc ||
 		    !psd_ops->get_stats ||
 		    (!psd_ops->tx_key_add != !psd_ops->tx_key_del) ||
-		    (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add)))
+		    (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add) ||
+		    (psd_ops->tx_key_add && !netdev_need_ops_lock(netdev))))
 		return ERR_PTR(-EINVAL);
 
 	psd = kzalloc_obj(*psd);
@@ -89,13 +92,16 @@ psp_dev_create(struct net_device *netdev,
 	INIT_LIST_HEAD(&psd->stale_assocs);
 	refcount_set(&psd->refcnt, 1);
 
+	err = psp_deferred_del_init(psd);
+	if (err)
+		goto err_free_psd;
+
 	mutex_lock(&psp_devs_lock);
 	err = xa_alloc_cyclic(&psp_devs, &psd->id, psd, xa_limit_16b,
 			      &last_id, GFP_KERNEL);
 	if (err) {
 		mutex_unlock(&psp_devs_lock);
-		kfree(psd);
-		return ERR_PTR(err);
+		goto err_uninit_deferred_del;
 	}
 	mutex_lock(&psd->lock);
 	mutex_unlock(&psp_devs_lock);
@@ -111,6 +117,12 @@ psp_dev_create(struct net_device *netdev,
 	mutex_unlock(&psd->lock);
 
 	return psd;
+
+err_uninit_deferred_del:
+	psp_deferred_del_uninit(psd, true);
+err_free_psd:
+	kfree(psd);
+	return ERR_PTR(err);
 }
 EXPORT_SYMBOL(psp_dev_create);
 
@@ -133,6 +145,8 @@ void psp_dev_unregister(struct psp_dev *psd)
 	struct psp_assoc_dev *entry, *entry_tmp;
 	struct psp_assoc *pas, *next;
 
+	psp_deferred_del_stop(psd);
+
 	mutex_lock(&psp_devs_lock);
 	mutex_lock(&psd->lock);
 
@@ -145,6 +159,8 @@ void psp_dev_unregister(struct psp_dev *psd)
 	xa_store(&psp_devs, psd->id, NULL, GFP_KERNEL);
 	mutex_unlock(&psp_devs_lock);
 
+	psp_deferred_del_uninit(psd, false);
+
 	list_splice_init(&psd->active_assocs, &psd->prev_assocs);
 	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
 	list_for_each_entry_safe(pas, next, &psd->stale_assocs, assocs_list) {
@@ -153,6 +169,9 @@ void psp_dev_unregister(struct psp_dev *psd)
 		list_del(&pas->assocs_list);
 	}
 
+	WARN(psd->stats.tx_key_cnt, "psp: %s: %lu Tx keys still installed\n",
+	     netdev_name(psd->main_netdev), psd->stats.tx_key_cnt);
+
 	list_for_each_entry_safe(entry, entry_tmp, &psd->assoc_dev_list,
 				 dev_list) {
 		list_del(&entry->dev_list);
diff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c
index cdfc2d72fb390..494022ab5a718 100644
--- a/net/psp/psp_nl.c
+++ b/net/psp/psp_nl.c
@@ -934,6 +934,10 @@ psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp,
 	    nla_put_uint(rsp, PSP_A_STATS_TX_ERROR, stats.tx_error))
 		goto err_cancel_msg;
 
+	if (psp_dev_has_sadb(psd) &&
+	    nla_put_uint(rsp, PSP_A_STATS_TX_KEY_COUNT, psd->stats.tx_key_cnt))
+		goto err_cancel_msg;
+
 	genlmsg_end(rsp, hdr);
 	return 0;
 
diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c
index a6b1c42dd626f..c458bc551b4b9 100644
--- a/net/psp/psp_sock.c
+++ b/net/psp/psp_sock.c
@@ -94,9 +94,11 @@ static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,
 
 	memcpy(&dummy->tx, key, sizeof(*key));
 	err = psd->ops->tx_key_add(psd, dummy, extack);
-	if (!err)
+	if (!err) {
+		psd->stats.tx_key_cnt++;
 		memcpy(pas->drv_data, dummy->drv_data,
 		       psd->caps->assoc_drv_spc);
+	}
 
 	kfree(dummy);
 	return err;
@@ -105,6 +107,8 @@ static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,
 void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas)
 {
 	psd->ops->tx_key_del(psd, pas);
+	if (!WARN_ON_ONCE(!psd->stats.tx_key_cnt))
+		psd->stats.tx_key_cnt--;
 }
 
 static void psp_assoc_free(struct work_struct *work)
@@ -114,8 +118,14 @@ static void psp_assoc_free(struct work_struct *work)
 
 	mutex_lock(&psd->lock);
 	if (psp_dev_is_registered(psd)) {
-		if (psp_assoc_needs_tx_key_del(pas))
+		if (psp_assoc_needs_tx_key_del(pas)) {
+			if (pas->flags & PSP_ASSOC_DEFER_TX_KEY_DEL) {
+				psp_deferred_del_queue(psd, pas);
+				mutex_unlock(&psd->lock);
+				return;
+			}
 			psp_dev_tx_key_del(psd, pas);
+		}
 		list_del(&pas->assocs_list);
 	}
 	mutex_unlock(&psd->lock);
@@ -149,10 +159,42 @@ void psp_sk_assoc_free(struct sock *sk)
 	psp_assoc_put(pas);
 }
 
+static int psp_sock_rx_rekey(struct psp_assoc *pas, struct psp_assoc *prev,
+			     struct netlink_ext_ack *extack)
+{
+	if (pas->psd != prev->psd) {
+		NL_SET_ERR_MSG(extack, "PSP device mismatch with existing state");
+		return -EINVAL;
+	}
+	if (pas->version != prev->version) {
+		NL_SET_ERR_MSG(extack, "PSP version mismatch with existing state");
+		return -EINVAL;
+	}
+	if (!prev->tx.spi || !prev->peer_tx) {
+		NL_SET_ERR_MSG(extack, "Socket PSP state is not fully established");
+		return -EBUSY;
+	}
+	if (!((pas->rx.spi ^ prev->rx.spi) & cpu_to_be32(PSP_SPI_KEY_PHASE))) {
+		NL_SET_ERR_MSG(extack, "New and prev SPI have same phase bit");
+		return -EINVAL;
+	}
+
+	pas->peer_tx = 1;
+	pas->prev_spi = prev->rx.spi;
+	pas->prev_generation = prev->generation;
+
+	memcpy(&pas->tx, &prev->tx, sizeof(pas->tx));
+	memcpy(pas->drv_data, prev->drv_data, pas->psd->caps->assoc_drv_spc);
+	prev->flags |= PSP_ASSOC_SKIP_TX_KEY_DEL;
+
+	return 0;
+}
+
 int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 			  struct psp_key_parsed *key,
 			  struct netlink_ext_ack *extack)
 {
+	struct psp_assoc *prev;
 	int err;
 
 	memcpy(&pas->rx, key, sizeof(*key));
@@ -165,10 +207,11 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 		goto exit_unlock;
 	}
 
-	if (psp_sk_assoc(sk)) {
-		NL_SET_ERR_MSG(extack, "Socket already has PSP state");
-		err = -EBUSY;
-		goto exit_unlock;
+	prev = psp_sk_assoc(sk);
+	if (prev) {
+		err = psp_sock_rx_rekey(pas, prev, extack);
+		if (err)
+			goto exit_unlock;
 	} else if (sk_has_decrypt_user(sk)) {
 		NL_SET_ERR_MSG(extack, "Socket has incompatible state");
 		err = -EINVAL;
@@ -177,6 +220,7 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 
 	refcount_inc(&pas->refcnt);
 	rcu_assign_pointer(sk->psp_assoc, pas);
+	psp_assoc_put(prev);
 	err = 0;
 
 exit_unlock:
@@ -249,6 +293,49 @@ psp_sock_set_tx_key(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,
 	return err;
 }
 
+static int
+psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,
+		  struct psp_key_parsed *key, struct netlink_ext_ack *extack)
+{
+	struct psp_assoc *new;
+	int err;
+
+	if (!pas->peer_tx) {
+		NL_SET_ERR_MSG(extack, "Socket PSP state is not fully established");
+		return -EBUSY;
+	}
+
+	new = kzalloc_flex(*new, drv_data, psd->caps->assoc_drv_spc,
+			   GFP_KERNEL_ACCOUNT);
+	if (!new)
+		return -ENOMEM;
+
+	new->psd             = pas->psd;
+	new->dev_id          = pas->dev_id;
+	new->generation      = pas->generation;
+	new->version         = pas->version;
+	new->peer_tx         = 1;
+	new->prev_spi        = pas->prev_spi;
+	new->prev_generation = pas->prev_generation;
+	refcount_set(&new->refcnt, 1);
+	memcpy(&new->rx, &pas->rx, sizeof(new->rx));
+
+	err = psp_assoc_set_tx(psd, new, key, extack);
+	if (err) {
+		kfree(new);
+		return err;
+	}
+
+	psp_dev_get(new->psd);
+	list_add(&new->assocs_list, &pas->assocs_list);
+
+	rcu_assign_pointer(sk->psp_assoc, new);
+	pas->flags |= PSP_ASSOC_DEFER_TX_KEY_DEL;
+	psp_assoc_put(pas);
+
+	return 0;
+}
+
 int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
 			  u32 version, struct psp_key_parsed *key,
 			  struct netlink_ext_ack *extack)
@@ -281,13 +368,11 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
 		err = -EINVAL;
 		goto exit_unlock;
 	}
-	if (pas->tx.spi) {
-		NL_SET_ERR_MSG(extack, "Tx key already set");
-		err = -EBUSY;
-		goto exit_unlock;
-	}
+	if (pas->tx.spi)
+		err = psp_sock_tx_rekey(sk, psd, pas, key, extack);
+	else
+		err = psp_sock_set_tx_key(sk, psd, pas, key, extack);
 
-	err = psp_sock_set_tx_key(sk, psd, pas, key, extack);
 exit_unlock:
 	release_sock(sk);
 	return err;
@@ -304,6 +389,10 @@ void psp_assocs_key_rotated(struct psp_dev *psd)
 		pas->generation |= ~PSP_GEN_VALID_MASK;
 		psd->stats.stales++;
 	}
+
+	list_for_each_entry(pas, &psd->active_assocs, assocs_list)
+		pas->prev_generation |= ~PSP_GEN_VALID_MASK;
+
 	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
 	list_splice_init(&psd->active_assocs, &psd->prev_assocs);
 
diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py
index 473500901879b..b22891b7f5ce8 100755
--- a/tools/testing/selftests/drivers/net/psp.py
+++ b/tools/testing/selftests/drivers/net/psp.py
@@ -15,7 +15,7 @@ from contextlib import contextmanager
 
 from lib.py import defer
 from lib.py import ksft_run, ksft_exit, ksft_pr
-from lib.py import ksft_true, ksft_eq, ksft_ne, ksft_gt, ksft_raises
+from lib.py import ksft_true, ksft_eq, ksft_ne, ksft_ge, ksft_gt, ksft_raises
 from lib.py import ksft_not_none
 from lib.py import ksft_variants, KsftNamedVariant
 from lib.py import KsftSkipEx, KsftFailEx
@@ -28,6 +28,12 @@ from lib.py import ip
 TCP_ULP = 31
 
 
+_PSP_MAX_KEY_LEN = 32
+_PSP_ASSOC_MSG = f'!IB3x{_PSP_MAX_KEY_LEN}s'
+_TX_REKEY_ROUNDS = 20
+_TX_KEY_DRAIN_TIMEOUT = 5
+
+
 def _get_outq(s):
     one = b'\0' * 4
     outq = fcntl.ioctl(s.fileno(), termios.TIOCOUTQ, one)
@@ -80,6 +86,36 @@ def _close_psp_conn(cfg, s):
     _close_conn(cfg, s)
 
 
+def _recv_all(s, target):
+    data = b''
+    while len(data) < target:
+        chunk = s.recv(target - len(data))
+        if not chunk:
+            raise KsftFailEx(f"peer closed after {len(data)} of {target} bytes")
+        data += chunk
+    return data
+
+
+def _psp_key_len(version):
+    return 16 if version in (0, 2) else 32
+
+
+def _remote_rx_assoc(cfg):
+    _send_with_ack(cfg, b'rx assoc\0')
+    msg = _recv_all(cfg.comm_sock, struct.calcsize(_PSP_ASSOC_MSG))
+    spi, version, key = struct.unpack(_PSP_ASSOC_MSG, msg)
+    return version, {'spi': spi, 'key': key[:_psp_key_len(version)]}
+
+
+def _remote_tx_assoc(cfg, version, rx):
+    msg = struct.pack(_PSP_ASSOC_MSG, rx['spi'], version, rx['key'])
+    _send_with_ack(cfg, b'tx assoc\0' + msg)
+
+
+def _remote_key_rotate(cfg):
+    _send_with_ack(cfg, b'key rotate\0')
+
+
 def _spi_xchg(s, rx):
     s.send(struct.pack('I', rx['spi']) + rx['key'])
     tx = s.recv(4 + len(rx['key']))
@@ -130,9 +166,57 @@ def _check_data_outq(s, exp_len, force_wait=False):
     ksft_eq(outq, exp_len)
 
 
+def _recv_careful(s, target, timeout=2):
+    """Read exactly target bytes, tolerating short reads"""
+    data = b''
+    end = time.monotonic() + timeout
+    while time.monotonic() < end:
+        try:
+            data += s.recv(target - len(data), socket.MSG_DONTWAIT)
+            if len(data) == target:
+                return data
+        except BlockingIOError:
+            time.sleep(0.001)
+    raise KsftFailEx(f"short read, got {len(data)} of {target} bytes")
+
+
+def _req_echo(cfg, s):
+    """Ask the peer to echo, and check the reply arrives intact"""
+    _send_with_ack(cfg, b'data echo\0')
+    ksft_eq(_recv_careful(s, 5), b'echo\0')
+
+
+def _psp_txrx(cfg, s, rounds, sent=0):
+    """Send data both ways, and return the total bytes sent to the peer"""
+    sent += _send_careful(cfg, s, rounds)
+    _check_data_rx(cfg, sent)
+    _req_echo(cfg, s)
+    return sent
+
+
+def _require_version(cfg, version):
+    """Skip the test unless the device supports the given PSP version"""
+    name = cfg.pspnl.consts["version"].entries_by_val[version].name
+    if name not in cfg.psp_info['psp-versions-cap']:
+        raise KsftSkipEx("PSP version not supported", name)
+
+
 def _get_stat(cfg, key):
     return cfg.pspnl.get_stats({'dev-id': cfg.psp_dev_id})[key]
 
+
+def _get_tx_key_count(cfg):
+    return cfg.pspnl.get_stats({'dev-id': cfg.psp_dev_id}).get('tx-key-count')
+
+
+def _wait_tx_key_drain(cfg, base):
+    cnt = _get_tx_key_count(cfg)
+    end = time.monotonic() + _TX_KEY_DRAIN_TIMEOUT
+    while cnt > base and time.monotonic() < end:
+        time.sleep(0.1)
+        cnt = _get_tx_key_count(cfg)
+    ksft_ge(base, cnt, comment="tx keys not removed from device after rekey")
+
 #
 # Test case boiler plate
 #
@@ -447,10 +531,11 @@ def assoc_twice(cfg):
             ksft_eq(len(tx), 0)
 
 
-def _data_basic_send(cfg, version, ipver):
-    """ Test basic data send """
-    _init_psp_dev(cfg)
+def _establish_psp_conn(cfg, version, ipver=None):
+    """Establish a PSP connection and return after key exchange
 
+    Requires _init_psp_dev() to have been called first.
+    """
     # Version 0 is required by spec, don't let it skip
     if version:
         name = cfg.pspnl.consts["version"].entries_by_val[version].name
@@ -475,12 +560,238 @@ def _data_basic_send(cfg, version, ipver):
                         "version": version,
                         "tx-key": tx,
                         "sock-fd": s.fileno()})
+    return s
 
+
+def _data_basic_send(cfg, version, ipver):
+    """ Test basic data send """
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, version, ipver)
     data_len = _send_careful(cfg, s, 100)
     _check_data_rx(cfg, data_len)
     _close_psp_conn(cfg, s)
 
 
+def _rekey_rx(cfg, s, version, sent):
+    """Rekey the Rx direction, running traffic after each step"""
+    rx_assoc = cfg.pspnl.rx_assoc({"version": version,
+                                   "dev-id": cfg.psp_dev_id,
+                                   "sock-fd": s.fileno()})
+    sent = _psp_txrx(cfg, s, 1, sent)
+
+    _remote_tx_assoc(cfg, version, rx_assoc['rx-key'])
+    return _psp_txrx(cfg, s, 1, sent)
+
+
+def _rekey_tx(cfg, s, sent):
+    """Rekey the Tx direction, running traffic after each step"""
+    version, tx = _remote_rx_assoc(cfg)
+    sent = _psp_txrx(cfg, s, 1, sent)
+
+    cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                        "version": version,
+                        "tx-key": tx,
+                        "sock-fd": s.fileno()})
+    return _psp_txrx(cfg, s, 1, sent)
+
+
+def rekey_rx_incomplete(cfg):
+    """Test rejecting Rx rekey until the PSP connection is established"""
+    psp_ver = 0
+    _init_psp_dev(cfg)
+
+    with _make_lo_conn() as s:
+        assoc = cfg.pspnl.rx_assoc({"version": psp_ver,
+                                    "dev-id": cfg.psp_dev_id,
+                                    "sock-fd": s.fileno()})
+
+        # Reject rekey before Tx state is configured.
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.rx_assoc({"version": psp_ver,
+                                "dev-id": cfg.psp_dev_id,
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY)
+
+        cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                            "version": psp_ver,
+                            "tx-key": assoc['rx-key'],
+                            "sock-fd": s.fileno()})
+
+        # Reject rekey until authenticated PSP traffic has been received.
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.rx_assoc({"version": psp_ver,
+                                "dev-id": cfg.psp_dev_id,
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY)
+
+
+def rekey_tx_incomplete(cfg):
+    """Test rejecting Tx rekey until the PSP connection is established"""
+    psp_ver = 0
+    _init_psp_dev(cfg)
+
+    with _make_lo_conn() as s:
+        assoc = cfg.pspnl.rx_assoc({"version": psp_ver,
+                                    "dev-id": cfg.psp_dev_id,
+                                    "sock-fd": s.fileno()})
+
+        cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                            "version": psp_ver,
+                            "tx-key": assoc['rx-key'],
+                            "sock-fd": s.fileno()})
+
+        # Reject rekey until authenticated PSP traffic has been received.
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                                "version": psp_ver,
+                                "tx-key": assoc['rx-key'],
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY)
+
+
+def rekey_rx_same_gen(cfg):
+    """Test rejecting an Rx rekey without an intervening key rotation"""
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, 0)
+    try:
+        _psp_txrx(cfg, s, 1)
+
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.rx_assoc({"version": 0,
+                                "dev-id": cfg.psp_dev_id,
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL)
+
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+        cfg.pspnl.rx_assoc({"version": 0,
+                            "dev-id": cfg.psp_dev_id,
+                            "sock-fd": s.fileno()})
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+def rekey_rx_version_mismatch(cfg):
+    """Test rejecting an Rx rekey whose version does not match socket state"""
+    _init_psp_dev(cfg)
+    _require_version(cfg, 1)
+
+    s = _establish_psp_conn(cfg, 0)
+    try:
+        _psp_txrx(cfg, s, 1)
+
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.rx_assoc({"dev-id": cfg.psp_dev_id,
+                                "version": 1,
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+def rekey_tx_version_mismatch(cfg):
+    """Test rejecting a Tx rekey whose version does not match socket state"""
+    _init_psp_dev(cfg)
+    _require_version(cfg, 1)
+
+    s = _establish_psp_conn(cfg, 0)
+    try:
+        _psp_txrx(cfg, s, 1)
+
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                                "version": 1,
+                                "tx-key": {'spi': 0x12345678,
+                                           'key': b'\xa5' * 32},
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+def _get_psp_ver_variants():
+    for ver in range(4):
+        yield KsftNamedVariant(f"v{ver}", ver)
+
+
+@ksft_variants(_get_psp_ver_variants())
+def rekey_rx_basic(cfg, version):
+    """Test rekeying the Rx key of an established connection"""
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, version)
+    try:
+        data_len = _psp_txrx(cfg, s, 10)
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+        _rekey_rx(cfg, s, version, data_len)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+@ksft_variants(_get_psp_ver_variants())
+def rekey_tx_basic(cfg, version):
+    """Test rekeying the Tx key of an established connection"""
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, version)
+    try:
+        data_len = _psp_txrx(cfg, s, 10)
+        _remote_key_rotate(cfg)
+        _rekey_tx(cfg, s, data_len)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+def rekey_tx_drain(cfg):
+    """Test that Tx rekeys do not leak keys on the device"""
+    _init_psp_dev(cfg)
+
+    if _get_tx_key_count(cfg) is None:
+        raise KsftSkipEx("Device does not track Tx keys")
+
+    s = _establish_psp_conn(cfg, 0)
+    try:
+        data_len = _psp_txrx(cfg, s, 1)
+        base = _get_tx_key_count(cfg)
+
+        for _ in range(_TX_REKEY_ROUNDS):
+            _remote_key_rotate(cfg)
+            data_len = _rekey_tx(cfg, s, data_len)
+
+        _wait_tx_key_drain(cfg, base)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+@ksft_variants(_get_psp_ver_variants())
+def rekey_both_sides(cfg, version):
+    """Test rekeying both directions"""
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, version)
+    try:
+        data_len = _psp_txrx(cfg, s, 10)
+
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+        _remote_key_rotate(cfg)
+
+        # first, rx then tx
+        data_len = _rekey_rx(cfg, s, version, data_len)
+        data_len = _rekey_tx(cfg, s, data_len)
+
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+        _remote_key_rotate(cfg)
+
+        # now, tx then rx
+        data_len = _rekey_tx(cfg, s, data_len)
+        _rekey_rx(cfg, s, version, data_len)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
 def __bad_xfer_do(cfg, s, tx, version='hdr0-aes-gcm-128'):
     # Make sure we accept the ACK for the SPI before we seal with the bad assoc
     _check_data_outq(s, 0)
@@ -1173,7 +1484,8 @@ def main() -> None:
                                                           cfg.comm_port),
                                                          timeout=1)
 
-                cases = [data_basic_send, data_mss_adjust]
+                cases = [data_basic_send, data_mss_adjust,
+                         rekey_rx_basic, rekey_tx_basic, rekey_both_sides]
 
                 if has_cont:
                     cases += [
@@ -1189,7 +1501,8 @@ def main() -> None:
                     ]
 
                 ksft_run(cases=cases, globs=globals(),
-                         case_pfx={"dev_", "data_", "assoc_", "removal_"},
+                         case_pfx={"dev_", "data_", "assoc_", "rekey_",
+                                   "removal_"},
                          args=(cfg, ))
 
                 cfg.comm_sock.send(b"exit\0")
diff --git a/tools/testing/selftests/drivers/net/psp_responder.c b/tools/testing/selftests/drivers/net/psp_responder.c
index a26e7628bbb13..b3e0fe6d69750 100644
--- a/tools/testing/selftests/drivers/net/psp_responder.c
+++ b/tools/testing/selftests/drivers/net/psp_responder.c
@@ -5,6 +5,7 @@
 #include <sys/poll.h>
 #include <sys/socket.h>
 #include <sys/time.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <unistd.h>
 
@@ -23,6 +24,7 @@ static bool should_quit;
 struct opts {
 	int port;
 	int ifindex;
+	int devid;
 	bool verbose;
 };
 
@@ -37,20 +39,24 @@ static struct {
 	unsigned char rx;
 } psp_vers;
 
-static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)
+static unsigned int psp_key_len(unsigned char version)
 {
+	switch (version) {
+	case PSP_VERSION_HDR0_AES_GCM_256:
+	case PSP_VERSION_HDR0_AES_GMAC_256:
+		return 32;
+	default:
+		return 16;
+	}
+}
+
+static int
+rx_assoc(struct ynl_sock *ys, __u32 *spi, char *key, int data_sock)
+{
+	unsigned int key_len = psp_key_len(psp_vers.rx);
 	struct psp_rx_assoc_rsp *rsp;
 	struct psp_rx_assoc_req *req;
-	struct psp_tx_assoc_rsp *tsp;
-	struct psp_tx_assoc_req *teq;
-	char info[300];
-	int key_len;
-	ssize_t sz;
-	__u32 spi;
 
-	dbg("create PSP connection\n");
-
-	// Rx assoc alloc
 	req = psp_rx_assoc_req_alloc();
 
 	psp_rx_assoc_req_set_sock_fd(req, data_sock);
@@ -64,29 +70,34 @@ static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)
 		return -1;
 	}
 
-	// SPI exchange
-	key_len = rsp->rx_key._len.key;
-	memcpy(info, &rsp->rx_key.spi, sizeof(spi));
-	memcpy(&info[sizeof(spi)], rsp->rx_key.key, key_len);
-	sz = sizeof(spi) + key_len;
+	if (rsp->rx_key._len.key != key_len) {
+		fprintf(stderr, "ERROR: unexpected Rx key length %u\n",
+			rsp->rx_key._len.key);
+		psp_rx_assoc_rsp_free(rsp);
+		return -1;
+	}
+
+	memcpy(spi, &rsp->rx_key.spi, sizeof(*spi));
+	memcpy(key, rsp->rx_key.key, key_len);
 
-	send(data_sock, info, sz, MSG_WAITALL);
 	psp_rx_assoc_rsp_free(rsp);
 
-	sz = recv(data_sock, info, sz, MSG_WAITALL);
-	if (sz < 0) {
-		perror("ERROR: failed to read PSP key from sock");
-		return -1;
-	}
-	memcpy(&spi, info, sizeof(spi));
+	return 0;
+}
+
+static int
+tx_assoc(struct ynl_sock *ys, __u8 version, __u32 spi, char *key,
+	 int data_sock)
+{
+	struct psp_tx_assoc_rsp *tsp;
+	struct psp_tx_assoc_req *teq;
 
-	// Setup Tx assoc
 	teq = psp_tx_assoc_req_alloc();
 
 	psp_tx_assoc_req_set_sock_fd(teq, data_sock);
-	psp_tx_assoc_req_set_version(teq, psp_vers.tx);
+	psp_tx_assoc_req_set_version(teq, version);
 	psp_tx_assoc_req_set_tx_key_spi(teq, spi);
-	psp_tx_assoc_req_set_tx_key_key(teq, &info[sizeof(spi)], key_len);
+	psp_tx_assoc_req_set_tx_key_key(teq, key, psp_key_len(version));
 
 	tsp = psp_tx_assoc(ys, teq);
 	psp_tx_assoc_req_free(teq);
@@ -99,6 +110,34 @@ static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)
 	return 0;
 }
 
+static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)
+{
+	unsigned int key_len = psp_key_len(psp_vers.rx);
+	char info[300];
+	ssize_t sz;
+	__u32 spi;
+
+	dbg("create PSP connection\n");
+
+	if (rx_assoc(ys, &spi, &info[sizeof(spi)], data_sock))
+		return -1;
+
+	// SPI exchange
+	memcpy(info, &spi, sizeof(spi));
+	sz = sizeof(spi) + key_len;
+
+	send(data_sock, info, sz, MSG_WAITALL);
+
+	sz = recv(data_sock, info, sz, MSG_WAITALL);
+	if (sz < 0) {
+		perror("ERROR: failed to read PSP key from sock");
+		return -1;
+	}
+	memcpy(&spi, info, sizeof(spi));
+
+	return tx_assoc(ys, psp_vers.tx, spi, &info[sizeof(spi)], data_sock);
+}
+
 static void send_ack(int sock)
 {
 	send(sock, "ack", 4, MSG_WAITALL);
@@ -118,6 +157,100 @@ static void send_str(int sock, int value)
 	send(sock, buf, ret + 1, MSG_WAITALL);
 }
 
+#define PSP_MAX_KEY_LEN		32
+
+struct assoc_msg {
+	__be32 spi;
+	__u8 version;
+	__u8 pad[3];
+	char key[PSP_MAX_KEY_LEN];
+};
+
+static void
+handle_rx_assoc(struct ynl_sock *ys, int data_sock, int comm_sock)
+{
+	struct assoc_msg msg = {};
+	__u32 spi;
+
+	if (data_sock < 0) {
+		fprintf(stderr, "WARN: rx assoc but no data sock\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	if (rx_assoc(ys, &spi, msg.key, data_sock)) {
+		fprintf(stderr, "ERROR: rx_assoc() failed\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	msg.spi = htonl(spi);
+	msg.version = psp_vers.rx;
+	send_ack(comm_sock);
+	send(comm_sock, &msg, sizeof(msg), MSG_WAITALL);
+}
+
+static void
+handle_tx_assoc(struct ynl_sock *ys, char *data, int data_sock, int comm_sock)
+{
+	struct assoc_msg msg;
+
+	if (data_sock < 0) {
+		fprintf(stderr, "WARN: tx assoc but no data sock\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	memcpy(&msg, data, sizeof(msg));
+	if (tx_assoc(ys, msg.version, ntohl(msg.spi), msg.key, data_sock)) {
+		fprintf(stderr, "ERROR: tx_assoc() failed!\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	send_ack(comm_sock);
+}
+
+static int rotate_key(struct ynl_sock *ys, int devid)
+{
+	struct psp_key_rotate_rsp *rsp;
+	struct psp_key_rotate_req *req;
+
+	req = psp_key_rotate_req_alloc();
+
+	psp_key_rotate_req_set_id(req, devid);
+
+	rsp = psp_key_rotate(ys, req);
+	psp_key_rotate_req_free(req);
+
+	if (!rsp) {
+		perror("ERROR: failed to rotate key");
+		return -1;
+	}
+
+	psp_key_rotate_rsp_free(rsp);
+
+	return 0;
+}
+
+static void
+handle_key_rotate(struct ynl_sock *ys, struct opts *opts, int comm_sock)
+{
+	if (opts->devid < 0) {
+		fprintf(stderr, "WARN: key rotate but no PSP device\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	if (rotate_key(ys, opts->devid)) {
+		fprintf(stderr, "ERROR: rotate_key() failed\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	send_ack(comm_sock);
+}
+
 static void
 run_session(struct ynl_sock *ys, struct opts *opts,
 	    int server_sock, int comm_sock)
@@ -210,6 +343,9 @@ run_session(struct ynl_sock *ys, struct opts *opts,
 			match;						\
 		})
 
+#define cmd_w_msg(_name, _type)						\
+		(off >= sizeof(_name) + sizeof(_type) && cmd(_name))
+
 			do {
 				consumed = false;
 
@@ -224,6 +360,16 @@ run_session(struct ynl_sock *ys, struct opts *opts,
 						fprintf(stderr, "WARN: echo but no data sock\n");
 					send_ack(comm_sock);
 				}
+				if (cmd("rx assoc"))
+					handle_rx_assoc(ys, data_sock,
+							comm_sock);
+				if (cmd_w_msg("tx assoc", struct assoc_msg)) {
+					handle_tx_assoc(ys, buf, data_sock,
+							comm_sock);
+					__consume(sizeof(struct assoc_msg));
+				}
+				if (cmd("key rotate"))
+					handle_key_rotate(ys, opts, comm_sock);
 				if (cmd("data close")) {
 					if (data_sock >= 0) {
 						close(data_sock);
@@ -254,6 +400,7 @@ run_session(struct ynl_sock *ys, struct opts *opts,
 				}
 				if (cmd("exit"))
 					should_quit = true;
+#undef cmd_w_msg
 #undef cmd
 
 				if (!consumed) {
@@ -449,6 +596,7 @@ int main(int argc, char **argv)
 		}
 	}
 	psp_dev_get_list_free(dev_list);
+	opts.devid = devid;
 
 	if (opts.ifindex && devid < 0)
 		fprintf(stderr,

3/2 2026/10/09 23:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21148
							output: 19
							thoughts: 278
						

Thoughts:
**Analyzing the PSP Patch for Fuzzing Potential**

Okay, let's dive into this patch and figure out if it's a good candidate for syzkaller. My initial instinct is to assess the code changes, and then determine if there are potential entry points or areas of interest for fuzzing.

First, I need to see exactly what's being modified. The patch touches a pretty broad range of files, including documentation and a new file:

*   `Documentation/netlink/specs/psp.yaml`
*   `Documentation/networking/psp.rst`
*   `include/net/psp/functions.h`
*   `include/net/psp/types.h`
*   `include/uapi/linux/psp.h`
*   `net/psp/Kconfig`
*   `net/psp/Makefile`
*   `net/psp/psp.h`
*   `net/psp/psp_deferred_del.c` (New!)
*   `net/psp/psp_main.c`
*   `net/psp/psp_nl.c`
*   `net/psp/psp_sock.c`
*   `tools/testing/selftests/...`

So, PSP is the Security Protocol support, which is good to know. Now I need to quickly get my head around the underlying architecture and how this is implemented. I need to understand how the `psp_dev` is created and used. Is this something that's tied to specific hardware, or can it function in a virtual environment? I need to look into netdevsim or similar virtual devices, can they implement psp.

I'll use `grepper` to search for `psp_dev_create` and other PSP driver-related functions to see how it's integrated into the kernel and see whether there are interesting entry points to target.



4/2 2026/10/09 23:06 tool grepper
0m Args:
{
  "Expression": "psp_dev_create"
}

Results:
{
  "Output": "drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c=1031=int mlx5e_psp_register(struct mlx5e_priv *priv)\n--\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c-1045-\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c:1046:\tpsd = psp_dev_create(priv-\u003enetdev, \u0026mlx5_psp_ops, \u0026psp-\u003ecaps, NULL);\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c-1047-\tif (IS_ERR(psd)) {\n--\ndrivers/net/netdevsim/psp.c=211=nsim_psp_rereg_write(struct file *file, const char __user *data, size_t count,\n--\ndrivers/net/netdevsim/psp.c-220-\ndrivers/net/netdevsim/psp.c:221:\tpsd = psp_dev_create(ns-\u003enetdev, \u0026nsim_psp_ops, \u0026nsim_psp_caps, ns);\ndrivers/net/netdevsim/psp.c-222-\tif (IS_ERR(psd)) {\n--\ndrivers/net/netdevsim/psp.c=241=int nsim_psp_init(struct netdevsim *ns)\n--\ndrivers/net/netdevsim/psp.c-245-\ndrivers/net/netdevsim/psp.c:246:\tpsd = psp_dev_create(ns-\u003enetdev, \u0026nsim_psp_ops, \u0026nsim_psp_caps, ns);\ndrivers/net/netdevsim/psp.c-247-\tif (IS_ERR(psd))\n--\ninclude/net/psp/functions.h=16=struct psp_dev *\ninclude/net/psp/functions.h:17:psp_dev_create(struct net_device *netdev, struct psp_dev_ops *psd_ops,\ninclude/net/psp/functions.h-18-\t       struct psp_dev_caps *psd_caps, void *priv_ptr);\n--\nnet/psp/psp_main.c=40=int psp_dev_check_access(struct psp_dev *psd, struct net *net, bool admin)\n--\nnet/psp/psp_main.c-51-/**\nnet/psp/psp_main.c:52: * psp_dev_create() - create and register PSP device\nnet/psp/psp_main.c-53- * @netdev:\tmain netdevice\n--\nnet/psp/psp_main.c=60=struct psp_dev *\nnet/psp/psp_main.c:61:psp_dev_create(struct net_device *netdev,\nnet/psp/psp_main.c-62-\t       struct psp_dev_ops *psd_ops, struct psp_dev_caps *psd_caps,\n--\nnet/psp/psp_main.c-126-}\nnet/psp/psp_main.c:127:EXPORT_SYMBOL(psp_dev_create);\nnet/psp/psp_main.c-128-\n"
}

5/2 2026/10/09 23:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22686
							output: 37
							thoughts: 72
						

Thoughts:
Here's my take on those thoughts:

**Peering into the netdevsim Depths**

Okay, so I'm looking at `drivers/net/netdevsim/psp.c`. Ah, right, netdevsim! That's the virtual network device, heavily utilized by tools like syzkaller and in self-tests. A software-emulated device – a crucial piece for testing and debugging. Now that I've got that refresher, let's dive into the `psp.c` source and see what interesting PSP-related implementations are there... I need to remember what PSP even is. Let's see how they've handled it in this simulated environment. This should be an interesting exploration.



6/2 2026/10/09 23:07 tool read-file
0m Args:
{
  "File": "drivers/net/netdevsim/psp.c",
  "FirstLine": 1,
  "LineCount": 80
}

Results:
{
  "Contents": "   1:\t// SPDX-License-Identifier: GPL-2.0\n   2:\t\n   3:\t#include \u003clinux/ip.h\u003e\n   4:\t#include \u003clinux/skbuff.h\u003e\n   5:\t#include \u003cnet/ip6_checksum.h\u003e\n   6:\t#include \u003cnet/psp.h\u003e\n   7:\t#include \u003cnet/sock.h\u003e\n   8:\t\n   9:\t#include \"netdevsim.h\"\n  10:\t\n  11:\tvoid nsim_psp_handle_ext(struct sk_buff *skb, struct skb_ext *psp_ext)\n  12:\t{\n  13:\t\tif (psp_ext)\n  14:\t\t\t__skb_ext_set(skb, SKB_EXT_PSP, psp_ext);\n  15:\t}\n  16:\t\n  17:\tenum skb_drop_reason\n  18:\tnsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,\n  19:\t\t    struct netdevsim *peer_ns, struct skb_ext **psp_ext)\n  20:\t{\n  21:\t\tenum skb_drop_reason rc = 0;\n  22:\t\tstruct psp_dev *peer_psd;\n  23:\t\tstruct psp_assoc *pas;\n  24:\t\tstruct net *net;\n  25:\t\tint psp_len;\n  26:\t\n  27:\t\trcu_read_lock();\n  28:\t\tpas = psp_skb_get_assoc_rcu(skb);\n  29:\t\tif (!pas) {\n  30:\t\t\trc = SKB_NOT_DROPPED_YET;\n  31:\t\t\tgoto out_unlock;\n  32:\t\t}\n  33:\t\n  34:\t\tif (!skb_transport_header_was_set(skb)) {\n  35:\t\t\trc = SKB_DROP_REASON_PSP_OUTPUT;\n  36:\t\t\tgoto out_unlock;\n  37:\t\t}\n  38:\t\n  39:\t\tnet = sock_net(skb-\u003esk);\n  40:\t\tif (!psp_dev_encapsulate(net, skb, pas-\u003etx.spi, pas-\u003eversion, 0)) {\n  41:\t\t\trc = SKB_DROP_REASON_PSP_OUTPUT;\n  42:\t\t\tgoto out_unlock;\n  43:\t\t}\n  44:\t\n  45:\t\tpsp_len = skb-\u003elen - skb_inner_transport_offset(skb);\n  46:\t\tatomic64_inc(\u0026ns-\u003epsp.tx_packets);\n  47:\t\tatomic64_add(psp_len, \u0026ns-\u003epsp.tx_bytes);\n  48:\t\n  49:\t\t/* Now pretend we just received this frame */\n  50:\t\tpeer_psd = rcu_dereference(peer_ns-\u003epsp.dev);\n  51:\t\tif (peer_psd \u0026\u0026 peer_psd-\u003econfig.versions \u0026 (1 \u003c\u003c pas-\u003eversion)) {\n  52:\t\t\tbool strip_icv = false;\n  53:\t\t\tu8 generation;\n  54:\t\n  55:\t\t\t/* We cheat a bit and put the generation in the key.\n  56:\t\t\t * In real life if generation was too old, then decryption would\n  57:\t\t\t * fail. Here, we just make it so a bad key causes a bad\n  58:\t\t\t * generation too, and psp_sk_rx_policy_check() will fail.\n  59:\t\t\t */\n  60:\t\t\tgeneration = pas-\u003etx.key[0];\n  61:\t\n  62:\t\t\tskb_ext_reset(skb);\n  63:\t\t\tskb-\u003emac_len = ETH_HLEN;\n  64:\t\t\tif (psp_dev_rcv(skb, peer_psd-\u003eid, generation, strip_icv)) {\n  65:\t\t\t\trc = SKB_DROP_REASON_PSP_OUTPUT;\n  66:\t\t\t\tgoto out_unlock;\n  67:\t\t\t}\n  68:\t\n  69:\t\t\t*psp_ext = skb-\u003eextensions;\n  70:\t\t\trefcount_inc(\u0026(*psp_ext)-\u003erefcnt);\n  71:\t\t\tskb-\u003edecrypted = 1;\n  72:\t\n  73:\t\t\tatomic64_inc(\u0026peer_ns-\u003epsp.rx_packets);\n  74:\t\t\tatomic64_add(psp_len, \u0026peer_ns-\u003epsp.rx_bytes);\n  75:\t\t} else {\n  76:\t\t\tstruct ipv6hdr *ip6h __maybe_unused;\n  77:\t\t\tstruct iphdr *iph;\n  78:\t\t\tstruct udphdr *uh;\n  79:\t\t\t__wsum csum;\n  80:\t\t\tint udplen;\n"
}

7/2 2026/10/09 23:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24164
							output: 39
							thoughts: 29
						

Thoughts:
Here's the summary, assuming I'm an expert:

**Investigating Potential Issues in the Network Device Simulator**

Okay, so I'm digging into this network device simulation code. Before I get too deep, it's probably wise to glance at `drivers/net/netdevsim/psp.c`, specifically lines 180 through 250. That section likely deals with the packet scheduling or processing, which is a common area for subtle bugs to creep in, especially in a simulated environment. Let me refresh my memory of what's implemented there. I'll focus on anything related to the interplay between the virtual hardware and software, the queuing mechanisms, or how the simulated network handles packet arrival and departure times. I need to make sure I understand the critical path of packet processing within the simulation. That particular section is often responsible for the subtle timing issues that can crop up, especially if it involves any concurrency or locking. I'll be looking for potential race conditions, incorrect buffer management, or maybe even unexpected behavior under load. It's a good starting point for a preliminary check.



8/2 2026/10/09 23:07 tool read-file
0m Args:
{
  "File": "drivers/net/netdevsim/psp.c",
  "FirstLine": 180,
  "LineCount": 80
}

Results:
{
  "Contents": " 180:\t};\n 181:\t\n 182:\tstatic struct psp_dev_caps nsim_psp_caps = {\n 183:\t\t.versions = 1 \u003c\u003c PSP_VERSION_HDR0_AES_GCM_128 |\n 184:\t\t\t    1 \u003c\u003c PSP_VERSION_HDR0_AES_GMAC_128 |\n 185:\t\t\t    1 \u003c\u003c PSP_VERSION_HDR0_AES_GCM_256 |\n 186:\t\t\t    1 \u003c\u003c PSP_VERSION_HDR0_AES_GMAC_256,\n 187:\t};\n 188:\t\n 189:\tstatic void __nsim_psp_uninit(struct netdevsim *ns, bool teardown)\n 190:\t{\n 191:\t\tstruct psp_dev *psd;\n 192:\t\n 193:\t\tpsd = rcu_dereference_protected(ns-\u003epsp.dev,\n 194:\t\t\t\t\t\tteardown ||\n 195:\t\t\t\t\t\tlockdep_is_held(\u0026ns-\u003epsp.rereg_lock));\n 196:\t\tif (psd) {\n 197:\t\t\trcu_assign_pointer(ns-\u003epsp.dev, NULL);\n 198:\t\t\tsynchronize_rcu();\n 199:\t\t\tpsp_dev_unregister(psd);\n 200:\t\t}\n 201:\t}\n 202:\t\n 203:\tvoid nsim_psp_uninit(struct netdevsim *ns)\n 204:\t{\n 205:\t\tdebugfs_remove(ns-\u003epsp.rereg);\n 206:\t\tmutex_destroy(\u0026ns-\u003epsp.rereg_lock);\n 207:\t\t__nsim_psp_uninit(ns, true);\n 208:\t}\n 209:\t\n 210:\tstatic ssize_t\n 211:\tnsim_psp_rereg_write(struct file *file, const char __user *data, size_t count,\n 212:\t\t\t     loff_t *ppos)\n 213:\t{\n 214:\t\tstruct netdevsim *ns = file-\u003eprivate_data;\n 215:\t\tstruct psp_dev *psd;\n 216:\t\tssize_t ret;\n 217:\t\n 218:\t\tmutex_lock(\u0026ns-\u003epsp.rereg_lock);\n 219:\t\t__nsim_psp_uninit(ns, false);\n 220:\t\n 221:\t\tpsd = psp_dev_create(ns-\u003enetdev, \u0026nsim_psp_ops, \u0026nsim_psp_caps, ns);\n 222:\t\tif (IS_ERR(psd)) {\n 223:\t\t\tret = PTR_ERR(psd);\n 224:\t\t\tgoto out;\n 225:\t\t}\n 226:\t\n 227:\t\trcu_assign_pointer(ns-\u003epsp.dev, psd);\n 228:\t\tret = count;\n 229:\tout:\n 230:\t\tmutex_unlock(\u0026ns-\u003epsp.rereg_lock);\n 231:\t\treturn ret;\n 232:\t}\n 233:\t\n 234:\tstatic const struct file_operations nsim_psp_rereg_fops = {\n 235:\t\t.open = simple_open,\n 236:\t\t.write = nsim_psp_rereg_write,\n 237:\t\t.llseek = generic_file_llseek,\n 238:\t\t.owner = THIS_MODULE,\n 239:\t};\n 240:\t\n 241:\tint nsim_psp_init(struct netdevsim *ns)\n 242:\t{\n 243:\t\tstruct dentry *ddir = ns-\u003ensim_dev_port-\u003eddir;\n 244:\t\tstruct psp_dev *psd;\n 245:\t\n 246:\t\tpsd = psp_dev_create(ns-\u003enetdev, \u0026nsim_psp_ops, \u0026nsim_psp_caps, ns);\n 247:\t\tif (IS_ERR(psd))\n 248:\t\t\treturn PTR_ERR(psd);\n 249:\t\n 250:\t\trcu_assign_pointer(ns-\u003epsp.dev, psd);\n 251:\t\n 252:\t\tmutex_init(\u0026ns-\u003epsp.rereg_lock);\n 253:\t\tns-\u003epsp.rereg = debugfs_create_file(\"psp_rereg\", 0200, ddir, ns,\n 254:\t\t\t\t\t\t    \u0026nsim_psp_rereg_fops);\n 255:\t\treturn 0;\n 256:\t}\n"
}

9/2 2026/10/09 23:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25691
							output: 39
							thoughts: 26
						

Thoughts:
Okay, let's dive in. Here's my thought process laid out:

**Checking `nsim_psp_ops` in `drivers/net/netdevsim/psp.c`**

Alright, I need to understand how the Network Device Simulator (Netdevsim) interacts with the Packet Streaming Processor (PSP) within the kernel. My immediate thought is to check the `nsim_psp_ops` structure definition, specifically within the `psp.c` file located in the `drivers/net/netdevsim` directory. This structure likely defines the function pointers or operational methods that the Netdevsim uses to interface with the PSP within the simulated environment. I'm assuming this will include things like how packets are sent to and received from the simulated PSP, how the PSP's internal state is managed, and perhaps any necessary initialization or cleanup routines related to this simulated device. I anticipate this structure to reveal the specific communication interface the Netdevsim uses. I'm expecting this will illuminate the underlying mechanics.



10/2 2026/10/09 23:07 tool read-file
0m Args:
{
  "File": "drivers/net/netdevsim/psp.c",
  "FirstLine": 140,
  "LineCount": 45
}

Results:
{
  "Contents": " 140:\t\t\tassoc-\u003ekey[i] = ns-\u003epsp.spi + i;\n 141:\t\n 142:\t\treturn 0;\n 143:\t}\n 144:\t\n 145:\tstatic int nsim_key_rotate(struct psp_dev *psd, struct netlink_ext_ack *extack)\n 146:\t{\n 147:\t\tstruct netdevsim *ns = psd-\u003edrv_priv;\n 148:\t\n 149:\t\t/* Flip key phase and reset SPI to 0 within that space\n 150:\t\t * (will be pre-incremented, as 0 is an invalid SPI).\n 151:\t\t */\n 152:\t\tif (ns-\u003epsp.spi \u0026 PSP_SPI_KEY_PHASE)\n 153:\t\t\tns-\u003epsp.spi = 0;\n 154:\t\telse\n 155:\t\t\tns-\u003epsp.spi = PSP_SPI_KEY_PHASE;\n 156:\t\n 157:\t\treturn 0;\n 158:\t}\n 159:\t\n 160:\tstatic void nsim_get_stats(struct psp_dev *psd, struct psp_dev_stats *stats)\n 161:\t{\n 162:\t\tstruct netdevsim *ns = psd-\u003edrv_priv;\n 163:\t\n 164:\t\t/* WARNING: do *not* blindly zero stats in real drivers!\n 165:\t\t * All required stats must be reported by the device!\n 166:\t\t */\n 167:\t\tmemset(stats, 0, sizeof(struct psp_dev_stats));\n 168:\t\n 169:\t\tstats-\u003erx_bytes = atomic64_read(\u0026ns-\u003epsp.rx_bytes);\n 170:\t\tstats-\u003erx_packets = atomic64_read(\u0026ns-\u003epsp.rx_packets);\n 171:\t\tstats-\u003etx_bytes = atomic64_read(\u0026ns-\u003epsp.tx_bytes);\n 172:\t\tstats-\u003etx_packets = atomic64_read(\u0026ns-\u003epsp.tx_packets);\n 173:\t}\n 174:\t\n 175:\tstatic struct psp_dev_ops nsim_psp_ops = {\n 176:\t\t.set_config\t= nsim_psp_set_config,\n 177:\t\t.rx_spi_alloc\t= nsim_rx_spi_alloc,\n 178:\t\t.key_rotate\t= nsim_key_rotate,\n 179:\t\t.get_stats\t= nsim_get_stats,\n 180:\t};\n 181:\t\n 182:\tstatic struct psp_dev_caps nsim_psp_caps = {\n 183:\t\t.versions = 1 \u003c\u003c PSP_VERSION_HDR0_AES_GCM_128 |\n 184:\t\t\t    1 \u003c\u003c PSP_VERSION_HDR0_AES_GMAC_128 |\n"
}

11/2 2026/10/09 23:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26738
							output: 19
							thoughts: 69
						

Thoughts:
Okay, here's my take on those thoughts, framed as my own mental processing:

**Observations on Key Management in Virtual Drivers**

Hmm, interesting. I'm looking at `nsim_psp_ops`, and it doesn't seem to expose the `.tx_key_add` or `.tx_key_del` function pointers. That strikes me as a bit odd. I'm wondering, is this typical for virtual drivers? Do *any* of the virtual drivers I'm familiar with actually implement key addition or deletion at the transmit level like that?

Alright, time to get a broader view. I'm going to quickly search the kernel source for any instance of `tx_key_add`. This will tell me what the landscape looks like. It'll give me a better understanding of how key management is handled in these kinds of drivers, and hopefully reveal if this absence in `nsim_psp_ops` is a deliberate design choice, an oversight, or simply handled differently elsewhere. Let's see what the broader picture tells us.



12/2 2026/10/09 23:07 tool grepper
0m Args:
{
  "Expression": "tx_key_add"
}

Results:
{
  "Output": "Documentation/networking/psp.rst=205=Deferred Tx key deletion\n--\nDocumentation/networking/psp.rst-207-\nDocumentation/networking/psp.rst:208:Drivers which implement ``tx_key_add`` and ``tx_key_del`` may hold key\nDocumentation/networking/psp.rst-209-references in their Tx rings, so PSP core waits until descriptors\n--\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c=1011=static struct psp_dev_ops mlx5_psp_ops = {\n--\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c-1013-\t.rx_spi_alloc = mlx5e_psp_rx_spi_alloc,\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c:1014:\t.tx_key_add   = mlx5e_psp_assoc_add,\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c-1015-\t.tx_key_del   = mlx5e_psp_assoc_del,\n--\ninclude/net/psp/types.h=229=struct psp_dev_ops {\n--\ninclude/net/psp/types.h-252-\t/**\ninclude/net/psp/types.h:253:\t * @tx_key_add: add a Tx key to the device\ninclude/net/psp/types.h-254-\t * Install an association in the device. Core will allocate space\n--\ninclude/net/psp/types.h-258-\t */\ninclude/net/psp/types.h:259:\tint (*tx_key_add)(struct psp_dev *psd, struct psp_assoc *pas,\ninclude/net/psp/types.h-260-\t\t\t  struct netlink_ext_ack *extack);\n--\ninclude/net/psp/types.h-263-\t * Remove an association from the device.\ninclude/net/psp/types.h:264:\t * Can be left NULL if device does not store Tx keys and @tx_key_add\ninclude/net/psp/types.h-265-\t * is also NULL.\n--\nnet/psp/psp_main.c=61=psp_dev_create(struct net_device *netdev,\n--\nnet/psp/psp_main.c-73-\t\t    !psd_ops-\u003eget_stats ||\nnet/psp/psp_main.c:74:\t\t    (!psd_ops-\u003etx_key_add != !psd_ops-\u003etx_key_del) ||\nnet/psp/psp_main.c:75:\t\t    (psd_caps-\u003eassoc_drv_spc \u0026\u0026 !psd_ops-\u003etx_key_add) ||\nnet/psp/psp_main.c:76:\t\t    (psd_ops-\u003etx_key_add \u0026\u0026 !netdev_need_ops_lock(netdev))))\nnet/psp/psp_main.c-77-\t\treturn ERR_PTR(-EINVAL);\n--\nnet/psp/psp_sock.c=69=static struct psp_assoc *psp_assoc_dummy(struct psp_assoc *pas)\n--\nnet/psp/psp_sock.c-79-\nnet/psp/psp_sock.c:80:static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,\nnet/psp/psp_sock.c-81-\t\t\t      struct psp_key_parsed *key,\n--\nnet/psp/psp_sock.c-95-\tmemcpy(\u0026dummy-\u003etx, key, sizeof(*key));\nnet/psp/psp_sock.c:96:\terr = psd-\u003eops-\u003etx_key_add(psd, dummy, extack);\nnet/psp/psp_sock.c-97-\tif (!err) {\n--\nnet/psp/psp_sock.c=232=static int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas,\n--\nnet/psp/psp_sock.c-238-\tif (psp_dev_has_sadb(psd)) {\nnet/psp/psp_sock.c:239:\t\terr = psp_dev_tx_key_add(psd, pas, key, extack);\nnet/psp/psp_sock.c-240-\t\tif (err)\n"
}

13/2 2026/10/09 23:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 28180
							output: 21
							thoughts: 187
						

Thoughts:
**Analyzing the Patch: Matching Network Packets**

Okay, hold on a second. Let's really dig into this. What exactly is this patch *doing*? I need to understand the implications of this code change before I can assess it properly.

First, I see the modification to `include/net/psp/functions.h`. Specifically, the `psp_pse_matches_pas` function. Looks like it's used to compare a `psp_skb_ext` structure (`pse`) to a `psp_assoc` structure (`pas`). Reading the function, it seems to be checking for a match based on several fields: version, device ID (`dev_id`), and then a more complex comparison involving the Service Provider Identifier (`spi`) and generation. The core logic now accounts for both the current and the previous SPI, which suggests some kind of state management or transition. This is interesting, but I need more context. I have to understand the *purpose* of this match, what it signifies.

Now, where is this function actually *used*? I'm going to need to track down the call sites. Time to fire up the grep utility and see where `psp_pse_matches_pas` is invoked within the codebase. That's the key to understanding the full picture here.



14/2 2026/10/09 23:07 tool grepper
0m Args:
{
  "Expression": "psp_pse_matches_pas"
}

Results:
{
  "Output": "include/net/psp/functions.h=77=static inline bool\ninclude/net/psp/functions.h:78:psp_pse_matches_pas(struct psp_skb_ext *pse, struct psp_assoc *pas)\ninclude/net/psp/functions.h-79-{\n--\ninclude/net/psp/functions.h=89=__psp_sk_rx_policy_check(struct sk_buff *skb, struct psp_assoc *pas)\n--\ninclude/net/psp/functions.h-95-\ninclude/net/psp/functions.h:96:\tif (likely(psp_pse_matches_pas(pse, pas))) {\ninclude/net/psp/functions.h-97-\t\tif (unlikely(!pas-\u003epeer_tx))\n--\nnet/psp/psp_sock.c=248=static int psp_sock_recv_queue_check(struct sock *sk, struct psp_assoc *pas)\n--\nnet/psp/psp_sock.c-254-\t\tpse = skb_ext_find(skb, SKB_EXT_PSP);\nnet/psp/psp_sock.c:255:\t\tif (!psp_pse_matches_pas(pse, pas))\nnet/psp/psp_sock.c-256-\t\t\treturn -EBUSY;\n--\nnet/psp/psp_sock.c-260-\t\tpse = skb_ext_find(skb, SKB_EXT_PSP);\nnet/psp/psp_sock.c:261:\t\tif (!psp_pse_matches_pas(pse, pas))\nnet/psp/psp_sock.c-262-\t\t\treturn -EBUSY;\n"
}

15/2 2026/10/09 23:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29083
							output: 24
							thoughts: 35
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert's internal monologue:

**Investigating the Role of `__psp_sk_rx_policy_check` in Packet Handling**

Alright, so the clue is that `__psp_sk_rx_policy_check` is being invoked on incoming, or *rx*, packets. That's a good starting point. My initial thought is, what exactly does this function *do* within the networking stack? It's probably related to security policy checks for incoming traffic, but I need more context to be certain. Now, where is it called from? I need to trace the call graph. Is it invoked directly from the receive path, or is it a helper function called by a higher-level module or filter? Are there any obvious candidates like iptables rules or security modules that might be the source of these calls? I'll need to use my debugging tools and source code navigation to pinpoint the calling function(s). I need to understand the control flow to determine the impact.



16/2 2026/10/09 23:07 tool grepper
0m Args:
{
  "Expression": "__psp_sk_rx_policy_check"
}

Results:
{
  "Output": "include/net/psp/functions.h=88=static inline enum skb_drop_reason\ninclude/net/psp/functions.h:89:__psp_sk_rx_policy_check(struct sk_buff *skb, struct psp_assoc *pas)\ninclude/net/psp/functions.h-90-{\n--\ninclude/net/psp/functions.h=113=psp_sk_rx_policy_check(struct sock *sk, struct sk_buff *skb)\ninclude/net/psp/functions.h-114-{\ninclude/net/psp/functions.h:115:\treturn __psp_sk_rx_policy_check(skb, psp_sk_assoc(sk));\ninclude/net/psp/functions.h-116-}\n--\ninclude/net/psp/functions.h=119=psp_twsk_rx_policy_check(struct inet_timewait_sock *tw, struct sk_buff *skb)\ninclude/net/psp/functions.h-120-{\ninclude/net/psp/functions.h:121:\treturn __psp_sk_rx_policy_check(skb, rcu_dereference(tw-\u003epsp_assoc));\ninclude/net/psp/functions.h-122-}\n"
}

17/2 2026/10/09 23:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29681
							output: 33
							thoughts: 77
						

Thoughts:
Okay, let's break this down.

**Investigating the Policy Check in Network Processing**

Alright, so I need to figure out the call path for this `psp_sk_rx_policy_check` function. The code immediately points to the TCP/IPv4/IPv6 input processing, which makes sense. I would expect policy checks at the ingress point. Now, to understand the associated policy structures, let's explore `psp_sk_assoc_set_rx` and `psp_sock_assoc_set_tx`. Ah, Netlink handlers! That's interesting, suggesting this policy configuration is managed via userspace interaction. Now, the next logical step is to dive into `psp_nl.c` to see how those handlers are implemented. That will likely reveal the details of how the policy association is established and enforced.



18/2 2026/10/09 23:07 tool grepper
0m Args:
{
  "Expression": "psp_sock_assoc_set_rx|psp_sock_assoc_set_tx"
}

Results:
{
  "Output": "net/psp/psp.h=31=void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas);\nnet/psp/psp.h:32:int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,\nnet/psp/psp.h-33-\t\t\t  struct psp_key_parsed *key,\nnet/psp/psp.h-34-\t\t\t  struct netlink_ext_ack *extack);\nnet/psp/psp.h:35:int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,\nnet/psp/psp.h-36-\t\t\t  u32 version, struct psp_key_parsed *key,\n--\nnet/psp/psp_nl.c=803=int psp_nl_rx_assoc_doit(struct sk_buff *skb, struct genl_info *info)\n--\nnet/psp/psp_nl.c-842-\nnet/psp/psp_nl.c:843:\terr = psp_sock_assoc_set_rx(socket-\u003esk, pas, \u0026key, info-\u003eextack);\nnet/psp/psp_nl.c-844-\tif (err) {\n--\nnet/psp/psp_nl.c=859=int psp_nl_tx_assoc_doit(struct sk_buff *skb, struct genl_info *info)\n--\nnet/psp/psp_nl.c-890-\nnet/psp/psp_nl.c:891:\terr = psp_sock_assoc_set_tx(socket-\u003esk, psd, version, \u0026key,\nnet/psp/psp_nl.c-892-\t\t\t\t    info-\u003eextack);\n--\nnet/psp/psp_sock.c=162=static int psp_sock_rx_rekey(struct psp_assoc *pas, struct psp_assoc *prev,\n--\nnet/psp/psp_sock.c-192-\nnet/psp/psp_sock.c:193:int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,\nnet/psp/psp_sock.c-194-\t\t\t  struct psp_key_parsed *key,\n--\nnet/psp/psp_sock.c=297=psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,\n--\nnet/psp/psp_sock.c-338-\nnet/psp/psp_sock.c:339:int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,\nnet/psp/psp_sock.c-340-\t\t\t  u32 version, struct psp_key_parsed *key,\n"
}

19/2 2026/10/09 23:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30694
							output: 32
							thoughts: 52
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience:

**Analyzing Generic Netlink Association in the PSP Subsystem**

Alright, so I'm looking at `psp_nl_rx_assoc_doit` and `psp_nl_tx_assoc_doit`. Seems pretty straightforward, these are the generic netlink operations used within the PSP subsystem to handle associations, right? Now, before I dive too deep into the code itself, I should probably take a step back and get a handle on the bigger picture. I need to understand how the PSP subsystem is configured in this kernel build. Time to check `net/psp/Kconfig`. That'll tell me what's enabled, any dependencies, and most importantly, how this whole PSP thing gets compiled in. This gives me context before diving deeper into the functionality of these specific association operations.



20/2 2026/10/09 23:07 tool read-file
0m Args:
{
  "File": "net/psp/Kconfig",
  "FirstLine": 1,
  "LineCount": 40
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\t#\n   3:\t# PSP configuration\n   4:\t#\n   5:\tconfig INET_PSP\n   6:\t\tbool \"PSP Security Protocol support\"\n   7:\t\tdepends on INET\n   8:\t\tdepends on BQL\n   9:\t\tselect SKB_DECRYPTED\n  10:\t\tselect SKB_EXTENSIONS\n  11:\t\tselect SOCK_VALIDATE_XMIT\n  12:\t\thelp\n  13:\t\tEnable kernel support for the PSP Security Protocol (PSP).\n  14:\t\tFor more information see:\n  15:\t\t  https://raw.githubusercontent.com/google/psp/main/doc/PSP_Arch_Spec.pdf\n  16:\t\n  17:\t\tIf unsure, say N.\n"
}

21/2 2026/10/09 23:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 31175
							output: 18
							thoughts: 23
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach this task, summarizing the given thought process from my expert perspective:

**Investigating netdevsim and PSP**

Right, so I need to figure out how `netdevsim` handles Packet Steering (PSP). My first instinct is to dive into the configuration. The question isn't *if* it's enabled, but *how*. I need to pinpoint the `Kconfig` options related to PSP within the `netdevsim` subsystem. Knowing where those configuration options reside is key, so I'll be looking for relevant `Kconfig` entries. That'll give me the building blocks to understand the underlying implementation and where the hooks for Packet Steering live. This should give me a solid foundation.



22/2 2026/10/09 23:07 tool grepper
0m Args:
{
  "Expression": "NETDEVSIM"
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 220 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (22 files in total):\nMAINTAINERS:1\ndrivers/net/Kconfig:1\ndrivers/net/Makefile:1\ndrivers/net/netdevsim/Makefile:1\ntools/net/ynl/tests/config:1\ntools/testing/selftests/bpf/config:1\ntools/testing/selftests/drivers/net/bonding/config:1\ntools/testing/selftests/drivers/net/config:1\ntools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh:1\ntools/testing/selftests/drivers/net/netconsole/config:1\ntools/testing/selftests/drivers/net/netdevsim/config:1\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:10\ntools/testing/selftests/drivers/net/netdevsim/fib.sh:3\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh:3\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh:3\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh:3\ntools/testing/selftests/drivers/net/netdevsim/psample.sh:3\ntools/testing/selftests/drivers/net/team/config:1\ntools/testing/selftests/net/config:1\ntools/testing/selftests/net/drop_monitor_tests.sh:4\ntools/testing/selftests/net/netfilter/config:1\ntools/testing/selftests/tc-testing/config:1\n\nMAINTAINERS=18838=F:\ttools/testing/selftests/drivers/net/netconsole/\nMAINTAINERS-18839-\nMAINTAINERS:18840:NETDEVSIM\nMAINTAINERS-18841-M:\tJakub Kicinski \u003ckuba@kernel.org\u003e\n--\ndrivers/net/Kconfig=602=source \"drivers/net/hyperv/Kconfig\"\ndrivers/net/Kconfig-603-\ndrivers/net/Kconfig:604:config NETDEVSIM\ndrivers/net/Kconfig-605-\ttristate \"Simulated networking device\"\n--\ndrivers/net/Makefile=86=obj-$(CONFIG_USB4_NET) += thunderbolt/\ndrivers/net/Makefile:87:obj-$(CONFIG_NETDEVSIM) += netdevsim/\ndrivers/net/Makefile-88-obj-$(CONFIG_NET_FAILOVER) += net_failover.o\n--\ndrivers/net/netdevsim/Makefile-2-\ndrivers/net/netdevsim/Makefile:3:obj-$(CONFIG_NETDEVSIM) += netdevsim.o\ndrivers/net/netdevsim/Makefile-4-\n--\ntools/net/ynl/tests/config=10=CONFIG_NET_SCHED=y\ntools/net/ynl/tests/config:11:CONFIG_NETDEVSIM=m\ntools/net/ynl/tests/config-12-CONFIG_NETKIT=y\n--\ntools/testing/selftests/bpf/config=86=CONFIG_NET_SCHED=y\ntools/testing/selftests/bpf/config:87:CONFIG_NETDEVSIM=y\ntools/testing/selftests/bpf/config-88-CONFIG_NETFILTER=y\n--\ntools/testing/selftests/drivers/net/bonding/config=15=CONFIG_NETCONSOLE_EXTENDED_LOG=y\ntools/testing/selftests/drivers/net/bonding/config:16:CONFIG_NETDEVSIM=m\ntools/testing/selftests/drivers/net/bonding/config-17-CONFIG_NET_IPGRE=y\n--\ntools/testing/selftests/drivers/net/config=15=CONFIG_NETCONSOLE_EXTENDED_LOG=y\ntools/testing/selftests/drivers/net/config:16:CONFIG_NETDEVSIM=m\ntools/testing/selftests/drivers/net/config-17-CONFIG_NETKIT=y\n--\ntools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh=300=function check_for_dependencies() {\n--\ntools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh-326-\tif [ ! -f \"${NSIM_DEV_SYS_NEW}\" ]; then\ntools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh:327:\t\techo \"SKIP: file ${NSIM_DEV_SYS_NEW} does not exist. Check if CONFIG_NETDEVSIM is enabled\" \u003e\u00262\ntools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh-328-\t\texit \"${ksft_skip}\"\n--\ntools/testing/selftests/drivers/net/netconsole/config=5=CONFIG_NETCONSOLE_EXTENDED_LOG=y\ntools/testing/selftests/drivers/net/netconsole/config:6:CONFIG_NETDEVSIM=m\n--\ntools/testing/selftests/drivers/net/netdevsim/config=4=CONFIG_MACSEC=m\ntools/testing/selftests/drivers/net/netdevsim/config:5:CONFIG_NETDEVSIM=m\ntools/testing/selftests/drivers/net/netdevsim/config-6-CONFIG_NET_SCH_MQPRIO=y\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh=9=ALL_TESTS=\"\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-23-\"\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:24:NETDEVSIM_PATH=/sys/bus/netdevsim/\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-25-DEV_ADDR=1337\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh=39=modprobe netdevsim \u0026\u003e /dev/null\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:40:if [ ! -d \"$NETDEVSIM_PATH\" ]; then\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-41-\techo \"SKIP: No netdevsim support\"\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh=43=fi\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-44-\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:45:if [ -d \"${NETDEVSIM_PATH}/devices/netdevsim${DEV_ADDR}\" ]; then\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-46-\techo \"SKIP: Device netdevsim${DEV_ADDR} already exists\"\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh=457=netdevsim_dev_create()\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-458-{\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:459:\techo \"$DEV_ADDR 0\" \u003e ${NETDEVSIM_PATH}/new_device\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-460-}\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh=462=netdevsim_dev_destroy()\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-463-{\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:464:\techo \"$DEV_ADDR\" \u003e ${NETDEVSIM_PATH}/del_device\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-465-}\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh=467=netdevsim_port_create()\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-468-{\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:469:\techo 1 \u003e ${NETDEVSIM_PATH}/devices/${DEV}/new_port\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-470-}\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh=472=netdevsim_port_destroy()\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-473-{\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:474:\techo 1 \u003e ${NETDEVSIM_PATH}/devices/${DEV}/del_port\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-475-}\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh=477=setup_prepare()\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-482-\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:483:\tif [ ! -d \"${NETDEVSIM_PATH}/devices/${DEV}\" ]; then\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-484-\t\techo \"Failed to create netdevsim device\"\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-489-\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:490:\tif [ ! -d \"${NETDEVSIM_PATH}/devices/${DEV}/net/\" ]; then\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-491-\t\techo \"Failed to create netdevsim port\"\n--\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-497-\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh:498:\tNETDEV=$(ls ${NETDEVSIM_PATH}/devices/${DEV}/net/)\ntools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh-499-}\n--\ntools/testing/selftests/drivers/net/netdevsim/fib.sh=9=ALL_TESTS=\"\n--\ntools/testing/selftests/drivers/net/netdevsim/fib.sh-34-\"\ntools/testing/selftests/drivers/net/netdevsim/fib.sh:35:NETDEVSIM_PATH=/sys/bus/netdevsim/\ntools/testing/selftests/drivers/net/netdevsim/fib.sh-36-DEV_ADDR=1337\n--\ntools/testing/selftests/drivers/net/netdevsim/fib.sh=362=setup_prepare()\n--\ntools/testing/selftests/drivers/net/netdevsim/fib.sh-367-\ntools/testing/selftests/drivers/net/netdevsim/fib.sh:368:\techo \"$DEV_ADDR 1\" \u003e ${NETDEVSIM_PATH}/new_device\ntools/testing/selftests/drivers/net/netdevsim/fib.sh-369-\twhile [ ! -d $SYSFS_NET_DIR ] ; do :; done\n--\ntools/testing/selftests/drivers/net/netdevsim/fib.sh=384=cleanup()\n--\ntools/testing/selftests/drivers/net/netdevsim/fib.sh-387-\tip netns del testns1\ntools/testing/selftests/drivers/net/netdevsim/fib.sh:388:\techo \"$DEV_ADDR\" \u003e ${NETDEVSIM_PATH}/del_device\ntools/testing/selftests/drivers/net/netdevsim/fib.sh-389-\tmodprobe -r netdevsim \u0026\u003e /dev/null\n--\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh=6=ALL_TESTS=\"\n--\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh-16-\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh:17:NETDEVSIM_PATH=/sys/bus/netdevsim/\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh-18-DEV_ADDR=1337\n--\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh=388=setup_prepare()\n--\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh-390-\tmodprobe netdevsim \u0026\u003e /dev/null\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh:391:\techo \"$DEV_ADDR 1\" \u003e ${NETDEVSIM_PATH}/new_device\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh-392-\twhile [ ! -d $SYSFS_NET_DIR ] ; do :; done\n--\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh=414=cleanup()\n--\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh-419-\tip netns del testns1\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh:420:\techo \"$DEV_ADDR\" \u003e ${NETDEVSIM_PATH}/del_device\ntools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh-421-\tmodprobe -r netdevsim \u0026\u003e /dev/null\n--\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh=6=ALL_TESTS=\"\n--\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh-13-\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh:14:NETDEVSIM_PATH=/sys/bus/netdevsim/\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh-15-DEV_ADDR_1=1337\n--\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh=51=nsim_add()\n--\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh-54-\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh:55:\techo \"$(DEV_ADDR $n) 1\" \u003e ${NETDEVSIM_PATH}/new_device\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh-56-\twhile [ ! -d $(SYSFS_NET_DIR $n) ] ; do :; done\n--\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh=73=nsim_del()\n--\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh-76-\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh:77:\techo \"$(DEV_ADDR $n)\" \u003e ${NETDEVSIM_PATH}/del_device\ntools/testing/selftests/drivers/net/netdevsim/hw_stats_l3.sh-78-}\n--\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh=9=ALL_TESTS=\"\n--\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh-43-\"\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh:44:NETDEVSIM_PATH=/sys/bus/netdevsim/\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh-45-DEV_ADDR=1337\n--\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh=1021=setup_prepare()\n--\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh-1026-\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh:1027:\techo \"$DEV_ADDR 1\" \u003e ${NETDEVSIM_PATH}/new_device\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh-1028-\twhile [ ! -d $SYSFS_NET_DIR ] ; do :; done\n--\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh=1044=cleanup()\n--\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh-1047-\tip netns del testns1\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh:1048:\techo \"$DEV_ADDR\" \u003e ${NETDEVSIM_PATH}/del_device\ntools/testing/selftests/drivers/net/netdevsim/nexthop.sh-1049-\tmodprobe -r netdevsim \u0026\u003e /dev/null\n--\ntools/testing/selftests/drivers/net/netdevsim/psample.sh=9=ALL_TESTS=\"\n--\ntools/testing/selftests/drivers/net/netdevsim/psample.sh-13-\"\ntools/testing/selftests/drivers/net/netdevsim/psample.sh:14:NETDEVSIM_PATH=/sys/bus/netdevsim/\ntools/testing/selftests/drivers/net/netdevsim/psample.sh-15-DEV_ADDR=1337\n--\ntools/testing/selftests/drivers/net/netdevsim/psample.sh=153=setup_prepare()\n--\ntools/testing/selftests/drivers/net/netdevsim/psample.sh-156-\ntools/testing/selftests/drivers/net/netdevsim/psample.sh:157:\techo \"$DEV_ADDR 1\" \u003e ${NETDEVSIM_PATH}/new_device\ntools/testing/selftests/drivers/net/netdevsim/psample.sh-158-\twhile [ ! -d $SYSFS_NET_DIR ] ; do :; done\n--\ntools/testing/selftests/drivers/net/netdevsim/psample.sh=168=cleanup()\n--\ntools/testing/selftests/drivers/net/netdevsim/psample.sh-172-\tip netns del testns1\ntools/testing/selftests/drivers/net/netdevsim/psample.sh:173:\techo \"$DEV_ADDR\" \u003e ${NETDEVSIM_PATH}/del_device\ntools/testing/selftests/drivers/net/netdevsim/psample.sh-174-\tmodprobe -r netdevsim \u0026\u003e /dev/null\n--\ntools/testing/selftests/drivers/net/team/config=4=CONFIG_MACVLAN=y\ntools/testing/selftests/drivers/net/team/config:5:CONFIG_NETDEVSIM=m\ntools/testing/selftests/drivers/net/team/config-6-CONFIG_NET_IPGRE=y\n--\ntools/testing/selftests/net/config=80=CONFIG_NET_CLS_U32=m\ntools/testing/selftests/net/config:81:CONFIG_NETDEVSIM=m\ntools/testing/selftests/net/config-82-CONFIG_NET_DROP_MONITOR=m\n--\ntools/testing/selftests/net/drop_monitor_tests.sh=9=TESTS=\"\n--\ntools/testing/selftests/net/drop_monitor_tests.sh-13-\ntools/testing/selftests/net/drop_monitor_tests.sh:14:NETDEVSIM_PATH=/sys/bus/netdevsim/\ntools/testing/selftests/net/drop_monitor_tests.sh-15-DEV_ADDR=1337\n--\n\n"
}

23/2 2026/10/09 23:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36647
							output: 26
							thoughts: 38
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:

**Investigating Netdevsim and PSP Dependencies**

Alright, I'm thinking I need to understand the connection between `netdevsim` and `psp` within this kernel configuration context. My immediate focus would be on the Kconfig files. I'm going to jump into either `drivers/net/netdevsim/Kconfig` or, for a broader perspective, `drivers/net/Kconfig`. The goal is to see how `netdevsim` itself either directly depends on a `psp` feature or module, or potentially includes configurations that then pull in `psp`. I want to identify any relationships, dependencies, or source code integrations between the two modules. I'm looking for direct dependencies, inclusion statements, or conditional compilation directives within the Kconfig files. This should give me a clear picture of how they interact and where `psp` is enabled, disabled, or conditionally configured based on `netdevsim`'s presence.



24/2 2026/10/09 23:07 tool grepper
0m Args:
{
  "Expression": "INET_PSP",
  "PathPrefixes": [
    "drivers/"
  ]
}

Results:
{
  "Output": "drivers/net/ethernet/mellanox/mlx5/core/Kconfig=210=config MLX5_EN_PSP\ndrivers/net/ethernet/mellanox/mlx5/core/Kconfig-211-\tbool \"Mellanox Technologies support for PSP cryptography-offload acceleration\"\ndrivers/net/ethernet/mellanox/mlx5/core/Kconfig:212:\tdepends on INET_PSP\ndrivers/net/ethernet/mellanox/mlx5/core/Kconfig-213-\tdepends on MLX5_CORE_EN\n--\ndrivers/net/netdevsim/Makefile=19=endif\ndrivers/net/netdevsim/Makefile-20-\ndrivers/net/netdevsim/Makefile:21:ifneq ($(CONFIG_INET_PSP),)\ndrivers/net/netdevsim/Makefile-22-netdevsim-objs += psp.o\n--\ndrivers/net/netdevsim/netdevsim.h=447=static inline void nsim_macsec_teardown(struct netdevsim *ns)\n--\ndrivers/net/netdevsim/netdevsim.h-451-\ndrivers/net/netdevsim/netdevsim.h:452:#if IS_ENABLED(CONFIG_INET_PSP)\ndrivers/net/netdevsim/netdevsim.h-453-int nsim_psp_init(struct netdevsim *ns);\n"
}

25/2 2026/10/09 23:08 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37286
							output: 22
							thoughts: 1607
						

Thoughts:
**Analyzing the PSP Patch: A Detailed Dive**

Okay, so I see this patch is conditional, tied to `CONFIG_INET_PSP`, and that `netdevsim` integrates with it. My first thought is to understand the changes in `net/psp/`. It looks like this is a substantial refactoring/addition to the PSP (probably for the security aspect of the code!)

1.  In `include/net/psp/functions.h`, the `psp_pse_matches_pas` function has been refined. It now has a more robust matching check, especially for cases when `pas->rx.spi == pse->spi && pas->generation == pse->generation` or the prev equivalent. This signals a tighter control over how PSP associations are validated.

2.  `include/net/psp/types.h` presents a more significant shift. There's the addition of `tx_del` to `struct psp_dev`, which suggests a deferred or delayed mechanism for handling TX keys. The struct contains a list head, work structure and a pointer to the TXQ state which points to a deferred workqueue. Along with that, new stats `stats.tx_key_cnt`, new flags `PSP_ASSOC_SKIP_TX_KEY_DEL`, and the associated flag `PSP_ASSOC_DEFER_TX_KEY_DEL` are added, that influence the overall TX key management flow. Additionally, the struct `psp_assoc` now also includes `prev_generation`, `flags`, and `prev_spi`, indicating more refined association tracking and control.

3.  `include/uapi/linux/psp.h` adds the `PSP_A_STATS_TX_KEY_COUNT` which should be a new metric being exposed to userspace.

4.  In `net/psp/Kconfig`, I see that `INET_PSP` now depends on `BQL` (Byte Queue Limits). This implies some kind of dependency on traffic shaping or queuing mechanisms.

5.  The `net/psp/Makefile` introduces `psp_deferred_del.o`, which is related to the aforementioned deferred TX key deletion.

6.  In `net/psp/psp.h` there are new functions: `psp_deferred_del_init`, `psp_deferred_del_stop`, `psp_deferred_del_uninit`, and `psp_deferred_del_queue`. These provide the deferred deletion management. The `psp_assoc_needs_tx_key_del` function has been updated to consider whether `PSP_ASSOC_SKIP_TX_KEY_DEL` flag is set.

7.  `net/psp/psp_deferred_del.c` implements the delayed workqueue, `psp_deferred_del_work`. It appears to be monitoring BQL progress to defer key deletion until packets have drained, which makes a lot of sense, preventing use-after-free issues.

8.  `net/psp/psp_main.c` now has some checks for `psd_ops->tx_key_add` along with `netdev_need_ops_lock`. It calls `psp_deferred_del_init`, and has cleanup on failure. Also, on unregister, it calls `psp_deferred_del_stop`, `psp_deferred_del_uninit`. There is also a warning if there are any tx_keys remaining.

9.  `net/psp/psp_nl.c` reports `PSP_A_STATS_TX_KEY_COUNT` via netlink if `psp_dev_has_sadb(psd)`.

10. In `net/psp/psp_sock.c`, the code tracks `psd->stats.tx_key_cnt`, with warnings if the count goes negative, confirming the key count is consistent. The `psp_assoc_free` function now checks if the TX key needs to be deleted, and if deferral is needed (through `PSP_ASSOC_DEFER_TX_KEY_DEL`). The interesting part is the addition of `psp_sock_rx_rekey`. This function is invoked when an existing socket association needs to be updated. It checks for a mismatch, version difference and checks the SPI. Crucially, if everything is correct, the existing association's `PSP_ASSOC_SKIP_TX_KEY_DEL` flag is set. Then, `psp_sock_tx_rekey` is similar, using the `PSP_ASSOC_DEFER_TX_KEY_DEL` flag. Also, `psp_assocs_key_rotated` has been updated to ensure an appropriate value is set in `pas->prev_generation`.

    Then I started wondering... what is `psp_dev_has_sadb`? Time to grep and find out what that means!



26/2 2026/10/09 23:08 tool grepper
0m Args:
{
  "Expression": "psp_dev_has_sadb"
}

Results:
{
  "Output": "net/psp/psp.h=56=static inline bool psp_dev_is_registered(struct psp_dev *psd)\n--\nnet/psp/psp.h-61-\nnet/psp/psp.h:62:static inline bool psp_dev_has_sadb(struct psp_dev *psd)\nnet/psp/psp.h-63-{\n--\nnet/psp/psp.h=68=static inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas)\n--\nnet/psp/psp.h-70-\tlockdep_assert_held(\u0026pas-\u003epsd-\u003elock);\nnet/psp/psp.h:71:\treturn psp_dev_has_sadb(pas-\u003epsd) \u0026\u0026 pas-\u003etx.spi \u0026\u0026\nnet/psp/psp.h-72-\t       !(pas-\u003eflags \u0026 PSP_ASSOC_SKIP_TX_KEY_DEL);\n--\nnet/psp/psp_nl.c=904=psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp,\n--\nnet/psp/psp_nl.c-936-\nnet/psp/psp_nl.c:937:\tif (psp_dev_has_sadb(psd) \u0026\u0026\nnet/psp/psp_nl.c-938-\t    nla_put_uint(rsp, PSP_A_STATS_TX_KEY_COUNT, psd-\u003estats.tx_key_cnt))\n--\nnet/psp/psp_sock.c=232=static int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas,\n--\nnet/psp/psp_sock.c-237-\nnet/psp/psp_sock.c:238:\tif (psp_dev_has_sadb(psd)) {\nnet/psp/psp_sock.c-239-\t\terr = psp_dev_tx_key_add(psd, pas, key, extack);\n"
}

27/2 2026/10/09 23:08 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40448
							output: 34
							thoughts: 17
						

Thoughts:
Okay, let's see what I can do here.

**Analyzing `psp_dev_has_sadb` Return Value**

Alright, let's get down to brass tacks. I'm taking a look at this `psp_dev_has_sadb` function call. I need to understand what this function is actually doing and what its return value signifies. Based on the naming convention, I suspect it's related to some Secure Association Database (SADB) check, probably regarding a particular "psp_dev" device. I'm betting the return value will be a boolean or a bitmask, indicating whether the device has a valid SADB entry or some specific SADB capabilities enabled. If it is returning a non-zero value, what does this indicate to me and the current operation? Does the device have a specific SADB entry that needs verification, or is it indicating something more complex? I need to understand the implications of this return value within the broader context of the system architecture to see how it shapes the next steps. I'm going to have to dive into the documentation, or even the source code if necessary, to get a clear picture of its intended use. Let's see what the documentation tells me.



28/2 2026/10/09 23:08 tool read-file
0m Args:
{
  "File": "net/psp/psp.h",
  "FirstLine": 55,
  "LineCount": 25
}

Results:
{
  "Contents": "  55:\t\n  56:\tstatic inline bool psp_dev_is_registered(struct psp_dev *psd)\n  57:\t{\n  58:\t\tlockdep_assert_held(\u0026psd-\u003elock);\n  59:\t\treturn !!psd-\u003eops;\n  60:\t}\n  61:\t\n  62:\tstatic inline bool psp_dev_has_sadb(struct psp_dev *psd)\n  63:\t{\n  64:\t\tlockdep_assert_held(\u0026psd-\u003elock);\n  65:\t\treturn !!psd-\u003eops-\u003etx_key_del;\n  66:\t}\n  67:\t\n  68:\tstatic inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas)\n  69:\t{\n  70:\t\tlockdep_assert_held(\u0026pas-\u003epsd-\u003elock);\n  71:\t\treturn psp_dev_has_sadb(pas-\u003epsd) \u0026\u0026 pas-\u003etx.spi \u0026\u0026\n  72:\t\t       !(pas-\u003eflags \u0026 PSP_ASSOC_SKIP_TX_KEY_DEL);\n  73:\t}\n  74:\t\n  75:\t#endif /* __PSP_PSP_H */\n"
}

29/2 2026/10/09 23:08 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 41077
							output: 37
							thoughts: 355
						

Thoughts:
**Analyzing the PSP Driver's Key Management**

Okay, so `psp_dev_has_sadb(psd)` boils down to `!!psd->ops->tx_key_del;`. That makes sense, but the immediate question is, who actually *defines* `psd->ops->tx_key_del`? My initial instinct is to track back, especially since we were just looking for functions like `tx_key_add`. From earlier searches, it looks like the Mellanox driver (`drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c`) is a likely candidate, along with `netdevsim`.

Now, does `netdevsim` come into play with the key management? Let me dig into the `netdevsim/psp.c` file. Ah, `nsim_psp_ops` is defined there, and looking at the structure… nope. No `tx_key_del` or `tx_key_add` in sight. So, `netdevsim` doesn't directly support these key operations.

However, that doesn't mean `netdevsim` can't *indirectly* be involved. Could the socket rekeying functions, like `psp_sock_rx_rekey` and `psp_sock_tx_rekey`, be reachable in a `netdevsim` scenario? That's the next avenue to explore. Let me check `psp_sock_tx_rekey` in `net/psp/psp_sock.c` to see how it's used. Time to read through `psp_sock_assoc_set_tx` and `psp_sock_tx_rekey` to understand this.



30/2 2026/10/09 23:08 tool read-file
0m Args:
{
  "File": "net/psp/psp_sock.c",
  "FirstLine": 290,
  "LineCount": 85
}

Results:
{
  "Contents": " 290:\t\ticsk-\u003eicsk_ext_hdr_len += psp_sk_overhead(sk);\n 291:\t\ticsk-\u003eicsk_sync_mss(sk, icsk-\u003eicsk_pmtu_cookie);\n 292:\t\n 293:\t\treturn err;\n 294:\t}\n 295:\t\n 296:\tstatic int\n 297:\tpsp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,\n 298:\t\t\t  struct psp_key_parsed *key, struct netlink_ext_ack *extack)\n 299:\t{\n 300:\t\tstruct psp_assoc *new;\n 301:\t\tint err;\n 302:\t\n 303:\t\tif (!pas-\u003epeer_tx) {\n 304:\t\t\tNL_SET_ERR_MSG(extack, \"Socket PSP state is not fully established\");\n 305:\t\t\treturn -EBUSY;\n 306:\t\t}\n 307:\t\n 308:\t\tnew = kzalloc_flex(*new, drv_data, psd-\u003ecaps-\u003eassoc_drv_spc,\n 309:\t\t\t\t   GFP_KERNEL_ACCOUNT);\n 310:\t\tif (!new)\n 311:\t\t\treturn -ENOMEM;\n 312:\t\n 313:\t\tnew-\u003epsd             = pas-\u003epsd;\n 314:\t\tnew-\u003edev_id          = pas-\u003edev_id;\n 315:\t\tnew-\u003egeneration      = pas-\u003egeneration;\n 316:\t\tnew-\u003eversion         = pas-\u003eversion;\n 317:\t\tnew-\u003epeer_tx         = 1;\n 318:\t\tnew-\u003eprev_spi        = pas-\u003eprev_spi;\n 319:\t\tnew-\u003eprev_generation = pas-\u003eprev_generation;\n 320:\t\trefcount_set(\u0026new-\u003erefcnt, 1);\n 321:\t\tmemcpy(\u0026new-\u003erx, \u0026pas-\u003erx, sizeof(new-\u003erx));\n 322:\t\n 323:\t\terr = psp_assoc_set_tx(psd, new, key, extack);\n 324:\t\tif (err) {\n 325:\t\t\tkfree(new);\n 326:\t\t\treturn err;\n 327:\t\t}\n 328:\t\n 329:\t\tpsp_dev_get(new-\u003epsd);\n 330:\t\tlist_add(\u0026new-\u003eassocs_list, \u0026pas-\u003eassocs_list);\n 331:\t\n 332:\t\trcu_assign_pointer(sk-\u003epsp_assoc, new);\n 333:\t\tpas-\u003eflags |= PSP_ASSOC_DEFER_TX_KEY_DEL;\n 334:\t\tpsp_assoc_put(pas);\n 335:\t\n 336:\t\treturn 0;\n 337:\t}\n 338:\t\n 339:\tint psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,\n 340:\t\t\t\t  u32 version, struct psp_key_parsed *key,\n 341:\t\t\t\t  struct netlink_ext_ack *extack)\n 342:\t{\n 343:\t\tstruct psp_assoc *pas;\n 344:\t\tint err;\n 345:\t\n 346:\t\tlock_sock(sk);\n 347:\t\n 348:\t\tif (sk-\u003esk_state != TCP_ESTABLISHED) {\n 349:\t\t\tNL_SET_ERR_MSG(extack, \"Socket must be in established state\");\n 350:\t\t\terr = -ENOTCONN;\n 351:\t\t\tgoto exit_unlock;\n 352:\t\t}\n 353:\t\n 354:\t\tpas = psp_sk_assoc(sk);\n 355:\t\tif (!pas) {\n 356:\t\t\tNL_SET_ERR_MSG(extack, \"Socket has no Rx key\");\n 357:\t\t\terr = -EINVAL;\n 358:\t\t\tgoto exit_unlock;\n 359:\t\t}\n 360:\t\tif (pas-\u003epsd != psd) {\n 361:\t\t\tNL_SET_ERR_MSG(extack, \"Rx key from different device\");\n 362:\t\t\terr = -EINVAL;\n 363:\t\t\tgoto exit_unlock;\n 364:\t\t}\n 365:\t\tif (pas-\u003eversion != version) {\n 366:\t\t\tNL_SET_ERR_MSG(extack,\n 367:\t\t\t\t       \"PSP version mismatch with existing state\");\n 368:\t\t\terr = -EINVAL;\n 369:\t\t\tgoto exit_unlock;\n 370:\t\t}\n 371:\t\tif (pas-\u003etx.spi)\n 372:\t\t\terr = psp_sock_tx_rekey(sk, psd, pas, key, extack);\n 373:\t\telse\n 374:\t\t\terr = psp_sock_set_tx_key(sk, psd, pas, key, extack);\n"
}

31/2 2026/10/09 23:08 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43166
							output: 41
							thoughts: 1147
						

Thoughts:
**Analyzing the PSP Rekeying Logic and its Implications**

Okay, so I'm digging into this `psp_sock_tx_rekey` function and I see a potentially interesting pattern here. It's triggered whenever `pas->tx.spi` is already non-zero, right? That suggests it's being called on subsequent associations. And in `psp_assoc_set_tx`, I noticed that even if `psp_dev_has_sadb` returns false (like it would with `netdevsim`), the `pas->tx.spi` is still getting populated! This means a subsequent call to `psp_sock_assoc_set_tx` on the same socket will hit the `psp_sock_tx_rekey` path.

Then, the plot thickens with what happens inside `psp_sock_tx_rekey`. We're setting `PSP_ASSOC_DEFER_TX_KEY_DEL` and calling `psp_assoc_put`. Later, when `psp_assoc` is freed via `psp_assoc_free`, we see that `psp_dev_tx_key_del` will be called IF `psp_dev_has_sadb` is true *and* `pas->tx.spi` is non-zero, but `!PSP_ASSOC_SKIP_TX_KEY_DEL`.

Hang on! If `psp_dev_has_sadb` is FALSE, then `psp_assoc_needs_tx_key_del` will be false, preventing the call to `psp_dev_tx_key_del`. Is there something else setting tx_key_del? That's when it hit me... the `tx_key_del` is specifically set by `mlx5`! But does that mean it's only in this case? Is MLX5 hardware even accessible in standard virtualized environments? MLX5 is Mellanox ConnectX hardware. That's a physical ASIC/PCIe card, based on section 2 of the prompt.

Wait, what about the scope of the patch? Is this limited to mlx5, or is PSP a core networking feature? I need to check section 2 and 3 again. `net/psp/` is under `net/`, so it's a core networking protocol: PSP Security Protocol. So it's not mlx5 only, it is PSP.

Let's check the commit. The commit modifies `include/net/psp/functions.h`, `include/net/psp/types.h`, `include/uapi/linux/psp.h`, `net/psp/Kconfig`, `net/psp/Makefile`, `net/psp/psp.h`, `net/psp/psp_deferred_del.c`, `net/psp/psp_main.c`, `net/psp/psp_nl.c`, `net/psp/psp_sock.c`.

Okay, can a user actually run PSP in QEMU? Yes, `netdevsim` supports PSP! Can `rekey` even be executed with `netdevsim`? The proof is in the self-test, right? I need to check `tools/testing/selftests/drivers/net/psp.py` in the commit diff. Let's see how the selftest runs. I have to see what device it uses!



32/2 2026/10/09 23:09 tool read-file
0m Args:
{
  "File": "tools/testing/selftests/drivers/net/psp.py",
  "FirstLine": 1,
  "LineCount": 70
}

Results:
{
  "Contents": "   1:\t#!/usr/bin/env python3\n   2:\t# SPDX-License-Identifier: GPL-2.0\n   3:\t\n   4:\t\"\"\"Test suite for PSP capable drivers.\"\"\"\n   5:\t\n   6:\timport errno\n   7:\timport fcntl\n   8:\timport os\n   9:\timport socket\n  10:\timport struct\n  11:\timport termios\n  12:\timport time\n  13:\t\n  14:\tfrom contextlib import contextmanager\n  15:\t\n  16:\tfrom lib.py import defer\n  17:\tfrom lib.py import ksft_run, ksft_exit, ksft_pr\n  18:\tfrom lib.py import ksft_true, ksft_eq, ksft_ne, ksft_ge, ksft_gt, ksft_raises\n  19:\tfrom lib.py import ksft_not_none\n  20:\tfrom lib.py import ksft_variants, KsftNamedVariant\n  21:\tfrom lib.py import KsftSkipEx, KsftFailEx\n  22:\tfrom lib.py import NetDrvEpEnv, NetDrvContEnv\n  23:\tfrom lib.py import Netlink, NlError, PSPFamily, RtnlFamily\n  24:\tfrom lib.py import NetNSEnter\n  25:\tfrom lib.py import bkg, rand_port, wait_port_listen\n  26:\tfrom lib.py import ip\n  27:\t\n  28:\tTCP_ULP = 31\n  29:\t\n  30:\t\n  31:\t_PSP_MAX_KEY_LEN = 32\n  32:\t_PSP_ASSOC_MSG = f'!IB3x{_PSP_MAX_KEY_LEN}s'\n  33:\t_TX_REKEY_ROUNDS = 20\n  34:\t_TX_KEY_DRAIN_TIMEOUT = 5\n  35:\t\n  36:\t\n  37:\tdef _get_outq(s):\n  38:\t    one = b'\\0' * 4\n  39:\t    outq = fcntl.ioctl(s.fileno(), termios.TIOCOUTQ, one)\n  40:\t    return struct.unpack(\"I\", outq)[0]\n  41:\t\n  42:\t\n  43:\tdef _send_with_ack(cfg, msg):\n  44:\t    cfg.comm_sock.send(msg)\n  45:\t    response = cfg.comm_sock.recv(4)\n  46:\t    if response != b'ack\\0':\n  47:\t        raise RuntimeError(\"Unexpected server response\", response)\n  48:\t\n  49:\t\n  50:\tdef _remote_read_len(cfg):\n  51:\t    cfg.comm_sock.send(b'read len\\0')\n  52:\t    return int(cfg.comm_sock.recv(1024)[:-1].decode('utf-8'))\n  53:\t\n  54:\t\n  55:\tdef _make_clr_conn(cfg, ipver=None):\n  56:\t    _send_with_ack(cfg, b'conn clr\\0')\n  57:\t    remote_addr = cfg.remote_addr_v[ipver] if ipver else cfg.remote_addr\n  58:\t    s = socket.create_connection((remote_addr, cfg.comm_port), )\n  59:\t    return s\n  60:\t\n  61:\t\n  62:\tdef _make_psp_conn(cfg, version=0, ipver=None):\n  63:\t    _send_with_ack(cfg, b'conn psp\\0' + struct.pack('BB', version, version))\n  64:\t    remote_addr = cfg.remote_addr_v[ipver] if ipver else cfg.remote_addr\n  65:\t    s = socket.create_connection((remote_addr, cfg.comm_port), )\n  66:\t    return s\n  67:\t\n  68:\t\n  69:\t@contextmanager\n  70:\tdef _make_lo_conn():\n"
}

33/2 2026/10/09 23:09 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46132
							output: 42
							thoughts: 29
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Analyzing the Connection Handling in `psp.py`**

Alright, let's dive right in. The core of this connection logic is in that `_make_lo_conn` function, which, I suspect, is the heart of establishing the low-level connection. I'm especially interested in how it handles the details, so I'm honing in on lines 70 through 100 within `psp.py`. That range should reveal how the low level details are being handled. I'm focusing on that area to get a clear picture of its error handling, resource management, and any potential threading considerations. Understanding that section will be key to grasp the overall reliability and performance implications. Let's see what gems are hidden there.



34/2 2026/10/09 23:09 tool read-file
0m Args:
{
  "File": "tools/testing/selftests/drivers/net/psp.py",
  "FirstLine": 70,
  "LineCount": 40
}

Results:
{
  "Contents": "  70:\tdef _make_lo_conn():\n  71:\t    # After tx-assoc, the client's egress is dropped, since lo has no\n  72:\t    # psp_dev, so its FIN never reaches the server. Closing the server\n  73:\t    # resets the unaccepted child, and the client accepts the cleartext\n  74:\t    # RST because it hasn't received any PSP traffic yet.\n  75:\t    with socket.create_server((\"localhost\", 0)) as srv, \\\n  76:\t         socket.create_connection(srv.getsockname()[:2]) as s:\n  77:\t        yield s\n  78:\t\n  79:\t\n  80:\tdef _close_conn(cfg, s):\n  81:\t    _send_with_ack(cfg, b'data close\\0')\n  82:\t    s.close()\n  83:\t\n  84:\t\n  85:\tdef _close_psp_conn(cfg, s):\n  86:\t    _close_conn(cfg, s)\n  87:\t\n  88:\t\n  89:\tdef _recv_all(s, target):\n  90:\t    data = b''\n  91:\t    while len(data) \u003c target:\n  92:\t        chunk = s.recv(target - len(data))\n  93:\t        if not chunk:\n  94:\t            raise KsftFailEx(f\"peer closed after {len(data)} of {target} bytes\")\n  95:\t        data += chunk\n  96:\t    return data\n  97:\t\n  98:\t\n  99:\tdef _psp_key_len(version):\n 100:\t    return 16 if version in (0, 2) else 32\n 101:\t\n 102:\t\n 103:\tdef _remote_rx_assoc(cfg):\n 104:\t    _send_with_ack(cfg, b'rx assoc\\0')\n 105:\t    msg = _recv_all(cfg.comm_sock, struct.calcsize(_PSP_ASSOC_MSG))\n 106:\t    spi, version, key = struct.unpack(_PSP_ASSOC_MSG, msg)\n 107:\t    return version, {'spi': spi, 'key': key[:_psp_key_len(version)]}\n 108:\t\n 109:\t\n"
}

35/2 2026/10/09 23:09 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 47003
							output: 43
							thoughts: 276
						

Thoughts:
**Analyzing the PSP Connection Test**

Okay, let's break this down. That `_make_lo_conn()` function is intriguing; it's using the loopback interface, meaning it's all software, no physical hardware dependencies for this test which is great for quick iteration and CI. I see it's setting up the base connection. Now, I need to see what's happening with `rekey_rx_incomplete`. Specifically, the code inside the function, I need to focus on this, and what the flow is.

Ah, `_init_psp_dev(cfg)` gets called first. I need to understand that setup process before I can really get a handle on what's going on. It seems essential, so I need to go look at `_init_psp_dev` and understand what it does to the `cfg` object. Then I'll have a much better picture of how `rekey_rx_incomplete` is designed to work. It looks like it's testing the rejection of a Rx rekey when it is incomplete. It's expecting an `EBUSY` error code, which makes sense.



36/2 2026/10/09 23:09 tool grepper
0m Args:
{
  "Expression": "def _init_psp_dev",
  "PathPrefixes": [
    "tools/testing/selftests/drivers/net/psp.py"
  ]
}

Results:
{
  "Output": "tools/testing/selftests/drivers/net/psp.py=212=def _wait_tx_key_drain(cfg, base):\n--\ntools/testing/selftests/drivers/net/psp.py-223-\ntools/testing/selftests/drivers/net/psp.py:224:def _init_psp_dev(cfg, use_psp_ifindex=False):\ntools/testing/selftests/drivers/net/psp.py-225-    if not hasattr(cfg, 'psp_dev_id'):\n"
}

37/2 2026/10/09 23:09 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 47710
							output: 43
							thoughts: 30
						

Thoughts:
Okay, let's dive into this. Here's my thought process as I approach this task:

**Analyzing `_init_psp_dev` in `psp.py`**

Alright, I need to understand how the PSP (presumably Packet Steering Processor) device is initialized within the context of these selftests. The goal is likely to see how they're setting up the device for various test scenarios.

First, I need to zero in on the exact location: `tools/testing/selftests/drivers/net/psp.py`. That means I'm looking at a Python file, probably designed to interact with a PSP device through some form of control or testing interface. Specifically, I'm concerned with the function or method named `_init_psp_dev`. The underscore prefix often suggests it's an internal function used within the module, not meant for direct external calls, but it's crucial for the setup process nonetheless.

I expect to see things like:
*   **Device instantiation**: Some mechanism for creating or acquiring a handle to the PSP device, possibly involving device nodes or configuration files.
*   **Configuration**: Setting up any necessary parameters, registers, or settings on the PSP, like queue assignments, interrupt settings, or address space setup.
*   **Error Handling**: I'm on the lookout for checks for errors during initialization. Failures are expected to be present as failure tests are often incorporated in selftests.
*   **Resource allocation**: Any potential memory allocation or resource allocation that needs to happen during the initialization process.
*   **Return value**: The function probably returns either a handle or indicator of successful initialization.

Now I'll get to reading the code itself.



38/2 2026/10/09 23:09 tool read-file
0m Args:
{
  "File": "tools/testing/selftests/drivers/net/psp.py",
  "FirstLine": 220,
  "LineCount": 40
}

Results:
{
  "Contents": " 220:\t#\n 221:\t# Test case boiler plate\n 222:\t#\n 223:\t\n 224:\tdef _init_psp_dev(cfg, use_psp_ifindex=False):\n 225:\t    if not hasattr(cfg, 'psp_dev_id'):\n 226:\t        # Figure out which local device we are testing against\n 227:\t        # For NetDrvContEnv: use psp_ifindex instead of ifindex\n 228:\t        target_ifindex = cfg.psp_ifindex if use_psp_ifindex else cfg.ifindex\n 229:\t        for dev in cfg.pspnl.dev_get({}, dump=True):\n 230:\t            if dev['ifindex'] == target_ifindex:\n 231:\t                cfg.psp_info = dev\n 232:\t                cfg.psp_dev_id = cfg.psp_info['id']\n 233:\t                break\n 234:\t        else:\n 235:\t            raise KsftSkipEx(\"No PSP devices found\")\n 236:\t\n 237:\t    # Enable PSP if necessary\n 238:\t    cap = cfg.psp_info['psp-versions-cap']\n 239:\t    ena = cfg.psp_info['psp-versions-ena']\n 240:\t    if cap != ena:\n 241:\t        cfg.pspnl.dev_set({'id': cfg.psp_dev_id, 'psp-versions-ena': cap})\n 242:\t        defer(cfg.pspnl.dev_set, {'id': cfg.psp_dev_id,\n 243:\t                                  'psp-versions-ena': ena })\n 244:\t\n 245:\t#\n 246:\t# Test cases\n 247:\t#\n 248:\t\n 249:\tdef dev_list_devices(cfg):\n 250:\t    \"\"\" Dump all devices \"\"\"\n 251:\t    _init_psp_dev(cfg)\n 252:\t\n 253:\t    devices = cfg.pspnl.dev_get({}, dump=True)\n 254:\t\n 255:\t    found = False\n 256:\t    for dev in devices:\n 257:\t        found |= dev['id'] == cfg.psp_dev_id\n 258:\t    ksft_true(found)\n 259:\t\n"
}

39/2 2026/10/09 23:09 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 48785
							output: 19
							thoughts: 2199
						

Thoughts:
**PSP Key Rotation Vulnerability Deep Dive**

Okay, so I've been digging into this `pspnl` interface and its interaction with PSP devices, specifically how it handles key rotation. My initial hunch was correct: `pspnl.dev_get` can dump PSP devices, and we can definitely reach the `net/psp` code through syzkaller, leveraging `netdevsim` devices created via `/sys/bus/netdevsim/new_device`, devlink, or netlink. When a `netdevsim` device is made, `nsim_psp_init` gets called, which ultimately calls `psp_dev_create`. Critically, within `psp_dev_create`, `psp_deferred_del_init` is invoked.

The user space then has access to the PSP device using generic netlink (pspnl), and I can create a TCP connection, attach PSP rx and tx associations, and importantly, REKEY them.

Now, here's where it gets interesting and where the potential problem lies. The introduction of `psp_sock_rx_rekey` and `psp_sock_tx_rekey` has changed how PSP keys are handled on socket rekey operations.  Previously, an existing PSP state on a socket would be rejected with `-EBUSY`.  Now, `psp_sock_rx_rekey` is called, and `rcu_assign_pointer` is used to update the socket's association. On the TX side, both `psp_sock_tx_rekey` and `psp_sock_set_tx_key` are available.

`psp_sock_tx_rekey` allocates a *new* `psp_assoc` struct, assigns the fields, links it to `pas->assocs_list`, and importantly sets `pas->flags |= PSP_ASSOC_DEFER_TX_KEY_DEL;`, then `psp_assoc_put(pas);`.  In `psp_assocs_key_rotated`, we see `pas->prev_generation |= ~PSP_GEN_VALID_MASK;` being set for all `active_assocs`, and `psp_pse_matches_pas` checks both current and `prev_spi` / `prev_generation`.

The presence of the `psp_deferred_del` mechanism is what I have to focus on.  It looks like key deletion is now deferred and put into a work queue. Let's dig deeper:

Inside `psp_assoc_free`, if `psp_assoc_needs_tx_key_del(pas)` is true AND the `PSP_ASSOC_DEFER_TX_KEY_DEL` flag is set, then `psp_deferred_del_queue` is called.

The key to the whole thing is `psp_dev_has_sadb`, which essentially depends on the presence of `psd->ops->tx_key_del`. I've confirmed that the only driver that implements `tx_key_del` (outside of the core PSP code itself) is the Mellanox `mlx5` driver.

So the attack scenario is clear. By using this combination of functions I can potentially make the PSP device believe that there are fewer keys installed than there really are by re-keying. This could bypass checks and/or lead to memory corruption, but it's important to understand the details of when and how `psp_deferred_del_queue` is called. The `tx_key_del` function from mlx5 is used here, and `psp_deferred_del` is a mechanism to remove keys. It seems that if the Mellanox driver isn't present, then the mechanism for key removal is disabled.



40/2 2026/10/09 23:09 tool grepper
0m Args:
{
  "Expression": "tx_key_del"
}

Results:
{
  "Output": "Documentation/networking/psp.rst=205=Deferred Tx key deletion\n--\nDocumentation/networking/psp.rst-207-\nDocumentation/networking/psp.rst:208:Drivers which implement ``tx_key_add`` and ``tx_key_del`` may hold key\nDocumentation/networking/psp.rst-209-references in their Tx rings, so PSP core waits until descriptors\n--\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c=1011=static struct psp_dev_ops mlx5_psp_ops = {\n--\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c-1014-\t.tx_key_add   = mlx5e_psp_assoc_add,\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c:1015:\t.tx_key_del   = mlx5e_psp_assoc_del,\ndrivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c-1016-\t.key_rotate   = mlx5e_psp_key_rotate,\n--\ninclude/net/psp/types.h=229=struct psp_dev_ops {\n--\ninclude/net/psp/types.h-255-\t * for the driver to use at drv_data.\ninclude/net/psp/types.h:256:\t * Can be left NULL if device does not store Tx keys and @tx_key_del\ninclude/net/psp/types.h-257-\t * is also NULL.\n--\ninclude/net/psp/types.h-261-\t/**\ninclude/net/psp/types.h:262:\t * @tx_key_del: remove a Tx key from the device\ninclude/net/psp/types.h-263-\t * Remove an association from the device.\n--\ninclude/net/psp/types.h-266-\t */\ninclude/net/psp/types.h:267:\tvoid (*tx_key_del)(struct psp_dev *psd, struct psp_assoc *pas);\ninclude/net/psp/types.h-268-\n--\nnet/psp/psp.h=30=struct psp_dev *psp_dev_get_for_sock(struct sock *sk);\nnet/psp/psp.h:31:void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas);\nnet/psp/psp.h-32-int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,\n--\nnet/psp/psp.h=62=static inline bool psp_dev_has_sadb(struct psp_dev *psd)\n--\nnet/psp/psp.h-64-\tlockdep_assert_held(\u0026psd-\u003elock);\nnet/psp/psp.h:65:\treturn !!psd-\u003eops-\u003etx_key_del;\nnet/psp/psp.h-66-}\nnet/psp/psp.h-67-\nnet/psp/psp.h:68:static inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas)\nnet/psp/psp.h-69-{\n--\nnet/psp/psp_deferred_del.c=147=static void psp_deferred_del_work(struct work_struct *work)\n--\nnet/psp/psp_deferred_del.c-170-\tlist_for_each_entry(pas, \u0026to_free, assocs_list)\nnet/psp/psp_deferred_del.c:171:\t\tpsp_dev_tx_key_del(psd, pas);\nnet/psp/psp_deferred_del.c-172-\n--\nnet/psp/psp_deferred_del.c=187=int psp_deferred_del_init(struct psp_dev *psd)\n--\nnet/psp/psp_deferred_del.c-192-\nnet/psp/psp_deferred_del.c:193:\tif (!psd-\u003eops-\u003etx_key_del)\nnet/psp/psp_deferred_del.c-194-\t\treturn 0;\n--\nnet/psp/psp_deferred_del.c=207=void psp_deferred_del_uninit(struct psp_dev *psd, bool unpublished)\n--\nnet/psp/psp_deferred_del.c-218-\t\tlist_del(\u0026pas-\u003eassocs_list);\nnet/psp/psp_deferred_del.c:219:\t\tpsp_dev_tx_key_del(psd, pas);\nnet/psp/psp_deferred_del.c-220-\t\tpsp_dev_put(psd);\n--\nnet/psp/psp_main.c=61=psp_dev_create(struct net_device *netdev,\n--\nnet/psp/psp_main.c-73-\t\t    !psd_ops-\u003eget_stats ||\nnet/psp/psp_main.c:74:\t\t    (!psd_ops-\u003etx_key_add != !psd_ops-\u003etx_key_del) ||\nnet/psp/psp_main.c-75-\t\t    (psd_caps-\u003eassoc_drv_spc \u0026\u0026 !psd_ops-\u003etx_key_add) ||\n--\nnet/psp/psp_main.c=143=void psp_dev_unregister(struct psp_dev *psd)\n--\nnet/psp/psp_main.c-166-\tlist_for_each_entry_safe(pas, next, \u0026psd-\u003estale_assocs, assocs_list) {\nnet/psp/psp_main.c:167:\t\tif (psp_assoc_needs_tx_key_del(pas))\nnet/psp/psp_main.c:168:\t\t\tpsp_dev_tx_key_del(psd, pas);\nnet/psp/psp_main.c-169-\t\tlist_del(\u0026pas-\u003eassocs_list);\n--\nnet/psp/psp_sock.c=80=static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,\n--\nnet/psp/psp_sock.c-106-\nnet/psp/psp_sock.c:107:void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas)\nnet/psp/psp_sock.c-108-{\nnet/psp/psp_sock.c:109:\tpsd-\u003eops-\u003etx_key_del(psd, pas);\nnet/psp/psp_sock.c-110-\tif (!WARN_ON_ONCE(!psd-\u003estats.tx_key_cnt))\n--\nnet/psp/psp_sock.c=114=static void psp_assoc_free(struct work_struct *work)\n--\nnet/psp/psp_sock.c-120-\tif (psp_dev_is_registered(psd)) {\nnet/psp/psp_sock.c:121:\t\tif (psp_assoc_needs_tx_key_del(pas)) {\nnet/psp/psp_sock.c-122-\t\t\tif (pas-\u003eflags \u0026 PSP_ASSOC_DEFER_TX_KEY_DEL) {\n--\nnet/psp/psp_sock.c-126-\t\t\t}\nnet/psp/psp_sock.c:127:\t\t\tpsp_dev_tx_key_del(psd, pas);\nnet/psp/psp_sock.c-128-\t\t}\n"
}

41/2 2026/10/09 23:09 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 53701
							output: 17
							thoughts: 2982
						

Thoughts:
**PSP Rekeying, Reachability, and Fuzzing Analysis**

Okay, let's break this down. My immediate focus is on whether the PSP rekeying functionality is reachable in a fuzzing context, particularly without the need for hardware support. My initial investigation revolves around how PSP operates with and without a hardware sadb, like `netdevsim`. I'm going through the code. I'm checking, first, if `psp_sock_rx_rekey` and `psp_sock_tx_rekey` depend on `tx_key_del`. Nope, they don't. And that's good!

`psp_assocs_key_rotated` and packet validation via `psp_pse_matches_pas` seem independent, too. Also `psp_dev_create` and `psp_dev_unregister` both call `psp_deferred_del_init`, `psp_deferred_del_stop`, and `psp_deferred_del_uninit`. And the statistics netlink command, `psp_nl_stats_fill`, queries `tx-key-count`.

My hypothesis is solidifying: PSP rekeying *is* reachable through standard netdevsim devices and Netlink sockets! The key functions within `net/psp/psp_sock.c` are all reachable via netdevsim. This is a game-changer for fuzzing, which can now target this functionality without being held back by specific hardware requirements.

Okay, next I'm checking the feasibility of syzkaller targeting this area. I need to know if syzkaller has the primitives to interact with PSP. Even if there aren't PSP-specific definitions, Syzkaller fuzzes generic netlink families, which are dynamically registered. And Syzkaller is configured with both `CONFIG_NETDEVSIM=y` and `CONFIG_INET_PSP=y`, so it has the basis for interaction with PSP.

Now I need to confirm whether a user can create `netdevsim` devices, which would be essential. Syzkaller's root VM has access to create devices. It can write to `/sys/bus/netdevsim/new_device`. I'm starting to put it all together.

Next: Is this a "worth fuzzing" patch? According to the guidelines, I need to evaluate its reachability. This patch directly touches the `net/psp/` subsystem, which is core networking and thus reachable. It can be accessed via netlink and sockets through the virtual `netdevsim` driver. This means this patch is definitely worth fuzzing. I have a lot of new runtime checks in the code. I'm also seeing refactoring and new logic for rekeying. New deferred deletion code. These are all fuzzable code paths. This looks like a definite "yes."

I was worried there for a bit with `psp_deferred_del.c`. I need to ensure it can be exercised even if `psd->ops->tx_key_del` is NULL, since it's only called when `tx_key_del` is implemented. Okay, so `psp_deferred_del_init` returns early if `tx_key_del` isn't implemented. So the deferred deletion code doesn't matter, but other parts of the code are still good. However, the critical rekeying, validation, and Netlink parts run regardless.

Finally, I'll confirm that the needed Kconfig options are set: `INET_PSP`, which depends on `INET`, and `BQL`. With `INET`, `BQL`, and `NETDEVSIM`, I'm confident that this code is both reachable and fuzzable.



42/2 2026/10/09 23:10 tool grepper
0m Args:
{
  "Expression": "config BQL"
}

Results:
{
  "Output": "net/Kconfig=349=config NET_RX_BUSY_POLL\n--\nnet/Kconfig-352-\nnet/Kconfig:353:config BQL\nnet/Kconfig-354-\tbool\n"
}

43/2 2026/10/09 23:10 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57548
							output: 32
							thoughts: 18
						

Thoughts:
Here's my take on those thoughts:

**Investigating `config BQL`**

Okay, so I need to check out what the configuration option `config BQL` represents within the `net/Kconfig` file. That's the next logical step in understanding this aspect of the networking setup. I need to get a clear definition of what this configuration option does, and how it is implemented.



44/2 2026/10/09 23:10 tool read-file
0m Args:
{
  "File": "net/Kconfig",
  "FirstLine": 350,
  "LineCount": 15
}

Results:
{
  "Contents": " 350:\t\tbool\n 351:\t\tdefault y if !PREEMPT_RT || (PREEMPT_RT \u0026\u0026 !NETCONSOLE)\n 352:\t\n 353:\tconfig BQL\n 354:\t\tbool\n 355:\t\tprompt \"Enable Byte Queue Limits\"\n 356:\t\tdepends on SYSFS\n 357:\t\tselect DQL\n 358:\t\tdefault y\n 359:\t\n 360:\tconfig BPF_STREAM_PARSER\n 361:\t\tbool \"enable BPF STREAM_PARSER\"\n 362:\t\tdepends on INET\n 363:\t\tdepends on BPF_SYSCALL\n 364:\t\tdepends on CGROUP_BPF\n"
}

45/2 2026/10/09 23:10 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57879
							output: 34
							thoughts: 44
						

Thoughts:
Okay, here's my interpretation of those thoughts, framed as my own:

**Investigating BQL Configuration Dependencies**

Alright, so `config BQL` is pointing towards a dependency on `SYSFS`, which defaults to "y." That's standard and not surprising. But hang on, there's also something about `NETDEVSIM`. I need to get a better handle on this. Let me quickly check the `config NETDEVSIM` definition. I'll head over to `drivers/net/Kconfig` to see what's what. That's the logical place to start looking for its configuration options. I need to understand how these elements interrelate.



46/2 2026/10/09 23:10 tool read-file
0m Args:
{
  "File": "drivers/net/Kconfig",
  "FirstLine": 600,
  "LineCount": 20
}

Results:
{
  "Contents": " 600:\t\n 601:\tsource \"drivers/net/thunderbolt/Kconfig\"\n 602:\tsource \"drivers/net/hyperv/Kconfig\"\n 603:\t\n 604:\tconfig NETDEVSIM\n 605:\t\ttristate \"Simulated networking device\"\n 606:\t\tdepends on DEBUG_FS\n 607:\t\tdepends on INET\n 608:\t\tdepends on PSAMPLE || PSAMPLE=n\n 609:\t\tdepends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n\n 610:\t\tselect NET_DEVLINK\n 611:\t\tselect PAGE_POOL\n 612:\t\tselect NET_SHAPER\n 613:\t\thelp\n 614:\t\t  This driver is a developer testing tool and software model that can\n 615:\t\t  be used to test various control path networking APIs, especially\n 616:\t\t  HW-offload related.\n 617:\t\n 618:\t\t  To compile this driver as a module, choose M here: the module\n 619:\t\t  will be called netdevsim.\n"
}

47/2 2026/10/09 23:10 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58410
							output: 22
							thoughts: 1680
						

Thoughts:
**Focus Symbol Analysis for PSP Key Rotation**

Okay, let's break this down. My initial thought is to confirm what parts of the PSP subsystem are viable for fuzzing, specifically in a QEMU environment.  First, it's clear `MLX5_CORE` and `MLX5_EN_PSP` are out; they're tied to physical hardware (`MLX5` is ASIC-based, as documented).  Good, that keeps the scope manageable.  On the other hand, `NETDEVSIM` and `INET_PSP` are definitely software-based, which is perfect for QEMU.

Now, a key question: Does `INET_PSP` *require* `NETDEVSIM`?  The code suggests it does.  `netdevsim` appears to create the PSP device itself via `nsim_psp_init`, which then instantiates a PSP device. Without that PSP device, the netlink calls are going to fail.  So, to get a PSP device in QEMU, `NETDEVSIM` is essential.

So, the minimal configuration I'll need to enable is:
-   `INET_PSP` (obvious)
-   `BQL` (it's a dependency of `INET_PSP`, I'll include it)
-   `NETDEVSIM` (absolutely critical for virtual PSP device creation)

Next, the focus, given I'm using fuzzing, is to determine the optimal focus symbols. Section 4 lays it out – target specific feature logic and entry points, avoiding ubiquitous functions.  I need to identify which functions are most relevant to the key rotation logic implemented in this patch.

Analyzing the code changes, here's what jumps out at me:

In `net/psp/psp_sock.c`:
*   `psp_sock_rx_rekey` (static) - a crucial rekeying function called by `psp_sock_assoc_set_rx`.
*   `psp_sock_tx_rekey` (static) - the complementary function to `psp_sock_rx_rekey`.
*   `psp_sock_assoc_set_rx` (non-static) - This one's important; it's a direct API entrypoint for setting the RX association with rekeying logic.
*   `psp_sock_assoc_set_tx` (non-static) - The TX equivalent to `psp_sock_assoc_set_rx`, similarly a key API entrypoint.
*   `psp_assocs_key_rotated` (non-static) - This one handles the updated key generation.
*   `psp_assoc_free` (static work handler) - altered for deferred deletion, possibly important to consider.
*   `psp_dev_tx_key_add` (static) - altered for tx_key_cnt.
*   `psp_dev_tx_key_del` (non-static) - This is key; altered for key deletion and tx counter with WARN_ON_ONCE.

In `net/psp/psp_main.c`:
*   `psp_dev_create` (non-static) - altered to init deferred del
*   `psp_dev_unregister` (non-static) - altered to stop/uninit deferred del and added WARN

In `net/psp/psp_nl.c`:
*   `psp_nl_stats_fill` (static) - called by `psp_nl_dev_get_doit` / dumpit
*   `psp_nl_rx_assoc_doit` (non-static)
*   `psp_nl_tx_assoc_doit` (non-static)

In `net/psp/psp_deferred_del.c`:
*   `psp_deferred_del_init`
*   `psp_deferred_del_stop`
*   `psp_deferred_del_uninit`
*   `psp_deferred_del_queue`
*   `psp_deferred_del_work`
*   `psp_tx_grace_start`
*   `psp_tx_grace_done`

Now, let's consider static versus non-static functions. While static functions in `.c` files *can* have symbols (unless inlined by the compiler), non-static functions are *guaranteed* exported or global. Including both is the safest bet to exercise both key functions and entry points.

Given this, I should focus on the following:
*   `psp_sock_assoc_set_rx` (non-static)
*   `psp_sock_assoc_set_tx` (non-static)
*   `


48/2 2026/10/09 23:10 tool grepper
0m Args:
{
  "Expression": "psp_assocs_key_rotated"
}

Results:
{
  "Output": "net/psp/psp.h=35=int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,\n--\nnet/psp/psp.h-37-\t\t\t  struct netlink_ext_ack *extack);\nnet/psp/psp.h:38:void psp_assocs_key_rotated(struct psp_dev *psd);\nnet/psp/psp.h-39-\n--\nnet/psp/psp_nl.c=484=int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info)\n--\nnet/psp/psp_nl.c-519-\nnet/psp/psp_nl.c:520:\tpsp_assocs_key_rotated(psd);\nnet/psp/psp_nl.c-521-\tpsd-\u003estats.rotations++;\n--\nnet/psp/psp_sock.c=339=int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,\n--\nnet/psp/psp_sock.c-380-\nnet/psp/psp_sock.c:381:void psp_assocs_key_rotated(struct psp_dev *psd)\nnet/psp/psp_sock.c-382-{\n"
}

49/2 2026/10/09 23:10 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 61483
							output: 239
							thoughts: 438
						

Thoughts:
**Fuzzing Readiness Confirmed**

Alright, the pieces are falling into place! I've confirmed that `psp_nl_key_rotate_doit` does indeed call `psp_assocs_key_rotated(psd)`. Let's run through the checklist again to make absolutely certain.

First, is this patch WorthFuzzing? Absolutely. This is touching the core of the PSP (PSP Security Protocol) implementation, specifically in `net/psp`. It's enabling connection rekeying, both Rx and Tx directions, through functions like `psp_sock_rx_rekey` and `psp_sock_tx_rekey`. This inherently modifies association management, reference counts, and packet reception logic. We're also seeing deferred Tx key deletion using BQL accounting and delayed work via `net/psp/psp_deferred_del.c`. There are new runtime assertion checks being introduced as well, which is always a good sign for identifying potential issues: `WARN(psd->stats.tx_key_cnt, ...)` and `WARN_ON_ONCE(!psd->stats.tx_key_cnt)`. The cherry on top is that this is reachable in standard virtualized environments via QEMU using virtual networking (`netdevsim`), generic netlink (`pspnl`), and even through standard TCP sockets. Excellent!

Next, the necessary EnableConfigs are present: `INET_PSP`, `NETDEVSIM`, and `BQL`. No issues there.

Finally, the FocusSymbols. I've compiled a list of the key functions: `psp_sock_assoc_set_rx`, `psp_sock_assoc_set_tx`, `psp_sock_rx_rekey`, `psp_sock_tx_rekey`, `psp_assocs_key_rotated`, `psp_dev_tx_key_del`, `psp_deferred_del_queue`, `psp_deferred_del_work`, and `psp_tx_grace_done`. I've verified each one to ensure they are *not* ubiquitous. And as expected, they aren't! They're all specific to PSP and the rekeying mechanisms.

With everything verified against the source tree and the initial assessment, the process is clear. It's time to call `set-results`.



50/2 2026/10/09 23:10 tool set-results
0m Args:
{
  "EnableConfigs": [
    "INET_PSP",
    "NETDEVSIM",
    "BQL"
  ],
  "FocusSymbols": [
    "psp_sock_assoc_set_rx",
    "psp_sock_assoc_set_tx",
    "psp_sock_rx_rekey",
    "psp_sock_tx_rekey",
    "psp_assocs_key_rotated",
    "psp_dev_tx_key_del",
    "psp_deferred_del_queue",
    "psp_deferred_del_work",
    "psp_tx_grace_done"
  ],
  "Reasoning": "The patch adds connection in-place rekeying support and deferred Tx key deletion using BQL accounting to the PSP (PSP Security Protocol) subsystem in net/psp/. It modifies association lifecycle management, reference counts, socket association assignment, packet acceptance checks, and introduces new WARN and WARN_ON_ONCE checks. The code is reachable in standard virtualized environments via simulated networking devices (netdevsim), generic netlink, and standard TCP sockets.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "INET_PSP",
    "NETDEVSIM",
    "BQL"
  ],
  "FocusSymbols": [
    "psp_sock_assoc_set_rx",
    "psp_sock_assoc_set_tx",
    "psp_sock_rx_rekey",
    "psp_sock_tx_rekey",
    "psp_assocs_key_rotated",
    "psp_dev_tx_key_del",
    "psp_deferred_del_queue",
    "psp_deferred_del_work",
    "psp_tx_grace_done"
  ],
  "Reasoning": "The patch adds connection in-place rekeying support and deferred Tx key deletion using BQL accounting to the PSP (PSP Security Protocol) subsystem in net/psp/. It modifies association lifecycle management, reference counts, socket association assignment, packet acceptance checks, and introduces new WARN and WARN_ON_ONCE checks. The code is reachable in standard virtualized environments via simulated networking devices (netdevsim), generic netlink, and standard TCP sockets.",
  "WorthFuzzing": true
}

51/1 2026/10/09 23:10 action If
1m Args:
{
  "WorthFuzzing": true
}

Results:
null

52/2 2026/10/09 23:10 agent kmsan-evaluator
1m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch implements PSP in-place rekeying and deferred Tx key deletion based on Byte Queue Limits (BQL).\n\n1. Memory initialization: All new or modified data structures (such as `struct psp_txq_state` and `struct psp_assoc`) are allocated with zeroing allocators (`kvzalloc_flex`, `kzalloc_flex`, `bitmap_zalloc`). All fields (including `prev_spi`, `prev_generation`, and `flags`) are either explicitly initialized or zero-filled upon creation.\n2. Kernel-to-userspace communication: The patch adds one netlink attribute (`PSP_A_STATS_TX_KEY_COUNT`) to `psp_nl_stats_fill()`. This exports a scalar `unsigned long` (`tx_key_cnt`), which is zero-initialized at `psp_dev` creation and incremented/decremented upon key addition/deletion. No structs with padding or uninitialized memory buffers are copied to user space.\n3. Bug profile: The patch touches concurrency, list operations, delayed work execution, and object lifetimes/reference counting across RCU and mutex critical sections. Any memory issues arising from these changes (e.g. use-after-free, double free, refcount leaks, out-of-bounds access, locking deadlocks) fall under KASAN, LOCKDEP, and standard sanitizer checks.\n\nBecause there are no uninitialized memory read risks or info-leaks, a dedicated KMSAN fuzzing session is not justified.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 9ecf5c48c0d9147c72e7843af57f7e4710b29694
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Oct 9 23:06:29 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml
index f3266763c3253..d14c11d098914 100644
--- a/Documentation/netlink/specs/psp.yaml
+++ b/Documentation/netlink/specs/psp.yaml
@@ -190,6 +190,13 @@ attribute-sets:
         doc: |
           Number of PSP packets for transmission with errors.
           Device statistic (from the PSP spec).
+      -
+        name: tx-key-count
+        type: uint
+        doc: |
+          Current number of Tx keys installed on the device.
+          Only visible if the driver stores keys on device.
+          Kernel statistic.
 
 operations:
   list:
@@ -316,6 +323,7 @@ operations:
             - tx-packets
             - tx-bytes
             - tx-error
+            - tx-key-count
         pre: psp-device-get-locked
         post: psp-device-unlock
       dump:
diff --git a/Documentation/networking/psp.rst b/Documentation/networking/psp.rst
index 0f9b6b73f2447..769c7b21045ce 100644
--- a/Documentation/networking/psp.rst
+++ b/Documentation/networking/psp.rst
@@ -140,14 +140,36 @@ The PSP assoc state of a socket is not reset when the connection is
 torn down. ``connect()`` on a socket that has PSP assoc state will
 return ``-EINVAL``.
 
+Rekeying
+--------
+
+A connection which has completed the exchange described above and is
+in the "PSP Full" state can be rekeyed in place without being torn
+down. The Tx and Rx directions are rekeyed separately using the same
+netlink calls as in connection setup.
+
+``rx-assoc`` allocates a new Rx key and SPI, which should be passed
+to the peer exactly as during the initial exchange. The SPI which was
+in use before the rekey remains acceptable on the socket until the
+next Rx rekey, so packets the peer sent before it learned the new SPI
+are still received.
+
+``tx-assoc`` installs a new Tx key, which takes effect immediately.
+The peer will accept data encrypted from the old and new SPI.
+
+A rekey is rejected with ``-EINVAL`` if it would change the PSP device
+or the PSP version of the association. It is rejected with ``-EBUSY``
+if the socket has not completed its initial exchange in both
+directions.
+
 Rotation notifications
 ----------------------
 
 The rotations of device key happen asynchronously and are usually
 performed by management daemons, not under application control.
 The PSP netlink family will generate a notification whenever keys
-are rotated. The applications are expected to re-establish connections
-before keys are rotated again.
+are rotated. Applications are expected to rekey their connections,
+as described above, before device keys are rotated again.
 
 Kernel implementation
 =====================
@@ -180,6 +202,44 @@ Drivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload
 was requested for given skb. On Rx drivers should allocate and populate
 the ``SKB_EXT_PSP`` skb extension, and set the skb->decrypted bit to 1.
 
+Deferred Tx key deletion
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Drivers which implement ``tx_key_add`` and ``tx_key_del`` may hold key
+references in their Tx rings, so PSP core waits until descriptors
+containing these references are completed before removing the key from
+the underlying device. PSP core uses accounting based on Byte Queue Limits
+(BQL) to wait for a suitable grace period before asking the driver to
+remove the key.
+
+Drivers which implement the Tx key callbacks must meet the following
+requirements:
+
+* The driver must be "ops locked"
+  (see Documentation/networking/netdevices.rst).
+* A PSP skb accepted by ``ndo_start_xmit()`` must remain socket-owned until
+  every Tx descriptor referencing its PSP key has been completed or otherwise
+  made incapable of using the key. The driver must not orphan the skb before
+  that point. Otherwise, the socket destructor may free the Tx key while key
+  references remain in the Tx ring.
+* Every PSP packet accepted by ``ndo_start_xmit()`` must be included in BQL
+  queued bytecount before the function returns.
+* Completion bytecounts must exactly match enqueue bytecounts and preserve
+  queue order. A later packet must not be reported as completed while an earlier
+  packet can still reference its key.
+* Before calling ``dql_reset()`` on a queue, the driver must ensure that all
+  outstanding descriptors containing key references have been completed or
+  discarded. If called under the netdev instance lock, then descriptors can
+  remain outstanding after the reset as long as they are completed or
+  discarded before the instance lock is released.
+* When decreasing ``real_num_tx_queues``, the driver must ensure that every
+  outstanding descriptor on the queues at or above the new Tx queue count
+  has been completed or otherwise made incapable of using its PSP key
+  before the netdev instance lock is released.
+* The BQL state of a queue below ``real_num_tx_queues`` must reflect all
+  bytes completed or be reset after the queue has been quiesced. Failure to
+  do so will stall the grace period algorithm.
+
 Kernel implementation notes
 ---------------------------
 
diff --git a/include/net/psp/functions.h b/include/net/psp/functions.h
index b23c30898389c..fb80e15e43681 100644
--- a/include/net/psp/functions.h
+++ b/include/net/psp/functions.h
@@ -77,10 +77,12 @@ psp_is_allowed_nondata(struct sk_buff *skb, struct psp_assoc *pas)
 static inline bool
 psp_pse_matches_pas(struct psp_skb_ext *pse, struct psp_assoc *pas)
 {
-	return pse && pas->rx.spi == pse->spi &&
-	       pas->generation == pse->generation &&
-	       pas->version == pse->version &&
-	       pas->dev_id == pse->dev_id;
+	return pse && pas->version == pse->version &&
+	       pas->dev_id == pse->dev_id &&
+	       ((pas->rx.spi == pse->spi &&
+		 pas->generation == pse->generation) ||
+		(pas->prev_spi && pas->prev_spi == pse->spi &&
+		 pas->prev_generation == pse->generation));
 }
 
 static inline enum skb_drop_reason
diff --git a/include/net/psp/types.h b/include/net/psp/types.h
index b8905efbd604e..970801cb65026 100644
--- a/include/net/psp/types.h
+++ b/include/net/psp/types.h
@@ -3,8 +3,10 @@
 #ifndef __NET_PSP_H
 #define __NET_PSP_H
 
+#include <linux/bits.h>
 #include <linux/mutex.h>
 #include <linux/refcount.h>
+#include <linux/workqueue.h>
 #include <net/net_trackers.h>
 
 struct netlink_ext_ack;
@@ -79,10 +81,16 @@ struct psp_assoc_dev {
  * @prev_assocs:	associations which use old (but still usable)
  *			device key
  * @stale_assocs:	associations which use a rotated out key
+ * @tx_del:		deferred TX key deletion state
+ * @tx_del.active:	TX keys to be deleted after the current grace period
+ * @tx_del.next:	TX keys queued for deletion during current grace period
+ * @tx_del.work:	delayed work item for periodic grace period checking
+ * @tx_del.txq_state:	TX queue state for deferred deletion grace periods
  *
  * @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-count
  *
  * @rcu:	RCU head for freeing the structure
  */
@@ -108,9 +116,17 @@ struct psp_dev {
 	struct list_head prev_assocs;
 	struct list_head stale_assocs;
 
+	struct {
+		struct list_head active;
+		struct list_head next;
+		struct delayed_work work;
+		struct psp_txq_state *txq_state;
+	} tx_del;
+
 	struct {
 		unsigned long rotations;
 		unsigned long stales;
+		unsigned long tx_key_cnt;
 	} stats;
 
 	struct rcu_head rcu;
@@ -152,6 +168,20 @@ struct psp_key_parsed {
 	u8 key[PSP_MAX_KEY];
 };
 
+/**
+ * enum psp_assoc_flags - flags of struct psp_assoc
+ * @PSP_ASSOC_SKIP_TX_KEY_DEL: Do not delete Tx key from psp_dev. It was
+ *	copied to a newer psp_assoc during an Rx rekey.
+ * @PSP_ASSOC_DEFER_TX_KEY_DEL: Send Tx key to psp_dev's deferred deletion
+ *	queue. This psp_assoc was detached from its socket during a Tx rekey
+ *	and requires device descriptor state referencing this key to be
+ *	drained.
+ */
+enum psp_assoc_flags {
+	PSP_ASSOC_SKIP_TX_KEY_DEL	= BIT(0),
+	PSP_ASSOC_DEFER_TX_KEY_DEL	= BIT(1),
+};
+
 struct psp_assoc {
 	struct psp_dev *psd;
 
@@ -159,6 +189,10 @@ struct psp_assoc {
 	u8 generation;
 	u8 version;
 	u8 peer_tx;
+	u8 prev_generation;
+	u8 flags; /* Slow path, protected by psd->lock */
+
+	__be32 prev_spi;
 
 	u32 upgrade_seq;
 
diff --git a/include/uapi/linux/psp.h b/include/uapi/linux/psp.h
index 1c8899cd4da5e..21810e8a72299 100644
--- a/include/uapi/linux/psp.h
+++ b/include/uapi/linux/psp.h
@@ -69,6 +69,7 @@ enum {
 	PSP_A_STATS_TX_PACKETS,
 	PSP_A_STATS_TX_BYTES,
 	PSP_A_STATS_TX_ERROR,
+	PSP_A_STATS_TX_KEY_COUNT,
 
 	__PSP_A_STATS_MAX,
 	PSP_A_STATS_MAX = (__PSP_A_STATS_MAX - 1)
diff --git a/net/psp/Kconfig b/net/psp/Kconfig
index 84d6b0f254606..36c12493784fd 100644
--- a/net/psp/Kconfig
+++ b/net/psp/Kconfig
@@ -5,6 +5,7 @@
 config INET_PSP
 	bool "PSP Security Protocol support"
 	depends on INET
+	depends on BQL
 	select SKB_DECRYPTED
 	select SKB_EXTENSIONS
 	select SOCK_VALIDATE_XMIT
diff --git a/net/psp/Makefile b/net/psp/Makefile
index eb5ff3c5bfb2a..40decd8fe0500 100644
--- a/net/psp/Makefile
+++ b/net/psp/Makefile
@@ -2,4 +2,4 @@
 
 obj-$(CONFIG_INET_PSP) += psp.o
 
-psp-y := psp_main.o psp_nl.o psp_sock.o psp-nl-gen.o
+psp-y := psp_main.o psp_nl.o psp_sock.o psp_deferred_del.o psp-nl-gen.o
diff --git a/net/psp/psp.h b/net/psp/psp.h
index b123c24279050..0cfc82c6c7110 100644
--- a/net/psp/psp.h
+++ b/net/psp/psp.h
@@ -18,6 +18,11 @@ int psp_dev_check_access(struct psp_dev *psd, struct net *net, bool admin);
 bool psp_has_assoc_dev_in_ns(struct psp_dev *psd, struct net *net);
 int psp_attach_netdev_notifier(void);
 
+int psp_deferred_del_init(struct psp_dev *psd);
+void psp_deferred_del_stop(struct psp_dev *psd);
+void psp_deferred_del_uninit(struct psp_dev *psd, bool unpublished);
+void psp_deferred_del_queue(struct psp_dev *psd, struct psp_assoc *pas);
+
 void psp_nl_notify_dev(struct psp_dev *psd, u32 cmd);
 void psp_nl_notify_disassoc(struct psp_dev *psd, struct net *net);
 
@@ -63,7 +68,8 @@ static inline bool psp_dev_has_sadb(struct psp_dev *psd)
 static inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas)
 {
 	lockdep_assert_held(&pas->psd->lock);
-	return psp_dev_has_sadb(pas->psd) && pas->tx.spi;
+	return psp_dev_has_sadb(pas->psd) && pas->tx.spi &&
+	       !(pas->flags & PSP_ASSOC_SKIP_TX_KEY_DEL);
 }
 
 #endif /* __PSP_PSP_H */
diff --git a/net/psp/psp_deferred_del.c b/net/psp/psp_deferred_del.c
new file mode 100644
index 0000000000000..cfbac72577e96
--- /dev/null
+++ b/net/psp/psp_deferred_del.c
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/bitmap.h>
+#include <linux/jiffies.h>
+#include <linux/list.h>
+#include <linux/netdevice.h>
+#include <linux/slab.h>
+#include <net/netdev_lock.h>
+#include <net/psp.h>
+
+#include "psp.h"
+
+#define PSP_TX_GRACE_POLL_MS	1000
+
+struct psp_txq_state {
+	unsigned int num_tx_queues;
+	unsigned long *drained_queues;
+	unsigned int to_complete[];
+};
+
+static void psp_txq_state_free(struct psp_txq_state *state)
+{
+	if (!state)
+		return;
+
+	bitmap_free(state->drained_queues);
+	kvfree(state);
+}
+
+static struct psp_txq_state *
+psp_txq_state_alloc(unsigned int max_tx_queues)
+{
+	struct psp_txq_state *state;
+
+	state = kvzalloc_flex(*state, to_complete, max_tx_queues);
+	if (!state)
+		return NULL;
+
+	state->drained_queues = bitmap_zalloc(max_tx_queues, GFP_KERNEL);
+	if (!state->drained_queues) {
+		psp_txq_state_free(state);
+		return NULL;
+	}
+
+	return state;
+}
+
+static void psp_tx_grace_start(struct psp_dev *psd)
+{
+	struct psp_txq_state *state = psd->tx_del.txq_state;
+	struct net_device *dev = psd->main_netdev;
+	unsigned int i;
+
+	netdev_assert_locked(dev);
+
+	/* Any instances of ndo_start_xmit() that observed these keys through
+	 * psp_skb_get_assoc_rcu() must already be accounted in BQL's queued
+	 * byte count. ndo_start_xmit() runs with BHs disabled, which forms an
+	 * implicit RCU read-side critical section, and we are now at least one
+	 * grace period after any of these psp_assocs have been cleared from
+	 * sk->psp_assoc.
+	 */
+	state->num_tx_queues = dev->real_num_tx_queues;
+	bitmap_zero(state->drained_queues, state->num_tx_queues);
+	for (i = 0; i < state->num_tx_queues; i++) {
+		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
+
+		state->to_complete[i] = READ_ONCE(txq->dql.num_queued);
+	}
+}
+
+static bool psp_tx_grace_done(struct psp_dev *psd)
+{
+	struct psp_txq_state *state = psd->tx_del.txq_state;
+	struct net_device *dev = psd->main_netdev;
+	bool all_completed = true;
+	unsigned int i;
+
+	netdev_assert_locked(dev);
+
+	if (dev->real_num_tx_queues < state->num_tx_queues)
+		state->num_tx_queues = dev->real_num_tx_queues;
+
+	for (i = 0; i < state->num_tx_queues; i++) {
+		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
+		unsigned int completed;
+		unsigned int queued;
+
+		if (test_bit(i, state->drained_queues))
+			continue;
+
+		/* Drivers must meet the requirements documented in
+		 * Documentation/networking/psp.rst to guarantee forward
+		 * progress and avoid ending the grace period prematurely.
+		 *
+		 * We snapshotted num_queued in psp_tx_grace_start() and need
+		 * to determine whether num_completed has since reached or
+		 * passed that mark. For a given queue, we can consider first
+		 * whether or not dql_reset() was called at any point between
+		 * when we read num_queued until we read num_completed and
+		 * num_queued here and then separate the space of possible
+		 * states based on that.
+		 *
+		 * Not reset: num_queued and num_completed only increase, and
+		 * dql keeps num_queued - num_completed <= INT_MAX at all
+		 * times. We can form three exhaustive sub cases:
+		 *
+		 * (int)(to_complete - completed) <= 0: completion reached or
+		 * passed the mark. At the time to_complete was read,
+		 * completed was in [to_complete - INT_MAX, to_complete].
+		 *
+		 * (int)(to_complete - queued) > 0: to_complete and queued are
+		 * both snapshots of num_queued, so queued has advanced more
+		 * than INT_MAX + 1 past to_complete. num_completed lags
+		 * queued by at most INT_MAX, so num_completed must have
+		 * crossed to_complete.
+		 *
+		 * Otherwise the mark may still be in flight, so poll again.
+		 *
+		 * Reset: By the driver conditions laid out in
+		 * Documentation/networking/psp.rst, if a dql_reset()
+		 * occurred, and we are holding the instance lock, then we
+		 * know the actual state of the queue is drained. The check
+		 * below is then conservative because there is no risk of
+		 * falsely declaring the queue drained. As long as dql makes
+		 * forward progress the check should eventually report
+		 * drained.
+		 */
+		completed = READ_ONCE(txq->dql.num_completed);
+		queued = READ_ONCE(txq->dql.num_queued);
+
+		if ((int)(state->to_complete[i] - completed) <= 0 ||
+		    (int)(state->to_complete[i] - queued) > 0)
+			__set_bit(i, state->drained_queues);
+		else
+			all_completed = false;
+	}
+
+	return all_completed;
+}
+
+static bool psp_tx_grace_active(struct psp_dev *psd)
+{
+	return !list_empty(&psd->tx_del.active);
+}
+
+static void psp_deferred_del_work(struct work_struct *work)
+{
+	struct delayed_work *dwork = to_delayed_work(work);
+	struct psp_assoc *pas, *tmp;
+	bool need_reschedule;
+	struct psp_dev *psd;
+	LIST_HEAD(to_free);
+
+	psd = container_of(dwork, struct psp_dev, tx_del.work);
+
+	mutex_lock(&psd->lock);
+	netdev_lock(psd->main_netdev);
+
+	if (psp_tx_grace_active(psd) && psp_tx_grace_done(psd))
+		list_splice_init(&psd->tx_del.active, &to_free);
+
+	if (!psp_tx_grace_active(psd) && !list_empty(&psd->tx_del.next)) {
+		psp_tx_grace_start(psd);
+		list_splice_init(&psd->tx_del.next, &psd->tx_del.active);
+	}
+
+	netdev_unlock(psd->main_netdev);
+
+	list_for_each_entry(pas, &to_free, assocs_list)
+		psp_dev_tx_key_del(psd, pas);
+
+	need_reschedule = psp_tx_grace_active(psd);
+	mutex_unlock(&psd->lock);
+
+	if (need_reschedule)
+		mod_delayed_work(system_percpu_wq, &psd->tx_del.work,
+				 msecs_to_jiffies(PSP_TX_GRACE_POLL_MS));
+
+	list_for_each_entry_safe(pas, tmp, &to_free, assocs_list) {
+		list_del(&pas->assocs_list);
+		psp_dev_put(psd);
+		kfree(pas);
+	}
+}
+
+int psp_deferred_del_init(struct psp_dev *psd)
+{
+	INIT_LIST_HEAD(&psd->tx_del.active);
+	INIT_LIST_HEAD(&psd->tx_del.next);
+	INIT_DELAYED_WORK(&psd->tx_del.work, psp_deferred_del_work);
+
+	if (!psd->ops->tx_key_del)
+		return 0;
+
+	psd->tx_del.txq_state =
+		psp_txq_state_alloc(psd->main_netdev->num_tx_queues);
+
+	return psd->tx_del.txq_state ? 0 : -ENOMEM;
+}
+
+void psp_deferred_del_stop(struct psp_dev *psd)
+{
+	disable_delayed_work_sync(&psd->tx_del.work);
+}
+
+void psp_deferred_del_uninit(struct psp_dev *psd, bool unpublished)
+{
+	struct psp_assoc *pas, *next;
+
+	lockdep_assert(unpublished || lockdep_is_held(&psd->lock));
+
+	psp_txq_state_free(psd->tx_del.txq_state);
+	psd->tx_del.txq_state = NULL;
+
+	list_splice_init(&psd->tx_del.active, &psd->tx_del.next);
+	list_for_each_entry_safe(pas, next, &psd->tx_del.next, assocs_list) {
+		list_del(&pas->assocs_list);
+		psp_dev_tx_key_del(psd, pas);
+		psp_dev_put(psd);
+		kfree(pas);
+	}
+}
+
+void psp_deferred_del_queue(struct psp_dev *psd, struct psp_assoc *pas)
+{
+	lockdep_assert_held(&psd->lock);
+
+	list_move_tail(&pas->assocs_list, &psd->tx_del.next);
+	schedule_delayed_work(&psd->tx_del.work, 0);
+}
diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
index 273b010d2355c..9f256157d88bf 100644
--- a/net/psp/psp_main.c
+++ b/net/psp/psp_main.c
@@ -3,8 +3,10 @@
 #include <linux/bitfield.h>
 #include <linux/list.h>
 #include <linux/netdevice.h>
+#include <linux/slab.h>
 #include <linux/xarray.h>
 #include <net/net_namespace.h>
+#include <net/netdev_lock.h>
 #include <net/psp.h>
 #include <net/udp.h>
 
@@ -70,7 +72,8 @@ psp_dev_create(struct net_device *netdev,
 		    !psd_ops->rx_spi_alloc ||
 		    !psd_ops->get_stats ||
 		    (!psd_ops->tx_key_add != !psd_ops->tx_key_del) ||
-		    (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add)))
+		    (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add) ||
+		    (psd_ops->tx_key_add && !netdev_need_ops_lock(netdev))))
 		return ERR_PTR(-EINVAL);
 
 	psd = kzalloc_obj(*psd);
@@ -89,13 +92,16 @@ psp_dev_create(struct net_device *netdev,
 	INIT_LIST_HEAD(&psd->stale_assocs);
 	refcount_set(&psd->refcnt, 1);
 
+	err = psp_deferred_del_init(psd);
+	if (err)
+		goto err_free_psd;
+
 	mutex_lock(&psp_devs_lock);
 	err = xa_alloc_cyclic(&psp_devs, &psd->id, psd, xa_limit_16b,
 			      &last_id, GFP_KERNEL);
 	if (err) {
 		mutex_unlock(&psp_devs_lock);
-		kfree(psd);
-		return ERR_PTR(err);
+		goto err_uninit_deferred_del;
 	}
 	mutex_lock(&psd->lock);
 	mutex_unlock(&psp_devs_lock);
@@ -111,6 +117,12 @@ psp_dev_create(struct net_device *netdev,
 	mutex_unlock(&psd->lock);
 
 	return psd;
+
+err_uninit_deferred_del:
+	psp_deferred_del_uninit(psd, true);
+err_free_psd:
+	kfree(psd);
+	return ERR_PTR(err);
 }
 EXPORT_SYMBOL(psp_dev_create);
 
@@ -133,6 +145,8 @@ void psp_dev_unregister(struct psp_dev *psd)
 	struct psp_assoc_dev *entry, *entry_tmp;
 	struct psp_assoc *pas, *next;
 
+	psp_deferred_del_stop(psd);
+
 	mutex_lock(&psp_devs_lock);
 	mutex_lock(&psd->lock);
 
@@ -145,6 +159,8 @@ void psp_dev_unregister(struct psp_dev *psd)
 	xa_store(&psp_devs, psd->id, NULL, GFP_KERNEL);
 	mutex_unlock(&psp_devs_lock);
 
+	psp_deferred_del_uninit(psd, false);
+
 	list_splice_init(&psd->active_assocs, &psd->prev_assocs);
 	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
 	list_for_each_entry_safe(pas, next, &psd->stale_assocs, assocs_list) {
@@ -153,6 +169,9 @@ void psp_dev_unregister(struct psp_dev *psd)
 		list_del(&pas->assocs_list);
 	}
 
+	WARN(psd->stats.tx_key_cnt, "psp: %s: %lu Tx keys still installed\n",
+	     netdev_name(psd->main_netdev), psd->stats.tx_key_cnt);
+
 	list_for_each_entry_safe(entry, entry_tmp, &psd->assoc_dev_list,
 				 dev_list) {
 		list_del(&entry->dev_list);
diff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c
index cdfc2d72fb390..494022ab5a718 100644
--- a/net/psp/psp_nl.c
+++ b/net/psp/psp_nl.c
@@ -934,6 +934,10 @@ psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp,
 	    nla_put_uint(rsp, PSP_A_STATS_TX_ERROR, stats.tx_error))
 		goto err_cancel_msg;
 
+	if (psp_dev_has_sadb(psd) &&
+	    nla_put_uint(rsp, PSP_A_STATS_TX_KEY_COUNT, psd->stats.tx_key_cnt))
+		goto err_cancel_msg;
+
 	genlmsg_end(rsp, hdr);
 	return 0;
 
diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c
index a6b1c42dd626f..c458bc551b4b9 100644
--- a/net/psp/psp_sock.c
+++ b/net/psp/psp_sock.c
@@ -94,9 +94,11 @@ static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,
 
 	memcpy(&dummy->tx, key, sizeof(*key));
 	err = psd->ops->tx_key_add(psd, dummy, extack);
-	if (!err)
+	if (!err) {
+		psd->stats.tx_key_cnt++;
 		memcpy(pas->drv_data, dummy->drv_data,
 		       psd->caps->assoc_drv_spc);
+	}
 
 	kfree(dummy);
 	return err;
@@ -105,6 +107,8 @@ static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,
 void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas)
 {
 	psd->ops->tx_key_del(psd, pas);
+	if (!WARN_ON_ONCE(!psd->stats.tx_key_cnt))
+		psd->stats.tx_key_cnt--;
 }
 
 static void psp_assoc_free(struct work_struct *work)
@@ -114,8 +118,14 @@ static void psp_assoc_free(struct work_struct *work)
 
 	mutex_lock(&psd->lock);
 	if (psp_dev_is_registered(psd)) {
-		if (psp_assoc_needs_tx_key_del(pas))
+		if (psp_assoc_needs_tx_key_del(pas)) {
+			if (pas->flags & PSP_ASSOC_DEFER_TX_KEY_DEL) {
+				psp_deferred_del_queue(psd, pas);
+				mutex_unlock(&psd->lock);
+				return;
+			}
 			psp_dev_tx_key_del(psd, pas);
+		}
 		list_del(&pas->assocs_list);
 	}
 	mutex_unlock(&psd->lock);
@@ -149,10 +159,42 @@ void psp_sk_assoc_free(struct sock *sk)
 	psp_assoc_put(pas);
 }
 
+static int psp_sock_rx_rekey(struct psp_assoc *pas, struct psp_assoc *prev,
+			     struct netlink_ext_ack *extack)
+{
+	if (pas->psd != prev->psd) {
+		NL_SET_ERR_MSG(extack, "PSP device mismatch with existing state");
+		return -EINVAL;
+	}
+	if (pas->version != prev->version) {
+		NL_SET_ERR_MSG(extack, "PSP version mismatch with existing state");
+		return -EINVAL;
+	}
+	if (!prev->tx.spi || !prev->peer_tx) {
+		NL_SET_ERR_MSG(extack, "Socket PSP state is not fully established");
+		return -EBUSY;
+	}
+	if (!((pas->rx.spi ^ prev->rx.spi) & cpu_to_be32(PSP_SPI_KEY_PHASE))) {
+		NL_SET_ERR_MSG(extack, "New and prev SPI have same phase bit");
+		return -EINVAL;
+	}
+
+	pas->peer_tx = 1;
+	pas->prev_spi = prev->rx.spi;
+	pas->prev_generation = prev->generation;
+
+	memcpy(&pas->tx, &prev->tx, sizeof(pas->tx));
+	memcpy(pas->drv_data, prev->drv_data, pas->psd->caps->assoc_drv_spc);
+	prev->flags |= PSP_ASSOC_SKIP_TX_KEY_DEL;
+
+	return 0;
+}
+
 int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 			  struct psp_key_parsed *key,
 			  struct netlink_ext_ack *extack)
 {
+	struct psp_assoc *prev;
 	int err;
 
 	memcpy(&pas->rx, key, sizeof(*key));
@@ -165,10 +207,11 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 		goto exit_unlock;
 	}
 
-	if (psp_sk_assoc(sk)) {
-		NL_SET_ERR_MSG(extack, "Socket already has PSP state");
-		err = -EBUSY;
-		goto exit_unlock;
+	prev = psp_sk_assoc(sk);
+	if (prev) {
+		err = psp_sock_rx_rekey(pas, prev, extack);
+		if (err)
+			goto exit_unlock;
 	} else if (sk_has_decrypt_user(sk)) {
 		NL_SET_ERR_MSG(extack, "Socket has incompatible state");
 		err = -EINVAL;
@@ -177,6 +220,7 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 
 	refcount_inc(&pas->refcnt);
 	rcu_assign_pointer(sk->psp_assoc, pas);
+	psp_assoc_put(prev);
 	err = 0;
 
 exit_unlock:
@@ -249,6 +293,49 @@ psp_sock_set_tx_key(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,
 	return err;
 }
 
+static int
+psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,
+		  struct psp_key_parsed *key, struct netlink_ext_ack *extack)
+{
+	struct psp_assoc *new;
+	int err;
+
+	if (!pas->peer_tx) {
+		NL_SET_ERR_MSG(extack, "Socket PSP state is not fully established");
+		return -EBUSY;
+	}
+
+	new = kzalloc_flex(*new, drv_data, psd->caps->assoc_drv_spc,
+			   GFP_KERNEL_ACCOUNT);
+	if (!new)
+		return -ENOMEM;
+
+	new->psd             = pas->psd;
+	new->dev_id          = pas->dev_id;
+	new->generation      = pas->generation;
+	new->version         = pas->version;
+	new->peer_tx         = 1;
+	new->prev_spi        = pas->prev_spi;
+	new->prev_generation = pas->prev_generation;
+	refcount_set(&new->refcnt, 1);
+	memcpy(&new->rx, &pas->rx, sizeof(new->rx));
+
+	err = psp_assoc_set_tx(psd, new, key, extack);
+	if (err) {
+		kfree(new);
+		return err;
+	}
+
+	psp_dev_get(new->psd);
+	list_add(&new->assocs_list, &pas->assocs_list);
+
+	rcu_assign_pointer(sk->psp_assoc, new);
+	pas->flags |= PSP_ASSOC_DEFER_TX_KEY_DEL;
+	psp_assoc_put(pas);
+
+	return 0;
+}
+
 int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
 			  u32 version, struct psp_key_parsed *key,
 			  struct netlink_ext_ack *extack)
@@ -281,13 +368,11 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
 		err = -EINVAL;
 		goto exit_unlock;
 	}
-	if (pas->tx.spi) {
-		NL_SET_ERR_MSG(extack, "Tx key already set");
-		err = -EBUSY;
-		goto exit_unlock;
-	}
+	if (pas->tx.spi)
+		err = psp_sock_tx_rekey(sk, psd, pas, key, extack);
+	else
+		err = psp_sock_set_tx_key(sk, psd, pas, key, extack);
 
-	err = psp_sock_set_tx_key(sk, psd, pas, key, extack);
 exit_unlock:
 	release_sock(sk);
 	return err;
@@ -304,6 +389,10 @@ void psp_assocs_key_rotated(struct psp_dev *psd)
 		pas->generation |= ~PSP_GEN_VALID_MASK;
 		psd->stats.stales++;
 	}
+
+	list_for_each_entry(pas, &psd->active_assocs, assocs_list)
+		pas->prev_generation |= ~PSP_GEN_VALID_MASK;
+
 	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
 	list_splice_init(&psd->active_assocs, &psd->prev_assocs);
 
diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py
index 473500901879b..b22891b7f5ce8 100755
--- a/tools/testing/selftests/drivers/net/psp.py
+++ b/tools/testing/selftests/drivers/net/psp.py
@@ -15,7 +15,7 @@ from contextlib import contextmanager
 
 from lib.py import defer
 from lib.py import ksft_run, ksft_exit, ksft_pr
-from lib.py import ksft_true, ksft_eq, ksft_ne, ksft_gt, ksft_raises
+from lib.py import ksft_true, ksft_eq, ksft_ne, ksft_ge, ksft_gt, ksft_raises
 from lib.py import ksft_not_none
 from lib.py import ksft_variants, KsftNamedVariant
 from lib.py import KsftSkipEx, KsftFailEx
@@ -28,6 +28,12 @@ from lib.py import ip
 TCP_ULP = 31
 
 
+_PSP_MAX_KEY_LEN = 32
+_PSP_ASSOC_MSG = f'!IB3x{_PSP_MAX_KEY_LEN}s'
+_TX_REKEY_ROUNDS = 20
+_TX_KEY_DRAIN_TIMEOUT = 5
+
+
 def _get_outq(s):
     one = b'\0' * 4
     outq = fcntl.ioctl(s.fileno(), termios.TIOCOUTQ, one)
@@ -80,6 +86,36 @@ def _close_psp_conn(cfg, s):
     _close_conn(cfg, s)
 
 
+def _recv_all(s, target):
+    data = b''
+    while len(data) < target:
+        chunk = s.recv(target - len(data))
+        if not chunk:
+            raise KsftFailEx(f"peer closed after {len(data)} of {target} bytes")
+        data += chunk
+    return data
+
+
+def _psp_key_len(version):
+    return 16 if version in (0, 2) else 32
+
+
+def _remote_rx_assoc(cfg):
+    _send_with_ack(cfg, b'rx assoc\0')
+    msg = _recv_all(cfg.comm_sock, struct.calcsize(_PSP_ASSOC_MSG))
+    spi, version, key = struct.unpack(_PSP_ASSOC_MSG, msg)
+    return version, {'spi': spi, 'key': key[:_psp_key_len(version)]}
+
+
+def _remote_tx_assoc(cfg, version, rx):
+    msg = struct.pack(_PSP_ASSOC_MSG, rx['spi'], version, rx['key'])
+    _send_with_ack(cfg, b'tx assoc\0' + msg)
+
+
+def _remote_key_rotate(cfg):
+    _send_with_ack(cfg, b'key rotate\0')
+
+
 def _spi_xchg(s, rx):
     s.send(struct.pack('I', rx['spi']) + rx['key'])
     tx = s.recv(4 + len(rx['key']))
@@ -130,9 +166,57 @@ def _check_data_outq(s, exp_len, force_wait=False):
     ksft_eq(outq, exp_len)
 
 
+def _recv_careful(s, target, timeout=2):
+    """Read exactly target bytes, tolerating short reads"""
+    data = b''
+    end = time.monotonic() + timeout
+    while time.monotonic() < end:
+        try:
+            data += s.recv(target - len(data), socket.MSG_DONTWAIT)
+            if len(data) == target:
+                return data
+        except BlockingIOError:
+            time.sleep(0.001)
+    raise KsftFailEx(f"short read, got {len(data)} of {target} bytes")
+
+
+def _req_echo(cfg, s):
+    """Ask the peer to echo, and check the reply arrives intact"""
+    _send_with_ack(cfg, b'data echo\0')
+    ksft_eq(_recv_careful(s, 5), b'echo\0')
+
+
+def _psp_txrx(cfg, s, rounds, sent=0):
+    """Send data both ways, and return the total bytes sent to the peer"""
+    sent += _send_careful(cfg, s, rounds)
+    _check_data_rx(cfg, sent)
+    _req_echo(cfg, s)
+    return sent
+
+
+def _require_version(cfg, version):
+    """Skip the test unless the device supports the given PSP version"""
+    name = cfg.pspnl.consts["version"].entries_by_val[version].name
+    if name not in cfg.psp_info['psp-versions-cap']:
+        raise KsftSkipEx("PSP version not supported", name)
+
+
 def _get_stat(cfg, key):
     return cfg.pspnl.get_stats({'dev-id': cfg.psp_dev_id})[key]
 
+
+def _get_tx_key_count(cfg):
+    return cfg.pspnl.get_stats({'dev-id': cfg.psp_dev_id}).get('tx-key-count')
+
+
+def _wait_tx_key_drain(cfg, base):
+    cnt = _get_tx_key_count(cfg)
+    end = time.monotonic() + _TX_KEY_DRAIN_TIMEOUT
+    while cnt > base and time.monotonic() < end:
+        time.sleep(0.1)
+        cnt = _get_tx_key_count(cfg)
+    ksft_ge(base, cnt, comment="tx keys not removed from device after rekey")
+
 #
 # Test case boiler plate
 #
@@ -447,10 +531,11 @@ def assoc_twice(cfg):
             ksft_eq(len(tx), 0)
 
 
-def _data_basic_send(cfg, version, ipver):
-    """ Test basic data send """
-    _init_psp_dev(cfg)
+def _establish_psp_conn(cfg, version, ipver=None):
+    """Establish a PSP connection and return after key exchange
 
+    Requires _init_psp_dev() to have been called first.
+    """
     # Version 0 is required by spec, don't let it skip
     if version:
         name = cfg.pspnl.consts["version"].entries_by_val[version].name
@@ -475,12 +560,238 @@ def _data_basic_send(cfg, version, ipver):
                         "version": version,
                         "tx-key": tx,
                         "sock-fd": s.fileno()})
+    return s
 
+
+def _data_basic_send(cfg, version, ipver):
+    """ Test basic data send """
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, version, ipver)
     data_len = _send_careful(cfg, s, 100)
     _check_data_rx(cfg, data_len)
     _close_psp_conn(cfg, s)
 
 
+def _rekey_rx(cfg, s, version, sent):
+    """Rekey the Rx direction, running traffic after each step"""
+    rx_assoc = cfg.pspnl.rx_assoc({"version": version,
+                                   "dev-id": cfg.psp_dev_id,
+                                   "sock-fd": s.fileno()})
+    sent = _psp_txrx(cfg, s, 1, sent)
+
+    _remote_tx_assoc(cfg, version, rx_assoc['rx-key'])
+    return _psp_txrx(cfg, s, 1, sent)
+
+
+def _rekey_tx(cfg, s, sent):
+    """Rekey the Tx direction, running traffic after each step"""
+    version, tx = _remote_rx_assoc(cfg)
+    sent = _psp_txrx(cfg, s, 1, sent)
+
+    cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                        "version": version,
+                        "tx-key": tx,
+                        "sock-fd": s.fileno()})
+    return _psp_txrx(cfg, s, 1, sent)
+
+
+def rekey_rx_incomplete(cfg):
+    """Test rejecting Rx rekey until the PSP connection is established"""
+    psp_ver = 0
+    _init_psp_dev(cfg)
+
+    with _make_lo_conn() as s:
+        assoc = cfg.pspnl.rx_assoc({"version": psp_ver,
+                                    "dev-id": cfg.psp_dev_id,
+                                    "sock-fd": s.fileno()})
+
+        # Reject rekey before Tx state is configured.
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.rx_assoc({"version": psp_ver,
+                                "dev-id": cfg.psp_dev_id,
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY)
+
+        cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                            "version": psp_ver,
+                            "tx-key": assoc['rx-key'],
+                            "sock-fd": s.fileno()})
+
+        # Reject rekey until authenticated PSP traffic has been received.
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.rx_assoc({"version": psp_ver,
+                                "dev-id": cfg.psp_dev_id,
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY)
+
+
+def rekey_tx_incomplete(cfg):
+    """Test rejecting Tx rekey until the PSP connection is established"""
+    psp_ver = 0
+    _init_psp_dev(cfg)
+
+    with _make_lo_conn() as s:
+        assoc = cfg.pspnl.rx_assoc({"version": psp_ver,
+                                    "dev-id": cfg.psp_dev_id,
+                                    "sock-fd": s.fileno()})
+
+        cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                            "version": psp_ver,
+                            "tx-key": assoc['rx-key'],
+                            "sock-fd": s.fileno()})
+
+        # Reject rekey until authenticated PSP traffic has been received.
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                                "version": psp_ver,
+                                "tx-key": assoc['rx-key'],
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY)
+
+
+def rekey_rx_same_gen(cfg):
+    """Test rejecting an Rx rekey without an intervening key rotation"""
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, 0)
+    try:
+        _psp_txrx(cfg, s, 1)
+
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.rx_assoc({"version": 0,
+                                "dev-id": cfg.psp_dev_id,
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL)
+
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+        cfg.pspnl.rx_assoc({"version": 0,
+                            "dev-id": cfg.psp_dev_id,
+                            "sock-fd": s.fileno()})
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+def rekey_rx_version_mismatch(cfg):
+    """Test rejecting an Rx rekey whose version does not match socket state"""
+    _init_psp_dev(cfg)
+    _require_version(cfg, 1)
+
+    s = _establish_psp_conn(cfg, 0)
+    try:
+        _psp_txrx(cfg, s, 1)
+
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.rx_assoc({"dev-id": cfg.psp_dev_id,
+                                "version": 1,
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+def rekey_tx_version_mismatch(cfg):
+    """Test rejecting a Tx rekey whose version does not match socket state"""
+    _init_psp_dev(cfg)
+    _require_version(cfg, 1)
+
+    s = _establish_psp_conn(cfg, 0)
+    try:
+        _psp_txrx(cfg, s, 1)
+
+        with ksft_raises(NlError) as cm:
+            cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+                                "version": 1,
+                                "tx-key": {'spi': 0x12345678,
+                                           'key': b'\xa5' * 32},
+                                "sock-fd": s.fileno()})
+        ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+def _get_psp_ver_variants():
+    for ver in range(4):
+        yield KsftNamedVariant(f"v{ver}", ver)
+
+
+@ksft_variants(_get_psp_ver_variants())
+def rekey_rx_basic(cfg, version):
+    """Test rekeying the Rx key of an established connection"""
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, version)
+    try:
+        data_len = _psp_txrx(cfg, s, 10)
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+        _rekey_rx(cfg, s, version, data_len)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+@ksft_variants(_get_psp_ver_variants())
+def rekey_tx_basic(cfg, version):
+    """Test rekeying the Tx key of an established connection"""
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, version)
+    try:
+        data_len = _psp_txrx(cfg, s, 10)
+        _remote_key_rotate(cfg)
+        _rekey_tx(cfg, s, data_len)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+def rekey_tx_drain(cfg):
+    """Test that Tx rekeys do not leak keys on the device"""
+    _init_psp_dev(cfg)
+
+    if _get_tx_key_count(cfg) is None:
+        raise KsftSkipEx("Device does not track Tx keys")
+
+    s = _establish_psp_conn(cfg, 0)
+    try:
+        data_len = _psp_txrx(cfg, s, 1)
+        base = _get_tx_key_count(cfg)
+
+        for _ in range(_TX_REKEY_ROUNDS):
+            _remote_key_rotate(cfg)
+            data_len = _rekey_tx(cfg, s, data_len)
+
+        _wait_tx_key_drain(cfg, base)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
+@ksft_variants(_get_psp_ver_variants())
+def rekey_both_sides(cfg, version):
+    """Test rekeying both directions"""
+    _init_psp_dev(cfg)
+
+    s = _establish_psp_conn(cfg, version)
+    try:
+        data_len = _psp_txrx(cfg, s, 10)
+
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+        _remote_key_rotate(cfg)
+
+        # first, rx then tx
+        data_len = _rekey_rx(cfg, s, version, data_len)
+        data_len = _rekey_tx(cfg, s, data_len)
+
+        cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+        _remote_key_rotate(cfg)
+
+        # now, tx then rx
+        data_len = _rekey_tx(cfg, s, data_len)
+        _rekey_rx(cfg, s, version, data_len)
+    finally:
+        _close_psp_conn(cfg, s)
+
+
 def __bad_xfer_do(cfg, s, tx, version='hdr0-aes-gcm-128'):
     # Make sure we accept the ACK for the SPI before we seal with the bad assoc
     _check_data_outq(s, 0)
@@ -1173,7 +1484,8 @@ def main() -> None:
                                                           cfg.comm_port),
                                                          timeout=1)
 
-                cases = [data_basic_send, data_mss_adjust]
+                cases = [data_basic_send, data_mss_adjust,
+                         rekey_rx_basic, rekey_tx_basic, rekey_both_sides]
 
                 if has_cont:
                     cases += [
@@ -1189,7 +1501,8 @@ def main() -> None:
                     ]
 
                 ksft_run(cases=cases, globs=globals(),
-                         case_pfx={"dev_", "data_", "assoc_", "removal_"},
+                         case_pfx={"dev_", "data_", "assoc_", "rekey_",
+                                   "removal_"},
                          args=(cfg, ))
 
                 cfg.comm_sock.send(b"exit\0")
diff --git a/tools/testing/selftests/drivers/net/psp_responder.c b/tools/testing/selftests/drivers/net/psp_responder.c
index a26e7628bbb13..b3e0fe6d69750 100644
--- a/tools/testing/selftests/drivers/net/psp_responder.c
+++ b/tools/testing/selftests/drivers/net/psp_responder.c
@@ -5,6 +5,7 @@
 #include <sys/poll.h>
 #include <sys/socket.h>
 #include <sys/time.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <unistd.h>
 
@@ -23,6 +24,7 @@ static bool should_quit;
 struct opts {
 	int port;
 	int ifindex;
+	int devid;
 	bool verbose;
 };
 
@@ -37,20 +39,24 @@ static struct {
 	unsigned char rx;
 } psp_vers;
 
-static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)
+static unsigned int psp_key_len(unsigned char version)
 {
+	switch (version) {
+	case PSP_VERSION_HDR0_AES_GCM_256:
+	case PSP_VERSION_HDR0_AES_GMAC_256:
+		return 32;
+	default:
+		return 16;
+	}
+}
+
+static int
+rx_assoc(struct ynl_sock *ys, __u32 *spi, char *key, int data_sock)
+{
+	unsigned int key_len = psp_key_len(psp_vers.rx);
 	struct psp_rx_assoc_rsp *rsp;
 	struct psp_rx_assoc_req *req;
-	struct psp_tx_assoc_rsp *tsp;
-	struct psp_tx_assoc_req *teq;
-	char info[300];
-	int key_len;
-	ssize_t sz;
-	__u32 spi;
 
-	dbg("create PSP connection\n");
-
-	// Rx assoc alloc
 	req = psp_rx_assoc_req_alloc();
 
 	psp_rx_assoc_req_set_sock_fd(req, data_sock);
@@ -64,29 +70,34 @@ static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)
 		return -1;
 	}
 
-	// SPI exchange
-	key_len = rsp->rx_key._len.key;
-	memcpy(info, &rsp->rx_key.spi, sizeof(spi));
-	memcpy(&info[sizeof(spi)], rsp->rx_key.key, key_len);
-	sz = sizeof(spi) + key_len;
+	if (rsp->rx_key._len.key != key_len) {
+		fprintf(stderr, "ERROR: unexpected Rx key length %u\n",
+			rsp->rx_key._len.key);
+		psp_rx_assoc_rsp_free(rsp);
+		return -1;
+	}
+
+	memcpy(spi, &rsp->rx_key.spi, sizeof(*spi));
+	memcpy(key, rsp->rx_key.key, key_len);
 
-	send(data_sock, info, sz, MSG_WAITALL);
 	psp_rx_assoc_rsp_free(rsp);
 
-	sz = recv(data_sock, info, sz, MSG_WAITALL);
-	if (sz < 0) {
-		perror("ERROR: failed to read PSP key from sock");
-		return -1;
-	}
-	memcpy(&spi, info, sizeof(spi));
+	return 0;
+}
+
+static int
+tx_assoc(struct ynl_sock *ys, __u8 version, __u32 spi, char *key,
+	 int data_sock)
+{
+	struct psp_tx_assoc_rsp *tsp;
+	struct psp_tx_assoc_req *teq;
 
-	// Setup Tx assoc
 	teq = psp_tx_assoc_req_alloc();
 
 	psp_tx_assoc_req_set_sock_fd(teq, data_sock);
-	psp_tx_assoc_req_set_version(teq, psp_vers.tx);
+	psp_tx_assoc_req_set_version(teq, version);
 	psp_tx_assoc_req_set_tx_key_spi(teq, spi);
-	psp_tx_assoc_req_set_tx_key_key(teq, &info[sizeof(spi)], key_len);
+	psp_tx_assoc_req_set_tx_key_key(teq, key, psp_key_len(version));
 
 	tsp = psp_tx_assoc(ys, teq);
 	psp_tx_assoc_req_free(teq);
@@ -99,6 +110,34 @@ static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)
 	return 0;
 }
 
+static int conn_setup_psp(struct ynl_sock *ys, struct opts *opts, int data_sock)
+{
+	unsigned int key_len = psp_key_len(psp_vers.rx);
+	char info[300];
+	ssize_t sz;
+	__u32 spi;
+
+	dbg("create PSP connection\n");
+
+	if (rx_assoc(ys, &spi, &info[sizeof(spi)], data_sock))
+		return -1;
+
+	// SPI exchange
+	memcpy(info, &spi, sizeof(spi));
+	sz = sizeof(spi) + key_len;
+
+	send(data_sock, info, sz, MSG_WAITALL);
+
+	sz = recv(data_sock, info, sz, MSG_WAITALL);
+	if (sz < 0) {
+		perror("ERROR: failed to read PSP key from sock");
+		return -1;
+	}
+	memcpy(&spi, info, sizeof(spi));
+
+	return tx_assoc(ys, psp_vers.tx, spi, &info[sizeof(spi)], data_sock);
+}
+
 static void send_ack(int sock)
 {
 	send(sock, "ack", 4, MSG_WAITALL);
@@ -118,6 +157,100 @@ static void send_str(int sock, int value)
 	send(sock, buf, ret + 1, MSG_WAITALL);
 }
 
+#define PSP_MAX_KEY_LEN		32
+
+struct assoc_msg {
+	__be32 spi;
+	__u8 version;
+	__u8 pad[3];
+	char key[PSP_MAX_KEY_LEN];
+};
+
+static void
+handle_rx_assoc(struct ynl_sock *ys, int data_sock, int comm_sock)
+{
+	struct assoc_msg msg = {};
+	__u32 spi;
+
+	if (data_sock < 0) {
+		fprintf(stderr, "WARN: rx assoc but no data sock\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	if (rx_assoc(ys, &spi, msg.key, data_sock)) {
+		fprintf(stderr, "ERROR: rx_assoc() failed\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	msg.spi = htonl(spi);
+	msg.version = psp_vers.rx;
+	send_ack(comm_sock);
+	send(comm_sock, &msg, sizeof(msg), MSG_WAITALL);
+}
+
+static void
+handle_tx_assoc(struct ynl_sock *ys, char *data, int data_sock, int comm_sock)
+{
+	struct assoc_msg msg;
+
+	if (data_sock < 0) {
+		fprintf(stderr, "WARN: tx assoc but no data sock\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	memcpy(&msg, data, sizeof(msg));
+	if (tx_assoc(ys, msg.version, ntohl(msg.spi), msg.key, data_sock)) {
+		fprintf(stderr, "ERROR: tx_assoc() failed!\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	send_ack(comm_sock);
+}
+
+static int rotate_key(struct ynl_sock *ys, int devid)
+{
+	struct psp_key_rotate_rsp *rsp;
+	struct psp_key_rotate_req *req;
+
+	req = psp_key_rotate_req_alloc();
+
+	psp_key_rotate_req_set_id(req, devid);
+
+	rsp = psp_key_rotate(ys, req);
+	psp_key_rotate_req_free(req);
+
+	if (!rsp) {
+		perror("ERROR: failed to rotate key");
+		return -1;
+	}
+
+	psp_key_rotate_rsp_free(rsp);
+
+	return 0;
+}
+
+static void
+handle_key_rotate(struct ynl_sock *ys, struct opts *opts, int comm_sock)
+{
+	if (opts->devid < 0) {
+		fprintf(stderr, "WARN: key rotate but no PSP device\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	if (rotate_key(ys, opts->devid)) {
+		fprintf(stderr, "ERROR: rotate_key() failed\n");
+		send_err(comm_sock);
+		return;
+	}
+
+	send_ack(comm_sock);
+}
+
 static void
 run_session(struct ynl_sock *ys, struct opts *opts,
 	    int server_sock, int comm_sock)
@@ -210,6 +343,9 @@ run_session(struct ynl_sock *ys, struct opts *opts,
 			match;						\
 		})
 
+#define cmd_w_msg(_name, _type)						\
+		(off >= sizeof(_name) + sizeof(_type) && cmd(_name))
+
 			do {
 				consumed = false;
 
@@ -224,6 +360,16 @@ run_session(struct ynl_sock *ys, struct opts *opts,
 						fprintf(stderr, "WARN: echo but no data sock\n");
 					send_ack(comm_sock);
 				}
+				if (cmd("rx assoc"))
+					handle_rx_assoc(ys, data_sock,
+							comm_sock);
+				if (cmd_w_msg("tx assoc", struct assoc_msg)) {
+					handle_tx_assoc(ys, buf, data_sock,
+							comm_sock);
+					__consume(sizeof(struct assoc_msg));
+				}
+				if (cmd("key rotate"))
+					handle_key_rotate(ys, opts, comm_sock);
 				if (cmd("data close")) {
 					if (data_sock >= 0) {
 						close(data_sock);
@@ -254,6 +400,7 @@ run_session(struct ynl_sock *ys, struct opts *opts,
 				}
 				if (cmd("exit"))
 					should_quit = true;
+#undef cmd_w_msg
 #undef cmd
 
 				if (!consumed) {
@@ -449,6 +596,7 @@ int main(int argc, char **argv)
 		}
 	}
 	psp_dev_get_list_free(dev_list);
+	opts.devid = devid;
 
 	if (opts.ifindex && devid < 0)
 		fprintf(stderr,

53/3 2026/10/09 23:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20360
							output: 31
							thoughts: 759
						

Thoughts:
**KMSAN Fuzzing Evaluation for PSP Rekeying**

Okay, so I need to decide if this patch warrants a KMSAN fuzzing session. My initial thought is to understand the scope of the changes first. This patch touches quite a few files related to the PSP Security Protocol: documentation, headers, Kconfig, Makefile, and several C files in `net/psp`, along with some selftests.

It looks like the primary focus here is rekeying for PSP associations, and importantly, deferred Tx key deletion. That's good, it suggests more complex logic is involved, which increases the likelihood of finding memory safety issues.

Let me drill down into the code changes. I'm seeing changes in `psp_deferred_del.c`. There's allocation with zeroing in `psp_txq_state_alloc`, including `bitmap_zalloc`. That's good. In the other functions, I see reads of `num_queued` and `num_completed` which is always a good area to check. There are also functions for deferred deletion management.

Moving to `psp_nl.c`, I see a critical area: the netlink statistics reporting. It looks like `psd->stats.tx_key_cnt` is being exposed via netlink. I know that `psd` is zero-initialized using `kzalloc`. The counter is an `unsigned long` that's incremented on key addition and decremented on key deletion. But `nla_put_uint` could be a problem; it's possible for there to be a size mismatch when putting into the netlink SKB, which could lead to a possible overflow.

I need to confirm the size of `nla_put_uint` and how it's used within this file to see if there is a possible mismatch of data types. I will use a `read-file` or `grepper` command to look around line 934 in `psp_nl.c`. This could be important.



54/3 2026/10/09 23:10 tool grepper
0m Args:
{
  "Expression": "nla_put_uint",
  "PathPrefixes": [
    "net/psp/"
  ]
}

Results:
{
  "Output": "net/psp/psp_nl.c=904=psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp,\n--\nnet/psp/psp_nl.c-923-\tif (nla_put_u32(rsp, PSP_A_STATS_DEV_ID, psd-\u003eid) ||\nnet/psp/psp_nl.c:924:\t    nla_put_uint(rsp, PSP_A_STATS_KEY_ROTATIONS,\nnet/psp/psp_nl.c-925-\t\t\t psd-\u003estats.rotations) ||\nnet/psp/psp_nl.c:926:\t    nla_put_uint(rsp, PSP_A_STATS_STALE_EVENTS, psd-\u003estats.stales) ||\nnet/psp/psp_nl.c:927:\t    nla_put_uint(rsp, PSP_A_STATS_RX_PACKETS, stats.rx_packets) ||\nnet/psp/psp_nl.c:928:\t    nla_put_uint(rsp, PSP_A_STATS_RX_BYTES, stats.rx_bytes) ||\nnet/psp/psp_nl.c:929:\t    nla_put_uint(rsp, PSP_A_STATS_RX_AUTH_FAIL, stats.rx_auth_fail) ||\nnet/psp/psp_nl.c:930:\t    nla_put_uint(rsp, PSP_A_STATS_RX_ERROR, stats.rx_error) ||\nnet/psp/psp_nl.c:931:\t    nla_put_uint(rsp, PSP_A_STATS_RX_BAD, stats.rx_bad) ||\nnet/psp/psp_nl.c:932:\t    nla_put_uint(rsp, PSP_A_STATS_TX_PACKETS, stats.tx_packets) ||\nnet/psp/psp_nl.c:933:\t    nla_put_uint(rsp, PSP_A_STATS_TX_BYTES, stats.tx_bytes) ||\nnet/psp/psp_nl.c:934:\t    nla_put_uint(rsp, PSP_A_STATS_TX_ERROR, stats.tx_error))\nnet/psp/psp_nl.c-935-\t\tgoto err_cancel_msg;\n--\nnet/psp/psp_nl.c-937-\tif (psp_dev_has_sadb(psd) \u0026\u0026\nnet/psp/psp_nl.c:938:\t    nla_put_uint(rsp, PSP_A_STATS_TX_KEY_COUNT, psd-\u003estats.tx_key_cnt))\nnet/psp/psp_nl.c-939-\t\tgoto err_cancel_msg;\n"
}

55/3 2026/10/09 23:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22258
							output: 34
							thoughts: 456
						

Thoughts:
**Analyzing PSP Association Rekeying**

Okay, let's dive into this `psp_sock.c` file and understand how `psp_assoc` structures are allocated and initialized. I'm focusing on the rekeying process, specifically the transmit (`tx`) and receive (`rx`) key updates.

First, I'm examining `psp_sock_tx_rekey`. I see a `kzalloc_flex` call for `new`. Excellent, that's crucial. I'm noting that this function zeroes out all the allocated memory, including `drv_data`, which is initialized via this function. This is an important detail to keep in mind, specifically when assessing possible vulnerabilities related to information leakage.

Now, I'm moving on to `psp_sock_rx_rekey`. Here, `pas` is being updated. Notice `memcpy` is being used for both `tx` and `drv_data`. `pas` is being populated with the previous association data. It also looks like a flag `PSP_ASSOC_SKIP_TX_KEY_DEL` is being set on the previous association.

A key question arises: how was `pas` allocated before `psp_sock_assoc_set_rx` is called? The allocation strategy for `pas` is critical to understanding the overall memory management and potential issues. Time to trace the callers of `psp_sock_assoc_set_rx` to identify and analyze its allocation process. This is where the potential gotchas usually hide.



56/3 2026/10/09 23:11 tool grepper
0m Args:
{
  "Expression": "psp_sock_assoc_set_rx",
  "PathPrefixes": [
    "net/psp/"
  ]
}

Results:
{
  "Output": "net/psp/psp.h=31=void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas);\nnet/psp/psp.h:32:int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,\nnet/psp/psp.h-33-\t\t\t  struct psp_key_parsed *key,\n--\nnet/psp/psp_nl.c=803=int psp_nl_rx_assoc_doit(struct sk_buff *skb, struct genl_info *info)\n--\nnet/psp/psp_nl.c-842-\nnet/psp/psp_nl.c:843:\terr = psp_sock_assoc_set_rx(socket-\u003esk, pas, \u0026key, info-\u003eextack);\nnet/psp/psp_nl.c-844-\tif (err) {\n--\nnet/psp/psp_sock.c=162=static int psp_sock_rx_rekey(struct psp_assoc *pas, struct psp_assoc *prev,\n--\nnet/psp/psp_sock.c-192-\nnet/psp/psp_sock.c:193:int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,\nnet/psp/psp_sock.c-194-\t\t\t  struct psp_key_parsed *key,\n"
}

57/3 2026/10/09 23:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23434
							output: 37
							thoughts: 28
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into `psp_nl_rx_assoc_doit`**

Alright, let's take a look at `psp_nl_rx_assoc_doit`. I'm going to jump into `net/psp/psp_nl.c` and refresh my memory on what's going on in that handler. I recall this is where the association requests from the PSP (presumably for things like network attachment or service discovery) are actually processed. I need to understand the exact mechanics. Specifically, I want to drill down into how the request is parsed, how the association process is triggered, how the configuration is handled, and how the results are sent back. Any sanity checks or error handling are going to be key. I know there's likely some interaction with the lower-level PSP drivers, so I need to see exactly how the netlink messages are translated into driver commands. I’m expecting to find the key pieces of that interaction, along with any relevant locking. This function's role in the larger PSP network context is very important, and a deep dive into its inner workings is needed to understand how association requests are actually handled.



58/3 2026/10/09 23:11 tool read-file
0m Args:
{
  "File": "net/psp/psp_nl.c",
  "FirstLine": 803,
  "LineCount": 50
}

Results:
{
  "Contents": " 803:\tint psp_nl_rx_assoc_doit(struct sk_buff *skb, struct genl_info *info)\n 804:\t{\n 805:\t\tstruct socket *socket = info-\u003euser_ptr[1];\n 806:\t\tstruct psp_dev *psd = info-\u003euser_ptr[0];\n 807:\t\tstruct psp_key_parsed key;\n 808:\t\tstruct psp_assoc *pas;\n 809:\t\tstruct sk_buff *rsp;\n 810:\t\tu32 version;\n 811:\t\tint err;\n 812:\t\n 813:\t\tif (GENL_REQ_ATTR_CHECK(info, PSP_A_ASSOC_VERSION))\n 814:\t\t\treturn -EINVAL;\n 815:\t\n 816:\t\tversion = nla_get_u32(info-\u003eattrs[PSP_A_ASSOC_VERSION]);\n 817:\t\tif (!(psd-\u003ecaps-\u003eversions \u0026 (1 \u003c\u003c version))) {\n 818:\t\t\tNL_SET_BAD_ATTR(info-\u003eextack, info-\u003eattrs[PSP_A_ASSOC_VERSION]);\n 819:\t\t\treturn -EOPNOTSUPP;\n 820:\t\t}\n 821:\t\n 822:\t\trsp = psp_nl_reply_new(info);\n 823:\t\tif (!rsp)\n 824:\t\t\treturn -ENOMEM;\n 825:\t\n 826:\t\tpas = psp_assoc_create(psd);\n 827:\t\tif (!pas) {\n 828:\t\t\terr = -ENOMEM;\n 829:\t\t\tgoto err_free_rsp;\n 830:\t\t}\n 831:\t\tpas-\u003eversion = version;\n 832:\t\n 833:\t\terr = psd-\u003eops-\u003erx_spi_alloc(psd, version, \u0026key, info-\u003eextack);\n 834:\t\tif (err)\n 835:\t\t\tgoto err_free_pas;\n 836:\t\n 837:\t\tif (nla_put_u32(rsp, PSP_A_ASSOC_DEV_ID, psd-\u003eid) ||\n 838:\t\t    psp_nl_put_key(rsp, PSP_A_ASSOC_RX_KEY, version, \u0026key)) {\n 839:\t\t\terr = -EMSGSIZE;\n 840:\t\t\tgoto err_free_pas;\n 841:\t\t}\n 842:\t\n 843:\t\terr = psp_sock_assoc_set_rx(socket-\u003esk, pas, \u0026key, info-\u003eextack);\n 844:\t\tif (err) {\n 845:\t\t\tNL_SET_BAD_ATTR(info-\u003eextack, info-\u003eattrs[PSP_A_ASSOC_SOCK_FD]);\n 846:\t\t\tgoto err_free_pas;\n 847:\t\t}\n 848:\t\tpsp_assoc_put(pas);\n 849:\t\n 850:\t\treturn psp_nl_reply_send(rsp, info);\n 851:\t\n 852:\terr_free_pas:\n"
}

59/3 2026/10/09 23:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24573
							output: 30
							thoughts: 11
						

Thoughts:
Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:

**Assessing the `psp_assoc_create` Function**

Alright, time to focus. Where do we begin? My initial thought is to zero in on `psp_assoc_create`. This function's critical, and probably the linchpin of some core functionality. Let's make sure that's understood. Now, let's see what we find. I need to understand it's role, and how it interplays with other parts of the system.



60/3 2026/10/09 23:11 tool grepper
0m Args:
{
  "Expression": "psp_assoc_create",
  "PathPrefixes": [
    "net/psp/"
  ]
}

Results:
{
  "Output": "net/psp/psp.h=27=void psp_nl_notify_disassoc(struct psp_dev *psd, struct net *net);\nnet/psp/psp.h-28-\nnet/psp/psp.h:29:struct psp_assoc *psp_assoc_create(struct psp_dev *psd);\nnet/psp/psp.h-30-struct psp_dev *psp_dev_get_for_sock(struct sock *sk);\n--\nnet/psp/psp_nl.c=803=int psp_nl_rx_assoc_doit(struct sk_buff *skb, struct genl_info *info)\n--\nnet/psp/psp_nl.c-825-\nnet/psp/psp_nl.c:826:\tpas = psp_assoc_create(psd);\nnet/psp/psp_nl.c-827-\tif (!pas) {\n--\nnet/psp/psp_sock.c=30=psp_validate_xmit(struct sock *sk, struct net_device *dev, struct sk_buff *skb)\n--\nnet/psp/psp_sock.c-46-\nnet/psp/psp_sock.c:47:struct psp_assoc *psp_assoc_create(struct psp_dev *psd)\nnet/psp/psp_sock.c-48-{\n"
}

61/3 2026/10/09 23:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25087
							output: 36
							thoughts: 19
						

Thoughts:
Okay, let's dive into this. I'm going to take a look at the `psp_sock.c` file, specifically lines 45 through 90. That range usually covers a critical function or a core section of a larger implementation within the PSP networking stack. I need to understand what's happening within that specific segment. What socket-related operation or initialization routine is being handled there? Given the file name, it's likely something directly involved in socket creation, connection handling, data transmission, or resource management for the Sony PlayStation Portable's network interface. I expect to see function calls related to BSD sockets, perhaps some PSP-specific adaptations or optimizations. The code might involve error checking, state management, or interactions with the PSP's hardware network controller. I'll be particularly focused on any potential race conditions or resource leaks within that range.



62/3 2026/10/09 23:11 tool read-file
0m Args:
{
  "File": "net/psp/psp_sock.c",
  "FirstLine": 45,
  "LineCount": 45
}

Results:
{
  "Contents": "  45:\t}\n  46:\t\n  47:\tstruct psp_assoc *psp_assoc_create(struct psp_dev *psd)\n  48:\t{\n  49:\t\tstruct psp_assoc *pas;\n  50:\t\n  51:\t\tlockdep_assert_held(\u0026psd-\u003elock);\n  52:\t\n  53:\t\tpas = kzalloc_flex(*pas, drv_data, psd-\u003ecaps-\u003eassoc_drv_spc,\n  54:\t\t\t\t   GFP_KERNEL_ACCOUNT);\n  55:\t\tif (!pas)\n  56:\t\t\treturn NULL;\n  57:\t\n  58:\t\tpas-\u003epsd = psd;\n  59:\t\tpas-\u003edev_id = psd-\u003eid;\n  60:\t\tpas-\u003egeneration = psd-\u003egeneration;\n  61:\t\tpsp_dev_get(psd);\n  62:\t\trefcount_set(\u0026pas-\u003erefcnt, 1);\n  63:\t\n  64:\t\tlist_add_tail(\u0026pas-\u003eassocs_list, \u0026psd-\u003eactive_assocs);\n  65:\t\n  66:\t\treturn pas;\n  67:\t}\n  68:\t\n  69:\tstatic struct psp_assoc *psp_assoc_dummy(struct psp_assoc *pas)\n  70:\t{\n  71:\t\tstruct psp_dev *psd = pas-\u003epsd;\n  72:\t\tsize_t sz;\n  73:\t\n  74:\t\tlockdep_assert_held(\u0026psd-\u003elock);\n  75:\t\n  76:\t\tsz = struct_size(pas, drv_data, psd-\u003ecaps-\u003eassoc_drv_spc);\n  77:\t\treturn kmemdup(pas, sz, GFP_KERNEL);\n  78:\t}\n  79:\t\n  80:\tstatic int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,\n  81:\t\t\t\t      struct psp_key_parsed *key,\n  82:\t\t\t\t      struct netlink_ext_ack *extack)\n  83:\t{\n  84:\t\tstruct psp_assoc *dummy;\n  85:\t\tint err;\n  86:\t\n  87:\t\t/* Pass a fake association to drivers to make sure they don't\n  88:\t\t * try to store pointers to it. For re-keying we'll need to\n  89:\t\t * re-allocate the assoc structures.\n"
}

63/3 2026/10/09 23:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25961
							output: 34
							thoughts: 1460
						

Thoughts:
**Analyzing PSP Code for Potential Uninitialized Memory Issues**

Okay, so I've been digging through this PSP code, trying to see if there are any obvious vulnerabilities related to uninitialized memory. Let's see... the `pas` struct, that's allocated with `kzalloc_flex`, so that's good. Initialized, no problem there. I'm checking the rest of `psp_sock.c` now to confirm. Looking at `prev_spi`, `prev_generation`, and `flags` in the `psp_assoc` struct...

When a `psp_assoc` is created, `kzalloc_flex` guarantees these are zeroed out. Re-keying calls, through `psp_sock_rx_rekey`, update `peer_tx`, `prev_spi`, and `prev_generation` with values from a previous association. Then in `psp_sock_tx_rekey`, a new `pas` is allocated with `kzalloc_flex` again, and the values are copied over. So the initialization path looks clean. All good on this front.

I'm now checking `psp_pse_matches_pas`. It checks `pas->prev_spi` and `pas->prev_generation` as part of the match condition.  The critical point here is that if `pas->prev_spi` is zero initially (as we know it is), the check short-circuits. Which means that the condition involving `prev_spi` and `prev_generation` are only evaluated if we're not in the initial state. The conditional logic appears sound; it doesn't try to use those variables before they're assigned.

Next, I'm analyzing the `psp_txq_state` struct. Here, `state` is allocated with `kvzalloc_flex`, and `drained_queues` is allocated with `bitmap_zalloc`. The `num_tx_queues` is written to `state`, and a loop populates `to_complete[]` in `psp_tx_grace_start`. The corresponding loop in `psp_tx_grace_done` also properly accesses valid array elements. This area of code looks okay.

Now the critical part: any information leakage to userspace. I'll need to check if there are any netlink messages, ioctls, socket options or copy_to_user operations. Let's start with netlink messages: in `psp_nl_stats_fill`, `psd->stats.tx_key_cnt` is being written to a netlink attribute. But `psd` is initialized with `kzalloc_obj` in `psp_dev_create`. So, `tx_key_cnt` is zero-initialized and only updated by increment/decrement operations and isn't a problem. No obvious uninitialized memory read there.

I am now going to comb through the source code again for other potential issues like this; the netlink part looks the most likely vector so I'm focusing on that now.



64/3 2026/10/09 23:11 tool grepper
0m Args:
{
  "Expression": "nla_put",
  "PathPrefixes": [
    "net/psp/psp_nl.c"
  ]
}

Results:
{
  "Output": "net/psp/psp_nl.c=242=static int psp_nl_fill_assoc_dev_list(struct psp_dev *psd, struct sk_buff *rsp,\n--\nnet/psp/psp_nl.c-268-\nnet/psp/psp_nl.c:269:\t\tif (nla_put_u32(rsp, PSP_A_ASSOC_DEV_INFO_IFINDEX,\nnet/psp/psp_nl.c-270-\t\t\t\tentry-\u003eassoc_dev-\u003eifindex) ||\nnet/psp/psp_nl.c:271:\t\t    nla_put_s32(rsp, PSP_A_ASSOC_DEV_INFO_NSID, nsid)) {\nnet/psp/psp_nl.c-272-\t\t\tnla_nest_cancel(rsp, nest);\n--\nnet/psp/psp_nl.c=283=psp_nl_dev_fill(struct psp_dev *psd, struct sk_buff *rsp,\n--\nnet/psp/psp_nl.c-295-\nnet/psp/psp_nl.c:296:\tif (nla_put_u32(rsp, PSP_A_DEV_ID, psd-\u003eid) ||\nnet/psp/psp_nl.c:297:\t    nla_put_u32(rsp, PSP_A_DEV_PSP_VERSIONS_CAP, psd-\u003ecaps-\u003eversions) ||\nnet/psp/psp_nl.c:298:\t    nla_put_u32(rsp, PSP_A_DEV_PSP_VERSIONS_ENA, psd-\u003econfig.versions))\nnet/psp/psp_nl.c-299-\t\tgoto err_cancel_msg;\n--\nnet/psp/psp_nl.c-302-\t\t/* Primary device - report the netdev, dump assoc list. */\nnet/psp/psp_nl.c:303:\t\tif (nla_put_u32(rsp, PSP_A_DEV_IFINDEX,\nnet/psp/psp_nl.c-304-\t\t\t\tpsd-\u003emain_netdev-\u003eifindex))\n--\nnet/psp/psp_nl.c-313-\t\t */\nnet/psp/psp_nl.c:314:\t\tif (nla_put_flag(rsp, PSP_A_DEV_BY_ASSOCIATION))\nnet/psp/psp_nl.c-315-\t\t\tgoto err_cancel_msg;\n--\nnet/psp/psp_nl.c=484=int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info)\n--\nnet/psp/psp_nl.c-502-\nnet/psp/psp_nl.c:503:\tif (nla_put_u32(rsp, PSP_A_DEV_ID, psd-\u003eid) ||\nnet/psp/psp_nl.c:504:\t    nla_put_u32(ntf, PSP_A_DEV_ID, psd-\u003eid)) {\nnet/psp/psp_nl.c-505-\t\terr = -EMSGSIZE;\n--\nnet/psp/psp_nl.c=784=psp_nl_put_key(struct sk_buff *skb, u32 attr, u32 version,\n--\nnet/psp/psp_nl.c-791-\nnet/psp/psp_nl.c:792:\tif (nla_put_u32(skb, PSP_A_KEYS_SPI, be32_to_cpu(key-\u003espi)) ||\nnet/psp/psp_nl.c:793:\t    nla_put(skb, PSP_A_KEYS_KEY, key_sz, key-\u003ekey)) {\nnet/psp/psp_nl.c-794-\t\tnla_nest_cancel(skb, nest);\n--\nnet/psp/psp_nl.c=803=int psp_nl_rx_assoc_doit(struct sk_buff *skb, struct genl_info *info)\n--\nnet/psp/psp_nl.c-836-\nnet/psp/psp_nl.c:837:\tif (nla_put_u32(rsp, PSP_A_ASSOC_DEV_ID, psd-\u003eid) ||\nnet/psp/psp_nl.c-838-\t    psp_nl_put_key(rsp, PSP_A_ASSOC_RX_KEY, version, \u0026key)) {\n--\nnet/psp/psp_nl.c=904=psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp,\n--\nnet/psp/psp_nl.c-922-\nnet/psp/psp_nl.c:923:\tif (nla_put_u32(rsp, PSP_A_STATS_DEV_ID, psd-\u003eid) ||\nnet/psp/psp_nl.c:924:\t    nla_put_uint(rsp, PSP_A_STATS_KEY_ROTATIONS,\nnet/psp/psp_nl.c-925-\t\t\t psd-\u003estats.rotations) ||\nnet/psp/psp_nl.c:926:\t    nla_put_uint(rsp, PSP_A_STATS_STALE_EVENTS, psd-\u003estats.stales) ||\nnet/psp/psp_nl.c:927:\t    nla_put_uint(rsp, PSP_A_STATS_RX_PACKETS, stats.rx_packets) ||\nnet/psp/psp_nl.c:928:\t    nla_put_uint(rsp, PSP_A_STATS_RX_BYTES, stats.rx_bytes) ||\nnet/psp/psp_nl.c:929:\t    nla_put_uint(rsp, PSP_A_STATS_RX_AUTH_FAIL, stats.rx_auth_fail) ||\nnet/psp/psp_nl.c:930:\t    nla_put_uint(rsp, PSP_A_STATS_RX_ERROR, stats.rx_error) ||\nnet/psp/psp_nl.c:931:\t    nla_put_uint(rsp, PSP_A_STATS_RX_BAD, stats.rx_bad) ||\nnet/psp/psp_nl.c:932:\t    nla_put_uint(rsp, PSP_A_STATS_TX_PACKETS, stats.tx_packets) ||\nnet/psp/psp_nl.c:933:\t    nla_put_uint(rsp, PSP_A_STATS_TX_BYTES, stats.tx_bytes) ||\nnet/psp/psp_nl.c:934:\t    nla_put_uint(rsp, PSP_A_STATS_TX_ERROR, stats.tx_error))\nnet/psp/psp_nl.c-935-\t\tgoto err_cancel_msg;\n--\nnet/psp/psp_nl.c-937-\tif (psp_dev_has_sadb(psd) \u0026\u0026\nnet/psp/psp_nl.c:938:\t    nla_put_uint(rsp, PSP_A_STATS_TX_KEY_COUNT, psd-\u003estats.tx_key_cnt))\nnet/psp/psp_nl.c-939-\t\tgoto err_cancel_msg;\n"
}

65/3 2026/10/09 23:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29903
							output: 32
							thoughts: 1293
						

Thoughts:
**Analysis of PSP Key Management Changes**

Okay, let's dive into these recent changes concerning PSP key management. First, I checked `psp_nl_put_key` and `rx_spi_alloc`, but nothing significant changed there. The primary modification in `psp_nl.c` is the addition of `PSP_A_STATS_TX_KEY_COUNT`.  That's straightforward, and `psd->stats.tx_key_cnt` is properly initialized to zero during `psp_dev` allocation with `kzalloc_obj`. Similar checks with `psp_assoc` using `kzalloc_flex`, and `psp_txq_state` with `kvzalloc_flex` and `bitmap_zalloc` confirm proper initialization.

Now, let's examine the broader changes within the `net/psp/` directory. `include/net/psp/functions.h` introduces a check for `pas->prev_spi` and `pas->prev_generation` in `psp_pse_matches_pas`. `include/net/psp/types.h` adds a `tx_del` struct to `psp_dev`, new stats fields, `psp_assoc_flags`, `prev_generation`, `flags`, and `prev_spi` in `psp_assoc`.

In `net/psp/psp.h`, function prototypes are added, and `psp_assoc_needs_tx_key_del` has an updated return condition.  `net/psp/psp_main.c` now includes a check for `netdev_need_ops_lock` in `psp_dev_create`, calls for `psp_deferred_del_init`, cleanup on error, and unregistering.  It also incorporates `psp_deferred_del_stop` and `psp_deferred_del_uninit`.

`net/psp/psp_sock.c` contains important updates. `psp_dev_tx_key_add` increments `psd->stats.tx_key_cnt`, while `psp_dev_tx_key_del` decrements it.  `psp_assoc_free` handles `PSP_ASSOC_DEFER_TX_KEY_DEL`.  `psp_sock_rx_rekey` rekeys rx, copying `prev->tx`, `prev->drv_data`, and setting `prev->flags`.  `psp_sock_assoc_set_rx` calls `psp_sock_rx_rekey` if `prev` exists.  `psp_sock_tx_rekey` allocates a new struct with `kzalloc_flex`, copies fields, and sets flags.  `psp_sock_assoc_set_tx` calls `psp_sock_tx_rekey` if `pas->tx.spi`. Finally, `psp_assocs_key_rotated` marks `pas->prev_generation` as invalid.

Considering potential bug risks, I'm focusing on concurrency, locking issues (RCU, netdev_lock, mutex_lock, workqueue) that KASAN, Lockdep, and syzkaller would likely catch. Use-after-free, double frees, and reference counting issues with `psp_dev_put`, `psp_assoc_put`, delayed work, and list deletions are also potential areas. Out-of-bounds or buffer overflows in allocations such as `to_complete[i]` and `drained_queues` are a concern as well. Finally logic errors in grace period tracking, and most of all, uninitialized memory usage.

However, after a thorough review, my conclusion is that this patch doesn't introduce any uninitialized memory risks that KMSAN would detect. All structures are zero-allocated using `kzalloc/kvzalloc`. The added netlink attribute is a simple scalar integer. Grace period tracking leverages zero-allocated state and driver dql counters. Potential memory corruption or lifetime issues (refcounting, delayed work, RCU) are already addressed by KASAN and standard kernel debugging tools.

A double-check of allocations using `kmemdup` or related functions reveals that `psp_assoc_dummy` uses `kmemdup` but not as a result of the patch, and that `psp_sock_tx_rekey` utilizes `kzalloc_flex`, which provides zero-allocation. This is a critical point. Furthermore, `memcpy` operations like `memcpy(&new->rx, &pas->rx, sizeof(new->rx))` ensures that data is copied from an initialized source. And now finally `psp_assoc_set_tx` and its surrounding code seem safe.



66/3 2026/10/09 23:11 tool grepper
0m Args:
{
  "Expression": "psp_assoc_set_tx",
  "PathPrefixes": [
    "net/psp/"
  ]
}

Results:
{
  "Output": "net/psp/psp_sock.c=193=int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,\n--\nnet/psp/psp_sock.c-231-\nnet/psp/psp_sock.c:232:static int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas,\nnet/psp/psp_sock.c-233-\t\t\t    struct psp_key_parsed *key,\n--\nnet/psp/psp_sock.c=268=psp_sock_set_tx_key(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,\n--\nnet/psp/psp_sock.c-280-\nnet/psp/psp_sock.c:281:\terr = psp_assoc_set_tx(psd, pas, key, extack);\nnet/psp/psp_sock.c-282-\tif (err)\n--\nnet/psp/psp_sock.c=297=psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,\n--\nnet/psp/psp_sock.c-322-\nnet/psp/psp_sock.c:323:\terr = psp_assoc_set_tx(psd, new, key, extack);\nnet/psp/psp_sock.c-324-\tif (err) {\n"
}

67/3 2026/10/09 23:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32591
							output: 37
							thoughts: 21
						

Thoughts:
Here's my take on the `psp_assoc_set_tx` function, starting with a review of the code in `psp_sock.c`:

**Diving into `psp_assoc_set_tx`**

Okay, let's dissect `psp_assoc_set_tx`. Given our familiarity with the PSP code base, I expect this function deals with associating a socket with a specific transmission queue, likely within the broader context of packet scheduling or traffic shaping. The name strongly suggests a "set" operation, implying we're either establishing or modifying this association. I'll be particularly interested in understanding:

*   **The Context:** What are the arguments passed to this function? Socket descriptors, probably some kind of queue identifier, and perhaps flags? I need to grasp how the socket is represented and how the transmission queue is defined within the PSP framework.
*   **The Locking Mechanism:** This is critical. Concurrent access to the socket and queue structures is likely, so I'll be scanning for mutexes, spinlocks, or other synchronization primitives. How is data consistency maintained? What's the potential for deadlocks?
*   **Error Handling:** What happens if the association fails? Are there error codes returned, and how are these errors handled upstream? Are there checks for invalid socket descriptors or queue identifiers?
*   **Side Effects:** Does this function trigger any internal state changes beyond the direct association? Does it impact packet processing in any way? Any changes to send buffers or flow control?
*   **Integration with the PSP Architecture:** How does this function fit into the overall picture of socket management, packet transmission, and network flow? Is it part of the fast path, or is it a control-plane function?

I'll be looking specifically for potential race conditions. Also, I'll be mindful of any inefficiencies, especially if any operations are performed within the critical section of the lock. I'm hoping it's straightforward but I've learned to expect the unexpected in the kernel space!



68/3 2026/10/09 23:12 tool read-file
0m Args:
{
  "File": "net/psp/psp_sock.c",
  "FirstLine": 230,
  "LineCount": 40
}

Results:
{
  "Contents": " 230:\t}\n 231:\t\n 232:\tstatic int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas,\n 233:\t\t\t\t    struct psp_key_parsed *key,\n 234:\t\t\t\t    struct netlink_ext_ack *extack)\n 235:\t{\n 236:\t\tint err;\n 237:\t\n 238:\t\tif (psp_dev_has_sadb(psd)) {\n 239:\t\t\terr = psp_dev_tx_key_add(psd, pas, key, extack);\n 240:\t\t\tif (err)\n 241:\t\t\t\treturn err;\n 242:\t\t}\n 243:\t\n 244:\t\tmemcpy(\u0026pas-\u003etx, key, sizeof(*key));\n 245:\t\treturn 0;\n 246:\t}\n 247:\t\n 248:\tstatic int psp_sock_recv_queue_check(struct sock *sk, struct psp_assoc *pas)\n 249:\t{\n 250:\t\tstruct psp_skb_ext *pse;\n 251:\t\tstruct sk_buff *skb;\n 252:\t\n 253:\t\tskb_rbtree_walk(skb, \u0026tcp_sk(sk)-\u003eout_of_order_queue) {\n 254:\t\t\tpse = skb_ext_find(skb, SKB_EXT_PSP);\n 255:\t\t\tif (!psp_pse_matches_pas(pse, pas))\n 256:\t\t\t\treturn -EBUSY;\n 257:\t\t}\n 258:\t\n 259:\t\tskb_queue_walk(\u0026sk-\u003esk_receive_queue, skb) {\n 260:\t\t\tpse = skb_ext_find(skb, SKB_EXT_PSP);\n 261:\t\t\tif (!psp_pse_matches_pas(pse, pas))\n 262:\t\t\t\treturn -EBUSY;\n 263:\t\t}\n 264:\t\treturn 0;\n 265:\t}\n 266:\t\n 267:\tstatic int\n 268:\tpsp_sock_set_tx_key(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,\n 269:\t\t\t    struct psp_key_parsed *key, struct netlink_ext_ack *extack)\n"
}

69/3 2026/10/09 23:12 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33715
							output: 343
							thoughts: 394
						

Thoughts:
**KMSAN Assessment: All Clear**

Okay, this is pretty cut and dried. Let's make sure we hit the right response structure: first the `set-results` tool with `NeedsKMSAN` (bool) and `KMSANReasoning` (string), and then the final reply.

Alright, let's step through this and make absolutely certain about KMSAN versus KASAN. My assessment: `NeedsKMSAN` is definitely false. Now for the reasoning, I need to be precise.

1.  This patch introduces support for PSP rekeying and delayed Tx key deletion, triggered by Byte Queue Limits (BQL).
2.  All the new heap allocations—`psp_txq_state`, `psp_assoc`, and the drained_queues bitmap—use zeroing allocators like `kvzalloc_flex`, `kzalloc_flex`, and `bitmap_zalloc`. This guarantees proper initialization of all struct fields and buffers. That's a key point.
3.  The only new netlink attribute exposed to user space is `PSP_A_STATS_TX_KEY_COUNT`, which transmits a single scalar counter, `tx_key_cnt`, an `unsigned long` initialized to zero and updated via simple arithmetic. No uninitialized memory or structure padding is leaked to userspace. This is solid.
4.  The risks here are centered around deferred work management, concurrency/synchronization between RCU, locks (`psd->lock`, `netdev_lock`), list manipulation, and object lifetime/refcounting (`psp_assoc`, `psp_dev`). Those types of bugs (use-after-free, double free, NULL pointer dereferences, locking deadlocks) are classic KASAN issues, LOCKDEP is a fine fit, and standard kernel debugging facilities are well-suited to handle these. Not KMSAN territory.
5.  Therefore, I'm confident that a dedicated KMSAN fuzzing session is not warranted. The risk profile is squarely in KASAN's wheelhouse.

Perfect. Everything checks out. Now let's call `set-results`.



70/3 2026/10/09 23:12 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch implements PSP in-place rekeying and deferred Tx key deletion based on Byte Queue Limits (BQL).\n\n1. Memory initialization: All new or modified data structures (such as `struct psp_txq_state` and `struct psp_assoc`) are allocated with zeroing allocators (`kvzalloc_flex`, `kzalloc_flex`, `bitmap_zalloc`). All fields (including `prev_spi`, `prev_generation`, and `flags`) are either explicitly initialized or zero-filled upon creation.\n2. Kernel-to-userspace communication: The patch adds one netlink attribute (`PSP_A_STATS_TX_KEY_COUNT`) to `psp_nl_stats_fill()`. This exports a scalar `unsigned long` (`tx_key_cnt`), which is zero-initialized at `psp_dev` creation and incremented/decremented upon key addition/deletion. No structs with padding or uninitialized memory buffers are copied to user space.\n3. Bug profile: The patch touches concurrency, list operations, delayed work execution, and object lifetimes/reference counting across RCU and mutex critical sections. Any memory issues arising from these changes (e.g. use-after-free, double free, refcount leaks, out-of-bounds access, locking deadlocks) fall under KASAN, LOCKDEP, and standard sanitizer checks.\n\nBecause there are no uninitialized memory read risks or info-leaks, a dedicated KMSAN fuzzing session is not justified.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch implements PSP in-place rekeying and deferred Tx key deletion based on Byte Queue Limits (BQL).\n\n1. Memory initialization: All new or modified data structures (such as `struct psp_txq_state` and `struct psp_assoc`) are allocated with zeroing allocators (`kvzalloc_flex`, `kzalloc_flex`, `bitmap_zalloc`). All fields (including `prev_spi`, `prev_generation`, and `flags`) are either explicitly initialized or zero-filled upon creation.\n2. Kernel-to-userspace communication: The patch adds one netlink attribute (`PSP_A_STATS_TX_KEY_COUNT`) to `psp_nl_stats_fill()`. This exports a scalar `unsigned long` (`tx_key_cnt`), which is zero-initialized at `psp_dev` creation and incremented/decremented upon key addition/deletion. No structs with padding or uninitialized memory buffers are copied to user space.\n3. Bug profile: The patch touches concurrency, list operations, delayed work execution, and object lifetimes/reference counting across RCU and mutex critical sections. Any memory issues arising from these changes (e.g. use-after-free, double free, refcount leaks, out-of-bounds access, locking deadlocks) fall under KASAN, LOCKDEP, and standard sanitizer checks.\n\nBecause there are no uninitialized memory read risks or info-leaks, a dedicated KMSAN fuzzing session is not justified.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)