From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.35 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796549832; b=1buONLo62lPTXIeG+0RVE823QDMAp2wc+x5ad3ewNfmtOOAfg7eA17coduWWWJcdP32n nkadTcX8bBjcs7sFh518D76Rb5cAAGJaVKbMQvDQ1FpRGb6kCA6mlMyfBWmSV8hEKOvZd xrcZPdQ96KYfYWGU1BdCgt6Wa8RydETqxWFAmojuygLn2MS/z4JxnzItqr59D1tpkX7wO gi3n5z6yPn1TUaWhUr+AyKvmRRcMbF1oPTbACfi4pE5wakFcjTZ2MKP42M+VFL2ot9HDC qAEBmbYYHMWqUhTyXo22rpDpdWm5lEOsTpsHbylxIiba9fLic08E1jjoMoaCH7OHx1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796549832; h=DMARC-Filter:DKIM-Signature:Date:Received:X-Original-From:Cc: X-Lms-Return-Path:Content-Transfer-Encoding:Subject:Message-Id: Mime-Version:In-Reply-To:User-Agent:To:Content-Type:References:From; bh=1a8WTggH+DilrjMqlOInTicqJjatGwy7OeN9PWTzm38=; b=lbm/iHSRFP6FRVXRB1q4HUiPwwfKnappiq/FS2hxykbFbfrqMNefhtHx1uK4XGCkT30V z4MFynjmyVxVKIdrpYQ6E2BXmODe60pNZ01ANwp7HKWIwo6qvYO+otRQnohdBPguP7fi/ vpfGhPftx2S05X9fjPe86MFYgDVWVvHB0zTCL4WZBLDoiCZoITJ+9cwM1N1Ue5TiclNP6 JkGjuJhRBHfs4+3SGcNzAlxanlI9tZCfqGiGDxgOKWqrGTEQPrLgxc+yrkLiwsYxs0IJ8 bqX7v+HFOF9tO8K4K+zIlJ7YVtlGoPBDfwJlII5dGzVILbjJt42m2GJ8dIiHAMhK38Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=yunsilicon.com; spf=pass smtp.mailfrom=yunsilicon.com; dkim=pass header.d=yunsilicon.com header.i=@yunsilicon.com header.a=rsa-sha256 header.s=feishu2403070942 header.b=kYyFWlqQ; arc=none smtp.remote-ip=209.127.231.35 Received: from va-2-35.ptr.blmpb.com (va-2-35.ptr.blmpb.com [209.127.231.35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C04A7606A335 for ; Sun, 6 Dec 2026 09:37:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C04A7606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yunsilicon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yunsilicon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yunsilicon.com header.i=@yunsilicon.com header.a=rsa-sha256 header.s=feishu2403070942 header.b=kYyFWlqQ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1796549825; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=1a8WTggH+DilrjMqlOInTicqJjatGwy7OeN9PWTzm38=; b=kYyFWlqQViZ4FDvAEB3MADZokDpj+2gLXy/MFWX25Sy6FX1YTc8ERjuskAJQFvspKoJvGY xhVSJd6yjfqYNfHT6a2gQrxqGT5+gA8O8+dggTqZL8iMFBx6P341c0dsHljF8/N1fCEgl5 RV5ryzeQc4X8oQV+P9a9wtaO9gJoCh2nMtKGCssNYDCpLZ70E0CUlKcCeIwxij/vtUknTP hnnU2QVCMeDZdyz3IRvEFLaM3Z8YGZWjIdZtZQ+dxwDm07dVAUkEtsKfSehE4jDvdzht00 o6zfptfTE06n79VFI6Ha54a0odLUcf4Ny8X5PNrgH5fWxqMjZZeLHLFlsFztBQ== Date: Sun, 6 Dec 2026 17:36:57 +0800 Received: from [127.0.0.1] ([183.193.56.225]) by smtp.feishu.cn with ESMTPS; Sun, 06 Dec 2026 17:37:02 +0800 X-Original-From: Xin Tian Cc: , , , , , , , , , , , , X-Lms-Return-Path: Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH v2 06/11] net/xsc: add CQ and QP helpers Message-Id: <192530cb-d3bb-4818-a8f0-2a0be22cc115@yunsilicon.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 In-Reply-To: <179579507706.3135.12238248578368681777@kernel.org> User-Agent: Mozilla Thunderbird To: Content-Type: text/plain; charset=UTF-8 References: <20261126145727.70868-7-tianx@yunsilicon.com> <179579507706.3135.12238248578368681777@kernel.org> From: "Xin Tian" On 11/27/2026 11:57 PM, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 8 potential > issue(s) to consider. > > Critical: 0 =C2=B7 High: 0 =C2=B7 Medium: 1 =C2=B7 Low: 7 > > If you believe none of the issues are legitimate, please reply to each > issue of Medium severity or higher and explain why the AI is wrong. > If any of them are legitimate and you plan to respin, please let patchwor= k > know by including "pw-bot: cr" as a separate line at the end of your repl= y > (one such reply per series is enough). > > - [Medium] In xsc_core_eth_destroy_cq() > (drivers/net/ethernet/yunsilicon/xsc/pci/cq.c), the CQ is taken out of= =E2=80=A6 > - [Low] xsc_eq_int() in drivers/net/ethernet/yunsilicon/xsc/pci/eq.c > groups XSC_EVENT_TYPE_INTERNAL_ERROR (0x08, defined in enum xsc_event= =E2=80=A6 > - [Low] xsc_cq_completion() ('Completion event for bogus CQ'), > xsc_eq_cq_event() ('Async event for bogus CQ') and xsc_qp_event()=E2= =80=A6 > - [Low] The CQ/QP number widths do not agree across three places. > - [Low] The comment in xsc_core_eth_destroy_cq() (cq.c lines 106-109) > says the completion reader 'looks the cq up under rcu_read_lock and=E2= =80=A6 > - [Low] The exported helper xsc_core_eth_modify_qp_status(xdev, qpn, u16 > status) (prototype in xsc_core.h, implementation in qp.c) and its=E2= =80=A6 > - [Low] Several new messages print unsigned u32 CQ/QP numbers with %d: > cq.c xsc_core_eth_create_cq() and xsc_core_eth_destroy_cq() ('failed= =E2=80=A6 > - [Low] xsc_core_eth_destroy_qp() (qp.c lines 134-159) first moves the QP > to RST with xsc_core_eth_modify_qp_status(..., XSC_CMD_OP_2RST_QP). > > -- > > net/xsc: add CQ and QP helpers > > This patch adds CQ and QP radix tree tables to the xsc PCI core, along > with exported ethernet helpers to create, destroy and modify CQs and QPs. > It also dispatches completion, CQ error and WQ error events from > xsc_eq_int() to the registered CQ/QP callbacks. > >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/cq.c b/drivers/net/= ethernet/yunsilicon/xsc/pci/cq.c >> new file mode 100644 >> index 0000000000000..a4f9b488d659d >> --- /dev/null >> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/cq.c >> @@ -0,0 +1,130 @@ > [ ... ] > >> +static int xsc_create_cq(struct xsc_core_device *xdev, u32 *p_cqn, >> + struct xsc_create_cq_mbox_in *in, int insize) >> +{ > [ ... ] > >> + *p_cqn =3D be32_to_cpu(out.cqn) & 0xffffff; >> + return 0; >> +} > [Severity: Low] > The CQN kept here is 24 bits wide. xsc_core_eth_create_qp() keeps a > 24-bit QPN the same way. Both are used as radix tree keys, but the EQE > that xsc_eq_int() uses to look them up only carries 15 bits: > > eq.h: > #define XSC_EQE_QUEUE_ID_MASK GENMASK(14, 0) > > The mailbox fields that carry the same IDs (cqn_send, cqn_recv and > input_qpn in xsc_create_qp_request, qpn in xsc_modify_raw_qp_request) are > __be16, and the eth driver casts them with (u16). > > If firmware ever returned an ID of 0x8000 or above, would EQE lookups for > that object miss and get reported as bogus? Could they instead alias > another registered CQ/QP and run its callback? Should the create path > reject IDs that don't fit in the EQE queue_id field? Declined. QP/CQ numbers max out at 32768 (firmware QP/CQ_NUM_MAX), so 15 bits is enough and 0x8000+ is unreachable. > [ ... ] > >> +int xsc_core_eth_destroy_cq(struct xsc_core_device *xdev, >> + struct xsc_core_cq *xcq) >> +{ >> + struct xsc_cq_table *table =3D &xdev->cq_table; >> + struct xsc_core_cq *tmp; >> + int err; >> + >> + spin_lock_irq(&table->lock); >> + tmp =3D radix_tree_delete(&table->tree, xcq->cqn); >> + spin_unlock_irq(&table->lock); > [ ... ] > >> + /* the completion reader looks the cq up under rcu_read_lock and >> + * takes its reference afterwards; wait for it before dropping >> + * the tree reference so it never touches a freed cq >> + */ >> + synchronize_rcu(); > [Severity: Low] > This isn't a bug, but the comment doesn't match xsc_cq_completion(). That > function takes the reference inside the RCU read-side section, before > rcu_read_unlock(): > > rcu_read_lock(); > cq =3D radix_tree_lookup(&table->tree, cqn); > if (likely(cq)) > atomic_inc(&cq->refcount); > rcu_read_unlock(); > > That placement is what lets synchronize_rcu() order against the final > atomic_dec_and_test(). If atomic_inc() were moved after rcu_read_unlock() > to match the comment, the result would be a use-after-free. > > The comment also leaves out xsc_eq_cq_event(), which uses table->lock > rather than RCU. It also doesn't say that any use after the RCU section i= s > protected only by the refcount and the completion. > > Could the comment be updated to describe this accurately? Fixed, comment rewritten: the ref is taken inside the RCU section and eq_cq_event uses table->lock. >> + >> + err =3D xsc_destroy_cq(xdev, xcq->cqn); >> + if (err) >> + goto err_destroy_cq; >> + >> + if (atomic_dec_and_test(&xcq->refcount)) >> + complete(&xcq->free); >> + wait_for_completion(&xcq->free); >> + return 0; >> + >> +err_destroy_cq: >> + pci_err(xdev->pdev, "failed to destroy cqn=3D%d, err=3D%d\n", >> + xcq->cqn, err); >> + return err; > [Severity: Medium] > What happens to the CQ if xsc_destroy_cq() fails here? > > By then radix_tree_delete() has already removed the CQ from cq_table. The > err_destroy_cq path only logs and returns. It never drops the tree > reference and never calls wait_for_completion(&xcq->free). > > synchronize_rcu() doesn't drain handlers that already hold a reference. > xsc_cq_completion() calls cq->comp() after rcu_read_unlock(): > > xsc_cq_completion() > rcu_read_lock(); > cq =3D radix_tree_lookup(...); > atomic_inc(&cq->refcount); > rcu_read_unlock(); > cq->comp(cq); > atomic_dec_and_test(&cq->refcount) -> complete(&cq->free) > > xsc_eq_cq_event() takes its reference under table->lock, with no RCU at > all. Only the refcount wait covers these handlers, and this error path > skips it. > > The hardware CQ also can't be destroyed afterwards. A retry of > xsc_core_eth_destroy_cq() finds nothing in the tree and returns -ENOENT > without sending DESTROY_CQ again. > > Later in the series, xsc_eth_close_cq() leaks the CQ buffer on failure, > which avoids DMA into freed pages. xsc_eth_close_channel() then does: > > xsc_eth_close_cq(c, &c->qp.rq.cq); > memset(&c->qp.rq, 0, sizeof(struct xsc_rq)); > > and the same for c->qp.sq. Suppose a handler that wasn't drained loaded > cq->comp before the memset. Could xsc_eth_comp() then read a zeroed > cq->napi and call napi_schedule(NULL)? > > On non-RT kernels the hardirq handler usually finishes long before a > failed firmware round trip completes. With PREEMPT_RT, though, the handle= r > can be preempted after rcu_read_unlock(). > > mlx5_core_destroy_cq() has the same delete-before-command ordering and > the same early return, so the pattern isn't unique to xsc. Should this > error path still drop the tree reference and wait on xcq->free before > returning? Fixed. The refcount is now dropped even when the destroy command fails, and the caller still waits, so the CQ can't leak on that path. >> +err_delete_cq: >> + pci_err(xdev->pdev, "cqn=3D%d not found in tree, err=3D%d\n", >> + xcq->cqn, err); >> + return err; >> +} > [Severity: Low] > This isn't a bug, but cqn is a u32 printed with %d. Several other new > messages do the same: > > "failed to destroy cqn=3D%d" in xsc_core_eth_create_cq() and > xsc_core_eth_destroy_cq() > "bogus CQ, cqn=3D%d" and "cq->event is NULL, cqn=3D%d" in eq.c > "sq%d" in xsc_core_eth_destroy_qp() > > Other messages in qp.c print the same kind of ID as 0x%x or %u. Could > these use one consistent unsigned format? Changed to %u in cq.c, eq.c and qp.c. >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/eq.c b/drivers/net/= ethernet/yunsilicon/xsc/pci/eq.c >> index 875a277a83cb8..1ebc8941081a8 100644 >> --- a/drivers/net/ethernet/yunsilicon/xsc/pci/eq.c >> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/eq.c > [ ... ] > >> @@ -52,8 +54,63 @@ static void eq_update_ci(struct xsc_eq *eq, int arm) >> xsc_update_eq_ci(eq->dev, eq->eqn, eq->cons_index, arm); >> } >> =20 >> +static void xsc_cq_completion(struct xsc_core_device *xdev, u32 cqn) >> +{ >> + struct xsc_cq_table *table =3D &xdev->cq_table; >> + struct xsc_core_cq *cq; >> + >> + rcu_read_lock(); >> + cq =3D radix_tree_lookup(&table->tree, cqn); >> + if (likely(cq)) >> + atomic_inc(&cq->refcount); >> + rcu_read_unlock(); >> + >> + if (!cq) { >> + pci_err(xdev->pdev, "Completion event for bogus CQ, cqn=3D%d\n", >> + cqn); >> + return; >> + } > [Severity: Low] > This runs from the MSI-X hard IRQ handler, via > xsc_msix_handler()->xsc_eq_int(), and the queue ID comes from the device. > Could a misbehaving device flood the console from hardirq context here? > EQEs that arrive after a CQ/QP has left its table could do the same, > since the destroy helpers delete from the tree before sending the > firmware destroy command. > > xsc_eq_cq_event() ("Async event for bogus CQ") and xsc_qp_event() ("Async > event for bogus QP") have the same unratelimited pci_err(). The equivalen= t > message in mlx5_eq_comp_int() uses dev_dbg_ratelimited(). Ratelimited now. > [ ... ] > >> @@ -63,6 +120,32 @@ static int xsc_eq_int(struct xsc_eq *eq) >> * checked the ownership bit. >> */ >> rmb(); >> + switch (eqe->type) { >> + case XSC_EVENT_TYPE_COMP: >> + case XSC_EVENT_TYPE_INTERNAL_ERROR: >> + queue_id =3D FIELD_GET(XSC_EQE_QUEUE_ID_MASK, >> + le16_to_cpu(eqe->queue_id_data)); >> + cqn =3D queue_id; >> + xsc_cq_completion(xdev, cqn); >> + break; > [Severity: Low] > Is XSC_EVENT_TYPE_INTERNAL_ERROR meant to be handled as a normal > completion? > > enum xsc_event lists it with the other error events. xsc_cq_completion() > only calls cq->comp(cq) and drops the event type. So cq->event never sees > an internal error, and nothing is logged for it. > > Should this go through xsc_eq_cq_event() like XSC_EVENT_TYPE_CQ_ERROR? Or > does the name not reflect what the hardware reports? The intended > semantics can't be confirmed from the tree. Intentional. INTERNAL_ERROR is a locally-detected fault that can't be tied to a WQE (pulled WQE error, QP-state/DB mismatch, unmatchable sop/eop, out-of-range qpid...). When it fires the hardware flushes the WQEs, moves the QP to error and posts an err-CQE on the CQ, so there is a CQE to reap and the EQE only needs to trigger a re-poll, which is what xsc_cq_completion() -> napi_schedule() does. The error detail is in the CQE (err_code/qpid, logged by the poll path's error dump); cq->event is for CQ-level errors that may not come with a CQE, so nothing is lost. > [ ... ] > >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/qp.c b/drivers/net/= ethernet/yunsilicon/xsc/pci/qp.c >> new file mode 100644 >> index 0000000000000..ca2ad4ab0b42b >> --- /dev/null >> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/qp.c >> @@ -0,0 +1,180 @@ > [ ... ] > >> +int xsc_core_eth_modify_qp_status(struct xsc_core_device *xdev, >> + u32 qpn, u16 status) >> +{ >> + struct xsc_modify_qp_mbox_out out =3D {}; >> + struct xsc_modify_qp_mbox_in in =3D {}; >> + int ret; >> + >> + in.hdr.opcode =3D cpu_to_be16(status); > [Severity: Low] > This isn't a bug with the current callers, but the third argument is > named status and printed as "status=3D%u", yet it is written straight int= o > the command opcode. > > The only valid values are XSC_CMD_OP_* opcodes, such as > XSC_CMD_OP_2RST_QP and XSC_CMD_OP_RTR2RTS_QP, which is what the in-tree > callers pass. struct xsc_modify_qp_mbox_in also has a real state field, > which stays zero here. > > Since this helper is exported, could the argument be renamed (to opcode, > for example)? A future caller could otherwise pass a QP state and send > firmware an invalid opcode. Fixed: renamed to opcode and the log now prints it as such. > [ ... ] > >> +int xsc_core_eth_destroy_qp(struct xsc_core_device *xdev, u32 qpn) >> +{ >> + struct xsc_destroy_qp_mbox_out out; >> + struct xsc_destroy_qp_mbox_in in; >> + int err; >> + >> + err =3D xsc_core_eth_modify_qp_status(xdev, qpn, XSC_CMD_OP_2RST_QP); >> + if (err) { >> + pci_err(xdev->pdev, "failed to set sq%d status=3Drst, err=3D%d\n", >> + qpn, err); >> + return err; >> + } > [Severity: Low] > If the 2RST command fails, this returns without ever sending > XSC_CMD_OP_DESTROY_QP. Does that leak the firmware QP context and its > qpn? > > The close paths later in the series, xsc_eth_close_qp_sq() and > xsc_eth_close_qp_rq(), leak the WQ buffers when this returns an error. > The open-path rollbacks in xsc_eth_open_qp_sq() and xsc_eth_open_qp_rq() > ignore the return value: > > err_sq_destroy: > xsc_core_eth_destroy_qp(xdev, psq->cqp.qpn); > > The QP has already been removed from qp_table at that point, so it can't > be retried. > > Would a best-effort DESTROY_QP after a failed 2RST be worthwhile? The tre= e > doesn't show whether firmware requires the QP to be in RST before it can > be destroyed. > >> + >> + memset(&in, 0, sizeof(in)); >> + memset(&out, 0, sizeof(out)); >> + in.hdr.opcode =3D cpu_to_be16(XSC_CMD_OP_DESTROY_QP); > [ ... ] Keeping it. 2RST is what actually flushes the hardware QP; DESTROY_QP just frees the qpn (unset_qp_info + qpn_free, it never looks at the QP state). If the RST failed the QP was never flushed and may still be generating traffic, so freeing the index would hand out a dangling qpn. A leaked qpn that goes away on the next rebind is the better failure mode. Thanks, Xin