From nobody Sat Feb 7 05:01:39 2026 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 1539767391075851.8608175349934; Wed, 17 Oct 2018 02:09:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B673D80F79; Wed, 17 Oct 2018 09:09:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7694143FFE; Wed, 17 Oct 2018 09:09:48 +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 1E3EF4BB79; Wed, 17 Oct 2018 09:09:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9H96YkN016798 for ; Wed, 17 Oct 2018 05:06:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id DA09280307; Wed, 17 Oct 2018 09:06:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 87E238030E; Wed, 17 Oct 2018 09:06:30 +0000 (UTC) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (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 8776431524D3; Wed, 17 Oct 2018 09:06:28 +0000 (UTC) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Oct 2018 02:06:28 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.20]) by fmsmga007.fm.intel.com with ESMTP; 17 Oct 2018 02:06:26 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,391,1534834800"; d="scan'208";a="78678830" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Wed, 17 Oct 2018 17:00:08 +0800 Message-Id: <20181017090008.16282-7-zhenyuw@linux.intel.com> In-Reply-To: <20180720021928.15343-1-zhenyuw@linux.intel.com> References: <20180720021928.15343-1-zhenyuw@linux.intel.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 17 Oct 2018 09:06:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 17 Oct 2018 09:06:28 +0000 (UTC) for IP:'192.55.52.136' DOMAIN:'mga12.intel.com' HELO:'mga12.intel.com' FROM:'zhenyuw@linux.intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_HELO_PASS) 192.55.52.136 mga12.intel.com 192.55.52.136 mga12.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Kevin Tian , Kirti Wankhede , Cornelia Huck , intel-gvt-dev@lists.freedesktop.org Subject: [libvirt] [PATCH v3 6/6] drm/i915/gvt: Add new type with aggregation support 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 17 Oct 2018 09:09:49 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" New aggregation type is created for KVMGT which can be used to combine minimal resource number for target instances, to create user defined number of resources. For KVMGT, aggregated resource is determined by memory and fence resource allocation for target number of instances. v2: - apply for new hooks Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Cc: Cornelia Huck Signed-off-by: Zhenyu Wang --- drivers/gpu/drm/i915/gvt/gvt.h | 11 +++++-- drivers/gpu/drm/i915/gvt/kvmgt.c | 53 ++++++++++++++++++++++++++++-- drivers/gpu/drm/i915/gvt/vgpu.c | 56 ++++++++++++++++++++++++++++++-- 3 files changed, 112 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h index 31f6cdbe5c42..cb318079fa74 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 { @@ -292,13 +295,15 @@ struct intel_gvt_firmware { =20 #define NR_MAX_INTEL_VGPU_TYPES 20 struct intel_vgpu_type { - char name[16]; + const char *drv_name; + 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; + unsigned int aggregation; }; =20 struct intel_gvt { @@ -484,7 +489,7 @@ 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_release_vgpu(struct intel_vgpu *vgpu); void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr, @@ -563,7 +568,7 @@ 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 *vgpu); void (*vgpu_release)(struct intel_vgpu *vgpu); void (*vgpu_reset)(struct intel_vgpu *); diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kv= mgt.c index c1072143da1d..841ad5437c4a 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -501,7 +501,9 @@ static void kvmgt_put_vfio_device(void *vgpu) vfio_device_put(((struct intel_vgpu *)vgpu)->vdev.vfio_device); } =20 -static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mde= v) +static int intel_vgpu_create_internal(struct kobject *kobj, + struct mdev_device *mdev, + unsigned int instances) { struct intel_vgpu *vgpu =3D NULL; struct intel_vgpu_type *type; @@ -520,7 +522,14 @@ static int intel_vgpu_create(struct kobject *kobj, str= uct mdev_device *mdev) goto out; } =20 - vgpu =3D intel_gvt_ops->vgpu_create(gvt, type); + if (instances > type->aggregation) { + gvt_vgpu_err("wrong aggregation specified for type %s\n", + kobject_name(kobj)); + ret =3D -EINVAL; + goto out; + } + + 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); @@ -540,6 +549,44 @@ static int intel_vgpu_create(struct kobject *kobj, str= uct mdev_device *mdev) return ret; } =20 +static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mde= v) +{ + return intel_vgpu_create_internal(kobj, mdev, 1); +} + +static int intel_vgpu_create_with_instances(struct kobject *kobj, + struct mdev_device *mdev, + unsigned int instances) +{ + return intel_vgpu_create_internal(kobj, mdev, instances); +} + +static int intel_vgpu_max_aggregated_instances(struct kobject *kobj, + struct device *dev, + unsigned int *max) +{ + struct intel_vgpu_type *type; + struct intel_gvt *gvt; + int ret =3D 0; + + gvt =3D kdev_to_i915(dev)->gvt; + + type =3D intel_gvt_ops->gvt_find_vgpu_type(gvt, kobject_name(kobj)); + if (!type) { + gvt_err("failed to find type %s to create\n", + kobject_name(kobj)); + ret =3D -EINVAL; + goto out; + } + + if (type->aggregation <=3D 1) + *max =3D 1; + else + *max =3D type->aggregation; +out: + return ret; +} + static int intel_vgpu_remove(struct mdev_device *mdev) { struct intel_vgpu *vgpu =3D mdev_get_drvdata(mdev); @@ -1442,6 +1489,8 @@ static const struct attribute_group *intel_vgpu_group= s[] =3D { static struct mdev_parent_ops intel_vgpu_ops =3D { .mdev_attr_groups =3D intel_vgpu_groups, .create =3D intel_vgpu_create, + .create_with_instances =3D intel_vgpu_create_with_instances, + .max_aggregated_instances =3D intel_vgpu_max_aggregated_instances, .remove =3D intel_vgpu_remove, =20 .open =3D intel_vgpu_open, diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgp= u.c index c628be05fbfe..d36f017c740b 100644 --- a/drivers/gpu/drm/i915/gvt/vgpu.c +++ b/drivers/gpu/drm/i915/gvt/vgpu.c @@ -108,6 +108,7 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt) unsigned int num_types; unsigned int i, low_avail, high_avail; unsigned int min_low; + const char *driver_name =3D dev_driver_string(&gvt->dev_priv->drm.pdev->d= ev); =20 /* vGPU type name is defined as GVTg_Vx_y which contains * physical GPU generation type (e.g V4 as BDW server, V5 as @@ -125,11 +126,15 @@ 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 kcalloc(num_types, sizeof(struct intel_vgpu_type), + gvt->types =3D kcalloc(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) @@ -147,6 +152,7 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt) gvt->types[i].resolution =3D vgpu_types[i].edid; gvt->types[i].avail_instance =3D min(low_avail / vgpu_types[i].low_mm, high_avail / vgpu_types[i].high_mm); + gvt->types[i].aggregation =3D 1; =20 if (IS_GEN8(gvt->dev_priv)) sprintf(gvt->types[i].name, "GVTg_V4_%s", @@ -154,6 +160,7 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt) else if (IS_GEN9(gvt->dev_priv)) sprintf(gvt->types[i].name, "GVTg_V5_%s", vgpu_types[i].name); + gvt->types[i].drv_name =3D driver_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, @@ -164,7 +171,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->types[i].drv_name =3D driver_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, + 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 gvt->types[i].avail_instance; + gvt->num_types =3D ++i; return 0; } =20 @@ -195,6 +227,8 @@ static void intel_gvt_update_vgpu_types(struct intel_gv= t *gvt) fence_min =3D fence_avail / gvt->types[i].fence; gvt->types[i].avail_instance =3D min(min(low_gm_min, high_gm_min), fence_min); + if (gvt->types[i].aggregation > 1) + gvt->types[i].aggregation =3D gvt->types[i].avail_instance; =20 gvt_dbg_core("update type[%d]: %s avail %u low %u high %u fence %u\n", i, gvt->types[i].name, @@ -464,7 +498,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; @@ -481,6 +516,21 @@ 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 (instances > 1 && instances <=3D type->aggregation) { + 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); + type->aggregation -=3D instances; + gvt_dbg_core("instances %d, low %lluMB, high %lluMB, fence %llu, left %u= \n", + instances, param.low_gm_sz, param.high_gm_sz, param.fence_sz, + type->aggregation); + } + mutex_lock(&gvt->lock); vgpu =3D __intel_gvt_create_vgpu(gvt, ¶m); if (!IS_ERR(vgpu)) --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list