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

Commit 145e06b

Browse files
committed
drm/i915/gvt: Move mdev attribute groups into kvmgt module
As kvmgt module contains all handling for VFIO/mdev, leaving mdev attribute groups in gvt module caused dependency issue. Although it was there for possible other hypervisor usage, that turns out never to be true. So this moves all mdev handling into kvmgt module completely to resolve dependency issue. With this fix, no config workaround is required. So revert previous workaround commits: adaeb71 ("vfio/gvt: fix DRM_I915_GVT dependency on VFIO_MDEV") and 07e543f ("vfio/gvt: Make DRM_I915_GVT depend on VFIO_MDEV"). Reviewed-by: Colin Xu <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Alex Williamson <[email protected]> Signed-off-by: Zhenyu Wang <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e452742 commit 145e06b

File tree

6 files changed

+118
-138
lines changed

6 files changed

+118
-138
lines changed

drivers/gpu/drm/i915/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ config DRM_I915_GVT
102102
bool "Enable Intel GVT-g graphics virtualization host support"
103103
depends on DRM_I915
104104
depends on 64BIT
105-
depends on VFIO_MDEV=y || VFIO_MDEV=DRM_I915
106105
default n
107106
help
108107
Choose this option if you want to enable Intel GVT-g graphics

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

Lines changed: 2 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -46,118 +46,6 @@ static const char * const supported_hypervisors[] = {
4646
[INTEL_GVT_HYPERVISOR_KVM] = "KVM",
4747
};
4848

49-
static struct intel_vgpu_type *
50-
intel_gvt_find_vgpu_type(struct intel_gvt *gvt, unsigned int type_group_id)
51-
{
52-
if (WARN_ON(type_group_id >= gvt->num_types))
53-
return NULL;
54-
return &gvt->types[type_group_id];
55-
}
56-
57-
static ssize_t available_instances_show(struct mdev_type *mtype,
58-
struct mdev_type_attribute *attr,
59-
char *buf)
60-
{
61-
struct intel_vgpu_type *type;
62-
unsigned int num = 0;
63-
void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;
64-
65-
type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype));
66-
if (!type)
67-
num = 0;
68-
else
69-
num = type->avail_instance;
70-
71-
return sprintf(buf, "%u\n", num);
72-
}
73-
74-
static ssize_t device_api_show(struct mdev_type *mtype,
75-
struct mdev_type_attribute *attr, char *buf)
76-
{
77-
return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING);
78-
}
79-
80-
static ssize_t description_show(struct mdev_type *mtype,
81-
struct mdev_type_attribute *attr, char *buf)
82-
{
83-
struct intel_vgpu_type *type;
84-
void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;
85-
86-
type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype));
87-
if (!type)
88-
return 0;
89-
90-
return sprintf(buf, "low_gm_size: %dMB\nhigh_gm_size: %dMB\n"
91-
"fence: %d\nresolution: %s\n"
92-
"weight: %d\n",
93-
BYTES_TO_MB(type->low_gm_size),
94-
BYTES_TO_MB(type->high_gm_size),
95-
type->fence, vgpu_edid_str(type->resolution),
96-
type->weight);
97-
}
98-
99-
static MDEV_TYPE_ATTR_RO(available_instances);
100-
static MDEV_TYPE_ATTR_RO(device_api);
101-
static MDEV_TYPE_ATTR_RO(description);
102-
103-
static struct attribute *gvt_type_attrs[] = {
104-
&mdev_type_attr_available_instances.attr,
105-
&mdev_type_attr_device_api.attr,
106-
&mdev_type_attr_description.attr,
107-
NULL,
108-
};
109-
110-
static struct attribute_group *gvt_vgpu_type_groups[] = {
111-
[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL,
112-
};
113-
114-
static bool intel_get_gvt_attrs(struct attribute_group ***intel_vgpu_type_groups)
115-
{
116-
*intel_vgpu_type_groups = gvt_vgpu_type_groups;
117-
return true;
118-
}
119-
120-
static int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
121-
{
122-
int i, j;
123-
struct intel_vgpu_type *type;
124-
struct attribute_group *group;
125-
126-
for (i = 0; i < gvt->num_types; i++) {
127-
type = &gvt->types[i];
128-
129-
group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL);
130-
if (WARN_ON(!group))
131-
goto unwind;
132-
133-
group->name = type->name;
134-
group->attrs = gvt_type_attrs;
135-
gvt_vgpu_type_groups[i] = group;
136-
}
137-
138-
return 0;
139-
140-
unwind:
141-
for (j = 0; j < i; j++) {
142-
group = gvt_vgpu_type_groups[j];
143-
kfree(group);
144-
}
145-
146-
return -ENOMEM;
147-
}
148-
149-
static void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt)
150-
{
151-
int i;
152-
struct attribute_group *group;
153-
154-
for (i = 0; i < gvt->num_types; i++) {
155-
group = gvt_vgpu_type_groups[i];
156-
gvt_vgpu_type_groups[i] = NULL;
157-
kfree(group);
158-
}
159-
}
160-
16149
static const struct intel_gvt_ops intel_gvt_ops = {
16250
.emulate_cfg_read = intel_vgpu_emulate_cfg_read,
16351
.emulate_cfg_write = intel_vgpu_emulate_cfg_write,
@@ -169,8 +57,6 @@ static const struct intel_gvt_ops intel_gvt_ops = {
16957
.vgpu_reset = intel_gvt_reset_vgpu,
17058
.vgpu_activate = intel_gvt_activate_vgpu,
17159
.vgpu_deactivate = intel_gvt_deactivate_vgpu,
172-
.gvt_find_vgpu_type = intel_gvt_find_vgpu_type,
173-
.get_gvt_attrs = intel_get_gvt_attrs,
17460
.vgpu_query_plane = intel_vgpu_query_plane,
17561
.vgpu_get_dmabuf = intel_vgpu_get_dmabuf,
17662
.write_protect_handler = intel_vgpu_page_track_handler,
@@ -274,7 +160,6 @@ void intel_gvt_clean_device(struct drm_i915_private *i915)
274160
return;
275161

276162
intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu);
277-
intel_gvt_cleanup_vgpu_type_groups(gvt);
278163
intel_gvt_clean_vgpu_types(gvt);
279164

280165
intel_gvt_debugfs_clean(gvt);
@@ -363,12 +248,6 @@ int intel_gvt_init_device(struct drm_i915_private *i915)
363248
if (ret)
364249
goto out_clean_thread;
365250

366-
ret = intel_gvt_init_vgpu_type_groups(gvt);
367-
if (ret) {
368-
gvt_err("failed to init vgpu type groups: %d\n", ret);
369-
goto out_clean_types;
370-
}
371-
372251
vgpu = intel_gvt_create_idle_vgpu(gvt);
373252
if (IS_ERR(vgpu)) {
374253
ret = PTR_ERR(vgpu);
@@ -454,7 +333,8 @@ EXPORT_SYMBOL_GPL(intel_gvt_register_hypervisor);
454333
void
455334
intel_gvt_unregister_hypervisor(void)
456335
{
457-
intel_gvt_hypervisor_host_exit(intel_gvt_host.dev);
336+
void *gvt = (void *)kdev_to_i915(intel_gvt_host.dev)->gvt;
337+
intel_gvt_hypervisor_host_exit(intel_gvt_host.dev, gvt);
458338
module_put(THIS_MODULE);
459339
}
460340
EXPORT_SYMBOL_GPL(intel_gvt_unregister_hypervisor);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,6 @@ struct intel_gvt_ops {
574574
void (*vgpu_reset)(struct intel_vgpu *);
575575
void (*vgpu_activate)(struct intel_vgpu *);
576576
void (*vgpu_deactivate)(struct intel_vgpu *);
577-
struct intel_vgpu_type *(*gvt_find_vgpu_type)(
578-
struct intel_gvt *gvt, unsigned int type_group_id);
579-
bool (*get_gvt_attrs)(struct attribute_group ***intel_vgpu_type_groups);
580577
int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *);
581578
int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int);
582579
int (*write_protect_handler)(struct intel_vgpu *, u64, void *,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum hypervisor_type {
4949
struct intel_gvt_mpt {
5050
enum hypervisor_type type;
5151
int (*host_init)(struct device *dev, void *gvt, const void *ops);
52-
void (*host_exit)(struct device *dev);
52+
void (*host_exit)(struct device *dev, void *gvt);
5353
int (*attach_vgpu)(void *vgpu, unsigned long *handle);
5454
void (*detach_vgpu)(void *vgpu);
5555
int (*inject_msi)(unsigned long handle, u32 addr, u16 data);

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

Lines changed: 113 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,104 @@ static inline bool handle_valid(unsigned long handle)
144144
return !!(handle & ~0xff);
145145
}
146146

147+
static ssize_t available_instances_show(struct mdev_type *mtype,
148+
struct mdev_type_attribute *attr,
149+
char *buf)
150+
{
151+
struct intel_vgpu_type *type;
152+
unsigned int num = 0;
153+
struct intel_gvt *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;
154+
155+
type = &gvt->types[mtype_get_type_group_id(mtype)];
156+
if (!type)
157+
num = 0;
158+
else
159+
num = type->avail_instance;
160+
161+
return sprintf(buf, "%u\n", num);
162+
}
163+
164+
static ssize_t device_api_show(struct mdev_type *mtype,
165+
struct mdev_type_attribute *attr, char *buf)
166+
{
167+
return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING);
168+
}
169+
170+
static ssize_t description_show(struct mdev_type *mtype,
171+
struct mdev_type_attribute *attr, char *buf)
172+
{
173+
struct intel_vgpu_type *type;
174+
struct intel_gvt *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;
175+
176+
type = &gvt->types[mtype_get_type_group_id(mtype)];
177+
if (!type)
178+
return 0;
179+
180+
return sprintf(buf, "low_gm_size: %dMB\nhigh_gm_size: %dMB\n"
181+
"fence: %d\nresolution: %s\n"
182+
"weight: %d\n",
183+
BYTES_TO_MB(type->low_gm_size),
184+
BYTES_TO_MB(type->high_gm_size),
185+
type->fence, vgpu_edid_str(type->resolution),
186+
type->weight);
187+
}
188+
189+
static MDEV_TYPE_ATTR_RO(available_instances);
190+
static MDEV_TYPE_ATTR_RO(device_api);
191+
static MDEV_TYPE_ATTR_RO(description);
192+
193+
static struct attribute *gvt_type_attrs[] = {
194+
&mdev_type_attr_available_instances.attr,
195+
&mdev_type_attr_device_api.attr,
196+
&mdev_type_attr_description.attr,
197+
NULL,
198+
};
199+
200+
static struct attribute_group *gvt_vgpu_type_groups[] = {
201+
[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL,
202+
};
203+
204+
static int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
205+
{
206+
int i, j;
207+
struct intel_vgpu_type *type;
208+
struct attribute_group *group;
209+
210+
for (i = 0; i < gvt->num_types; i++) {
211+
type = &gvt->types[i];
212+
213+
group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL);
214+
if (!group)
215+
goto unwind;
216+
217+
group->name = type->name;
218+
group->attrs = gvt_type_attrs;
219+
gvt_vgpu_type_groups[i] = group;
220+
}
221+
222+
return 0;
223+
224+
unwind:
225+
for (j = 0; j < i; j++) {
226+
group = gvt_vgpu_type_groups[j];
227+
kfree(group);
228+
}
229+
230+
return -ENOMEM;
231+
}
232+
233+
static void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt)
234+
{
235+
int i;
236+
struct attribute_group *group;
237+
238+
for (i = 0; i < gvt->num_types; i++) {
239+
group = gvt_vgpu_type_groups[i];
240+
gvt_vgpu_type_groups[i] = NULL;
241+
kfree(group);
242+
}
243+
}
244+
147245
static int kvmgt_guest_init(struct mdev_device *mdev);
148246
static void intel_vgpu_release_work(struct work_struct *work);
149247
static bool kvmgt_guest_exit(struct kvmgt_guest_info *info);
@@ -694,14 +792,13 @@ static int intel_vgpu_create(struct mdev_device *mdev)
694792
struct intel_vgpu *vgpu = NULL;
695793
struct intel_vgpu_type *type;
696794
struct device *pdev;
697-
void *gvt;
795+
struct intel_gvt *gvt;
698796
int ret;
699797

700798
pdev = mdev_parent_dev(mdev);
701799
gvt = kdev_to_i915(pdev)->gvt;
702800

703-
type = intel_gvt_ops->gvt_find_vgpu_type(gvt,
704-
mdev_get_type_group_id(mdev));
801+
type = &gvt->types[mdev_get_type_group_id(mdev)];
705802
if (!type) {
706803
ret = -EINVAL;
707804
goto out;
@@ -1667,19 +1764,26 @@ static struct mdev_parent_ops intel_vgpu_ops = {
16671764

16681765
static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
16691766
{
1670-
struct attribute_group **kvm_vgpu_type_groups;
1767+
int ret;
1768+
1769+
ret = intel_gvt_init_vgpu_type_groups((struct intel_gvt *)gvt);
1770+
if (ret)
1771+
return ret;
16711772

16721773
intel_gvt_ops = ops;
1673-
if (!intel_gvt_ops->get_gvt_attrs(&kvm_vgpu_type_groups))
1674-
return -EFAULT;
1675-
intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
1774+
intel_vgpu_ops.supported_type_groups = gvt_vgpu_type_groups;
16761775

1677-
return mdev_register_device(dev, &intel_vgpu_ops);
1776+
ret = mdev_register_device(dev, &intel_vgpu_ops);
1777+
if (ret)
1778+
intel_gvt_cleanup_vgpu_type_groups((struct intel_gvt *)gvt);
1779+
1780+
return ret;
16781781
}
16791782

1680-
static void kvmgt_host_exit(struct device *dev)
1783+
static void kvmgt_host_exit(struct device *dev, void *gvt)
16811784
{
16821785
mdev_unregister_device(dev);
1786+
intel_gvt_cleanup_vgpu_type_groups((struct intel_gvt *)gvt);
16831787
}
16841788

16851789
static int kvmgt_page_track_add(unsigned long handle, u64 gfn)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ static inline int intel_gvt_hypervisor_host_init(struct device *dev,
6363
/**
6464
* intel_gvt_hypervisor_host_exit - exit GVT-g host side
6565
*/
66-
static inline void intel_gvt_hypervisor_host_exit(struct device *dev)
66+
static inline void intel_gvt_hypervisor_host_exit(struct device *dev, void *gvt)
6767
{
6868
/* optional to provide */
6969
if (!intel_gvt_host.mpt->host_exit)
7070
return;
7171

72-
intel_gvt_host.mpt->host_exit(dev);
72+
intel_gvt_host.mpt->host_exit(dev, gvt);
7373
}
7474

7575
/**

0 commit comments

Comments
 (0)