Skip to content

Commit

Permalink
fwctl/mlx5: Support for communicating with mlx5 fw
Browse files Browse the repository at this point in the history
mlx5 FW has a built in security context called UID. Each UID has a set of
permissions controlled by the kernel when it is created and every command
is tagged by the kernel with a particular UID. In general commands cannot
reach objects outside of their UID and commands cannot exceed their UID's
permissions. These restrictions are enforced by FW.

This mechanism has long been used in RDMA for the devx interface where
RDMA will sent commands directly to the FW and the UID limitations
restrict those commands to a ib_device/verbs security domain. For instance
commands that would effect other VFs, or global device resources. The
model is suitable for unprivileged userspace to operate the RDMA
functionality.

The UID has been extended with a "tools resources" permission which allows
additional commands and sub-commands that are intended to match with the
scope limitations set in FWCTL. This is an alternative design to the
"command intent log" where the FW does the enforcement rather than having
the FW report the enforcement the kernel should do.

Consistent with the fwctl definitions the "tools resources" security
context is limited to the FWCTL_RPC_CONFIGURATION,
FWCTL_RPC_DEBUG_READ_ONLY, FWCTL_RPC_DEBUG_WRITE, and
FWCTL_RPC_DEBUG_WRITE_FULL security scopes.

Like RDMA devx, each opened fwctl file descriptor will get a unique UID
associated with each file descriptor.

The fwctl driver is kept simple and we reject commands that can create
objects as the UID mechanism relies on the kernel to track and destroy
objects prior to detroying the UID. Filtering into fwctl sub scopes is
done inside the driver with a switch statement. This substantially limits
what is possible to primarily query functions ad a few limited set
operations.

mlx5 already has a robust infrastructure for delivering RPC messages to
fw. Trivially connect fwctl's RPC mechanism to mlx5_cmd_do(). Enforce the
User Context ID in every RPC header accepted from the FD so the FW knows
the security context of the issuing ID.

Link: https://patch.msgid.link/r/7-v5-642aa0c94070+4447f-fwctl_jgg@nvidia.com
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
  • Loading branch information
Saeed Mahameed authored and Jason Gunthorpe committed Mar 6, 2025
1 parent 18285ac commit 52929c2
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 0 deletions.
1 change: 1 addition & 0 deletions Documentation/userspace-api/fwctl/fwctl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fwctl User API
==============

.. kernel-doc:: include/uapi/fwctl/fwctl.h
.. kernel-doc:: include/uapi/fwctl/mlx5.h

sysfs Class
-----------
Expand Down
7 changes: 7 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -9568,6 +9568,13 @@ F: drivers/fwctl/
F: include/linux/fwctl.h
F: include/uapi/fwctl/

FWCTL MLX5 DRIVER
M: Saeed Mahameed <saeedm@nvidia.com>
R: Itay Avraham <itayavr@nvidia.com>
L: linux-kernel@vger.kernel.org
S: Maintained
F: drivers/fwctl/mlx5/

GALAXYCORE GC0308 CAMERA SENSOR DRIVER
M: Sebastian Reichel <sre@kernel.org>
L: linux-media@vger.kernel.org
Expand Down
14 changes: 14 additions & 0 deletions drivers/fwctl/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ menuconfig FWCTL
support a wide range of lockdown compatible device behaviors including
manipulating device FLASH, debugging, and other activities that don't
fit neatly into an existing subsystem.

if FWCTL
config FWCTL_MLX5
tristate "mlx5 ConnectX control fwctl driver"
depends on MLX5_CORE
help
MLX5 provides interface for the user process to access the debug and
configuration registers of the ConnectX hardware family
(NICs, PCI switches and SmartNIC SoCs).
This will allow configuration and debug tools to work out of the box on
mainstream kernel.

If you don't know what to do here, say N.
endif
1 change: 1 addition & 0 deletions drivers/fwctl/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_FWCTL) += fwctl.o
obj-$(CONFIG_FWCTL_MLX5) += mlx5/

fwctl-y += main.o
4 changes: 4 additions & 0 deletions drivers/fwctl/mlx5/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_FWCTL_MLX5) += mlx5_fwctl.o

mlx5_fwctl-y += main.o
Loading

0 comments on commit 52929c2

Please sign in to comment.