New aggregation type is created for KVMGT which can be used with
new mdev create "instances=xxx" parameter to combine minimal resource
number for target instances, which can create user defined number
of resources.
User space checks whether there's "aggregation" attribute for mdev
type and "instances" parameter can't be larger than
"avail_instances".
Cc: Alex Williamson <alex.williamson(a)redhat.com>
Cc: Kirti Wankhede <kwankhede(a)nvidia.com>
Signed-off-by: Zhenyu Wang <zhenyuw(a)linux.intel.com>
---
drivers/gpu/drm/i915/gvt/gvt.c | 26 ++++++++++++---
drivers/gpu/drm/i915/gvt/gvt.h | 14 +++++---
drivers/gpu/drm/i915/gvt/kvmgt.c | 6 ++--
drivers/gpu/drm/i915/gvt/vgpu.c | 56 ++++++++++++++++++++++++++++----
4 files changed, 81 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
index 4e65266e7b95..ae90bd368b3f 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.c
+++ b/drivers/gpu/drm/i915/gvt/gvt.c
@@ -57,7 +57,7 @@ static struct intel_vgpu_type *intel_gvt_find_vgpu_type(struct intel_gvt
*gvt,
for (i = 0; i < gvt->num_types; i++) {
t = &gvt->types[i];
if (!strncmp(t->name, name + strlen(driver_name) + 1,
- sizeof(t->name)))
+ strlen(t->name)))
return t;
}
@@ -105,9 +105,16 @@ static ssize_t description_show(struct kobject *kobj, struct device
*dev,
type->weight);
}
+static ssize_t aggregation_show(struct kobject *kobj, struct device *dev,
+ char *buf)
+{
+ return sprintf(buf, "%s\n", "true");
+}
+
static MDEV_TYPE_ATTR_RO(available_instances);
static MDEV_TYPE_ATTR_RO(device_api);
static MDEV_TYPE_ATTR_RO(description);
+static MDEV_TYPE_ATTR_RO(aggregation);
static struct attribute *gvt_type_attrs[] = {
&mdev_type_attr_available_instances.attr,
@@ -116,14 +123,20 @@ static struct attribute *gvt_type_attrs[] = {
NULL,
};
+static struct attribute *gvt_type_aggregate_attrs[] = {
+ &mdev_type_attr_available_instances.attr,
+ &mdev_type_attr_device_api.attr,
+ &mdev_type_attr_description.attr,
+ &mdev_type_attr_aggregation.attr,
+ NULL,
+};
+
static struct attribute_group *gvt_vgpu_type_groups[] = {
[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL,
};
-static bool intel_get_gvt_attrs(struct attribute ***type_attrs,
- struct attribute_group ***intel_vgpu_type_groups)
+static bool intel_get_gvt_attrs(struct attribute_group ***intel_vgpu_type_groups)
{
- *type_attrs = gvt_type_attrs;
*intel_vgpu_type_groups = gvt_vgpu_type_groups;
return true;
}
@@ -142,7 +155,10 @@ static bool intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
goto unwind;
group->name = type->name;
- group->attrs = gvt_type_attrs;
+ if (type->aggregation)
+ group->attrs = gvt_type_aggregate_attrs;
+ else
+ group->attrs = gvt_type_attrs;
gvt_vgpu_type_groups[i] = group;
}
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index de2a3a2580be..c0320b95804c 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -241,6 +241,9 @@ struct intel_vgpu {
struct intel_gvt_gm {
unsigned long vgpu_allocated_low_gm_size;
unsigned long vgpu_allocated_high_gm_size;
+ unsigned long low_avail;
+ unsigned long high_avail;
+ unsigned long fence_avail;
};
struct intel_gvt_fence {
@@ -290,13 +293,14 @@ struct intel_gvt_firmware {
#define NR_MAX_INTEL_VGPU_TYPES 20
struct intel_vgpu_type {
- char name[16];
+ char name[32];
unsigned int avail_instance;
unsigned int low_gm_size;
unsigned int high_gm_size;
unsigned int fence;
unsigned int weight;
enum intel_vgpu_edid resolution;
+ bool aggregation; /* fine-grained resource type with aggregation capability */
};
struct intel_gvt {
@@ -482,7 +486,8 @@ void intel_gvt_clean_vgpu_types(struct intel_gvt *gvt);
struct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt);
void intel_gvt_destroy_idle_vgpu(struct intel_vgpu *vgpu);
struct intel_vgpu *intel_gvt_create_vgpu(struct intel_gvt *gvt,
- struct intel_vgpu_type *type);
+ struct intel_vgpu_type *type,
+ unsigned int);
void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu);
void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr,
unsigned int engine_mask);
@@ -560,15 +565,14 @@ struct intel_gvt_ops {
int (*emulate_mmio_write)(struct intel_vgpu *, u64, void *,
unsigned int);
struct intel_vgpu *(*vgpu_create)(struct intel_gvt *,
- struct intel_vgpu_type *);
+ struct intel_vgpu_type *, unsigned int);
void (*vgpu_destroy)(struct intel_vgpu *);
void (*vgpu_reset)(struct intel_vgpu *);
void (*vgpu_activate)(struct intel_vgpu *);
void (*vgpu_deactivate)(struct intel_vgpu *);
struct intel_vgpu_type *(*gvt_find_vgpu_type)(struct intel_gvt *gvt,
const char *name);
- bool (*get_gvt_attrs)(struct attribute ***type_attrs,
- struct attribute_group ***intel_vgpu_type_groups);
+ bool (*get_gvt_attrs)(struct attribute_group ***intel_vgpu_type_groups);
int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *);
int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int);
int (*write_protect_handler)(struct intel_vgpu *, u64, void *,
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 4a543e23b9a0..f02c3a17714f 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -464,7 +464,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device
*mdev,
goto out;
}
- vgpu = intel_gvt_ops->vgpu_create(gvt, type);
+ vgpu = intel_gvt_ops->vgpu_create(gvt, type, instances);
if (IS_ERR_OR_NULL(vgpu)) {
ret = vgpu == NULL ? -EFAULT : PTR_ERR(vgpu);
gvt_err("failed to create intel vgpu: %d\n", ret);
@@ -1389,12 +1389,10 @@ static struct mdev_parent_ops intel_vgpu_ops = {
static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
{
- struct attribute **kvm_type_attrs;
struct attribute_group **kvm_vgpu_type_groups;
intel_gvt_ops = ops;
- if (!intel_gvt_ops->get_gvt_attrs(&kvm_type_attrs,
- &kvm_vgpu_type_groups))
+ if (!intel_gvt_ops->get_gvt_attrs(&kvm_vgpu_type_groups))
return -EFAULT;
intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
index 889d10f8ee96..e4a5540401be 100644
--- a/drivers/gpu/drm/i915/gvt/vgpu.c
+++ b/drivers/gpu/drm/i915/gvt/vgpu.c
@@ -124,11 +124,14 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt)
high_avail = gvt_hidden_sz(gvt) - HOST_HIGH_GM_SIZE;
num_types = sizeof(vgpu_types) / sizeof(vgpu_types[0]);
- gvt->types = kzalloc(num_types * sizeof(struct intel_vgpu_type),
+ gvt->types = kzalloc((num_types + 1) * sizeof(struct intel_vgpu_type),
GFP_KERNEL);
if (!gvt->types)
return -ENOMEM;
+ gvt->gm.low_avail = low_avail;
+ gvt->gm.high_avail = high_avail;
+ gvt->gm.fence_avail = 32 - HOST_FENCE;
min_low = MB_TO_BYTES(32);
for (i = 0; i < num_types; ++i) {
if (low_avail / vgpu_types[i].low_mm == 0)
@@ -148,11 +151,11 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt)
high_avail / vgpu_types[i].high_mm);
if (IS_GEN8(gvt->dev_priv))
- sprintf(gvt->types[i].name, "GVTg_V4_%s",
- vgpu_types[i].name);
+ snprintf(gvt->types[i].name, sizeof(gvt->types[i].name),
+ "GVTg_V4_%s", vgpu_types[i].name);
else if (IS_GEN9(gvt->dev_priv))
- sprintf(gvt->types[i].name, "GVTg_V5_%s",
- vgpu_types[i].name);
+ snprintf(gvt->types[i].name, sizeof(gvt->types[i].name),
+ "GVTg_V5_%s", vgpu_types[i].name);
gvt_dbg_core("type[%d]: %s avail %u low %u high %u fence %u weight %u res
%s\n",
i, gvt->types[i].name,
@@ -163,7 +166,32 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt)
vgpu_edid_str(gvt->types[i].resolution));
}
- gvt->num_types = i;
+ /* add aggregation type */
+ gvt->types[i].low_gm_size = MB_TO_BYTES(32);
+ gvt->types[i].high_gm_size = MB_TO_BYTES(192);
+ gvt->types[i].fence = 2;
+ gvt->types[i].weight = 16;
+ gvt->types[i].resolution = GVT_EDID_1024_768;
+ gvt->types[i].avail_instance = min(low_avail / gvt->types[i].low_gm_size,
+ high_avail / gvt->types[i].high_gm_size);
+ gvt->types[i].avail_instance = min(gvt->types[i].avail_instance,
+ (32 - HOST_FENCE) / gvt->types[i].fence);
+ if (IS_GEN8(gvt->dev_priv))
+ strcat(gvt->types[i].name, "GVTg_V4_aggregate");
+ else if (IS_GEN9(gvt->dev_priv))
+ strcat(gvt->types[i].name, "GVTg_V5_aggregate");
+
+ gvt_dbg_core("type[%d]: %s avail %u low %u high %u fence %u weight %u res
%s\n",
+ i, gvt->types[i].name,
+ gvt->types[i].avail_instance,
+ gvt->types[i].low_gm_size,
+ gvt->types[i].high_gm_size, gvt->types[i].fence,
+ gvt->types[i].weight,
+ vgpu_edid_str(gvt->types[i].resolution));
+
+ gvt->types[i].aggregation = true;
+ gvt->num_types = ++i;
+
return 0;
}
@@ -443,7 +471,8 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt
*gvt,
* pointer to intel_vgpu, error pointer if failed.
*/
struct intel_vgpu *intel_gvt_create_vgpu(struct intel_gvt *gvt,
- struct intel_vgpu_type *type)
+ struct intel_vgpu_type *type,
+ unsigned int instances)
{
struct intel_vgpu_creation_params param;
struct intel_vgpu *vgpu;
@@ -460,6 +489,19 @@ struct intel_vgpu *intel_gvt_create_vgpu(struct intel_gvt *gvt,
param.low_gm_sz = BYTES_TO_MB(param.low_gm_sz);
param.high_gm_sz = BYTES_TO_MB(param.high_gm_sz);
+ if (type->aggregation && instances > 1) {
+ if (instances > type->avail_instance)
+ return ERR_PTR(-EINVAL);
+ param.low_gm_sz = min(param.low_gm_sz * instances,
+ (u64)BYTES_TO_MB(gvt->gm.low_avail));
+ param.high_gm_sz = min(param.high_gm_sz * instances,
+ (u64)BYTES_TO_MB(gvt->gm.high_avail));
+ param.fence_sz = min(param.fence_sz * instances,
+ (u64)gvt->gm.fence_avail);
+ gvt_dbg_core("instances %d, low %lluMB, high %lluMB, fence %llu\n",
+ instances, param.low_gm_sz, param.high_gm_sz, param.fence_sz);
+ }
+
mutex_lock(&gvt->lock);
vgpu = __intel_gvt_create_vgpu(gvt, ¶m);
if (!IS_ERR(vgpu))
--
2.18.0.rc2