Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit beb6d3a

Browse files
committed
Merge remote-tracking branch 'origin/gvt-next' into gvt-staging
2 parents b5fab9b + 8884717 commit beb6d3a

Some content is hidden

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

42 files changed

+2531
-3138
lines changed

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

+5-22
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ structure to represent a mediated device's driver::
105105
struct mdev_driver {
106106
int (*probe) (struct mdev_device *dev);
107107
void (*remove) (struct mdev_device *dev);
108+
struct attribute_group **supported_type_groups;
108109
struct device_driver driver;
109110
};
110111

@@ -119,33 +120,15 @@ to register and unregister itself with the core driver:
119120

120121
extern void mdev_unregister_driver(struct mdev_driver *drv);
121122

122-
The mediated bus driver is responsible for adding mediated devices to the VFIO
123-
group when devices are bound to the driver and removing mediated devices from
124-
the VFIO when devices are unbound from the driver.
125-
126-
127-
Physical Device Driver Interface
128-
--------------------------------
129-
130-
The physical device driver interface provides the mdev_parent_ops[3] structure
131-
to define the APIs to manage work in the mediated core driver that is related
132-
to the physical device.
133-
134-
The structures in the mdev_parent_ops structure are as follows:
135-
136-
* dev_attr_groups: attributes of the parent device
137-
* mdev_attr_groups: attributes of the mediated device
138-
* supported_config: attributes to define supported configurations
139-
* device_driver: device driver to bind for mediated device instances
140-
141-
The mdev_parent_ops also still has various functions pointers. Theses exist
142-
for historical reasons only and shall not be used for new drivers.
123+
The mediated bus driver's probe function should create a vfio_device on top of
124+
the mdev_device and connect it to an appropriate implementation of
125+
vfio_device_ops.
143126

144127
When a driver wants to add the GUID creation sysfs to an existing device it has
145128
probe'd to then it should call::
146129

147130
extern int mdev_register_device(struct device *dev,
148-
const struct mdev_parent_ops *ops);
131+
struct mdev_driver *mdev_driver);
149132

150133
This will provide the 'mdev_supported_types/XX/create' files which can then be
151134
used to trigger the creation of a mdev_device. The created mdev_device will be

drivers/gpu/drm/i915/Kconfig

+13-23
Original file line numberDiff line numberDiff line change
@@ -102,40 +102,30 @@ config DRM_I915_USERPTR
102102
If in doubt, say "Y".
103103

104104
config DRM_I915_GVT
105-
bool "Enable Intel GVT-g graphics virtualization host support"
105+
bool
106+
107+
config DRM_I915_GVT_KVMGT
108+
tristate "Enable KVM host support Intel GVT-g graphics virtualization"
106109
depends on DRM_I915
107110
depends on X86
108111
depends on 64BIT
109-
default n
112+
depends on KVM
113+
depends on VFIO_MDEV
114+
select DRM_I915_GVT
115+
select KVM_EXTERNAL_WRITE_TRACKING
116+
110117
help
111118
Choose this option if you want to enable Intel GVT-g graphics
112119
virtualization technology host support with integrated graphics.
113120
With GVT-g, it's possible to have one integrated graphics
114-
device shared by multiple VMs under different hypervisors.
115-
116-
Note that at least one hypervisor like Xen or KVM is required for
117-
this driver to work, and it only supports newer device from
118-
Broadwell+. For further information and setup guide, you can
119-
visit: http://01.org/igvt-g.
121+
device shared by multiple VMs under KVM.
120122

121-
Now it's just a stub to support the modifications of i915 for
122-
GVT device model. It requires at least one MPT modules for Xen/KVM
123-
and other components of GVT device model to work. Use it under
124-
you own risk.
123+
Note that this driver only supports newer device from Broadwell on.
124+
For further information and setup guide, you can visit:
125+
http://01.org/igvt-g.
125126

126127
If in doubt, say "N".
127128

128-
config DRM_I915_GVT_KVMGT
129-
tristate "Enable KVM/VFIO support for Intel GVT-g"
130-
depends on DRM_I915_GVT
131-
depends on KVM
132-
depends on VFIO_MDEV
133-
select KVM_EXTERNAL_WRITE_TRACKING
134-
default n
135-
help
136-
Choose this option if you want to enable KVMGT support for
137-
Intel GVT-g.
138-
139129
config DRM_I915_PXP
140130
bool "Enable Intel PXP support"
141131
depends on DRM_I915

drivers/gpu/drm/i915/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ i915-$(CONFIG_DRM_I915_SELFTEST) += \
328328
# virtual gpu code
329329
i915-y += i915_vgpu.o
330330

331-
ifeq ($(CONFIG_DRM_I915_GVT),y)
332-
i915-y += intel_gvt.o
331+
i915-$(CONFIG_DRM_I915_GVT) += \
332+
intel_gvt.o \
333+
intel_gvt_mmio_table.o
333334
include $(src)/gvt/Makefile
334-
endif
335335

336336
obj-$(CONFIG_DRM_I915) += i915.o
337-
obj-$(CONFIG_DRM_I915_GVT_KVMGT) += gvt/kvmgt.o
337+
obj-$(CONFIG_DRM_I915_GVT_KVMGT) += kvmgt.o
338338

339339
# header test
340340

drivers/gpu/drm/i915/gvt/Makefile

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
GVT_DIR := gvt
3-
GVT_SOURCE := gvt.o aperture_gm.o handlers.o vgpu.o trace_points.o firmware.o \
4-
interrupt.o gtt.o cfg_space.o opregion.o mmio.o display.o edid.o \
5-
execlist.o scheduler.o sched_policy.o mmio_context.o cmd_parser.o debugfs.o \
6-
fb_decoder.o dmabuf.o page_track.o
72

8-
ccflags-y += -I $(srctree)/$(src) -I $(srctree)/$(src)/$(GVT_DIR)/
9-
i915-y += $(addprefix $(GVT_DIR)/, $(GVT_SOURCE))
3+
kvmgt-$(CONFIG_DRM_I915_GVT) += \
4+
gvt/aperture_gm.o \
5+
gvt/cfg_space.o \
6+
gvt/cmd_parser.o \
7+
gvt/debugfs.o \
8+
gvt/display.o \
9+
gvt/dmabuf.o \
10+
gvt/edid.o \
11+
gvt/execlist.o \
12+
gvt/fb_decoder.o \
13+
gvt/firmware.o \
14+
gvt/gtt.o \
15+
gvt/handlers.o \
16+
gvt/interrupt.o \
17+
gvt/kvmgt.o \
18+
gvt/mmio.o \
19+
gvt/mmio_context.o \
20+
gvt/opregion.o \
21+
gvt/page_track.o \
22+
gvt/sched_policy.o \
23+
gvt/scheduler.o \
24+
gvt/trace_points.o \
25+
gvt/vgpu.o

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

+17-72
Original file line numberDiff line numberDiff line change
@@ -129,60 +129,16 @@ int intel_vgpu_emulate_cfg_read(struct intel_vgpu *vgpu, unsigned int offset,
129129
return 0;
130130
}
131131

132-
static int map_aperture(struct intel_vgpu *vgpu, bool map)
132+
static void map_aperture(struct intel_vgpu *vgpu, bool map)
133133
{
134-
phys_addr_t aperture_pa = vgpu_aperture_pa_base(vgpu);
135-
unsigned long aperture_sz = vgpu_aperture_sz(vgpu);
136-
u64 first_gfn;
137-
u64 val;
138-
int ret;
139-
140-
if (map == vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_APERTURE].tracked)
141-
return 0;
142-
143-
val = vgpu_cfg_space(vgpu)[PCI_BASE_ADDRESS_2];
144-
if (val & PCI_BASE_ADDRESS_MEM_TYPE_64)
145-
val = *(u64 *)(vgpu_cfg_space(vgpu) + PCI_BASE_ADDRESS_2);
146-
else
147-
val = *(u32 *)(vgpu_cfg_space(vgpu) + PCI_BASE_ADDRESS_2);
148-
149-
first_gfn = (val + vgpu_aperture_offset(vgpu)) >> PAGE_SHIFT;
150-
151-
ret = intel_gvt_hypervisor_map_gfn_to_mfn(vgpu, first_gfn,
152-
aperture_pa >> PAGE_SHIFT,
153-
aperture_sz >> PAGE_SHIFT,
154-
map);
155-
if (ret)
156-
return ret;
157-
158-
vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_APERTURE].tracked = map;
159-
return 0;
134+
if (map != vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_APERTURE].tracked)
135+
vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_APERTURE].tracked = map;
160136
}
161137

162-
static int trap_gttmmio(struct intel_vgpu *vgpu, bool trap)
138+
static void trap_gttmmio(struct intel_vgpu *vgpu, bool trap)
163139
{
164-
u64 start, end;
165-
u64 val;
166-
int ret;
167-
168-
if (trap == vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_GTTMMIO].tracked)
169-
return 0;
170-
171-
val = vgpu_cfg_space(vgpu)[PCI_BASE_ADDRESS_0];
172-
if (val & PCI_BASE_ADDRESS_MEM_TYPE_64)
173-
start = *(u64 *)(vgpu_cfg_space(vgpu) + PCI_BASE_ADDRESS_0);
174-
else
175-
start = *(u32 *)(vgpu_cfg_space(vgpu) + PCI_BASE_ADDRESS_0);
176-
177-
start &= ~GENMASK(3, 0);
178-
end = start + vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_GTTMMIO].size - 1;
179-
180-
ret = intel_gvt_hypervisor_set_trap_area(vgpu, start, end, trap);
181-
if (ret)
182-
return ret;
183-
184-
vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_GTTMMIO].tracked = trap;
185-
return 0;
140+
if (trap != vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_GTTMMIO].tracked)
141+
vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_GTTMMIO].tracked = trap;
186142
}
187143

188144
static int emulate_pci_command_write(struct intel_vgpu *vgpu,
@@ -191,26 +147,17 @@ static int emulate_pci_command_write(struct intel_vgpu *vgpu,
191147
u8 old = vgpu_cfg_space(vgpu)[offset];
192148
u8 new = *(u8 *)p_data;
193149
u8 changed = old ^ new;
194-
int ret;
195150

196151
vgpu_pci_cfg_mem_write(vgpu, offset, p_data, bytes);
197152
if (!(changed & PCI_COMMAND_MEMORY))
198153
return 0;
199154

200155
if (old & PCI_COMMAND_MEMORY) {
201-
ret = trap_gttmmio(vgpu, false);
202-
if (ret)
203-
return ret;
204-
ret = map_aperture(vgpu, false);
205-
if (ret)
206-
return ret;
156+
trap_gttmmio(vgpu, false);
157+
map_aperture(vgpu, false);
207158
} else {
208-
ret = trap_gttmmio(vgpu, true);
209-
if (ret)
210-
return ret;
211-
ret = map_aperture(vgpu, true);
212-
if (ret)
213-
return ret;
159+
trap_gttmmio(vgpu, true);
160+
map_aperture(vgpu, true);
214161
}
215162

216163
return 0;
@@ -230,13 +177,12 @@ static int emulate_pci_rom_bar_write(struct intel_vgpu *vgpu,
230177
return 0;
231178
}
232179

233-
static int emulate_pci_bar_write(struct intel_vgpu *vgpu, unsigned int offset,
180+
static void emulate_pci_bar_write(struct intel_vgpu *vgpu, unsigned int offset,
234181
void *p_data, unsigned int bytes)
235182
{
236183
u32 new = *(u32 *)(p_data);
237184
bool lo = IS_ALIGNED(offset, 8);
238185
u64 size;
239-
int ret = 0;
240186
bool mmio_enabled =
241187
vgpu_cfg_space(vgpu)[PCI_COMMAND] & PCI_COMMAND_MEMORY;
242188
struct intel_vgpu_pci_bar *bars = vgpu->cfg_space.bar;
@@ -259,14 +205,14 @@ static int emulate_pci_bar_write(struct intel_vgpu *vgpu, unsigned int offset,
259205
* Untrap the BAR, since guest hasn't configured a
260206
* valid GPA
261207
*/
262-
ret = trap_gttmmio(vgpu, false);
208+
trap_gttmmio(vgpu, false);
263209
break;
264210
case PCI_BASE_ADDRESS_2:
265211
case PCI_BASE_ADDRESS_3:
266212
size = ~(bars[INTEL_GVT_PCI_BAR_APERTURE].size -1);
267213
intel_vgpu_write_pci_bar(vgpu, offset,
268214
size >> (lo ? 0 : 32), lo);
269-
ret = map_aperture(vgpu, false);
215+
map_aperture(vgpu, false);
270216
break;
271217
default:
272218
/* Unimplemented BARs */
@@ -282,19 +228,18 @@ static int emulate_pci_bar_write(struct intel_vgpu *vgpu, unsigned int offset,
282228
*/
283229
trap_gttmmio(vgpu, false);
284230
intel_vgpu_write_pci_bar(vgpu, offset, new, lo);
285-
ret = trap_gttmmio(vgpu, mmio_enabled);
231+
trap_gttmmio(vgpu, mmio_enabled);
286232
break;
287233
case PCI_BASE_ADDRESS_2:
288234
case PCI_BASE_ADDRESS_3:
289235
map_aperture(vgpu, false);
290236
intel_vgpu_write_pci_bar(vgpu, offset, new, lo);
291-
ret = map_aperture(vgpu, mmio_enabled);
237+
map_aperture(vgpu, mmio_enabled);
292238
break;
293239
default:
294240
intel_vgpu_write_pci_bar(vgpu, offset, new, lo);
295241
}
296242
}
297-
return ret;
298243
}
299244

300245
/**
@@ -336,8 +281,8 @@ int intel_vgpu_emulate_cfg_write(struct intel_vgpu *vgpu, unsigned int offset,
336281
case PCI_BASE_ADDRESS_0 ... PCI_BASE_ADDRESS_5:
337282
if (drm_WARN_ON(&i915->drm, !IS_ALIGNED(offset, 4)))
338283
return -EINVAL;
339-
return emulate_pci_bar_write(vgpu, offset, p_data, bytes);
340-
284+
emulate_pci_bar_write(vgpu, offset, p_data, bytes);
285+
break;
341286
case INTEL_GVT_PCI_SWSCI:
342287
if (drm_WARN_ON(&i915->drm, !IS_ALIGNED(offset, 4)))
343288
return -EINVAL;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ static int cmd_reg_handler(struct parser_exec_state *s,
10111011
if (GRAPHICS_VER(s->engine->i915) == 9 &&
10121012
intel_gvt_mmio_is_sr_in_ctx(gvt, offset) &&
10131013
!strncmp(cmd, "lri", 3)) {
1014-
intel_gvt_hypervisor_read_gpa(s->vgpu,
1014+
intel_gvt_read_gpa(s->vgpu,
10151015
s->workload->ring_context_gpa + 12, &ctx_sr_ctl, 4);
10161016
/* check inhibit context */
10171017
if (ctx_sr_ctl & 1) {
@@ -1775,7 +1775,7 @@ static int copy_gma_to_hva(struct intel_vgpu *vgpu, struct intel_vgpu_mm *mm,
17751775
copy_len = (end_gma - gma) >= (I915_GTT_PAGE_SIZE - offset) ?
17761776
I915_GTT_PAGE_SIZE - offset : end_gma - gma;
17771777

1778-
intel_gvt_hypervisor_read_gpa(vgpu, gpa, va + len, copy_len);
1778+
intel_gvt_read_gpa(vgpu, gpa, va + len, copy_len);
17791779

17801780
len += copy_len;
17811781
gma += copy_len;

0 commit comments

Comments
 (0)