From nobody Mon Apr 29 06:29:26 2024 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 1529480742405982.3315735592025; Wed, 20 Jun 2018 00:45:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 658C430820CD; Wed, 20 Jun 2018 07:45:40 +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 A63015D755; Wed, 20 Jun 2018 07:45:39 +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 464351800537; Wed, 20 Jun 2018 07:45:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5K7ja0m030685 for ; Wed, 20 Jun 2018 03:45:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 571F886EFA; Wed, 20 Jun 2018 07:45:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B853FB1A17; 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 EEF7C87622; 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:28 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.10]) by orsmga007.jf.intel.com with ESMTP; 20 Jun 2018 00:45:14 -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="50418467" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Wed, 20 Jun 2018 15:40:38 +0800 Message-Id: <20180620074039.10539-2-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.26]); Wed, 20 Jun 2018 07:45:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Jun 2018 07:45:30 +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.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: intel-gvt-dev@lists.freedesktop.org, kevin.tian@intel.com, kwankhede@nvidia.com Subject: [libvirt] [RFC PATCH 1/2] vfio/mdev: Add new instances parameters for mdev create 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 20 Jun 2018 07:45:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For special mdev type which can aggregate instances for mdev device, this extends mdev create interface by allowing extra "instances=3Dxxx" parameter, which is passed to mdev device model to be able to create arbitrary bundled number of instances for target mdev device. For created mdev device, also create new sysfs attr "instances" to show. For compatibility, current default instances is 1. Cc: Alex Williamson Cc: Kirti Wankhede Signed-off-by: Zhenyu Wang --- drivers/gpu/drm/i915/gvt/kvmgt.c | 3 ++- drivers/s390/cio/vfio_ccw_ops.c | 3 ++- drivers/vfio/mdev/mdev_core.c | 11 ++++++--- drivers/vfio/mdev/mdev_private.h | 6 ++++- drivers/vfio/mdev/mdev_sysfs.c | 42 +++++++++++++++++++++++++++----- include/linux/mdev.h | 3 ++- samples/vfio-mdev/mbochs.c | 3 ++- samples/vfio-mdev/mdpy.c | 3 ++- samples/vfio-mdev/mtty.c | 3 ++- 9 files changed, 60 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kv= mgt.c index df4e4a07db3d..4a543e23b9a0 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -444,7 +444,8 @@ 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(struct kobject *kobj, struct mdev_device *mde= v, + unsigned int instances) { struct intel_vgpu *vgpu =3D NULL; struct intel_vgpu_type *type; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_op= s.c index 41eeb57d68a3..4c37826ec9d0 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -106,7 +106,8 @@ static struct attribute_group *mdev_type_groups[] =3D { NULL, }; =20 -static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *= mdev) +static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *= mdev, + unsigned int instances) { struct vfio_ccw_private *private =3D dev_get_drvdata(mdev_parent_dev(mdev)); diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 0212f0ee8aea..98b0a78e6832 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -104,12 +104,13 @@ static inline void mdev_put_parent(struct mdev_parent= *parent) } =20 static int mdev_device_create_ops(struct kobject *kobj, - struct mdev_device *mdev) + struct mdev_device *mdev, + unsigned int instances) { struct mdev_parent *parent =3D mdev->parent; int ret; =20 - ret =3D parent->ops->create(kobj, mdev); + ret =3D parent->ops->create(kobj, mdev, instances); if (ret) return ret; =20 @@ -276,7 +277,8 @@ static void mdev_device_release(struct device *dev) kfree(mdev); } =20 -int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le u= uid) +int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le u= uid, + unsigned int instances) { int ret; struct mdev_device *mdev, *tmp; @@ -316,6 +318,7 @@ int mdev_device_create(struct kobject *kobj, struct dev= ice *dev, uuid_le uuid) mdev->dev.bus =3D &mdev_bus_type; mdev->dev.release =3D mdev_device_release; dev_set_name(&mdev->dev, "%pUl", uuid.b); + mdev->type_instances =3D instances; =20 ret =3D device_register(&mdev->dev); if (ret) { @@ -323,7 +326,7 @@ int mdev_device_create(struct kobject *kobj, struct dev= ice *dev, uuid_le uuid) goto mdev_fail; } =20 - ret =3D mdev_device_create_ops(kobj, mdev); + ret =3D mdev_device_create_ops(kobj, mdev, instances); if (ret) goto create_fail; =20 diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_priv= ate.h index b5819b7d7ef7..aa0b4b64c503 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -33,6 +33,7 @@ struct mdev_device { struct kref ref; struct list_head next; struct kobject *type_kobj; + unsigned int type_instances; bool active; }; =20 @@ -52,13 +53,16 @@ struct mdev_type { #define to_mdev_type(_kobj) \ container_of(_kobj, struct mdev_type, kobj) =20 +#define MDEV_CREATE_OPT_LEN 32 + int parent_create_sysfs_files(struct mdev_parent *parent); void parent_remove_sysfs_files(struct mdev_parent *parent); =20 int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type); void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type); =20 -int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le = uuid); +int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le = uuid, + unsigned int instances); int mdev_device_remove(struct device *dev, bool force_remove); =20 #endif /* MDEV_PRIVATE_H */ diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 249472f05509..5a417a20e774 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -54,11 +54,15 @@ static const struct sysfs_ops mdev_type_sysfs_ops =3D { static ssize_t create_store(struct kobject *kobj, struct device *dev, const char *buf, size_t count) { - char *str; + char *str, *opt =3D NULL; uuid_le uuid; int ret; + unsigned int instances =3D 1; =20 - if ((count < UUID_STRING_LEN) || (count > UUID_STRING_LEN + 1)) + if (count < UUID_STRING_LEN) + return -EINVAL; + + if (count > UUID_STRING_LEN + 1 + MDEV_CREATE_OPT_LEN) return -EINVAL; =20 str =3D kstrndup(buf, count, GFP_KERNEL); @@ -66,13 +70,31 @@ static ssize_t create_store(struct kobject *kobj, struc= t device *dev, return -ENOMEM; =20 ret =3D uuid_le_to_bin(str, &uuid); - kfree(str); - if (ret) + if (ret) { + kfree(str); return ret; + } =20 - ret =3D mdev_device_create(kobj, dev, uuid); - if (ret) + if (count > UUID_STRING_LEN + 1) { + opt =3D str + UUID_STRING_LEN; + if (*opt++ !=3D ',' || + strncmp(opt, "instances=3D", 10)) { + kfree(str); + return -EINVAL; + } + opt +=3D 10; + if (kstrtouint(opt, 10, &instances)) { + kfree(str); + return -EINVAL; + } + } + + ret =3D mdev_device_create(kobj, dev, uuid, instances); + if (ret) { + kfree(str); return ret; + } + kfree(str); =20 return count; } @@ -246,10 +268,18 @@ static ssize_t remove_store(struct device *dev, struc= t device_attribute *attr, return count; } =20 +static ssize_t instances_show(struct device *dev, struct device_attribute = *attr, char *buf) +{ + struct mdev_device *mdev =3D to_mdev_device(dev); + return sprintf(buf, "%u\n", mdev->type_instances); +} + static DEVICE_ATTR_WO(remove); +static DEVICE_ATTR_RO(instances); =20 static const struct attribute *mdev_device_attrs[] =3D { &dev_attr_remove.attr, + &dev_attr_instances.attr, NULL, }; =20 diff --git a/include/linux/mdev.h b/include/linux/mdev.h index b6e048e1045f..12d42aa30f81 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -70,7 +70,8 @@ struct mdev_parent_ops { const struct attribute_group **mdev_attr_groups; struct attribute_group **supported_type_groups; =20 - int (*create)(struct kobject *kobj, struct mdev_device *mdev); + int (*create)(struct kobject *kobj, struct mdev_device *mdev, + unsigned int instances); int (*remove)(struct mdev_device *mdev); int (*open)(struct mdev_device *mdev); void (*release)(struct mdev_device *mdev); diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 2960e26c6ea4..8b2a9e98c587 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -432,7 +432,8 @@ static int mbochs_reset(struct mdev_device *mdev) return 0; } =20 -static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev) +static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev, + unsigned int instances) { const struct mbochs_type *type =3D mbochs_find_type(kobj); struct device *dev =3D mdev_dev(mdev); diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 96e7969c473a..0ec48ea5225a 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -226,7 +226,8 @@ static int mdpy_reset(struct mdev_device *mdev) return 0; } =20 -static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) +static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev, + unsigned int instances) { const struct mdpy_type *type =3D mdpy_find_type(kobj); struct device *dev =3D mdev_dev(mdev); diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 7abb79d8313d..ff2eaffa1155 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -727,7 +727,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, ch= ar *buf, size_t count, return ret; } =20 -int mtty_create(struct kobject *kobj, struct mdev_device *mdev) +int mtty_create(struct kobject *kobj, struct mdev_device *mdev, + unsigned int instances) { struct mdev_state *mdev_state; char name[MTTY_STRING_LEN]; --=20 2.18.0.rc2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 06:29:26 2024 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