All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xin Tian" <tianx@yunsilicon.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH 01/15] yunsilicon: add PCI core driver skeleton
Date: Tue, 13 Oct 2026 11:46:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-169646@kernel.org> (raw)
In-Reply-To: <20261012114352.2471317-2-tianx@yunsilicon.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] mm: invalid kfree() on memory allocated with kvzalloc_obj()
- [High] hw: endian-dependent C bitfields in hardware descriptors corrupt data
- [High] hw: native host-endian types used in hardware DMA structures
- [High] hw: implicit compiler padding corrupts hardware command layouts
- [Medium] pci: missing dma_set_mask() forces 32-bit streaming DMA fallback
--

commit 2f6b2de0263e58c06ddcb030ee0e72ee0f685f39
Author: Xin Tian <tianx@yunsilicon.com>
Subject: yunsilicon: add PCI core driver skeleton

This commit adds the basic PCI core driver for the Yunsilicon XSC network
device. It includes Kconfig, Makefiles, register definitions, and basic PCI
probe/remove routines that enable the device and allocate the per-function
resource structure.

[Severity: High]
In drivers/net/ethernet/yunsilicon/xsc/pci/main.c, inside xsc_dev_res_init()
around line 105, xdev->dev_res is allocated using kvzalloc_obj(). However,
in xsc_dev_res_cleanup() at line 118, the memory is freed using kfree()
instead of kvfree(). Does this code potentially cause a kernel panic or SLUB
corruption during driver unbind or probe failure? If kvmalloc() falls back to
a vmalloc address because physically contiguous memory is unavailable, calling
kfree() on it violates the allocator API.

[Severity: Medium]
In drivers/net/ethernet/yunsilicon/xsc/pci/main.c within xsc_set_dma_caps()
at line 22, the code configures a 64-bit mask for coherent allocations via
dma_set_coherent_mask(), but omits dma_set_mask() for the streaming DMA mask.
Is the streaming DMA mask intentionally left at the 32-bit default? By not
setting it, all network packet buffers mapped via dma_map_single() or
dma_map_page() will be restricted to the lower 4GB of physical RAM. On 64-bit
systems with more than 4GB of RAM, this forces the networking stack to bounce
all network traffic through the SWIOTLB, which can cause massive performance
degradation and potential silent allocation failures if the SWIOTLB is
exhausted.

[Severity: High]
In drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h (for xsc_cqe at line
242, and xsc_send_wqe_ctrl_seg at line 99) and xsc_cmdq.h (for
xsc_cmd_layout at line 113), hardware descriptors mapped to device DMA memory
define C bitfields using types like __le32 and u8. Will these hardware
descriptor layouts break on big-endian architectures? The C standard dictates
that bitfield packing order is implementation-defined. On little-endian
systems, GCC packs bits from LSB to MSB, but on big-endian systems, from MSB
to LSB. Furthermore, mixing types like u8 and __le32 in bitfields causes
compiler-dependent alignment padding that bloats structural sizes. Compiling
this driver on a big-endian system might result in malformed commands and
silent data corruption. Fixed-size types with bitwise masks should likely be
used instead.

[Severity: High]
In drivers/net/ethernet/yunsilicon/xsc/common/xsc_cmd.h, several structures
passed to or read from the hardware via DMA or mailbox commands define fields
using native host types. For example, xsc_cq_context_ex uses u32 pa_num_ex
at line 196, xsc_event_linkinfo uses u32 and u64 for linkspeed and supported
at line 863, and xsc_hw_stats_rdma_pf uses u64 for statistics at line 927.
Can this cause data corruption on big-endian hosts? Hardware devices operate
with a fixed endianness, and using native host types will cause the CPU on
big-endian hosts to read or write the bytes without swapping them, producing
incorrect values. All fields in DMA-shared structures typically need explicit
__le32/__le64 or __be32/__be64 types.

[Severity: High]
Also in drivers/net/ethernet/yunsilicon/xsc/common/xsc_cmd.h, missing packed
attributes or explicit manual padding creates implicit holes in hardware
command and configuration structures. For instance, in struct xsc_hca_cap,
__be64 flags requires 8-byte alignment but follows u8 rsvd16[2], resulting in
6 bytes of implicit padding. In struct xsc_create_qp_request at line 313,
__be64 pas[] forces 4 bytes of padding after u8 rsvd. In struct xsc_rss_attr
at line 782, __be32 hash_tmpl forces 2 bytes of padding after __be16 rqn_num.
Does this implicit compiler padding misalign the hardware command layouts?
This padding shifts all subsequent fields transmitted to and from the
hardware, potentially corrupting the mailbox commands and breaking the ABI
contract with the firmware.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012114352.2471317-1-tianx@yunsilicon.com?part=1

  reply	other threads:[~2026-10-13 11:46 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 11:44 [PATCH 00/15] Yunsilicon ethernet and RDMA drivers Xin Tian
2026-10-12 11:43 ` [PATCH 01/15] yunsilicon: add PCI core driver skeleton Xin Tian
2026-10-13 11:46   ` sashiko-bot [this message]
2026-10-12 11:43 ` [PATCH 02/15] yunsilicon: add the register HAL Xin Tian
2026-10-12 15:21   ` Andrew Lunn
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:43 ` [PATCH 03/15] yunsilicon: add the command queue Xin Tian
2026-10-13  3:11   ` Junxian Huang
2026-10-13 14:31     ` Leon Romanovsky
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 04/15] yunsilicon: add event queues, interrupts and the Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 05/15] yunsilicon: add the CQ and QP resource pools Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 06/15] yunsilicon: add ethernet netdev registration Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 07/15] yunsilicon: add ethernet TX path Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 08/15] yunsilicon: add ethernet RX path and statistics Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 09/15] yunsilicon: add RDMA device support Xin Tian
2026-10-13  6:17   ` Junxian Huang
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 10/15] yunsilicon: add RDMA PD/MR Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 11/15] yunsilicon: add RDMA CQ/SRQ/AH Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 12/15] yunsilicon: add RDMA QP verbs Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 13/15] yunsilicon: add the RDMA send path Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 14/15] yunsilicon: add RDMA counters and sysfs Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 15/15] MAINTAINERS: add the Yunsilicon XSC drivers Xin Tian
2026-10-13 14:34 ` [PATCH 00/15] Yunsilicon ethernet and RDMA drivers Leon Romanovsky

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-169646@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tianx@yunsilicon.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.