idpf: add PSP offload support, part 1
cover idpf: add PSP offload support, part 1
This series adds PSP (PSP Security Protocol) [1] inline crypto offload to idpf, through the PSP device API of the PSP core [2]. It comes in two parts. This is part 1, which adds the control path.
The device encrypts and decrypts the PSP packets. Its control plane (CP) holds the master keys and the security association database (SADB) of the TX keys. idpf manages them with new virtchnl2 commands over the mailbox:
- the CP derives an RX key from a master key and the SPI it allocates, one synchronous request per rx_spi_alloc;
- the TX keys are inserted into the SADB asynchronously, in batches of up to 101 keys. The SA index that the CP returns for a key goes into a TX context descriptor of each of its packets (part 2);
- the SA indexes of the released associations are deleted in batches.
Part 1:
- patches 1-2 wipe the mailbox send buffers on release, as some of the messages carry keys;
- patch 3 makes the mailbox workqueue visible in sysfs, like the PSP workqueue added later;
- patches 4-7 add the PSP initialization and negotiate the crypto offload capabilities, the PSP capabilities and the FIPS compliance status;
- patches 8-10 implement the rx_spi_alloc, key_rotate and get_stats PSP device ops;
- patches 11-15 add the TX key state, and the insertion of the TX keys into the SADB and their deletion.
Part 2 makes idpf_tso() run after the splitq TX resource check, implements the tx_key_add and tx_key_del PSP device ops and the TX and RX datapath, and registers the PSP device. Until then, the only change visible on a device with the crypto offload is the capability negotiation, which also logs the FIPS compliance status.
PSP is only enabled if the CP grants the new VIRTCHNL2_CAP_CRYPTO capability, idpf works as before otherwise. The crypto offload API of the CP uses the virtchnl2 opcodes 560 to 567, the VIRTCHNL2_EVENT_PSP_ROTATE_KEY event and the VIRTCHNL2_PROTO_HDR_PSP protocol ID.
Limitations:
- PSP version 0 (AES-GCM-128) and the splitq queue model only;
- the RX datapath only recognizes the IPv6 PSP packet type;
- master key rotations started by the CP itself can't be reported to the PSP core, as in mlx5;
- the PSP state doesn't survive a hard reset: the PSP device is unregistered at the start of the reset and registered again once the reset is done, as in mlx5.
Testing, of both parts on next-queue/dev-queue:
- each patch built with W=1 (allmodconfig) with gcc 15 and clang 21, and with gcc without CONFIG_INET_PSP: no warnings in idpf, libie and ixd, and no new kernel-doc warnings. checkpatch --strict only asks for blank lines between the new virtchnl2.h structures and their VIRTCHNL2_CHECK_STRUCT_LEN(), which would break the style of the file;
- tools/testing/selftests/drivers/net/psp.py between two hosts with Intel IPU devices (idpf PF, PCI ID 8086:1452), in both directions, plus a local case that checks that a connection keeps receiving after one key rotation: pass:19 fail:1 xfail:2 skip:11. Same result with RX checksum offload off on both hosts, without TCP checksum errors. The skips are the IPv4 cases (no IPv4 on these hosts), PSP versions 1 to 3 and kTLS, the xfails need netdevsim. data_mss_adjust fails since commit 3c6e29760c13 ("tcp: Subtract psp_sk_overhead() in __tcp_mtu_to_mss() and tcp_mss_to_mtu()."): the routes between these hosts have mtu 4220 and advmss 4108, so the PSP overhead no longer reduces the 4096 byte MSS, as that commit intends, while the test expects a 40 byte reduction. It passed on the same hosts without that commit;
- after the tests, the TX keys inserted into the SADB were all deleted once their sockets were gone;
- with part 1 only, the hosts boot, negotiate the crypto offload and log the FIPS compliance status, without a PSP device.
An AI coding assistant was used to rework parts of the code and of the commit messages of this series after an internal review, and an AI code review tool (Sashiko) reviewed the series. I reviewed and tested all the changes.
[1] https://raw.githubusercontent.com/google/psp/main/doc/PSP_Arch_Spec.pdf
[2] https://docs.kernel.org/networking/psp.html
Stan Iliev (15):
libie: wipe copied small send buffers on release
idpf: wipe mailbox send buffers on release
idpf: make the mailbox workqueue visible in sysfs
idpf: psp: add psp offload initialization
idpf: psp: add support for crypto capabilities
idpf: psp: add support for psp capabilities
idpf: psp: add support for fips compliance status
idpf: psp: add support for psp rx key allocation
idpf: psp: add support for psp key rotation
idpf: psp: add support for psp statistics
idpf: psp: add psp tx key state
idpf: psp: add support for psp tx key deletion
idpf: psp: add psp work and tx key insertion completion
idpf: psp: add support for psp tx key insertion
idpf: psp: add psp tx key registration
drivers/net/ethernet/intel/idpf/Makefile | 2 + drivers/net/ethernet/intel/idpf/idpf.h | 15 + drivers/net/ethernet/intel/idpf/idpf_lib.c | 16 + drivers/net/ethernet/intel/idpf/idpf_main.c | 5 +- drivers/net/ethernet/intel/idpf/idpf_psp.c | 738 +++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_psp.h | 86 ++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 190 ++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 841 ++++++++++++++++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 23 + .../intel/idpf/idpf_psp_virtchnl_def.h | 24 + .../net/ethernet/intel/idpf/idpf_virtchnl.c | 24 +- drivers/net/ethernet/intel/libie/controlq.c | 28 +- include/linux/net/intel/virtchnl2.h | 393 ++++++++ 13 files changed, 2376 insertions(+), 9 deletions(-) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp.h create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_def.h create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl_def.h
base-commit: 4cd5d9c333fb45a4e70ad6a77c44f13bd7312afb
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH 1/15 libie: wipe copied small send buffers on release
libie_ctlq_xn_send() copies the messages that fit in LIBIE_CP_TX_COPYBREAK bytes into a DMA buffer of their transaction, which is reused for later messages but never cleared. The messages can hold secrets, e.g. the PSP TX keys that idpf inserts into the SADB of the device.
Wipe the copy once the message was sent, when its send queue entry is cleaned, and when it couldn't be sent. The transaction can be reused as soon as that entry is cleared, see libie_ctlq_xn_pop_free(): order the wipe before it with smp_wmb(), paired with smp_acquire__after_ctrl_dep() after the check of the entry, so that the wipe can't overwrite the next message on weakly ordered architectures.
--- drivers/net/ethernet/intel/libie/controlq.c | 28 ++++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/libie/controlq.c +24 -4
@@ -694,9 +694,16 @@ libie_ctlq_xn_pop_free(struct libie_ctlq_xn_manager *xnm)* address is dirty in any way, reuse is already safe. */ if (xn->tx_msg && -data_race (xn->tx_msg->send_mem.pa) == xn->small_dma_mem.pa) +/* READ_ONCE() for the control dependency below */ +data_race (READ_ONCE (xn->tx_msg->send_mem.pa)) == + xn->small_dma_mem.pa)continue ; +/* The small buffer is wiped before the message is cleared, +* pairs with the smp_wmb() of libie_ctlq_xn_rel_tx_buf() +*/ +smp_acquire__after_ctrl_dep (); +clear_bit (free_idx, xnm->free_xns_bm);return xn;
@@ -998,6 +1005,8 @@ int libie_ctlq_xn_process_send(struct libie_ctlq_xn_send_params *params,if (!libie_ctlq_send_desc_avail (ctlq)) {if (!libie_cp_can_send_onstack (buf_len))libie_cp_unmap_dma_mem (dev, dma_mem); +else +memzero_explicit (dma_mem->va, buf_len);return -EBUSY ; }
@@ -1132,10 +1141,21 @@ static void libie_ctlq_xn_rel_tx_buf(const void *ctx, {const struct libie_ctlq_xn_rel_tx_ctx *rel_ctx = ctx; -if (!libie_cp_can_send_onstack (dma_mem->size)) { -libie_cp_unmap_dma_mem (rel_ctx->dev, dma_mem); - rel_ctx->rel_tx_buf (dma_mem->va); +/* Small messages are copied into the buffer of their transaction, +* which is reused: wipe the copy, the message may hold secrets, e.g. +* crypto keys +*/ +if (libie_cp_can_send_onstack (dma_mem->size)) { +memzero_explicit (dma_mem->va, dma_mem->size); +/* libie_ctlq_send_clean() clears the message next, which lets +* libie_ctlq_xn_pop_free() reuse the buffer +*/ +smp_wmb (); +return ; } + +libie_cp_unmap_dma_mem (rel_ctx->dev, dma_mem); + rel_ctx->rel_tx_buf (dma_mem->va); }/**
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH 2/15 idpf: wipe mailbox send buffers on release
In reply to Stan IlievThe mailbox messages are freed with kfree() once they were sent, or when they couldn't be sent. Some messages hold secrets, e.g. the PSP TX keys inserted into the SADB of the device. Free all of them with kfree_sensitive() instead: the mailbox isn't a fast path.
--- drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +4 -4
@@ -129,7 +129,7 @@ void idpf_recv_event_msg(struct libie_ctlq_ctx *ctx,*/ static void idpf_mb_clean (struct libie_ctlq_info *asq,bool deinit) { -libie_ctlq_xn_send_clean (asq, kfree, deinit); +libie_ctlq_xn_send_clean (asq, kfree_sensitive, deinit); }#if IS_ENABLED (CONFIG_PTP_1588_CLOCK )
@@ -218,7 +218,7 @@ int idpf_send_mb_msg(struct idpf_adapter *adapter,if (err) {if (!libie_cp_can_send_onstack (send_buf_size)) -kfree (send_buf); +kfree_sensitive (send_buf);return err; }
@@ -230,7 +230,7 @@ int idpf_send_mb_msg(struct idpf_adapter *adapter, xn_params->send_buf.iov_len = send_buf_size; xn_params->xnm = adapter->xnm; xn_params->ctlq = xn_params->ctlq ? xn_params->ctlq : adapter->asq; - xn_params->rel_tx_buf = kfree; + xn_params->rel_tx_buf = kfree_sensitive; xn_params->timeout_ms =min_t (u64, xn_params->timeout_ms, timeout_ms);idpf_mb_clean (xn_params->ctlq, false);
@@ -264,7 +264,7 @@ int idpf_send_mb_msg_kfree(struct idpf_adapter *adapter,int err =idpf_send_mb_msg (adapter, xn_params, send_buf, send_buf_size);if (libie_cp_can_send_onstack (send_buf_size)) -kfree (send_buf); +kfree_sensitive (send_buf);return err; }
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH 3/15 idpf: make the mailbox workqueue visible in sysfs
In reply to Stan IlievAdd WQ_SYSFS to the mailbox workqueue: the workqueue attributes are then exported in /sys/devices/virtual/workqueue/, e.g. to inspect or change the CPU mask and the nice level of the mailbox workqueue while debugging mailbox latency. This is one of those cases where, when the need arises, we wish we had that flag enabled, see https://lwn.net/Articles/967016/.
The PSP workqueue added later in this series sets it too.
--- drivers/net/ethernet/intel/idpf/idpf_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/idpf_main.c +2 -1
@@ -319,7 +319,8 @@ static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_serv_wq_alloc; } - adapter->mbx_wq =alloc_workqueue ("%s-%s-mbx" ,WQ_UNBOUND |WQ_HIGHPRI , + adapter->mbx_wq =alloc_workqueue ("%s-%s-mbx" , +WQ_UNBOUND |WQ_HIGHPRI |WQ_SYSFS ,0 ,dev_driver_string (dev),dev_name (dev));if (!adapter->mbx_wq) {
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH 4/15 idpf: psp: add psp offload initialization
In reply to Stan IlievAdd the PSP offload initialization:
- Introduce VIRTCHNL2_CAP_CRYPTO (bit 26 of the other capabilities) and request it in VIRTCHNL2_OP_GET_CAPS if CONFIG_INET_PSP is enabled.
- Add struct idpf_adapter_psp to struct idpf_adapter.
- Implement idpf_psp_init(), called from idpf_vc_core_init() on each core init, including after a hard reset, and idpf_psp_free(), called from idpf_remove(). PSP is enabled if VIRTCHNL2_CAP_CRYPTO was granted, see idpf_is_psp_ena(). A failure disables PSP instead of failing the core init.
- Add the PSP device ops with idpf_psp_set_config(), and idpf_psp_register()/idpf_psp_unregister(). The PSP device is registered in a later patch, once all mandatory PSP device ops and the datapath are implemented.
- Build idpf_psp.c only with CONFIG_INET_PSP, with static inline stubs in idpf_psp.h otherwise.
--- drivers/net/ethernet/intel/idpf/Makefile | 2 + drivers/net/ethernet/intel/idpf/idpf.h | 15 +++ drivers/net/ethernet/intel/idpf/idpf_lib.c | 1 + drivers/net/ethernet/intel/idpf/idpf_main.c | 2 + drivers/net/ethernet/intel/idpf/idpf_psp.c | 115 ++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_psp.h | 24 ++++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 21 ++++ .../net/ethernet/intel/idpf/idpf_virtchnl.c | 7 ++ include/linux/net/intel/virtchnl2.h | 1 + 9 files changed, 188 insertions(+) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp.h create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_def.h
drivers/net/ethernet/intel/idpf/Makefile +2 -0
@@ -21,5 +21,7 @@ idpf-$(CONFIG_IDPF_SINGLEQ) += idpf_singleq_txrx.o idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_ptp.o idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_virtchnl_ptp.o +idpf-$(CONFIG_INET_PSP) += idpf_psp.o + idpf-y += xdp.o idpf-y += xsk.o
drivers/net/ethernet/intel/idpf/idpf.h +15 -0
@@ -28,6 +28,7 @@ struct idpf_rss_data;#include <linux/net/intel/virtchnl2.h> #include "idpf_txrx.h" +#include "idpf_psp_def.h" #define GETMAXVAL (num_bits) GENMASK((num_bits) - 1, 0)
@@ -625,6 +626,7 @@ struct idpf_rdma_irq {* @req_vec_chunks: Requested vector chunk data * @mb_vector: Mailbox vector data * @irq_mb_handler: Handler for hard interrupt for mailbox +* @psp: PSP offload state, see idpf_psp_init() * @tx_timeout_count: Number of TX timeouts that have occurred * @avail_queues: Device given queue limits * @vports: Array to store vports created by the driver
@@ -683,6 +685,7 @@ struct idpf_adapter {struct idpf_q_vector mb_vector;irqreturn_t (*irq_mb_handler)(int irq,void *data); +struct idpf_adapter_psp psp;u32 tx_timeout_count;struct idpf_avail_queue_info avail_queues;struct idpf_vport **vports;
@@ -761,6 +764,18 @@ static inline bool idpf_is_rdma_cap_ena(struct idpf_adapter *adapter)return idpf_is_cap_ena (adapter,IDPF_OTHER_CAPS ,VIRTCHNL2_CAP_RDMA ); } +/** +* idpf_is_psp_ena - Determine if PSP offload is enabled +* @adapter: private data struct +* +* Return: true if PSP offload was negotiated in the last core init, see +* idpf_psp_init(), false otherwise +*/ +static inline bool idpf_is_psp_ena (const struct idpf_adapter *adapter) +{ +return IS_ENABLED (CONFIG_INET_PSP ) &&READ_ONCE (adapter->psp.enabled); +} +#define IDPF_CAP_RSS (\ VIRTCHNL2_FLOW_IPV4_TCP |\ VIRTCHNL2_FLOW_IPV4_UDP |\
drivers/net/ethernet/intel/idpf/idpf_lib.c +1 -0
@@ -6,6 +6,7 @@#include "idpf_ptp.h" #include "xdp.h" #include "xsk.h" +#include "idpf_psp.h" static const struct net_device_ops idpf_netdev_ops;
drivers/net/ethernet/intel/idpf/idpf_main.c +2 -0
@@ -5,6 +5,7 @@#include "idpf_devids.h" #include "idpf_devlink.h" #include "idpf_lan_vf_regs.h" +#include "idpf_psp.h" #include "idpf_virtchnl.h" #define DRV_SUMMARY "Intel(R) Infrastructure Data Path Function Linux Driver"
@@ -180,6 +181,7 @@ static void idpf_remove(struct pci_dev *pdev) }kfree (adapter->vport_config); adapter->vport_config =NULL ; +idpf_psp_free (adapter);kfree (adapter->netdevs); adapter->netdevs =NULL ;
drivers/net/ethernet/intel/idpf/idpf_psp.c new file +115 -0
115 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _IDPF_PSP_H_ +#define _IDPF_PSP_H_ + +#include "idpf.h" + +#if IS_ENABLED (CONFIG_INET_PSP ) + +void idpf_psp_init (struct idpf_adapter *adapter); +void idpf_psp_free (struct idpf_adapter *adapter); +void idpf_psp_register (struct idpf_adapter *adapter); +void idpf_psp_unregister (struct idpf_adapter *adapter); + +#else /* !CONFIG_INET_PSP */ + +static inline void idpf_psp_init (struct idpf_adapter *adapter) { } +static inline void idpf_psp_free (struct idpf_adapter *adapter) { } +static inline void idpf_psp_register (struct idpf_adapter *adapter) { } +static inline void idpf_psp_unregister (struct idpf_adapter *adapter) { } + +#endif /* CONFIG_INET_PSP */ + +#endif /* !_IDPF_PSP_H_ */
drivers/net/ethernet/intel/idpf/idpf_psp_def.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _IDPF_PSP_DEF_H_ +#define _IDPF_PSP_DEF_H_ + +#include <net/psp.h> + +/** +* struct idpf_adapter_psp - PSP offload state of an adapter +* @enabled: PSP was negotiated with the CP in the last core init, see +* idpf_is_psp_ena() +* @psp_dev: the PSP device, see idpf_psp_register() +* @caps: capabilities of @psp_dev +*/ +struct idpf_adapter_psp { +bool enabled; +struct psp_dev *psp_dev; +struct psp_dev_caps caps; +}; + +#endif /* !_IDPF_PSP_DEF_H_ */
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +7 -0
@@ -9,6 +9,7 @@#include "idpf.h" #include "idpf_virtchnl.h" #include "idpf_ptp.h" +#include "idpf_psp.h" /** * idpf_vid_to_vport - Translate vport id to vport pointer
@@ -584,6 +585,10 @@ static int idpf_send_get_caps_msg(struct idpf_adapter *adapter)VIRTCHNL2_CAP_PTP | VIRTCHNL2_CAP_EDT); +/* PSP offload uses the virtchnl2 crypto offload API */ +if (IS_ENABLED (CONFIG_INET_PSP )) + caps.other_caps |=cpu_to_le64 (VIRTCHNL2_CAP_CRYPTO ); + err =idpf_send_mb_msg_stack (adapter, &xn_params, &caps);if (err)return err;
@@ -3179,6 +3184,8 @@ int idpf_vc_core_init(struct idpf_adapter *adapter) goto intr_rel; } +idpf_psp_init (adapter); + err =idpf_ptp_init (adapter);if (err) pci_err(adapter->pdev, "PTP init failed, err=%pe\n",
include/linux/net/intel/virtchnl2.h +1 -0
@@ -221,6 +221,7 @@ enum virtchnl2_cap_other {/* Other capability 20 is reserved */ VIRTCHNL2_CAP_FLOW_STEER =BIT_ULL (21 ),VIRTCHNL2_CAP_LAN_MEMORY_REGIONS =BIT_ULL (22 ), +VIRTCHNL2_CAP_CRYPTO =BIT_ULL (26 ),/* this must be the last capability */ VIRTCHNL2_CAP_OEM = BIT_ULL(63),
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH iwl-next 04/15] idpf: psp: add psp offload initialization
Quoted 24 lines · Stan Iliev
Add the PSP offload initialization:
- IntroduceVIRTCHNL2_CAP_CRYPTO(bit 26 of the other capabilities) and request it inVIRTCHNL2_OP_GET_CAPSifCONFIG_INET_PSPis enabled.
- Add structidpf_adapter_pspto structidpf_adapter.
- Implementidpf_psp_init(), called fromidpf_vc_core_init()on each core init, including after a hard reset, andidpf_psp_free(), called fromidpf_remove(). PSP is enabled ifVIRTCHNL2_CAP_CRYPTOwas granted, seeidpf_is_psp_ena(). A failure disables PSP instead of failing the core init.
- Add the PSP device ops withidpf_psp_set_config(), and idpf_psp_register()/idpf_psp_unregister(). The PSP device is registered in a later patch, once all mandatory PSP device ops and the datapath are implemented.
- Buildidpf_psp.conly withCONFIG_INET_PSP, with static inline stubs inidpf_psp.hotherwise.Signed-off-by Stan Iliev <[email protected]>---
drivers/net/ethernet/intel/idpf/idpf_psp.c new file +5
-0+ +/** +* idpf_psp_set_config - Set the PSP device configuration +* @psd: PSP device +* @conf: new configuration
drivers/net/ethernet/intel/idpf/idpf_psp.c line 56
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_psp.c new file +10
-0+* @extack: netlink extended ack for error reporting +* +* The configuration is applied by the PSP core. +* +* Return: 0. +*/ +static int idpf_psp_set_config (struct psp_dev *psd,struct psp_dev_config *conf, +struct netlink_ext_ack *extack) +{ +return 0 ;
this is supposed to enable/disable PSP Rx on the device. It should probably either do something or have a TODO or comment explaining that the HW doesn't support disabling parsing packets as PSP.
[email protected]
AI reviewRe: [PATCH iwl-next 04/15] idpf: psp: add psp offload initialization
In reply to Stan IlievThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] idpf: psp: use-after-free on netdev in idpf_remove() via idpf_psp_free() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] idpf: psp: use-after-free on netdev in idpf_remove() via idpf_psp_free()
--
commit 77673bf9c57703b770d88ecaf99ce33c90db8e20
Author: Stan Iliev <[email protected]>
idpf: psp: add psp offload initialization
This commit adds PSP offload capability negotiation and initialization, along with helpers to register and unregister the PSP device.
Quoted 4 lines
drivers/net/ethernet/intel/idpf/idpf_main.c +0
-0
[ ... ]
drivers/net/ethernet/intel/idpf/idpf_main.c static void idpf_remove(struct pci_dev *pdev) · line 186
Quoted 7 lines
drivers/net/ethernet/intel/idpf/idpf_main.c +1
-0@@ -180,6 +181,7 @@ static void idpf_remove(struct pci_dev *pdev) }kfree (adapter->vport_config); adapter->vport_config =NULL ; +idpf_psp_free (adapter);kfree (adapter->netdevs); adapter->netdevs =NULL ;
[Severity: Medium]
Once idpf_psp_register() is wired up, can calling idpf_psp_free() at this point in idpf_remove() cause a use-after-free on adapter->netdevs[0]?
idpf_psp_free() calls idpf_psp_unregister() -> psp_dev_unregister(psd), which dereferences psd->main_netdev (adapter->netdevs[0]) in psp_nl_notify_dev() and writes NULL to psd->main_netdev->psp_dev:
net/psp/psp_main.c:psp_dev_unregister() {
...
psp_nl_notify_dev(psd, PSP_CMD_DEV_DEL_NTF);
...
rcu_assign_pointer(psd->main_netdev->psp_dev, NULL);
}In idpf_remove(), however, the net_device structs in adapter->netdevs[] have already been unregistered and freed by free_netdev() during idpf_vc_core_deinit() or the cleanup loop above destroy_wqs, and kfree(adapter->netdevs) here only frees the pointer array.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH 5/15 idpf: psp: add support for crypto capabilities
In reply to Stan IlievAdd support for negotiating the crypto offload capabilities:
- Introduce VIRTCHNL2_OP_CRYPTO_GET_CAPS (564),
enum virtchnl2_cap_crypto and struct virtchnl2_crypto_get_caps.
- Implement idpf_send_get_crypto_caps() in the new idpf_psp_virtchnl.c and call it from idpf_psp_negotiate_caps() in idpf_psp_init(). PSP stays disabled, without failing probe, unless PSP crypto offload and SADB entries are granted with a 21 or 26 bit SA index width, and the SA indexes of all the SADB entries fit in the width.
- Store the SADB size and the SA index width of the adapter in adapter->psp.sadb_entries and adapter->psp.saidx_width.
--- drivers/net/ethernet/intel/idpf/Makefile | 2 +- drivers/net/ethernet/intel/idpf/idpf_psp.c | 61 ++++++++++++++++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 10 +++ .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 71 +++++++++++++++++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 13 ++++ include/linux/net/intel/virtchnl2.h | 26 +++++++ 6 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h
drivers/net/ethernet/intel/idpf/Makefile +1 -1
@@ -21,7 +21,7 @@ idpf-$(CONFIG_IDPF_SINGLEQ) += idpf_singleq_txrx.o idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_ptp.o idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_virtchnl_ptp.o -idpf-$(CONFIG_INET_PSP) += idpf_psp.o +idpf-$(CONFIG_INET_PSP) += idpf_psp.o idpf_psp_virtchnl.o idpf-y += xdp.o idpf-y += xsk.o
drivers/net/ethernet/intel/idpf/idpf_psp.c +61 -0
79 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +10 -0
@@ -5,15 +5,25 @@#include <net/psp.h> +/* SA index widths supported by the driver, negotiated per adapter with +* VIRTCHNL2_OP_CRYPTO_GET_CAPS, see idpf_psp_negotiate_caps(). +*/ +#define IDPF_PSP_SAIDX_WIDTH_21 21 +#define IDPF_PSP_SAIDX_WIDTH_26 26 +/** * struct idpf_adapter_psp - PSP offload state of an adapter * @enabled: PSP was negotiated with the CP in the last core init, see * idpf_is_psp_ena() +* @sadb_entries: SADB size granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS +* @saidx_width: SA index width granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS * @psp_dev: the PSP device, see idpf_psp_register() * @caps: capabilities of @psp_dev */ struct idpf_adapter_psp {bool enabled; +u32 sadb_entries; +u8 saidx_width;struct psp_dev *psp_dev;struct psp_dev_caps caps; };
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c new file +71 -0
71 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _IDPF_PSP_VIRTCHNL_H_ +#define _IDPF_PSP_VIRTCHNL_H_ + +#include <linux/net/intel/libie/controlq.h> + +#include "idpf_psp.h" + +int idpf_send_get_crypto_caps (struct idpf_adapter *adapter, +struct virtchnl2_crypto_get_caps *caps); + +#endif /* !_IDPF_PSP_VIRTCHNL_H_ */
include/linux/net/intel/virtchnl2.h +26 -0
@@ -84,6 +84,8 @@ enum virtchnl2_op {VIRTCHNL2_OP_ADD_FLOW_RULE =551 ,VIRTCHNL2_OP_GET_FLOW_RULE =552 ,VIRTCHNL2_OP_DEL_FLOW_RULE =553 , +/* Crypto/PSP opcodes */ + VIRTCHNL2_OP_CRYPTO_GET_CAPS = 564, };/**
@@ -1817,4 +1819,28 @@ struct virtchnl2_flow_rule_add_del { };VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_flow_rule_add_del); +/* Generic crypto offload types */ +enum virtchnl2_cap_crypto { +VIRTCHNL2_CAP_CRYPTO_PSP =BIT (0 ), +}; + +/** +* struct virtchnl2_crypto_get_caps - Crypto global capabilities +* @crypto_caps: See enum virtchnl2_cap_crypto +* @num_sadb_entries: Number of SADB entries of the function, not shared with +* the other functions of the device +* @saidx_width: SA index width in bits +* @padding: Padding to 256 bytes +* +* Request and response of VIRTCHNL2_OP_CRYPTO_GET_CAPS. On input @crypto_caps +* holds the requested capabilities, on output the granted ones. +*/ +struct virtchnl2_crypto_get_caps { +__le32 crypto_caps; +__le32 num_sadb_entries; +u8 saidx_width; +u8 padding[247 ]; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (256 , virtchnl2_crypto_get_caps); +#endif /* _VIRTCHNL_2_H_ */
Signature · 1 line
2.56.0.679.gc527c65306-goog
RE: [PATCH iwl-next 05/15] idpf: psp: add support for crypto capabilities
Quoted 327 lines
-----Original Message-----
From: Stan Iliev <[email protected]>
Sent: Tuesday, November 17, 2026 3:55 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Andrew Lunn <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; David Decotigny <[email protected]>; Chittim, Madhu <[email protected]>; Tantilov, Emil S <[email protected]>; Samudrala, Sridhar <[email protected]>; Brian Vazquez <[email protected]>; Li Li <[email protected]>; Lobakin, Aleksander <[email protected]>; Daniel Zahka <[email protected]>; Willem de Bruijn <[email protected]>; Kees Cook <[email protected]>; Gustavo A. R. Silva <[email protected]>; [email protected]
Subject: [PATCH iwl-next 05/15] idpf: psp: add support for crypto capabilitiesAdd support for negotiating the crypto offload capabilities:
- IntroduceVIRTCHNL2_OP_CRYPTO_GET_CAPS(564),
enumvirtchnl2_cap_cryptoand structvirtchnl2_crypto_get_caps.
- Implementidpf_send_get_crypto_caps()in the newidpf_psp_virtchnl.cand call it fromidpf_psp_negotiate_caps()inidpf_psp_init(). PSP stays disabled, without failing probe, unless PSP crypto offload and SADB entries are granted with a 21 or 26 bit SA index width, and the SA indexes of all the SADB entries fit in the width.
- Store the SADB size and the SA index width of the adapter inadapter->psp.sadb_entriesandadapter->psp.saidx_width.Signed-off-by Stan Iliev <[email protected]>--- drivers/net/ethernet/intel/idpf/Makefile | 2 +- drivers/net/ethernet/intel/idpf/idpf_psp.c | 61 ++++++++++++++++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 10 +++ .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 71 +++++++++++++++++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 13 ++++ include/linux/net/intel/virtchnl2.h | 26 +++++++ 6 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.hdrivers/net/ethernet/intel/idpf/Makefile +1
-1@@ -21,7 +21,7 @@ idpf-$(CONFIG_IDPF_SINGLEQ) += idpf_singleq_txrx.o idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_ptp.o idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_virtchnl_ptp.o -idpf-$(CONFIG_INET_PSP) += idpf_psp.o +idpf-$(CONFIG_INET_PSP) += idpf_psp.o idpf_psp_virtchnl.o idpf-y += xdp.o idpf-y += xsk.odrivers/net/ethernet/intel/idpf/idpf_psp.c +54
-0@@ -3,6 +3,59 @@#include <net/psp.h> #include "idpf_psp.h" +#include "idpf_psp_virtchnl.h" + +/** +* idpf_psp_negotiate_caps - Negotiate the crypto and PSP capabilities +* @adapter: private data struct +* +* Query the crypto and PSP capabilities granted by the CP, check that +they +* cover what the driver implements and apply the negotiated values. +Must only +* be called if VIRTCHNL2_CAP_CRYPTO was negotiated. +* +* Return: 0 if PSP offload can be used, negative error code otherwise. +*/ +static int idpf_psp_negotiate_caps (struct idpf_adapter *adapter) { +struct virtchnl2_crypto_get_caps crypto_caps = { }; +struct device *dev = &adapter->pdev->dev; +u32 sadb_entries; +int err; + + err =idpf_send_get_crypto_caps (adapter, &crypto_caps); +if (err) +return err; + +if (!(le32_to_cpu (crypto_caps.crypto_caps) &VIRTCHNL2_CAP_CRYPTO_PSP )) { +dev_notice (dev,"PSP crypto offload not granted by CP\n" ); +return -EOPNOTSUPP ; + } + +if (crypto_caps.saidx_width !=IDPF_PSP_SAIDX_WIDTH_21 && + crypto_caps.saidx_width !=IDPF_PSP_SAIDX_WIDTH_26 ) { +dev_err (dev,"Unsupported PSP SA index width %u\n" , + crypto_caps.saidx_width); +return -EOPNOTSUPP ; + } + + sadb_entries =le32_to_cpu (crypto_caps.num_sadb_entries); +if (!sadb_entries) { +dev_notice (dev,"No PSP SADB entries granted by CP\n" ); +return -EOPNOTSUPP ; + } + +/* The SA indexes of all the SADB entries must fit in the width */ +if (sadb_entries >BIT (crypto_caps.saidx_width)) { +dev_err (dev,"%u PSP SADB entries don't fit in %u bit SA indexes\n", + sadb_entries, crypto_caps.saidx_width); +return -EOPNOTSUPP ; + } + + adapter->psp.sadb_entries = sadb_entries; + adapter->psp.saidx_width = crypto_caps.saidx_width; + +return 0 ; +}/** * idpf_psp_init - Initialize PSP offload @@ -18,6 +71,7 @@ void
idpf_psp_init(struct idpf_adapter *adapter){drivers/net/ethernet/intel/idpf/idpf_psp.c +8
-0struct idpf_adapter_psp *psp = &adapter->psp;struct device *dev = &adapter->pdev->dev; +int err;WRITE_ONCE (psp->enabled, false);@@ -26,6 +80,13 @@ void idpf_psp_init(struct idpf_adapter *adapter)return ; } + err =idpf_psp_negotiate_caps (adapter); +if (err) { +dev_warn (dev,"PSP disabled, capability negotiation failed: %d\n", + err); +return ; + } +WRITE_ONCE (psp->enabled, true); }drivers/net/ethernet/intel/idpf/idpf_psp_def.h +10
-0@@ -5,15 +5,25 @@#include <net/psp.h> +/* SA index widths supported by the driver, negotiated per adapter with +* VIRTCHNL2_OP_CRYPTO_GET_CAPS, see idpf_psp_negotiate_caps(). +*/ +#define IDPF_PSP_SAIDX_WIDTH_21 21 +#define IDPF_PSP_SAIDX_WIDTH_26 26 +/** * struct idpf_adapter_psp - PSP offload state of an adapter * @enabled: PSP was negotiated with the CP in the last core init, see * idpf_is_psp_ena() +* @sadb_entries: SADB size granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS +* @saidx_width: SA index width granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS * @psp_dev: the PSP device, see idpf_psp_register() * @caps: capabilities of @psp_dev */ struct idpf_adapter_psp {bool enabled; +u32 sadb_entries; +u8 saidx_width;struct psp_dev *psp_dev;struct psp_dev_caps caps; };drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c new file +12
-0@@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include "idpf_psp_virtchnl.h" +#include "idpf_virtchnl.h" + +/** +* idpf_print_crypto_caps - Print values inside +virtchnl2_crypto_get_caps +* @adapter: Driver specific private structure +* @caps: Pointer to virtchnl2_crypto_get_caps structure */ static +void idpf_print_crypto_caps (struct idpf_adapter *adapter, + const struct virtchnl2_crypto_get_caps*caps) {
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c new file +5
-0+u32 num_sadb_entries =le32_to_cpu (caps->num_sadb_entries); +u32 crypto_caps =le32_to_cpu (caps->crypto_caps); + + dev_dbg(&adapter->pdev->dev, + "virtchnl2_crypto_get_caps: crypto_caps=0x%08x (PSP=%u),num_sadb_entries=%u, saidx_width=%u\n",
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c new file +35
-0+ crypto_caps, !!(crypto_caps &VIRTCHNL2_CAP_CRYPTO_PSP ), + num_sadb_entries, caps->saidx_width); } + +/** +* idpf_send_get_crypto_caps - Send VIRTCHNL2_OP_CRYPTO_GET_CAPS +request to CP +* @adapter: Driver specific private structure +* @caps: Output buffer for virtchnl2_crypto_get_caps +* +* Request the PSP crypto offload. Must only be sent if +VIRTCHNL2_CAP_CRYPTO +* was granted. +* +* Return: 0 on success, negative on failure. +*/ +int idpf_send_get_crypto_caps (struct idpf_adapter *adapter, +struct virtchnl2_crypto_get_caps *caps) { +struct libie_ctlq_xn_send_params xn_params = { + .chnl_opcode =VIRTCHNL2_OP_CRYPTO_GET_CAPS , + .timeout_ms =IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC , + }; +struct virtchnl2_crypto_get_caps *send_caps; +int err; + +/* Too large to be sent from the stack */ + send_caps =kzalloc_obj (*send_caps); +if (!send_caps) +return -ENOMEM ; + + send_caps->crypto_caps =cpu_to_le32 (VIRTCHNL2_CAP_CRYPTO_PSP ); + + err =idpf_send_mb_msg_kfree (adapter, &xn_params, send_caps, +sizeof (*send_caps)); +if (err) { + dev_err(&adapter->pdev->dev, "Failed to get crypto caps:%d\n",
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c new file +6
-0+ err); +return err; + } + +if (xn_params.recv_mem.iov_len <sizeof (*caps)) { + dev_err(&adapter->pdev->dev, "Invalid crypto caps replysize: %zu\n",
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c new file +12
-0+ xn_params.recv_mem.iov_len); + err = -EIO ; + goto release_rx; + } + +memcpy (caps, xn_params.recv_mem.iov_base,sizeof (*caps)); +idpf_print_crypto_caps (adapter, caps); + +release_rx: +libie_ctlq_release_rx_buf (&xn_params.recv_mem); +return err; +}drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h new file +13
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _IDPF_PSP_VIRTCHNL_H_ +#define _IDPF_PSP_VIRTCHNL_H_ + +#include <linux/net/intel/libie/controlq.h> + +#include "idpf_psp.h" + +int idpf_send_get_crypto_caps (struct idpf_adapter *adapter, +struct virtchnl2_crypto_get_caps *caps); + +#endif /* !_IDPF_PSP_VIRTCHNL_H_ */ include/linux/net/intel/virtchnl2.h +11
-0@@ -84,6 +84,8 @@ enum virtchnl2_op {VIRTCHNL2_OP_ADD_FLOW_RULE =551 ,VIRTCHNL2_OP_GET_FLOW_RULE =552 ,VIRTCHNL2_OP_DEL_FLOW_RULE =553 , +/* Crypto/PSP opcodes */ + VIRTCHNL2_OP_CRYPTO_GET_CAPS = 564, };/** @@ -1817,4 +1819,28 @@ struct virtchnl2_flow_rule_add_del { };VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_flow_rule_add_del); +/* Generic crypto offload types */ +enum virtchnl2_cap_crypto { +VIRTCHNL2_CAP_CRYPTO_PSP =BIT (0 ), +}; + +/** +* struct virtchnl2_crypto_get_caps - Crypto global capabilities +* @crypto_caps: See enum virtchnl2_cap_crypto +* @num_sadb_entries: Number of SADB entries of the function, not shared with
+ * the other functions of the device
+ * @saidx_width: SA index width in bits
+ * @padding: Padding to 256 bytes
+ *
+ * Request and response ofVIRTCHNL2_OP_CRYPTO_GET_CAPS. On input +@crypto_caps
+ * holds the requested capabilities, on output the granted ones.
+ */include/linux/net/intel/virtchnl2.h +8
-1+struct virtchnl2_crypto_get_caps { +__le32 crypto_caps; +__le32 num_sadb_entries; +u8 saidx_width; +u8 padding[247 ]; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (256 , virtchnl2_crypto_get_caps); +#endif /* _VIRTCHNL_2_H_ */ --
Quoted 1 line
2.56.0.679.gc527c65306-goog
PATCH 6/15 idpf: psp: add support for psp capabilities
In reply to Stan IlievAdd support for negotiating the PSP capabilities:
- Introduce VIRTCHNL2_OP_PSP_GET_CAPS (565), enum virtchnl2_psp_caps and struct virtchnl2_psp_get_caps (64 bytes, sent from the stack).
- Introduce the common PSP key definitions:
enum virtchnl2_psp_key_type, VIRTCHNL2_PSP_KEY_SIZE_V0/V1, enum virtchnl2_psp_domain_type and struct virtchnl2_psp_key_domain.
- Implement idpf_send_get_psp_caps(), which requests all PSP capabilities, and call it from idpf_psp_negotiate_caps(). PSP stays disabled unless PSP version 0 keys are granted. The granted capabilities are stored in adapter->psp.psp_caps.
--- drivers/net/ethernet/intel/idpf/idpf_psp.c | 15 ++++- .../net/ethernet/intel/idpf/idpf_psp_def.h | 3 + .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 66 +++++++++++++++++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 2 + include/linux/net/intel/virtchnl2.h | 65 ++++++++++++++++++ 5 files changed, 150 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/idpf_psp.c +14 -1
@@ -18,8 +18,9 @@static int idpf_psp_negotiate_caps (struct idpf_adapter *adapter) {struct virtchnl2_crypto_get_caps crypto_caps = { }; +struct virtchnl2_psp_get_caps psp_caps = { };struct device *dev = &adapter->pdev->dev; -u32 sadb_entries; +u32 caps, sadb_entries;int err; err =idpf_send_get_crypto_caps (adapter, &crypto_caps);
@@ -51,6 +52,18 @@ static int idpf_psp_negotiate_caps(struct idpf_adapter *adapter)return -EOPNOTSUPP ; } + err =idpf_send_get_psp_caps (adapter, &psp_caps); +if (err) +return err; + +/* The driver only allocates and inserts PSP version 0 keys */ + caps =le32_to_cpu (psp_caps.psp_caps); +if (!(caps &VIRTCHNL2_CAP_PSP_PROTO_V0 )) { +dev_notice (dev,"PSP version 0 keys not granted by CP\n" ); +return -EOPNOTSUPP ; + } + + adapter->psp.psp_caps = caps; adapter->psp.sadb_entries = sadb_entries; adapter->psp.saidx_width = crypto_caps.saidx_width;
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +3 -0
@@ -17,6 +17,8 @@* idpf_is_psp_ena() * @sadb_entries: SADB size granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS * @saidx_width: SA index width granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS +* @psp_caps: PSP capabilities granted by VIRTCHNL2_OP_PSP_GET_CAPS, see +* enum virtchnl2_psp_caps * @psp_dev: the PSP device, see idpf_psp_register() * @caps: capabilities of @psp_dev */
@@ -24,6 +26,7 @@ struct idpf_adapter_psp {bool enabled;u32 sadb_entries;u8 saidx_width; +u32 psp_caps;struct psp_dev *psp_dev;struct psp_dev_caps caps; };
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +66 -0
69 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h +2 -0
@@ -9,5 +9,7 @@int idpf_send_get_crypto_caps (struct idpf_adapter *adapter,struct virtchnl2_crypto_get_caps *caps); +int idpf_send_get_psp_caps (struct idpf_adapter *adapter, +struct virtchnl2_psp_get_caps *caps);#endif /* !_IDPF_PSP_VIRTCHNL_H_ */
include/linux/net/intel/virtchnl2.h +65 -0
75 lines not on this page · raw message
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH 7/15 idpf: psp: add support for fips compliance status
In reply to Stan IlievAdd support for querying the FIPS compliance status of the crypto offload:
- Introduce VIRTCHNL2_OP_GET_FIPS_COMPLIANCE_STATUS (567) and struct virtchnl2_get_fips_compliance_status_resp.
- Implement idpf_send_get_fips_compliance_status(), called from idpf_psp_init(), which logs the status as "compliant@cmvp_cert_<a>_and_<b>" or "noncompliant". The status is informational only: failing to read it doesn't disable PSP.
--- drivers/net/ethernet/intel/idpf/idpf_psp.c | 6 ++ .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 59 +++++++++++++++++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 1 + include/linux/net/intel/virtchnl2.h | 14 +++++ 4 files changed, 80 insertions(+)
drivers/net/ethernet/intel/idpf/idpf_psp.c +6 -0
@@ -100,6 +100,12 @@ void idpf_psp_init(struct idpf_adapter *adapter)return ; } +/* The FIPS compliance status is informational only */ + err =idpf_send_get_fips_compliance_status (adapter); +if (err) +dev_warn (dev,"Failed to get PSP FIPS compliance status: %d\n" , + err); +WRITE_ONCE (psp->enabled, true); }
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +59 -0
62 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h +1 -0
@@ -11,5 +11,6 @@ int idpf_send_get_crypto_caps(struct idpf_adapter *adapter, struct virtchnl2_crypto_get_caps *caps);int idpf_send_get_psp_caps (struct idpf_adapter *adapter,struct virtchnl2_psp_get_caps *caps); +int idpf_send_get_fips_compliance_status (struct idpf_adapter *adapter);#endif /* !_IDPF_PSP_VIRTCHNL_H_ */
include/linux/net/intel/virtchnl2.h +14 -0
@@ -87,6 +87,7 @@ enum virtchnl2_op {/* Crypto/PSP opcodes */ VIRTCHNL2_OP_CRYPTO_GET_CAPS =564 ,VIRTCHNL2_OP_PSP_GET_CAPS =565 , + VIRTCHNL2_OP_GET_FIPS_COMPLIANCE_STATUS = 567, };/**
@@ -1908,4 +1909,17 @@ struct virtchnl2_psp_key_domain { };VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_psp_key_domain); +/** +* struct virtchnl2_get_fips_compliance_status_resp - FIPS compliance response +* @num_certs: Number of certificates, 0 if not FIPS compliant +* @pad: Reserved/padding +* @certs: Flexible array of certificate IDs +*/ +struct virtchnl2_get_fips_compliance_status_resp { +__le32 num_certs; +u8 pad[4 ]; + __le32 certs[] __counted_by_le(num_certs); +}; +VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_get_fips_compliance_status_resp); +#endif /* _VIRTCHNL_2_H_ */
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH iwl-next 07/15] idpf: psp: add support for fips compliance status
Quoted 11 lines · Stan Iliev
Add support for querying the FIPS compliance status of the crypto offload:
- IntroduceVIRTCHNL2_OP_GET_FIPS_COMPLIANCE_STATUS(567) and structvirtchnl2_get_fips_compliance_status_resp.
- Implementidpf_send_get_fips_compliance_status(), called fromidpf_psp_init(), which logs the status as "compliant@cmvp_cert_<a>_and_<b>" or "noncompliant". The status is informational only: failing to read it doesn't disable PSP.Signed-off-by Stan Iliev <[email protected]>---
[...]
Quoted 45 lines
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +45
-0+ +/** +* idpf_send_get_fips_compliance_status - Get the FIPS compliance status +* @adapter: Driver specific private structure +* +* Query the FIPS compliance status of the crypto offload with +* VIRTCHNL2_OP_GET_FIPS_COMPLIANCE_STATUS and log it in the legacy +* "compliant@cmvp_cert_<a>_and_<b>" form, or as "noncompliant". +* +* Return: 0 on success, negative on failure. +*/ +int idpf_send_get_fips_compliance_status (struct idpf_adapter *adapter) +{ +struct libie_ctlq_xn_send_params xn_params = { + .chnl_opcode =VIRTCHNL2_OP_GET_FIPS_COMPLIANCE_STATUS , + .timeout_ms =IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC , + }; +const struct virtchnl2_get_fips_compliance_status_resp *resp; +struct device *dev = &adapter->pdev->dev; +char status[128 ]; +size_t reply_sz; +u32 num_certs; +int len, err; +/* The request has no payload, but libie can't send empty messages */ +u8 dummy =0 ; +u32 i; + + err =idpf_send_mb_msg (adapter, &xn_params, &dummy,sizeof (dummy)); +if (err) +return err; + + reply_sz = xn_params.recv_mem.iov_len; + resp = xn_params.recv_mem.iov_base; +if (reply_sz <sizeof (*resp)) { + err = -EIO ; + goto release_rx; + } + + num_certs =le32_to_cpu (resp->num_certs); +if (struct_size (resp, certs, num_certs) > reply_sz) { + err = -EIO ; + goto release_rx; + } + +if (!num_certs) {
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c int idpf_send_get_psp_caps(struct idpf_adapter *adapter, · line 192
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +10
-0+dev_info (dev,"PSP FIPS compliance: noncompliant\n" ); + goto release_rx; + } + + len =scnprintf (status,sizeof (status),"compliant@cmvp_cert_" ); +for (i =0 ; i < num_certs; i++) + len +=scnprintf (status + len,sizeof (status) - len,"%s%u" , + i ?"_and_" :"" ,le32_to_cpu (resp->certs[i])); +dev_info (dev,"PSP FIPS compliance: %s\n" , status); +
You should think about exposing this with a netlink uapi instead of making userspace parse it from dmesg. Maybe PSP dev-get.
I would also suggest moving this to a series after the PSP implementation. It doesn't make sense to have the PSP driver API implemented over the span of two separate series when stuff like this is in between.
Quoted 4 lines
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +4
-0+release_rx: +libie_ctlq_release_rx_buf (&xn_params.recv_mem); +return err; +}
PATCH 8/15 idpf: psp: add support for psp rx key allocation
In reply to Stan IlievAdd support for allocating PSP RX keys on demand:
- Introduce VIRTCHNL2_OP_PSP_ALLOCATE_KEYS (560),
enum virtchnl2_psp_allocate_response_flags,
struct virtchnl2_psp_allocate_keys_request/_response and struct virtchnl2_allocate_psp_key_v0/_v1.
- Implement idpf_send_allocate_psp_key(), which allocates one V0 RX key with a synchronous request, validates the reply (key type, keys_size_bytes, length, and an SPI with a key ID, which the PSP core requires) and wipes the key from the mailbox buffer. The key, its SPI and its master key generation are returned in struct idpf_psp_rx_key.
- Implement the rx_spi_alloc PSP device op. It gets the adapter from the netdev of the PSP device, as the vports can be freed while the PSP device is registered.
- Keep a copy of the vport ID in adapter->psp.vport_id, for the same reason.
- Wipe the RX keys of late replies, which libie passes to idpf_recv_event_msg() after the request timed out.
--- drivers/net/ethernet/intel/idpf/idpf_lib.c | 3 + drivers/net/ethernet/intel/idpf/idpf_psp.c | 43 +++++++++ drivers/net/ethernet/intel/idpf/idpf_psp.h | 6 ++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 19 ++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 89 +++++++++++++++++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 2 + .../net/ethernet/intel/idpf/idpf_virtchnl.c | 3 + include/linux/net/intel/virtchnl2.h | 78 ++++++++++++++++ 8 files changed, 243 insertions(+)
drivers/net/ethernet/intel/idpf/idpf_lib.c +3 -0
@@ -1144,6 +1144,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,/* fill vport slot in the adapter struct */ adapter->vports[idx] = vport; adapter->vport_ids[idx] =idpf_get_vport_id (vport); +/* Copy for the PSP requests that can run while the vports are freed */ +if (IS_ENABLED (CONFIG_INET_PSP ) && !idx) +WRITE_ONCE (adapter->psp.vport_id, adapter->vport_ids[idx]); adapter->num_alloc_vports++;/* prepare adapter->next_vport for next use */
drivers/net/ethernet/intel/idpf/idpf_psp.c +43 -0
58 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp.h +6 -0
@@ -11,6 +11,8 @@ void idpf_psp_init(struct idpf_adapter *adapter);void idpf_psp_free (struct idpf_adapter *adapter);void idpf_psp_register (struct idpf_adapter *adapter);void idpf_psp_unregister (struct idpf_adapter *adapter); +void idpf_psp_recv_late_reply (struct idpf_adapter *adapter, +const struct libie_ctlq_msg *ctlq_msg);#else /* !CONFIG_INET_PSP */
@@ -19,6 +21,10 @@ static inline void idpf_psp_free(struct idpf_adapter *adapter) { }static inline void idpf_psp_register (struct idpf_adapter *adapter) { }static inline void idpf_psp_unregister (struct idpf_adapter *adapter) { } +static inline void +idpf_psp_recv_late_reply (struct idpf_adapter *adapter, +const struct libie_ctlq_msg *ctlq_msg) { } +#endif /* CONFIG_INET_PSP */ #endif /* !_IDPF_PSP_H_ */
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +19 -0
@@ -3,6 +3,7 @@#ifndef _IDPF_PSP_DEF_H_#define _IDPF_PSP_DEF_H_ +#include <linux/net/intel/virtchnl2.h> #include <net/psp.h> /* SA index widths supported by the driver, negotiated per adapter with
@@ -11,6 +12,18 @@#define IDPF_PSP_SAIDX_WIDTH_21 21#define IDPF_PSP_SAIDX_WIDTH_26 26 +/** +* struct idpf_psp_rx_key - PSP RX key allocated by the CP +* @spi: SPI of the key +* @generation: CP master key generation of the key +* @key: the key +*/ +struct idpf_psp_rx_key { +__be32 spi; +u32 generation; +u8 key[VIRTCHNL2_PSP_KEY_SIZE_V0 ]; +}; +/** * struct idpf_adapter_psp - PSP offload state of an adapter * @enabled: PSP was negotiated with the CP in the last core init, see
@@ -19,6 +32,10 @@* @saidx_width: SA index width granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS * @psp_caps: PSP capabilities granted by VIRTCHNL2_OP_PSP_GET_CAPS, see * enum virtchnl2_psp_caps +* @vport_id: ID of adapter->vports[0] for the PSP requests. A copy, as the +* PSP device stays registered while the vports are freed and +* allocated again during a soft reset. Set in idpf_vport_alloc(). +* @keys_allocated: RX keys allocated * @psp_dev: the PSP device, see idpf_psp_register() * @caps: capabilities of @psp_dev */
@@ -27,6 +44,8 @@ struct idpf_adapter_psp {u32 sadb_entries;u8 saidx_width;u32 psp_caps; +u32 vport_id; +atomic_t keys_allocated;struct psp_dev *psp_dev;struct psp_dev_caps caps; };
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +89 -0
92 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h +2 -0
@@ -12,5 +12,7 @@ int idpf_send_get_crypto_caps(struct idpf_adapter *adapter,int idpf_send_get_psp_caps (struct idpf_adapter *adapter,struct virtchnl2_psp_get_caps *caps);int idpf_send_get_fips_compliance_status (struct idpf_adapter *adapter); +int idpf_send_allocate_psp_key (struct idpf_adapter *adapter, +struct idpf_psp_rx_key *key);#endif /* !_IDPF_PSP_VIRTCHNL_H_ */
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +3 -0
@@ -91,6 +91,9 @@ void idpf_recv_event_msg(struct libie_ctlq_ctx *ctx, adapter = container_of(ctx, struct idpf_adapter, ctlq_ctx);if (ctlq_msg->chnl_opcode !=VIRTCHNL2_OP_EVENT ) { +/* Late reply to a PSP request that timed out */ +idpf_psp_recv_late_reply (adapter, ctlq_msg); +dev_dbg (&adapter->pdev->dev,"Unhandled message with opcode %u from CP\n" , ctlq_msg->chnl_opcode);
include/linux/net/intel/virtchnl2.h +78 -0
96 lines not on this page · raw message
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH iwl-next 08/15] idpf: psp: add support for psp rx key allocation
Quoted 20 lines · Stan Iliev
Add support for allocating PSP RX keys on demand:
- IntroduceVIRTCHNL2_OP_PSP_ALLOCATE_KEYS(560),
enumvirtchnl2_psp_allocate_response_flags,
struct virtchnl2_psp_allocate_keys_request/_response and struct virtchnl2_allocate_psp_key_v0/_v1.
- Implementidpf_send_allocate_psp_key(), which allocates one V0 RX key with a synchronous request, validates the reply (key type,keys_size_bytes, length, and an SPI with a key ID, which the PSP core requires) and wipes the key from the mailbox buffer. The key, its SPI and its master key generation are returned in structidpf_psp_rx_key.
- Implement therx_spi_allocPSP device op. It gets the adapter from the netdev of the PSP device, as the vports can be freed while the PSP device is registered.
- Keep a copy of the vport ID inadapter->psp.vport_id, for the same reason.
- Wipe the RX keys of late replies, which libie passes toidpf_recv_event_msg()after the request timed out.Signed-off-by Stan Iliev <[email protected]>---
[...]
Quoted 31 lines
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +31
-0+int idpf_send_allocate_psp_key (struct idpf_adapter *adapter, +struct idpf_psp_rx_key *key) +{ +struct libie_ctlq_xn_send_params xn_params = { + .chnl_opcode =VIRTCHNL2_OP_PSP_ALLOCATE_KEYS , + .timeout_ms =IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC , + }; +const struct virtchnl2_psp_allocate_keys_response *vc_reply; +struct virtchnl2_psp_allocate_keys_request key_req = { }; +const struct virtchnl2_allocate_psp_key_v0 *v0_key; +size_t reply_sz; +u32 spi; +int err; + +BUILD_BUG_ON (sizeof (key->key) !=sizeof (v0_key->v0_key)); + + key_req.vport_id =cpu_to_le32 (READ_ONCE (adapter->psp.vport_id)); + key_req.num_keys =cpu_to_le32 (1 ); + key_req.key_type =VIRTCHNL2_PSP_KEY_TYPE_V0 ; +/* key_req.domain stays zeroed: VIRTCHNL2_PSP_DOMAIN_NONE */ + + err =idpf_send_mb_msg_stack (adapter, &xn_params, &key_req); +if (err) +return err; + + reply_sz = xn_params.recv_mem.iov_len; + vc_reply = xn_params.recv_mem.iov_base; +if (reply_sz <sizeof (*vc_reply) +sizeof (*v0_key) || + vc_reply->key_type !=VIRTCHNL2_PSP_KEY_TYPE_V0 || +le32_to_cpu (vc_reply->keys_size_bytes) !=sizeof (*v0_key)) { + net_warn_ratelimited("%s: invalid reply of %zu bytes\n",
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c int idpf_send_get_fips_compliance_status(struct idpf_adapter *adapter) · line 248
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +10
-0+ __func__, reply_sz); + err = -EIO ; + goto release_rx; + } + + v0_key = (const struct virtchnl2_allocate_psp_key_v0 *)vc_reply->keys; + spi =le32_to_cpu (v0_key->spi); +if (!(spi &PSP_SPI_KEY_ID )) { +net_warn_ratelimited ("%s: invalid SPI %#x\n" , __func__, spi); + err = -EIO ;
nit: seems a bit defensive not to trust the fw to provide a valid SPI. No issues with keeping it around though.
Quoted 15 lines
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +15
-0+ goto release_rx; + } + + key->spi =cpu_to_be32 (spi); + key->generation =le32_to_cpu (vc_reply->master_key_generation); +memcpy (key->key, v0_key->v0_key,sizeof (key->key)); +atomic_inc (&adapter->psp.keys_allocated); + +release_rx: +/* Don't leave the RX key in the recycled mailbox buffer */ +memzero_explicit (xn_params.recv_mem.iov_base, reply_sz); +libie_ctlq_release_rx_buf (&xn_params.recv_mem); +return err; +} +
[email protected]
AI reviewRe: [PATCH iwl-next 08/15] idpf: psp: add support for psp rx key allocation
In reply to Stan IlievThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] idpf: psp: race with hard reset in idpf_psp_rx_spi_alloc() - [Low] idpf: psp: wrong reset type in…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] idpf: psp: race with hard reset in idpf_psp_rx_spi_alloc()
- [Low] idpf: psp: wrong reset type in vport_id kernel-doc comment It also noticed 1 related pre-existing issue this patch does not introduce:
- [Medium] idpf: memory leak of tx_tstamp_caps on RSS error paths in idpf_vport_alloc() [1]
--
commit 579b4b79a623f0ec9c780b3ed4bd922d42ad422e
Author: Stan Iliev <[email protected]>
idpf: psp: add support for psp rx key allocation
This commit adds virtchnl definitions and driver support for allocating PSP V0 RX keys on demand via the rx_spi_alloc PSP device operation.
drivers/net/ethernet/intel/idpf/idpf_lib.c static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter, · line 1149
Quoted 11 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +3
-0@@ -1144,6 +1144,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,/* fill vport slot in the adapter struct */ adapter->vports[idx] = vport; adapter->vport_ids[idx] =idpf_get_vport_id (vport); +/* Copy for the PSP requests that can run while the vports are freed */ +if (IS_ENABLED (CONFIG_INET_PSP ) && !idx) +WRITE_ONCE (adapter->psp.vport_id, adapter->vport_ids[idx]);
[Severity: Medium]
This problem wasn't introduced by this patch, but does idpf_vport_alloc() leak vport->tx_tstamp_caps [1] if RSS initialization fails before adapter->vports[idx] is assigned?
Earlier in idpf_vport_alloc(), idpf_vport_init() calls idpf_ptp_get_vport_tstamps_caps(), which allocates vport->tx_tstamp_caps and populates its latches_free list. If allocating rss_data->rss_key or idpf_init_rss_lut() then fails, the error path jumps to deinit_vport_queues or free_rss_key and frees vport without releasing vport->tx_tstamp_caps, and the caller's cleanup via idpf_ptp_release() also misses it because adapter->vports[idx] is still NULL:
drivers/net/ethernet/intel/idpf/idpf_lib.c:idpf_vport_alloc() {
...
err = idpf_vport_init(vport, max_q);
if (err)
goto free_vport;
...
rss_data->rss_key = kzalloc(rss_data->rss_key_size, GFP_KERNEL);
if (!rss_data->rss_key)
goto deinit_vport_queues;
...
err = idpf_init_rss_lut(vport, rss_data);
if (err)
goto free_rss_key;
/* fill vport slot in the adapter struct */
adapter->vports[idx] = vport;
...
free_rss_key:
kfree(rss_data->rss_key);
rss_data->rss_key = NULL;
deinit_vport_queues:
idpf_vport_deinit_queue_reg_chunks(adapter->vport_config[idx]);
free_vport:
kfree(vport);
}Calling idpf_ptp_release_vport_tstamp(vport) on the deinit_vport_queues error path would avoid leaking the timestamp capability structure and its latch entries.
Quoted 4 lines
drivers/net/ethernet/intel/idpf/idpf_psp.c +0
-0
[ ... ]
Quoted 21 lines
drivers/net/ethernet/intel/idpf/idpf_psp.c +17
-0@@ -136,9 +139,49 @@ static int idpf_psp_set_config(struct psp_dev *psd, struct psp_dev_config *conf,return 0 ; } +/** +* idpf_psp_rx_spi_alloc - Allocate a PSP RX SPI and key +* @psd: PSP device +* @version: PSP version +* @key: filled with the allocated SPI and key +* @extack: netlink extended ack for error reporting +* +* Allocate one RX key with a synchronous VIRTCHNL2_OP_PSP_ALLOCATE_KEYS +* request. +* +* Return: 0 on success, negative error code on failure. +*/ +static int idpf_psp_rx_spi_alloc (struct psp_dev *psd,u32 version, +struct psp_key_parsed *key, +struct netlink_ext_ack *extack) +{ +struct idpf_adapter *adapter =idpf_netdev_to_adapter (psd->main_netdev);
drivers/net/ethernet/intel/idpf/idpf_psp.c static int idpf_psp_set_config(struct psp_dev *psd, struct psp_dev_config *conf, · line 168
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_psp.c +10
-0+struct idpf_psp_rx_key rx_key; +int err; + +/* Only version 0 keys are allocated, see idpf_psp_register() */ +if (psp_key_size (version) !=sizeof (rx_key.key)) { +NL_SET_ERR_MSG_MOD (extack,"Unsupported PSP version" ); +return -EOPNOTSUPP ; + } + + err =idpf_send_allocate_psp_key (adapter, &rx_key);
[Severity: High]
Can idpf_psp_rx_spi_alloc() race with a hard reset and trigger a use-after-free or NULL pointer dereference on the default mailbox queues?
idpf_psp_rx_spi_alloc() holds psd->lock, but does not acquire adapter->vport_ctrl_lock or check idpf_is_reset_in_prog(). When a hard reset runs, idpf_deinit_dflt_mbx() calls libie_ctlq_xn_deinit(), which frees adapter->xnm, adapter->asq and adapter->arq before setting those pointers to NULL:
CPU0 CPU1idpf_init_hard_reset() psp_nl_rx_assoc_doit()
idpf_vport_ctrl_lock(adapter) idpf_psp_rx_spi_alloc()
idpf_vc_core_deinit(adapter) idpf_send_allocate_psp_key()
idpf_deinit_dflt_mbx(adapter) idpf_send_mb_msg()
libie_ctlq_xn_deinit(...) idpf_is_reset_detected()
kfree(adapter->arq) readl(adapter->arq->...)
<-- use-after-free
adapter->arq = NULLIf idpf_send_mb_msg() passes idpf_is_reset_detected() just before idpf_deinit_dflt_mbx(), or during idpf_init_dflt_mbx() after adapter->arq is assigned but before adapter->xnm is set, idpf_mb_clean() and libie_ctlq_xn_send() can also dereference a freed or NULL adapter->asq or adapter->xnm.
In addition, neither idpf_psp_rx_spi_alloc() nor idpf_send_allocate_psp_key() checks idpf_is_psp_ena(adapter), so once idpf_init_dflt_mbx() finishes during a reset, VIRTCHNL2_OP_PSP_ALLOCATE_KEYS can be sent with a stale vport_id before vport recreation, or after idpf_psp_init() has disabled PSP offload.
drivers/net/ethernet/intel/idpf/idpf_psp_def.h line 37
Quoted 11 lines
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +3
-0@@ -19,6 +32,10 @@* @saidx_width: SA index width granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS * @psp_caps: PSP capabilities granted by VIRTCHNL2_OP_PSP_GET_CAPS, see * enum virtchnl2_psp_caps +* @vport_id: ID of adapter->vports[0] for the PSP requests. A copy, as the +* PSP device stays registered while the vports are freed and +* allocated again during a soft reset. Set in idpf_vport_alloc().
[Severity: Low]
This isn't a bug, but vports are freed and reallocated via idpf_vport_alloc() during a hard reset rather than a soft reset (idpf_initiate_soft_reset() only reallocates queue resources on the existing vport).
[1] https://sashiko.dev/#/bug/linux-9b904fce-205d-411e-be8c-4b18ed5978ec
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH 9/15 idpf: psp: add support for psp key rotation
In reply to Stan IlievAdd support for PSP master key rotation:
- Introduce VIRTCHNL2_OP_PSP_ROTATE_KEYGEN_REQUEST (563), struct virtchnl2_psp_rotate_keygen_request/_response, VIRTCHNL2_EVENT_PSP_ROTATE_KEY (4) and
struct virtchnl2_psp_rotation_event/_data.
- Implement the key_rotate PSP device op with idpf_psp_rotation_request(), which fails with -EOPNOTSUPP if VIRTCHNL2_CAP_PSP_REQUEST_ROTATION was not granted. The PSP core increments the PSP device generation before calling the op and doesn't restore it if the op fails: the op restores it then.
- Track the master key of the allocated RX SPIs, to report their generation on receive in a later patch: bit 31 of an SPI selects one of the two master keys of the CP, and the CP master key generation of the allocation tells when a master key was replaced. The packets of a master key get the PSP device generation that was current when its first SPI was allocated, which is the generation of the associations using it. Associations then survive one rotation, as the PSP core expects.
- Handle VIRTCHNL2_EVENT_PSP_ROTATE_KEY in idpf_recv_event_msg() with idpf_psp_rotation_event(), which logs the new master key generation. The PSP core can't be told about rotations it didn't request, like in mlx5: document the limitation and a possible solution.
--- drivers/net/ethernet/intel/idpf/idpf_psp.c | 72 +++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_psp.h | 6 ++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 23 +++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 89 +++++++++++++++++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 1 + .../net/ethernet/intel/idpf/idpf_virtchnl.c | 3 + include/linux/net/intel/virtchnl2.h | 53 +++++++++++ 7 files changed, 247 insertions(+)
drivers/net/ethernet/intel/idpf/idpf_psp.c +72 -0
@@ -106,6 +106,11 @@ void idpf_psp_init(struct idpf_adapter *adapter)dev_warn (dev,"Failed to get PSP FIPS compliance status: %d\n" , err); +/* The master keys are tracked again for the new PSP device */ + psp->generation =0 ; + psp->rx_gen[0 ].gen =IDPF_PSP_GEN_UNKNOWN ; + psp->rx_gen[1 ].gen =IDPF_PSP_GEN_UNKNOWN ; +/* The counters cover the time since the core init */ atomic_set (&psp->keys_allocated,0 );
@@ -139,6 +144,36 @@ static int idpf_psp_set_config(struct psp_dev *psd, struct psp_dev_config *conf,return 0 ; } +/** +* idpf_psp_rx_gen_update - Track the master key of an allocated SPI +* @adapter: private data struct +* @psd: PSP device, locked +* @spi: SPI allocated by the CP +* @cp_gen: CP master key generation of @spi +* +* Bit 31 of an SPI selects one of the two master keys of the CP, a rotation +* replaces the older one. The HW doesn't tell which master key decrypted a +* packet: report the PSP device generation that was current when the first +* SPI of the master key was allocated, which is the generation of the +* associations using it, see idpf_psp_rx_process_skb(). The CP master key +* generation tells when a master key was replaced, including by a rotation +* the PSP core didn't request, see idpf_psp_rotation_event(). +*/ +static void idpf_psp_rx_gen_update (struct idpf_adapter *adapter, +struct psp_dev *psd,__be32 spi,u32 cp_gen) +{ +struct idpf_psp_rx_gen *rx_gen; + +lockdep_assert_held (&psd->lock); + + rx_gen = &adapter->psp.rx_gen[be32_to_cpu (spi) >>31 ]; +if (rx_gen->gen !=IDPF_PSP_GEN_UNKNOWN && rx_gen->cp_gen == cp_gen) +return ; + + rx_gen->cp_gen = cp_gen; +WRITE_ONCE (rx_gen->gen, psd->generation); +} +/** * idpf_psp_rx_spi_alloc - Allocate a PSP RX SPI and key * @psd: PSP device
@@ -171,6 +206,8 @@ static int idpf_psp_rx_spi_alloc(struct psp_dev *psd, u32 version,return err; } +idpf_psp_rx_gen_update (adapter, psd, rx_key.spi, rx_key.generation); + key->spi = rx_key.spi;memcpy (key->key, rx_key.key,sizeof (rx_key.key));memzero_explicit (&rx_key,sizeof (rx_key));
@@ -178,10 +215,45 @@ static int idpf_psp_rx_spi_alloc(struct psp_dev *psd, u32 version,return 0 ; } +/** +* idpf_psp_key_rotate - Rotate the PSP master keys +* @psd: PSP device +* @extack: netlink extended ack for error reporting +* +* The PSP core increments the PSP device generation before calling this op +* and doesn't restore it if the op fails, see psp_nl_key_rotate_doit(): restore +* it then, the master keys didn't change. +* +* Return: 0 on success, negative error code on failure. +*/ +static int idpf_psp_key_rotate (struct psp_dev *psd, +struct netlink_ext_ack *extack) +{ +struct idpf_adapter *adapter =idpf_netdev_to_adapter (psd->main_netdev); +int err; + + err =idpf_psp_rotation_request (adapter); +if (err) { + psd->generation = adapter->psp.generation; + +if (err == -EOPNOTSUPP ) +NL_SET_ERR_MSG_MOD (extack,"PSP key rotation request not granted by CP" ); +else +NL_SET_ERR_MSG_MOD (extack,"PSP key rotation request failed" ); + +return err; + } + + adapter->psp.generation = psd->generation; + +return 0 ; +} +/* PSP device operations, see idpf_psp_register() */ static struct psp_dev_ops idpf_psp_ops = { .set_config = idpf_psp_set_config, .rx_spi_alloc = idpf_psp_rx_spi_alloc, + .key_rotate = idpf_psp_key_rotate, };/**
drivers/net/ethernet/intel/idpf/idpf_psp.h +6 -0
@@ -13,6 +13,8 @@ void idpf_psp_register(struct idpf_adapter *adapter);void idpf_psp_unregister (struct idpf_adapter *adapter);void idpf_psp_recv_late_reply (struct idpf_adapter *adapter,const struct libie_ctlq_msg *ctlq_msg); +void idpf_psp_rotation_event (struct idpf_adapter *adapter, +const struct libie_ctlq_msg *ctlq_msg);#else /* !CONFIG_INET_PSP */
@@ -25,6 +27,10 @@ static inline void idpf_psp_recv_late_reply(struct idpf_adapter *adapter, const struct libie_ctlq_msg *ctlq_msg) { } +static inline void +idpf_psp_rotation_event (struct idpf_adapter *adapter, +const struct libie_ctlq_msg *ctlq_msg) { } +#endif /* CONFIG_INET_PSP */ #endif /* !_IDPF_PSP_H_ */
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +23 -0
@@ -24,6 +24,23 @@ struct idpf_psp_rx_key {u8 key[VIRTCHNL2_PSP_KEY_SIZE_V0 ]; }; +/* PSP device generation of an SPI phase whose master key isn't known */ +#define IDPF_PSP_GEN_UNKNOWN 0xff + +/** +* struct idpf_psp_rx_gen - Generation of the master key of an SPI phase +* @cp_gen: CP master key generation of the SPIs allocated in the phase +* @gen: PSP device generation reported for the packets of the phase, +* IDPF_PSP_GEN_UNKNOWN if no SPI was allocated in the phase +* +* Bit 31 of an SPI selects one of the two master keys of the CP, see +* idpf_psp_rx_gen_update(). +*/ +struct idpf_psp_rx_gen { +u32 cp_gen; +u8 gen; +}; +/** * struct idpf_adapter_psp - PSP offload state of an adapter * @enabled: PSP was negotiated with the CP in the last core init, see
@@ -35,6 +52,10 @@ struct idpf_psp_rx_key {* @vport_id: ID of adapter->vports[0] for the PSP requests. A copy, as the * PSP device stays registered while the vports are freed and * allocated again during a soft reset. Set in idpf_vport_alloc(). +* @generation: PSP device generation after the last key rotation, protected +* by the PSP device lock, see idpf_psp_key_rotate() +* @rx_gen: generation of the master key of each SPI phase, protected by the +* PSP device lock, see idpf_psp_rx_gen_update() * @keys_allocated: RX keys allocated * @psp_dev: the PSP device, see idpf_psp_register() * @caps: capabilities of @psp_dev
@@ -45,6 +66,8 @@ struct idpf_adapter_psp {u8 saidx_width;u32 psp_caps;u32 vport_id; +u8 generation; +struct idpf_psp_rx_gen rx_gen[2 ];atomic_t keys_allocated;struct psp_dev *psp_dev;struct psp_dev_caps caps;
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +89 -0
95 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h +1 -0
@@ -14,5 +14,6 @@ int idpf_send_get_psp_caps(struct idpf_adapter *adapter,int idpf_send_get_fips_compliance_status (struct idpf_adapter *adapter);int idpf_send_allocate_psp_key (struct idpf_adapter *adapter,struct idpf_psp_rx_key *key); +int idpf_psp_rotation_request (struct idpf_adapter *adapter);#endif /* !_IDPF_PSP_VIRTCHNL_H_ */
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +3 -0
@@ -114,6 +114,9 @@ void idpf_recv_event_msg(struct libie_ctlq_ctx *ctx,case VIRTCHNL2_EVENT_LINK_CHANGE :idpf_handle_event_link (adapter, v2e);break ; +case VIRTCHNL2_EVENT_PSP_ROTATE_KEY : +idpf_psp_rotation_event (adapter, ctlq_msg); +break ;default :dev_err (&adapter->pdev->dev,"Unknown event %d from PF\n" , event);
include/linux/net/intel/virtchnl2.h +53 -0
71 lines not on this page · raw message
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH iwl-next 09/15] idpf: psp: add support for psp key rotation
Quoted 25 lines · Stan Iliev
Add support for PSP master key rotation:
- IntroduceVIRTCHNL2_OP_PSP_ROTATE_KEYGEN_REQUEST(563), struct virtchnl2_psp_rotate_keygen_request/_response,VIRTCHNL2_EVENT_PSP_ROTATE_KEY(4) and
struct virtchnl2_psp_rotation_event/_data.
- Implement thekey_rotatePSP device op withidpf_psp_rotation_request(), which fails with-EOPNOTSUPPifVIRTCHNL2_CAP_PSP_REQUEST_ROTATIONwas not granted. The PSP core increments the PSP device generation before calling the op and doesn't restore it if the op fails: the op restores it then.
- Track the master key of the allocated RX SPIs, to report their generation on receive in a later patch: bit 31 of an SPI selects one of the two master keys of the CP, and the CP master key generation of the allocation tells when a master key was replaced. The packets of a master key get the PSP device generation that was current when its first SPI was allocated, which is the generation of the associations using it. Associations then survive one rotation, as the PSP core expects.
- HandleVIRTCHNL2_EVENT_PSP_ROTATE_KEYinidpf_recv_event_msg()withidpf_psp_rotation_event(), which logs the new master key generation. The PSP core can't be told about rotations it didn't request, like in mlx5: document the limitation and a possible solution.Signed-off-by Stan Iliev <[email protected]>---
[...]
Quoted 18 lines
drivers/net/ethernet/intel/idpf/idpf_psp.c +18
-0+/** +* idpf_psp_rx_gen_update - Track the master key of an allocated SPI +* @adapter: private data struct +* @psd: PSP device, locked +* @spi: SPI allocated by the CP +* @cp_gen: CP master key generation of @spi +* +* Bit 31 of an SPI selects one of the two master keys of the CP, a rotation +* replaces the older one. The HW doesn't tell which master key decrypted a +* packet: report the PSP device generation that was current when the first +* SPI of the master key was allocated, which is the generation of the +* associations using it, see idpf_psp_rx_process_skb(). The CP master key +* generation tells when a master key was replaced, including by a rotation +* the PSP core didn't request, see idpf_psp_rotation_event(). +*/ +static void idpf_psp_rx_gen_update (struct idpf_adapter *adapter, +struct psp_dev *psd,__be32 spi,u32 cp_gen) +{
drivers/net/ethernet/intel/idpf/idpf_psp.c static int idpf_psp_set_config(struct psp_dev *psd, struct psp_dev_config *conf, · line 174
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_psp.c +10
-0+struct idpf_psp_rx_gen *rx_gen; + +lockdep_assert_held (&psd->lock); + + rx_gen = &adapter->psp.rx_gen[be32_to_cpu (spi) >>31 ]; +if (rx_gen->gen !=IDPF_PSP_GEN_UNKNOWN && rx_gen->cp_gen == cp_gen) +return ; + + rx_gen->cp_gen = cp_gen; +WRITE_ONCE (rx_gen->gen, psd->generation);
WRITE_ONCE isn't paired here. I'm guessing the Rx code in series 2 will copy rx_gen->gen into the psp skb extension, but that would likely not be correct. The generation field in the extension should be copied from Rx completion metadata. If such a descriptor field doesn't exist, then the key_rotate() implementation might as well pin psd->generation = 0 like mlx5 does.
Quoted 2 lines
(quoted diff) +2
-0+} +
PATCH 10/15 idpf: psp: add support for psp statistics
In reply to Stan IlievAdd support for the PSP device statistics:
- Introduce VIRTCHNL2_OP_GET_PSP_GLOBAL_STATS (566),
enum virtchnl2_psp_global_stats_type,
struct virtchnl2_psp_global_stats_request/_response, struct virtchnl2_psp_global_common_stats and
struct virtchnl2_psp_global_addon_stats.
- Implement idpf_send_get_psp_global_stats(): only the requested stat groups present in the reply are reported as supported.
- Implement the get_stats PSP device op. The last statistics read are kept in adapter->psp.stats and reported when they can't be read, e.g. during a reset.
--- drivers/net/ethernet/intel/idpf/idpf_psp.c | 51 +++++++++++++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 13 ++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 52 +++++++++++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 2 + include/linux/net/intel/virtchnl2.h | 75 +++++++++++++++++++ 5 files changed, 193 insertions(+)
drivers/net/ethernet/intel/idpf/idpf_psp.c +51 -0
@@ -249,11 +249,62 @@ static int idpf_psp_key_rotate(struct psp_dev *psd,return 0 ; } +/** +* idpf_psp_get_stats - Get the PSP device statistics +* @psd: PSP device +* @stats: statistics to fill in +* +* Read the PSP global statistics with VIRTCHNL2_OP_GET_PSP_GLOBAL_STATS. The +* last statistics read are reported if they can't be read, e.g. during reset. +*/ +static void idpf_psp_get_stats (struct psp_dev *psd,struct psp_dev_stats *stats) +{ +struct idpf_adapter *adapter =idpf_netdev_to_adapter (psd->main_netdev); +struct idpf_psp_dev_stats *cur = &adapter->psp.stats; +struct virtchnl2_psp_global_stats_response resp; +u32 supported; + +if (!idpf_send_get_psp_global_stats (adapter, &resp)) { + supported =le32_to_cpu (resp.supported_stats); + +if (supported &VIRTCHNL2_PSP_STAT_COMMON ) { +const struct virtchnl2_psp_global_common_stats *cs = + &resp.common_stats; + + cur->rx_packets =le64_to_cpu (cs->rx_decrypted_packets); + cur->rx_bytes =le64_to_cpu (cs->rx_decrypted_bytes); + cur->rx_auth_fail =le32_to_cpu (cs->rx_auth_failures); +/* PSP spec: rx_error counts length/framing errors, +* rx_bad miscellaneous errors. +*/ + cur->rx_error =le32_to_cpu (cs->rx_bad_packets); + cur->rx_bad =le32_to_cpu (cs->rx_misc_errors); + cur->tx_packets =le64_to_cpu (cs->tx_encrypted_packets); + cur->tx_bytes =le64_to_cpu (cs->tx_encrypted_bytes); + cur->tx_error = (u64 )le32_to_cpu (cs->tx_misc_errors) + +le32_to_cpu (cs->tx_bad_packets); +if (supported &VIRTCHNL2_PSP_STAT_ADDON ) + cur->tx_error += +le32_to_cpu (resp.addon_stats.tx_inv_sa_packets); + } + } + + stats->rx_packets = cur->rx_packets; + stats->rx_bytes = cur->rx_bytes; + stats->rx_auth_fail = cur->rx_auth_fail; + stats->rx_error = cur->rx_error; + stats->rx_bad = cur->rx_bad; + stats->tx_packets = cur->tx_packets; + stats->tx_bytes = cur->tx_bytes; + stats->tx_error = cur->tx_error; +} +/* PSP device operations, see idpf_psp_register() */ static struct psp_dev_ops idpf_psp_ops = { .set_config = idpf_psp_set_config, .rx_spi_alloc = idpf_psp_rx_spi_alloc, .key_rotate = idpf_psp_key_rotate, + .get_stats = idpf_psp_get_stats, };/**
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +13 -0
@@ -56,6 +56,9 @@ struct idpf_psp_rx_gen {* by the PSP device lock, see idpf_psp_key_rotate() * @rx_gen: generation of the master key of each SPI phase, protected by the * PSP device lock, see idpf_psp_rx_gen_update() +* @stats: last PSP device statistics read with +* VIRTCHNL2_OP_GET_PSP_GLOBAL_STATS, protected by the PSP device +* lock, see idpf_psp_get_stats() * @keys_allocated: RX keys allocated * @psp_dev: the PSP device, see idpf_psp_register() * @caps: capabilities of @psp_dev
@@ -68,6 +71,16 @@ struct idpf_adapter_psp {u32 vport_id;u8 generation;struct idpf_psp_rx_gen rx_gen[2 ]; +struct idpf_psp_dev_stats { +u64 rx_packets; +u64 rx_bytes; +u64 rx_auth_fail; +u64 rx_error; +u64 rx_bad; +u64 tx_packets; +u64 tx_bytes; +u64 tx_error; + } stats;atomic_t keys_allocated;struct psp_dev *psp_dev;struct psp_dev_caps caps;
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +52 -0
58 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h +2 -0
@@ -15,5 +15,7 @@ int idpf_send_get_fips_compliance_status(struct idpf_adapter *adapter);int idpf_send_allocate_psp_key (struct idpf_adapter *adapter,struct idpf_psp_rx_key *key);int idpf_psp_rotation_request (struct idpf_adapter *adapter); +int idpf_send_get_psp_global_stats (struct idpf_adapter *adapter, +struct virtchnl2_psp_global_stats_response *stats);#endif /* !_IDPF_PSP_VIRTCHNL_H_ */
include/linux/net/intel/virtchnl2.h +75 -0
87 lines not on this page · raw message
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH 11/15 idpf: psp: add psp tx key state
In reply to Stan IlievTX 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.
--- 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(+)
drivers/net/ethernet/intel/idpf/idpf_psp.c +51 -0
@@ -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
drivers/net/ethernet/intel/idpf/idpf_psp.h +31 -0
@@ -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) { }
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +30 -0
@@ -3,6 +3,8 @@#ifndef _IDPF_PSP_DEF_H_#define _IDPF_PSP_DEF_H_ +#include <linux/kref.h> +#include <linux/spinlock.h> #include <linux/net/intel/virtchnl2.h> #include <net/psp.h>
@@ -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
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH 12/15 idpf: psp: add support for psp tx key deletion
In reply to Stan IlievAdd support for deleting TX keys from the SADB:
- Introduce VIRTCHNL2_OP_PSP_DELETE_KEYS (562) and
struct virtchnl2_psp_delete_keys_request/_response.
- Add the delete queue, filled by idpf_psp_queue_delete(): a list of the TX keys whose SA index (hw_idx) must be deleted, which holds a reference on them. No deletion is queued during a reset or remove, as the SADB is flushed then.
- Implement idpf_send_delete_psp_keys(), which deletes up to IDPF_PSP_DELETE_KEYS_MAX (1018) SA indexes per request:
- the SA indexes of a request the CP failed, e.g. because of an
invalid SA index, are retried once each on their own;
- only the num_sa_indexes_deleted SA indexes of the reply are
removed, the others are counted as lost; - a request that timed out is not sent again, as the CP may have processed it: its SA indexes are counted as lost. A late reply, passed by libie to idpf_recv_event_msg(), moves the deleted ones to removed, at most the SA indexes counted as lost since the last core init;
- a request that couldn't be sent is queued again.
--- drivers/net/ethernet/intel/idpf/idpf_psp.c | 38 ++++ drivers/net/ethernet/intel/idpf/idpf_psp.h | 3 + .../net/ethernet/intel/idpf/idpf_psp_def.h | 23 +++ .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 175 +++++++++++++++++- .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 1 + .../intel/idpf/idpf_psp_virtchnl_def.h | 17 ++ include/linux/net/intel/virtchnl2.h | 30 +++ 7 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl_def.h
drivers/net/ethernet/intel/idpf/idpf_psp.c +38 -0
@@ -106,6 +106,13 @@ void idpf_psp_init(struct idpf_adapter *adapter)dev_warn (dev,"Failed to get PSP FIPS compliance status: %d\n" , err); +/* Initialized the first time PSP is negotiated */ +if (!psp->initialized) { +spin_lock_init (&psp->del_lock); +INIT_LIST_HEAD (&psp->del_list); + psp->initialized = true; + } +/* The master keys are tracked again for the new PSP device */ psp->generation =0 ; psp->rx_gen[0 ].gen =IDPF_PSP_GEN_UNKNOWN ;
@@ -113,6 +120,9 @@ void idpf_psp_init(struct idpf_adapter *adapter)/* The counters cover the time since the core init */ atomic_set (&psp->keys_allocated,0 ); +atomic_set (&psp->keys_removed,0 ); +atomic_set (&psp->keys_lost,0 ); +atomic_set (&psp->del_retries,0 );WRITE_ONCE (psp->enabled, true); }
@@ -144,6 +154,8 @@ struct idpf_psp_tx_key *idpf_psp_tx_key_alloc(void)kref_init (&key->ref);spin_lock_init (&key->lock); key->idx =IDPF_PSP_IDX_IN_PROG ; + key->hw_idx =IDPF_PSP_IDX_NONE ; +INIT_LIST_HEAD (&key->del_node);return key; }
@@ -179,6 +191,32 @@ void idpf_psp_tx_key_put(struct idpf_psp_tx_key *key)kref_put (&key->ref, idpf_psp_tx_key_free); } +/** +* idpf_psp_queue_delete - Queue the deletion of the SA index of a TX key +* @adapter: private data struct +* @key: the TX key, whose hw_idx is the SA index to delete +* +* The deletion requests are sent by the PSP work, which releases the +* reference taken on @key once the SA index was deleted, see +* idpf_send_delete_psp_keys(). No deletion is queued during a reset or +* remove: the SADB is flushed by the reset, and by the function reset on +* remove. +*/ +void idpf_psp_queue_delete (struct idpf_adapter *adapter, +struct idpf_psp_tx_key *key) +{ +struct idpf_adapter_psp *psp = &adapter->psp; + +if (idpf_is_reset_in_prog (adapter) || +test_bit (IDPF_REMOVE_IN_PROG , adapter->flags)) +return ; + +idpf_psp_tx_key_get (key); +spin_lock_bh (&psp->del_lock); +list_add_tail (&key->del_node, &psp->del_list); +spin_unlock_bh (&psp->del_lock); +} +/** * idpf_psp_set_config - Set the PSP device configuration * @psd: PSP device
drivers/net/ethernet/intel/idpf/idpf_psp.h +3 -0
@@ -47,6 +47,9 @@ static inline bool idpf_psp_idx_valid(u32 idx) return idx <= IDPF_PSP_IDX_MAX; } +void idpf_psp_queue_delete (struct idpf_adapter *adapter, +struct idpf_psp_tx_key *key); +#else /* !CONFIG_INET_PSP */ static inline void idpf_psp_init (struct idpf_adapter *adapter) { }
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +23 -0
@@ -4,10 +4,13 @@#define _IDPF_PSP_DEF_H_#include <linux/kref.h> +#include <linux/list.h> #include <linux/spinlock.h> #include <linux/net/intel/virtchnl2.h> #include <net/psp.h> +#include "idpf_psp_virtchnl_def.h" +/* SA index widths supported by the driver, negotiated per adapter with * VIRTCHNL2_OP_CRYPTO_GET_CAPS, see idpf_psp_negotiate_caps(). */
@@ -33,12 +36,19 @@* @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. +* @hw_idx: SA index of the key in the SADB, IDPF_PSP_IDX_NONE if it has none +* @del_node: entry in the delete queue, see idpf_psp_queue_delete() +* @del_single: delete @hw_idx in a request of its own, after a request that +* failed * @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; +u32 hw_idx; +struct list_head del_node; +bool del_single;struct rcu_head rcu; };
@@ -89,7 +99,14 @@ struct idpf_psp_rx_gen {* @stats: last PSP device statistics read with * VIRTCHNL2_OP_GET_PSP_GLOBAL_STATS, protected by the PSP device * lock, see idpf_psp_get_stats() +* @initialized: the locks and lists below were initialized, the first time +* PSP was negotiated +* @del_lock: protects @del_list +* @del_list: TX keys whose SA index is queued for deletion * @keys_allocated: RX keys allocated +* @keys_removed: SA indexes deleted +* @keys_lost: SA indexes that couldn't be deleted +* @del_retries: SA indexes retried after a failed deletion request * @psp_dev: the PSP device, see idpf_psp_register() * @caps: capabilities of @psp_dev */
@@ -111,7 +128,13 @@ struct idpf_adapter_psp {u64 tx_bytes;u64 tx_error; } stats; +bool initialized; +spinlock_t del_lock;/* protects del_list */ +struct list_head del_list;atomic_t keys_allocated; +atomic_t keys_removed; +atomic_t keys_lost; +atomic_t del_retries;struct psp_dev *psp_dev;struct psp_dev_caps caps; };
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +174 -1
198 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h +1 -0
@@ -17,5 +17,6 @@ int idpf_send_allocate_psp_key(struct idpf_adapter *adapter,int idpf_psp_rotation_request (struct idpf_adapter *adapter);int idpf_send_get_psp_global_stats (struct idpf_adapter *adapter,struct virtchnl2_psp_global_stats_response *stats); +bool idpf_send_delete_psp_keys (struct idpf_adapter *adapter);#endif /* !_IDPF_PSP_VIRTCHNL_H_ */
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl_def.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _IDPF_PSP_VIRTCHNL_DEF_H_ +#define _IDPF_PSP_VIRTCHNL_DEF_H_ + +#include <linux/net/intel/libie/controlq.h> +#include <linux/net/intel/virtchnl2.h> + +/* PSP key insertion and deletion requests must fit in one mailbox buffer, +* which limits the number of TX keys and SA indexes per request. +*/ +#define IDPF_PSP_DELETE_KEYS_MAX \ + ((LIBIE_CTLQ_MAX_BUF_LEN - \ + sizeof(struct virtchnl2_psp_delete_keys_request)) / \ + sizeof(__le32)) + +#endif /* !_IDPF_PSP_VIRTCHNL_DEF_H_ */
include/linux/net/intel/virtchnl2.h +30 -0
@@ -86,6 +86,7 @@ enum virtchnl2_op {VIRTCHNL2_OP_DEL_FLOW_RULE =553 ,/* Crypto/PSP opcodes */ VIRTCHNL2_OP_PSP_ALLOCATE_KEYS =560 , +VIRTCHNL2_OP_PSP_DELETE_KEYS =562 ,VIRTCHNL2_OP_PSP_ROTATE_KEYGEN_REQUEST =563 ,VIRTCHNL2_OP_CRYPTO_GET_CAPS =564 , VIRTCHNL2_OP_PSP_GET_CAPS = 565,
@@ -1990,6 +1991,35 @@ struct virtchnl2_psp_allocate_keys_response { };VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_psp_allocate_keys_response); +/** +* struct virtchnl2_psp_delete_keys_request - Delete PSP TX keys request +* @vport_id: Virtual port ID +* @num_sa_indexes: Number of SA indexes to delete +* @domain: Key domain, must be zero-filled if VIRTCHNL2_CAP_PSP_DOMAIN was +* not granted +* @sa_indexes: Flexible array of SA indexes to delete +*/ +struct virtchnl2_psp_delete_keys_request { +__le32 vport_id; +__le32 num_sa_indexes; +struct virtchnl2_psp_key_domain domain; + __le32 sa_indexes[] __counted_by_le(num_sa_indexes); +}; +VIRTCHNL2_CHECK_STRUCT_LEN (24 , virtchnl2_psp_delete_keys_request); + +/** +* struct virtchnl2_psp_delete_keys_response - Delete PSP TX keys response +* @vport_id: Virtual port ID +* @num_sa_indexes_deleted: Number of SA indexes deleted. The request fails if +* any SA index is invalid, and the deletion stops at +* the first hardware/config queue error. +*/ +struct virtchnl2_psp_delete_keys_response { +__le32 vport_id; +__le32 num_sa_indexes_deleted; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_psp_delete_keys_response); +/** * struct virtchnl2_psp_rotate_keygen_request - Request master key rotation * @vport_id: Virtual port ID
Signature · 1 line
2.56.0.679.gc527c65306-goog
[email protected]
AI reviewRe: [PATCH iwl-next 12/15] idpf: psp: add support for psp tx key deletion
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] idpf: psp: race on keys_lost in idpf_psp_recv_late_reply() on timeout --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] idpf: psp: race on keys_lost in idpf_psp_recv_late_reply() on timeout
--
commit 4b0d48dccce789bdff76728f6f4499fe7e727901
Author: Stan Iliev <[email protected]>
idpf: psp: add support for psp tx key deletion
This commit adds virtchnl definitions and driver support for queueing and sending VIRTCHNL2_OP_PSP_DELETE_KEYS requests to delete PSP TX keys from the SADB, including retry and late-reply accounting.
Quoted 27 lines
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +19
-0@@ -402,24 +402,197 @@ int idpf_send_get_psp_global_stats(struct idpf_adapter *adapter,return err; } +/** +* idpf_psp_delete_done - Release the TX keys of a deletion request +* @adapter: Driver specific private structure +* @batch: TX keys of the request +* @removed: number of SA indexes the CP deleted +* @lost: number of SA indexes that couldn't be deleted +*/ +static void idpf_psp_delete_done (struct idpf_adapter *adapter, +struct list_head *batch,u32 removed, +u32 lost) +{ +struct idpf_psp_tx_key *key, *tmp; + +atomic_add (removed, &adapter->psp.keys_removed); +if (lost) { +atomic_add (lost, &adapter->psp.keys_lost); +net_warn_ratelimited ("%s: %u SA indexes couldn't be deleted\n" , + __func__, lost); + }
[ ... ]
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +10
-0+case -ETIMEDOUT : +break ; +default : + goto requeue; + } + +/* The request timed out, or failed again on its own */ +idpf_psp_delete_done (adapter, &batch,0 , num_keys); + +return more;
[ ... ]
Quoted 16 lines
void idpf_psp_recv_late_reply(struct
idpf_adapter*adapter,drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +6
-0const struct libie_ctlq_msg *ctlq_msg) {const struct kvec *buff = &ctlq_msg->recv_mem; +const struct virtchnl2_psp_delete_keys_response *del_resp; +u32 deleted;switch (ctlq_msg->chnl_opcode) {case VIRTCHNL2_OP_PSP_ALLOCATE_KEYS :if (buff->iov_base)memzero_explicit (buff->iov_base, buff->iov_len);break ; +case VIRTCHNL2_OP_PSP_DELETE_KEYS : + del_resp = buff->iov_base; +if (!idpf_is_psp_ena (adapter) || ctlq_msg->chnl_retval || + !del_resp || buff->iov_len <sizeof (*del_resp))
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c int idpf_send_get_psp_global_stats(struct idpf_adapter *adapter, · line 595
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +10
-0+break ; + +/* Only the SA indexes counted as lost since the last core +* init, the counters were reset by a reset meanwhile +*/ + deleted =min_t (u32,le32_to_cpu (del_resp->num_sa_indexes_deleted), +max (atomic_read (&adapter->psp.keys_lost),0 )); +atomic_sub (deleted, &adapter->psp.keys_lost); +atomic_add (deleted, &adapter->psp.keys_removed); +break ;
[Severity: Medium]
Can idpf_psp_recv_late_reply() read adapter->psp.keys_lost before idpf_send_delete_psp_keys() adds the timed-out request's keys to it?
When wait_for_completion_timeout() expires in libie_ctlq_xn_send(), it marks the transaction LIBIE_CTLQ_XN_IDLE and drops xn->xn_lock before returning -ETIMEDOUT to idpf_send_delete_psp_keys():
CPU0 CPU1 (adapter->mbx_wq)idpf_send_delete_psp_keys()
idpf_send_mb_msg_kfree()
...
libie_ctlq_xn_send()
spin_lock(&xn->xn_lock)
xn->state = LIBIE_CTLQ_XN_IDLE
spin_unlock(&xn->xn_lock)
idpf_mbx_task()
...
idpf_psp_recv_late_reply()
atomic_read(&psp->keys_lost)
--> 0, clamps deleted to 0
idpf_psp_delete_done()
atomic_add(lost, &psp->keys_lost)Because idpf_psp_recv_late_reply() clamps deleted to keys_lost before idpf_psp_delete_done() adds num_keys, the deleted SA indexes are ignored by the late reply and remain permanently counted in keys_lost instead of keys_removed.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
PATCH 13/15 idpf: psp: add psp work and tx key insertion completion
In reply to Stan IlievAdd the PSP work and the completion of the asynchronous TX key insertion requests:
- Add the PSP work on the PSP workqueue, allocated the first time PSP is negotiated, which sends the queued deletion requests. A request that couldn't be sent, e.g. because no mailbox transaction was free, is sent again after IDPF_PSP_RETRY_MSEC: the PSP work is a delayed work. It is cancelled during a reset and while a soft reset reallocates the queues, and queued again afterwards.
- Introduce VIRTCHNL2_OP_PSP_INSERT_KEYS (561) and
struct virtchnl2_psp_insert_keys_response.
- Add struct idpf_psp_insert_req, the context of an insertion request, which holds a reference on its keys: it binds the response callback to the keys the request was sent for. At most one request is in flight.
- Implement idpf_psp_tx_key_inserted(), which publishes the SA index of an inserted key, and idpf_psp_tx_key_failed(). A key deleted while its insertion was pending gets its SA index deleted.
- libie calls the response callback of a request once, after the reply or the timeout, except on shutdown: idpf_psp_quiesce(), called after libie_ctlq_xn_shutdown() in idpf_vc_core_deinit(), fails the request in flight and drops the delete queue. libie only checks the timeouts in the mailbox task: a timer runs it once the request timed out, so that a lost reply in mailbox interrupt mode doesn't block the insertions.
- The SA indexes of late replies, passed by libie to idpf_recv_event_msg(), are queued for deletion.
--- drivers/net/ethernet/intel/idpf/idpf_lib.c | 12 + drivers/net/ethernet/intel/idpf/idpf_psp.c | 213 ++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_psp.h | 14 ++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 34 +++ .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 50 +++- .../intel/idpf/idpf_psp_virtchnl_def.h | 3 + .../net/ethernet/intel/idpf/idpf_virtchnl.c | 3 + include/linux/net/intel/virtchnl2.h | 16 ++ 8 files changed, 344 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/idpf_lib.c +12 -0
@@ -1458,6 +1458,9 @@ static int idpf_vport_open(struct idpf_vport *vport, bool rtnl)idpf_up_complete (vport); +/* Send the PSP requests queued while the vport was down */ +idpf_queue_psp_work (adapter); +if (rtnl)rtnl_unlock ();
@@ -1755,6 +1758,9 @@ static void idpf_init_hard_reset(struct idpf_adapter *adapter)dev_info (dev,"Device HW Reset initiated\n" ); +/* Stop sending PSP requests */ +idpf_cancel_psp_work (adapter); +/* Prepare for reset */ if (test_bit (IDPF_HR_DRV_LOAD , adapter->flags)) { reg_ops->trigger_reset (adapter,IDPF_HR_DRV_LOAD );
@@ -1882,6 +1888,11 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport,if (!new_vport)return -ENOMEM ; +/* No PSP packet is sent while the queues are reallocated, the PSP +* work is queued again below +*/ +idpf_cancel_psp_work (adapter); +/* This purposely avoids copying the end of the struct because it * contains wait_queues and mutexes and other stuff we don't want to * mess with. Nothing below should use those variables from new_vport
@@ -1970,6 +1981,7 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport, free_vport:kfree (new_vport); +idpf_queue_psp_work (adapter);if (reset_cause ==IDPF_SR_MTU_CHANGE ) idpf_idc_vdev_mtu_event(vport->vdev_info,
drivers/net/ethernet/intel/idpf/idpf_psp.c +213 -0
250 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp.h +14 -0
@@ -50,6 +50,16 @@ static inline bool idpf_psp_idx_valid(u32 idx)void idpf_psp_queue_delete (struct idpf_adapter *adapter,struct idpf_psp_tx_key *key); +void idpf_queue_psp_work (struct idpf_adapter *adapter); +void idpf_retry_psp_work (struct idpf_adapter *adapter); +void idpf_cancel_psp_work (struct idpf_adapter *adapter); +void idpf_psp_quiesce (struct idpf_adapter *adapter); +void idpf_psp_insert_timer_arm (struct idpf_adapter *adapter,u32 timeout_ms); +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); +#else /* !CONFIG_INET_PSP */ static inline void idpf_psp_init (struct idpf_adapter *adapter) { }
@@ -65,6 +75,10 @@ static inline void idpf_psp_rotation_event(struct idpf_adapter *adapter, const struct libie_ctlq_msg *ctlq_msg) { } +static inline void idpf_queue_psp_work (struct idpf_adapter *adapter) { } +static inline void idpf_cancel_psp_work (struct idpf_adapter *adapter) { } +static inline void idpf_psp_quiesce (struct idpf_adapter *adapter) { } +#endif /* CONFIG_INET_PSP */ #endif /* !_IDPF_PSP_H_ */
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +34 -0
@@ -6,6 +6,8 @@#include <linux/kref.h> #include <linux/list.h> #include <linux/spinlock.h> +#include <linux/timer.h> +#include <linux/workqueue.h> #include <linux/net/intel/virtchnl2.h> #include <net/psp.h>
@@ -52,6 +54,21 @@ struct idpf_psp_tx_key {struct rcu_head rcu; }; +/** +* struct idpf_psp_insert_req - VIRTCHNL2_OP_PSP_INSERT_KEYS request +* @adapter: adapter the request was sent for +* @num_keys: number of keys in the request +* @keys: keys of the request in request order, with a reference each +* +* The request is the context of the response callback: it binds the response +* to the keys it was sent for, see idpf_psp_insert_keys_cb(). +*/ +struct idpf_psp_insert_req { +struct idpf_adapter *adapter; +u32 num_keys; + struct idpf_psp_tx_key *keys[] __counted_by(num_keys); +}; +/** * struct idpf_psp_rx_key - PSP RX key allocated by the CP * @spi: SPI of the key
@@ -103,7 +120,16 @@ struct idpf_psp_rx_gen {* PSP was negotiated * @del_lock: protects @del_list * @del_list: TX keys whose SA index is queued for deletion +* @wq: workqueue of @work +* @work: sends the insertion and deletion requests +* @insert_lock: protects @insert_req +* @insert_req: the VIRTCHNL2_OP_PSP_INSERT_KEYS request in flight, if any +* @insert_timer: makes the mailbox task time out a lost insert request, +* see idpf_psp_insert_timeout() * @keys_allocated: RX keys allocated +* @keys_inserted: TX keys inserted into the SADB +* @insert_errors: TX keys whose insertion failed +* @insert_late: SA indexes of late insertion replies, queued for deletion * @keys_removed: SA indexes deleted * @keys_lost: SA indexes that couldn't be deleted * @del_retries: SA indexes retried after a failed deletion request
@@ -131,7 +157,15 @@ struct idpf_adapter_psp {bool initialized;spinlock_t del_lock;/* protects del_list */ struct list_head del_list; +struct workqueue_struct *wq; +struct delayed_work work; +spinlock_t insert_lock;/* protects the insertions */ +struct idpf_psp_insert_req *insert_req; +struct timer_list insert_timer;atomic_t keys_allocated; +atomic_t keys_inserted; +atomic_t insert_errors; +atomic_t insert_late;atomic_t keys_removed;atomic_t keys_lost;atomic_t del_retries;
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +49 -1
78 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl_def.h +3 -0
@@ -6,6 +6,9 @@#include <linux/net/intel/libie/controlq.h> #include <linux/net/intel/virtchnl2.h> +/* Timeout of the asynchronous VIRTCHNL2_OP_PSP_INSERT_KEYS requests */ +#define IDPF_VC_XN_PSP_RESPONSE_TIMEOUT_MSEC (60 * 1000) +/* PSP key insertion and deletion requests must fit in one mailbox buffer, * which limits the number of TX keys and SA indexes per request. */
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +3 -0
@@ -3281,6 +3281,9 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter)if (remove_in_prog)libie_ctlq_xn_shutdown (adapter->xnm); +/* The mailbox transactions were shut down in both cases */ +idpf_psp_quiesce (adapter); +cancel_delayed_work_sync (&adapter->serv_task);cancel_delayed_work_sync (&adapter->mbx_task);
include/linux/net/intel/virtchnl2.h +16 -0
@@ -86,6 +86,7 @@ enum virtchnl2_op {VIRTCHNL2_OP_DEL_FLOW_RULE =553 ,/* Crypto/PSP opcodes */ VIRTCHNL2_OP_PSP_ALLOCATE_KEYS =560 , +VIRTCHNL2_OP_PSP_INSERT_KEYS =561 ,VIRTCHNL2_OP_PSP_DELETE_KEYS =562 ,VIRTCHNL2_OP_PSP_ROTATE_KEYGEN_REQUEST =563 , VIRTCHNL2_OP_CRYPTO_GET_CAPS = 564,
@@ -1991,6 +1992,21 @@ struct virtchnl2_psp_allocate_keys_response { };VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_psp_allocate_keys_response); +/** +* struct virtchnl2_psp_insert_keys_response - Insert PSP TX keys response +* @vport_id: Virtual port ID +* @num_sa_indexes: Number of allocated SA indexes, at most the number of keys +* requested. On partial success the insertion stops at the +* first failure. +* @sa_indexes: Flexible array of allocated SA indexes +*/ +struct virtchnl2_psp_insert_keys_response { +__le32 vport_id; +__le32 num_sa_indexes; + __le32 sa_indexes[] __counted_by_le(num_sa_indexes); +}; +VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_psp_insert_keys_response); +/** * struct virtchnl2_psp_delete_keys_request - Delete PSP TX keys request * @vport_id: Virtual port ID
Signature · 1 line
2.56.0.679.gc527c65306-goog
[email protected]
AI reviewRe: [PATCH iwl-next 13/15] idpf: psp: add psp work and tx key insertion completion
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 2 related pre-existing issues it does not introduce: - [Critical] idpf: double free of vport->txqs…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 2 related pre-existing issues it does not introduce:
- [Critical] idpf: double free of vport->txqs in idpf_initiate_soft_reset() [1]
- [Critical] idpf: use-after-free in idpf_ptp_get_txq_tstamp_capability() [2]
--
commit 1bdbc7bd2b7486c90a1b74658932d35032195933
Author: Stan Iliev <[email protected]>
idpf: psp: add psp work and tx key insertion completion
This commit adds delayed work to send queued PSP key deletion requests and implements completion handling, timeout recovery, and quiescing for asynchronous TX key insertion requests.
Quoted 4 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +0
-0
[ ... ]
Quoted 13 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +5
-0@@ -1882,6 +1888,11 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport,if (!new_vport)return -ENOMEM ; +/* No PSP packet is sent while the queues are reallocated, the PSP +* work is queued again below +*/ +idpf_cancel_psp_work (adapter); +/* This purposely avoids copying the end of the struct because it * contains wait_queues and mutexes and other stuff we don't want to * mess with. Nothing below should use those variables from new_vport
drivers/net/ethernet/intel/idpf/idpf_lib.c int idpf_initiate_soft_reset(struct idpf_vport *vport, · line 1987
Quoted 7 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +1
-0@@ -1970,6 +1981,7 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport, free_vport:kfree (new_vport); +idpf_queue_psp_work (adapter);if (reset_cause ==IDPF_SR_MTU_CHANGE ) idpf_idc_vdev_mtu_event(vport->vdev_info,
[Severity: Critical]
This problem wasn't introduced by this patch, but can idpf_initiate_soft_reset() cause a double free of vport->txqs [1]?
After copying vport into new_vport, idpf_vport_stop() calls idpf_vport_queues_rel(), which frees vport->txqs and sets it to NULL, while only new_rsrc->rxq_grps is cleared in the clone:
drivers/net/ethernet/intel/idpf/idpf_lib.c:idpf_initiate_soft_reset() {
...
memcpy(new_vport, vport, offsetof(struct idpf_vport, link_up));
...
} else {
set_bit(IDPF_VPORT_DEL_QUEUES, vport->flags);
idpf_vport_stop(vport, false);
/* Drop the stale pointer in the clone, as rxq_grps was freed
* by idpf_vport_stop().
*/
new_rsrc->rxq_grps = NULL;
}
...
memcpy(vport, new_vport, offsetof(struct idpf_vport, link_up));
...
}The second memcpy() writes the freed vport->txqs pointer from new_vport back into vport. If idpf_set_real_num_queues() or idpf_vport_open() fails before reallocating the queues, the dangling vport->txqs pointer remains in vport and is freed a second time when idpf_vport_queues_alloc() later fails into idpf_vport_queues_rel().
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c void idpf_vc_core_deinit(struct idpf_adapter *adapter) · line 3288
Quoted 13 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +3
-0@@ -3281,6 +3281,9 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter)if (remove_in_prog)libie_ctlq_xn_shutdown (adapter->xnm); +/* The mailbox transactions were shut down in both cases */ +idpf_psp_quiesce (adapter); +cancel_delayed_work_sync (&adapter->serv_task);cancel_delayed_work_sync (&adapter->mbx_task);
[Severity: Critical]
This problem wasn't introduced by this patch, but can idpf_ptp_get_txq_tstamp_capability() trigger a use-after-free on txq->cached_tstamp_caps during teardown [2]?
In idpf_vc_core_deinit(), idpf_ptp_release() frees vport->tx_tstamp_caps before idpf_deinit_task() stops the vports and netdevs, while txq->cached_tstamp_caps on active TX queues still points to it:
CPU0 CPU1idpf_vc_core_deinit()
idpf_ptp_release()
idpf_ptp_release_vport_tstamp()
kfree(vport->tx_tstamp_caps)
idpf_tx_start()
...
idpf_ptp_get_txq_tstamp_capability()
txq->cached_tstamp_caps->access
<-- use-after-free idpf_deinit_task()
[1] https://sashiko.dev/#/bug/linux-2cb96bfd-fe1d-4dd4-ba7f-97cce6b47ab6
[2] https://sashiko.dev/#/bug/linux-6f8f8f90-94e3-4193-85dc-3ce7d6f00653
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
PATCH 14/15 idpf: psp: add support for psp tx key insertion
In reply to Stan IlievAdd support for inserting TX keys into the SADB:
- Introduce struct virtchnl2_insert_psp_key and
struct virtchnl2_psp_insert_keys_request.
- Add the insert queue, a list of the TX keys to insert with their SPI and key.
- Implement idpf_send_insert_psp_keys(), called from the PSP work, which inserts up to IDPF_PSP_INSERT_KEYS_MAX (101) queued TX keys with one asynchronous request. A request that couldn't be sent puts its keys back in the queue, they are sent again after a delay.
- Implement its response callback idpf_psp_insert_keys_cb(): the CP inserts the keys in request order and stops at the first failure, the keys without a valid SA index in the reply are failed. The callback queues the work again for the next request, so the work never waits for a reply.
- The keys are wiped once the request completed, the request buffer is freed with kfree_sensitive() by idpf_send_mb_msg_kfree().
--- drivers/net/ethernet/intel/idpf/idpf_psp.c | 13 ++ .../net/ethernet/intel/idpf/idpf_psp_def.h | 12 +- .../ethernet/intel/idpf/idpf_psp_virtchnl.c | 190 ++++++++++++++++++ .../ethernet/intel/idpf/idpf_psp_virtchnl.h | 1 + .../intel/idpf/idpf_psp_virtchnl_def.h | 4 + include/linux/net/intel/virtchnl2.h | 35 ++++ 6 files changed, 254 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/idpf_psp.c +13 -0
@@ -66,6 +66,7 @@ static void idpf_psp_work(struct work_struct *work) test_bit(IDPF_REMOVE_IN_PROG, adapter->flags)) return; +idpf_send_insert_psp_keys (adapter);if (idpf_send_delete_psp_keys (adapter))idpf_queue_psp_work (adapter); }
@@ -208,6 +209,7 @@ void idpf_psp_init(struct idpf_adapter *adapter)INIT_DELAYED_WORK (&psp->work, idpf_psp_work);spin_lock_init (&psp->insert_lock);timer_setup (&psp->insert_timer, idpf_psp_insert_timeout,0 ); +INIT_LIST_HEAD (&psp->ins_list); psp->initialized = true; }
@@ -266,6 +268,8 @@ void idpf_psp_quiesce(struct idpf_adapter *adapter)spin_lock_bh (&psp->insert_lock); req = psp->insert_req; psp->insert_req =NULL ; +list_splice_init (&psp->ins_list, &keys); +WRITE_ONCE (psp->ins_queued,0 );spin_unlock_bh (&psp->insert_lock);if (req) {
@@ -276,6 +280,12 @@ void idpf_psp_quiesce(struct idpf_adapter *adapter)kfree (req); } +list_for_each_entry_safe (key, tmp, &keys, ins_node) { +list_del_init (&key->ins_node); +idpf_psp_tx_key_failed (adapter, key); +idpf_psp_tx_key_put (key); + } +spin_lock_bh (&psp->del_lock);list_splice_init (&psp->del_list, &keys);spin_unlock_bh (&psp->del_lock);
@@ -322,6 +332,7 @@ struct idpf_psp_tx_key *idpf_psp_tx_key_alloc(void) key->idx =IDPF_PSP_IDX_IN_PROG ; key->hw_idx =IDPF_PSP_IDX_NONE ;INIT_LIST_HEAD (&key->del_node); +INIT_LIST_HEAD (&key->ins_node);return key; }
@@ -335,6 +346,8 @@ 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); +/* In case the key was never copied into an insert request */ +memzero_explicit (key->key,sizeof (key->key));/* The TX path may still read the SA index of the key */ kfree_rcu (key, rcu); }
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +11 -1
@@ -39,6 +39,9 @@* @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. * @hw_idx: SA index of the key in the SADB, IDPF_PSP_IDX_NONE if it has none +* @spi: SPI of the key +* @key: the key, wiped once copied into the insert request +* @ins_node: entry in the insert queue, see idpf_psp_queue_insert() * @del_node: entry in the delete queue, see idpf_psp_queue_delete() * @del_single: delete @hw_idx in a request of its own, after a request that * failed
@@ -49,6 +52,9 @@ struct idpf_psp_tx_key {spinlock_t lock;/* protects the SA indexes and tx_queue */ u32 idx;u32 hw_idx; +__be32 spi; +u8 key[VIRTCHNL2_PSP_KEY_SIZE_V0 ]; +struct list_head ins_node;struct list_head del_node;bool del_single;struct rcu_head rcu;
@@ -122,10 +128,12 @@ struct idpf_psp_rx_gen {* @del_list: TX keys whose SA index is queued for deletion * @wq: workqueue of @work * @work: sends the insertion and deletion requests -* @insert_lock: protects @insert_req +* @insert_lock: protects @insert_req, @ins_list and @ins_queued * @insert_req: the VIRTCHNL2_OP_PSP_INSERT_KEYS request in flight, if any * @insert_timer: makes the mailbox task time out a lost insert request, * see idpf_psp_insert_timeout() +* @ins_list: TX keys queued for insertion +* @ins_queued: number of keys in @ins_list * @keys_allocated: RX keys allocated * @keys_inserted: TX keys inserted into the SADB * @insert_errors: TX keys whose insertion failed
@@ -162,6 +170,8 @@ struct idpf_adapter_psp {spinlock_t insert_lock;/* protects the insertions */ struct idpf_psp_insert_req *insert_req;struct timer_list insert_timer; +struct list_head ins_list; +u32 ins_queued;atomic_t keys_allocated;atomic_t keys_inserted;atomic_t insert_errors;
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +190 -0
202 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h +1 -0
@@ -18,5 +18,6 @@ int idpf_psp_rotation_request(struct idpf_adapter *adapter);int idpf_send_get_psp_global_stats (struct idpf_adapter *adapter,struct virtchnl2_psp_global_stats_response *stats);bool idpf_send_delete_psp_keys (struct idpf_adapter *adapter); +void idpf_send_insert_psp_keys (struct idpf_adapter *adapter);#endif /* !_IDPF_PSP_VIRTCHNL_H_ */
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl_def.h +4 -0
@@ -12,6 +12,10 @@/* PSP key insertion and deletion requests must fit in one mailbox buffer, * which limits the number of TX keys and SA indexes per request. */ +#define IDPF_PSP_INSERT_KEYS_MAX \ + ((LIBIE_CTLQ_MAX_BUF_LEN - \ + sizeof(struct virtchnl2_psp_insert_keys_request)) / \ + sizeof(struct virtchnl2_insert_psp_key))#define IDPF_PSP_DELETE_KEYS_MAX \ ((LIBIE_CTLQ_MAX_BUF_LEN - \ sizeof(struct virtchnl2_psp_delete_keys_request)) / \
include/linux/net/intel/virtchnl2.h +35 -0
@@ -1992,6 +1992,41 @@ struct virtchnl2_psp_allocate_keys_response { };VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_psp_allocate_keys_response); +/** +* struct virtchnl2_insert_psp_key - PSP TX key entry to insert into SADB +* @spi: Security parameter index +* @key_type: See enum virtchnl2_psp_key_type +* @pad: Reserved/padding +* @v0_key: 128-bit key for V0 +* @v1_key: 256-bit key for V1 +*/ +struct virtchnl2_insert_psp_key { +__le32 spi; +u8 key_type; +u8 pad[3 ]; +union { +u8 v0_key[VIRTCHNL2_PSP_KEY_SIZE_V0 ]; +u8 v1_key[VIRTCHNL2_PSP_KEY_SIZE_V1 ]; + }; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (40 , virtchnl2_insert_psp_key); + +/** +* struct virtchnl2_psp_insert_keys_request - Insert PSP TX keys request +* @vport_id: Virtual port ID +* @num_keys: Number of keys to insert +* @domain: Key domain, must be zero-filled if VIRTCHNL2_CAP_PSP_DOMAIN was +* not granted +* @keys: Flexible array of keys to insert +*/ +struct virtchnl2_psp_insert_keys_request { +__le32 vport_id; +__le32 num_keys; +struct virtchnl2_psp_key_domain domain; + struct virtchnl2_insert_psp_key keys[] __counted_by_le(num_keys); +}; +VIRTCHNL2_CHECK_STRUCT_LEN (24 , virtchnl2_psp_insert_keys_request); +/** * struct virtchnl2_psp_insert_keys_response - Insert PSP TX keys response * @vport_id: Virtual port ID
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH 15/15 idpf: psp: add psp tx key registration
In reply to Stan IlievAdd 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.
--- 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(+)
drivers/net/ethernet/intel/idpf/idpf_psp.c +62 -0
@@ -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" );
drivers/net/ethernet/intel/idpf/idpf_psp.h +2 -0
@@ -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 */
drivers/net/ethernet/intel/idpf/idpf_psp_def.h +4 -0
@@ -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; };
drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c +4 -0
@@ -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)
Signature · 1 line
2.56.0.679.gc527c65306-goog