Bug 298485 - fc0a5ae09430 (linuxkpi device_add) hides class sysctl nodes, breaking all InfiniBand/RoCE userspace: ibv_devices/ibv_devinfo find no devices
Summary: fc0a5ae09430 (linuxkpi device_add) hides class sysctl nodes, breaking all Inf...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: Bjoern A. Zeeb
URL:
Keywords: regression, vendor
Depends on:
Blocks:
 
Reported: 2026-09-14 12:55 UTC by Ariel Ehrenberg
Modified: 2026-09-14 20:01 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ariel Ehrenberg 2026-09-14 12:55:05 UTC
OVERVIEW
Commit fc0a5ae09430 ("linuxkpi: Add device under parent, not under class")
changes LinuxKPI device_add() to register a device's kobject under
dev->parent instead of dev->class when a parent is set. 
On FreeBSD the sysfs emulation is sysctl-backed and has no symlinks, so this does not *add* a hierarchy view, it removes the class view. Any consumer that looks devices up by class stops finding them.
This silently breaks the entire InfiniBand/RoCE userspace. ibv_devices and
ibv_devinfo report no devices on a fully functional adapter.
I have confirmed the cause by reverting only this commit. Details under VALIDATION below.

AFFECTED VERSIONS
  Bad:  main-n289089-e46a7d842a75  (built 2026-09-12)  -- fails
  Good: main-n287270-3e3752ce73b7  (built 2026-07-07)  -- works

SYMPTOMS
  # ibv_devices
      device            node GUID
      ------            ----------------
                                          <- empty list, exit status 0
  # ibv_devinfo
  No IB devices found

THE KERNEL SIDE IS HEALTHY
All four adapters attach, mlx5ib registers four IB devices, and the
character devices are present:
  /dev/uverbs0 /dev/uverbs1 /dev/uverbs2 /dev/uverbs3
  /dev/umad0 /dev/umad1 /dev/umad2 /dev/umad3
  /dev/rdma_cm

ROOT CAUSE
FreeBSD's libibverbs has no sysfs. ibv_read_sysfs_file() in
contrib/ofed/libibverbs/sysfs.c translates a sysfs path into a sysctl name
by replacing '/' with '.':
    for (s = &path[0]; *s != '\0'; s++)
            if (*s == '/')
                    *s = '.';
    ret = sysctlbyname(&path[1], buf, &len, NULL, 0);
Device discovery in find_sysfs_devs() (contrib/ofed/libibverbs/init.c)
iterates uverbs0..255 and reads
<sysfs>/class/infiniband_verbs/uverbsN/ibdev, i.e. sysctl
sys.class.infiniband_verbs.uverbsN.ibdev. Enumeration therefore depends
entirely on the CLASS view of the tree.

VALIDATION
Reversing only this commit's own hunk with 'git apply -R', rebuilding and
reloading restores full functionality.

REPRODUCTION
On an affected main system with any RDMA-capable adapter:
  kldload mlx5ib                    # pulls in ibcore
  ibv_devices                       # empty list, exit status 0
  sysctl -N sys.class.infiniband_verbs sys.class.infiniband
  sysctl -n sys.device.mlx5_core0.uverbs0.ibdev   # -> mlx5_0, misplaced node
  sysctl -n sys.class.infiniband_mad.umad0.ibdev  # -> mlx5_0, still correct
WORKAROUND
Boot a kernel predating 2026-09-09, or revert fc0a5ae09430 and rebuild both
linuxkpi.ko and ibcore.ko. There is no userspace workaround: libibverbs
honours the SYSFS_PATH environment variable, but the "class/infiniband_verbs"
path component is hardcoded, so the class subtree cannot be redirected.

SUGGESTED DIRECTION
The DRM motivation for the change is legitimate, so a plain revert is
probably not wanted. Options, roughly in order of preference:
 1. Have device_add() register into BOTH hierarchies when dev->class !=
    NULL -- the parent for the device tree plus an entry under the class --
    emulating what the Linux symlink provides and matching existing
    device_register() behaviour.
 2. Keep parent-based placement but make it opt-in for the DRM case, so
    existing class-based consumers are untouched.
 3. Fix ibcore to register under its class explicitly. This works but leaves
    the device_add()/device_register() inconsistency in place, and any
    future LinuxKPI driver that sets dev->parent hits the same trap.
It would also be worth auditing other LinuxKPI consumers that set
dev->parent and whose userspace looks devices up by class.
ENVIRONMENT
  # uname -a
  FreeBSD 16.0-CURRENT #139 main-n289089-e46a7d842a75:
  Sat Sep 12 16:10:10 IDT 2026 amd64
  uname -K: 1600025    uname -U: 1600013
Hardware: Dell PowerEdge R760, 4x Mellanox ConnectX-7, firmware 28.51.0256,
ports in Ethernet (RoCE) mode.
  # pciconf -lv | grep -A2 '^mlx5_core'
  mlx5_core0@pci0:97:0:0:  class=0x020000 vendor=0x15b3 device=0x1021
      vendor = 'Mellanox Technologies'
      device = 'MT2910 Family [ConnectX-7]'
  mlx5_core1@pci0:97:0:1:  (same)
  mlx5_core2@pci0:160:0:0: (same)
  mlx5_core3@pci0:160:0:1: (same)
Kernel configuration (sys/amd64/conf/LATEST):
  include GENERIC
  ident  LATEST
  nooptions  COMPAT_LINUXKPI
  nodevice  mlx5
  nodevice  mlxfw
  nodevice  mlx5en
  options  IPSEC_OFFLOAD
  include ../../conf/std.nodebug
Relevant dmesg (normal, shown to demonstrate the kernel side is fine):
  mlx5_core0: <mlx5_core> mem 0x25fff8000000-0x25fff9ffffff at device 0.0
      numa-domain 0 on pci11
  mlx5: Mellanox Core driver 3.7.1 (November 2021)
  mlx5_core0: INFO: mlx5_port_module_event: Module 0, status: plugged and
      enabled
  mlx5_core: INFO: (mlx5_core0): E-Switch: Total vports 17
Comment 1 Bjoern A. Zeeb freebsd_committer freebsd_triage 2026-09-14 17:05:43 UTC
dumbbell, seems there are consumers we did not think of.
Probably good to back it out with a reference to the PR and add a comment that it's used by IB userspace.
Comment 2 Bjoern A. Zeeb freebsd_committer freebsd_triage 2026-09-14 18:51:32 UTC
Actually let me take it I have more stuff in my commit pile already so I can just push the revert.
Comment 3 Jean-Sébastien Pédron freebsd_committer freebsd_triage 2026-09-14 19:42:39 UTC
I’m ok to revert the change for now to unbreak this use case. I can run it locally only.
Comment 4 commit-hook freebsd_committer freebsd_triage 2026-09-14 19:49:12 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=b0094b5b7320fc40ca581f9ac7c52514ddb5c2cb

commit b0094b5b7320fc40ca581f9ac7c52514ddb5c2cb
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2026-09-14 18:51:51 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-09-14 19:06:01 +0000

    Revert "linuxkpi: Add device under parent, not under class"

    This reverts commit fc0a5ae094308609927e9c355928d08923278325.

    This changed the sysctl node path and broke IB user space tools (ibv_*).

    PR:     298485
    Reported by:     Ariel Ehrenberg (aehrenberg nvidia.com)

 sys/compat/linuxkpi/common/include/linux/device.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Comment 5 Bjoern A. Zeeb freebsd_committer freebsd_triage 2026-09-14 20:01:43 UTC
(In reply to Jean-Sébastien Pédron from comment #3)

I think the more and more we hit this, someone should write a proper sysfs implementation and all the troubles go away (just seeding the idea further beyond Phabricator).


Ariel:  thanks a lot for reporting!