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 3/7] RDMA/zrdma: Add internal headers and hardware register definitions
Date: Thu, 03 Dec 2026 13:17:46 +0000	[thread overview]
Message-ID: <sashiko-outbox-247840@kernel.org> (raw)
In-Reply-To: <20261203124928.48716-4-zhang.yanze@zte.com.cn>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] RDMA/zrdma: private duplication of DingHai PF auxiliary
  device structures
- [Medium] RDMA/zrdma: unratelimited pr_err() on pool exhaustion in
  zxdh_alloc_rsrc()
- [Medium] RDMA/zrdma: redundant double bitmap scan under IRQ lock in
  zxdh_alloc_rsrc()
- [Low] RDMA/zrdma: custom bitmap allocator in zxdh_alloc_rsrc()
  duplicates IDA
- [Low] RDMA/zrdma: inaccurate commit message and unused include in
  zrdma_hw.h
--

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

RDMA/zrdma: Add internal headers and hardware register definitions

This commit adds zrdma_hw.h and zrdma_main.h with resource capacity limits,
driver state structures, and inline resource bitmap helpers, and adds a
comment to zrdma_type.h describing the auxiliary device layout.

> diff --git a/drivers/infiniband/hw/zrdma/zrdma_hw.h b/drivers/infiniband/hw/zrdma/zrdma_hw.h
> new file mode 100644
> index 0000000000000..16c5041ac0757
> --- /dev/null
> +++ b/drivers/infiniband/hw/zrdma/zrdma_hw.h
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
> + *
> + * ZTE DingHai Rdma driver
> + * Copyright (c) 2022-2026, ZTE Corporation
> + */
> +
> +#ifndef ZRDMA_HW_H
> +#define ZRDMA_HW_H
> +#include "zrdma_main.h"
> +
> +#define ZXDH_MAX_CQE 0x200000
> +#define ZXDH_MAX_QP 0x4000
> +#define ZXDH_MAX_MR 0x10000
> +#define ZXDH_MAX_CQ 0x4000
> +#define ZXDH_MAX_SRQ 0x2000
> +#define ZXDH_MAX_PD 0x100000
> +#define ZXDH_MAX_AH 0x10000
> +#define ZXDH_MAX_MCG 0x4000
> +#define ZXDH_MAX_8K_IDX 0x1c0
> +
> +#endif /* ZRDMA_HW_H */

[Severity: Low]
Does zrdma_hw.h need to include zrdma_main.h?  It references nothing from
zrdma_main.h, and pulling it in here prevents zrdma_main.h from including
zrdma_hw.h without a circular include.

Also, the commit subject and message state that this adds hardware register
definitions, whereas zrdma_hw.h only defines ZXDH_MAX_* resource capacity
limits and the message does not mention the comment added to zrdma_type.h.

> diff --git a/drivers/infiniband/hw/zrdma/zrdma_main.h b/drivers/infiniband/hw/zrdma/zrdma_main.h
> new file mode 100644
> index 0000000000000..d65811735e74e
> --- /dev/null
> +++ b/drivers/infiniband/hw/zrdma/zrdma_main.h
> @@ -0,0 +1,177 @@

[ ... ]

> +	unsigned long *allocated_qps;
> +	unsigned long *allocated_cqs;
> +	unsigned long *allocated_mrs;
> +	unsigned long *allocated_pds;
> +	unsigned long *allocated_mcgs;
> +	unsigned long *allocated_ahs;
> +	unsigned long *allocated_srqs;
> +	unsigned long *allocated_pris;
> +	unsigned long *allocated_8k_idx;

[Severity: Low]
Can these nine resource bitmaps and zxdh_alloc_rsrc()/zxdh_free_rsrc() use
struct ida or XArray instead of a custom bitmap allocator?  Per-pool IDA
avoids allocating 128 KiB upfront for allocated_pds (ZXDH_MAX_PD) when few
PDs are used and removes cross-pool contention on rsrc_lock.

In zxdh_alloc_rsrc(), scoped_guard(spinlock_irqsave, &rf->rsrc_lock) would
also avoid the bare compound block around guard(), and -ENOSPC or -ENOMEM
would fit pool exhaustion better than -EOVERFLOW.

[ ... ]

> +static inline int zxdh_alloc_rsrc(struct zxdh_pci_f *rf,
> +				  unsigned long *rsrc_array, u32 max_rsrc,
> +				  u32 *req_rsrc_num, u32 *next,
> +				  const char *rsrc_name)
> +{

[ ... ]

> +	{
> +		guard(spinlock_irqsave)(&rf->rsrc_lock);
> +
> +		rsrc_num = find_next_zero_bit(rsrc_array, max_rsrc, *next);
> +		if (rsrc_num >= max_rsrc)
> +			rsrc_num = find_first_zero_bit(rsrc_array, max_rsrc);

[Severity: Medium]
Why does the wrap-around call to find_first_zero_bit() scan up to max_rsrc
instead of *next?  Since rf->rsrc_lock is held across both calls, the range
[*next, max_rsrc) is still all-ones and is scanned twice.

For a full PD pool (ZXDH_MAX_PD = 0x100000, a 128 KiB bitmap), this scans up
to 256 KiB with local IRQs disabled while stalling zxdh_free_rsrc() and all
other pools sharing rf->rsrc_lock.  Bounding the second scan to
min(*next, max_rsrc) would avoid the redundant pass.

[ ... ]

> +	if (ret)
> +		pr_err("zrdma: %s pool exhausted (capacity %u)\n",
> +		       rsrc_name, max_rsrc);

[Severity: Medium]
Can userspace flood the kernel log through this unratelimited pr_err()?
Once a pool is full, repeated allocation requests from /dev/infiniband/uverbs
will emit an unbounded stream of error messages without device context.

Using ibdev_dbg() (as irdma_alloc_rsrc() does) or ibdev_err_ratelimited(),
or leaving logging to the callers, would prevent log flooding.

> diff --git a/drivers/infiniband/hw/zrdma/zrdma_type.h b/drivers/infiniband/hw/zrdma/zrdma_type.h
> index ded4052453455..c6ad2be17c159 100644
> --- a/drivers/infiniband/hw/zrdma/zrdma_type.h
> +++ b/drivers/infiniband/hw/zrdma/zrdma_type.h
> @@ -21,6 +21,12 @@ enum zxdh_function_type {
>  	ZXDH_FUNCTION_TYPE_VF,
>  };
>  
> +/*
> + * The structures below describe the auxiliary device of the DingHai PF
> + * driver. Their layout has to match the definition of the PF driver
> + * exactly, because the probe path reads them through the auxiliary device
> + * that the PF driver provides.
> + */
>  struct zxdh_rdma_core_dev;

[Severity: Medium]
Should struct zxdh_auxiliary_dev and struct zxdh_rdma_core_dev live in a
shared header under include/linux/ instead of being duplicated here?  Private
copies drop compile-time layout checks across modules, so any PF struct change
or CONFIG_RANDSTRUCT corrupts memory on container_of() in probe.

This also breaks the rule in include/linux/auxiliary_bus.h that the parent
wrapper and shared objects live in a shared header, and the in-tree DingHai
PF driver (drivers/net/ethernet/zte/dinghai/en_pf.c) neither defines these
structures nor registers an auxiliary device.

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

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

Thread overview: 14+ 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 [this message]
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

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-247840@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