dlb2: introduce DLB 2.0 device driver
Subsystems (3)
cover dlb2: introduce DLB 2.0 device driver
This commit introduces a new misc device driver for the Intel(r) Dynamic Load Balancer 2.0 (Intel(r) DLB 2.0). The Intel DLB 2.0 is a PCIe device that provides load-balanced, prioritized scheduling of core-to-core communication.
The Intel DLB 2.0 consists of queues and arbiters that connect producer cores and consumer cores. The device implements load-balanced queueing features including:
- Lock-free multi-producer/multi-consumer operation.
- Multiple priority levels for varying traffic types.
- 'Direct' traffic (i.e. multi-producer/single-consumer)
- Simple unordered load-balanced distribution.
- Atomic lock free load balancing across multiple consumers.
- Queue element reordering feature allowing ordered load-balanced distribution.
Intel DLB 2.0 can be used in an event-driven programming model, such as DPDK's Event Device Library[2]. Such frameworks are commonly used in packet processing pipelines that benefit from the framework's multi-core scalability, dynamic load-balancing, and variety of packet distribution and synchronization schemes.
These distribution schemes include "parallel" (packets are load-balanced across multiple cores and processed in parallel), "ordered" (similar to "parallel" but packets are reordered into ingress order by the device), and "atomic" (packet flows are scheduled to a single core at a time such that locks are not required to access per-flow data, and dynamically migrated to ensure load-balance).
The fundamental unit of communication through the device is a queue entry (QE), which consists of 8B of data and 8B of metadata (destination queue, priority, etc.). The data field can be any type that fits within 8B.
A core's interface to the device, a "port," consists of a memory-mappable region through which the core enqueues a queue entry, and an in-memory queue (the "consumer queue") to which the device schedules QEs. Each QE is enqueued to a device-managed queue, and from there scheduled to a port. Software specifies the "linking" of queues and ports; i.e. which ports the device is allowed to schedule to for a given queue. The device uses a credit scheme to prevent overflow of the on-device queue storage.
Applications can interface directly with the device by mapping the port's memory and MMIO regions into the application's address space for enqueue and dequeue operations, but call into the kernel driver for configuration operations. An application can also be polling- or interrupt-driven; Intel DLB 2.0 supports both modes of operation.
Device resources -- i.e. ports, queues, and credits -- are contained within a scheduling domain. Scheduling domains are isolated from one another; a port can only enqueue to and dequeue from queues within its scheduling domain. A scheduling domain's resources are configured through a scheduling domain file, which is acquired through an ioctl.
Intel DLB 2.0 supports SR-IOV and Scalable IOV, and allows for a flexible division of its resources among the PF and its virtual devices. The virtual devices are incapable of configuring the device directly; they use a hardware mailbox to proxy configuration requests to the PF driver. This driver supports both PF and virtual devices, as there is significant code re-use between the two, with device-specific behavior handled through a callback interface. Virtualization support will be added in a later patch set.
The dlb driver uses ioctls as its primary interface (it makes use of sysfs as well, to a lesser extent). The dlb device file supports a different ioctl interface than the scheduling domain file; the dlb device file is used for device-wide operations (including scheduling domain creation), and the scheduling domain file supports operations on the scheduling domain's resources (primarily resource configuration).
The dlb driver is partially dual-licensed (GPLv2 and BSD 3 clause). The dual-licensed files implement a "hardware access library" that is largely Linux independent (except, for example, kmalloc() and kfree() calls), so that they can be ported to other environments (e.g. DPDK).
[1] https://builders.intel.com/docs/networkbuilders/SKU-343247-001US-queue-management-and-load-balancing-on-intel-architecture.pdf
[2] https://doc.dpdk.org/guides/prog_guide/eventdev.html
Note: This patchset underwent multiple internal reviews and revisions, and those changes include:
- Many style corrections (multi-line comments, header order, etc.)
- Add device and software documentation (dlb2.rst)
- Use dyndbg for debug messages
- Refactor mmap and device file architecture
- Use ida library for ID management
- Fill data structure holes
- Add missing static keyword for various functions
- Various bug fixes
Gage Eads (20):
dlb2: add skeleton for DLB 2.0 driver
dlb2: initialize PF device
dlb2: add resource and device initialization
dlb2: add device ioctl layer and first 4 ioctls
dlb2: add sched domain config and reset support
dlb2: add ioctl to get sched domain fd
dlb2: add runtime power-management support
dlb2: add queue create and queue-depth-get ioctls
dlb2: add ioctl to configure ports, query poll mode
dlb2: add port mmap support
dlb2: add start domain ioctl
dlb2: add queue map and unmap ioctls
dlb2: add port enable/disable ioctls
dlb2: add CQ interrupt support
dlb2: add domain alert support
dlb2: add sequence-number management ioctls
dlb2: add cos bandwidth get/set ioctls
dlb2: add device FLR support
dlb2: add basic PF sysfs interfaces
dlb2: add ingress error handling
Documentation/ABI/testing/sysfs-driver-dlb2 | 202 + Documentation/misc-devices/dlb2.rst | 313 ++ Documentation/misc-devices/index.rst | 1 + MAINTAINERS | 7 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/dlb2/Kconfig | 11 + drivers/misc/dlb2/Makefile | 13 + drivers/misc/dlb2/dlb2_bitmap.h | 286 ++ drivers/misc/dlb2/dlb2_file.c | 133 + drivers/misc/dlb2/dlb2_file.h | 19 + drivers/misc/dlb2/dlb2_hw_types.h | 357 ++ drivers/misc/dlb2/dlb2_intr.c | 140 + drivers/misc/dlb2/dlb2_intr.h | 30 + drivers/misc/dlb2/dlb2_ioctl.c | 1319 +++++ drivers/misc/dlb2/dlb2_ioctl.h | 19 + drivers/misc/dlb2/dlb2_main.c | 1181 +++++ drivers/misc/dlb2/dlb2_main.h | 285 ++ drivers/misc/dlb2/dlb2_pf_ops.c | 1313 +++++ drivers/misc/dlb2/dlb2_regs.h | 3702 ++++++++++++++ drivers/misc/dlb2/dlb2_resource.c | 7119 +++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 924 ++++ include/linux/pci_ids.h | 2 + include/uapi/linux/dlb2_user.h | 1158 +++++ 24 files changed, 18536 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-dlb2 create mode 100644 Documentation/misc-devices/dlb2.rst create mode 100644 drivers/misc/dlb2/Kconfig create mode 100644 drivers/misc/dlb2/Makefile create mode 100644 drivers/misc/dlb2/dlb2_bitmap.h create mode 100644 drivers/misc/dlb2/dlb2_file.c create mode 100644 drivers/misc/dlb2/dlb2_file.h create mode 100644 drivers/misc/dlb2/dlb2_hw_types.h create mode 100644 drivers/misc/dlb2/dlb2_intr.c create mode 100644 drivers/misc/dlb2/dlb2_intr.h create mode 100644 drivers/misc/dlb2/dlb2_ioctl.c create mode 100644 drivers/misc/dlb2/dlb2_ioctl.h create mode 100644 drivers/misc/dlb2/dlb2_main.c create mode 100644 drivers/misc/dlb2/dlb2_main.h create mode 100644 drivers/misc/dlb2/dlb2_pf_ops.c create mode 100644 drivers/misc/dlb2/dlb2_regs.h create mode 100644 drivers/misc/dlb2/dlb2_resource.c create mode 100644 drivers/misc/dlb2/dlb2_resource.h create mode 100644 include/uapi/linux/dlb2_user.h
base-commit: 2d41d2ab85d414f6ea9eac2f853b1aa31ba0820f
Signature · 1 line
2.13.6
PATCH 1/20 dlb2: add skeleton for DLB 2.0 driver
This initial commit contains basic driver functionality (load, unload, probe, and remove callbacks) file_operations stubs, and device documentation as well.
--- Documentation/misc-devices/dlb2.rst | 313 +++++++++++++++++++++++++++++++++++ Documentation/misc-devices/index.rst | 1 + MAINTAINERS | 7 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/dlb2/Kconfig | 11 ++ drivers/misc/dlb2/Makefile | 8 + drivers/misc/dlb2/dlb2_hw_types.h | 29 ++++ drivers/misc/dlb2/dlb2_main.c | 216 ++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_main.h | 37 +++++ include/linux/pci_ids.h | 2 + 11 files changed, 626 insertions(+) create mode 100644 Documentation/misc-devices/dlb2.rst create mode 100644 drivers/misc/dlb2/Kconfig create mode 100644 drivers/misc/dlb2/Makefile create mode 100644 drivers/misc/dlb2/dlb2_hw_types.h create mode 100644 drivers/misc/dlb2/dlb2_main.c create mode 100644 drivers/misc/dlb2/dlb2_main.h
Documentation/misc-devices/dlb2.rst new file +313 -0
@@ -0,0 +1,313 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +=========================================== +Intel(R) Dynamic Load Balancer 2.0 Overview +=========================================== + +:Author: Gage Eads + +Contents +======== + +- Introduction +- Scheduling +- Queue Entry +- Port +- Queue +- Credits +- Scheduling Domain +- Interrupts +- Power Management +- Virtualization +- User Interface +- Reset + +Introduction +============ + +The Intel(r) Dynamic Load Balancer 2.0 (Intel(r) DLB 2.0) is a PCIe device that +provides load-balanced, prioritized scheduling of core-to-core communication. + +The Intel DLB 2.0 device consists of queues and arbiters that connect producer +cores and consumer cores. The device implements load-balanced queueing features +including: +- Lock-free multi-producer/multi-consumer operation. +- Multiple priority levels for varying traffic types. +- 'Direct' traffic (i.e. multi-producer/single-consumer) +- Simple unordered load-balanced distribution. +- Atomic lock free load balancing across multiple consumers. +- Queue element reordering feature allowing ordered load-balanced distribution. + +Intel DLB 2.0 can be used in an event-driven programming model, such as DPDK's +Event Device Library[2]. Such frameworks are commonly used in packet processing +pipelines that benefit from the framework's multi-core scalability, dynamic +load-balancing, and variety of packet distribution and synchronization schemes. + +Scheduling Types +================ + +Intel DLB 2.0 supports four types of scheduling of 'events' (using DPDK +terminology), where an event can represent any type of data (e.g. a network +packet). The first, ``directed``, is multi-producer/single-consumer style +core-to-core communication. The remaining three are +multi-producer/multi-consumer, and support load-balancing across the consumers. + +- ``Unordered``: events are load-balanced across consumers without any ordering + guarantees. + +- ``Ordered``: events are load-balanced across consumers, and when the consumer + re-injects each event into the device it is re-ordered into the + original order. This scheduling type allows software to + parallelize ordered event processing without the synchronization + cost of re-ordering packets. + +- ``Atomic``: events are load-balanced across consumers, with the guarantee that + events from a particular 'flow' are only scheduled to a single + consumer at a time (but can migrate over time). This allows, for + example, packet processing applications to parallelize while + avoiding locks on per-flow data and maintaining ordering within a + flow. + +Intel DLB 2.0 provides hierarchical priority scheduling, with eight priority +levels within each. Each consumer selects up to eight queues to receive events +from, and assigns a priority to each of these 'connected' queues. To schedule +an event to a consumer, the device selects the highest priority non-empty queue +of the (up to) eight connected queues. Within that queue, the device selects +the highest priority event available (selecting a lower priority event for +starvation avoidance 1% of the time, by default). + +The device also supports four load-balanced scheduler classes of service. Each +class of service receives a (user-configurable) guaranteed percentage of the +scheduler bandwidth, and any unreserved bandwidth is divided evenly among the +four classes. + +Queue Entry +=========== + +Each event is contained in a queue entry (QE), the fundamental unit of +communication through the device, which consists of 8B of data and 8B of +metadata, as depicted below. + +QE structure format +:: + data :64 + opaque :16 + qid :8 + sched :2 + priority :3 + msg_type :3 + lock_id :16 + rsvd :8 + cmd :8 + +The ``data`` field can be any type that fits within 8B (pointer, integer, +etc.); DLB 2.0 merely copies this field from producer to consumer. The +``opaque`` and ``msg_type`` fields behave the same way. + +``qid`` is set by the producer to specify to which DLB 2.0 queue it wishes to +enqueue this QE. The ID spaces for load-balanced and directed queues are both +zero-based; the ``sched`` field is used to distinguish whether the queue is +load-balanced or directed. + +``sched`` controls the scheduling type: atomic, unordered, ordered, or +directed. The first three scheduling types are only valid for load-balanced +queues, and the directed scheduling type is only valid for directed queues. + +``priority`` is the priority with which this QE should be scheduled. + +``lock_id``, used only by atomic scheduling, identifies the atomic flow to +which the QE belongs. When sending a directed event, ``lock_id`` is simply +copied like the ``data``, ``opaque``, and ``msg_type`` fields. + +``cmd`` specifies the operation, such as: +- Enqueue a new QE +- Forward a QE that was dequeued +- Complete/terminate a QE that was dequeued +- Return one or more consumer queue tokens. +- Arm the port's consumer queue interrupt. + +Port +==== + +A core's interface to the DLB 2.0 is called a "port," and consists of an MMIO +region through which the core enqueues a queue entry, and an in-memory queue +(the "consumer queue") to which the device schedules QEs. A core enqueues a QE +to a device queue, then the device schedules the event to a port. Software +specifies the connection of queues and ports; i.e. for each queue, to which +ports the device is allowed to schedule its events. The device uses a credit +scheme to prevent overflow of the on-device queue storage. + +Applications interface directly with the device by mapping the port's memory +and MMIO regions into the application's address space for enqueue and dequeue +operations, but call into the kernel driver for configuration operations. An +application can also be polling- or interrupt-driven; DLB 2.0 supports both +modes of operation. + +Queue +===== + +The device contains 32 load-balanced (i.e. capable of atomic, ordered, and +unordered scheduling) queues and 64 directed queues. Each queue comprises 8 +internal queues, one per priority level. The internal queue that an event is +enqueued to is selected by the event's priority field. + +A load-balanced queue is capable of scheduling its events to any combination of +load-balanced ports, whereas each directed queue has one-to-one mapping with a +directed port. There is no restriction on port or queue types when a port +enqueues an event to a queue; that is, a load-balanced port can enqueue to a +directed queue and vice versa. + +Credits +======= + +The Intel DLB 2.0 uses a credit scheme to prevent overflow of the on-device +queue storage, with separate credits for load-balanced and directed queues. A +port spends one credit when it enqueues a QE, and one credit is replenished +when a QE is scheduled to a consumer queue. Each scheduling domain has one pool +of load-balanced credits and one pool of directed credits; software is +responsible for managing the allocation and replenishment of these credits among +the scheduling domain's ports. + +Scheduling Domain +================= + +Device resources -- including ports, queues, and credits -- are contained +within a scheduling domain. Scheduling domains are isolated from one another; a +port can only enqueue to and dequeue from queues within its scheduling domain. + +A scheduling domain's resources are configured through a domain file descriptor, +which is acquired through an ioctl. This design means that any application with +sufficient permissions to access the device file can request the fd of any +scheduling domain within that device. When necessary to prevent independent dlb2 +applications from potentially accessing each other's scheduling domains, the +user can create multiple virtual functions (each with its own device file) and +restrict access via file permissions. + +Consumer Queue Interrupts +========================= + +Each port has its own interrupt which fires, if armed, when the consumer queue +depth becomes non-zero. Software arms an interrupt by enqueueing a special +'interrupt arm' command to the device through the port's MMIO window. + +Power Management +================ + +The kernel driver keeps the device in D3Hot when not in use. The driver +transitions the device to D0 when the first device file is opened or a virtual +function is created, and keeps it there until there are no open device files, +memory mappings, or virtual functions. + +Virtualization +============== + +The DLB 2.0 supports both SR-IOV and Scalable IOV, and can flexibly divide its +resources among the physical function (PF) and its virtual devices. Virtual +devices do not configure the device directly; they use a hardware mailbox to +proxy configuration requests to the PF driver. Mailbox communication is +initiated by the virtual device with a registration message that establishes +the mailbox interface version. + +SR-IOV +------ + +Each SR-IOV virtual function (VF) has 32 interrupts, 1 for PF->VF mailbox +messages and the remainder for CQ interrupts. If a VF user (e.g. a guest OS) +needs more CQ interrupts, they have to use more than one VF. + +To support this case, the driver introduces the notion of primary and auxiliary +VFs. A VF is either considered primary or auxiliary: +- Primary: the VF is used as a regular DLB 2.0 device. The primary VF has 0+ + auxiliary VFs supporting it. +- Auxiliary: the VF doesn't have any resources of its own, and serves only to + provide the primary VF with MSI vectors for its CQ interrupts. + +Each VF has an aux_vf_ids file in its sysfs directory, which is a R/W file that +controls the primary VF’s auxiliaries. When a VF is made auxiliary to another, +its resources are relinquished to the PF device. + +When the VF driver registers its device with the PF driver, the PF driver tells +the VF driver whether its device is auxiliary or primary, and if so then the ID +of its primary VF. If it is auxiliary, the VF device will “claim” up to 31 of +the primary VF’s CQs, such that they use the auxiliary VF’s MSI vectors. + +When a primary VF has one or more auxiliary VFs, the entire VF group must be +assigned to the same virtual machine. The PF driver will not allow the primary +VF to configure its resources until all its auxiliary VFs have been registered +by the guest OS’s driver. + +Scalable IOV +------------ + +Scalable IOV is a virtualization solution that, compared to SR-IOV, enables +highly-scalable, high-performance, and fine-grained sharing of I/O devices +across isolated domains. + +In Scalable IOV, the smallest granularity of sharing a device is the Assignable Device +Interface (ADI). Similar to SR-IOV’s Virtual Function, Scalable IOV defines the +Virtual Device (VDEV) as the abstraction at which a Scalable IOV device is exposed to +guest software, and a VDEV contains one or more ADIs. + +Kernel software is responsible for composing and managing VDEV instances in +Scalable IOV. The device-specific software components are the Host (PF) Driver, +the Guest (VDEV) Driver, and the Virtual Device Composition Module (VDCM). The +VDCM is responsible for managing the software-based virtualization of (slow) +control path operations, like the mailbox between Host and Guest drivers. + +For DLB 2.0, the ADI is the scheduling domain, which consists of load-balanced +and directed queues, ports, and other resources. Each port, whether +load-balanced or directed, consists of: +- A producer port: a 4-KB separated MMIO window +- A consumer queue: a memory-based ring to which the device writes queue entries +- One CQ interrupt message + +DLB 2.0 supports up to 16 VDEVs per PF. + +For Scalable IOV guest-host communication, DLB 2.0 uses a software-based +mailbox. This mailbox interface matches the SR-IOV hardware mailbox (i.e. PF2VF +and VF2PF MMIO regions) except that it is backed by shared memory (allocated +and managed by the VDCM). Similarly, the VF2PF interrupt trigger register +instead causes a VM exit into the VDCM driver, and the PF2VF interrupt is +replaced by a virtual interrupt injected into the guest through the VDCM. + +User Interface +============== + +The dlb2 driver uses ioctls as its primary interface. It provides two types of +files: the dlb2 device file and the scheduling domain file. + +The two types support different ioctl interfaces; the dlb2 device file is used +for device-wide operations (including scheduling domain creation), and the +scheduling domain device file supports operations on the scheduling domain's +resources such as port and queue configuration. + +The driver also exports an mmap interface through port files, which are +acquired through scheduling domain ioctls. This mmap interface is used to map +a port's memory and MMIO window into the process's address space. + +Reset +===== + +The dlb2 driver supports reset at two levels: scheduling domain and device-wide +(i.e. FLR). + +Scheduling domain reset occurs when an application stops using its domain. +Specifically, when no more file references or memory mappings exist. At this +time, the driver resets all the domain's resources (flushes its queues and +ports) and puts them in their respective available-resource lists for later +use. + +An FLR can occur while the device is in use by user-space software, so the +driver uses its reset_prepare callback to ensure that no applications continue +to use the device while the FLR executes. First, the driver blocks user-space +from executing ioctls or opening a device file, and evicts any threads blocked +on a CQ interrupt. The driver then notifies applications and virtual functions +that an FLR is pending, and waits for them to clean up with a timeout (default +of 5 seconds). If the timeout expires and the device is still in use by an +application, the driver zaps its MMIO mappings. Virtual functions, whether in +use or not, are reset as part of a PF FLR. + +While PF FLR is a hardware procedure, VF FLR is a software procedure. When a +VF FLR is triggered, this causes an interrupt to be delivered to the PF driver, +which performs the actual reset. This consists of performing the scheduling +domain reset operation for each of the VF's scheduling domains.
Documentation/misc-devices/index.rst +1 -0
@@ -14,6 +14,7 @@ fit into other categories. .. toctree:: :maxdepth: 2 + dlb2 eeprom ibmvmc ics932s401
MAINTAINERS +7 -0
@@ -8622,6 +8622,13 @@ L: [email protected] S: Supported F: arch/x86/include/asm/intel-family.h +INTEL DYNAMIC LOAD BALANCER 2.0 DRIVER +M: Gage Eads <[email protected]> +S: Maintained +F: Documentation/ABI/testing/sysfs-driver-dlb2 +F: drivers/misc/dlb* +F: include/uapi/linux/dlb2_user.h + INTEL DRM DRIVERS (excluding Poulsbo, Moorestown and derivative chipsets) M: Jani Nikula <[email protected]> M: Joonas Lahtinen <[email protected]>
drivers/misc/Kconfig +1 -0
@@ -472,4 +472,5 @@ source "drivers/misc/ocxl/Kconfig" source "drivers/misc/cardreader/Kconfig" source "drivers/misc/habanalabs/Kconfig" source "drivers/misc/uacce/Kconfig" +source "drivers/misc/dlb2/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -57,3 +57,4 @@ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_HABANA_AI) += habanalabs/ obj-$(CONFIG_UACCE) += uacce/ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o +obj-$(CONFIG_INTEL_DLB2) += dlb2/
drivers/misc/dlb2/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config INTEL_DLB2 + tristate "Intel(R) Dynamic Load Balancer 2.0 Driver" + depends on 64BIT && PCI && X86 + help + This driver supports the Intel(R) Dynamic Load Balancer 2.0 (DLB 2.0) + device. + + To compile this driver as a module, choose M here. The module + will be called dlb2.
drivers/misc/dlb2/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# +# Makefile for the Intel(R) Dynamic Load Balancer 2.0 (dlb2.ko) driver +# + +obj-$(CONFIG_INTEL_DLB2) := dlb2.o + +dlb2-objs := \ + dlb2_main.o \
drivers/misc/dlb2/dlb2_hw_types.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) +* Copyright(c) 2016-2020 Intel Corporation +*/ + +#ifndef __DLB2_HW_TYPES_H +#define __DLB2_HW_TYPES_H + +#define DLB2_MAX_NUM_VDEVS 16 +#define DLB2_MAX_NUM_DOMAINS 32 +#define DLB2_MAX_NUM_LDB_QUEUES 32/* LDB == load-balanced */ +#define DLB2_MAX_NUM_DIR_QUEUES 64/* DIR == directed */ +#define DLB2_MAX_NUM_LDB_PORTS 64 +#define DLB2_MAX_NUM_DIR_PORTS DLB2_MAX_NUM_DIR_QUEUES +#define DLB2_MAX_NUM_LDB_CREDITS 8192 +#define DLB2_MAX_NUM_DIR_CREDITS 2048 +#define DLB2_MAX_NUM_HIST_LIST_ENTRIES 2048 +#define DLB2_MAX_NUM_AQED_ENTRIES 2048 +#define DLB2_MAX_NUM_QIDS_PER_LDB_CQ 8 +#define DLB2_MAX_NUM_SEQUENCE_NUMBER_GROUPS 2 +#define DLB2_MAX_NUM_SEQUENCE_NUMBER_MODES 5 +#define DLB2_QID_PRIORITIES 8 +#define DLB2_NUM_ARB_WEIGHTS 8 +#define DLB2_MAX_WEIGHT 255 +#define DLB2_NUM_COS_DOMAINS 4 +#define DLB2_MAX_CQ_COMP_CHECK_LOOPS 409600 +#define DLB2_MAX_QID_EMPTY_CHECK_LOOPS (32 * 64 * 1024 * (800 / 30)) +#define DLB2_HZ 800000000 + +#endif /* __DLB2_HW_TYPES_H */
drivers/misc/dlb2/dlb2_main.c new file +216 -0
216 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* Copyright(c) 2017-2020 Intel Corporation +*/ + +#ifndef __DLB2_MAIN_H +#define __DLB2_MAIN_H + +#include <linux/cdev.h> +#include <linux/device.h> +#include <linux/ktime.h> +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/pci.h> +#include <linux/types.h> + +#include "dlb2_hw_types.h" + +static const char dlb2_driver_name[] =KBUILD_MODNAME ; + +/* +* The dlb2 driver uses a different minor number for each device file, of which +* there are: +* - 33 per device (PF or VF/VDEV): 1 for the device, 32 for scheduling domains +* - Up to 17 devices per PF: 1 PF and up to 16 VFs/VDEVs +* - Up to 16 PFs per system +*/ +#define DLB2_MAX_NUM_PFS 16 +#define DLB2_NUM_FUNCS_PER_DEVICE (1 + DLB2_MAX_NUM_VDEVS) +#define DLB2_MAX_NUM_DEVICES (DLB2_MAX_NUM_PFS * DLB2_NUM_FUNCS_PER_DEVICE) + +struct dlb2_dev { +struct pci_dev *pdev; +struct list_head list; +int id; +}; + +#endif /* __DLB2_MAIN_H */
include/linux/pci_ids.h +2 -0
@@ -2807,6 +2807,8 @@#define PCI_DEVICE_ID_INTEL_ESB2_14 0x2698#define PCI_DEVICE_ID_INTEL_ESB2_17 0x269b#define PCI_DEVICE_ID_INTEL_ESB2_18 0x269e +#define PCI_DEVICE_ID_INTEL_DLB2_PF 0x2710 +#define PCI_DEVICE_ID_INTEL_DLB2_VF 0x2711#define PCI_DEVICE_ID_INTEL_ICH7_0 0x27b8#define PCI_DEVICE_ID_INTEL_ICH7_1 0x27b9#define PCI_DEVICE_ID_INTEL_ICH7_30 0x27b0
Signature · 1 line
2.13.6
Greg KH
maintainerRe: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
drivers/misc/dlb2/Kconfig line 5
Quoted 3 lines · Gage Eads
drivers/misc/dlb2/Kconfig new file +3
-0+config INTEL_DLB2 + tristate "Intel(R) Dynamic Load Balancer 2.0 Driver" + depends on 64BIT && PCI && X86
Why just that platform? What about CONFIG_TEST for everything else?
drivers/misc/dlb2/Kconfig line 8
Quoted 3 lines
drivers/misc/dlb2/Kconfig new file +3
-0+ help + This driver supports the Intel(R) Dynamic Load Balancer 2.0 (DLB 2.0) + device.
Are you sure you need the (R) in Kconfig texts everywhere?
And a bit more info here would be nice, as no one knows if they have this or not, right?
drivers/misc/dlb2/dlb2_hw_types.h line 1
Quoted 4 lines
drivers/misc/dlb2/dlb2_hw_types.h new file +1
-0@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
Why dual licensed? I thought that Intel told me they were not going to do that anymore for any kernel code going forward as it was just such a pain and never actually helped anything. Has that changed?
Quoted 16 lines
drivers/misc/dlb2/dlb2_hw_types.h new file +16
-0+* Copyright(c) 2016-2020 Intel Corporation +*/ + +#ifndef __DLB2_HW_TYPES_H +#define __DLB2_HW_TYPES_H + +#define DLB2_MAX_NUM_VDEVS 16 +#define DLB2_MAX_NUM_DOMAINS 32 +#define DLB2_MAX_NUM_LDB_QUEUES 32/* LDB == load-balanced */ +#define DLB2_MAX_NUM_DIR_QUEUES 64/* DIR == directed */ +#define DLB2_MAX_NUM_LDB_PORTS 64 +#define DLB2_MAX_NUM_DIR_PORTS DLB2_MAX_NUM_DIR_QUEUES +#define DLB2_MAX_NUM_LDB_CREDITS 8192 +#define DLB2_MAX_NUM_DIR_CREDITS 2048 +#define DLB2_MAX_NUM_HIST_LIST_ENTRIES 2048 +#define DLB2_MAX_NUM_AQED_ENTRIES 2048
drivers/misc/dlb2/dlb2_hw_types.h line 27
Quoted 10 lines
drivers/misc/dlb2/dlb2_hw_types.h new file +10
-0+#define DLB2_MAX_NUM_QIDS_PER_LDB_CQ 8 +#define DLB2_MAX_NUM_SEQUENCE_NUMBER_GROUPS 2 +#define DLB2_MAX_NUM_SEQUENCE_NUMBER_MODES 5 +#define DLB2_QID_PRIORITIES 8 +#define DLB2_NUM_ARB_WEIGHTS 8 +#define DLB2_MAX_WEIGHT 255 +#define DLB2_NUM_COS_DOMAINS 4 +#define DLB2_MAX_CQ_COMP_CHECK_LOOPS 409600 +#define DLB2_MAX_QID_EMPTY_CHECK_LOOPS (32 * 64 * 1024 * (800 / 30)) +#define DLB2_HZ 800000000
No tabs? How easy is that to read? :(
greg k-h
RE: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
Quoted 10 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Sunday, July 12, 2020 10:57 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
Quoted 6 lines
drivers/misc/dlb2/Kconfig line 5
Quoted 3 lines · Gage Eads
drivers/misc/dlb2/Kconfig new file +3
-0+config INTEL_DLB2 + tristate "Intel(R) Dynamic Load Balancer 2.0 Driver" + depends on 64BIT && PCI && X86Why just that platform? What about
CONFIG_TESTfor everything else?
This device will only appear on an x86 platform. CONFIG_COMPILE_TEST won't work, since the driver uses the x86-only function iosubmit_cmds512().
Quoted 6 lines
drivers/misc/dlb2/Kconfig line 8
Quoted 4 lines
drivers/misc/dlb2/Kconfig new file +3
-0+ help + This driver supports the Intel(R) Dynamic Load Balancer 2.0 (DLB 2.0) + device.Are you sure you need the (R) in
Kconfigtexts everywhere?
The second is probably overkill. Just the first one is required.
Quoted 3 lines
And a bit more info here would be nice, as no one knows if they have this or not, right?
Intel hasn't yet announced more information that I can include here. For now, "lspci -d 8086:2710" will tell the user if this device is present.
Quoted 10 lines
drivers/misc/dlb2/dlb2_hw_types.h line 1
Quoted 5 lines
drivers/misc/dlb2/dlb2_hw_types.h new file +1
-0@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) Why dual licensed? I thought that Intel told me they were not going to do that anymore for any kernel code going forward as it was just such a pain and never actually helped anything. Has that changed?
The driver is mostly GPLv2-only, but a subset constitutes a "hardware access library" that is almost completely OS-independent. "almost" because it has calls to non-GPL symbols like kmalloc() and kfree(). This dual-licensed portion can be ported to other environments that need the more permissive BSD license.
For the broader policy question, Intel's open source team will get back to you on this.
Quoted 21 lines
drivers/misc/dlb2/dlb2_hw_types.h line 10
Quoted 9 lines
drivers/misc/dlb2/dlb2_hw_types.h new file +8
-0+* Copyright(c) 2016-2020 Intel Corporation */ + +#ifndef __DLB2_HW_TYPES_H +#define __DLB2_HW_TYPES_H + +#define DLB2_MAX_NUM_VDEVS 16 +#define DLB2_MAX_NUM_DOMAINS 32 +#define DLB2_MAX_NUM_LDB_QUEUES 32/* LDB == load-balanced */ #define
drivers/misc/dlb2/dlb2_hw_types.h line 12
Quoted 3 lines
drivers/misc/dlb2/dlb2_hw_types.h new file +3
-0+DLB2_MAX_NUM_DIR_QUEUES 64 /* DIR == directed */ #define +DLB2_MAX_NUM_LDB_PORTS 64 #define DLB2_MAX_NUM_DIR_PORTS +DLB2_MAX_NUM_DIR_QUEUES #define DLB2_MAX_NUM_LDB_CREDITS8192 #define
drivers/misc/dlb2/dlb2_hw_types.h line 13
Quoted 1 line
drivers/misc/dlb2/dlb2_hw_types.h new file +1
-0+DLB2_MAX_NUM_DIR_CREDITS 2048 #define
DLB2_MAX_NUM_HIST_LIST_ENTRIESdrivers/misc/dlb2/dlb2_hw_types.h line 17
Quoted 4 lines
drivers/misc/dlb2/dlb2_hw_types.h new file +4
-0+2048 #define DLB2_MAX_NUM_AQED_ENTRIES 2048 #define +DLB2_MAX_NUM_QIDS_PER_LDB_CQ 8 #define +DLB2_MAX_NUM_SEQUENCE_NUMBER_GROUPS 2 #define +DLB2_MAX_NUM_SEQUENCE_NUMBER_MODES 5 #define
DLB2_QID_PRIORITIES8
Quoted 8 lines
drivers/misc/dlb2/dlb2_hw_types.h line 18
Quoted 1 line
drivers/misc/dlb2/dlb2_hw_types.h new file +1
-0+#define DLB2_NUM_ARB_WEIGHTS 8 #define DLB2_MAX_WEIGHT 255#define
drivers/misc/dlb2/dlb2_hw_types.h line 19
Quoted 1 line
drivers/misc/dlb2/dlb2_hw_types.h new file +1
-0+DLB2_NUM_COS_DOMAINS 4 #define DLB2_MAX_CQ_COMP_CHECK_LOOPS409600
drivers/misc/dlb2/dlb2_hw_types.h line 27
Quoted 2 lines
drivers/misc/dlb2/dlb2_hw_types.h new file +2
-0+#define DLB2_MAX_QID_EMPTY_CHECK_LOOPS (32 * 64 * 1024 * (800 / 30)) +#define DLB2_HZ 800000000No tabs? How easy is that to read? :(
I'll improve this (and a few other instances in later patches) in V2.
Thanks,
Gage
Quoted 2 lines
greg k-h
Greg KH
maintainerRe: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
Quoted 10 lines · Gage
Quoted 10 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Sunday, July 12, 2020 10:57 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
Quoted 8 lines
Quoted 6 lines · Gage Eads
drivers/misc/dlb2/Kconfig line 5
Quoted 3 lines
drivers/misc/dlb2/Kconfig new file +3
-0+config INTEL_DLB2 + tristate "Intel(R) Dynamic Load Balancer 2.0 Driver" + depends on 64BIT && PCI && X86Why just that platform? What about
CONFIG_TESTfor everything else?This device will only appear on an x86 platform.
CONFIG_COMPILE_TESTwon't work, since the driver uses the x86-only functioniosubmit_cmds512().
Please wrap your lines correctly...
Anyway, there is no config option for that function that you can trigger off of?
Quoted 7 lines
Quoted 5 lines
drivers/misc/dlb2/Kconfig line 8
Quoted 3 lines
drivers/misc/dlb2/Kconfig new file +3
-0+ help + This driver supports the Intel(R) Dynamic Load Balancer 2.0 (DLB 2.0) + device.Are you sure you need the (R) in
Kconfigtexts everywhere?The second is probably overkill. Just the first one is required.
Really? I would just drop it. Unless you get a signed-off-by from a lawyer saying it is required :)
Quoted 4 lines
Quoted 2 lines
And a bit more info here would be nice, as no one knows if they have this or not, right?
Intel hasn't yet announced more information that I can include here. For now, "lspci -d 8086:2710" will tell the user if this device is present.
That's fine, but we can't take a 1 sentance help text, that means nothing.
Quoted 11 lines
Quoted 9 lines
drivers/misc/dlb2/dlb2_hw_types.h line 1
Quoted 4 lines
drivers/misc/dlb2/dlb2_hw_types.h new file +1
-0@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) Why dual licensed? I thought that Intel told me they were not going to do that anymore for any kernel code going forward as it was just such a pain and never actually helped anything. Has that changed?
The driver is mostly GPLv2-only, but a subset constitutes a "hardware access library" that is almost completely OS-independent. "almost" because it has calls to non-GPL symbols like
kmalloc()andkfree(). This dual-licensed portion can be ported to other environments that need the more permissive BSD license.
Then put that "OS independant" part as a separate file, with a separate license. You all know how to do this properly, don't mix this stuff up.
But even then, I would drop such a library as that's not going to make a good Linux driver, we do not like, or need, such things in the kernel.
Quoted 1 line
For the broader policy question, Intel's open source team will get back to you on this.
Wonderful, when will that happen?
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
In reply to Gage Eadsdrivers/misc/dlb2/dlb2_main.c line 72
Quoted 7 lines · Gage Eads
drivers/misc/dlb2/dlb2_main.c new file +7
-0+static int dlb2_probe (struct pci_dev *pdev, +const struct pci_device_id *pdev_id) +{ +struct dlb2_dev *dlb2_dev; +int ret; + +dev_dbg (&pdev->dev,"probe\n" );
ftrace is your friend. Remove all of your debugging code now, you don't need it anymore, especially for stuff like this where you didn't even need it in the first place :(
Same for everywhere else in all of these patches. I'll stop reviewing now, someone at Intel should have caught basic stuff like this before now, sad...
greg k-h
RE: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
Quoted 11 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Sunday, July 12, 2020 10:58 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driverOn Sun, Jul 12, 2020 at 08:43:12AM -0500, Gage Eads wrote:
Quoted 10 lines
drivers/misc/dlb2/dlb2_main.c line 72
Quoted 6 lines
drivers/misc/dlb2/dlb2_main.c new file +6
-0+static int dlb2_probe (struct pci_dev *pdev, +const struct pci_device_id *pdev_id) { +struct dlb2_dev *dlb2_dev; +int ret; + +dev_dbg (&pdev->dev,"probe\n" );ftrace is your friend. Remove all of your debugging code now, you don't need it anymore, especially for stuff like this where you didn't even need it in the first place :(
I'll remove this and other similar dev_dbg() calls. This was an oversight on my part.
I have other instances that a kprobe can't easily replace, such as printing structure contents, that are useful for tracing the usage of the driver. It looks like other misc drivers use dev_dbg() similarly -- do you consider this an acceptable use of a debug print?
Thanks,
Gage
Quoted 5 lines
Same for everywhere else in all of these patches. I'll stop reviewing now, someone at Intel should have caught basic stuff like this before now, sad...
greg k-h
Greg KH
maintainerRe: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
Quoted 22 lines · Gage
Quoted 11 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Sunday, July 12, 2020 10:58 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driverOn Sun, Jul 12, 2020 at 08:43:12AM -0500, Gage Eads wrote:
Quoted 10 lines
drivers/misc/dlb2/dlb2_main.c line 72
Quoted 6 lines
drivers/misc/dlb2/dlb2_main.c new file +6
-0+static int dlb2_probe (struct pci_dev *pdev, +const struct pci_device_id *pdev_id) { +struct dlb2_dev *dlb2_dev; +int ret; + +dev_dbg (&pdev->dev,"probe\n" );ftrace is your friend. Remove all of your debugging code now, you don't need it anymore, especially for stuff like this where you didn't even need it in the first place :(
Quoted 3 lines
I'll remove this and other similar
dev_dbg()calls. This was an oversight on my part.I have other instances that a kprobe can't easily replace, such as printing structure contents, that are useful for tracing the usage of the driver. It looks like other misc drivers use
dev_dbg()similarly -- do you consider this an acceptable use of a debug print?
Why can't a kernel tracepoint print a structure?
thanks,
greg k-h
RE: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
Quoted 36 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Saturday, July 18, 2020 1:47 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driverQuoted 11 lines · Gage
Quoted 11 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Sunday, July 12, 2020 10:58 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driverOn Sun, Jul 12, 2020 at 08:43:12AM -0500, Gage Eads wrote:
Quoted 8 lines
Quoted 8 lines
drivers/misc/dlb2/dlb2_main.c line 72
Quoted 6 lines
drivers/misc/dlb2/dlb2_main.c new file +6
-0+static int dlb2_probe (struct pci_dev *pdev, +const struct pci_device_id *pdev_id) { +struct dlb2_dev *dlb2_dev; +int ret; + +dev_dbg (&pdev->dev,"probe\n" );ftrace is your friend. Remove all of your debugging code now, you don't
need
Quoted 1 line
Quoted 1 line
it anymore, especially for stuff like this where you didn't even need it in
the
Quoted 3 lines
Quoted 1 line
first place :(
I'll remove this and other similar
dev_dbg()calls. This was an oversight on
Quoted 8 lines
my part.
Quoted 2 lines
I have other instances that a kprobe can't easily replace, such as printing
structure contents, that are useful for tracing the usage of the driver. It looks like other misc drivers use
dev_dbg()similarly -- do you consider this an acceptable use of a debug print?Why can't a kernel tracepoint print a structure?
I meant the command-line installed kprobes[1], but instrumenting the driver is certainly an option. We don't require the much lower overhead of a tracepoint, so I didn't choose it. This driver handles the (performance-insensitive) device configuration, while the fast-path operations take place in user-space.
Another reason is the "hardware access library" files use only non-GPL external symbols, and some tracepoint functions are exported GPL. Though it's probably feasible to lift that tracing code up into a (GPLv2-only) caller function.
But if tracepoints are the preferred method and/or you think the driver would benefit, I'll make the change.
Thanks,
Gage
[1] https://www.kernel.org/doc/html/latest/trace/kprobetrace.html
Greg KH
maintainerRe: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
Quoted 45 lines · Gage
Quoted 36 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Saturday, July 18, 2020 1:47 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driverQuoted 11 lines · Gage
Quoted 11 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Sunday, July 12, 2020 10:58 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driverOn Sun, Jul 12, 2020 at 08:43:12AM -0500, Gage Eads wrote:
Quoted 8 lines
Quoted 8 lines
drivers/misc/dlb2/dlb2_main.c line 72
Quoted 6 lines
drivers/misc/dlb2/dlb2_main.c new file +6
-0+static int dlb2_probe (struct pci_dev *pdev, +const struct pci_device_id *pdev_id) { +struct dlb2_dev *dlb2_dev; +int ret; + +dev_dbg (&pdev->dev,"probe\n" );ftrace is your friend. Remove all of your debugging code now, you don't
need
Quoted 1 line
Quoted 1 line
it anymore, especially for stuff like this where you didn't even need it in
the
Quoted 3 lines
Quoted 1 line
first place :(
I'll remove this and other similar
dev_dbg()calls. This was an oversight onQuoted 8 lines
my part.
Quoted 2 lines
I have other instances that a kprobe can't easily replace, such as printing
structure contents, that are useful for tracing the usage of the driver. It looks like other misc drivers use
dev_dbg()similarly -- do you consider this an acceptable use of a debug print?Why can't a kernel tracepoint print a structure?
Quoted 8 lines
I meant the command-line installed kprobes[1], but instrumenting the driver is certainly an option. We don't require the much lower overhead of a tracepoint, so I didn't choose it. This driver handles the (performance-insensitive) device configuration, while the fast-path operations take place in user-space.
Another reason is the "hardware access library" files use only non-GPL external symbols, and some tracepoint functions are exported GPL. Though it's probably feasible to lift that tracing code up into a (GPLv2-only) caller function.
Stop going through crazy gyrations for something that your own legal team has told you not to do anymore in the first place.
No "hardware access library" files please, that's not how Linux drivers are written.
you all know better...
Quoted 2 lines
But if tracepoints are the preferred method and/or you think the driver would benefit, I'll make the change.
I don't think you need any of that stuff, now that the code works properly, right?
greg k-h
RE: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driver
Quoted 81 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Monday, July 20, 2020 2:19 PM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driverQuoted 22 lines · Gage
Quoted 22 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Saturday, July 18, 2020 1:47 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driverQuoted 11 lines · Gage
Quoted 11 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Sunday, July 12, 2020 10:58 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 01/20] dlb2: add skeleton for DLB 2.0 driverOn Sun, Jul 12, 2020 at 08:43:12AM -0500, Gage Eads wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/misc/dlb2/dlb2_main.c line 72
Quoted 6 lines
drivers/misc/dlb2/dlb2_main.c new file +6
-0+static int dlb2_probe (struct pci_dev *pdev, +const struct pci_device_id *pdev_id) { +struct dlb2_dev *dlb2_dev; +int ret; + +dev_dbg (&pdev->dev,"probe\n" );ftrace is your friend. Remove all of your debugging code now, you
don't
Quoted 2 lines
Quoted 2 lines
need
Quoted 1 line
Quoted 1 line
it anymore, especially for stuff like this where you didn't even need it
in
Quoted 4 lines
Quoted 4 lines
the
Quoted 3 lines
Quoted 1 line
first place :(
I'll remove this and other similar
dev_dbg()calls. This was an oversighton
Quoted 3 lines
Quoted 3 lines
my part.
Quoted 2 lines
I have other instances that a kprobe can't easily replace, such as
printing
Quoted 1 line
Quoted 1 line
structure contents, that are useful for tracing the usage of the driver. It
looks
Quoted 6 lines
Quoted 4 lines
like other misc drivers use
dev_dbg()similarly -- do you consider this an acceptable use of a debug print?Why can't a kernel tracepoint print a structure?
I meant the command-line installed kprobes[1], but instrumenting the
driver is
Quoted 1 line
certainly an option. We don't require the much lower overhead of a
tracepoint,
Quoted 2 lines
so I didn't choose it. This driver handles the (performance-insensitive) device configuration, while the fast-path operations take place in user-
space.
Quoted 2 lines
Another reason is the "hardware access library" files use only non-GPL
external
Quoted 1 line
symbols, and some tracepoint functions are exported GPL. Though it's
probably
Quoted 1 line
feasible to lift that tracing code up into a (GPLv2-only) caller function.
Stop going through crazy gyrations for something that your own legal team has told you not to do anymore in the first place.
No "hardware access library" files please, that's not how Linux drivers are written.
Quoted 8 lines
you all know better...
Quoted 1 line
But if tracepoints are the preferred method and/or you think the driver
would
Quoted 1 line
benefit, I'll make the change.
I don't think you need any of that stuff, now that the code works properly, right?
There are no known issues, correct. The logging (whether it's dev_dbg/tracepoints/etc.) would be for user-space developers -- visibility into the driver could help them debug issues in their own code.
It's hardly a critical feature; I'm happy to change or remove it if necessary. But it could be helpful, isn't a maintenance burden or performance hindrance, and (AFAICT) shouldn't pose any security risks.
Thanks,
Gage
Quoted 2 lines
greg k-h
PATCH 2/20 dlb2: initialize PF device
In reply to Gage EadsThe driver detects the device type (PF/VF) at probe time, and assigns the corresponding 'ops' callbacks from that. These callbacks include mapping and unmapping the PCI BAR space, creating/destroying the device, and adding/deleting a char device.
--- drivers/misc/dlb2/Makefile | 5 +- drivers/misc/dlb2/dlb2_hw_types.h | 28 ++++++++ drivers/misc/dlb2/dlb2_main.c | 49 ++++++++++++- drivers/misc/dlb2/dlb2_main.h | 30 ++++++++ drivers/misc/dlb2/dlb2_pf_ops.c | 140 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 drivers/misc/dlb2/dlb2_pf_ops.c
drivers/misc/dlb2/Makefile +3 -2
@@ -4,5 +4,6 @@ obj-$(CONFIG_INTEL_DLB2) := dlb2.o -dlb2-objs := \ - dlb2_main.o \ +dlb2-objs := \ + dlb2_main.o \ + dlb2_pf_ops.o \
drivers/misc/dlb2/dlb2_hw_types.h +28 -0
@@ -5,6 +5,25 @@#ifndef __DLB2_HW_TYPES_H#define __DLB2_HW_TYPES_H +#include <linux/io.h> + +#define DLB2_PCI_REG_READ (addr) ioread32(addr) +#define DLB2_PCI_REG_WRITE (reg, value) iowrite32(value, reg) + +/* Read/write register 'reg' in the CSR BAR space */ +#define DLB2_CSR_REG_ADDR (a, reg) ((a)->csr_kva + (reg)) +#define DLB2_CSR_RD (hw, reg) \ + DLB2_PCI_REG_READ(DLB2_CSR_REG_ADDR((hw), (reg))) +#define DLB2_CSR_WR (hw, reg, value) \ + DLB2_PCI_REG_WRITE(DLB2_CSR_REG_ADDR((hw), (reg)), (value)) + +/* Read/write register 'reg' in the func BAR space */ +#define DLB2_FUNC_REG_ADDR (a, reg) ((a)->func_kva + (reg)) +#define DLB2_FUNC_RD (hw, reg) \ + DLB2_PCI_REG_READ(DLB2_FUNC_REG_ADDR((hw), (reg))) +#define DLB2_FUNC_WR (hw, reg, value) \ + DLB2_PCI_REG_WRITE(DLB2_FUNC_REG_ADDR((hw), (reg)), (value)) +#define DLB2_MAX_NUM_VDEVS 16#define DLB2_MAX_NUM_DOMAINS 32#define DLB2_MAX_NUM_LDB_QUEUES 32/* LDB == load-balanced */
@@ -26,4 +45,13 @@#define DLB2_MAX_QID_EMPTY_CHECK_LOOPS (32 * 64 * 1024 * (800 / 30))#define DLB2_HZ 800000000 +struct dlb2_hw { +/* BAR 0 address */ +void __iomem *csr_kva; +unsigned long csr_phys_addr; +/* BAR 2 address */ +void __iomem *func_kva; +unsigned long func_phys_addr; +}; +#endif /* __DLB2_HW_TYPES_H */
drivers/misc/dlb2/dlb2_main.c +48 -1
85 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.h +30 -0
@@ -28,10 +28,40 @@ static const char dlb2_driver_name[] = KBUILD_MODNAME;#define DLB2_NUM_FUNCS_PER_DEVICE (1 + DLB2_MAX_NUM_VDEVS)#define DLB2_MAX_NUM_DEVICES (DLB2_MAX_NUM_PFS * DLB2_NUM_FUNCS_PER_DEVICE) +enum dlb2_device_type { +DLB2_PF , +DLB2_VF , +}; + +struct dlb2_dev ; + +struct dlb2_device_ops { +int (*map_pci_bar_space)(struct dlb2_dev *dev,struct pci_dev *pdev); +void (*unmap_pci_bar_space)(struct dlb2_dev *dev, +struct pci_dev *pdev); +int (*device_create)(struct dlb2_dev *dlb2_dev, +struct pci_dev *pdev, +struct class *dlb2_class); +void (*device_destroy)(struct dlb2_dev *dlb2_dev, +struct class *dlb2_class); +int (*cdev_add)(struct dlb2_dev *dlb2_dev, +dev_t base, +const struct file_operations *fops); +void (*cdev_del)(struct dlb2_dev *dlb2_dev); +}; + +extern struct dlb2_device_ops dlb2_pf_ops; +struct dlb2_dev {struct pci_dev *pdev; +struct dlb2_hw hw; +struct cdev cdev; +struct dlb2_device_ops *ops;struct list_head list; +struct device *dlb2_device; +enum dlb2_device_type type;int id; +dev_t dev_number; };#endif /* __DLB2_MAIN_H */
drivers/misc/dlb2/dlb2_pf_ops.c new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 3/20 dlb2: add resource and device initialization
In reply to Gage EadsThis commit adds the hardware resource data structures and functions for their initialization/teardown and for device power-on. In subsequent commits, dlb2_resource.c will be expanded to hold the dlb2 resource-management and configuration logic (using the data structures defined in dlb2_hw_types.h).
This commit also introduces dlb2_bitmap_* functions, a thin convenience layer wrapping the Linux bitmap interfaces, used by the bitmaps in the dlb2 hardware types.
--- drivers/misc/dlb2/Makefile | 7 +- drivers/misc/dlb2/dlb2_bitmap.h | 121 +++++++++++++++++++++++ drivers/misc/dlb2/dlb2_hw_types.h | 173 +++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_main.c | 51 ++++++++++ drivers/misc/dlb2/dlb2_main.h | 11 +++ drivers/misc/dlb2/dlb2_pf_ops.c | 73 ++++++++++++++ drivers/misc/dlb2/dlb2_regs.h | 83 ++++++++++++++++ drivers/misc/dlb2/dlb2_resource.c | 197 ++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 46 +++++++++ 9 files changed, 759 insertions(+), 3 deletions(-) create mode 100644 drivers/misc/dlb2/dlb2_bitmap.h create mode 100644 drivers/misc/dlb2/dlb2_regs.h create mode 100644 drivers/misc/dlb2/dlb2_resource.c create mode 100644 drivers/misc/dlb2/dlb2_resource.h
drivers/misc/dlb2/Makefile +4 -3
@@ -4,6 +4,7 @@ obj-$(CONFIG_INTEL_DLB2) := dlb2.o -dlb2-objs := \ - dlb2_main.o \ - dlb2_pf_ops.o \ +dlb2-objs := \ + dlb2_main.o \ + dlb2_pf_ops.o \ + dlb2_resource.o \
drivers/misc/dlb2/dlb2_bitmap.h new file +121 -0
121 lines not on this page · raw message
drivers/misc/dlb2/dlb2_hw_types.h +173 -0
191 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.c +51 -0
81 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.h +11 -0
@@ -39,6 +39,8 @@ struct dlb2_device_ops {int (*map_pci_bar_space)(struct dlb2_dev *dev,struct pci_dev *pdev);void (*unmap_pci_bar_space)(struct dlb2_dev *dev,struct pci_dev *pdev); +int (*init_driver_state)(struct dlb2_dev *dev); +void (*free_driver_state)(struct dlb2_dev *dev);int (*device_create)(struct dlb2_dev *dlb2_dev,struct pci_dev *pdev,struct class *dlb2_class);
@@ -48,6 +50,10 @@ struct dlb2_device_ops {dev_t base, const struct file_operations *fops);void (*cdev_del)(struct dlb2_dev *dlb2_dev); +void (*enable_pm)(struct dlb2_dev *dev); +int (*wait_for_device_ready)(struct dlb2_dev *dev, +struct pci_dev *pdev); +void (*init_hardware)(struct dlb2_dev *dev); };extern struct dlb2_device_ops dlb2_pf_ops;
@@ -59,6 +65,11 @@ struct dlb2_dev {struct dlb2_device_ops *ops;struct list_head list;struct device *dlb2_device; +/* +* The resource mutex serializes access to driver data structures and +* hardware registers. +*/ +struct mutex resource_mutex;enum dlb2_device_type type;int id;dev_t dev_number;
drivers/misc/dlb2/dlb2_pf_ops.c +73 -0
100 lines not on this page · raw message
drivers/misc/dlb2/dlb2_regs.h new file +83 -0
83 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.c new file +197 -0
197 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 4/20 dlb2: add device ioctl layer and first 4 ioctls
In reply to Gage EadsThis commit introduces the dlb2 device ioctl layer, and the first four
ioctls: query device version, driver version, and available resources; and create a scheduling domain. This commit also introduces the user-space interface file dlb2_user.h.
The PF hardware operation for scheduling domain creation will be added in a subsequent commit.
--- drivers/misc/dlb2/Makefile | 1 + drivers/misc/dlb2/dlb2_bitmap.h | 63 ++++++++++ drivers/misc/dlb2/dlb2_ioctl.c | 186 ++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_ioctl.h | 14 +++ drivers/misc/dlb2/dlb2_main.c | 33 +++++- drivers/misc/dlb2/dlb2_main.h | 7 ++ drivers/misc/dlb2/dlb2_pf_ops.c | 21 ++++ drivers/misc/dlb2/dlb2_resource.c | 48 ++++++++ drivers/misc/dlb2/dlb2_resource.h | 22 ++++ include/uapi/linux/dlb2_user.h | 236 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 630 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/dlb2/dlb2_ioctl.c create mode 100644 drivers/misc/dlb2/dlb2_ioctl.h create mode 100644 include/uapi/linux/dlb2_user.h
drivers/misc/dlb2/Makefile +1 -0
@@ -6,5 +6,6 @@ obj-$(CONFIG_INTEL_DLB2) := dlb2.o dlb2-objs := \ dlb2_main.o \ + dlb2_ioctl.o \ dlb2_pf_ops.o \ dlb2_resource.o \
drivers/misc/dlb2/dlb2_bitmap.h +63 -0
67 lines not on this page · raw message
drivers/misc/dlb2/dlb2_ioctl.c new file +186 -0
186 lines not on this page · raw message
drivers/misc/dlb2/dlb2_ioctl.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* Copyright(c) 2017-2020 Intel Corporation +*/ + +#ifndef __DLB2_IOCTL_H +#define __DLB2_IOCTL_H + +#include "dlb2_main.h" + +int dlb2_ioctl_dispatcher (struct dlb2_dev *dev, +unsigned int cmd, +unsigned long arg); + +#endif /* __DLB2_IOCTL_H */
drivers/misc/dlb2/dlb2_main.c +32 -1
@@ -11,15 +11,25 @@#include <linux/pci.h> #include <linux/uaccess.h> +#include "dlb2_ioctl.h" #include "dlb2_main.h" #include "dlb2_resource.h" static const char dlb2_driver_copyright[] ="Copyright(c) 2018-2020 Intel Corporation" ; +#define TO_STR2 (s) #s +#define TO_STR (s) TO_STR2(s) + +#define DRV_VERSION \ + TO_STR(DLB2_VERSION_MAJOR_NUMBER) "." \ + TO_STR(DLB2_VERSION_MINOR_NUMBER) "." \ + TO_STR(DLB2_VERSION_REVISION_NUMBER) +MODULE_LICENSE ("Dual BSD/GPL" );MODULE_AUTHOR ("Copyright(c) 2018-2020 Intel Corporation" );MODULE_DESCRIPTION ("Intel(R) Dynamic Load Balancer 2.0 Driver" ); +MODULE_VERSION (DRV_VERSION );/* The driver lock protects data structures that used by multiple devices. */ static DEFINE_MUTEX (dlb2_driver_lock);
@@ -59,10 +69,28 @@ static int dlb2_close(struct inode *i, struct file *f)return 0 ; } +static long +dlb2_ioctl (struct file *f,unsigned int cmd,unsigned long arg) +{ +struct dlb2_dev *dev; + + dev = container_of(f->f_inode->i_cdev, struct dlb2_dev, cdev); + +if (_IOC_TYPE (cmd) !=DLB2_IOC_MAGIC ) { +dev_err (dev->dlb2_device, +"[%s()] Bad magic number!\n" , __func__); +return -EINVAL ; + } + +return dlb2_ioctl_dispatcher (dev, cmd, arg); +} +static const struct file_operations dlb2_fops = { .owner =THIS_MODULE , .open = dlb2_open, .release = dlb2_close, + .unlocked_ioctl = dlb2_ioctl, + .compat_ioctl = compat_ptr_ioctl, };/**********************************/
@@ -260,7 +288,10 @@ static int __init dlb2_init_module(void) {int err; -pr_info ("%s\n" , dlb2_driver_name); +pr_info ("%s - version %d.%d.%d\n" , dlb2_driver_name, +DLB2_VERSION_MAJOR_NUMBER , +DLB2_VERSION_MINOR_NUMBER , +DLB2_VERSION_REVISION_NUMBER );pr_info ("%s\n" , dlb2_driver_copyright); dlb2_class =class_create (THIS_MODULE , dlb2_driver_name);
drivers/misc/dlb2/dlb2_main.h +7 -0
@@ -13,6 +13,8 @@#include <linux/pci.h> #include <linux/types.h> +#include <uapi/linux/dlb2_user.h> +#include "dlb2_hw_types.h" static const char dlb2_driver_name[] =KBUILD_MODNAME ;
@@ -53,6 +55,11 @@ struct dlb2_device_ops {void (*enable_pm)(struct dlb2_dev *dev);int (*wait_for_device_ready)(struct dlb2_dev *dev,struct pci_dev *pdev); +int (*create_sched_domain)(struct dlb2_hw *hw, +struct dlb2_create_sched_domain_args *args, +struct dlb2_cmd_response *resp); +int (*get_num_resources)(struct dlb2_hw *hw, +struct dlb2_get_num_resources_args *args);void (*init_hardware)(struct dlb2_dev *dev); };
drivers/misc/dlb2/dlb2_pf_ops.c +21 -0
@@ -194,6 +194,25 @@ dlb2_pf_init_hardware(struct dlb2_dev *dlb2_dev) { } +/*****************************/ +/****** IOCTL callbacks ******/ +/*****************************/ + +static int +dlb2_pf_create_sched_domain (struct dlb2_hw *hw, +struct dlb2_create_sched_domain_args *args, +struct dlb2_cmd_response *resp) +{ +return 0 ; +} + +static int +dlb2_pf_get_num_resources (struct dlb2_hw *hw, +struct dlb2_get_num_resources_args *args) +{ +return dlb2_hw_get_num_resources (hw, args, false,0 ); +} +/********************************/ /****** DLB2 PF Device Ops ******/ /********************************/
@@ -209,5 +228,7 @@ struct dlb2_device_ops dlb2_pf_ops = { .cdev_del = dlb2_pf_cdev_del, .enable_pm = dlb2_pf_enable_pm, .wait_for_device_ready = dlb2_pf_wait_for_device_ready, + .create_sched_domain = dlb2_pf_create_sched_domain, + .get_num_resources = dlb2_pf_get_num_resources, .init_hardware = dlb2_pf_init_hardware, };
drivers/misc/dlb2/dlb2_resource.c +48 -0
54 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +22 -0
@@ -35,6 +35,28 @@ int dlb2_resource_init(struct dlb2_hw *hw);void dlb2_resource_free (struct dlb2_hw *hw);/** +* dlb2_hw_get_num_resources() - query the PCI function's available resources +* @hw: dlb2_hw handle for a particular device. +* @arg: pointer to resource counts. +* @vdev_request: indicates whether this request came from a vdev. +* @vdev_id: If vdev_request is true, this contains the vdev's ID. +* +* This function returns the number of available resources for the PF or for a +* VF. +* +* A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual +* device. +* +* Return: +* Returns 0 upon success, -EINVAL if vdev_request is true and vdev_id is +* invalid. +*/ +int dlb2_hw_get_num_resources (struct dlb2_hw *hw, +struct dlb2_get_num_resources_args *arg, +bool vdev_request, +unsigned int vdev_id); + +/** * dlb2_clr_pmcsr_disable() - power on bulk of DLB 2.0 logic * @hw: dlb2_hw handle for a particular device. *
include/uapi/linux/dlb2_user.h new file +236 -0
236 lines not on this page · raw message
Signature · 1 line
2.13.6
Randy Dunlap
reviewerRe: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
include/uapi/linux/dlb2_user.h line 217
Quoted 5 lines · Gage Eads
include/uapi/linux/dlb2_user.h new file +5
-0+/********************/ +/* dlb2 ioctl codes */ +/********************/ + +#define DLB2_IOC_MAGIC 'h'
Hi,
This magic value should be documented in Documentation/userspace-api/ioctl/ioctl-number.rst.
thanks.
Signature · 1 line
~Randy
RE: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 22 lines
-----Original Message-----
From: Randy Dunlap <[email protected]>
Sent: Sunday, July 12, 2020 9:42 AM
To: Eads, Gage <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctlsinclude/uapi/linux/dlb2_user.h line 217
Quoted 5 lines · Gage Eads
include/uapi/linux/dlb2_user.h new file +5
-0+/********************/ +/* dlb2 ioctl codes */ +/********************/ + +#define DLB2_IOC_MAGIC 'h'Hi,
This magic value should be documented inDocumentation/userspace-api/ioctl/ioctl-number.rst.
Quoted 3 lines
thanks.
--
~Randy
Will fix in v2.
Thanks,
Gage
Randy Dunlap
reviewerRe: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
In reply to Gage Eadsdrivers/misc/dlb2/dlb2_ioctl.c line 178
Quoted 7 lines · Gage Eads
drivers/misc/dlb2/dlb2_ioctl.c new file +7
-0+int dlb2_ioctl_dispatcher (struct dlb2_dev *dev, +unsigned int cmd, +unsigned long arg) +{ +u16 sz =_IOC_SIZE (cmd); + +if (_IOC_NR (cmd) >=NUM_DLB2_CMD ) {
Does this bounds check need to use array_index_nospec() from <linux/nospec.h> ?
drivers/misc/dlb2/dlb2_ioctl.c line 186
Quoted 8 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +8
-0+dev_err (dev->dlb2_device, +"[%s()] Unexpected DLB command %d\n" , + __func__,_IOC_NR (cmd)); +return -1 ; + } + +return dlb2_ioctl_callback_fns[_IOC_NR (cmd)](dev, arg, sz); +}
I don't know if it needs to or not. I just want to make sure that you or someone has thought about it.
Signature · 1 line
~Randy
RE: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 23 lines
-----Original Message-----
From: Randy Dunlap <[email protected]>
Sent: Sunday, July 12, 2020 9:54 AM
To: Eads, Gage <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctlsdrivers/misc/dlb2/dlb2_ioctl.c line 178
Quoted 7 lines · Gage Eads
drivers/misc/dlb2/dlb2_ioctl.c new file +7
-0+int dlb2_ioctl_dispatcher (struct dlb2_dev *dev, +unsigned int cmd, +unsigned long arg) +{ +u16 sz =_IOC_SIZE (cmd); + +if (_IOC_NR (cmd) >=NUM_DLB2_CMD ) {Does this bounds check need to use
array_index_nospec()from <linux/nospec.h> ?
Quoted 10 lines
drivers/misc/dlb2/dlb2_ioctl.c
Quoted 7 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +7
-0+dev_err (dev->dlb2_device, +"[%s()] Unexpected DLB command %d\n" , + __func__,_IOC_NR (cmd)); +return -1 ; + } + +return dlb2_ioctl_callback_fns[_IOC_NR (cmd)](dev, arg, sz); }I don't know if it needs to or not. I just want to make sure that you or someone has thought about it.
Thanks for catching this -- it does. Per Arnd's suggestion, I'm going to convert this to a switch statement and avoid the index altogether.
Thanks,
Gage
Quoted 3 lines
--
~Randy
Arnd Bergmann
maintainerRe: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
In reply to Gage EadsQuoted 11 lines · Gage Eads
This commit introduces the dlb2 device ioctl layer, and the first four
ioctls: query device version, driver version, and available resources; and create a scheduling domain. This commit also introduces the user-space interface filedlb2_user.h.The PF hardware operation for scheduling domain creation will be added in a subsequent commit.
Signed-off-by Gage Eads <[email protected]>Reviewed-by Magnus Karlsson <[email protected]>
I'm looking only at the ioctl interface here, as that is usually the hardest part to get right, and you can't easily change it after it gets merged.
The definitions all look portable and will work fine in compat mode (which is often a problem), but you have added a bit of complexity compared to how it is commonly done, so it's better to simplify it and write it more like other drivers do. More on that below.
Quoted 11 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +11
-0+/* Verify the ioctl argument size and copy the argument into kernel memory */ +static int dlb2_copy_from_user (struct dlb2_dev *dev, +unsigned long user_arg, +u16 user_size, +void *arg, +size_t size) +{ +if (user_size != size) { +dev_err (dev->dlb2_device, +"[%s()] Invalid ioctl size\n" , __func__); +return -EINVAL ;
drivers/misc/dlb2/dlb2_ioctl.c line 31
Quoted 10 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +10
-0+ } + +if (copy_from_user (arg, (void __user *)user_arg, size)) { +dev_err (dev->dlb2_device, +"[%s()] Invalid ioctl argument pointer\n" , __func__); +return -EFAULT ; + } + +return 0 ; +}
You should avoid error messages that are triggered based on user input. and can cause a denial-of-service when the console is spammed that way.
A plain copy_from_user() in place of this function should be fine.
Quoted 11 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +11
-0+/* [7:0]: device revision, [15:8]: device version */ +#define DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev)) + +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response; +int ret; +
drivers/misc/dlb2/dlb2_ioctl.c line 66
Quoted 10 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +10
-0+dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + + ret =dlb2_copy_resp_to_user (dev, arg.response, &response);
Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use _IOWR() to define it and put all arguments into the same structure.
drivers/misc/dlb2/dlb2_ioctl.c line 83
Quoted 9 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +9
-0+static int dlb2_ioctl_create_sched_domain (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_create_sched_domain_args arg; +struct dlb2_cmd_response response = {0 }; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__);
I assume you have finished debugging this version and can remove these debug comments again. If you find new bugs, you can add them temporarily, but nothing is gained by these here. You can use ftrace to see when functions are called.
drivers/misc/dlb2/dlb2_ioctl.c line 92
Quoted 9 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +9
-0+ + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret;
There is no need to verify the response pointer. If it fails later, it's the user's fault, and they get to deal with it.
drivers/misc/dlb2/dlb2_ioctl.c line 146
Quoted 12 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +12
-0+static int dlb2_ioctl_get_driver_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_get_driver_version_args arg; +struct dlb2_cmd_response response; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_VERSION ;
Just remove the driver version command, trying to have explicit interface versions creates more problems than it solves.
Quoted 5 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +5
-0+int dlb2_ioctl_dispatcher (struct dlb2_dev *dev, +unsigned int cmd, +unsigned long arg) +{ +u16 sz =_IOC_SIZE (cmd);
drivers/misc/dlb2/dlb2_ioctl.c line 186
Quoted 10 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +10
-0+ +if (_IOC_NR (cmd) >=NUM_DLB2_CMD ) { +dev_err (dev->dlb2_device, +"[%s()] Unexpected DLB command %d\n" , + __func__,_IOC_NR (cmd)); +return -1 ; + } + +return dlb2_ioctl_callback_fns[_IOC_NR (cmd)](dev, arg, sz); +}
This is usually written with a switch/case statement, so doing the same here tends to make it easier to understand.
Quoted 5 lines
drivers/misc/dlb2/dlb2_main.c +5
-0+static long +dlb2_ioctl (struct file *f,unsigned int cmd,unsigned long arg) +{ +struct dlb2_dev *dev; +
drivers/misc/dlb2/dlb2_main.c static int dlb2_close(struct inode *i, struct file *f) · line 86
Quoted 10 lines
drivers/misc/dlb2/dlb2_main.c +10
-0+ dev = container_of(f->f_inode->i_cdev, struct dlb2_dev, cdev); + +if (_IOC_TYPE (cmd) !=DLB2_IOC_MAGIC ) { +dev_err (dev->dlb2_device, +"[%s()] Bad magic number!\n" , __func__); +return -EINVAL ; + } + +return dlb2_ioctl_dispatcher (dev, cmd, arg); +}
This function can also be removed then, just call the dispatcher directly.
drivers/misc/dlb2/dlb2_main.c static int __init dlb2_init_module(void) · line 295
Quoted 8 lines
int err;drivers/misc/dlb2/dlb2_main.c +4
-1-pr_info ("%s\n" , dlb2_driver_name); +pr_info ("%s - version %d.%d.%d\n" , dlb2_driver_name, +DLB2_VERSION_MAJOR_NUMBER , +DLB2_VERSION_MINOR_NUMBER , +DLB2_VERSION_REVISION_NUMBER );pr_info ("%s\n" , dlb2_driver_copyright);
Just remove the pr_info completely.
Arnd
RE: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 16 lines
Quoted 16 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +15
-0+/* Verify the ioctl argument size and copy the argument into kernel +memory */ static int dlb2_copy_from_user (struct dlb2_dev *dev, +unsigned long user_arg, +u16 user_size, +void *arg, +size_t size) { +if (user_size != size) { +dev_err (dev->dlb2_device, +"[%s()] Invalid ioctl size\n" , __func__); +return -EINVAL ; + } + +if (copy_from_user (arg, (void __user *)user_arg, size)) { +dev_err (dev->dlb2_device, +"[%s()] Invalid ioctl argument pointer\n" , __func__);
Quoted 9 lines
drivers/misc/dlb2/dlb2_ioctl.c line 31
Quoted 5 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +5
-0+return -EFAULT ; + } + +return 0 ; +}You should avoid error messages that are triggered based on user input. and can cause a denial-of-service when the console is spammed that way.
Makes sense, will fix.
Quoted 1 line
A plain
copy_from_user()in place of this function should be fine.
This function also validates the user size arg to prevent buffer overflow; centralizing it here avoids the case where a programmer accidentally forgets the check in an ioctl handler (and reduces code duplication). If it's alright with you, I'll keep the function but drop the dev_err() prints.
Quoted 18 lines
Quoted 18 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +17
-0+/* [7:0]: device revision, [15:8]: device version */ #define +DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev)) + +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) { +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret)
Quoted 8 lines
drivers/misc/dlb2/dlb2_ioctl.c line 66
Quoted 3 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +3
-0+return ret; + + ret =dlb2_copy_resp_to_user (dev, arg.response, &response);Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use
_IOWR()to define it and put all arguments into the same structure.
Ok, I'll merge the response structure into the ioctl structure (here and elsewhere).
Say I add this command later: without driver versioning, how would user-space know in advance whether the command is supported? It could attempt the command and interpret -ENOTTY as "unsupported", but that strikes me as an inelegant way to reverse-engineer the version.
Quoted 14 lines
drivers/misc/dlb2/dlb2_ioctl.c line 83
Quoted 9 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +8
-0+static int dlb2_ioctl_create_sched_domain (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) { +struct dlb2_create_sched_domain_args arg; +struct dlb2_cmd_response response = {0 }; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__);I assume you have finished debugging this version and can remove these debug comments again. If you find new bugs, you can add them temporarily, but nothing is gained by these here. You can use ftrace to see when functions are called.
You're right, and this was mentioned in another comment as well. I'll remove these unnecessary dev_dbg() calls.
Quoted 14 lines
drivers/misc/dlb2/dlb2_ioctl.c line 92
Quoted 10 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +9
-0+ + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret;There is no need to verify the response pointer. If it fails later, it's the user's fault, and they get to deal with it.
Quoted 14 lines
drivers/misc/dlb2/dlb2_ioctl.c line 146
Quoted 11 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +11
-0+static int dlb2_ioctl_get_driver_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) { +struct dlb2_get_driver_version_args arg; +struct dlb2_cmd_response response; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_VERSION ;Just remove the driver version command, trying to have explicit interface versions creates more problems than it solves.
(See question above)
Quoted 18 lines
Quoted 4 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +3
-0+int dlb2_ioctl_dispatcher (struct dlb2_dev *dev, +unsigned int cmd, +unsigned long arg) {drivers/misc/dlb2/dlb2_ioctl.c
Quoted 10 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +10
-0+u16 sz =_IOC_SIZE (cmd); + +if (_IOC_NR (cmd) >=NUM_DLB2_CMD ) { +dev_err (dev->dlb2_device, +"[%s()] Unexpected DLB command %d\n" , + __func__,_IOC_NR (cmd)); +return -1 ; + } + +return dlb2_ioctl_callback_fns[_IOC_NR (cmd)](dev, arg, sz); }This is usually written with a switch/case statement, so doing the same here tends to make it easier to understand.
Will do. And as Randy noticed, this needed array_index_nospec() -- easier to avoid that entirely with a switch statement.
Quoted 17 lines
drivers/misc/dlb2/dlb2_main.c static int dlb2_close(struct inode *i, struct file *f)
Quoted 13 lines
drivers/misc/dlb2/dlb2_main.c +13
-0+static long +dlb2_ioctl (struct file *f,unsigned int cmd,unsigned long arg) { +struct dlb2_dev *dev; + + dev = container_of(f->f_inode->i_cdev, struct dlb2_dev, cdev); + +if (_IOC_TYPE (cmd) !=DLB2_IOC_MAGIC ) { +dev_err (dev->dlb2_device, +"[%s()] Bad magic number!\n" , __func__); +return -EINVAL ; + } + +return dlb2_ioctl_dispatcher (dev, cmd, arg); }This function can also be removed then, just call the dispatcher directly.
Quoted 2 lines
int err;
Quoted 8 lines
drivers/misc/dlb2/dlb2_main.c static int __init dlb2_init_module(void) · line 295
Quoted 6 lines
drivers/misc/dlb2/dlb2_main.c +4
-1-pr_info ("%s\n" , dlb2_driver_name); +pr_info ("%s - version %d.%d.%d\n" , dlb2_driver_name, +DLB2_VERSION_MAJOR_NUMBER , +DLB2_VERSION_MINOR_NUMBER , +DLB2_VERSION_REVISION_NUMBER );pr_info ("%s\n" , dlb2_driver_copyright);Just remove the
pr_infocompletely.
Can you elaborate? Printing the driver name/copyright/etc. seems to be a common pattern in upstream drivers.
Thanks,
Gage
Quoted 2 lines
Arnd
Arnd Bergmann
maintainerRe: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 3 lines · Gage
Quoted 1 line
A plain
copy_from_user()in place of this function should be fine.This function also validates the user size arg to prevent buffer overflow; centralizing it here avoids the case where a programmer accidentally forgets the check in an ioctl handler (and reduces code duplication). If it's alright with you, I'll keep the function but drop the
dev_err()prints.
Once you use a 'switch(cmd)' statement in the top ioctl handler, the data structure size will be fixed, so there is no way the argument size can go wrong.
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +17
-0+/* [7:0]: device revision, [15:8]: device version */ #define +DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev)) + +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) { +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret)Quoted 8 lines
drivers/misc/dlb2/dlb2_ioctl.c line 66
Quoted 3 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +3
-0+return ret; + + ret =dlb2_copy_resp_to_user (dev, arg.response, &response);Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use
_IOWR()to define it and put all arguments into the same structure.
Quoted 6 lines
Ok, I'll merge the response structure into the ioctl structure (here and elsewhere).
Say I add this command later: without driver versioning, how would user-space know in advance whether the command is supported? It could attempt the command and interpret
-ENOTTYas "unsupported", but that strikes me as an inelegant way to reverse-engineer the version.
There is not really a driver "version" once the driver is upstream, the concept doesn't really make sense here when arbitrary patches can get backported from the latest kernel into whatever the user is running.
The ENOTTY check is indeed the normal way that user space deals with interfaces that may have been added later. What you normally want is to keep using the original interfaces anyway, unless you absolutely need a later revision for a certain feature, and in that case the user space program will fail no matter what.
Quoted 10 lines
Quoted 10 lines
This function can also be removed then, just call the dispatcher directly.
Quoted 8 lines
int err;drivers/misc/dlb2/dlb2_main.c +4
-1-pr_info ("%s\n" , dlb2_driver_name); +pr_info ("%s - version %d.%d.%d\n" , dlb2_driver_name, +DLB2_VERSION_MAJOR_NUMBER , +DLB2_VERSION_MINOR_NUMBER , +DLB2_VERSION_REVISION_NUMBER );pr_info ("%s\n" , dlb2_driver_copyright);
Quoted 3 lines
Quoted 1 line
Just remove the
pr_infocompletely.Can you elaborate? Printing the driver name/copyright/etc. seems to be a common pattern in upstream drivers.
Most drivers don't do it, and it's generally not recommended. You can print a message when something goes wrong, but most users don't care about that stuff and it clutters up the kernel log if each driver prints a line or two.
Arnd
RE: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 15 lines
-----Original Message-----
From: Arnd Bergmann <[email protected]>
Sent: Friday, July 17, 2020 1:57 PM
To: Eads, Gage <[email protected]>
Cc: [email protected]; gregkh <[email protected]>; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctlsQuoted 2 lines · Gage
Quoted 1 line
A plain
copy_from_user()in place of this function should be fine.
Quoted 8 lines
Quoted 1 line
This function also validates the user size arg to prevent buffer overflow;
centralizing it here avoids the case where a programmer accidentally forgets the check in an ioctl handler (and reduces code duplication). If it's alright with you, I'll keep the function but drop the
dev_err()prints.Once you use a 'switch(cmd)' statement in the top ioctl handler, the data structure size will be fixed, so there is no way the argument size can go wrong.
Ah, understood. Will fix in v2.
Quoted 32 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +18
-0+/* [7:0]: device revision, [15:8]: device version */ #define +DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev)) + +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) { +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret;Quoted 8 lines
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ + ret = dlb2_copy_resp_to_user(dev, arg.response, + &response);Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use
_IOWR()to define it and put all arguments into the samestructure.
Quoted 2 lines
Ok, I'll merge the response structure into the ioctl structure (here and
elsewhere).
Quoted 1 line
Quoted 9 lines
Quoted 4 lines
Say I add this command later: without driver versioning, how would user-space know in advance whether the command is supported? It could attempt the command and interpret
-ENOTTYas "unsupported", but that strikes me as an inelegant way to reverse-engineer the version.There is not really a driver "version" once the driver is upstream, the concept doesn't really make sense here when arbitrary patches can get backported from the latest kernel into whatever the user is running.
"Driver interface version" is the better term for what I'm trying to accomplish here. Any backports would have to be done in such a way that the interface version is honored, but if that can't be reasonably expected...then I agree, versioning is unworkable.
Quoted 16 lines
The ENOTTY check is indeed the normal way that user space deals with interfaces that may have been added later. What you normally want is to keep using the original interfaces anyway, unless you absolutely need a later revision for a certain feature, and in that case the user space program will fail no matter what.
Quoted 10 lines
Quoted 10 lines
This function can also be removed then, just call the dispatcher directly.
Quoted 8 lines
int err;drivers/misc/dlb2/dlb2_main.c +4
-1-pr_info ("%s\n" , dlb2_driver_name); +pr_info ("%s - version %d.%d.%d\n" , dlb2_driver_name, +DLB2_VERSION_MAJOR_NUMBER , +DLB2_VERSION_MINOR_NUMBER , +DLB2_VERSION_REVISION_NUMBER );pr_info ("%s\n" , dlb2_driver_copyright);
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
Just remove the
pr_infocompletely.Can you elaborate? Printing the driver name/copyright/etc. seems to be a
common pattern in upstream drivers.
Most drivers don't do it, and it's generally not recommended. You can print a message when something goes wrong, but most users don't care about that stuff and it clutters up the kernel log if each driver prints a line or two.
Fair enough. I'll remove it.
Thanks,
Gage
Quoted 1 line
Arnd
gregkh
maintainerRe: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 63 lines · Gage
Quoted 15 lines
-----Original Message-----
From: Arnd Bergmann <[email protected]>
Sent: Friday, July 17, 2020 1:57 PM
To: Eads, Gage <[email protected]>
Cc: [email protected]; gregkh <[email protected]>; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctlsQuoted 2 lines · Gage
Quoted 1 line
A plain
copy_from_user()in place of this function should be fine.Quoted 8 lines
Quoted 1 line
This function also validates the user size arg to prevent buffer overflow;
centralizing it here avoids the case where a programmer accidentally forgets the check in an ioctl handler (and reduces code duplication). If it's alright with you, I'll keep the function but drop the
dev_err()prints.Once you use a 'switch(cmd)' statement in the top ioctl handler, the data structure size will be fixed, so there is no way the argument size can go wrong.
Ah, understood. Will fix in v2.
Quoted 37 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +18
-0+/* [7:0]: device revision, [15:8]: device version */ #define +DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev)) + +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) { +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret;Quoted 8 lines
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ + ret = dlb2_copy_resp_to_user(dev, arg.response, + &response);Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use
_IOWR()to define it and put all arguments into the samestructure.
Quoted 2 lines
Ok, I'll merge the response structure into the ioctl structure (here and
elsewhere).
Quoted 5 lines
Say I add this command later: without driver versioning, how would user-space know in advance whether the command is supported? It could attempt the command and interpret
-ENOTTYas "unsupported", but that strikes me as an inelegant way to reverse-engineer the version.
Quoted 6 lines
Quoted 4 lines
There is not really a driver "version" once the driver is upstream, the concept doesn't really make sense here when arbitrary patches can get backported from the latest kernel into whatever the user is running.
"Driver interface version" is the better term for what I'm trying to accomplish here. Any backports would have to be done in such a way that the interface version is honored, but if that can't be reasonably expected...then I agree, versioning is unworkable.
There is no such thing as a "driver interface version", sorry, that is not going to be workable at all.
thanks,
greg k-h
RE: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
In reply to Arnd BergmannQuoted 19 lines
Quoted 19 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +19
-0+/* [7:0]: device revision, [15:8]: device version */ +#define DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev)) + +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret;
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + ret = dlb2_copy_resp_to_user(dev, arg.response, &response);Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use
_IOWR()to define it and put all arguments into the same structure.
I should've caught this in my earlier response, sorry. The device version command is intentionally the first in the user interface enum. My goal is for all device versions (e.g. DLB 1.0 in the future) to be accessible through a /dev/dlb%d node. To allow this, all drivers would support the same device-version command as command 0, then the subsequent commands can be tailored to that particular device. User-space would query the version first to determine which set of ioctl commands it needs to use.
So even though the response is constant (for now), it must occupy command 0 for this design to work.
Thanks,
Gage
gregkh
maintainerRe: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 36 lines · Gage
Quoted 19 lines
Quoted 19 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +19
-0+/* [7:0]: device revision, [15:8]: device version */ +#define DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev)) + +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret;Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + ret = dlb2_copy_resp_to_user(dev, arg.response, &response);Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use
_IOWR()to define it and put all arguments into the same structure.I should've caught this in my earlier response, sorry. The device version command is intentionally the first in the user interface enum. My goal is for all device versions (e.g. DLB 1.0 in the future) to be accessible through a /dev/dlb%d node. To allow this, all drivers would support the same device-version command as command 0, then the subsequent commands can be tailored to that particular device. User-space would query the version first to determine which set of ioctl commands it needs to use.
Quoted 2 lines
So even though the response is constant (for now), it must occupy command 0 for this design to work.
"versions" for ioctls just do not work, please don't go down that path, they should not be needed. See the many different discussions about this topic on lkml for other subsystem submissions if you are curious.
thanks,
greg k-h
RE: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 51 lines
-----Original Message-----
From: gregkh <[email protected]>
Sent: Wednesday, August 5, 2020 1:46 AM
To: Eads, Gage <[email protected]>
Cc: Arnd Bergmann <[email protected]>; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctlsQuoted 9 lines · Gage
Quoted 9 lines
Quoted 9 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +9
-0+/* [7:0]: device revision, [15:8]: device version */ +#define DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev)) + +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response;Quoted 8 lines
Quoted 8 lines
drivers/misc/dlb2/dlb2_ioctl.c
Quoted 8 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +8
-0+int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret = dlb2_copy_from_user(dev, user_arg, size, &arg,sizeof(arg));
Quoted 11 lines
Quoted 10 lines
drivers/misc/dlb2/dlb2_ioctl.c line 66
Quoted 4 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +4
-0+if (ret) +return ret; + + ret =dlb2_copy_resp_to_user (dev, arg.response, &response);Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use
_IOWR()to define it and put all arguments into the same structure.Quoted 4 lines
I should've caught this in my earlier response, sorry. The device version command is intentionally the first in the user interface enum. My goal is for all device versions (e.g. DLB 1.0 in the future) to be accessible through a /dev/dlb%d node. To allow this, all drivers would support the
same
Quoted 1 line
device-version command as command 0, then the subsequent commands
can be
Quoted 3 lines
tailored to that particular device. User-space would query the version first to determine which set of ioctl commands it needs to use.
Quoted 8 lines
Quoted 1 line
So even though the response is constant (for now), it must occupy
command 0 for
Quoted 1 line
this design to work.
"versions" for ioctls just do not work, please don't go down that path, they should not be needed. See the many different discussions about this topic on lkml for other subsystem submissions if you are curious.
This approach is based on VFIO's modular ioctl design, which has a different API for Type1 vs. SPAPR IOMMUs. Similarly a DLB driver could have a different API for each device version (but each API would be fixed, not versioned). I didn't see any concerns on lkml over VFIO when it was originally submitted -- though that was 8 years ago, perhaps the community's feelings have changed since then.
Thanks,
Gage
gregkh
maintainerRe: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 60 lines · Gage
Quoted 51 lines
-----Original Message-----
From: gregkh <[email protected]>
Sent: Wednesday, August 5, 2020 1:46 AM
To: Eads, Gage <[email protected]>
Cc: Arnd Bergmann <[email protected]>; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctlsQuoted 9 lines · Gage
Quoted 9 lines
Quoted 9 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +9
-0+/* [7:0]: device revision, [15:8]: device version */ +#define DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev)) + +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response;Quoted 8 lines
Quoted 8 lines
drivers/misc/dlb2/dlb2_ioctl.c
Quoted 8 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +8
-0+int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret = dlb2_copy_from_user(dev, user_arg, size, &arg,sizeof(arg));
Quoted 11 lines
Quoted 10 lines
drivers/misc/dlb2/dlb2_ioctl.c line 66
Quoted 4 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +4
-0+if (ret) +return ret; + + ret =dlb2_copy_resp_to_user (dev, arg.response, &response);Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use
_IOWR()to define it and put all arguments into the same structure.Quoted 4 lines
I should've caught this in my earlier response, sorry. The device version command is intentionally the first in the user interface enum. My goal is for all device versions (e.g. DLB 1.0 in the future) to be accessible through a /dev/dlb%d node. To allow this, all drivers would support the
same
Quoted 1 line
device-version command as command 0, then the subsequent commands
can be
Quoted 3 lines
tailored to that particular device. User-space would query the version first to determine which set of ioctl commands it needs to use.
Quoted 8 lines
Quoted 1 line
So even though the response is constant (for now), it must occupy
command 0 for
Quoted 1 line
this design to work.
"versions" for ioctls just do not work, please don't go down that path, they should not be needed. See the many different discussions about this topic on lkml for other subsystem submissions if you are curious.
Quoted 5 lines
This approach is based on VFIO's modular ioctl design, which has a different API for Type1 vs. SPAPR IOMMUs. Similarly a DLB driver could have a different API for each device version (but each API would be fixed, not versioned). I didn't see any concerns on lkml over VFIO when it was originally submitted -- though that was 8 years ago, perhaps the community's feelings have changed since then.
Fixed apis for device types is usually the better way to go. See the review comments on the nitro_enclaves driver submission a few weeks ago for the full details.
greg k-h
RE: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctls
Quoted 85 lines
-----Original Message-----
From: gregkh <[email protected]>
Sent: Wednesday, August 5, 2020 10:18 AM
To: Eads, Gage <[email protected]>
Cc: Arnd Bergmann <[email protected]>; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctlsQuoted 11 lines · Gage
Quoted 11 lines
-----Original Message-----
From: gregkh <[email protected]>
Sent: Wednesday, August 5, 2020 1:46 AM
To: Eads, Gage <[email protected]>
Cc: Arnd Bergmann <[email protected]>; [email protected]; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 04/20] dlb2: add device ioctl layer and first 4 ioctlsQuoted 3 lines
Quoted 3 lines · Gage
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* [7:0]: device revision, [15:8]: device version */ +#define DLB2_SET_DEVICE_VERSION(ver, rev) (((ver) << 8) |(rev))
Quoted 16 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +7
-0+ +static int dlb2_ioctl_get_device_version (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_get_device_version_args arg; +struct dlb2_cmd_response response;Quoted 8 lines
Quoted 8 lines
drivers/misc/dlb2/dlb2_ioctl.c
Quoted 8 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +8
-0+int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + response.status =0 ; + response.id =DLB2_SET_DEVICE_VERSION (2 ,DLB2_REV_A0 ); + + ret = dlb2_copy_from_user(dev, user_arg, size, &arg,sizeof(arg));
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/misc/dlb2/dlb2_ioctl.c
Quoted 4 lines
drivers/misc/dlb2/dlb2_ioctl.c new file +4
-0+if (ret) +return ret; + + ret = dlb2_copy_resp_to_user(dev, arg.response,&response);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Better avoid any indirect pointers. As you always return a constant here, I think the entire ioctl command can be removed until you actually need it. If you have an ioctl command that needs both input and output, use
_IOWR()to define it and put all arguments into the same structure.I should've caught this in my earlier response, sorry. The device
version
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
command is intentionally the first in the user interface enum. My goal is for all device versions (e.g. DLB 1.0 in the future) to be
accessible
Quoted 1 line
Quoted 1 line
Quoted 1 line
through a /dev/dlb%d node. To allow this, all drivers would support
the
Quoted 2 lines
Quoted 2 lines
same
Quoted 1 line
device-version command as command 0, then the subsequent
commands
Quoted 2 lines
Quoted 2 lines
can be
Quoted 1 line
tailored to that particular device. User-space would query the version
first
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
to determine which set of ioctl commands it needs to use.
So even though the response is constant (for now), it must occupy
command 0 for
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
this design to work.
"versions" for ioctls just do not work, please don't go down that path, they should not be needed. See the many different discussions about this topic on lkml for other subsystem submissions if you are curious.
This approach is based on VFIO's modular ioctl design, which has a
different
Quoted 1 line
API for Type1 vs. SPAPR IOMMUs. Similarly a DLB driver could have a
different
Quoted 2 lines
API for each device version (but each API would be fixed, not versioned). I didn't see any concerns on lkml over VFIO when it was originally submitted
Quoted 7 lines
-- though
Quoted 1 line
that was 8 years ago, perhaps the community's feelings have changed
since then.
Fixed apis for device types is usually the better way to go. See the review comments on the
nitro_enclavesdriver submission a few weeks ago for the full details.
Thanks for the pointer -- I think we're on the same page regarding fixed APIs. I'll clarify the documentation for this ioctl in v2 so it's clear that its purpose is to support fixed APIs for different hardware versions/types.
Thanks,
Gage
PATCH 5/20 dlb2: add sched domain config and reset support
In reply to Gage EadsWhen a user requests to create a scheduling domain, the requested resources are validated then reserved for the scheduling domain. This takes place in dlb2_resource.c. Finally, the ioctl handler allocates an anonymous file descriptor for the domain.
Once created, user-space can use its file descriptor for the scheduling domain to configure the domain's resources (to be added in a subsequent commit). User-space can also get additional file descriptors (for multiprocess usage).
The driver maintains a reference count for each scheduling domain, incrementing it each time user-space requests a file descriptor and decrementing it in the file's release callback.
When the reference count transitions from 1->0 the driver automatically resets the scheduling domain's resources and makes them available for use by future applications. This ensures that applications that crash without explicitly cleaning up do not orphan device resources.
Broadly speaking, the scheduling domain reset logic progressively disables resources and flushes/drains them. The driver uses iosubmit_cmds512() to flush load-balanced and directed ports. At the end of the domain reset function, it resets hardware (register) state and software state.
This commit introduces device register definitions (dlb2_regs.h), used in this and upcoming commits.
--- drivers/misc/dlb2/dlb2_bitmap.h | 102 ++ drivers/misc/dlb2/dlb2_hw_types.h | 96 + drivers/misc/dlb2/dlb2_ioctl.c | 42 +- drivers/misc/dlb2/dlb2_main.c | 80 + drivers/misc/dlb2/dlb2_main.h | 25 + drivers/misc/dlb2/dlb2_pf_ops.c | 9 +- drivers/misc/dlb2/dlb2_regs.h | 3619 +++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.c | 3140 +++++++++++++++++++++++++++++++- drivers/misc/dlb2/dlb2_resource.h | 74 + include/uapi/linux/dlb2_user.h | 112 +- 10 files changed, 7273 insertions(+), 26 deletions(-)
drivers/misc/dlb2/dlb2_bitmap.h +102 -0
@@ -119,6 +119,108 @@ static inline int dlb2_bitmap_zero(struct dlb2_bitmap *bitmap) }/** +* dlb2_bitmap_set_range() - set a range of bitmap entries +* @bitmap: pointer to dlb2_bitmap structure. +* @bit: starting bit index. +* @len: length of the range. +* +* Return: +* Returns 0 upon success, < 0 otherwise. +* +* Errors: +* EINVAL - bitmap is NULL or is uninitialized, or the range exceeds the bitmap +* length. +*/ +static inline int dlb2_bitmap_set_range (struct dlb2_bitmap *bitmap, +unsigned int bit, +unsigned int len) +{ +if (!bitmap || !bitmap->map) +return -EINVAL ; + +if (bitmap->len <= bit) +return -EINVAL ; + +bitmap_set (bitmap->map, bit, len); + +return 0 ; +} + +/** +* dlb2_bitmap_clear_range() - clear a range of bitmap entries +* @bitmap: pointer to dlb2_bitmap structure. +* @bit: starting bit index. +* @len: length of the range. +* +* Return: +* Returns 0 upon success, < 0 otherwise. +* +* Errors: +* EINVAL - bitmap is NULL or is uninitialized, or the range exceeds the bitmap +* length. +*/ +static inline int dlb2_bitmap_clear_range (struct dlb2_bitmap *bitmap, +unsigned int bit, +unsigned int len) +{ +if (!bitmap || !bitmap->map) +return -EINVAL ; + +if (bitmap->len <= bit) +return -EINVAL ; + +bitmap_clear (bitmap->map, bit, len); + +return 0 ; +} + +/** +* dlb2_bitmap_find_set_bit_range() - find an range of set bits +* @bitmap: pointer to dlb2_bitmap structure. +* @len: length of the range. +* +* This function looks for a range of set bits of length @len. +* +* Return: +* Returns the base bit index upon success, < 0 otherwise. +* +* Errors: +* ENOENT - unable to find a length *len* range of set bits. +* EINVAL - bitmap is NULL or is uninitialized, or len is invalid. +*/ +static inline int dlb2_bitmap_find_set_bit_range (struct dlb2_bitmap *bitmap, +unsigned int len) +{ +struct dlb2_bitmap *complement_mask =NULL ; +int ret; + +if (!bitmap || !bitmap->map || len ==0 ) +return -EINVAL ; + +if (bitmap->len < len) +return -ENOENT ; + + ret =dlb2_bitmap_alloc (&complement_mask, bitmap->len); +if (ret) +return ret; + +dlb2_bitmap_zero (complement_mask); + +bitmap_complement (complement_mask->map, bitmap->map, bitmap->len); + + ret =bitmap_find_next_zero_area (complement_mask->map, + complement_mask->len, +0 , + len, +0 ); + +dlb2_bitmap_free (complement_mask); + +/* No set bit range of length len? */ +return (ret >= (int )bitmap->len) ? -ENOENT : ret; +} + +/** * dlb2_bitmap_count() - returns the number of set bits * @bitmap: pointer to dlb2_bitmap structure. *
drivers/misc/dlb2/dlb2_hw_types.h +96 -0
120 lines not on this page · raw message
drivers/misc/dlb2/dlb2_ioctl.c +41 -1
62 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.c +80 -0
92 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.h +25 -0
@@ -60,10 +60,18 @@ struct dlb2_device_ops { struct dlb2_cmd_response *resp);int (*get_num_resources)(struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args); +int (*reset_domain)(struct dlb2_hw *hw,u32 domain_id);void (*init_hardware)(struct dlb2_dev *dev); };extern struct dlb2_device_ops dlb2_pf_ops; +extern const struct file_operations dlb2_domain_fops; + +struct dlb2_domain { +struct dlb2_dev *dlb2_dev; +struct kref refcnt; +u8 id; +};struct dlb2_dev {struct pci_dev *pdev;
@@ -72,6 +80,7 @@ struct dlb2_dev {struct dlb2_device_ops *ops;struct list_head list;struct device *dlb2_device; +struct dlb2_domain *sched_domains[DLB2_MAX_NUM_DOMAINS ];/* * The resource mutex serializes access to driver data structures and * hardware registers.
@@ -80,6 +89,22 @@ struct dlb2_dev {enum dlb2_device_type type;int id;dev_t dev_number; + u8 domain_reset_failed; }; +int dlb2_init_domain (struct dlb2_dev *dlb2_dev,u32 domain_id); +void dlb2_free_domain (struct kref *kref); + +#define DLB2_HW_ERR (dlb2, ...) do { \ + struct dlb2_dev *dev; \ + dev = container_of(dlb2, struct dlb2_dev, hw); \ + dev_err(dev->dlb2_device, __VA_ARGS__); \ +} while (0) + +#define DLB2_HW_DBG (dlb2, ...) do { \ + struct dlb2_dev *dev; \ + dev = container_of(dlb2, struct dlb2_dev, hw); \ + dev_dbg(dev->dlb2_device, __VA_ARGS__); \ +} while (0) +#endif /* __DLB2_MAIN_H */
drivers/misc/dlb2/dlb2_pf_ops.c +8 -1
@@ -203,7 +203,7 @@ dlb2_pf_create_sched_domain(struct dlb2_hw *hw,struct dlb2_create_sched_domain_args *args, struct dlb2_cmd_response *resp) { -return 0 ; + return dlb2_hw_create_sched_domain(hw, args, resp, false, 0); } static int
@@ -213,6 +213,12 @@ dlb2_pf_get_num_resources(struct dlb2_hw *hw,return dlb2_hw_get_num_resources (hw, args, false,0 ); } +static int +dlb2_pf_reset_domain (struct dlb2_hw *hw,u32 id) +{ +return dlb2_reset_domain (hw, id, false,0 ); +} +/********************************/ /****** DLB2 PF Device Ops ******/ /********************************/
@@ -230,5 +236,6 @@ struct dlb2_device_ops dlb2_pf_ops = { .wait_for_device_ready = dlb2_pf_wait_for_device_ready, .create_sched_domain = dlb2_pf_create_sched_domain, .get_num_resources = dlb2_pf_get_num_resources, + .reset_domain = dlb2_pf_reset_domain, .init_hardware = dlb2_pf_init_hardware, };
drivers/misc/dlb2/dlb2_regs.h +3619 -0
2,545 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.c +3136 -4
3,140 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +74 -0
74 lines not on this page · raw message
include/uapi/linux/dlb2_user.h +92 -20
112 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.6
Part of the diff is not shown here. View the raw message.
PATCH 6/20 dlb2: add ioctl to get sched domain fd
In reply to Gage EadsTo create the file and install it in the current process's file table, the driver uses anon_inode_getfd(). The calling process can then use this fd to issue ioctls for configuration of the scheduilng domain's resources (to be added in an upcoming commit).
This design means that any application with sufficient permissions to access the /dev/dlb<N> file can request the fd of any scheduling domain -- potentially one that was created by another process. One way to ensure that dlb applications cannot access each other's scheduling domains is to use virtualization; that is, create multiple virtual functions -- and thus multiple /dev/dlb<N> nodes -- each using unique file permissions.
--- drivers/misc/dlb2/dlb2_ioctl.c | 68 ++++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/dlb2_user.h | 30 +++++++++++++++++++ 2 files changed, 98 insertions(+)
drivers/misc/dlb2/dlb2_ioctl.c +68 -0
@@ -147,6 +147,73 @@ static int dlb2_ioctl_create_sched_domain(struct dlb2_dev *dev,return ret; } +static int dlb2_ioctl_get_sched_domain_fd (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_get_sched_domain_fd_args arg; +struct dlb2_cmd_response response = {0 }; +struct dlb2_domain *domain; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +if (arg.domain_id >=DLB2_MAX_NUM_DOMAINS ) { +dev_err (dev->dlb2_device, +"[%s()] Invalid domain id %u\n" , + __func__, arg.domain_id); + response.status =DLB2_ST_INVALID_DOMAIN_ID ; + ret = -EINVAL ; + goto copy; + } + +mutex_lock (&dev->resource_mutex); + + domain = dev->sched_domains[arg.domain_id]; + +if (!domain) { +dev_err (dev->dlb2_device, +"[%s()] Domain %u not configured\n" , + __func__, arg.domain_id); + response.status =DLB2_ST_DOMAIN_UNAVAILABLE ; + ret = -ENOENT ; + goto unlock; + } + + ret =anon_inode_getfd ("[dlb2domain]" , &dlb2_domain_fops, + domain,O_RDWR ); + + response.id = ret; + +if (ret >=0 ) { +kref_get (&domain->refcnt); + + ret =0 ; + } + +unlock: +mutex_unlock (&dev->resource_mutex); + +copy: +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} +static int dlb2_ioctl_get_num_resources (struct dlb2_dev *dev,unsigned long user_arg,u16 size)
@@ -205,6 +272,7 @@ typedef int (*dlb2_ioctl_callback_fn_t)(struct dlb2_dev *dev,static dlb2_ioctl_callback_fn_t dlb2_ioctl_callback_fns[NUM_DLB2_CMD ] = { dlb2_ioctl_get_device_version, dlb2_ioctl_create_sched_domain, + dlb2_ioctl_get_sched_domain_fd, dlb2_ioctl_get_num_resources, dlb2_ioctl_get_driver_version, };
include/uapi/linux/dlb2_user.h +30 -0
@@ -239,6 +239,31 @@ struct dlb2_create_sched_domain_args { };/* +* DLB2_CMD_GET_SCHED_DOMAIN_FD: Get an anonymous scheduling domain fd. +* +* The domain must have been previously created with the ioctl +* DLB2_CMD_CREATE_SCHED_DOMAIN. The domain is reset when all +* its open files and memory mappings are closed. +* +* Input parameters: +* - domain_id: Domain ID. +* - padding0: Reserved for future use. +* +* Output parameters: +* - response: pointer to a struct dlb2_cmd_response. +* response.status: Detailed error code. In certain cases, such as if the +* response pointer is invalid, the driver won't set status. +* response.id: domain fd. +*/ +struct dlb2_get_sched_domain_fd_args { +/* Output parameters */ +__u64 response; +/* Input parameters */ +__u32 domain_id; +__u32 padding0; +}; + +/* * DLB2_CMD_GET_NUM_RESOURCES: Return the number of available resources * (queues, ports, etc.) that this device owns. *
@@ -275,6 +300,7 @@ struct dlb2_get_num_resources_args {enum dlb2_user_interface_commands {DLB2_CMD_GET_DEVICE_VERSION ,DLB2_CMD_CREATE_SCHED_DOMAIN , +DLB2_CMD_GET_SCHED_DOMAIN_FD ,DLB2_CMD_GET_NUM_RESOURCES ,DLB2_CMD_GET_DRIVER_VERSION ,
@@ -296,6 +322,10 @@ enum dlb2_user_interface_commands {_IOWR (DLB2_IOC_MAGIC , \DLB2_CMD_CREATE_SCHED_DOMAIN , \ struct dlb2_create_sched_domain_args) +#define DLB2_IOC_GET_SCHED_DOMAIN_FD \ + _IOWR(DLB2_IOC_MAGIC, \ + DLB2_CMD_GET_SCHED_DOMAIN_FD, \ + struct dlb2_get_sched_domain_fd_args)#define DLB2_IOC_GET_NUM_RESOURCES \ _IOWR(DLB2_IOC_MAGIC, \ DLB2_CMD_GET_NUM_RESOURCES, \
Signature · 1 line
2.13.6
PATCH 7/20 dlb2: add runtime power-management support
In reply to Gage EadsThe driver's power-management policy is to put the device in D0 when in use (when there are any open device files or memory mappings, or there are any virtual devices), and leave it in D3Hot otherwise. This includes resume/suspend callbacks; when the device resumes, the driver resets the hardware to a known good state.
--- drivers/misc/dlb2/dlb2_ioctl.c | 2 ++ drivers/misc/dlb2/dlb2_main.c | 79 +++++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_main.h | 2 ++ drivers/misc/dlb2/dlb2_pf_ops.c | 30 ++++++++++++++++ 4 files changed, 113 insertions(+)
drivers/misc/dlb2/dlb2_ioctl.c +2 -0
@@ -197,6 +197,8 @@ static int dlb2_ioctl_get_sched_domain_fd(struct dlb2_dev *dev,if (ret >=0 ) {kref_get (&domain->refcnt); + dev->ops->inc_pm_refcnt (dev->pdev, true); + ret =0 ; }
drivers/misc/dlb2/dlb2_main.c +79 -0
125 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.h +2 -0
@@ -41,6 +41,8 @@ struct dlb2_device_ops {int (*map_pci_bar_space)(struct dlb2_dev *dev,struct pci_dev *pdev);void (*unmap_pci_bar_space)(struct dlb2_dev *dev,struct pci_dev *pdev); +void (*inc_pm_refcnt)(struct pci_dev *pdev,bool resume); +void (*dec_pm_refcnt)(struct pci_dev *pdev);int (*init_driver_state)(struct dlb2_dev *dev);void (*free_driver_state)(struct dlb2_dev *dev); int (*device_create)(struct dlb2_dev *dlb2_dev,
drivers/misc/dlb2/dlb2_pf_ops.c +30 -0
@@ -2,11 +2,39 @@/* Copyright(c) 2017-2020 Intel Corporation */ #include <linux/delay.h> +#include <linux/pm_runtime.h> #include "dlb2_main.h" #include "dlb2_regs.h" #include "dlb2_resource.h" +/***********************************/ +/****** Runtime PM management ******/ +/***********************************/ + +static void +dlb2_pf_pm_inc_refcnt (struct pci_dev *pdev,bool resume) +{ +if (resume) +/* +* Increment the device's usage count and immediately wake it +* if it was suspended. +*/ +pm_runtime_get_sync (&pdev->dev); +else +pm_runtime_get_noresume (&pdev->dev); +} + +static void +dlb2_pf_pm_dec_refcnt (struct pci_dev *pdev) +{ +/* +* Decrement the device's usage count and suspend it if the +* count reaches zero. +*/ +pm_runtime_put_sync_suspend (&pdev->dev); +} +/********************************/ /****** PCI BAR management ******/ /********************************/
@@ -226,6 +254,8 @@ dlb2_pf_reset_domain(struct dlb2_hw *hw, u32 id)struct dlb2_device_ops dlb2_pf_ops = { .map_pci_bar_space = dlb2_pf_map_pci_bar_space, .unmap_pci_bar_space = dlb2_pf_unmap_pci_bar_space, + .inc_pm_refcnt = dlb2_pf_pm_inc_refcnt, + .dec_pm_refcnt = dlb2_pf_pm_dec_refcnt, .init_driver_state = dlb2_pf_init_driver_state, .free_driver_state = dlb2_pf_free_driver_state, .device_create = dlb2_pf_device_create,
Signature · 1 line
2.13.6
PATCH 8/20 dlb2: add queue create and queue-depth-get ioctls
In reply to Gage EadsWhen a CPU enqueues a queue entry (QE) to DLB 2.0, the QE entry is sent to a DLB 2.0 queue. These queues hold queue entries (QEs) that have not yet been scheduled to a destination port. The queue's depth is the number of QEs residing in a queue.
Each queue supports multiple priority levels, and while a directed queue has a 1:1 mapping with a directed port, load-balanced queues can be configured with a set of load-balanced ports that software desires the queue's QEs to be scheduled to.
--- drivers/misc/dlb2/dlb2_ioctl.c | 82 +++++ drivers/misc/dlb2/dlb2_ioctl.h | 5 + drivers/misc/dlb2/dlb2_main.c | 17 + drivers/misc/dlb2/dlb2_main.h | 16 + drivers/misc/dlb2/dlb2_pf_ops.c | 40 +++ drivers/misc/dlb2/dlb2_resource.c | 732 ++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 125 +++++++ include/uapi/linux/dlb2_user.h | 142 ++++++++ 8 files changed, 1159 insertions(+)
drivers/misc/dlb2/dlb2_ioctl.c +82 -0
@@ -44,6 +44,88 @@ static int dlb2_copy_resp_to_user(struct dlb2_dev *dev,return 0 ; } +/* +* The DLB domain ioctl callback template minimizes replication of boilerplate +* code to copy arguments, acquire and release the resource lock, and execute +* the command. The arguments and response structure name should have the +* format dlb2_<lower_name>_args. +*/ +#define DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE (lower_name) \ +static int dlb2_domain_ioctl_##lower_name(struct dlb2_dev *dev, \ + struct dlb2_domain *domain, \ + unsigned long user_arg, \ + u16 size) \ +{ \ + struct dlb2_##lower_name##_args arg; \ + struct dlb2_cmd_response response = {0}; \ + int ret; \ + \ + dev_dbg(dev->dlb2_device, "Entering %s()\n", __func__); \ + \ + ret = dlb2_copy_from_user(dev, user_arg, size, &arg, sizeof(arg)); \ + if (ret) \ + return ret; \ + \ +/* Copy zeroes to verify the user-provided response pointer */ \ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); \ +if (ret) \ +return ret; \ + \ +mutex_lock (&dev->resource_mutex); \ + \ + ret = dev->ops->lower_name (&dev->hw, \ + domain->id, \ + &arg, \ + &response); \ + \ +mutex_unlock (&dev->resource_mutex); \ + \ + if (copy_to_user((void __user *)arg.response, \ + &response, \ +sizeof (response))) \ +return -EFAULT ; \ + \ +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); \ + \ +return ret; \ +} + +DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE (create_ldb_queue) +DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE (create_dir_queue ) +DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE (get_ldb_queue_depth) +DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE (get_dir_queue_depth) + +typedef int (*dlb2_domain_ioctl_callback_fn_t)(struct dlb2_dev *dev, +struct dlb2_domain *domain, +unsigned long arg, + u16 size); + +static dlb2_domain_ioctl_callback_fn_t +dlb2_domain_ioctl_callback_fns[NUM_DLB2_DOMAIN_CMD ] = { + dlb2_domain_ioctl_create_ldb_queue, + dlb2_domain_ioctl_create_dir_queue, + dlb2_domain_ioctl_get_ldb_queue_depth, + dlb2_domain_ioctl_get_dir_queue_depth, +}; + +int dlb2_domain_ioctl_dispatcher (struct dlb2_dev *dev, +struct dlb2_domain *domain, +unsigned int cmd, +unsigned long arg) +{ +int cmd_nr =_IOC_NR (cmd); +u16 sz =_IOC_SIZE (cmd); + +if (cmd_nr >=NUM_DLB2_DOMAIN_CMD ) { +dev_err (dev->dlb2_device, +"[%s()] Unexpected DLB DOMAIN command %d\n" , + __func__,_IOC_NR (cmd)); +return -1 ; + } + +return dlb2_domain_ioctl_callback_fns[cmd_nr](dev, domain, arg, sz); +} +/* [7:0]: device revision, [15:8]: device version */ #define DLB2_SET_DEVICE_VERSION (ver, rev) (((ver) << 8) | (rev))
drivers/misc/dlb2/dlb2_ioctl.h +5 -0
@@ -11,4 +11,9 @@ int dlb2_ioctl_dispatcher(struct dlb2_dev *dev,unsigned int cmd, unsigned long arg); +int dlb2_domain_ioctl_dispatcher (struct dlb2_dev *dev, +struct dlb2_domain *domain, +unsigned int cmd, +unsigned long arg); +#endif /* __DLB2_IOCTL_H */
drivers/misc/dlb2/dlb2_main.c +17 -0
@@ -180,9 +180,26 @@ static int dlb2_domain_close(struct inode *i, struct file *f)return ret; } +static long +dlb2_domain_ioctl (struct file *f,unsigned int cmd,unsigned long arg) +{ +struct dlb2_domain *domain = f->private_data; +struct dlb2_dev *dev = domain->dlb2_dev; + +if (_IOC_TYPE (cmd) !=DLB2_IOC_MAGIC ) { +dev_err (dev->dlb2_device, +"[%s()] Bad magic number!\n" , __func__); +return -EINVAL ; + } + +return dlb2_domain_ioctl_dispatcher (dev, domain, cmd, arg); +} +const struct file_operations dlb2_domain_fops = { .owner =THIS_MODULE , .release = dlb2_domain_close, + .unlocked_ioctl = dlb2_domain_ioctl, + .compat_ioctl = compat_ptr_ioctl, };/**********************************/
drivers/misc/dlb2/dlb2_main.h +16 -0
@@ -60,9 +60,25 @@ struct dlb2_device_ops {int (*create_sched_domain)(struct dlb2_hw *hw,struct dlb2_create_sched_domain_args *args,struct dlb2_cmd_response *resp); +int (*create_ldb_queue)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_create_ldb_queue_args *args, +struct dlb2_cmd_response *resp); +int (*create_dir_queue)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_create_dir_queue_args *args, +struct dlb2_cmd_response *resp);int (*get_num_resources)(struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args);int (*reset_domain)(struct dlb2_hw *hw,u32 domain_id); +int (*get_ldb_queue_depth)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_get_ldb_queue_depth_args *args, +struct dlb2_cmd_response *resp); +int (*get_dir_queue_depth)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_get_dir_queue_depth_args *args, +struct dlb2_cmd_response *resp);void (*init_hardware)(struct dlb2_dev *dev); };
drivers/misc/dlb2/dlb2_pf_ops.c +40 -0
@@ -235,6 +235,24 @@ dlb2_pf_create_sched_domain(struct dlb2_hw *hw, }static int +dlb2_pf_create_ldb_queue (struct dlb2_hw *hw, +u32 id, +struct dlb2_create_ldb_queue_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_create_ldb_queue (hw, id, args, resp, false,0 ); +} + +static int +dlb2_pf_create_dir_queue (struct dlb2_hw *hw, +u32 id, +struct dlb2_create_dir_queue_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_create_dir_queue (hw, id, args, resp, false,0 ); +} + +static int dlb2_pf_get_num_resources (struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args) {
@@ -247,6 +265,24 @@ dlb2_pf_reset_domain(struct dlb2_hw *hw, u32 id)return dlb2_reset_domain (hw, id, false,0 ); } +static int +dlb2_pf_get_ldb_queue_depth (struct dlb2_hw *hw, +u32 id, +struct dlb2_get_ldb_queue_depth_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_get_ldb_queue_depth (hw, id, args, resp, false,0 ); +} + +static int +dlb2_pf_get_dir_queue_depth (struct dlb2_hw *hw, +u32 id, +struct dlb2_get_dir_queue_depth_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_get_dir_queue_depth (hw, id, args, resp, false,0 ); +} +/********************************/ /****** DLB2 PF Device Ops ******/ /********************************/
@@ -265,7 +301,11 @@ struct dlb2_device_ops dlb2_pf_ops = { .enable_pm = dlb2_pf_enable_pm, .wait_for_device_ready = dlb2_pf_wait_for_device_ready, .create_sched_domain = dlb2_pf_create_sched_domain, + .create_ldb_queue = dlb2_pf_create_ldb_queue, + .create_dir_queue = dlb2_pf_create_dir_queue, .get_num_resources = dlb2_pf_get_num_resources, .reset_domain = dlb2_pf_reset_domain, + .get_ldb_queue_depth = dlb2_pf_get_ldb_queue_depth, + .get_dir_queue_depth = dlb2_pf_get_dir_queue_depth, .init_hardware = dlb2_pf_init_hardware, };
drivers/misc/dlb2/dlb2_resource.c +732 -0
774 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +125 -0
137 lines not on this page · raw message
include/uapi/linux/dlb2_user.h +142 -0
153 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 9/20 dlb2: add ioctl to configure ports, query poll mode
In reply to Gage EadsThe port is a core's interface to the DLB, and it consists of an MMIO page (the "producer port" (PP)) through which the core enqueues a queue entry and an in-memory queue (the "consumer queue" (CQ)) to which the device schedules QEs. The driver allocates DMA memory for each port's CQ, and frees this memory during domain reset or driver removal. A subsequent commit will add the mmap interface for an application to directly access the PP and CQ regions.
The device supports two formats ("standard" and "sparse") for CQ entries, dubbed the "poll mode". This (device-wide) mode is selected by the driver; to determine the mode at run time, the driver provides an ioctl for user-space software to query which mode the driver has configured. In this way, the policy of which mode to use is decoupled from user-space software.
--- drivers/misc/dlb2/dlb2_hw_types.h | 1 + drivers/misc/dlb2/dlb2_ioctl.c | 194 ++++++++ drivers/misc/dlb2/dlb2_main.c | 73 +++ drivers/misc/dlb2/dlb2_main.h | 23 + drivers/misc/dlb2/dlb2_pf_ops.c | 46 ++ drivers/misc/dlb2/dlb2_resource.c | 922 ++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 89 ++++ include/uapi/linux/dlb2_user.h | 102 +++++ 8 files changed, 1450 insertions(+)
drivers/misc/dlb2/dlb2_hw_types.h +1 -0
@@ -321,6 +321,7 @@ struct dlb2_hw {/* Virtualization */ int virt_mode; + unsigned int pasid[DLB2_MAX_NUM_VDEVS]; };#endif /* __DLB2_HW_TYPES_H */
drivers/misc/dlb2/dlb2_ioctl.c +194 -0
218 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.c +73 -0
90 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.h +23 -0
@@ -68,6 +68,16 @@ struct dlb2_device_ops {u32 domain_id, struct dlb2_create_dir_queue_args *args, struct dlb2_cmd_response *resp); +int (*create_ldb_port)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_create_ldb_port_args *args, +uintptr_t cq_dma_base, +struct dlb2_cmd_response *resp); +int (*create_dir_port)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_create_dir_port_args *args, +uintptr_t cq_dma_base, +struct dlb2_cmd_response *resp);int (*get_num_resources)(struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args);int (*reset_domain)(struct dlb2_hw *hw,u32 domain_id);
@@ -80,11 +90,22 @@ struct dlb2_device_ops {struct dlb2_get_dir_queue_depth_args *args, struct dlb2_cmd_response *resp);void (*init_hardware)(struct dlb2_dev *dev); +int (*query_cq_poll_mode)(struct dlb2_dev *dev, +struct dlb2_cmd_response *user_resp); };extern struct dlb2_device_ops dlb2_pf_ops;extern const struct file_operations dlb2_domain_fops; +struct dlb2_port { +void *cq_base; +dma_addr_t cq_dma_base; +struct dlb2_domain *domain; +int id; +u8 is_ldb; +u8 valid; +}; +struct dlb2_domain {struct dlb2_dev *dlb2_dev;struct kref refcnt;
@@ -99,6 +120,8 @@ struct dlb2_dev {struct list_head list;struct device *dlb2_device;struct dlb2_domain *sched_domains[DLB2_MAX_NUM_DOMAINS ]; +struct dlb2_port ldb_port[DLB2_MAX_NUM_LDB_PORTS ]; +struct dlb2_port dir_port[DLB2_MAX_NUM_DIR_PORTS ];/* * The resource mutex serializes access to driver data structures and * hardware registers.
drivers/misc/dlb2/dlb2_pf_ops.c +46 -0
76 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.c +922 -0
943 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +89 -0
99 lines not on this page · raw message
include/uapi/linux/dlb2_user.h +102 -0
144 lines not on this page · raw message
Signature · 1 line
2.13.6
Arnd Bergmann
maintainerRe: [PATCH 09/20] dlb2: add ioctl to configure ports, query poll mode
Quoted 12 lines · Gage Eads
enum
dlb2_user_interface_commands{
DLB2_CMD_GET_DEVICE_VERSION,
DLB2_CMD_CREATE_SCHED_DOMAIN,
DLB2_CMD_GET_SCHED_DOMAIN_FD,
DLB2_CMD_GET_NUM_RESOURCES,
DLB2_CMD_GET_DRIVER_VERSION,include/uapi/linux/dlb2_user.h +1
-0+DLB2_CMD_QUERY_CQ_POLL_MODE ,/* NUM_DLB2_CMD must be last */ NUM_DLB2_CMD,
include/uapi/linux/dlb2_user.h struct dlb2_get_dir_queue_depth_args { · line 519
Quoted 7 lines
include/uapi/linux/dlb2_user.h +2
-0@@ -427,6 +513,8 @@ struct dlb2_get_dir_queue_depth_args {enum dlb2_domain_user_interface_commands {DLB2_DOMAIN_CMD_CREATE_LDB_QUEUE ,DLB2_DOMAIN_CMD_CREATE_DIR_QUEUE , +DLB2_DOMAIN_CMD_CREATE_LDB_PORT , +DLB2_DOMAIN_CMD_CREATE_DIR_PORT ,DLB2_DOMAIN_CMD_GET_LDB_QUEUE_DEPTH ,DLB2_DOMAIN_CMD_GET_DIR_QUEUE_DEPTH ,
You cannot add new commands in the middle without changing the ABI.
Maybe use individual #define lines in place of the enum to make sure these remain constants, or add a numeric value for each one when they are originally introduced.
(yes, I realize this is the initial contribution of the new driver, but it still seems wrong to have it change in the middle of the series).
Arnd
RE: [PATCH 09/20] dlb2: add ioctl to configure ports, query poll mode
Quoted 35 lines
-----Original Message-----
From: Arnd Bergmann <[email protected]>
Sent: Sunday, July 12, 2020 10:34 AM
To: Eads, Gage <[email protected]>
Cc: [email protected]; gregkh <[email protected]>; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>
Subject: Re: [PATCH 09/20] dlb2: add ioctl to configure ports, query poll modeQuoted 12 lines · Gage Eads
enum
dlb2_user_interface_commands{
DLB2_CMD_GET_DEVICE_VERSION,
DLB2_CMD_CREATE_SCHED_DOMAIN,
DLB2_CMD_GET_SCHED_DOMAIN_FD,
DLB2_CMD_GET_NUM_RESOURCES,
DLB2_CMD_GET_DRIVER_VERSION,include/uapi/linux/dlb2_user.h +1
-0+DLB2_CMD_QUERY_CQ_POLL_MODE ,/* NUM_DLB2_CMD must be last */ NUM_DLB2_CMD,include/uapi/linux/dlb2_user.h struct dlb2_get_dir_queue_depth_args { enum · line 519
Quoted 7 lines
include/uapi/linux/dlb2_user.h +2
-0@@ -427,6 +513,8 @@ struct dlb2_get_dir_queue_depth_args { enum dlb2_domain_user_interface_commands {DLB2_DOMAIN_CMD_CREATE_LDB_QUEUE ,DLB2_DOMAIN_CMD_CREATE_DIR_QUEUE , +DLB2_DOMAIN_CMD_CREATE_LDB_PORT , +DLB2_DOMAIN_CMD_CREATE_DIR_PORT ,DLB2_DOMAIN_CMD_GET_LDB_QUEUE_DEPTH , DLB2_DOMAIN_CMD_GET_DIR_QUEUE_DEPTH,You cannot add new commands in the middle without changing the ABI.
Quoted 6 lines
Maybe use individual #define lines in place of the enum to make sure these remain constants, or add a numeric value for each one when they are originally introduced.
(yes, I realize this is the initial contribution of the new driver, but it still seems wrong to have it change in the middle of the series).
Ok, no problem -- I was assuming this patchset would be considered an atomic unit. I'll correct this in V2.
Thanks,
Gage
Quoted 2 lines
Arnd
PATCH 10/20 dlb2: add port mmap support
In reply to Gage EadsOnce a port is created, the application can mmap the corresponding DMA memory and MMIO into user-space. This allows user-space applications to do (performance-sensitive) enqueue and dequeue independent of the kernel driver.
The mmap callback is only available through special port files: a producer port (PP) file and a consumer queue (CQ) file. User-space gets an fd for these files by calling a new ioctl, DLB2_DOMAIN_CMD_GET_{LDB, DIR}_PORT_{PP, CQ}_FD, and passing in a port ID. If the ioctl succeeds, the returned fd can be used to mmap that port's PP/CQ.
Device reset requires first unmapping all user-space mappings, to prevent applications from interfering with the reset operation. To this end, the driver uses a single inode -- allocated when the first PP/CQ file is created, and freed when the last such file is closed -- and attaches all port files to this common inode, as done elsewhere in Linux (e.g. cxl, dax).
Allocating this inode requires creating a pseudo-filesystem. The driver initializes this FS when the inode is allocated, and frees the FS after the inode is freed.
The driver doesn't use anon_inode_getfd() for these port mmap files because the anon inode layer uses a single inode that is shared with other kernel components -- calling unmap_mapping_range() on that shared inode would likely break the kernel.
--- drivers/misc/dlb2/Makefile | 1 + drivers/misc/dlb2/dlb2_file.c | 133 +++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_file.h | 19 ++++ drivers/misc/dlb2/dlb2_ioctl.c | 203 ++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_main.c | 109 ++++++++++++++++++++ drivers/misc/dlb2/dlb2_main.h | 13 +++ drivers/misc/dlb2/dlb2_pf_ops.c | 22 +++++ drivers/misc/dlb2/dlb2_resource.c | 99 +++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 50 ++++++++++ include/uapi/linux/dlb2_user.h | 60 +++++++++++ 10 files changed, 709 insertions(+) create mode 100644 drivers/misc/dlb2/dlb2_file.c create mode 100644 drivers/misc/dlb2/dlb2_file.h
drivers/misc/dlb2/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_INTEL_DLB2) := dlb2.o dlb2-objs := \ dlb2_main.o \ + dlb2_file.o \ dlb2_ioctl.o \ dlb2_pf_ops.o \ dlb2_resource.o \
drivers/misc/dlb2/dlb2_file.c new file +133 -0
133 lines not on this page · raw message
drivers/misc/dlb2/dlb2_file.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* Copyright(c) 2020 Intel Corporation +*/ + +#ifndef __DLB2_FILE_H +#define __DLB2_FILE_H + +#include <linux/file.h> + +#include "dlb2_main.h" + +void dlb2_release_fs (struct dlb2_dev *dev); + +struct file *dlb2_getfile (struct dlb2_dev *dev, +int flags, +const struct file_operations *fops, +const char *name); + +#endif /* __DLB2_FILE_H */
drivers/misc/dlb2/dlb2_ioctl.c +203 -0
221 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.c +109 -0
121 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.h +13 -0
@@ -81,6 +81,12 @@ struct dlb2_device_ops {int (*get_num_resources)(struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args);int (*reset_domain)(struct dlb2_hw *hw,u32 domain_id); +int (*ldb_port_owned_by_domain)(struct dlb2_hw *hw, +u32 domain_id, +u32 port_id); +int (*dir_port_owned_by_domain)(struct dlb2_hw *hw, +u32 domain_id, +u32 port_id); int (*get_ldb_queue_depth)(struct dlb2_hw *hw, u32 domain_id, struct dlb2_get_ldb_queue_depth_args *args,
@@ -96,6 +102,8 @@ struct dlb2_device_ops {extern struct dlb2_device_ops dlb2_pf_ops;extern const struct file_operations dlb2_domain_fops; +extern const struct file_operations dlb2_pp_fops; +extern const struct file_operations dlb2_cq_fops;struct dlb2_port {void *cq_base;
@@ -123,6 +131,11 @@ struct dlb2_dev {struct dlb2_port ldb_port[DLB2_MAX_NUM_LDB_PORTS ];struct dlb2_port dir_port[DLB2_MAX_NUM_DIR_PORTS ];/* +* Anonymous inode used to share an address_space for all domain +* device file mappings. +*/ +struct inode *inode; +/* * The resource mutex serializes access to driver data structures and * hardware registers. */
drivers/misc/dlb2/dlb2_pf_ops.c +22 -0
@@ -326,6 +326,26 @@ dlb2_pf_query_cq_poll_mode(struct dlb2_dev *dlb2_dev,return 0 ; } +/**************************************/ +/****** Resource query callbacks ******/ +/**************************************/ + +static int +dlb2_pf_ldb_port_owned_by_domain (struct dlb2_hw *hw, +u32 domain_id, +u32 port_id) +{ +return dlb2_ldb_port_owned_by_domain (hw, domain_id, port_id, false,0 ); +} + +static int +dlb2_pf_dir_port_owned_by_domain (struct dlb2_hw *hw, +u32 domain_id, +u32 port_id) +{ +return dlb2_dir_port_owned_by_domain (hw, domain_id, port_id, false,0 ); +} +/********************************/ /****** DLB2 PF Device Ops ******/ /********************************/
@@ -350,6 +370,8 @@ struct dlb2_device_ops dlb2_pf_ops = { .create_dir_port = dlb2_pf_create_dir_port, .get_num_resources = dlb2_pf_get_num_resources, .reset_domain = dlb2_pf_reset_domain, + .ldb_port_owned_by_domain = dlb2_pf_ldb_port_owned_by_domain, + .dir_port_owned_by_domain = dlb2_pf_dir_port_owned_by_domain, .get_ldb_queue_depth = dlb2_pf_get_ldb_queue_depth, .get_dir_queue_depth = dlb2_pf_get_dir_queue_depth, .init_hardware = dlb2_pf_init_hardware,
drivers/misc/dlb2/dlb2_resource.c +99 -0
117 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +50 -0
56 lines not on this page · raw message
include/uapi/linux/dlb2_user.h +60 -0
83 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 11/20 dlb2: add start domain ioctl
In reply to Gage EadsOnce a scheduling domain and its resources have been configured, the start domain ioctl is called to enable its ports to begin enqueueing to the device. Once started, the domain's resources cannot be configured again until after the domain is reset.
--- drivers/misc/dlb2/dlb2_ioctl.c | 2 + drivers/misc/dlb2/dlb2_main.h | 4 ++ drivers/misc/dlb2/dlb2_pf_ops.c | 10 ++++ drivers/misc/dlb2/dlb2_resource.c | 120 ++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 30 ++++++++++ include/uapi/linux/dlb2_user.h | 24 ++++++++ 6 files changed, 190 insertions(+)
drivers/misc/dlb2/dlb2_ioctl.c +2 -0
@@ -93,6 +93,7 @@ static int dlb2_domain_ioctl_##lower_name(struct dlb2_dev *dev, \ DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(create_ldb_queue) DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(create_dir_queue) +DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(start_domain) DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(get_ldb_queue_depth) DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(get_dir_queue_depth)
@@ -465,6 +466,7 @@ dlb2_domain_ioctl_callback_fns[NUM_DLB2_DOMAIN_CMD] = { dlb2_domain_ioctl_create_dir_queue, dlb2_domain_ioctl_create_ldb_port, dlb2_domain_ioctl_create_dir_port, + dlb2_domain_ioctl_start_domain, dlb2_domain_ioctl_get_ldb_queue_depth, dlb2_domain_ioctl_get_dir_queue_depth, dlb2_domain_ioctl_get_ldb_port_pp_fd,
drivers/misc/dlb2/dlb2_main.h +4 -0
@@ -78,6 +78,10 @@ struct dlb2_device_ops {struct dlb2_create_dir_port_args *args, uintptr_t cq_dma_base, struct dlb2_cmd_response *resp); +int (*start_domain)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_start_domain_args *args, +struct dlb2_cmd_response *resp);int (*get_num_resources)(struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args);int (*reset_domain)(struct dlb2_hw *hw,u32 domain_id);
drivers/misc/dlb2/dlb2_pf_ops.c +10 -0
@@ -282,6 +282,15 @@ dlb2_pf_create_dir_port(struct dlb2_hw *hw, }static int +dlb2_pf_start_domain (struct dlb2_hw *hw, +u32 id, +struct dlb2_start_domain_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_start_domain (hw, id, args, resp, false,0 ); +} + +static int dlb2_pf_get_num_resources (struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args) {
@@ -368,6 +377,7 @@ struct dlb2_device_ops dlb2_pf_ops = { .create_dir_queue = dlb2_pf_create_dir_queue, .create_ldb_port = dlb2_pf_create_ldb_port, .create_dir_port = dlb2_pf_create_dir_port, + .start_domain = dlb2_pf_start_domain, .get_num_resources = dlb2_pf_get_num_resources, .reset_domain = dlb2_pf_reset_domain, .ldb_port_owned_by_domain = dlb2_pf_ldb_port_owned_by_domain,
drivers/misc/dlb2/dlb2_resource.c +120 -0
132 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +30 -0
@@ -209,6 +209,36 @@ int dlb2_hw_create_ldb_port(struct dlb2_hw *hw, unsigned int vdev_id);/** +* dlb2_hw_start_domain() - start a scheduling domain +* @hw: dlb2_hw handle for a particular device. +* @domain_id: domain ID. +* @args: start domain arguments. +* @resp: response structure. +* @vdev_request: indicates whether this request came from a vdev. +* @vdev_id: If vdev_request is true, this contains the vdev's ID. +* +* This function starts a scheduling domain, which allows applications to send +* traffic through it. Once a domain is started, its resources can no longer be +* configured (besides QID remapping and port enable/disable). +* +* A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual +* device. +* +* Return: +* Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is +* assigned a detailed error code from enum dlb2_error. +* +* Errors: +* EINVAL - the domain is not configured, or the domain is already started. +*/ +int dlb2_hw_start_domain (struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_start_domain_args *args, +struct dlb2_cmd_response *resp, +bool vdev_request, +unsigned int vdev_id); + +/** * dlb2_reset_domain() - reset a scheduling domain * @hw: dlb2_hw handle for a particular device. * @domain_id: domain ID.
include/uapi/linux/dlb2_user.h +24 -0
@@ -471,6 +471,25 @@ struct dlb2_create_dir_port_args { };/* +* DLB2_DOMAIN_CMD_START_DOMAIN: Mark the end of the domain configuration. This +* must be called before passing QEs into the device, and no configuration +* ioctls can be issued once the domain has started. Sending QEs into the +* device before calling this ioctl will result in undefined behavior. +* Input parameters: +* - (None) +* +* Output parameters: +* - response: pointer to a struct dlb2_cmd_response. +* response.status: Detailed error code. In certain cases, such as if the +* response pointer is invalid, the driver won't set status. +*/ +struct dlb2_start_domain_args { +/* Output parameters */ +__u64 response; +/* Input parameters */ +}; + +/* * DLB2_DOMAIN_CMD_GET_LDB_QUEUE_DEPTH: Get a load-balanced queue's depth. * Input parameters: * - queue_id: The load-balanced queue ID.
@@ -550,6 +569,7 @@ enum dlb2_domain_user_interface_commands {DLB2_DOMAIN_CMD_CREATE_DIR_QUEUE ,DLB2_DOMAIN_CMD_CREATE_LDB_PORT ,DLB2_DOMAIN_CMD_CREATE_DIR_PORT , +DLB2_DOMAIN_CMD_START_DOMAIN ,DLB2_DOMAIN_CMD_GET_LDB_QUEUE_DEPTH ,DLB2_DOMAIN_CMD_GET_DIR_QUEUE_DEPTH , DLB2_DOMAIN_CMD_GET_LDB_PORT_PP_FD,
@@ -614,6 +634,10 @@ enum dlb2_domain_user_interface_commands {_IOWR (DLB2_IOC_MAGIC , \DLB2_DOMAIN_CMD_CREATE_DIR_PORT , \ struct dlb2_create_dir_port_args) +#define DLB2_IOC_START_DOMAIN \ + _IOWR(DLB2_IOC_MAGIC, \ + DLB2_DOMAIN_CMD_START_DOMAIN, \ + struct dlb2_start_domain_args)#define DLB2_IOC_GET_LDB_QUEUE_DEPTH \ _IOWR(DLB2_IOC_MAGIC, \ DLB2_DOMAIN_CMD_GET_LDB_QUEUE_DEPTH, \
Signature · 1 line
2.13.6
PATCH 12/20 dlb2: add queue map and unmap ioctls
In reply to Gage EadsLoad-balanced queues can be "mapped" to any number of load-balanced ports. Once mapped, the port becomes a candidate to which the device can schedule queue entries from the queue. If a port is unmapped from a queue, it is no longer a candidate for scheduling from that queue.
The process for map and unmap is different depending on whether or not the domain is started, because the process requires updating hardware structures that are dynamically modified by the device when it's in use. If the domain is not started, its ports and queues are guaranteed not to be in active use.
If the domain is started, the map process must (temporarily) disable the queue and wait for it to quiesce. Similarly, the unmap process must (temporarily) disable the port and wait for it to quiesce. 'Quiesce' here means the user processes any in-flight QEs.
It's possible that the thread that requires the map/unmap is the same one which is responsible for doing the processing that would quiesce the queue/port, thus the driver may have to complete the operation asynchronously. To that end, the driver uses a workqueue that periodically checks whether any outstanding operations can be completed. This workqueue function is only scheduled when there is at least one outstanding map/unmap operation.
To support this asynchronous operation while also providing a reasonably usable user-interface, the driver maintains two views of the queue map state:
- The hardware view: the actual queue map state in the device
- The user/software view: the queue map state as though the operations were synchronous.
While a map/unmap operation is inflight, these two views are out-of-sync. When the user requests a new map/unmap operation, the driver verifies the request against the software view, so the errors are synchronous from the user’s perspective, then adds the request to the queue of in-progress operations. When possible -- for example if the user requests to map a queue and then immediately requests to unmap it -- the driver will coalesce or cancel outstanding operations.
This commit also adds a pending-port-unmaps ioctl, that user-space can call to query how many pending/outstanding unmap operations exist for a given port.
--- drivers/misc/dlb2/dlb2_ioctl.c | 6 + drivers/misc/dlb2/dlb2_main.h | 14 + drivers/misc/dlb2/dlb2_pf_ops.c | 30 ++ drivers/misc/dlb2/dlb2_resource.c | 789 ++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 111 ++++++ include/uapi/linux/dlb2_user.h | 82 ++++ 6 files changed, 1032 insertions(+)
drivers/misc/dlb2/dlb2_ioctl.c +6 -0
@@ -94,8 +94,11 @@ static int dlb2_domain_ioctl_##lower_name(struct dlb2_dev *dev, \ DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(create_ldb_queue) DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(create_dir_queue) DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(start_domain) +DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(map_qid) +DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(unmap_qid) DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(get_ldb_queue_depth) DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(get_dir_queue_depth) +DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(pending_port_unmaps)/* * Port creation ioctls don't use the callback template macro because they have
@@ -467,8 +470,11 @@ dlb2_domain_ioctl_callback_fns[NUM_DLB2_DOMAIN_CMD] = { dlb2_domain_ioctl_create_ldb_port, dlb2_domain_ioctl_create_dir_port, dlb2_domain_ioctl_start_domain, + dlb2_domain_ioctl_map_qid, + dlb2_domain_ioctl_unmap_qid, dlb2_domain_ioctl_get_ldb_queue_depth, dlb2_domain_ioctl_get_dir_queue_depth, + dlb2_domain_ioctl_pending_port_unmaps, dlb2_domain_ioctl_get_ldb_port_pp_fd, dlb2_domain_ioctl_get_ldb_port_cq_fd, dlb2_domain_ioctl_get_dir_port_pp_fd,
drivers/misc/dlb2/dlb2_main.h +14 -0
@@ -82,6 +82,18 @@ struct dlb2_device_ops {u32 domain_id, struct dlb2_start_domain_args *args, struct dlb2_cmd_response *resp); +int (*map_qid)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_map_qid_args *args, +struct dlb2_cmd_response *resp); +int (*unmap_qid)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_unmap_qid_args *args, +struct dlb2_cmd_response *resp); +int (*pending_port_unmaps)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_pending_port_unmaps_args *args, +struct dlb2_cmd_response *resp);int (*get_num_resources)(struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args);int (*reset_domain)(struct dlb2_hw *hw,u32 domain_id);
@@ -144,10 +156,12 @@ struct dlb2_dev {* hardware registers. */ struct mutex resource_mutex; +struct work_struct work;enum dlb2_device_type type;int id;dev_t dev_number;u8 domain_reset_failed; +u8 worker_launched; };int dlb2_init_domain (struct dlb2_dev *dlb2_dev,u32 domain_id);
drivers/misc/dlb2/dlb2_pf_ops.c +30 -0
@@ -291,6 +291,33 @@ dlb2_pf_start_domain(struct dlb2_hw *hw, }static int +dlb2_pf_map_qid (struct dlb2_hw *hw, +u32 id, +struct dlb2_map_qid_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_map_qid (hw, id, args, resp, false,0 ); +} + +static int +dlb2_pf_unmap_qid (struct dlb2_hw *hw, +u32 id, +struct dlb2_unmap_qid_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_unmap_qid (hw, id, args, resp, false,0 ); +} + +static int +dlb2_pf_pending_port_unmaps (struct dlb2_hw *hw, +u32 id, +struct dlb2_pending_port_unmaps_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_pending_port_unmaps (hw, id, args, resp, false,0 ); +} + +static int dlb2_pf_get_num_resources (struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args) {
@@ -378,6 +405,9 @@ struct dlb2_device_ops dlb2_pf_ops = { .create_ldb_port = dlb2_pf_create_ldb_port, .create_dir_port = dlb2_pf_create_dir_port, .start_domain = dlb2_pf_start_domain, + .map_qid = dlb2_pf_map_qid, + .unmap_qid = dlb2_pf_unmap_qid, + .pending_port_unmaps = dlb2_pf_pending_port_unmaps, .get_num_resources = dlb2_pf_get_num_resources, .reset_domain = dlb2_pf_reset_domain, .ldb_port_owned_by_domain = dlb2_pf_ldb_port_owned_by_domain,
drivers/misc/dlb2/dlb2_resource.c +789 -0
855 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +111 -0
123 lines not on this page · raw message
include/uapi/linux/dlb2_user.h +82 -0
114 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 13/20 dlb2: add port enable/disable ioctls
In reply to Gage EadsThe ioctls can be used to dynamically enable or disable scheduling to a port. (By default, ports start with their scheduling enabled.) Doing so allows software to, for example, quickly add/remove cores to/from a worker pool.
--- drivers/misc/dlb2/dlb2_ioctl.c | 152 +++++++++++++++ drivers/misc/dlb2/dlb2_main.h | 16 ++ drivers/misc/dlb2/dlb2_pf_ops.c | 40 ++++ drivers/misc/dlb2/dlb2_resource.c | 382 ++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 120 ++++++++++++ include/uapi/linux/dlb2_user.h | 96 ++++++++++ 6 files changed, 806 insertions(+)
drivers/misc/dlb2/dlb2_ioctl.c +152 -0
@@ -101,6 +101,154 @@ DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE(get_dir_queue_depth)DLB2_DOMAIN_IOCTL_CALLBACK_TEMPLATE (pending_port_unmaps)/* +* Port enable/disable ioctls don't use the callback template macro because +* they have additional CQ interrupt management logic. +*/ +static int dlb2_domain_ioctl_enable_ldb_port(struct dlb2_dev *dev, +struct dlb2_domain *domain, +unsigned long user_arg, +u16 size) +{ +struct dlb2_cmd_response response = {0 }; +struct dlb2_enable_ldb_port_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +mutex_lock (&dev->resource_mutex); + + ret = dev->ops->enable_ldb_port (&dev->hw, domain->id, &arg, &response); + +mutex_unlock (&dev->resource_mutex); + +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} + +static int dlb2_domain_ioctl_enable_dir_port (struct dlb2_dev *dev, +struct dlb2_domain *domain, +unsigned long user_arg, +u16 size) +{ +struct dlb2_cmd_response response = {0 }; +struct dlb2_enable_dir_port_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +mutex_lock (&dev->resource_mutex); + + ret = dev->ops->enable_dir_port (&dev->hw, domain->id, &arg, &response); + +mutex_unlock (&dev->resource_mutex); + +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} + +static int dlb2_domain_ioctl_disable_ldb_port (struct dlb2_dev *dev, +struct dlb2_domain *domain, +unsigned long user_arg, +u16 size) +{ +struct dlb2_cmd_response response = {0 }; +struct dlb2_disable_ldb_port_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +mutex_lock (&dev->resource_mutex); + + ret = dev->ops->disable_ldb_port (&dev->hw, domain->id, &arg, &response); + +mutex_unlock (&dev->resource_mutex); + +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} + +static int dlb2_domain_ioctl_disable_dir_port (struct dlb2_dev *dev, +struct dlb2_domain *domain, +unsigned long user_arg, +u16 size) +{ +struct dlb2_cmd_response response = {0 }; +struct dlb2_disable_dir_port_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +mutex_lock (&dev->resource_mutex); + + ret = dev->ops->disable_dir_port (&dev->hw, domain->id, &arg, &response); + +mutex_unlock (&dev->resource_mutex); + +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} + +/* * Port creation ioctls don't use the callback template macro because they have * a number of OS-dependent memory operations. */
@@ -472,6 +620,10 @@ dlb2_domain_ioctl_callback_fns[NUM_DLB2_DOMAIN_CMD] = { dlb2_domain_ioctl_start_domain, dlb2_domain_ioctl_map_qid, dlb2_domain_ioctl_unmap_qid, + dlb2_domain_ioctl_enable_ldb_port, + dlb2_domain_ioctl_enable_dir_port, + dlb2_domain_ioctl_disable_ldb_port, + dlb2_domain_ioctl_disable_dir_port, dlb2_domain_ioctl_get_ldb_queue_depth, dlb2_domain_ioctl_get_dir_queue_depth, dlb2_domain_ioctl_pending_port_unmaps,
drivers/misc/dlb2/dlb2_main.h +16 -0
@@ -94,6 +94,22 @@ struct dlb2_device_ops {u32 domain_id, struct dlb2_pending_port_unmaps_args *args, struct dlb2_cmd_response *resp); +int (*enable_ldb_port)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_enable_ldb_port_args *args, +struct dlb2_cmd_response *resp); +int (*disable_ldb_port)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_disable_ldb_port_args *args, +struct dlb2_cmd_response *resp); +int (*enable_dir_port)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_enable_dir_port_args *args, +struct dlb2_cmd_response *resp); +int (*disable_dir_port)(struct dlb2_hw *hw, +u32 domain_id, +struct dlb2_disable_dir_port_args *args, +struct dlb2_cmd_response *resp);int (*get_num_resources)(struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args);int (*reset_domain)(struct dlb2_hw *hw,u32 domain_id);
drivers/misc/dlb2/dlb2_pf_ops.c +40 -0
@@ -318,6 +318,42 @@ dlb2_pf_pending_port_unmaps(struct dlb2_hw *hw, }static int +dlb2_pf_enable_ldb_port (struct dlb2_hw *hw, +u32 id, +struct dlb2_enable_ldb_port_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_enable_ldb_port (hw, id, args, resp, false,0 ); +} + +static int +dlb2_pf_disable_ldb_port (struct dlb2_hw *hw, +u32 id, +struct dlb2_disable_ldb_port_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_disable_ldb_port (hw, id, args, resp, false,0 ); +} + +static int +dlb2_pf_enable_dir_port (struct dlb2_hw *hw, +u32 id, +struct dlb2_enable_dir_port_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_enable_dir_port (hw, id, args, resp, false,0 ); +} + +static int +dlb2_pf_disable_dir_port (struct dlb2_hw *hw, +u32 id, +struct dlb2_disable_dir_port_args *args, +struct dlb2_cmd_response *resp) +{ +return dlb2_hw_disable_dir_port (hw, id, args, resp, false,0 ); +} + +static int dlb2_pf_get_num_resources (struct dlb2_hw *hw,struct dlb2_get_num_resources_args *args) {
@@ -408,6 +444,10 @@ struct dlb2_device_ops dlb2_pf_ops = { .map_qid = dlb2_pf_map_qid, .unmap_qid = dlb2_pf_unmap_qid, .pending_port_unmaps = dlb2_pf_pending_port_unmaps, + .enable_ldb_port = dlb2_pf_enable_ldb_port, + .enable_dir_port = dlb2_pf_enable_dir_port, + .disable_ldb_port = dlb2_pf_disable_ldb_port, + .disable_dir_port = dlb2_pf_disable_dir_port, .get_num_resources = dlb2_pf_get_num_resources, .reset_domain = dlb2_pf_reset_domain, .ldb_port_owned_by_domain = dlb2_pf_ldb_port_owned_by_domain,
drivers/misc/dlb2/dlb2_resource.c +382 -0
394 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +120 -0
126 lines not on this page · raw message
include/uapi/linux/dlb2_user.h +96 -0
114 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 14/20 dlb2: add CQ interrupt support
In reply to Gage EadsDLB 2.0 supports interrupt-driven applications with per-CQ interrupts. A CQ interrupt is armed by user-space software by enqueueing a special command to the device through the port's MMIO window, and the interrupt fires when the armed CQ becomes non-empty.
All CQ interrupts use a single MSI-X interrupt vector, and the ISR reads bitmap registers to determine which CQ(s)'s interrupt fired. For each of these CQs, the driver wakes up a wait-queue -- on which user-space threads may be blocking waiting for the interrupt. User-space software calls a block-on-CQ-interrupt ioctl in order to block on the wait queue.
A CQ's interrupt is enabled when its port is configured, and interrupts are enabled/disabled when a port is enabled/disabled. If a port is disabled and a thread is blocked on the wait queue, the thread is woken and returned to user-space.
--- drivers/misc/dlb2/Makefile | 1 + drivers/misc/dlb2/dlb2_hw_types.h | 13 ++ drivers/misc/dlb2/dlb2_intr.c | 133 +++++++++++++++++ drivers/misc/dlb2/dlb2_intr.h | 29 ++++ drivers/misc/dlb2/dlb2_ioctl.c | 80 ++++++++++ drivers/misc/dlb2/dlb2_main.c | 20 ++- drivers/misc/dlb2/dlb2_main.h | 43 ++++++ drivers/misc/dlb2/dlb2_pf_ops.c | 219 +++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.c | 306 ++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 128 ++++++++++++++++ include/uapi/linux/dlb2_user.h | 38 +++++ 11 files changed, 1009 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/dlb2/dlb2_intr.c create mode 100644 drivers/misc/dlb2/dlb2_intr.h
drivers/misc/dlb2/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_INTEL_DLB2) := dlb2.o dlb2-objs := \ dlb2_main.o \ + dlb2_intr.o \ dlb2_file.o \ dlb2_ioctl.o \ dlb2_pf_ops.o \
drivers/misc/dlb2/dlb2_hw_types.h +13 -0
@@ -48,6 +48,19 @@#define DLB2_MAX_QID_EMPTY_CHECK_LOOPS (32 * 64 * 1024 * (800 / 30))#define DLB2_HZ 800000000 +/* Interrupt related macros */ +#define DLB2_PF_NUM_NON_CQ_INTERRUPT_VECTORS 1 +#define DLB2_PF_NUM_CQ_INTERRUPT_VECTORS 64 +#define DLB2_PF_TOTAL_NUM_INTERRUPT_VECTORS \ + (DLB2_PF_NUM_NON_CQ_INTERRUPT_VECTORS + \ + DLB2_PF_NUM_CQ_INTERRUPT_VECTORS) +#define DLB2_PF_NUM_COMPRESSED_MODE_VECTORS \ + (DLB2_PF_NUM_NON_CQ_INTERRUPT_VECTORS + 1) +#define DLB2_PF_NUM_PACKED_MODE_VECTORS \ + DLB2_PF_TOTAL_NUM_INTERRUPT_VECTORS +#define DLB2_PF_COMPRESSED_MODE_CQ_VECTOR_ID \ + DLB2_PF_NUM_NON_CQ_INTERRUPT_VECTORS +/* * Hardware-defined base addresses. Those prefixed 'DLB2_DRV' are only used by * the PF driver.
drivers/misc/dlb2/dlb2_intr.c new file +133 -0
133 lines not on this page · raw message
drivers/misc/dlb2/dlb2_intr.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* Copyright(c) 2017-2020 Intel Corporation +*/ + +#ifndef __DLB2_INTR_H +#define __DLB2_INTR_H + +#include <linux/pci.h> + +#include "dlb2_main.h" + +int dlb2_block_on_cq_interrupt (struct dlb2_dev *dev, +struct dlb2_domain *domain, +int port_id, +bool is_ldb, +u64 cq_va, +u8 cq_gen, +bool arm); + +enum dlb2_wake_reason { +WAKE_CQ_INTR , +WAKE_PORT_DISABLED , +}; + +void dlb2_wake_thread (struct dlb2_dev *dev, +struct dlb2_cq_intr *intr, +enum dlb2_wake_reason reason); + +#endif /* __DLB2_INTR_H */
drivers/misc/dlb2/dlb2_ioctl.c +80 -0
134 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.c +19 -1
@@ -205,13 +205,20 @@ static void dlb2_release_device_memory(struct dlb2_dev *dev)static int __dlb2_free_domain (struct dlb2_dev *dev,struct dlb2_domain *domain) { -int ret =0 ; +int i, ret =0 ; ret = dev->ops->reset_domain (&dev->hw, domain->id);/* Unpin and free all memory pages associated with the domain */ dlb2_release_domain_memory (dev, domain->id); +for (i =0 ; i <DLB2_MAX_NUM_LDB_PORTS ; i++) +if (dev->intr.ldb_cq_intr[i].domain_id == domain->id) + dev->intr.ldb_cq_intr[i].configured = false; +for (i =0 ; i <DLB2_MAX_NUM_DIR_PORTS ; i++) +if (dev->intr.dir_cq_intr[i].domain_id == domain->id) + dev->intr.dir_cq_intr[i].configured = false; +if (ret) { dev->domain_reset_failed = true; dev_err(dev->dlb2_device,
@@ -488,6 +495,10 @@ static int dlb2_probe(struct pci_dev *pdev,if (ret) goto dlb2_reset_fail; + ret = dlb2_dev->ops->init_interrupts (dlb2_dev, pdev); +if (ret) + goto init_interrupts_fail; + ret =dlb2_resource_init (&dlb2_dev->hw);if (ret) goto resource_init_fail;
@@ -516,6 +527,8 @@ static int dlb2_probe(struct pci_dev *pdev, init_driver_state_fail:dlb2_resource_free (&dlb2_dev->hw); resource_init_fail: + dlb2_dev->ops->free_interrupts (dlb2_dev, pdev); +init_interrupts_fail: dlb2_reset_fail: wait_for_device_ready_fail: dma_set_mask_fail:
@@ -556,6 +569,8 @@ static void dlb2_remove(struct pci_dev *pdev)dlb2_resource_free (&dlb2_dev->hw); + dlb2_dev->ops->free_interrupts (dlb2_dev, pdev); +dlb2_release_device_memory (dlb2_dev); dlb2_dev->ops->device_destroy (dlb2_dev, dlb2_class);
@@ -580,6 +595,9 @@ static void dlb2_reset_hardware_state(struct dlb2_dev *dev) {dlb2_reset_device (dev->pdev); +/* Reinitialize interrupt configuration */ + dev->ops->reinit_interrupts (dev); +/* Reinitialize any other hardware state */ dev->ops->init_hardware (dev); }
drivers/misc/dlb2/dlb2_main.h +43 -0
61 lines not on this page · raw message
drivers/misc/dlb2/dlb2_pf_ops.c +219 -0
237 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.c +306 -0
324 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +128 -0
134 lines not on this page · raw message
include/uapi/linux/dlb2_user.h +38 -0
@@ -609,6 +609,39 @@ struct dlb2_disable_dir_port_args { };/* +* DLB2_DOMAIN_CMD_BLOCK_ON_CQ_INTERRUPT: Block on a CQ interrupt until a QE +* arrives for the specified port. If a QE is already present, the ioctl +* will immediately return. +* +* Note: Only one thread can block on a CQ's interrupt at a time. Doing +* otherwise can result in hung threads. +* +* Input parameters: +* - port_id: Port ID. +* - is_ldb: True if the port is load-balanced, false otherwise. +* - arm: Tell the driver to arm the interrupt. +* - cq_gen: Current CQ generation bit. +* - padding0: Reserved for future use. +* - cq_va: VA of the CQ entry where the next QE will be placed. +* +* Output parameters: +* - response: pointer to a struct dlb2_cmd_response. +* response.status: Detailed error code. In certain cases, such as if the +* response pointer is invalid, the driver won't set status. +*/ +struct dlb2_block_on_cq_interrupt_args { +/* Output parameters */ +__u64 response; +/* Input parameters */ +__u32 port_id; +__u8 is_ldb; +__u8 arm; +__u8 cq_gen; +__u8 padding0; +__u64 cq_va; +}; + +/* * DLB2_DOMAIN_CMD_GET_LDB_QUEUE_DEPTH: Get a load-balanced queue's depth. * Input parameters: * - queue_id: The load-balanced queue ID.
@@ -719,6 +752,7 @@ enum dlb2_domain_user_interface_commands {DLB2_DOMAIN_CMD_ENABLE_DIR_PORT ,DLB2_DOMAIN_CMD_DISABLE_LDB_PORT ,DLB2_DOMAIN_CMD_DISABLE_DIR_PORT , +DLB2_DOMAIN_CMD_BLOCK_ON_CQ_INTERRUPT ,DLB2_DOMAIN_CMD_GET_LDB_QUEUE_DEPTH ,DLB2_DOMAIN_CMD_GET_DIR_QUEUE_DEPTH , DLB2_DOMAIN_CMD_PENDING_PORT_UNMAPS,
@@ -812,6 +846,10 @@ enum dlb2_domain_user_interface_commands {_IOWR (DLB2_IOC_MAGIC , \DLB2_DOMAIN_CMD_DISABLE_DIR_PORT , \ struct dlb2_disable_dir_port_args) +#define DLB2_IOC_BLOCK_ON_CQ_INTERRUPT \ + _IOWR(DLB2_IOC_MAGIC, \ + DLB2_DOMAIN_CMD_BLOCK_ON_CQ_INTERRUPT, \ + struct dlb2_block_on_cq_interrupt_args)#define DLB2_IOC_GET_LDB_QUEUE_DEPTH \ _IOWR(DLB2_IOC_MAGIC, \ DLB2_DOMAIN_CMD_GET_LDB_QUEUE_DEPTH, \
Signature · 1 line
2.13.6
PATCH 15/20 dlb2: add domain alert support
In reply to Gage EadsDomain alerts are a mechanism for the driver to asynchronously notify user-space applications of device reset or hardware alarms (both to be added in later commits). This mechanism also allows the application to enqueue an alert to its domain, as a form of (limited) IPC in a multi-process scenario.
An application can read its domain alerts through the domain device file's read callback. Applications are expected to spawn a thread that performs a blocking read, and rarely (if ever) wakes and returns to user-space.
--- drivers/misc/dlb2/dlb2_ioctl.c | 21 +++++++ drivers/misc/dlb2/dlb2_main.c | 134 ++++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_main.h | 16 +++++ include/uapi/linux/dlb2_user.h | 135 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 306 insertions(+)
drivers/misc/dlb2/dlb2_ioctl.c +21 -0
@@ -487,6 +487,26 @@ static int dlb2_domain_ioctl_block_on_cq_interrupt(struct dlb2_dev *dev,return ret; } +static int dlb2_domain_ioctl_enqueue_domain_alert (struct dlb2_dev *dev, +struct dlb2_domain *domain, +unsigned long user_arg, +u16 size) +{ +struct dlb2_enqueue_domain_alert_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +return dlb2_write_domain_alert (dev, + domain, +DLB2_DOMAIN_ALERT_USER , + arg.aux_alert_data); +} + static int dlb2_create_port_fd(struct dlb2_dev *dev, struct dlb2_domain *domain, const char *prefix,
@@ -704,6 +724,7 @@ dlb2_domain_ioctl_callback_fns[NUM_DLB2_DOMAIN_CMD] = { dlb2_domain_ioctl_disable_ldb_port, dlb2_domain_ioctl_disable_dir_port, dlb2_domain_ioctl_block_on_cq_interrupt, + dlb2_domain_ioctl_enqueue_domain_alert, dlb2_domain_ioctl_get_ldb_queue_depth, dlb2_domain_ioctl_get_dir_queue_depth, dlb2_domain_ioctl_pending_port_unmaps,
drivers/misc/dlb2/dlb2_main.c +134 -0
152 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.h +16 -0
@@ -11,6 +11,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/pci.h> +#include <linux/spinlock.h> #include <linux/types.h> #include <uapi/linux/dlb2_user.h>
@@ -161,9 +162,20 @@ struct dlb2_port {u8 valid; }; +#define DLB2_DOMAIN_ALERT_RING_SIZE 256 +struct dlb2_domain {struct dlb2_dev *dlb2_dev; +struct dlb2_domain_alert alerts[DLB2_DOMAIN_ALERT_RING_SIZE ]; +wait_queue_head_t wq_head; +/* +* The alert lock protects access to the alert ring and its read and +* write indexes. +*/ +spinlock_t alert_lock;struct kref refcnt; +u8 alert_rd_idx; +u8 alert_wr_idx;u8 id; };
@@ -225,6 +237,10 @@ struct dlb2_dev {int dlb2_init_domain (struct dlb2_dev *dlb2_dev,u32 domain_id);void dlb2_free_domain (struct kref *kref); +int dlb2_write_domain_alert (struct dlb2_dev *dev, +struct dlb2_domain *domain, +u64 alert_id, +u64 aux_alert_data);#define DLB2_HW_ERR (dlb2, ...) do { \ struct dlb2_dev *dev; \
include/uapi/linux/dlb2_user.h +135 -0
159 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 16/20 dlb2: add sequence-number management ioctls
In reply to Gage EadsIn order for a load-balanced DLB 2.0 queue to support ordered scheduling, it must be configured with an allocation of sequence numbers (SNs) -- a hardware resource used to re-order QEs.
The device evenly partitions its SNs across two groups. A queue is allocated SNs by taking a 'slot' in one of these two groups, and the number of slots is variable. A group can support as many as 16 slots (64 SNs per slot) and as few as 1 slot (1024 SNs per slot).
This commit adds ioctls to get and set a sequence number group's slot configuration, as well as query the group's slot occupancy.
--- drivers/misc/dlb2/dlb2_ioctl.c | 116 ++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_main.h | 3 + drivers/misc/dlb2/dlb2_pf_ops.c | 21 +++++++ drivers/misc/dlb2/dlb2_resource.c | 67 ++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 47 +++++++++++++++ include/uapi/linux/dlb2_user.h | 87 ++++++++++++++++++++++++++++ 6 files changed, 341 insertions(+)
drivers/misc/dlb2/dlb2_ioctl.c +116 -0
@@ -975,6 +975,119 @@ static int dlb2_ioctl_get_driver_version(struct dlb2_dev *dev,return 0 ; } +static int dlb2_ioctl_set_sn_allocation (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_cmd_response response = {0 }; +struct dlb2_set_sn_allocation_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +mutex_lock (&dev->resource_mutex); + + ret = dev->ops->set_sn_allocation (&dev->hw, arg.group, arg.num); + +mutex_unlock (&dev->resource_mutex); + +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} + +static int dlb2_ioctl_get_sn_allocation (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_cmd_response response = {0 }; +struct dlb2_get_sn_allocation_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +mutex_lock (&dev->resource_mutex); + + ret = dev->ops->get_sn_allocation (&dev->hw, arg.group); + + response.id = ret; + + ret = (ret >0 ) ?0 : ret; + +mutex_unlock (&dev->resource_mutex); + +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} + +static int dlb2_ioctl_get_sn_occupancy (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_cmd_response response = {0 }; +struct dlb2_get_sn_occupancy_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +mutex_lock (&dev->resource_mutex); + + ret = dev->ops->get_sn_occupancy (&dev->hw, arg.group); + + response.id = ret; + + ret = (ret >0 ) ?0 : ret; + +mutex_unlock (&dev->resource_mutex); + +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} +static int dlb2_ioctl_query_cq_poll_mode (struct dlb2_dev *dev,unsigned long user_arg,u16 size)
@@ -1016,6 +1129,9 @@ static dlb2_ioctl_callback_fn_t dlb2_ioctl_callback_fns[NUM_DLB2_CMD] = { dlb2_ioctl_get_sched_domain_fd, dlb2_ioctl_get_num_resources, dlb2_ioctl_get_driver_version, + dlb2_ioctl_set_sn_allocation, + dlb2_ioctl_get_sn_allocation, + dlb2_ioctl_get_sn_occupancy, dlb2_ioctl_query_cq_poll_mode, };
drivers/misc/dlb2/dlb2_main.h +3 -0
@@ -135,6 +135,9 @@ struct dlb2_device_ops {int (*dir_port_owned_by_domain)(struct dlb2_hw *hw,u32 domain_id,u32 port_id); +int (*get_sn_allocation)(struct dlb2_hw *hw,u32 group_id); +int (*set_sn_allocation)(struct dlb2_hw *hw,u32 group_id,u32 num); +int (*get_sn_occupancy)(struct dlb2_hw *hw,u32 group_id); int (*get_ldb_queue_depth)(struct dlb2_hw *hw, u32 domain_id, struct dlb2_get_ldb_queue_depth_args *args,
drivers/misc/dlb2/dlb2_pf_ops.c +21 -0
@@ -631,6 +631,24 @@ dlb2_pf_dir_port_owned_by_domain(struct dlb2_hw *hw,return dlb2_dir_port_owned_by_domain (hw, domain_id, port_id, false,0 ); } +static int +dlb2_pf_get_sn_allocation (struct dlb2_hw *hw,u32 group_id) +{ +return dlb2_get_group_sequence_numbers (hw, group_id); +} + +static int +dlb2_pf_set_sn_allocation (struct dlb2_hw *hw,u32 group_id,u32 num) +{ +return dlb2_set_group_sequence_numbers (hw, group_id, num); +} + +static int +dlb2_pf_get_sn_occupancy (struct dlb2_hw *hw,u32 group_id) +{ +return dlb2_get_group_sequence_number_occupancy (hw, group_id); +} +/********************************/ /****** DLB2 PF Device Ops ******/ /********************************/
@@ -671,6 +689,9 @@ struct dlb2_device_ops dlb2_pf_ops = { .reset_domain = dlb2_pf_reset_domain, .ldb_port_owned_by_domain = dlb2_pf_ldb_port_owned_by_domain, .dir_port_owned_by_domain = dlb2_pf_dir_port_owned_by_domain, + .get_sn_allocation = dlb2_pf_get_sn_allocation, + .set_sn_allocation = dlb2_pf_set_sn_allocation, + .get_sn_occupancy = dlb2_pf_get_sn_occupancy, .get_ldb_queue_depth = dlb2_pf_get_ldb_queue_depth, .get_dir_queue_depth = dlb2_pf_get_dir_queue_depth, .init_hardware = dlb2_pf_init_hardware,
drivers/misc/dlb2/dlb2_resource.c +67 -0
73 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +47 -0
53 lines not on this page · raw message
include/uapi/linux/dlb2_user.h +87 -0
105 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 17/20 dlb2: add cos bandwidth get/set ioctls
In reply to Gage EadsThe DLB 2.0 supports four load-balanced port classes of service (CoS). Each CoS receives a guaranteed percentage of the load-balanced scheduler's bandwidth, and any unreserved bandwidth is divided among the four CoS.
These two ioctls allow applications to query CoS allocations and adjust them as needed. These allocations are controlled by the PF driver; virtual devices, when support for them is added, will not be able to adjust them.
--- drivers/misc/dlb2/dlb2_ioctl.c | 76 +++++++++++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_main.h | 2 ++ drivers/misc/dlb2/dlb2_pf_ops.c | 14 ++++++++ drivers/misc/dlb2/dlb2_resource.c | 59 ++++++++++++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.h | 28 +++++++++++++++ include/uapi/linux/dlb2_user.h | 54 ++++++++++++++++++++++++++++ 6 files changed, 233 insertions(+)
drivers/misc/dlb2/dlb2_ioctl.c +76 -0
@@ -1049,6 +1049,80 @@ static int dlb2_ioctl_get_sn_allocation(struct dlb2_dev *dev,return ret; } +static int dlb2_ioctl_set_cos_bw (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_cmd_response response = {0 }; +struct dlb2_set_cos_bw_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +mutex_lock (&dev->resource_mutex); + + ret = dev->ops->set_cos_bw (&dev->hw, arg.cos_id, arg.bandwidth); + +mutex_unlock (&dev->resource_mutex); + +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} + +static int dlb2_ioctl_get_cos_bw (struct dlb2_dev *dev, +unsigned long user_arg, +u16 size) +{ +struct dlb2_cmd_response response = {0 }; +struct dlb2_get_cos_bw_args arg; +int ret; + +dev_dbg (dev->dlb2_device,"Entering %s()\n" , __func__); + + ret =dlb2_copy_from_user (dev, user_arg, size, &arg,sizeof (arg)); +if (ret) +return ret; + +/* Copy zeroes to verify the user-provided response pointer */ + ret =dlb2_copy_resp_to_user (dev, arg.response, &response); +if (ret) +return ret; + +mutex_lock (&dev->resource_mutex); + + ret = dev->ops->get_cos_bw (&dev->hw, arg.cos_id); + + response.id = ret; + + ret = (ret >0 ) ?0 : ret; + +mutex_unlock (&dev->resource_mutex); + +if (copy_to_user ((void __user *)arg.response, + &response, +sizeof (response))) +return -EFAULT ; + +dev_dbg (dev->dlb2_device,"Exiting %s()\n" , __func__); + +return ret; +} +static int dlb2_ioctl_get_sn_occupancy (struct dlb2_dev *dev,unsigned long user_arg,u16 size)
@@ -1131,6 +1205,8 @@ static dlb2_ioctl_callback_fn_t dlb2_ioctl_callback_fns[NUM_DLB2_CMD] = { dlb2_ioctl_get_driver_version, dlb2_ioctl_set_sn_allocation, dlb2_ioctl_get_sn_allocation, + dlb2_ioctl_set_cos_bw, + dlb2_ioctl_get_cos_bw, dlb2_ioctl_get_sn_occupancy, dlb2_ioctl_query_cq_poll_mode, };
drivers/misc/dlb2/dlb2_main.h +2 -0
@@ -146,6 +146,8 @@ struct dlb2_device_ops {u32 domain_id, struct dlb2_get_dir_queue_depth_args *args, struct dlb2_cmd_response *resp); +int (*set_cos_bw)(struct dlb2_hw *hw,u32 cos_id,u8 bandwidth); +int (*get_cos_bw)(struct dlb2_hw *hw,u32 cos_id);void (*init_hardware)(struct dlb2_dev *dev);int (*query_cq_poll_mode)(struct dlb2_dev *dev,struct dlb2_cmd_response *user_resp);
drivers/misc/dlb2/dlb2_pf_ops.c +14 -0
@@ -644,6 +644,18 @@ dlb2_pf_set_sn_allocation(struct dlb2_hw *hw, u32 group_id, u32 num) }static int +dlb2_pf_set_cos_bw (struct dlb2_hw *hw,u32 cos_id,u8 bandwidth) +{ +return dlb2_hw_set_cos_bandwidth (hw, cos_id, bandwidth); +} + +static int +dlb2_pf_get_cos_bw (struct dlb2_hw *hw,u32 cos_id) +{ +return dlb2_hw_get_cos_bandwidth (hw, cos_id); +} + +static int dlb2_pf_get_sn_occupancy (struct dlb2_hw *hw,u32 group_id) {return dlb2_get_group_sequence_number_occupancy (hw, group_id);
@@ -694,6 +706,8 @@ struct dlb2_device_ops dlb2_pf_ops = { .get_sn_occupancy = dlb2_pf_get_sn_occupancy, .get_ldb_queue_depth = dlb2_pf_get_ldb_queue_depth, .get_dir_queue_depth = dlb2_pf_get_dir_queue_depth, + .set_cos_bw = dlb2_pf_set_cos_bw, + .get_cos_bw = dlb2_pf_get_cos_bw, .init_hardware = dlb2_pf_init_hardware, .query_cq_poll_mode = dlb2_pf_query_cq_poll_mode, };
drivers/misc/dlb2/dlb2_resource.c +59 -0
65 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +28 -0
@@ -823,6 +823,34 @@ int dlb2_hw_pending_port_unmaps(struct dlb2_hw *hw, unsigned int vf_id);/** +* dlb2_hw_get_cos_bandwidth() - returns the percent of bandwidth allocated +* to a port class-of-service. +* @hw: dlb2_hw handle for a particular device. +* @cos_id: class-of-service ID. +* +* Return: +* Returns -EINVAL if cos_id is invalid, else the class' bandwidth allocation. +*/ +int dlb2_hw_get_cos_bandwidth (struct dlb2_hw *hw,u32 cos_id); + +/** +* dlb2_hw_set_cos_bandwidth() - set a bandwidth allocation percentage for a +* port class-of-service. +* @hw: dlb2_hw handle for a particular device. +* @cos_id: class-of-service ID. +* @bandwidth: class-of-service bandwidth. +* +* Return: +* Returns 0 upon success, < 0 otherwise. +* +* Errors: +* EINVAL - Invalid cos ID, bandwidth is greater than 100, or bandwidth would +* cause the total bandwidth across all classes of service to exceed +* 100%. +*/ +int dlb2_hw_set_cos_bandwidth (struct dlb2_hw *hw,u32 cos_id,u8 bandwidth); + +/** * dlb2_hw_enable_sparse_ldb_cq_mode() - enable sparse mode for load-balanced * ports. * @hw: dlb2_hw handle for a particular device.
include/uapi/linux/dlb2_user.h +54 -0
72 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 18/20 dlb2: add device FLR support
In reply to Gage EadsA device FLR can be triggered while applications are actively using the device, which poses two problems:
- If applications continue to enqueue to the hardware they will cause hardware errors, because the FLR will have reset the scheduling domains, ports, and queues.
- When the applications end, they must not trigger the driver's domain reset logic, which would fail because the device's registers will have been reset by the FLR.
The driver needs to stop applications from using the device before the FLR begins, and detect when these applications exit (so they don't trigger the domain reset that occurs when their last file reference (or memory mapping) closes). The driver must also disallow applications from configuring the device while the reset is in progress.
To avoid these problems, the driver handles unexpected resets as follows:
1. Set the reset_active flag. This flag blocks new device files from being opened and is used as a wakeup condition in the driver's wait queues.
2. If this is a PF FLR and there are active VFs, send them a pre-reset notification, so they can stop any VF applications. (Added in a later commit.)
3. Disable all device files (set the per-file valid flag to false, which prevents the file from being used after FLR completes) and wake any threads blocked on a wait queue.
4. If the device is not in use -- i.e. no open device files or memory mappings, and no VFs in use (PF FLR only) -- the FLR can begin.
5. Else, the driver waits (up to a user-specified timeout, default 5s) for software to stop using the driver and the device. If the timeout elapses, the driver zaps any remaining MMIO mappings so the extant applications can no longer use the device.
6. Do not unlock the resource mutex at the end of the reset prepare function, to prevent device access during the reset.
The reset timeout is exposed as a module parameter.
After the FLR:
1. Clear the per-domain pointers (the memory is freed elsewhere).
2. Release any remaining allocated port or CQ memory, now that it's guaranteed the device is unconfigured and won't write to memory.
3. Reset software and hardware state.
4. Notify VFs that the FLR is complete. (Added in a later commit.)
5. Set reset_active to false.
6. Unlock the resource mutex.
--- Documentation/ABI/testing/sysfs-driver-dlb2 | 22 ++ drivers/misc/dlb2/dlb2_intr.c | 13 +- drivers/misc/dlb2/dlb2_intr.h | 1 + drivers/misc/dlb2/dlb2_ioctl.c | 91 ++++++++ drivers/misc/dlb2/dlb2_main.c | 327 +++++++++++++++++++++++++++- drivers/misc/dlb2/dlb2_main.h | 4 + drivers/misc/dlb2/dlb2_resource.c | 17 ++ drivers/misc/dlb2/dlb2_resource.h | 9 + 8 files changed, 475 insertions(+), 9 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-dlb2
Documentation/ABI/testing/sysfs-driver-dlb2 new file +22 -0
@@ -0,0 +1,22 @@ +What: /sys/bus/pci/drivers/dlb2/module/parameters/reset_timeout_s +Date: June 22, 2020 +KernelVersion: 5.9 +Contact: [email protected] +Description: Interface for setting the driver's reset timeout. + When a device reset (FLR) is issued, the driver waits for + user-space to stop using the device before allowing the FLR to + proceed, with a timeout. The device is considered in use if + there are any open domain device file descriptors or memory + mapped producer ports. (For PF device resets, this includes all + VF-owned domains and producer ports.) + + The amount of time the driver waits for userspace to stop using + the device is controlled by the module parameter + reset_timeout_s, which is in units of seconds and defaults to + 5. If reset_timeout_s seconds elapse and any user is still + using the device, the driver zaps those processes' memory + mappings and marks their device file descriptors as invalid. + This is necessary because user processes that do not relinquish + their device mappings can interfere with processes that use the + device after the reset completes. To ensure that user processes + have enough time to clean up, reset_timeout_s can be increased.
drivers/misc/dlb2/dlb2_intr.c +10 -3
@@ -30,7 +30,10 @@ static inline bool wake_condition(struct dlb2_cq_intr *intr,struct dlb2_dev *dev, struct dlb2_domain *domain) { - return (READ_ONCE(intr->wake) || READ_ONCE(intr->disabled)); + return (READ_ONCE(intr->wake) || + READ_ONCE(dev->reset_active) || + !READ_ONCE(domain->valid) || + READ_ONCE(intr->disabled)); } struct dlb2_dequeue_qe {
@@ -117,8 +120,12 @@ int dlb2_block_on_cq_interrupt(struct dlb2_dev *dev, ret =wait_event_interruptible (intr->wq_head,wake_condition (intr, dev, dom)); -if (ret ==0 &&READ_ONCE (intr->disabled)) - ret = -EACCES ; +if (ret ==0 ) { +if (READ_ONCE (dev->reset_active) || !READ_ONCE (dom->valid)) + ret = -EINTR ; +else if (READ_ONCE (intr->disabled)) + ret = -EACCES ; + }WRITE_ONCE (intr->wake, false);
drivers/misc/dlb2/dlb2_intr.h +1 -0
@@ -20,6 +20,7 @@ int dlb2_block_on_cq_interrupt(struct dlb2_dev *dev,enum dlb2_wake_reason {WAKE_CQ_INTR ,WAKE_PORT_DISABLED , +WAKE_DEV_RESET }; void dlb2_wake_thread(struct dlb2_dev *dev,
drivers/misc/dlb2/dlb2_ioctl.c +91 -0
157 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.c +321 -6
426 lines not on this page · raw message
drivers/misc/dlb2/dlb2_main.h +4 -0
@@ -31,6 +31,8 @@ static const char dlb2_driver_name[] = KBUILD_MODNAME;#define DLB2_NUM_FUNCS_PER_DEVICE (1 + DLB2_MAX_NUM_VDEVS)#define DLB2_MAX_NUM_DEVICES (DLB2_MAX_NUM_PFS * DLB2_NUM_FUNCS_PER_DEVICE) +#define DLB2_DEFAULT_RESET_TIMEOUT_S 5 +enum dlb2_device_type {DLB2_PF ,DLB2_VF ,
@@ -182,6 +184,7 @@ struct dlb2_domain {u8 alert_rd_idx;u8 alert_wr_idx;u8 id; +u8 valid; };struct dlb2_cq_intr {
@@ -237,6 +240,7 @@ struct dlb2_dev {int id;dev_t dev_number;u8 domain_reset_failed; +u8 reset_active;u8 worker_launched; };
drivers/misc/dlb2/dlb2_resource.c +17 -0
@@ -24,6 +24,9 @@#define DLB2_DOM_LIST_FOR_SAFE (head, ptr, ptr_tmp) \ list_for_each_entry_safe(ptr, ptr_tmp, &(head), domain_list) +#define DLB2_FUNC_LIST_FOR_SAFE (head, ptr, ptr_tmp) \ + list_for_each_entry_safe(ptr, ptr_tmp, &(head), func_list) +/* * The PF driver cannot assume that a register write will affect subsequent HCW * writes. To ensure a write completes, the driver must read back a CSR. This
@@ -5327,6 +5330,20 @@ static int dlb2_domain_reset_software_state(struct dlb2_hw *hw,return 0 ; } +void dlb2_resource_reset (struct dlb2_hw *hw) +{ + struct dlb2_hw_domain *domain, *next __attribute__((unused)); +int i; + +for (i =0 ; i <DLB2_MAX_NUM_VDEVS ; i++) { + DLB2_FUNC_LIST_FOR_SAFE(hw->vdev[i].used_domains, domain, next) +dlb2_domain_reset_software_state (hw, domain); + } + + DLB2_FUNC_LIST_FOR_SAFE(hw->pf.used_domains, domain, next) +dlb2_domain_reset_software_state (hw, domain); +} +static u32 dlb2_dir_queue_depth (struct dlb2_hw *hw,struct dlb2_dir_pq_pair *queue) {
drivers/misc/dlb2/dlb2_resource.h +9 -0
@@ -37,6 +37,15 @@ int dlb2_resource_init(struct dlb2_hw *hw);void dlb2_resource_free (struct dlb2_hw *hw);/** +* dlb2_resource_reset() - reset in-use resources to their initial state +* @hw: dlb2_hw handle for a particular device. +* +* This function resets in-use resources, and makes them available for use. +* All resources go back to their owning function, whether a PF or a VF. +*/ +void dlb2_resource_reset (struct dlb2_hw *hw); + +/** * dlb2_hw_create_sched_domain() - create a scheduling domain * @hw: dlb2_hw handle for a particular device. * @args: scheduling domain creation arguments.
Signature · 1 line
2.13.6
PATCH 19/20 dlb2: add basic PF sysfs interfaces
In reply to Gage EadsThese interfaces include files for reading the total and available device resources, getting and setting sequence number group allocations, and reading the device ID.
--- Documentation/ABI/testing/sysfs-driver-dlb2 | 165 +++++++++++ drivers/misc/dlb2/dlb2_main.c | 11 + drivers/misc/dlb2/dlb2_main.h | 3 + drivers/misc/dlb2/dlb2_pf_ops.c | 423 ++++++++++++++++++++++++++++ 4 files changed, 602 insertions(+)
Documentation/ABI/testing/sysfs-driver-dlb2 +165 -0
@@ -20,3 +20,168 @@ Description: Interface for setting the driver's reset timeout. their device mappings can interfere with processes that use the device after the reset completes. To ensure that user processes have enough time to clean up, reset_timeout_s can be increased. + +What: /sys/bus/pci/devices/.../sequence_numbers/group<N>_sns_per_queue +Date: June 22, 2020 +KernelVersion: 5.9 +Contact: [email protected] +Description: Interface for configuring dlb2 load-balanced sequence numbers. + + The DLB 2.0 has a fixed number of sequence numbers used for + ordered scheduling. They are divided among two sequence number + groups. A group can be configured to contain one queue with + 1,024 sequence numbers, or two queues with 512 sequence numbers + each, and so on, down to 16 queues with 64 sequence numbers + each. + + When a load-balanced queue is configured with non-zero sequence + numbers, the driver finds a group configured for the same + number of sequence numbers and an available slot. If no such + groups are found, the queue cannot be configured. + + Once the first ordered queue is configured, the sequence number + configurations are locked. The driver returns an error on writes + to locked sequence number configurations. When all ordered + queues are unconfigured, the sequence number configurations can + be changed again. + + This file is only accessible for physical function DLB 2.0 + devices. + +What: /sys/bus/pci/devices/.../total_resources/num_atomic_inflights +What: /sys/bus/pci/devices/.../total_resources/num_dir_credits +What: /sys/bus/pci/devices/.../total_resources/num_dir_ports +What: /sys/bus/pci/devices/.../total_resources/num_hist_list_entries +What: /sys/bus/pci/devices/.../total_resources/num_ldb_credits +What: /sys/bus/pci/devices/.../total_resources/num_ldb_ports +What: /sys/bus/pci/devices/.../total_resources/num_cos0_ldb_ports +What: /sys/bus/pci/devices/.../total_resources/num_cos1_ldb_ports +What: /sys/bus/pci/devices/.../total_resources/num_cos2_ldb_ports +What: /sys/bus/pci/devices/.../total_resources/num_cos3_ldb_ports +What: /sys/bus/pci/devices/.../total_resources/num_ldb_queues +What: /sys/bus/pci/devices/.../total_resources/num_sched_domains +Date: June 22, 2020 +KernelVersion: 5.9 +Contact: [email protected] +Description: + The total_resources subdirectory contains read-only files that + indicate the total number of resources in the device. + + num_atomic_inflights: Total number of atomic inflights in the + device. Atomic inflights refers to the + on-device storage used by the atomic + scheduler. + + num_dir_credits: Total number of directed credits in the + device. + + num_dir_ports: Total number of directed ports (and + queues) in the device. + + num_hist_list_entries: Total number of history list entries in + the device. + + num_ldb_credits: Total number of load-balanced credits in + the device. + + num_ldb_ports: Total number of load-balanced ports in + the device. + + num_cos<M>_ldb_ports: Total number of load-balanced ports + belonging to class-of-service M in the + device. + + num_ldb_queues: Total number of load-balanced queues in + the device. + + num_sched_domains: Total number of scheduling domains in the + device. + +What: /sys/bus/pci/devices/.../avail_resources/num_atomic_inflights +What: /sys/bus/pci/devices/.../avail_resources/num_dir_credits +What: /sys/bus/pci/devices/.../avail_resources/num_dir_ports +What: /sys/bus/pci/devices/.../avail_resources/num_hist_list_entries +What: /sys/bus/pci/devices/.../avail_resources/num_ldb_credits +What: /sys/bus/pci/devices/.../avail_resources/num_ldb_ports +What: /sys/bus/pci/devices/.../avail_resources/num_cos0_ldb_ports +What: /sys/bus/pci/devices/.../avail_resources/num_cos1_ldb_ports +What: /sys/bus/pci/devices/.../avail_resources/num_cos2_ldb_ports +What: /sys/bus/pci/devices/.../avail_resources/num_cos3_ldb_ports +What: /sys/bus/pci/devices/.../avail_resources/num_ldb_queues +What: /sys/bus/pci/devices/.../avail_resources/num_sched_domains +What: /sys/bus/pci/devices/.../avail_resources/max_ctg_hl_entries +Date: June 22, 2020 +KernelVersion: 5.9 +Contact: [email protected] +Description: + The avail_resources subdirectory contains read-only files that + indicate the available number of resources in the device. + "Available" here means resources that are not currently in use + by an application or, in the case of a physical function + device, assigned to a virtual function. + + num_atomic_inflights: Available number of atomic inflights in + the device. + + num_dir_ports: Available number of directed ports (and + queues) in the device. + + num_hist_list_entries: Available number of history list entries + in the device. + + num_ldb_credits: Available number of load-balanced credits + in the device. + + num_ldb_ports: Available number of load-balanced ports + in the device. + + num_cos<M>_ldb_ports: Available number of load-balanced ports + belonging to class-of-service M in the + device. + + num_ldb_queues: Available number of load-balanced queues + in the device. + + num_sched_domains: Available number of scheduling domains in + the device. + + max_ctg_hl_entries: Maximum contiguous history list entries + available in the device. + + Each scheduling domain is created with + an allocation of history list entries, + and each domain's allocation of entries + must be contiguous. + +What: /sys/bus/pci/devices/.../cos_bw/cos<N>_bw_percent +Date: June 22, 2020 +KernelVersion: 5.9 +Contact: [email protected] +Description: Interface for configuring dlb2 class-of-service bandwidths. + + The DLB 2.0 supports four load-balanced port classes of service + (CoS). Each CoS receives a guaranteed percentage of the + load-balanced scheduler's bandwidth, and any unreserved + bandwidth is divided among the four CoS. + + By default, each CoS is guaranteed 25% of the bandwidth. Writing + these files allows the user to change the CoS, subject to the + constraint that the total reserved bandwidth of all CoS cannot + exceed 100%. + + Bandwidth reservations can be modified during run-time. + + These files are only accessible for physical function DLB 2.0 + devices. + +What: /sys/bus/pci/devices/.../dev_id +Date: June 22, 2020 +KernelVersion: 5.9 +Contact: [email protected] +Description: Device ID used in /dev, i.e. /dev/dlb<device ID> + + Each DLB 2.0 PF and VF device is granted a unique ID by the + kernel driver, and this ID is used to construct the device's + /dev directory: /dev/dlb<device ID>. This sysfs file can be read + to determine a device's ID, which allows the user to map a + device file to a PCI BDF.
drivers/misc/dlb2/dlb2_main.c +11 -0
@@ -669,6 +669,10 @@ static int dlb2_probe(struct pci_dev *pdev,if (ret) goto dma_set_mask_fail; + ret = dlb2_dev->ops->sysfs_create (dlb2_dev); +if (ret) + goto sysfs_create_fail; +/* * PM enable must be done before any other MMIO accesses, and this * setting is persistent across device reset.
@@ -719,6 +723,8 @@ static int dlb2_probe(struct pci_dev *pdev, init_interrupts_fail: dlb2_reset_fail: wait_for_device_ready_fail: + dlb2_dev->ops->sysfs_destroy (dlb2_dev); +sysfs_create_fail: dma_set_mask_fail: dlb2_dev->ops->device_destroy (dlb2_dev, dlb2_class); device_add_fail:
@@ -761,6 +767,8 @@ static void dlb2_remove(struct pci_dev *pdev)dlb2_release_device_memory (dlb2_dev); + dlb2_dev->ops->sysfs_destroy (dlb2_dev); + dlb2_dev->ops->device_destroy (dlb2_dev, dlb2_class); dlb2_dev->ops->cdev_del (dlb2_dev);
@@ -786,6 +794,9 @@ static void dlb2_reset_hardware_state(struct dlb2_dev *dev, bool issue_flr)/* Reinitialize interrupt configuration */ dev->ops->reinit_interrupts (dev); +/* Reset configuration done through the sysfs */ + dev->ops->sysfs_reapply (dev); +/* Reinitialize any other hardware state */ dev->ops->init_hardware (dev); }
drivers/misc/dlb2/dlb2_main.h +3 -0
@@ -57,6 +57,9 @@ struct dlb2_device_ops {dev_t base, const struct file_operations *fops);void (*cdev_del)(struct dlb2_dev *dlb2_dev); +int (*sysfs_create)(struct dlb2_dev *dlb2_dev); +void (*sysfs_destroy)(struct dlb2_dev *dlb2_dev); +void (*sysfs_reapply)(struct dlb2_dev *dev);int (*init_interrupts)(struct dlb2_dev *dev,struct pci_dev *pdev); int (*enable_ldb_cq_interrupts)(struct dlb2_dev *dev, int domain_id,
drivers/misc/dlb2/dlb2_pf_ops.c +423 -0
435 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 20/20 dlb2: add ingress error handling
In reply to Gage EadsWhen DLB 2.0 detects that an application enqueued an illegal QE, it fires an ingress error interrupt. The driver processes these errors and notifies user-space through a domain alert.
A malicious application or virtual machine could attempt a denial-of-service attack by enqueueing illegal QEs at a high rate and tying up the PF driver, so the driver tracks the rate of ingress error alarms per second. If they exceed a threshold of 1000/second, the driver simply disables the interrupt. The interrupt is re-enabled when the device is reset, the driver is reloaded, or by a user through a sysfs interface.
--- Documentation/ABI/testing/sysfs-driver-dlb2 | 15 ++ drivers/misc/dlb2/dlb2_hw_types.h | 17 ++ drivers/misc/dlb2/dlb2_main.h | 16 ++ drivers/misc/dlb2/dlb2_pf_ops.c | 177 ++++++++++++++++++++ drivers/misc/dlb2/dlb2_resource.c | 251 +++++++++++++++++++++++++++- drivers/misc/dlb2/dlb2_resource.h | 45 +++++ 6 files changed, 520 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-driver-dlb2 +15 -0
@@ -185,3 +185,18 @@ Description: Device ID used in /dev, i.e. /dev/dlb<device ID> /dev directory: /dev/dlb<device ID>. This sysfs file can be read to determine a device's ID, which allows the user to map a device file to a PCI BDF. + +What: /sys/bus/pci/devices/.../ingress_err_en +Date: June 22, 2020 +KernelVersion: 5.9 +Contact: [email protected] +Description: Interface for re-enabling ingress error interrupts + + If the PF driver detects an overload of ingress error + interrupts, it will -- to prevent a possible denial-of-service + attack -- disable them. + + If the ingress error interrupt is disabled, they will be + re-enabled when the device is reset or the driver is reloaded. + This interface can be used to re-enable the interrupt as well, + and can be read to determine whether the interrupt is enabled.
drivers/misc/dlb2/dlb2_hw_types.h +17 -0
@@ -61,6 +61,23 @@#define DLB2_PF_COMPRESSED_MODE_CQ_VECTOR_ID \ DLB2_PF_NUM_NON_CQ_INTERRUPT_VECTORS +/* DLB non-CQ interrupts (alarm, mailbox, WDT) */ +#define DLB2_INT_NON_CQ 0 + +#define DLB2_ALARM_HW_SOURCE_SYS 0 +#define DLB2_ALARM_HW_SOURCE_DLB 1 + +#define DLB2_ALARM_HW_UNIT_CHP 4 + +#define DLB2_ALARM_SYS_AID_ILLEGAL_QID 3 +#define DLB2_ALARM_SYS_AID_DISABLED_QID 4 +#define DLB2_ALARM_SYS_AID_ILLEGAL_HCW 5 +#define DLB2_ALARM_HW_CHP_AID_ILLEGAL_ENQ 1 +#define DLB2_ALARM_HW_CHP_AID_EXCESS_TOKEN_POPS 2 + +#define DLB2_VF_NUM_NON_CQ_INTERRUPT_VECTORS 1 +#define DLB2_VF_NUM_CQ_INTERRUPT_VECTORS 31 +/* * Hardware-defined base addresses. Those prefixed 'DLB2_DRV' are only used by * the PF driver.
drivers/misc/dlb2/dlb2_main.h +16 -0
@@ -217,6 +217,21 @@ struct dlb2_intr {int mode; }; +/* +* ISR overload is defined as more than DLB2_ISR_OVERLOAD_THRESH interrupts +* (of a particular type) occurring in a 1s period. If overload is detected, +* the driver blocks that interrupt (exact mechanism depending on the +* interrupt) from overloading the PF driver. +*/ +#define DLB2_ISR_OVERLOAD_THRESH 1000 +#define DLB2_ISR_OVERLOAD_PERIOD_S 1 + +struct dlb2_alarm { +ktime_t ts; +unsigned int enabled; +u32 count; +}; +struct dlb2_dev {struct pci_dev *pdev;struct dlb2_hw hw;
@@ -239,6 +254,7 @@ struct dlb2_dev {*/ struct mutex resource_mutex;struct work_struct work; +struct dlb2_alarm ingress_err;enum dlb2_device_type type;int id;dev_t dev_number;
drivers/misc/dlb2/dlb2_pf_ops.c +177 -0
225 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.c +250 -1
263 lines not on this page · raw message
drivers/misc/dlb2/dlb2_resource.h +45 -0
63 lines not on this page · raw message
Signature · 1 line
2.13.6