From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794927350; b=5mImDLvLbnsNLeyfNCeVXNz8SlrbdelPJIFvUNm7w/IeVqTP+Mdw4NxpOGurKLCEqaOn gUo4eHlmrjE0IeTp9u1qJ0zQ1RanzdX8rwc12pHHeAlE+uXL0zAu9MQnPKGDcUSAThU8U 7MIX8hli+NzPB13zaZ5eJg8T3yOs4GYi8gtbt7wZ90C1S6fp6CXK7iK6IvzhkdA+W9s8a T4yqTYdlytzSG582lSHS16XEwAdQUVnP6Qw/OLo/2NK0TMpHClKKn+eSGX8zdTzO/YtXh Ik+IO1kEAJs7Zu3tELDL26yPM3h1cs4iUNU2AbZnztiFazsSdVMdzBf7DUN7PgiKRPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794927350; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=N2W1vGbTN1fxXgYMzqAEGGqqwODSJcSkIJEHTLlETcw=; b=4Qck9idPWs3XSjgNRwpvCtVf0nbgmDCdRaAd/egYDW5rxoNwrF8MBOG5twt6F0ANanFU AkYezMSdBUdsDs6Q5H5JiD85ebryxkcGw5ew9HpZr0vJxuxl5x5bvPMWVj9GWca+EJRt4 f1GfZTBLT0f17S5Xj7134ENzFiH1GzYu6tDgXtWIPIVHLObmUCtyrDeqEc021yUaGZ0sN vgcs8karqda8jTYbjoyI4HSUZazyGKX4k2OTgaoK+sUl/1qHxkP/lDTSxEUIb7LV26mP4 IxHbU/E/Cm5Aoeq2o03VBkd9qDBSVY5Q0fr5wBxd58NV05YA+U+zRhEIS+uQ9V+0kGw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--stani.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VgDZIXUN; arc=none smtp.remote-ip=209.85.128.199 Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9B1760A6F4C for ; Tue, 17 Nov 2026 14:55:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C9B1760A6F4C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--stani.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VgDZIXUN Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-8b4bfc0b441so42226437b3.2 for ; Tue, 17 Nov 2026 06:55:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1794927349; x=1795532149; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=N2W1vGbTN1fxXgYMzqAEGGqqwODSJcSkIJEHTLlETcw=; b=VgDZIXUNb/v6nkklYfbI32flOuhEE4d7GwSXmQM+hLCunE+AZyMZcdCrUFW6+Mv/g1 dnApFv8C1UGnV3UxXkCp/idcKL9WX8O2l0NNkb2a3RtfZ0Ak5fMb1SSWqT3uVkRF+xEX Ksa37izYL6U2uczaatstBIg4O2vVs8oPhP7jHQd7xeSLAaQ1p7haV2uL1WcCHuryu2tR SNFYNLl/Y+cl2YtUPmpQe6QxGUYH8W8S3IfDLYsDRnJNP/hJw8C0nrIOzjAeu5VLg9Qx d2EaVEU58m28IxcUkh+bCUHsAoCBKPyVyod0u8CC2tN8KZ+qIQfeJLL2BwhC8zBZL2zS 0ZIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794927349; x=1795532149; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=N2W1vGbTN1fxXgYMzqAEGGqqwODSJcSkIJEHTLlETcw=; b=pEYCD0wzwzoEKyvOr3awIQ07P9yMrlvVGTeaOkaAj9MdA74C8xubZ8w899GLjMroX+ s0NGPRS9eXaoNd+npw4Ne7UAKi0E75j0rZ182oTI1lIfxYcAAKnrzPttL+x6gqxL/8m8 ODcR3o8O4HQRCb+y0VHlKYM0nnuiHaFlVN8AQ4wb6Gf1SrdG4LsrmHIhQ2+DB241Gggb eTLMF9zoHceSD4JYHFQQ9eNlVlTXCx8rCmxVJnoQm1cAFRS9i61q/kcEb0ZCtKqkmPfB RPUEH97hKShFnTr4GI2BKArQPxBOi/WQBURw1yZerNCNS3kErCL28CFPglyW1bbsTkVu zOSg== X-Gm-Message-State: APuU4Z+oOlOR4KM6smH75eLpYHsdWfVxsJprBZQQv55NYgUQK5qMO3a2 b/2aBX81H1SFlEntlwvJmwOFY1pHNY42pRKebl/LM/FfFx5P3MB2KHvhnsVTWdlE17465rXXIKy o8g== X-Received: from yxbv18.prod.google.com ([2002:a05:690e:7d2:b0:675:604a:47fe]) (user=stani job=prod-delivery.src-stubby-dispatcher) by 2002:a05:690e:d8f:b0:67c:8ea:be13 with SMTP id 956f58d0204a3-67d896a0ae3mr6694528d50.52.1794927348674; Tue, 17 Nov 2026 06:55:48 -0800 (PST) Date: Tue, 17 Nov 2026 14:55:17 +0000 In-Reply-To: <20261117145522.1910636-1-stani@google.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261117145522.1910636-1-stani@google.com> X-Mailer: git-send-email 2.56.0.679.gc527c65306-goog Message-ID: <20261117145522.1910636-12-stani@google.com> Subject: [PATCH iwl-next 11/15] idpf: psp: add psp tx key state From: Stan Iliev To: Tony Nguyen , Przemek Kitszel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , intel-wired-lan@lists.osuosl.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, David Decotigny , Madhu Chittim , Emil Tantilov , Sridhar Samudrala , Brian Vazquez , Li Li , Alexander Lobakin , Daniel Zahka , Willem de Bruijn , Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" TX keys are inserted into the SADB asynchronously: the SA index of a key is only known when the CP replies. Add struct idpf_psp_tx_key, the reference counted state of a TX key, stored in the driver data of its PSP association in a later patch: - idpf_psp_tx_key_alloc(), idpf_psp_tx_key_get() and idpf_psp_tx_key_put(). The TX path reads the SA index of the key under RCU: the key is freed after an RCU grace period. - The SA index is IDPF_PSP_IDX_IN_PROG while the insertion is pending, IDPF_PSP_IDX_ERROR if it failed and IDPF_PSP_IDX_DELETED once the key was deleted, see idpf_psp_idx_valid(). - idpf_psp_saidx_ok() checks the SA indexes returned by the CP against the SA index width negotiated for the adapter. Signed-off-by: Stan Iliev --- drivers/net/ethernet/intel/idpf/idpf_psp.c | 51 +++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_psp.h | 31 +++++++++++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 30 +++++++++++ 3 files changed, 112 insertions(+) diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp.c b/drivers/net/ethernet/intel/idpf/idpf_psp.c index 844463754632..ef23b1699b09 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_psp.c +++ b/drivers/net/ethernet/intel/idpf/idpf_psp.c @@ -128,6 +128,57 @@ void idpf_psp_free(struct idpf_adapter *adapter) idpf_psp_unregister(adapter); } +/** + * idpf_psp_tx_key_alloc - Allocate the state of a PSP TX key + * + * Return: the TX key with a reference, NULL if it couldn't be allocated. + */ +struct idpf_psp_tx_key *idpf_psp_tx_key_alloc(void) +{ + struct idpf_psp_tx_key *key; + + key = kzalloc_obj(*key); + if (!key) + return NULL; + + kref_init(&key->ref); + spin_lock_init(&key->lock); + key->idx = IDPF_PSP_IDX_IN_PROG; + + return key; +} + +/** + * idpf_psp_tx_key_free - Free the state of a PSP TX key + * @ref: reference count of the TX key + */ +static void idpf_psp_tx_key_free(struct kref *ref) +{ + struct idpf_psp_tx_key *key = container_of(ref, struct idpf_psp_tx_key, + ref); + + /* The TX path may still read the SA index of the key */ + kfree_rcu(key, rcu); +} + +/** + * idpf_psp_tx_key_get - Get a reference on a PSP TX key + * @key: the TX key + */ +void idpf_psp_tx_key_get(struct idpf_psp_tx_key *key) +{ + kref_get(&key->ref); +} + +/** + * idpf_psp_tx_key_put - Release a reference on a PSP TX key + * @key: the TX key + */ +void idpf_psp_tx_key_put(struct idpf_psp_tx_key *key) +{ + kref_put(&key->ref, idpf_psp_tx_key_free); +} + /** * idpf_psp_set_config - Set the PSP device configuration * @psd: PSP device diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp.h b/drivers/net/ethernet/intel/idpf/idpf_psp.h index 34534076da47..44ac750e2c3b 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_psp.h +++ b/drivers/net/ethernet/intel/idpf/idpf_psp.h @@ -16,6 +16,37 @@ void idpf_psp_recv_late_reply(struct idpf_adapter *adapter, void idpf_psp_rotation_event(struct idpf_adapter *adapter, const struct libie_ctlq_msg *ctlq_msg); +struct idpf_psp_tx_key *idpf_psp_tx_key_alloc(void); +void idpf_psp_tx_key_get(struct idpf_psp_tx_key *key); +void idpf_psp_tx_key_put(struct idpf_psp_tx_key *key); + +/** + * idpf_psp_saidx_ok - Check an SA index returned by the CP + * @adapter: private data struct + * @saidx: the SA index + * + * Return: true if @saidx fits in the SA index width negotiated for the + * adapter, false otherwise. + */ +static inline bool idpf_psp_saidx_ok(const struct idpf_adapter *adapter, + u32 saidx) +{ + return saidx < BIT(adapter->psp.saidx_width); +} + +/** + * idpf_psp_idx_valid - Check if the SA index of a TX key is usable + * @idx: SA index or state of a TX key, see struct idpf_psp_tx_key + * + * Only SA indexes checked with idpf_psp_saidx_ok() are stored in a TX key. + * + * Return: true if @idx is an SA index, false if it is a state. + */ +static inline bool idpf_psp_idx_valid(u32 idx) +{ + return idx <= IDPF_PSP_IDX_MAX; +} + #else /* !CONFIG_INET_PSP */ static inline void idpf_psp_init(struct idpf_adapter *adapter) { } diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h index fdd65bc5321a..9ba99e08853a 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h +++ b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h @@ -3,6 +3,8 @@ #ifndef _IDPF_PSP_DEF_H_ #define _IDPF_PSP_DEF_H_ +#include +#include #include #include @@ -12,6 +14,34 @@ #define IDPF_PSP_SAIDX_WIDTH_21 21 #define IDPF_PSP_SAIDX_WIDTH_26 26 +/* Largest SA index the driver supports. The SA indexes the CP returns are + * checked against the width negotiated for the adapter before they are used, + * see idpf_psp_saidx_ok(). + */ +#define IDPF_PSP_IDX_MAX (BIT(IDPF_PSP_SAIDX_WIDTH_26) - 1) +/* States of a TX key without a usable SA index, see struct idpf_psp_tx_key */ +#define IDPF_PSP_IDX_NONE (U32_MAX - 3) /* no SA index */ +#define IDPF_PSP_IDX_IN_PROG (U32_MAX - 2) /* insertion pending */ +#define IDPF_PSP_IDX_ERROR (U32_MAX - 1) /* insertion failed */ +#define IDPF_PSP_IDX_DELETED U32_MAX /* key deleted */ + +/** + * struct idpf_psp_tx_key - State of a PSP TX key + * @ref: reference count, held by the PSP association, see + * idpf_psp_tx_key_add(), and by the lists and the insert request the + * key is on + * @lock: protects @idx and @hw_idx updates, and @tx_queue + * @idx: SA index the TX path uses, or IDPF_PSP_IDX_IN_PROG, + * IDPF_PSP_IDX_ERROR or IDPF_PSP_IDX_DELETED. Read without @lock. + * @rcu: for freeing the key after the RCU readers of the TX path + */ +struct idpf_psp_tx_key { + struct kref ref; + spinlock_t lock; /* protects the SA indexes and tx_queue */ + u32 idx; + struct rcu_head rcu; +}; + /** * struct idpf_psp_rx_key - PSP RX key allocated by the CP * @spi: SPI of the key -- 2.56.0.679.gc527c65306-goog