From: Stan Iliev <stani@google.com>
To: Tony Nguyen <anthony.l.nguyen@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
David Decotigny <decot@google.com>,
Madhu Chittim <madhu.chittim@intel.com>,
Emil Tantilov <emil.s.tantilov@intel.com>,
Sridhar Samudrala <sridhar.samudrala@intel.com>,
Brian Vazquez <brianvv@google.com>, Li Li <boolli@google.com>,
Alexander Lobakin <aleksander.lobakin@intel.com>,
Daniel Zahka <daniel.zahka@gmail.com>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org
Subject: [PATCH iwl-next 15/15] idpf: psp: add psp tx key registration
Date: Tue, 17 Nov 2026 14:55:21 +0000 [thread overview]
Message-ID: <20261117145522.1910636-16-stani@google.com> (raw)
In-Reply-To: <20261117145522.1910636-1-stani@google.com>
Add idpf_psp_queue_insert(), which queues a TX key for insertion:
- The key reserves a SADB entry, released if the insertion fails, or
once its SA index was deleted. An SA index that couldn't be deleted
keeps its SADB entry, as does the SA index of a late insertion reply
until it is deleted.
- New keys are refused with -ENOSPC once the SADB or the insert queue
(IDPF_PSP_INS_QUEUE_MAX keys) is full.
- The RX SPI allocation refuses the RX keys of new connections then,
instead of failing their TX keys later.
Signed-off-by: Stan Iliev <stani@google.com>
---
drivers/net/ethernet/intel/idpf/idpf_psp.c | 62 +++++++++++++++++++
drivers/net/ethernet/intel/idpf/idpf_psp.h | 2 +
.../net/ethernet/intel/idpf/idpf_psp_def.h | 4 ++
.../ethernet/intel/idpf/idpf_psp_virtchnl.c | 4 ++
4 files changed, 72 insertions(+)
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp.c b/drivers/net/ethernet/intel/idpf/idpf_psp.c
index 95926ac99777..1dfec4177c43 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp.c
@@ -11,6 +11,9 @@
/* Delay before the PSP work sends again a request that couldn't be sent */
#define IDPF_PSP_RETRY_MSEC 100
+/* Maximum number of TX keys queued for insertion */
+#define IDPF_PSP_INS_QUEUE_MAX 1024
+
/**
* idpf_queue_psp_work - Queue the PSP work
* @adapter: private data struct
@@ -237,6 +240,8 @@ void idpf_psp_init(struct idpf_adapter *adapter)
atomic_set(&psp->keys_inserted, 0);
atomic_set(&psp->insert_errors, 0);
atomic_set(&psp->insert_late, 0);
+ atomic_set(&psp->sadb_used, 0);
+ atomic_set(&psp->keys_refused, 0);
WRITE_ONCE(psp->enabled, true);
}
@@ -436,6 +441,8 @@ void idpf_psp_tx_key_failed(struct idpf_adapter *adapter,
struct idpf_psp_tx_key *key)
{
atomic_inc(&adapter->psp.insert_errors);
+ /* The SADB entry reserved for the key wasn't used */
+ atomic_dec(&adapter->psp.sadb_used);
spin_lock_bh(&key->lock);
if (key->idx == IDPF_PSP_IDX_IN_PROG)
@@ -443,6 +450,54 @@ void idpf_psp_tx_key_failed(struct idpf_adapter *adapter,
spin_unlock_bh(&key->lock);
}
+/**
+ * idpf_psp_sadb_full - Check if new PSP keys must be refused
+ * @adapter: private data struct
+ *
+ * Return: true if the SADB or the insertion queue is full, false otherwise.
+ */
+static bool idpf_psp_sadb_full(struct idpf_adapter *adapter)
+{
+ /* sadb_entries fits in 26 bits, see idpf_psp_negotiate_caps() */
+ return atomic_read(&adapter->psp.sadb_used) >=
+ (int)adapter->psp.sadb_entries ||
+ READ_ONCE(adapter->psp.ins_queued) >= IDPF_PSP_INS_QUEUE_MAX;
+}
+
+/**
+ * idpf_psp_queue_insert - Queue a TX key for insertion into the SADB
+ * @adapter: private data struct
+ * @key: the TX key, with its SPI and key set
+ *
+ * Reserve a SADB entry for the key and queue it for insertion. The PSP work
+ * inserts the queued keys, see idpf_send_insert_psp_keys(), and releases the
+ * reference taken on @key once the insertion completed.
+ *
+ * Return: 0 on success, -ENOSPC if the SADB or the insertion queue is full.
+ */
+int idpf_psp_queue_insert(struct idpf_adapter *adapter,
+ struct idpf_psp_tx_key *key)
+{
+ struct idpf_adapter_psp *psp = &adapter->psp;
+
+ spin_lock_bh(&psp->insert_lock);
+ if (idpf_psp_sadb_full(adapter)) {
+ spin_unlock_bh(&psp->insert_lock);
+ atomic_inc(&psp->keys_refused);
+ return -ENOSPC;
+ }
+
+ atomic_inc(&psp->sadb_used);
+ idpf_psp_tx_key_get(key);
+ list_add_tail(&key->ins_node, &psp->ins_list);
+ WRITE_ONCE(psp->ins_queued, psp->ins_queued + 1);
+ spin_unlock_bh(&psp->insert_lock);
+
+ idpf_queue_psp_work(adapter);
+
+ return 0;
+}
+
/**
* idpf_psp_set_config - Set the PSP device configuration
* @psd: PSP device
@@ -515,6 +570,13 @@ static int idpf_psp_rx_spi_alloc(struct psp_dev *psd, u32 version,
return -EOPNOTSUPP;
}
+ /* Refuse new connections whose TX key couldn't be inserted */
+ if (idpf_psp_sadb_full(adapter)) {
+ atomic_inc(&adapter->psp.keys_refused);
+ NL_SET_ERR_MSG_MOD(extack, "PSP SADB full");
+ return -ENOSPC;
+ }
+
err = idpf_send_allocate_psp_key(adapter, &rx_key);
if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to allocate RX SPI and key");
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp.h b/drivers/net/ethernet/intel/idpf/idpf_psp.h
index 0b2ae019b4a0..377cd4889f51 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp.h
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp.h
@@ -59,6 +59,8 @@ void idpf_psp_tx_key_inserted(struct idpf_adapter *adapter,
struct idpf_psp_tx_key *key, u32 saidx);
void idpf_psp_tx_key_failed(struct idpf_adapter *adapter,
struct idpf_psp_tx_key *key);
+int idpf_psp_queue_insert(struct idpf_adapter *adapter,
+ struct idpf_psp_tx_key *key);
#else /* !CONFIG_INET_PSP */
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
index 5af3347d9596..449bcb3c9ee2 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
@@ -134,6 +134,7 @@ struct idpf_psp_rx_gen {
* see idpf_psp_insert_timeout()
* @ins_list: TX keys queued for insertion
* @ins_queued: number of keys in @ins_list
+ * @sadb_used: SADB entries used, or reserved by keys queued for insertion
* @keys_allocated: RX keys allocated
* @keys_inserted: TX keys inserted into the SADB
* @insert_errors: TX keys whose insertion failed
@@ -141,6 +142,7 @@ struct idpf_psp_rx_gen {
* @keys_removed: SA indexes deleted
* @keys_lost: SA indexes that couldn't be deleted
* @del_retries: SA indexes retried after a failed deletion request
+ * @keys_refused: RX and TX keys refused, SADB or insertion queue full
* @psp_dev: the PSP device, see idpf_psp_register()
* @caps: capabilities of @psp_dev
*/
@@ -172,6 +174,7 @@ struct idpf_adapter_psp {
struct timer_list insert_timer;
struct list_head ins_list;
u32 ins_queued;
+ atomic_t sadb_used;
atomic_t keys_allocated;
atomic_t keys_inserted;
atomic_t insert_errors;
@@ -179,6 +182,7 @@ struct idpf_adapter_psp {
atomic_t keys_removed;
atomic_t keys_lost;
atomic_t del_retries;
+ atomic_t keys_refused;
struct psp_dev *psp_dev;
struct psp_dev_caps caps;
};
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c
index 480b56ce8164..0843f8e0ffea 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c
@@ -416,6 +416,7 @@ static void idpf_psp_delete_done(struct idpf_adapter *adapter,
struct idpf_psp_tx_key *key, *tmp;
atomic_add(removed, &adapter->psp.keys_removed);
+ atomic_sub(removed, &adapter->psp.sadb_used);
if (lost) {
atomic_add(lost, &adapter->psp.keys_lost);
net_warn_ratelimited("%s: %u SA indexes couldn't be deleted\n",
@@ -661,6 +662,8 @@ static void idpf_psp_insert_late(struct idpf_adapter *adapter,
continue;
atomic_inc(&adapter->psp.insert_late);
+ /* The SA index is used until it is deleted */
+ atomic_inc(&adapter->psp.sadb_used);
key = idpf_psp_tx_key_alloc();
if (!key) {
atomic_inc(&adapter->psp.keys_lost);
@@ -826,6 +829,7 @@ void idpf_psp_recv_late_reply(struct idpf_adapter *adapter,
max(atomic_read(&adapter->psp.keys_lost), 0));
atomic_sub(deleted, &adapter->psp.keys_lost);
atomic_add(deleted, &adapter->psp.keys_removed);
+ atomic_sub(deleted, &adapter->psp.sadb_used);
break;
case VIRTCHNL2_OP_PSP_INSERT_KEYS:
if (idpf_is_psp_ena(adapter) && !ctlq_msg->chnl_retval)
--
2.56.0.679.gc527c65306-goog
prev parent reply other threads:[~2026-11-17 14:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 14:55 [PATCH iwl-next 00/15] idpf: add PSP offload support, part 1 Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 01/15] libie: wipe copied small send buffers on release Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 02/15] idpf: wipe mailbox " Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 03/15] idpf: make the mailbox workqueue visible in sysfs Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 04/15] idpf: psp: add psp offload initialization Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 05/15] idpf: psp: add support for crypto capabilities Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 06/15] idpf: psp: add support for psp capabilities Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 07/15] idpf: psp: add support for fips compliance status Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 08/15] idpf: psp: add support for psp rx key allocation Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 09/15] idpf: psp: add support for psp key rotation Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 10/15] idpf: psp: add support for psp statistics Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 11/15] idpf: psp: add psp tx key state Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 12/15] idpf: psp: add support for psp tx key deletion Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 13/15] idpf: psp: add psp work and tx key insertion completion Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 14/15] idpf: psp: add support for psp tx key insertion Stan Iliev
2026-11-17 14:55 ` Stan Iliev [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117145522.1910636-16-stani@google.com \
--to=stani@google.com \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=boolli@google.com \
--cc=brianvv@google.com \
--cc=daniel.zahka@gmail.com \
--cc=davem@davemloft.net \
--cc=decot@google.com \
--cc=edumazet@kernel.org \
--cc=emil.s.tantilov@intel.com \
--cc=gustavoars@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=madhu.chittim@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=sridhar.samudrala@intel.com \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox