From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796304756; b=MtCtE+ruR+6L3b+7VN9e9qjGIH6TM3R0WnMbuL2VRjkSF47S0DXQeWIM0vLPmlwaU+D4 U+xwutO9bBU/8JLZoKKZWISqVb9hKJvCfvxymg6SrTzt83r1Nok74aB97Rk/6kqXtB2gy qiGEmVB5o8LwSCzwtnxznAAr1hjo1DhAhUQa0LSDYgpzGEPvrV7rvSqInTPi1RtsRtyin 6DPz3Q5NM2Ei+u+NEyhE3KYZCdDxB6Xa8Y7a1iOm+YND73Zg0z9jd3ypgmOZQSjNAXF4S l16L4J+Cg38XuJXlKIRVe9iI1Z/n0fLSfrLgeXpoJ6XyFuRRfkZZr/2rujnGjMneYoA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796304756; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=zOAgpA7YbfqTKBmaBeYv3S3x/KTWU4I+ntr1JUWtGwQ=; b=FrbCbnyWmWAP/mQbPRL0cxx1hGoW0Ie2OwxQ5Zjvjv/Ce/nA1CgNw8pVsXQqnjZDcFU0 OnEzG5BQ61Y2GZIQHaIzv6O99hTPOHatLjG1CI5trxndHrCzTesPdVMmElcb62CXC+BsP 8Xlr/uRcyDYXhPZJ60NfXHWa6S7flOdZDBeyCtcqXkhQv9CRkk4cN+zY6/WqNIUqN2zkU usM3RMvNhEbJEJQJcMNaRGq0sOTbtiz2WU09crONosz68tmqTwr3cWdFVA8c0IB+vn1Xp xVE4MOfE5BP26wrzkz7RfuFbtO2sxlJsV2wrVA01TaDHkzduaBN1oG3ZKUcZ0FZJtxw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Zkzpt3Cf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62BF1606A33E for ; Thu, 3 Dec 2026 13:32:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Zkzpt3Cf Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4FED1F00899; Thu, 3 Dec 2026 13:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796304756; bh=zOAgpA7YbfqTKBmaBeYv3S3x/KTWU4I+ntr1JUWtGwQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Zkzpt3Cf65RxHEzNxbyhRo81a0csCrtgiOgX5XO+1M1sCoQmio5fnyv5JtFIF5MVc fLrxKgIB/gRtbXh4BalbJ5y0dXt3lFmYJuzzgS3PyCYfNY9A9K2Wjri1HlSa1V2QJO YDN3y92ulVnz8SZCl8sdI97GPDz7qwNYqaJkgsokO2y+9nq/9GEo2qdAtHNR7N45T6 2+z8ARL7DJ+hUESisC4i5F+O5aTL1HNgWTroGqKvNuGDgkJ4BYHMoJkQH2Y5LgSYGo hLECUJpI2a3YEMGDKQvKgrVQfDh3St8FwYKFcdD5l0ii53IwT2hkQUVg2+k0jKp1eB DU+RTF4Dpr/bA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH rdma v10 5/7] RDMA/zrdma: Implement device and port query operations Reply-To: sashiko-reviews@lists.linux.dev To: "Yanze Zhang" Cc: linux-rdma@vger.kernel.org In-Reply-To: <20261203124928.48716-6-zhang.yanze@zte.com.cn> References: <20261203124928.48716-1-zhang.yanze@zte.com.cn> <20261203124928.48716-6-zhang.yanze@zte.com.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 13:32:35 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 10 potential issues to consider: - [High] RDMA/zrdma: zxdh_get_drvinfo() lacks netdev ref and state validation - [Medium] RDMA/zrdma: per-query global rtnl_lock() contention in zxdh_get_drvinfo() - [Medium] RDMA/zrdma: wrong device caps and resource limits in zxdh_query_device() - [Medium] RDMA/zrdma: zxdh_roce_port_immutable() advertises unsupported RoCEv1 - [Medium] RDMA/zrdma: zxdh_query_port() ignores ib_get_eth_speed() errors - [Medium] RDMA/zrdma: zxdh_get_drvinfo() bypasses ethtool_ops locking and PM contract - [Medium] RDMA/zrdma: raw zdev->netdev access without ib_device_get_netdev() - [Low] RDMA/zrdma: zxdh_get_drvinfo() falls back to bond master for fw_ver - [Low] RDMA/zrdma: zxdh_get_dev_fw_str() returns N/A instead of empty string - [Low] RDMA/zrdma: lockless plain read of netdev->mtu in zxdh_query_port() -- commit 0e0d51e910e9f9f58edf3a99788eb26f71ff9a42 Author: Yanze Zhang RDMA/zrdma: Implement device and port query operations This commit implements the query_device, query_port, query_pkey, get_link_layer, get_port_immutable, and get_dev_fw_str callbacks for zrdma, along with RoCE device initialization and ethtool firmware version extraction. > diff --git a/drivers/infiniband/hw/zrdma/zrdma_verbs.c b/drivers/infiniba= nd/hw/zrdma/zrdma_verbs.c > index 84ee7be418139..b5322a8e129bb 100644 > --- a/drivers/infiniband/hw/zrdma/zrdma_verbs.c > +++ b/drivers/infiniband/hw/zrdma/zrdma_verbs.c > @@ -7,11 +7,305 @@ [ ... ] > +static bool zxdh_get_drvinfo(struct zxdh_device *zdev, > + struct ethtool_drvinfo *info) > +{ > + struct net_device *slave =3D NULL, *dev; > + struct list_head *iter; > + bool ret =3D true; > + > + memset(info, 0, sizeof(*info)); > + > + if (!zdev->netdev) > + return false; [Severity: High] Can dereferencing zdev->netdev directly without taking a reference or checking device state cause a use-after-free or invoke get_drvinfo() on an unregistered or detached netdev? During ib_unregister_device(), __ib_unregister_device() calls free_netdevs() before device_del() removes the fw_ver sysfs attribute. Since fw_ver_show() does not hold an ib_device reference, a concurrent read can run after the sole netdev reference from ib_device_set_netdev() has been dropped: CPU0 CPU1 __ib_unregister_device() free_netdevs(ib_dev) netdev_put(netdev) ... free_netdev(netdev) fw_ver_show() ib_get_device_fw_str() zxdh_get_drvinfo() zdev->netdev <-- use-after-free device_del(&ib_dev->dev) Even while a reference exists, zxdh_get_drvinfo() never checks READ_ONCE(dev->reg_state) =3D=3D NETREG_REGISTERED under rtnl_lock(), so it= can call get_drvinfo() on an unregistering netdev after ndo_uninit() has torn down driver state. It also omits netif_device_present(dev), allowing calls on a detached netdev or bond slave during reset or hot-unplug. Pinning the netdev with ib_device_get_netdev(), checking reg_state and netif_device_present() under rtnl_lock(), and releasing it with dev_put() before rtnl_unlock() (as ib_get_eth_speed() does) avoids these hazards. > + > + rtnl_lock(); [Severity: Medium] Does taking rtnl_lock() unconditionally in zxdh_get_drvinfo() introduce unnecessary global lock contention on every query? zxdh_get_drvinfo() runs on every ibv_query_device_ex() call, every sysfs fw_ver read, and once per device during RDMA_NLDEV_CMD_GET netlink dumps. Each call acquires global rtnl_lock() and runs netdev_run_todo() on unlock, and ib_enum_all_devs() performs O(N) such cycles while holding devices_rwsem, which can stall RDMA device registration and unregistration. Caching the firmware version at initialization and refreshing it only on reset or bond changes would avoid per-query global RTNL serialization. > + > + /* Only the master of a bond has the slaves in its lower device > + * list. A slave carries the bonding flag as well, but it has no > + * lower devices of its own. > + */ > + if (netif_is_bond_master(zdev->netdev)) > + netdev_for_each_lower_dev(zdev->netdev, slave, iter) > + break; > + > + dev =3D slave ? slave : zdev->netdev; [Severity: Low] What happens here when zdev->netdev is a bond master with no lower slave devices attached? slave remains NULL and dev falls back to the bond master itself. bond_ethtool_get_drvinfo() then writes BOND_ABI_VERSION ("2") into info->fw_version, which extract_version() preserves verbatim and zxdh_get_dev_fw_str() reports as the RDMA firmware version instead of treating it as unavailable. > + if (dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) > + dev->ethtool_ops->get_drvinfo(dev, info); [Severity: Medium] Is it safe to call dev->ethtool_ops->get_drvinfo() directly under only rtnl_lock() without the locking, runtime PM, and begin/complete guards that ethtool core enforces? Because zxdh_get_drvinfo() traverses bond lower devices, dev can be an arbitrary Ethernet driver enslaved to the bond. For runtime-PM drivers like igc, calling get_drvinfo() without pm_runtime_get_sync(dev->dev.parent) and netif_device_present(dev) can issue live PCI MMIO against a suspended device. For ops-locked drivers like bnxt, ethtool_ops run under netdev_lock_ops(dev) rather than rtnl_lock(), so invoking get_drvinfo() without netdev_lock_ops() races with netdev_lock-only paths such as bnxt_fw_reset_task(). It also skips dev->ethtool_ops->begin() and complete(). [ ... ] > + /* Only the capabilities that the driver implements are reported. > + * The memory management extensions need the advise_mr operation, > + * the notification of the completion queue needs req_notify_cq and > + * the RNR NAK generation needs the queue pair data path. > + */ > + props->device_cap_flags =3D > + IB_DEVICE_MEM_WINDOW | IB_DEVICE_SYS_IMAGE_GUID; > + props->vendor_id =3D pcidev->vendor; > + props->vendor_part_id =3D pcidev->device; > + props->hw_ver =3D pcidev->revision; > + props->page_size_cap =3D SZ_4K | SZ_2M | SZ_1G; > + props->max_mr_size =3D MAX_MR_SIZE; > + props->max_qp =3D MAX_QP; > + props->max_qp_wr =3D MAX_QP_WR; > + props->max_cq =3D MAX_CQ; > + props->max_cqe =3D MAX_CQE; > + props->max_mr =3D MAX_MR; > + props->max_mw =3D MAX_MW; > + props->max_pd =3D MAX_PD; > + props->max_send_sge =3D MAX_SEND_SGE; > + props->max_recv_sge =3D MAX_RECV_SGE; > + props->max_sge_rd =3D MAX_SGE_RD; > + props->max_qp_rd_atom =3D MAX_QP_RD_ATOM; > + props->max_res_rd_atom =3D MAX_RES_RD_ATOM; > + props->max_qp_init_rd_atom =3D MAX_QP_INIT_RD_ATOM; > + props->max_srq =3D MAX_SRQ; > + props->max_srq_wr =3D MAX_SRQ_WR; > + props->max_srq_sge =3D MAX_SRQ_SGE; > + props->local_ca_ack_delay =3D LOCAL_CA_ACK_DELAY; > + props->hca_core_clock =3D HCA_CORE_CLOCK; > + props->max_wq_type_rq =3D MAX_WQ_TYPE_RQ; > + if (rdma_protocol_roce(ibdev, rdma_start_port(ibdev))) { > + props->max_pkeys =3D ZXDH_PKEY_TBL_SZ; > + props->max_ah =3D MAX_AH; > + props->max_mcast_grp =3D 0; > + props->max_mcast_qp_attach =3D 0; > + props->max_total_mcast_qp_attach =3D 0; > + } > + props->max_fast_reg_page_list_len =3D MAX_FAST_REG_PAGE_LIST_LEN; > + props->cq_caps.max_cq_moderation_count =3D MAX_CQ_MODERATION_COUNT; > + props->cq_caps.max_cq_moderation_period =3D MAX_CQ_MODERATION_PERIOD; > + props->timestamp_mask =3D TIMESTAMP_MASK; [Severity: Medium] Should zxdh_query_device() avoid advertising unimplemented capabilities and align its reported resource limits with the actual hardware pools? Despite the comment above device_cap_flags, this sets IB_DEVICE_MEM_WINDOW and max_mw even though zxdh_dev_ops implements neither alloc_mw nor dealloc_mw. It also reports non-zero cq_caps moderation limits without modify_cq, non-zero timestamp_mask without timestamp support, and non-zero max_fast_reg_page_list_len without IB_DEVICE_MEM_MGT_EXTENSIONS (and the comment attributes IB_DEVICE_MEM_MGT_EXTENSIONS to advise_mr rather than FRWR alloc_mr / map_mr_sg). The hardcoded MAX_* macros also diverge from the pools initialized in zxdh_initialize_hw_rsrc(): max_srq reports MAX_SRQ (0x200) while rf->max_srq is ZXDH_MAX_SRQ (0x2000), max_ah reports MAX_AH (0x10000) even though entry 0 is reserved in rf->allocated_ahs leaving 0xffff allocatable AHs, and max_cq reports MAX_CQ (0x3fff) while rf->max_cq is ZXDH_MAX_CQ (0x4000) with entry 0 not reserved. [ ... ] > +static int zxdh_query_port(struct ib_device *ibdev, u32 port, > + struct ib_port_attr *props) > +{ > + struct zxdh_device *zdev =3D to_zdev(ibdev); > + struct net_device *netdev =3D zdev->netdev; [Severity: Medium] Can accessing zdev->netdev directly in zxdh_query_port() race with ib_unregister_device()? In __ib_unregister_device(), free_netdevs() drops the ib_device_set_netdev() reference before ib_free_port_attrs() removes the port sysfs attributes. If zdev->netdev is a bond master being deleted while a port sysfs read enters zxdh_query_port(), it can dereference a freed net_device; zrdma also registers no NETDEV_UNREGISTER notifier. Pinning the netdev with ib_device_get_netdev(ibdev, port) and calling dev_put() on exit avoids the raw pointer lifetime hazard. > + > + props->max_mtu =3D IB_MTU_4096; > + props->active_mtu =3D ib_mtu_int_to_enum(netdev->mtu - ZXDH_MTU_HEADER_= RSV); [Severity: Low] Should netdev->mtu be read with READ_ONCE() here? zxdh_query_port() runs without rtnl_lock(), while __netif_set_mtu() updates dev->mtu with WRITE_ONCE(), so a plain load creates a KCSAN data race. [ ... ] > + /* The link speed is read from the netdev on every query, so a > + * link change is never reported with a stale value. > + */ > + if (ib_get_eth_speed(ibdev, port, &props->active_speed, > + &props->active_width)) > + pr_warn_ratelimited("zrdma: failed to get the port speed\n"); [Severity: Medium] Should zxdh_query_port() propagate the error from ib_get_eth_speed() instead of returning 0? When ib_get_eth_speed() fails with -ENODEV (for example during ib_unregister_device() after free_netdevs() or while the netdev is unregistering), props->active_speed and props->active_width remain 0. Because 0 is not a valid speed or width enum value, sysfs rate_show() turns the error into -EINVAL via ib_width_enum_to_int(0), and uverbs QUERY_PORT succeeds while returning invalid zero values to userspace. Since ib_get_eth_speed() already defaults unknown ethtool link speeds to SPEED_1000 and returns 0, a non-zero return indicates an unavailable netdev. [ ... ] > +static int zxdh_roce_port_immutable(struct ib_device *ibdev, u32 port_nu= m, > + struct ib_port_immutable *immutable) > +{ [ ... ] > + immutable->core_cap_flags =3D RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP | > + RDMA_CORE_CAP_PROT_ROCE; [Severity: Medium] Does setting RDMA_CORE_CAP_PROT_ROCE advertise unsupported RoCEv1 on this device? enum zxdh_rdma_protocol defines only iWARP and RoCEv2, and RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP alone already satisfies rdma_protocol_roce(). Adding RDMA_CORE_CAP_PROT_ROCE enables rdma_protocol_roce_eth_encap(), causing the RDMA core to reserve an extra default GID slot and populate unsupported RoCEv1 GIDs for every address, halving effective GID table capacity and exposing them to userspace. [ ... ] > +static void zxdh_get_dev_fw_str(struct ib_device *dev, char *str) > +{ > + struct zxdh_device *zdev =3D to_zdev(dev); > + struct ethtool_drvinfo info; > + char extracted_version[32]; > + > + strscpy(str, "N/A", IB_FW_VERSION_NAME_MAX); [Severity: Low] Should zxdh_get_dev_fw_str() leave str empty instead of writing "N/A" when the firmware version is unavailable? ib_get_device_fw_str() and fill_dev_info() in drivers/infiniband/core/nldev= .c use strlen(fw) =3D=3D 0 to detect a missing firmware version and omit RDMA_NLDEV_ATTR_FW_VERSION. Returning "N/A" causes RDMA netlink to emit that placeholder as a firmware version string. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203124928.4871= 6-1-zhang.yanze@zte.com.cn?part=3D5