From nobody Thu Jul 3 23:03:16 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1529480758701765.5545658636684; Wed, 20 Jun 2018 00:45:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9DD873082A37; Wed, 20 Jun 2018 07:45:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1EA8F6016F; Wed, 20 Jun 2018 07:45:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C2AAA180053A; Wed, 20 Jun 2018 07:45:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5K7jaBj030692 for ; Wed, 20 Jun 2018 03:45:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id C734C308BDB0; Wed, 20 Jun 2018 07:45:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 31BCF308BDA2; Wed, 20 Jun 2018 07:45:31 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BF614E90E; Wed, 20 Jun 2018 07:45:29 +0000 (UTC) Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jun 2018 00:45:27 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.10]) by orsmga007.jf.intel.com with ESMTP; 20 Jun 2018 00:45:16 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,246,1526367600"; d="scan'208";a="50418469" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Wed, 20 Jun 2018 15:40:39 +0800 Message-Id: <20180620074039.10539-3-zhenyuw@linux.intel.com> In-Reply-To: <20180620074039.10539-1-zhenyuw@linux.intel.com> References: <20180620074039.10539-1-zhenyuw@linux.intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 20 Jun 2018 07:45:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 20 Jun 2018 07:45:29 +0000 (UTC) for IP:'134.134.136.126' DOMAIN:'mga18.intel.com' HELO:'mga18.intel.com' FROM:'zhenyuw@linux.intel.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED) 134.134.136.126 mga18.intel.com 134.134.136.126 mga18.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Cc: intel-gvt-dev@lists.freedesktop.org, kevin.tian@intel.com, kwankhede@nvidia.com Subject: [libvirt] [RFC PATCH 2/2] drm/i915/gvt: Add new aggregation type X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 20 Jun 2018 07:45:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" New aggregation type is created for KVMGT which can be used with new mdev create "instances=3Dxxx" 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 Cc: Kirti Wankhede Signed-off-by: Zhenyu Wang --- 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(s= truct intel_gvt *gvt, for (i =3D 0; i < gvt->num_types; i++) { t =3D &gvt->types[i]; if (!strncmp(t->name, name + strlen(driver_name) + 1, - sizeof(t->name))) + strlen(t->name))) return t; } =20 @@ -105,9 +105,16 @@ static ssize_t description_show(struct kobject *kobj, = struct device *dev, type->weight); } =20 +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); =20 static struct attribute *gvt_type_attrs[] =3D { &mdev_type_attr_available_instances.attr, @@ -116,14 +123,20 @@ static struct attribute *gvt_type_attrs[] =3D { NULL, }; =20 +static struct attribute *gvt_type_aggregate_attrs[] =3D { + &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[] =3D { [0 ... NR_MAX_INTEL_VGPU_TYPES - 1] =3D NULL, }; =20 -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 =3D gvt_type_attrs; *intel_vgpu_type_groups =3D gvt_vgpu_type_groups; return true; } @@ -142,7 +155,10 @@ static bool intel_gvt_init_vgpu_type_groups(struct int= el_gvt *gvt) goto unwind; =20 group->name =3D type->name; - group->attrs =3D gvt_type_attrs; + if (type->aggregation) + group->attrs =3D gvt_type_aggregate_attrs; + else + group->attrs =3D gvt_type_attrs; gvt_vgpu_type_groups[i] =3D group; } =20 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; }; =20 struct intel_gvt_fence { @@ -290,13 +293,14 @@ struct intel_gvt_firmware { =20 #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 capabil= ity */ }; =20 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/kv= mgt.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, stru= ct mdev_device *mdev, goto out; } =20 - vgpu =3D intel_gvt_ops->vgpu_create(gvt, type); + vgpu =3D intel_gvt_ops->vgpu_create(gvt, type, instances); if (IS_ERR_OR_NULL(vgpu)) { ret =3D vgpu =3D=3D 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 =3D { =20 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; =20 intel_gvt_ops =3D 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 =3D kvm_vgpu_type_groups; =20 diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgp= u.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 =3D gvt_hidden_sz(gvt) - HOST_HIGH_GM_SIZE; num_types =3D sizeof(vgpu_types) / sizeof(vgpu_types[0]); =20 - gvt->types =3D kzalloc(num_types * sizeof(struct intel_vgpu_type), + gvt->types =3D kzalloc((num_types + 1) * sizeof(struct intel_vgpu_type), GFP_KERNEL); if (!gvt->types) return -ENOMEM; =20 + gvt->gm.low_avail =3D low_avail; + gvt->gm.high_avail =3D high_avail; + gvt->gm.fence_avail =3D 32 - HOST_FENCE; min_low =3D MB_TO_BYTES(32); for (i =3D 0; i < num_types; ++i) { if (low_avail / vgpu_types[i].low_mm =3D=3D 0) @@ -148,11 +151,11 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt) high_avail / vgpu_types[i].high_mm); =20 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); =20 gvt_dbg_core("type[%d]: %s avail %u low %u high %u fence %u weight %u re= s %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)); } =20 - gvt->num_types =3D i; + /* add aggregation type */ + gvt->types[i].low_gm_size =3D MB_TO_BYTES(32); + gvt->types[i].high_gm_size =3D MB_TO_BYTES(192); + gvt->types[i].fence =3D 2; + gvt->types[i].weight =3D 16; + gvt->types[i].resolution =3D GVT_EDID_1024_768; + gvt->types[i].avail_instance =3D min(low_avail / gvt->types[i].low_gm_siz= e, + high_avail / gvt->types[i].high_gm_size); + gvt->types[i].avail_instance =3D 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 =3D true; + gvt->num_types =3D ++i; + return 0; } =20 @@ -443,7 +471,8 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struc= t 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 =3D BYTES_TO_MB(param.low_gm_sz); param.high_gm_sz =3D BYTES_TO_MB(param.high_gm_sz); =20 + if (type->aggregation && instances > 1) { + if (instances > type->avail_instance) + return ERR_PTR(-EINVAL); + param.low_gm_sz =3D min(param.low_gm_sz * instances, + (u64)BYTES_TO_MB(gvt->gm.low_avail)); + param.high_gm_sz =3D min(param.high_gm_sz * instances, + (u64)BYTES_TO_MB(gvt->gm.high_avail)); + param.fence_sz =3D 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 =3D __intel_gvt_create_vgpu(gvt, ¶m); if (!IS_ERR(vgpu)) --=20 2.18.0.rc2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list