History

iommufd: File descriptor, context, kconfig and makefiles

This is the basic infrastructure of a new miscdevice to hold the iommufd IOCTL API. It provides: - A miscdevice to create file descriptors to run the IOCTL interface over - A table based ioctl dispatch and centralized extendable pre-validation step - An xarray mapping userspace ID's to kernel objects. The design has multiple inter-related objects held within in a single IOMMUFD fd - A simple usage count to build a graph of object relations and protect against hostile userspace racing ioctls The only IOCTL provided in this patch is the generic 'destroy any object by handle' operation.

Jason Gunthorpe committed 3 years ago

Commit 2ff4bed1 parent 658234d10 files · +571 −1Browse files

Showing the changes to include/uapi (1 of 10 files). Show all

Unified · Split

include/uapi/linux/iommufd.h+55−0
@@ -0,0 +1,55 @@
1+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+/* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES.
3+ */
4+#ifndef _UAPI_IOMMUFD_H
5+#define _UAPI_IOMMUFD_H
6+
7+#include <linux/types.h>
8+#include <linux/ioctl.h>
9+
10+#define IOMMUFD_TYPE (';')
11+
12+/**
13+ * DOC: General ioctl format
14+ *
15+ * The ioctl interface follows a general format to allow for extensibility. Each
16+ * ioctl is passed in a structure pointer as the argument providing the size of
17+ * the structure in the first u32. The kernel checks that any structure space
18+ * beyond what it understands is 0. This allows userspace to use the backward
19+ * compatible portion while consistently using the newer, larger, structures.
20+ *
21+ * ioctls use a standard meaning for common errnos:
22+ *
23+ * - ENOTTY: The IOCTL number itself is not supported at all
24+ * - E2BIG: The IOCTL number is supported, but the provided structure has
25+ * non-zero in a part the kernel does not understand.
26+ * - EOPNOTSUPP: The IOCTL number is supported, and the structure is
27+ * understood, however a known field has a value the kernel does not
28+ * understand or support.
29+ * - EINVAL: Everything about the IOCTL was understood, but a field is not
30+ * correct.
31+ * - ENOENT: An ID or IOVA provided does not exist.
32+ * - ENOMEM: Out of memory.
33+ * - EOVERFLOW: Mathematics overflowed.
34+ *
35+ * As well as additional errnos, within specific ioctls.
36+ */
37+enum {
38+ IOMMUFD_CMD_BASE = 0x80,
39+ IOMMUFD_CMD_DESTROY = IOMMUFD_CMD_BASE,
40+};
41+
42+/**
43+ * struct iommu_destroy - ioctl(IOMMU_DESTROY)
44+ * @size: sizeof(struct iommu_destroy)
45+ * @id: iommufd object ID to destroy. Can by any destroyable object type.
46+ *
47+ * Destroy any object held within iommufd.
48+ */
49+struct iommu_destroy {
50+ __u32 size;
51+ __u32 id;
52+};
53+#define IOMMU_DESTROY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DESTROY)
54+
55+#endif