aboutsummarylogtreecommitdiffstats
path: root/fourteen.patch
blob: 8c20985ad941a3ee50663066e79e4039b86d7a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
--- ./common/inc/nv-time.h
+++ ./common/inc/nv-time.h
@@ -205,7 +205,7 @@
         // the requested timeout has expired, loop until less
         // than a jiffie of the desired delay remains.
         //
-        current->state = TASK_INTERRUPTIBLE;
+        current->__state = TASK_INTERRUPTIBLE;
         do
         {
             schedule_timeout(jiffies);

--- ./conftest.sh
+++ ./conftest.sh
@@ -4736,17 +4736,47 @@
         #
         VERBOSE=$6
         iommu=CONFIG_VFIO_IOMMU_TYPE1
-        mdev=CONFIG_VFIO_MDEV_DEVICE
+        mdev=CONFIG_VFIO_MDEV
         kvm=CONFIG_KVM_VFIO
+        VFIO_IOMMU_PRESENT=0
+        VFIO_MDEV_DEVICE_PRESENT=0
+        KVM_PRESENT=0

         if [ -n "$VGX_KVM_BUILD" ]; then
-            if (test_configuration_option ${iommu} || test_configuration_option ${iommu}_MODULE) &&
-               (test_configuration_option ${mdev} || test_configuration_option ${mdev}_MODULE) &&
-               (test_configuration_option ${kvm} || test_configuration_option ${kvm}_MODULE); then
+            if (test_configuration_option ${iommu} || test_configuration_option ${iommu}_MODULE); then
+                VFIO_IOMMU_PRESENT=1
+            fi
+
+            if (test_configuration_option ${mdev} || test_configuration_option ${mdev}_MODULE); then
+                VFIO_MDEV_DEVICE_PRESENT=1
+            fi
+
+            if (test_configuration_option ${kvm} || test_configuration_option ${kvm}_MODULE); then
+                KVM_PRESENT=1
+            fi
+
+            if [ "$VFIO_IOMMU_PRESENT" != "0" ] &&
+               [ "$VFIO_MDEV_DEVICE_PRESENT" != "0" ] &&
+               [ "$KVM_PRESENT" != "0" ] ; then
                     exit 0
             else
-                echo "The kernel is not running a vGPU on KVM host.";
+                echo "Below CONFIG options are missing on the kernel for installing";
+                echo "NVIDIA vGPU driver on KVM host";
+                if [ "$VFIO_IOMMU_PRESENT" = "0" ]; then
+                    echo "CONFIG_VFIO_IOMMU_TYPE1";
+                fi
+
+                if [ "$VFIO_MDEV_DEVICE_PRESENT" = "0" ]; then
+                    echo "CONFIG_VFIO_MDEV_DEVICE";
+                fi
+
+                if [ "$KVM_PRESENT" = "0" ]; then
+                    echo "CONFIG_KVM";
+                fi
+                echo "Please install the kernel with above CONFIG options set, then";
+                echo "try installing again";
                 echo "";
+
                 if [ "$VERBOSE" = "full_output" ]; then
                     echo "*** Failed vGPU on KVM sanity check. Bailing out! ***";
                     echo "";

--- ./Kbuild
+++ ./Kbuild
@@ -75,7 +75,7 @@
 EXTRA_CFLAGS += -D__KERNEL__ -DMODULE -DNVRM -DNV_VERSION_STRING=\"460.73.01\" -Wno-unused-function -Wuninitialized -fno-strict-aliasing -mno-red-zone -mcmodel=kernel -DNV_UVM_ENABLE
 EXTRA_CFLAGS += $(call cc-option,-Werror=undef,)
 EXTRA_CFLAGS += -DNV_SPECTRE_V2=$(NV_SPECTRE_V2)
-EXTRA_CFLAGS += -DNV_KERNEL_INTERFACE_LAYER
+EXTRA_CFLAGS += -DNV_KERNEL_INTERFACE_LAYER -Wfatal-errors

 #
 # Detect SGI UV systems and apply system-specific optimizations.

--- ./nvidia-drm/nvidia-drm-crtc.c
+++ ./nvidia-drm/nvidia-drm-crtc.c
@@ -227,7 +227,7 @@
 }

 static int nv_drm_plane_atomic_check(struct drm_plane *plane,
-                                     struct drm_plane_state *plane_state)
+                                     struct drm_atomic_state *plane_state)
 {
     int i;
     struct drm_crtc *crtc;
@@ -238,7 +238,7 @@
         goto done;
     }

-    nv_drm_for_each_crtc_in_state(plane_state->state, crtc, crtc_state, i) {
+    nv_drm_for_each_crtc_in_state(plane_state, crtc, crtc_state, i) {
         struct nv_drm_crtc_state *nv_crtc_state = to_nv_crtc_state(crtc_state);
         struct NvKmsKapiHeadRequestedConfig *head_req_config =
             &nv_crtc_state->req_config;
@@ -246,14 +246,14 @@
             &head_req_config->layerRequestedConfig[type];

         if (plane->state->crtc == crtc &&
-            plane->state->crtc != plane_state->crtc) {
+            plane->state->crtc != plane_state->crtcs->ptr) {
             plane_req_config_disable(plane_requested_config);
             continue;
         }

-        if (plane_state->crtc == crtc) {
+        if (plane_state->crtcs->ptr == crtc) {
             plane_req_config_update(plane,
-                                    plane_state,
+                                    plane_state->planes->state,
                                     plane_requested_config);

             if (__is_async_flip_requested(plane, crtc_state)) {
@@ -276,12 +276,12 @@
 }

 static void nv_drm_plane_atomic_update(struct drm_plane *plane,
-                                       struct drm_plane_state *old_state)
+                                       struct drm_atomic_state *old_state)
 {
 }

 static void nv_drm_plane_atomic_disable(struct drm_plane *plane,
-                                        struct drm_plane_state *old_state)
+                                        struct drm_atomic_state *old_state)
 {
 }

--- ./nvidia-drm/nvidia-drm-drv.c
+++ ./nvidia-drm/nvidia-drm-drv.c
@@ -866,7 +866,7 @@
     dev->dev_private = nv_dev;
     nv_dev->dev = dev;
     if (device->bus == &pci_bus_type) {
-        dev->pdev = to_pci_dev(device);
+        //dev->pdev = to_pci_dev(device);
     }

     /* Register DRM device to DRM sub-system */

--- ./nvidia-vgpu-vfio/nvidia-vgpu-vfio.c
+++ ./nvidia-vgpu-vfio/nvidia-vgpu-vfio.c
@@ -25,6 +25,9 @@
 #include <linux/init.h>
 #include <linux/err.h>
 #include <linux/eventfd.h>
+#include <uapi/linux/uuid.h>
+#include <linux/device.h>
+#include <linux/mdev.h>
 #include "nvstatus.h"
 #include "nv-misc.h"
 #include "nv-linux.h"
@@ -38,6 +41,25 @@
 struct vgpu_devs vgpu_devices;
 struct phys_devs phys_devices;

+struct mdev_parent {
+	struct device *dev;
+	const struct mdev_parent_ops *ops;
+	struct kref ref;
+	struct list_head next;
+	struct kset *mdev_types_kset;
+	struct list_head type_list;
+	/* Synchronize device creation/removal with parent unregistration */
+	struct rw_semaphore unreg_sem;
+};
+
+struct mdev_type {
+	struct kobject kobj;
+	struct kobject *devices_kobj;
+	struct mdev_parent *parent;
+	struct list_head next;
+	unsigned int type_group_id;
+};
+
 #define SLEEP_TIME_MILLISECONDS 20
 #define VGPU_EXIT_TIMEOUT_MILLISECONDS 5000
 #define WAITQUEUE_TIMEOUT_SECONDS 25000
@@ -203,8 +225,8 @@
     .remove           = nv_vgpu_vfio_destroy,
     .read             = nv_vgpu_vfio_read,
     .write            = nv_vgpu_vfio_write,
-    .open             = nv_vgpu_vfio_open,
-    .release          = nv_vgpu_vfio_close,
+    .open_device      = nv_vgpu_vfio_open,
+    .close_device    = nv_vgpu_vfio_close,
     .ioctl            = nv_vgpu_vfio_ioctl,
     .mmap             = nv_vgpu_vfio_mmap,
 };
@@ -412,9 +434,9 @@
     return NV_OK;
 }

-static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
+static ssize_t name_show(struct mdev_type *mtype, struct mdev_type_attribute *attr, char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
+    struct pci_dev *pdev = to_pci_dev(mtype->parent->dev);
     struct pci_dev *parent_device;
     NvU32 vgpu_type_id;
     NV_STATUS status;
@@ -425,7 +447,7 @@

         parent_device = pdev;

-    if (nv_get_vgpu_type_id(kobj->name, dev, &vgpu_type_id)
+    if (nv_get_vgpu_type_id(mtype->kobj.name, mtype->parent->dev, &vgpu_type_id)
          == NV_OK)
         status = rm_vgpu_vfio_ops.get_name(parent_device, vgpu_type_id, buf);
     else
@@ -438,9 +460,9 @@
 }
 MDEV_TYPE_ATTR_RO(name);

-static ssize_t description_show(struct kobject *kobj, struct device *dev, char *buf)
+static ssize_t description_show(struct mdev_type *mtype, struct mdev_type_attribute *attr, char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
+    struct pci_dev *pdev = to_pci_dev(mtype->parent->dev);
     struct pci_dev *parent_device;
     NvU32 vgpu_type_id;
     NV_STATUS status;
@@ -451,7 +473,7 @@

         parent_device = pdev;

-    if (nv_get_vgpu_type_id(kobj->name, dev, &vgpu_type_id)
+    if (nv_get_vgpu_type_id(mtype->kobj.name, mtype->parent->dev, &vgpu_type_id)
          == NV_OK)
         status = rm_vgpu_vfio_ops.get_description(parent_device, vgpu_type_id, buf);
     else
@@ -464,13 +486,13 @@
 }
 MDEV_TYPE_ATTR_RO(description);

-static ssize_t available_instances_show(struct kobject *kobj, struct device *dev, char *buf)
+static ssize_t available_instances_show(struct mdev_type *t, struct mdev_type_attribute *ta, char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
+    struct pci_dev *pdev = to_pci_dev(t->parent->dev);
     NvU32 vgpu_type_id;
     NV_STATUS status;

-    if ((nv_get_vgpu_type_id(kobj->name, dev, &vgpu_type_id)) == NV_OK)
+    if ((nv_get_vgpu_type_id(t->kobj.name, t->parent->dev, &vgpu_type_id)) == NV_OK)
         status = rm_vgpu_vfio_ops.get_instances(pdev, vgpu_type_id, buf);
     else
         return -EINVAL;
@@ -482,8 +504,7 @@
 }
 MDEV_TYPE_ATTR_RO(available_instances);

-static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
-                               char *buf)
+static ssize_t device_api_show(struct mdev_type *t, struct mdev_type_attribute *ta, char *buf)
 {
     return sprintf(buf, "%s\n",
                    VFIO_DEVICE_API_PCI_STRING);
@@ -578,7 +599,7 @@
     return ret;
 }

-static int nv_vgpu_vfio_create(struct kobject *kobj, struct mdev_device *mdev)
+static int nv_vgpu_vfio_create(struct mdev_device *mdev)
 {
     NV_STATUS status = NV_OK;
     vgpu_dev_t *vgpu_dev = NULL;
@@ -600,7 +621,7 @@
     if (!pdev)
         return -EINVAL;

-    if (nv_get_vgpu_type_id(kobj->name, NV_GET_MDEV_PARENT(mdev), &vgpu_type_id)
+    if (nv_get_vgpu_type_id(mdev->type->kobj.name, NV_GET_MDEV_PARENT(mdev), &vgpu_type_id)
         != NV_OK)
     {
         ret = -EINVAL;
@@ -676,12 +697,7 @@
     if (pdev->is_virtfn)
     {
 #if defined(NV_MDEV_SET_IOMMU_DEVICE_PRESENT)
-        ret = mdev_set_iommu_device(NV_GET_MDEV_DEV(mdev), NV_GET_MDEV_PARENT(mdev));
-        if (ret != 0)
-        {
-            NV_VGPU_DEV_LOG(VGPU_ERR, mdev, "Failed to set IOMMU device. ret: %d \n", ret);
-            goto remove_vgpu;
-        }
+        mdev_set_iommu_device(mdev, NV_GET_MDEV_PARENT(mdev));
 #endif
     }

--- ./nvidia-vgpu-vfio/nvidia-vgpu-vfio.h
+++ ./nvidia-vgpu-vfio/nvidia-vgpu-vfio.h
@@ -37,7 +37,6 @@
 #include <linux/list.h>
 #include <linux/pci.h>
 #include <linux/sched.h>
-#include <linux/eventfd.h>

 struct vgpu_dev_s;
 struct mapping_node_s;
@@ -52,7 +51,7 @@
 static NV_STATUS  nv_vgpu_vfio_validate_map_request(struct mdev_device *, loff_t, NvU64 *,
                                                     NvU64 *, NvU64 *, pgprot_t *, NvBool *);
 static void       nv_vgpu_remove(struct pci_dev *);
-static int        nv_vgpu_vfio_create(struct kobject *, struct mdev_device *);
+static int        nv_vgpu_vfio_create(struct mdev_device *);
 static int        nv_vgpu_vfio_destroy(struct mdev_device *mdev);
 static int        nv_vgpu_vfio_open(struct mdev_device *);
 static void       nv_vgpu_vfio_close(struct mdev_device *);
@@ -307,6 +306,7 @@

 } intr_info_t;

+
 typedef struct
 {
     NvU64 pending;