Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yanze Zhang" <zhang.yanze@zte.com.cn>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma v10 7/7] RDMA/zrdma: Implement context, PD, and mmap operations
Date: Thu, 03 Dec 2026 13:42:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-247876@kernel.org> (raw)
In-Reply-To: <20261203124928.48716-8-zhang.yanze@zte.com.cn>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] RDMA/zrdma: missing disassociate_ucontext hangs device removal
- [Medium] RDMA/zrdma: outlen < sizeof(uresp) breaks V1/V2 ucontext and
  UAPI growth
- [Medium] RDMA/zrdma: unratelimited pr_err() reachable from userspace
  verbs
- [Medium] RDMA/zrdma: zxdh_alloc_ucontext() reports unimplemented flags
  and zero limits
- [Medium] RDMA/zrdma: zxdh_mmap() exposes adjacent BAR 0 MMIO on >4K
  PAGE_SIZE
- [Low] RDMA/zrdma: missing zero check on reserved fields in
  zxdh_alloc_ucontext()
--

commit ea4f0663a81787280ffe1f1f535dd9dec3ffd022
Author: Yanze Zhang <zhang.yanze@zte.com.cn>

RDMA/zrdma: Implement context, PD, and mmap operations

This patch implements Protection Domain (PD) allocation and deallocation,
user context allocation and deallocation, and doorbell mmap support for
the zrdma driver.

> diff --git a/drivers/infiniband/hw/zrdma/zrdma_verbs.c b/drivers/infiniband/hw/zrdma/zrdma_verbs.c
> index a410ef4521ad5..fb33bf1bde615 100644
> --- a/drivers/infiniband/hw/zrdma/zrdma_verbs.c
> +++ b/drivers/infiniband/hw/zrdma/zrdma_verbs.c

[ ... ]

> +	err = zxdh_alloc_rsrc(rf, rf->allocated_pds, rf->max_pd, &pd_id,
> +			      &rf->next_pd, "PD");
> +	if (err) {
> +		pr_warn_ratelimited("zrdma: PD allocation failed err=%d\n",
> +				    err);
> +		return err;
> +	}

[Severity: Medium]
Can an unprivileged user flood the kernel log here once the PD pool is
exhausted?

zxdh_alloc_pd() ratelimits its own warning, but zxdh_alloc_rsrc() emits an
unratelimited pr_err() on every failed allocation.  The error paths in
zxdh_alloc_ucontext() (when srq_db_mmap_entry is NULL) and zxdh_mmap()
(when rdma_user_mmap_io() fails) also call unratelimited pr_err() despite
neighboring checks using pr_err_ratelimited().

[ ... ]

> +static int zxdh_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata *udata)
> +{
> +	struct zxdh_ucontext *ucontext = to_ucontext(uctx);
> +	struct zxdh_alloc_ucontext_resp uresp = {};
> +	struct ib_device *ibdev = uctx->device;
> +	struct zxdh_device *zdev = to_zdev(ibdev);
> +	struct zxdh_alloc_ucontext_req req = {};
> +	u64 srq_db_mmap_size;
> +	int err;
> +
> +	/* The request is validated against the size of the structure, so
> +	 * that a truncated or an oversized buffer is rejected instead of
> +	 * being read partially.
> +	 */
> +	err = ib_copy_validate_udata_in(udata, req, rsvd8);
> +	if (err)
> +		return err;

[Severity: Low]
Should zxdh_alloc_ucontext() reject non-zero values in req.rsvd32 and
req.rsvd8?

ib_copy_validate_udata_in() only checks trailing bytes beyond sizeof(req),
not reserved fields inside the struct.  Allowing uninitialized bytes in
these fields will prevent repurposing them in future ABI revisions without
breaking userspace.

[ ... ]

> +	/* The response carries the keys of the doorbell mappings, so the
> +	 * user has to provide a buffer for the whole of it. A short buffer
> +	 * is reported instead of being silently truncated.
> +	 */
> +	if (udata->outlen < sizeof(uresp))
> +		return -ENOSPC;

[Severity: Medium]
Does this sizeof(uresp) check break V1 and V2 userspace contexts and
future response extensions?

struct zxdh_alloc_ucontext_resp notes that V1 and V2 contexts do not have
the trailing srq_db_mmap_size field, and zxdh_alloc_ucontext() later maps
only PAGE_SIZE for them, yet this check rejects any response buffer shorter
than the full V3 struct with -ENOSPC.  Both zxdh_alloc_ucontext() and
zxdh_alloc_pd() check udata->outlen against sizeof(uresp) instead of a
fixed offsetofend() minimum, which also prevents extending either response
struct without breaking existing userspace.

[ ... ]

> +	uresp.rdma_tool_flags =
> +		ZXDH_QP_EXTEND_OP | ZXDH_CAPTURE | ZXDH_GET_HW_DATA |
> +		ZXDH_GET_HW_OBJECT_DATA | ZXDH_CHECK_HW_HEALTH |
> +		ZXDH_RDMA_TOOL_CFG_DEV_PARAM | ZXDH_RDMA_TOOL_READ_RAM |
> +		ZXDH_RDMA_TOOL_DEVX_MODIFY_CQ | ZXDH_RDMA_SET_CREDIT_CAP |
> +		ZXDH_RDMA_SWITCH | ZXDH_RDMA_TOOL_DEVX_EXT_MEM |
> +		ZXDH_RDMA_TOOL_PRIV_EXT |
> +		ZXDH_RDMA_TOOL_IOVA_CAP;
> +
> +	uresp.feature_flags = ZXDH_FEATURE_RTS_AE | ZXDH_FEATURE_CQ_RESIZE |
> +			      ZXDH_FEATURE_64_BYTE_CQE;

[Severity: Medium]
Why does zxdh_alloc_ucontext() advertise tool and feature flags for
operations that are not implemented?

None of the DEVX/tool ioctls or CQ/QP verbs (such as resize_cq) exist in
zxdh_dev_ops or driver_def, which contradicts zxdh_query_device()'s policy
of reporting only implemented capabilities and breaks userspace feature
discovery once these bits are shipped.  The ZXDH_FEATURE_* constants are
also only in private zrdma_defs.h rather than the UAPI header, and the
documented max_pds, max_qps, and wq_size response fields are always left
zero.

[ ... ]

> +	pfn = (entry->bar_offset +
> +	       pci_resource_start(ucontext->zdev->rf->pcidev, 0)) >>
> +	      PAGE_SHIFT;
> +
> +	switch (entry->mmap_flag) {
> +	case ZXDH_MMAP_IO_NC:
> +		ret = rdma_user_mmap_io(context, vma, pfn, PAGE_SIZE,
> +					pgprot_noncached(vma->vm_page_prot),
> +					rdma_entry);
> +		break;
> +	case ZXDH_MMAP_IO_NC_BY_SIZE:
> +		ret = rdma_user_mmap_io(context, vma, pfn,
> +					vma->vm_end - vma->vm_start,
> +					pgprot_noncached(vma->vm_page_prot),
> +					rdma_entry);
> +		break;

[Severity: Medium]
Can this expose adjacent BAR 0 registers read/write to unprivileged
userspace on 16K or 64K PAGE_SIZE kernels?

CQ_DB_BAR_OFF (0x43000), SQ_DB_BAR_OFF (0x4c000), and SRQ_DB_BAR_OFF
(0x62000) are only 4K-aligned, so shifting down by PAGE_SHIFT and mapping
full host pages exposes up to 40 KB (16K pages) or 120 KB (64K pages) of
surrounding BAR 0 MMIO space via /dev/infiniband/uverbsX.  Unless hardware
guarantees 64K isolation around those doorbell regions, consider rejecting
PAGE_SIZE > SZ_4K or gating non-4K mappings behind capable(CAP_SYS_RAWIO).

[ ... ]

>  const struct ib_device_ops zxdh_dev_ops = {
>  	.owner = THIS_MODULE,
>  	.driver_id = RDMA_DRIVER_ZRDMA,
>  	.uverbs_abi_ver = ZXDH_ABI_VER,
>  	.dealloc_driver = zxdh_ib_dealloc_device,
> +	.alloc_pd = zxdh_alloc_pd,
> +	.alloc_ucontext = zxdh_alloc_ucontext,
> +	.dealloc_pd = zxdh_dealloc_pd,
> +	.dealloc_ucontext = zxdh_dealloc_ucontext,
>  	.query_device = zxdh_query_device,
>  	.query_port = zxdh_query_port,
>  	.query_pkey = zxdh_query_pkey,
>  	.get_link_layer = zxdh_get_link_layer,
>  	.get_port_immutable = zxdh_roce_port_immutable,
>  	.get_dev_fw_str = zxdh_get_dev_fw_str,
> +	.mmap = zxdh_mmap,
> +	.mmap_free = zxdh_mmap_free,
> +
> +	INIT_RDMA_OBJ_SIZE(ib_pd, zxdh_pd, ibpd),
> +	INIT_RDMA_OBJ_SIZE(ib_ucontext, zxdh_ucontext, ibucontext),
>  };

[Severity: High]
Will omitting .disassociate_ucontext hang device removal whenever a
userspace client holds a uverbs fd open?

When .disassociate_ucontext is NULL, ib_uverbs_remove_one() skips
ib_uverbs_free_hw_resources() and blocks indefinitely in
wait_for_completion(&uverbs_dev->comp), wedging zxdh_remove() during PF
reset, unbind, or PCI hot-unplug while leaving live BAR 0 MMIO mappings
un-zapped.  It also causes ib_device_set_netns_put() to reject network
namespace moves with -EOPNOTSUPP.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203124928.48716-1-zhang.yanze@zte.com.cn?part=7

      reply	other threads:[~2026-12-03 13:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 12:49 [PATCH rdma v10 0/7] Add ZTE DingHai Ethernet Protocol Driver for RDMA Yanze Zhang
2026-12-03 12:49 ` [PATCH rdma v10 1/7] RDMA/zrdma: Add build infrastructure and module skeleton Yanze Zhang
2026-12-03 13:19   ` sashiko-bot
2026-12-03 12:49 ` [PATCH rdma v10 2/7] RDMA/zrdma: Add core data structures and ABI definitions Yanze Zhang
2026-12-03 13:21   ` sashiko-bot
2026-12-03 12:49 ` [PATCH rdma v10 3/7] RDMA/zrdma: Add internal headers and hardware register definitions Yanze Zhang
2026-12-03 13:17   ` sashiko-bot
2026-12-03 12:49 ` [PATCH rdma v10 4/7] RDMA/zrdma: Add hardware resource initialization and verbs skeleton Yanze Zhang
2026-12-03 13:20   ` sashiko-bot
2026-12-03 12:49 ` [PATCH rdma v10 5/7] RDMA/zrdma: Implement device and port query operations Yanze Zhang
2026-12-03 13:32   ` sashiko-bot
2026-12-03 12:49 ` [PATCH rdma v10 6/7] RDMA/zrdma: Add device probe and remove logic Yanze Zhang
2026-12-03 13:28   ` sashiko-bot
2026-12-03 12:49 ` [PATCH rdma v10 7/7] RDMA/zrdma: Implement context, PD, and mmap operations Yanze Zhang
2026-12-03 13:42   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-247876@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhang.yanze@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox