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=1796547885; b=3iPUeMhEHwRbV6pCnDHTUirmiG5+8k4/RLkP6b5tuToxxej9TzzWMKBE3QmSpLCFU3ho L4H8aUy9A6oCV7FUOC06hB67A82Hqfi3Sn9U91dG1+Gs1+8vPjCGiOxqgdus0Xes1bO5a VYgoiXrvjm4SgnndVQit94DAdDxqN0pwN1YuNVNksGkQ2smYMMl00pv8Rwl5akPVPn7gc VZfO7O7phm/xSG1OmpFnsGB8i+5+71cpVqjYksRItpA1hyzg0ktMj193H6zierDCP6nNV LMQzUtaiSGbcErFWFmwwUWbnyS3EUKCCnKYr/zyB02Do6oBs7GNf1irFSDGnjD+7V+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796547885; h=DMARC-Filter:DKIM-Signature:To:Subject:Mime-Version:Cc:User-Agent: Content-Transfer-Encoding:In-Reply-To:X-Original-From:From: X-Lms-Return-Path:Content-Type:Date:Message-Id:References:Received; bh=/YT6WutJUctLpbzX1gfBxchSQbHlyK6eTXbs0Xm9UHA=; b=g3TvOfallIubZSZ6fv+j2O+3lFWb9LCeu5MoV7S0frBlPtp5QwAU9p4/fCsOMeGL7e12 rAdXvTIllDcTDtEEdDMgujGvfB5ixM5g7aHgn8MbMx91lSJFuoO5eRYBkNmrvrdiv8hZ0 YX7eMWgqZ/2JCrIGyE42DW88+dfxQLxDJiZIbI9DzA4Kv1Ft9IKCUx0tBxgvauEM0rndt BASJrR7ko6SNlBjrY2Dk679n8aCOQ/jjAhoSkpxPpQOZedrocyNGpsI6y6dBseR4V7pEc AdUlKEzTvHLeeszgSMtQbZyD8SXlJw5eY51Noz620CUz4uR7QDovFIGAbBq4vVNz+zg== 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=VIKgoOj+; 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 2C444606A31F for ; Sun, 6 Dec 2026 09:04:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2C444606A31F 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=VIKgoOj+ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1796547879; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=/YT6WutJUctLpbzX1gfBxchSQbHlyK6eTXbs0Xm9UHA=; b=VIKgoOj+QcCeyYMCrmRkxpWfWGd043LngbKr49Rpe/4lJ7QLphxhT9l6CY6iivi1QyxJjQ KdYdjOGCFB9m+oa+qgminBR/PanuW9YdHaUwrPyWo8E+t8Zx+TWMoprkz/dAOIUSW+jIx5 KhnFZjXPqSKy1NI1PNJKWfV62V9rspz8RpoP3Wf42euUgf2NOK41QjZ6NzkwYkoi/UrPVi ep5quU5s+1oGVO/b4Jbs30ZDmGygXJSUv/0Y3xQz1t5gKmkAM1gn1SbGnim5ou+l409OuK OXChrYc6bxuZ8aF6lvThpvQqVT7MbHe05jNtHUWsSXOPGQI6PM+s61u/tE9RRg== To: Subject: Re: [PATCH v2 04/11] net/xsc: query HCA capabilities and reset function X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Cc: , , , , , , , , , , , , User-Agent: Mozilla Thunderbird Content-Transfer-Encoding: quoted-printable In-Reply-To: <179579507336.3135.5729346813922191216@kernel.org> X-Original-From: Xin Tian From: "Xin Tian" X-Lms-Return-Path: Content-Type: text/plain; charset=UTF-8 Date: Sun, 6 Dec 2026 17:04:35 +0800 Message-Id: <31a17e26-cb06-48eb-8a2c-e3360307984c@yunsilicon.com> References: <20261126145721.70868-5-tianx@yunsilicon.com> <179579507336.3135.5729346813922191216@kernel.org> Received: from [127.0.0.1] ([183.193.56.225]) by smtp.feishu.cn with ESMTPS; Sun, 06 Dec 2026 17:04:36 +0800 On 11/27/2026 11:57 PM, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 5 potential > issue(s) to consider. > > Critical: 0 =C2=B7 High: 1 =C2=B7 Medium: 1 =C2=B7 Low: 3 > > 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). > > - [High] In xsc_pci_init() > (drivers/net/ethernet/yunsilicon/xsc/pci/main.c), the new=E2=80=A6 > - [Medium] net/xsc: missing in.hdr.ver initialization in > xsc_cmd_query_hca_cap() > - [Low] xsc_cmd_query_hca_cap() in > drivers/net/ethernet/yunsilicon/xsc/pci/main.c computes=E2=80=A6 > - [Low] The subject line is split across two lines. > - [Low] xsc_cmd_query_hca_cap() > (drivers/net/ethernet/yunsilicon/xsc/pci/main.c) takes an unneeded=E2= =80=A6 > > -- > > net/xsc: query HCA capabilities and reset function > > During probe, this commit queries the firmware HCA capabilities (CQ size, > segment counts, MSI-X range, port and PF identifiers). It stores them in > struct xsc_caps and struct xsc_core_device, then sends the firmware > FUNCTION_RESET command to reset the function's resources. > >> net/xsc: query HCA capabilities and reset function >> >> resources > [Severity: Low] > This isn't a bug, but the subject line looks like it was wrapped onto two > lines. Git will use "net/xsc: query HCA capabilities and reset function" > as the subject, and "resources" will become the first paragraph of the > body. > > The cut-off shortlog also reads like a PCI function-level reset. The patc= h > actually sends the firmware XSC_CMD_OP_FUNCTION_RESET command. > > Could the subject be joined back into a single line? Fixed, same SMTP folding as P01 >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c b/drivers/ne= t/ethernet/yunsilicon/xsc/pci/main.c >> index 9b08580f52f38..42c5a1baed23b 100644 >> --- a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c >> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c >> @@ -29,6 +29,63 @@ static int xsc_set_dma_caps(struct pci_dev *pdev) >> return err; >> } >> =20 >> +static int xsc_cmd_query_hca_cap(struct xsc_core_device *xdev, >> + struct xsc_caps *caps) >> +{ > [ ... ] > >> + xdev->glb_func_id =3D be32_to_cpu(out->hca_cap.glb_func_id); >> + >> + caps->max_cqes =3D 1 << out->hca_cap.log_max_cq_sz; > [Severity: Low] > log_max_cq_sz is a u8 that comes straight from firmware, and nothing > checks its range. The 1 here is a signed int, so a value of 31 shifts int= o > the sign bit, and a value of 32 or more is undefined behaviour. > > Later in the series, xsc_eth_build_queue_param() does: > > min_t(int, XSC_RQCQ_ELE_NUM, xdev->caps.max_cqes) > > A max_cqes of 0x80000000 would become INT_MIN there and give a negative > queue size. log_max_qp_depth is also stored unchecked, and the same > function uses it in BIT(xdev->caps.log_max_qp_depth) for rq_size with no > upper clamp. > > Would it make sense to use 1U << n (or BIT()) here, and reject or clamp > out-of-range exponents? Declined. Firmware caps these exponents at 15, so the shift cannot overflow, and the resulting depths get clamped to the CQ capacity / max_cqes anyway. >> + caps->send_ds_num =3D out->hca_cap.send_seg_num; >> + caps->recv_ds_num =3D out->hca_cap.recv_seg_num; >> + >> + caps->nic_caps =3D (caps->nic_caps & ~XSC_CAP_MAC_PORT_MASK) | >> + FIELD_PREP(XSC_CAP_MAC_PORT_MASK, >> + out->hca_cap.mac_port & 0xff); >> + xdev->mac_port =3D FIELD_GET(XSC_CAP_MAC_PORT_MASK, caps->nic_caps); > [Severity: Low] > This isn't a bug, but is the round trip through caps->nic_caps needed? > Packing mac_port with FIELD_PREP() and then unpacking it with FIELD_GET() > gives the same result as: > > xdev->mac_port =3D out->hca_cap.mac_port; > > As far as I can tell, nothing else in the series reads caps->nic_caps. Th= at > leaves the nic_caps field and XSC_CAP_MAC_PORT_MASK otherwise unused. The > other capability fields are read by later patches, so this applies only t= o > nic_caps. > > The & 0xff masks on the u8 fields mac_port and log_max_qp_depth also have > no effect. Fixed. mac_port is assigned directly, the field/mask round-trip and the dead & 0xff are gone. > [ ... ] > >> @@ -90,6 +147,19 @@ static int xsc_pci_init(struct xsc_core_device *xdev= , >> goto err_cmd_cleanup; >> } >> =20 >> + err =3D xsc_cmd_query_hca_cap(xdev, &xdev->caps); >> + if (err) { >> + pci_err(pdev, "failed to query hca caps: err=3D%d\n", err); >> + goto err_cmd_cleanup; >> + } >> + >> + err =3D xsc_reset_function_resource(xdev); >> + if (err) { >> + pci_err(pdev, "failed to reset function resource: err=3D%d\n", >> + err); >> + goto err_cmd_cleanup; >> + } > [Severity: High] > What happens to the device's DMA if one of these commands times out and > probe takes the err_cmd_cleanup path? > > On a timeout, xsc_cmd_invoke() leaves the entry registered, and > _xsc_cmd_exec() leaves both mailboxes owned by the device: > > drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c: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; > } > ... > } > > drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c:_xsc_cmd_exec() { > ... > err =3D xsc_cmd_invoke(xdev, inb, outb, &status); > if (err =3D=3D -ETIMEDOUT) > /* the command owns both mailboxes now */ > return err; > ... > } > > The device still holds out->next->dma through lay->out_ptr. It also still > has cq_buf and cmd_buf programmed as DMA targets. > > xsc_cmd_cleanup() then stops only the polling kthread. It frees all of > that memory while bus mastering is still enabled: > > drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c:xsc_cmd_cleanup() { > ... > xsc_free_msg(xdev, cmd->ent_arr[i]->in); > xsc_free_msg(xdev, cmd->ent_arr[i]->out); > ... > dma_free_coherent(&xdev->pdev->dev, PAGE_SIZE, cmd->cq_buf, cmd->cq_dma)= ; > dma_free_coherent(&xdev->pdev->dev, PAGE_SIZE, cmd->cmd_buf, cmd->dma); > dma_pool_destroy(cmd->pool); > ... > } > > pci_clear_master() only runs later, at err_clr_master, after > pci_iounmap(). If the firmware finishes the timed-out command late, can i= t > DMA the response and completion entry into memory that has already gone > back to the page allocator or the dma_pool? > > The comment in xsc_cmd_cleanup() describes a response that "may never > come", which suggests the driver expects a late response is possible. > > This ordering comes from the earlier "net/xsc: add the command queue" > patch in this series. The xsc_cmd_version_check() error path can already > reach it, and xsc_pci_fini() also calls xsc_cmd_cleanup() before > pci_clear_master(). This patch adds two more probe paths into it. > FUNCTION_RESET is a firmware resource teardown, so it seems likely to run > long and time out. > > Should the device's cmdq be quiesced, or bus mastering cleared, before > the mailboxes and rings are freed? Same root cause as the P03 High, fixed there: the pci_clear_master() in xsc_cmd_cleanup(). The new error paths in this patch go through the same cleanup. > [ ... ] > >> @@ -29,6 +29,63 @@ static int xsc_set_dma_caps(struct pci_dev *pdev) >> return err; >> } >> =20 >> +static int xsc_cmd_query_hca_cap(struct xsc_core_device *xdev, >> + struct xsc_caps *caps) >> +{ >> + struct xsc_cmd_query_hca_cap_mbox_out *out; >> + struct xsc_cmd_query_hca_cap_mbox_in in; >> + int err; >> + >> + out =3D kzalloc_obj(*out, GFP_KERNEL); >> + if (!out) >> + return -ENOMEM; >> + >> + memset(&in, 0, sizeof(in)); >> + in.hdr.opcode =3D cpu_to_be16(XSC_CMD_OP_QUERY_HCA_CAP); >> + in.cpu_num =3D cpu_to_be16(num_online_cpus()); >> + >> + err =3D xsc_cmd_exec(xdev, &in, sizeof(in), out, sizeof(*out)); >> + if (err) >> + goto err_free; >> + >> + xdev->glb_func_id =3D be32_to_cpu(out->hca_cap.glb_func_id); >> + >> + caps->max_cqes =3D 1 << out->hca_cap.log_max_cq_sz; >> + caps->send_ds_num =3D out->hca_cap.send_seg_num; >> + caps->recv_ds_num =3D out->hca_cap.recv_seg_num; >> + >> + caps->nic_caps =3D (caps->nic_caps & ~XSC_CAP_MAC_PORT_MASK) | >> + FIELD_PREP(XSC_CAP_MAC_PORT_MASK, >> + out->hca_cap.mac_port & 0xff); >> + xdev->mac_port =3D FIELD_GET(XSC_CAP_MAC_PORT_MASK, caps->nic_caps); >> + >> + caps->msix_base =3D be16_to_cpu(out->hca_cap.msix_base); >> + caps->msix_num =3D be16_to_cpu(out->hca_cap.msix_num); >> + >> + caps->log_max_qp_depth =3D out->hca_cap.log_max_qp_depth & 0xff; >> + >> + xdev->pcie_no =3D out->hca_cap.pcie_no; >> + xdev->pf_id =3D out->hca_cap.pf_id; >> + >> + kfree(out); >> + return 0; >> +err_free: >> + kfree(out); >> + return err; >> +} >> + >> +static int xsc_reset_function_resource(struct xsc_core_device *xdev) >> +{ >> + struct xsc_function_reset_mbox_out out; >> + struct xsc_function_reset_mbox_in in; >> + >> + memset(&in, 0, sizeof(in)); >> + in.hdr.opcode =3D cpu_to_be16(XSC_CMD_OP_FUNCTION_RESET); >> + in.glb_func_id =3D cpu_to_be16(xdev->glb_func_id); >> + >> + return xsc_cmd_exec(xdev, &in, sizeof(in), &out, sizeof(out)); >> +} >> + >> static int xsc_pci_init(struct xsc_core_device *xdev, >> const struct pci_device_id *id) >> { > [Severity: Medium] > The input mailbox is zeroed by memset(), and only in.hdr.opcode and > in.cpu_num are filled in, so in.hdr.ver goes to the firmware as 0. > xsc_cmd.h defines XSC_CMD_QUERY_HCA_CAP_V1 as the hca_cap mbox > version, but nothing in the driver uses it. > > This matters because the function then reads out->hca_cap.pcie_no and > out->hca_cap.pf_id without any check. Those fields are part of the > versioned extension of struct xsc_hca_cap, and later in the series > xsc_core_eth_modify_raw_qp() uses them to set up raw QP port routing. > > The firmware might validate hdr.ver, or fill in the extended fields > only for a V1 request. In that case a version 0 request could fail > the query and abort probe. It could also leave pcie_no and pf_id at > zero from the kzalloc. In that second case probe succeeds and the raw > QPs are set up with the wrong port routing, and nothing is logged. > > Should this set in.hdr.ver =3D cpu_to_be16(XSC_CMD_QUERY_HCA_CAP_V1)? > If the firmware is meant to return the full structure for version 0, > could the commit message say so, and the unused define be dropped? Fixed: in.hdr.ver =3D XSC_CMD_QUERY_HCA_CAP_V1. Thanks, Xin