From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.37 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796548309; b=DtNyChg39uSQ42WUN1sE6eSCpw46g+kjVvjmNgGBBWVSEnjsgKQtj6aufBrkfWbAsNoR 1pIslCBoKk/YGLpc8AnX9qNtzOTy4ipXONKf947DyGnyhbasG3ZQEHdIEibzDUOC/iRqk rq32+LUwamHAUTjok/4QlLIOoaG3txBNHMwyMcFgy8nZAFqgVSb+lpzhZTFdszIP3xvM6 4qfiWhPuMG/uxUlFeRXP6dk9NQ5lBpPVglghxZb45Zi6wyJEMPf7BRjP7rVL2ZAEwOtvy COea91WVLJZfVGQXXIkbRPZjR8XiYRSoaU9vcmtDSk/gIBhLJ+tUO7ZTK2qZolTC1kA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796548309; h=DMARC-Filter:DKIM-Signature:X-Original-From:To:Mime-Version: User-Agent:Content-Transfer-Encoding:References:X-Lms-Return-Path: Subject:Date:In-Reply-To:Content-Type:Received:Cc:From:Message-Id; bh=S2NFxL+j1DsqyuUfae9/6qzZ5dhzJd9YQ/5ChaNUF6s=; b=cquq8nVXwWcho2Tv37ohxDIqKFvzJsFA2ftITUCcyczMigAJBQuY8BwB8o/fogIv8aY0 82pRyetUdppC7FaobKKFDtKQdt3/QxP1ikjYO0ZJ+4bklzhVLAFktrCECRXwuYfvGZusG 3zrwR/u/3ocO5GrfS6eDbXgrL/PF5VaA5Sgr6ycPeawnI8sLxkgwBy8IhoCxHwu/HzkUY hsJ4k0+RMlcUNlvBqh98gdd8RdAQ62MyPMbv94gY5S2AMcFjqqFysuzqFf9L8JvqNegte x1IhoTuJEezcv39wudgl1qp25+NqJjayKIMJTTpHMSNnCSx43v/0fnPucferRZcijMA== 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=RxxgTL2M; arc=none smtp.remote-ip=209.127.231.37 Received: from va-2-37.ptr.blmpb.com (va-2-37.ptr.blmpb.com [209.127.231.37]) (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 BD4B0606A31F for ; Sun, 6 Dec 2026 09:11:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BD4B0606A31F 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=RxxgTL2M DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1796548302; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=S2NFxL+j1DsqyuUfae9/6qzZ5dhzJd9YQ/5ChaNUF6s=; b=RxxgTL2MROy4BKmXDIRRfLGnWpI/mOEc8+cJpSdwU/PjKK0buDxgjQs0mx4hw+ywrbA5p8 grwfQrsjo49MEXMrWoqP1+17jMvPbuYAjgo0iT39pDB+ARFiDY7jGEuw95qfehGbvtMPXq anqgBVqwjsI2A6dpqRndGe6nDuDyaWC3eB7G/LtrK92wDZwsYhN3nVEv2VOoM9odVGWyYc loqPM/j6d8TnBZJAVPFiJyYfnD4VrAXQrSTEAnUGFQ4c8awXH+NnT/F42ZOBCh8pF3uZIv D/u1D5KLH/0mc00FvUTvgTSQtbndrhwU4XdDWuxoUtHpftg5QvxDWsQaZKRxlg== X-Original-From: Xin Tian To: 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 User-Agent: Mozilla Thunderbird Content-Transfer-Encoding: quoted-printable References: <20261126145724.70868-6-tianx@yunsilicon.com> <179579507511.3135.1874125473034318876@kernel.org> X-Lms-Return-Path: Subject: Re: [PATCH v2 05/11] net/xsc: add event queues and MSI-X Date: Sun, 6 Dec 2026 17:11:38 +0800 In-Reply-To: <179579507511.3135.1874125473034318876@kernel.org> Content-Type: text/plain; charset=UTF-8 Received: from [127.0.0.1] ([183.193.56.225]) by smtp.feishu.cn with ESMTPS; Sun, 06 Dec 2026 17:11:40 +0800 Cc: , , , , , , , , , , , , From: "Xin Tian" Message-Id: On 11/27/2026 11:57 PM, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 7 potential > issue(s) to consider. > > Critical: 0 =C2=B7 High: 0 =C2=B7 Medium: 2 =C2=B7 Low: 5 > > 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] xsc_buf_alloc() > (drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c) handles buffers=E2= =80=A6 > - [Medium] xsc_create_map_eq() > (drivers/net/ethernet/yunsilicon/xsc/pci/eq.c) frees the EQ ring for= =E2=80=A6 > - [Low] In xsc_destroy_unmap_eq() (eq.c), the u32 eq->eqn is printed with > "%d", a signed specifier. > - [Low] struct xsc_eq::index gets two different meanings. > - [Low] The exported link-event callback API publishes the handler with a > plain WRITE_ONCE() in xsc_irq_event_register(). > - [Low] The EQ consumer-index doorbell field is only 11 bits wide > (XSC_EQ_DB_DATA0_NEXT_CID_MASK =3D GENMASK(10, 0), with eqn in=E2=80= =A6 > - [Low] xsc_irq_eq_destroy() tears down the async EQ (xsc_stop_eqs) > before the completion EQs (free_comp_eqs). > > -- > > net/xsc: add event queues and MSI-X > > This commit creates the asynchronous and completion event queues, > allocates MSI-X vectors, and dispatches link events from a dedicated > workqueue. The command queue remains polling-only. > >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c b/drivers/n= et/ethernet/yunsilicon/xsc/pci/alloc.c >> new file mode 100644 >> index 0000000000000..46eb0b031511d >> --- /dev/null >> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c >> @@ -0,0 +1,123 @@ > [ ... ] > >> + for (i =3D 0; i < buf->nbufs; i++) { >> + buf->page_list[i].buf =3D >> + dma_alloc_coherent(&xdev->pdev->dev, PAGE_SIZE, >> + &t, GFP_KERNEL); > [ ... ] > >> + for (i =3D 0; i < buf->nbufs; i++) { >> + void *addr =3D buf->page_list[i].buf; >> + >> + if (is_vmalloc_addr(addr)) >> + pages[i] =3D vmalloc_to_page(addr); >> + else >> + pages[i] =3D virt_to_page(addr); >> + } >> + buf->direct.buf =3D vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL); > [Severity: Medium] > Is it valid to call virt_to_page()/vmalloc_to_page() on memory returned b= y > dma_alloc_coherent() and then vmap() it with PAGE_KERNEL? > > The DMA API doesn't guarantee that a coherent allocation sits behind a > linear-map address with a valid struct page. It can be an uncached remap, > memory from a memremap'd per-device or restricted pool, or a decrypted pa= ge > on SEV/TDX guests. In those cases the derived struct page is wrong, or th= e > new cacheable alias has attributes that don't match. vmap() can also fail= , > and then EQ creation fails. > > On 4K-page systems this path runs on every probe. Each completion EQ has > nent =3D roundup_pow_of_two(1024 + 0x80) =3D 2048 entries of 8 bytes. Tha= t is > 16 KiB, which is more than the max_direct =3D PAGE_SIZE passed by > xsc_create_map_eq(). > > The vmap'd buffer also seems to be unused. xsc_buf_offset() in xsc_core.h > never reads direct.buf when nbufs !=3D 1: > > if (likely(buf->nbufs =3D=3D 1)) > return buf->direct.buf + offset; > else > return buf->page_list[offset >> PAGE_SHIFT].buf + > (offset & (PAGE_SIZE - 1)); > > So direct.buf is only ever passed to vunmap(). > > Upstream removed the same pattern from mlx4_buf_alloc(). The current mlx4 > alloc.c uses per-page dma_alloc_coherent() fragments and no vmap. > > Could the vmap() step be dropped here too? Removed. nbufs > 1 never reads direct.buf so the vmap was dead code, and a coherent allocation has no struct page to vmap. Matches what mlx4 does. > [ ... ] > >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/eq.c b/drivers/net/= ethernet/yunsilicon/xsc/pci/eq.c >> new file mode 100644 >> index 0000000000000..875a277a83cb8 >> --- /dev/null >> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/eq.c >> @@ -0,0 +1,217 @@ > [ ... ] > >> +int xsc_create_map_eq(struct xsc_core_device *xdev, >> + struct xsc_eq *eq, u16 vecidx, >> + u32 nent, const char *name) >> +{ > [ ... ] > >> + eq->nent =3D roundup_pow_of_two(nent + XSC_NUM_SPARE_EQE); >> + err =3D xsc_buf_alloc(xdev, eq->nent * XSC_EQE_SIZE, PAGE_SIZE, &eq->b= uf); > [ ... ] > >> + in->hdr.opcode =3D cpu_to_be16(XSC_CMD_OP_CREATE_EQ); >> + in->ctx.log_eq_sz =3D ilog2(eq->nent); > [Severity: Low] > Can the consumer index doorbell describe a 2048-entry EQ? The CID field i= n > doorbell.c is only 11 bits wide: > > #define XSC_EQ_DB_DATA0_NEXT_CID_MASK GENMASK(10, 0) > #define XSC_EQ_DB_DATA0_EQ_ID_MASK GENMASK(21, 11) > > xsc_update_eq_ci() fills that field from the free-running eq->cons_index > using FIELD_PREP(), which silently masks non-constant values. > > The comp EQs have nent =3D 2048 (log_eq_sz =3D 11), so their doorbell car= ries > only the slot index. Bit 11, the wrap/phase bit that next_eqe_sw() uses > for ownership, is lost. The 512-entry async EQ keeps its index bits plus > two wrap bits. > > Whether this matters depends on how the hardware reads CID, which the > source doesn't show, and EQ occupancy is small today. > > Should the driver check the firmware-reported log_max_eq_sz before asking > for a 2^11 EQ? The field is in the hca_cap layout in xsc_cmd.h, but it is > not stored in xsc_caps. Fixed. EQ size is now roundup_pow2(roundup(nent, spare)) and the completion EQ stays at 1024, so the index fits the 11-bit doorbell field and the firmware EQ_SIZE_MAX. >> + in->ctx.vecidx =3D cpu_to_be16(msix_vec_offset); >> + in->ctx.pa_num =3D cpu_to_be16(hw_npages); >> + in->ctx.glb_func_id =3D cpu_to_be16(xdev->glb_func_id); >> + in->ctx.is_async_eq =3D (vecidx =3D=3D XSC_EQ_VEC_ASYNC ? 1 : 0); >> + >> + err =3D xsc_cmd_exec(xdev, in, inlen, &out, sizeof(out)); >> + if (err) >> + goto err_free_in; > [Severity: Medium] > What happens to the EQ ring when xsc_cmd_exec() returns -ETIMEDOUT here? > > The command layer treats a timeout as a command that is still in flight. > In xsc_cmd_invoke(): > > if (!wait_for_completion_timeout(&ent->done, timeout)) { > cmd->cmd_status =3D XSC_CMD_STATUS_TIMEDOUT; > ... > /* the entry stays registered for the completion handler */ > return -ETIMEDOUT; > } > > and _xsc_cmd_exec() keeps the mailboxes alive on a timeout: > > if (err =3D=3D -ETIMEDOUT) > /* the command owns both mailboxes now */ > return err; > > Here the error path goes to err_free_in and then err_free_eq_buf, so > xsc_buf_free() returns the ring pages with dma_free_coherent(). Their bus > addresses were already passed to firmware in in->pas[]. > > If the firmware completes the late CREATE_EQ, can it end up with an armed > EQ that DMAs into freed pages? Once cmd_status is TIMEDOUT, every later > xsc_cmd_exec() returns -ETIMEDOUT at once, so a DESTROY_EQ can never be > sent to recover. > > The err_destroy_eq path and xsc_destroy_unmap_eq() already leak the buffe= r > for this reason when DESTROY_EQ fails. Should a CREATE_EQ timeout leak > eq->buf as well, instead of freeing it? Agreed. On a CREATE_EQ timeout the ring is no longer freed: the device may still own it, so we leak rather than hand it back. > [ ... ] > >> + eq->index =3D vecidx; > [ ... ] > >> +int xsc_destroy_unmap_eq(struct xsc_core_device *xdev, struct xsc_eq *e= q) >> +{ >> + int err; >> + >> + free_irq(eq->irqn, eq); >> + err =3D xsc_cmd_destroy_eq(xdev, eq->eqn); >> + if (err) { >> + pci_err(xdev->pdev, "failed to destroy a previously created eq: eqn %= d\n", >> + eq->eqn); > [Severity: Low] > This isn't a bug, but eq->eqn is a u32 and is printed with %d. The caller > free_comp_eqs() logs the same failure again as "failed to destroy EQ > 0x%x". A single DESTROY_EQ failure therefore produces two error lines, > with the same EQ number shown once in decimal and once in hex. > > Could one of the messages be dropped, or both use the same format? Changed to %u and dropped the duplicate log in free_comp_eqs(). > [ ... ] > >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/pci_irq.c b/drivers= /net/ethernet/yunsilicon/xsc/pci/pci_irq.c >> new file mode 100644 >> index 0000000000000..accc3e56ba46c >> --- /dev/null >> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/pci_irq.c >> @@ -0,0 +1,345 @@ > [ ... ] > >> +int xsc_core_vector2eqn(struct xsc_core_device *xdev, int vector, u32 *= eqn, >> + unsigned int *irqn) >> +{ > [ ... ] > >> + list_for_each_entry_safe(eq, n, &table->comp_eqs_list, list) { >> + if (eq->index =3D=3D vector) { > [ ... ] > >> + snprintf(name, XSC_MAX_IRQ_NAME, "xsc_comp%d", i); >> + err =3D xsc_create_map_eq(xdev, eq, >> + i + table->eq_vec_comp_base, >> + nent, name); >> + if (err) { >> + kfree(eq); >> + goto err_free; >> + } >> + >> + eq->index =3D i; > [Severity: Low] > This isn't a bug, but struct xsc_eq::index ends up with two meanings. > xsc_create_map_eq() sets eq->index =3D vecidx, which is the absolute MSI-= X > table entry: 0 for async, and comp EQs starting at > XSC_EQ_VEC_COMP_BASE =3D 4. This line then immediately overwrites it with > the comp-relative i. > > The exported xsc_core_vector2eqn() compares vector against this field. > That makes the store in xsc_create_map_eq() dead for comp EQs, and the AP= I > does not say that vector is comp-relative. > > The in-tree callers added later in the series, xsc_eth_open_channel() and > xsc_eth_set_cq(), pass comp-relative indices and work today. > > Could the field or the vector argument of xsc_core_vector2eqn() be > documented, or split into two fields, so that a caller expecting MSI-X > numbering is not misled? Fixed: removed the dead eq->index store and documented that vector2eqn's @vector is a completion EQ index, not an MSI-X table entry. > [ ... ] > >> +static void xsc_event_work(struct work_struct *work) >> +{ > [ ... ] > >> + handler =3D READ_ONCE(xdev->link_event_handler); >> + if (handler) >> + handler(xdev); > [ ... ] > >> +void xsc_irq_event_register(struct xsc_core_device *xdev, >> + void (*handler)(void *xdev)) >> +{ >> + WRITE_ONCE(xdev->link_event_handler, handler); >> +} > [Severity: Low] > Is there enough ordering between xsc_irq_event_register() and > xsc_event_work()? > > The handler is published with a plain WRITE_ONCE(), read with a plain > READ_ONCE(), and called right away. It reaches the registrant's state > through xdev (for example xdev->eth_priv), and that access has no address > dependency on the function pointer. > > There is no smp_store_release()/smp_load_acquire() pair, lock, or RCU > here. A worker on another CPU could therefore see the new handler togethe= r > with state written before the register call that is still stale. > > The in-tree user in xsc_eth_probe() happens to get a wmb() on the writer > side from the xsc_cmd_exec() calls in between. Also, > xsc_eth_link_event_handler() returns early when !adapter || > !adapter->opened, so at worst a link event is ignored today. > > The header comment describes a register/unregister contract, but nothing > in the code orders it. Would release/acquire semantics be worth using > here? Declined, I don't see a reachable race: eth_priv is set in probe and two commands complete before the handler is registered, the handler re-checks opened under state_lock, and unregister flushes the workqueue. Worst case a pre-open link event gets dropped, and open() samples the link itself. > [ ... ] > >> +void xsc_irq_eq_destroy(struct xsc_core_device *xdev) >> +{ >> + xsc_stop_eqs(xdev); >> + free_comp_eqs(xdev); > [Severity: Low] > Should this teardown run in reverse creation order? > xsc_irq_eq_create() creates the async EQ first and the comp EQs after it. > Its own error unwind gets the order right: > > err_free_comp_eqs: > free_comp_eqs(xdev); > err_stop_eqs: > xsc_stop_eqs(xdev); > > Here, the async EQ (is_async_eq =3D 1, where firmware reports CQ/QP error > events) is destroyed while the comp EQs are still live in firmware. > > Later in the series xsc_pci_fini() calls xsc_adev_uninit() before this, s= o > no concrete failure is known. The normal teardown and the error unwind > still disagree. > > [ ... ] Fixed: completion EQs are torn down first and the async EQ last, reverse of creation. Thanks, Xin >