Skip to content

Commit d3cf405

Browse files
committed
Merge tag 'vfio-v6.1-rc1' of https://github.com/awilliam/linux-vfio
Pull VFIO updates from Alex Williamson: - Prune private items from vfio_pci_core.h to a new internal header, fix missed function rename, and refactor vfio-pci interrupt defines (Jason Gunthorpe) - Create consistent naming and handling of ioctls with a function per ioctl for vfio-pci and vfio group handling, use proper type args where available (Jason Gunthorpe) - Implement a set of low power device feature ioctls allowing userspace to make use of power states such as D3cold where supported (Abhishek Sahu) - Remove device counter on vfio groups, which had restricted the page pinning interface to singleton groups to account for limitations in the type1 IOMMU backend. Document usage as limited to emulated IOMMU devices, ie. traditional mdev devices where this restriction is consistent (Jason Gunthorpe) - Correct function prefix in hisi_acc driver incurred during previous refactoring (Shameer Kolothum) - Correct typo and remove redundant warning triggers in vfio-fsl driver (Christophe JAILLET) - Introduce device level DMA dirty tracking uAPI and implementation in the mlx5 variant driver (Yishai Hadas & Joao Martins) - Move much of the vfio_device life cycle management into vfio core, simplifying and avoiding duplication across drivers. This also facilitates adding a struct device to vfio_device which begins the introduction of device rather than group level user support and fills a gap allowing userspace identify devices as vfio capable without implicit knowledge of the driver (Kevin Tian & Yi Liu) - Split vfio container handling to a separate file, creating a more well defined API between the core and container code, masking IOMMU backend implementation from the core, allowing for an easier future transition to an iommufd based implementation of the same (Jason Gunthorpe) - Attempt to resolve race accessing the iommu_group for a device between vfio releasing DMA ownership and removal of the device from the IOMMU driver. Follow-up with support to allow vfio_group to exist with NULL iommu_group pointer to support existing userspace use cases of holding the group file open (Jason Gunthorpe) - Fix error code and hi/lo register manipulation issues in the hisi_acc variant driver, along with various code cleanups (Longfang Liu) - Fix a prior regression in GVT-g group teardown, resulting in unreleased resources (Jason Gunthorpe) - A significant cleanup and simplification of the mdev interface, consolidating much of the open coded per driver sysfs interface support into the mdev core (Christoph Hellwig) - Simplification of tracking and locking around vfio_groups that fall out from previous refactoring (Jason Gunthorpe) - Replace trivial open coded f_ops tests with new helper (Alex Williamson) * tag 'vfio-v6.1-rc1' of https://github.com/awilliam/linux-vfio: (77 commits) vfio: More vfio_file_is_group() use cases vfio: Make the group FD disassociate from the iommu_group vfio: Hold a reference to the iommu_group in kvm for SPAPR vfio: Add vfio_file_is_group() vfio: Change vfio_group->group_rwsem to a mutex vfio: Remove the vfio_group->users and users_comp vfio/mdev: add mdev available instance checking to the core vfio/mdev: consolidate all the description sysfs into the core code vfio/mdev: consolidate all the available_instance sysfs into the core code vfio/mdev: consolidate all the name sysfs into the core code vfio/mdev: consolidate all the device_api sysfs into the core code vfio/mdev: remove mtype_get_parent_dev vfio/mdev: remove mdev_parent_dev vfio/mdev: unexport mdev_bus_type vfio/mdev: remove mdev_from_dev vfio/mdev: simplify mdev_type handling vfio/mdev: embedd struct mdev_parent in the parent data structure vfio/mdev: make mdev.h standalone includable drm/i915/gvt: simplify vgpu configuration management drm/i915/gvt: fix a memory leak in intel_gvt_init_vgpu_types ...
2 parents 778ce72 + b1b8132 commit d3cf405

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+4888
-2721
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
What: /sys/.../<device>/vfio-dev/vfioX/
2+
Date: September 2022
3+
Contact: Yi Liu <[email protected]>
4+
Description:
5+
This directory is created when the device is bound to a
6+
vfio driver. The layout under this directory matches what
7+
exists for a standard 'struct device'. 'X' is a unique
8+
index marking this device in vfio.

Documentation/driver-api/vfio-mediated-device.rst

+12-14
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ devices as examples, as these devices are the first devices to use this module::
5858
| MDEV CORE |
5959
| MODULE |
6060
| mdev.ko |
61-
| +-----------+ | mdev_register_device() +--------------+
61+
| +-----------+ | mdev_register_parent() +--------------+
6262
| | | +<------------------------+ |
6363
| | | | | nvidia.ko |<-> physical
6464
| | | +------------------------>+ | device
6565
| | | | callbacks +--------------+
6666
| | Physical | |
67-
| | device | | mdev_register_device() +--------------+
67+
| | device | | mdev_register_parent() +--------------+
6868
| | interface | |<------------------------+ |
6969
| | | | | i915.ko |<-> physical
7070
| | | +------------------------>+ | device
7171
| | | | callbacks +--------------+
7272
| | | |
73-
| | | | mdev_register_device() +--------------+
73+
| | | | mdev_register_parent() +--------------+
7474
| | | +<------------------------+ |
7575
| | | | | ccw_device.ko|<-> physical
7676
| | | +------------------------>+ | device
@@ -103,7 +103,8 @@ structure to represent a mediated device's driver::
103103
struct mdev_driver {
104104
int (*probe) (struct mdev_device *dev);
105105
void (*remove) (struct mdev_device *dev);
106-
struct attribute_group **supported_type_groups;
106+
unsigned int (*get_available)(struct mdev_type *mtype);
107+
ssize_t (*show_description)(struct mdev_type *mtype, char *buf);
107108
struct device_driver driver;
108109
};
109110

@@ -125,16 +126,16 @@ vfio_device_ops.
125126
When a driver wants to add the GUID creation sysfs to an existing device it has
126127
probe'd to then it should call::
127128

128-
int mdev_register_device(struct device *dev,
129-
struct mdev_driver *mdev_driver);
129+
int mdev_register_parent(struct mdev_parent *parent, struct device *dev,
130+
struct mdev_driver *mdev_driver);
130131

131132
This will provide the 'mdev_supported_types/XX/create' files which can then be
132133
used to trigger the creation of a mdev_device. The created mdev_device will be
133134
attached to the specified driver.
134135

135136
When the driver needs to remove itself it calls::
136137

137-
void mdev_unregister_device(struct device *dev);
138+
void mdev_unregister_parent(struct mdev_parent *parent);
138139

139140
Which will unbind and destroy all the created mdevs and remove the sysfs files.
140141

@@ -200,17 +201,14 @@ Directories and files under the sysfs for Each Physical Device
200201

201202
sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name);
202203

203-
(or using mdev_parent_dev(mdev) to arrive at the parent device outside
204-
of the core mdev code)
205-
206204
* device_api
207205

208-
This attribute should show which device API is being created, for example,
206+
This attribute shows which device API is being created, for example,
209207
"vfio-pci" for a PCI device.
210208

211209
* available_instances
212210

213-
This attribute should show the number of devices of type <type-id> that can be
211+
This attribute shows the number of devices of type <type-id> that can be
214212
created.
215213

216214
* [device]
@@ -220,11 +218,11 @@ Directories and files under the sysfs for Each Physical Device
220218

221219
* name
222220

223-
This attribute should show human readable name. This is optional attribute.
221+
This attribute shows a human readable name.
224222

225223
* description
226224

227-
This attribute should show brief features/description of the type. This is
225+
This attribute can show brief features/description of the type. This is an
228226
optional attribute.
229227

230228
Directories and Files Under the sysfs for Each mdev Device

Documentation/s390/vfio-ap.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ of the VFIO AP mediated device driver::
297297
| MDEV CORE |
298298
| MODULE |
299299
| mdev.ko |
300-
| +---------+ | mdev_register_device() +--------------+
300+
| +---------+ | mdev_register_parent() +--------------+
301301
| |Physical | +<-----------------------+ |
302302
| | device | | | vfio_ap.ko |<-> matrix
303303
| |interface| +----------------------->+ | device

Documentation/s390/vfio-ccw.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Below is a high Level block diagram::
156156
| MDEV CORE |
157157
| MODULE |
158158
| mdev.ko |
159-
| +---------+ | mdev_register_device() +--------------+
159+
| +---------+ | mdev_register_parent() +--------------+
160160
| |Physical | +<-----------------------+ |
161161
| | device | | | vfio_ccw.ko |<-> subchannel
162162
| |interface| +----------------------->+ | device

MAINTAINERS

+1
Original file line numberDiff line numberDiff line change
@@ -21558,6 +21558,7 @@ R: Cornelia Huck <[email protected]>
2155821558
2155921559
S: Maintained
2156021560
T: git git://github.com/awilliam/linux-vfio.git
21561+
F: Documentation/ABI/testing/sysfs-devices-vfio-dev
2156121562
F: Documentation/driver-api/vfio.rst
2156221563
F: drivers/vfio/
2156321564
F: include/linux/vfio.h

drivers/gpu/drm/i915/gvt/aperture_gm.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ static void free_resource(struct intel_vgpu *vgpu)
240240
}
241241

242242
static int alloc_resource(struct intel_vgpu *vgpu,
243-
struct intel_vgpu_creation_params *param)
243+
const struct intel_vgpu_config *conf)
244244
{
245245
struct intel_gvt *gvt = vgpu->gvt;
246246
unsigned long request, avail, max, taken;
247247
const char *item;
248248

249-
if (!param->low_gm_sz || !param->high_gm_sz || !param->fence_sz) {
249+
if (!conf->low_mm || !conf->high_mm || !conf->fence) {
250250
gvt_vgpu_err("Invalid vGPU creation params\n");
251251
return -EINVAL;
252252
}
@@ -255,7 +255,7 @@ static int alloc_resource(struct intel_vgpu *vgpu,
255255
max = gvt_aperture_sz(gvt) - HOST_LOW_GM_SIZE;
256256
taken = gvt->gm.vgpu_allocated_low_gm_size;
257257
avail = max - taken;
258-
request = MB_TO_BYTES(param->low_gm_sz);
258+
request = conf->low_mm;
259259

260260
if (request > avail)
261261
goto no_enough_resource;
@@ -266,7 +266,7 @@ static int alloc_resource(struct intel_vgpu *vgpu,
266266
max = gvt_hidden_sz(gvt) - HOST_HIGH_GM_SIZE;
267267
taken = gvt->gm.vgpu_allocated_high_gm_size;
268268
avail = max - taken;
269-
request = MB_TO_BYTES(param->high_gm_sz);
269+
request = conf->high_mm;
270270

271271
if (request > avail)
272272
goto no_enough_resource;
@@ -277,16 +277,16 @@ static int alloc_resource(struct intel_vgpu *vgpu,
277277
max = gvt_fence_sz(gvt) - HOST_FENCE;
278278
taken = gvt->fence.vgpu_allocated_fence_num;
279279
avail = max - taken;
280-
request = param->fence_sz;
280+
request = conf->fence;
281281

282282
if (request > avail)
283283
goto no_enough_resource;
284284

285285
vgpu_fence_sz(vgpu) = request;
286286

287-
gvt->gm.vgpu_allocated_low_gm_size += MB_TO_BYTES(param->low_gm_sz);
288-
gvt->gm.vgpu_allocated_high_gm_size += MB_TO_BYTES(param->high_gm_sz);
289-
gvt->fence.vgpu_allocated_fence_num += param->fence_sz;
287+
gvt->gm.vgpu_allocated_low_gm_size += conf->low_mm;
288+
gvt->gm.vgpu_allocated_high_gm_size += conf->high_mm;
289+
gvt->fence.vgpu_allocated_fence_num += conf->fence;
290290
return 0;
291291

292292
no_enough_resource:
@@ -340,11 +340,11 @@ void intel_vgpu_reset_resource(struct intel_vgpu *vgpu)
340340
*
341341
*/
342342
int intel_vgpu_alloc_resource(struct intel_vgpu *vgpu,
343-
struct intel_vgpu_creation_params *param)
343+
const struct intel_vgpu_config *conf)
344344
{
345345
int ret;
346346

347-
ret = alloc_resource(vgpu, param);
347+
ret = alloc_resource(vgpu, conf);
348348
if (ret)
349349
return ret;
350350

drivers/gpu/drm/i915/gvt/gvt.h

+24-22
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <uapi/linux/pci_regs.h>
3737
#include <linux/kvm_host.h>
3838
#include <linux/vfio.h>
39+
#include <linux/mdev.h>
3940

4041
#include "i915_drv.h"
4142
#include "intel_gvt.h"
@@ -172,6 +173,7 @@ struct intel_vgpu_submission {
172173
#define KVMGT_DEBUGFS_FILENAME "kvmgt_nr_cache_entries"
173174

174175
struct intel_vgpu {
176+
struct vfio_device vfio_device;
175177
struct intel_gvt *gvt;
176178
struct mutex vgpu_lock;
177179
int id;
@@ -211,7 +213,6 @@ struct intel_vgpu {
211213

212214
u32 scan_nonprivbb;
213215

214-
struct vfio_device vfio_device;
215216
struct vfio_region *region;
216217
int num_regions;
217218
struct eventfd_ctx *intx_trigger;
@@ -294,15 +295,25 @@ struct intel_gvt_firmware {
294295
bool firmware_loaded;
295296
};
296297

297-
#define NR_MAX_INTEL_VGPU_TYPES 20
298-
struct intel_vgpu_type {
299-
char name[16];
300-
unsigned int avail_instance;
301-
unsigned int low_gm_size;
302-
unsigned int high_gm_size;
298+
struct intel_vgpu_config {
299+
unsigned int low_mm;
300+
unsigned int high_mm;
303301
unsigned int fence;
302+
303+
/*
304+
* A vGPU with a weight of 8 will get twice as much GPU as a vGPU with
305+
* a weight of 4 on a contended host, different vGPU type has different
306+
* weight set. Legal weights range from 1 to 16.
307+
*/
304308
unsigned int weight;
305-
enum intel_vgpu_edid resolution;
309+
enum intel_vgpu_edid edid;
310+
const char *name;
311+
};
312+
313+
struct intel_vgpu_type {
314+
struct mdev_type type;
315+
char name[16];
316+
const struct intel_vgpu_config *conf;
306317
};
307318

308319
struct intel_gvt {
@@ -326,6 +337,8 @@ struct intel_gvt {
326337
struct intel_gvt_workload_scheduler scheduler;
327338
struct notifier_block shadow_ctx_notifier_block[I915_NUM_ENGINES];
328339
DECLARE_HASHTABLE(cmd_table, GVT_CMD_HASH_BITS);
340+
struct mdev_parent parent;
341+
struct mdev_type **mdev_types;
329342
struct intel_vgpu_type *types;
330343
unsigned int num_types;
331344
struct intel_vgpu *idle_vgpu;
@@ -436,19 +449,8 @@ int intel_gvt_load_firmware(struct intel_gvt *gvt);
436449
/* ring context size i.e. the first 0x50 dwords*/
437450
#define RING_CTX_SIZE 320
438451

439-
struct intel_vgpu_creation_params {
440-
__u64 low_gm_sz; /* in MB */
441-
__u64 high_gm_sz; /* in MB */
442-
__u64 fence_sz;
443-
__u64 resolution;
444-
__s32 primary;
445-
__u64 vgpu_id;
446-
447-
__u32 weight;
448-
};
449-
450452
int intel_vgpu_alloc_resource(struct intel_vgpu *vgpu,
451-
struct intel_vgpu_creation_params *param);
453+
const struct intel_vgpu_config *conf);
452454
void intel_vgpu_reset_resource(struct intel_vgpu *vgpu);
453455
void intel_vgpu_free_resource(struct intel_vgpu *vgpu);
454456
void intel_vgpu_write_fence(struct intel_vgpu *vgpu,
@@ -494,8 +496,8 @@ void intel_gvt_clean_vgpu_types(struct intel_gvt *gvt);
494496

495497
struct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt);
496498
void intel_gvt_destroy_idle_vgpu(struct intel_vgpu *vgpu);
497-
struct intel_vgpu *intel_gvt_create_vgpu(struct intel_gvt *gvt,
498-
struct intel_vgpu_type *type);
499+
int intel_gvt_create_vgpu(struct intel_vgpu *vgpu,
500+
const struct intel_vgpu_config *conf);
499501
void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu);
500502
void intel_gvt_release_vgpu(struct intel_vgpu *vgpu);
501503
void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr,

0 commit comments

Comments
 (0)