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. > diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c > b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c > index d36f46a46cfd7..42a7d74db2328 100644 > --- a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c > +++ b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c > @@ -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); > + } [ ... ] > + 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; [ ... ] > void idpf_psp_recv_late_reply(struct idpf_adapter *adapter, > const 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)) > + 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. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=12
