From nobody Wed May 1 05:29:32 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 153205349226438.98907968517949; Thu, 19 Jul 2018 19:24:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 389508762E; Fri, 20 Jul 2018 02:24:50 +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 856B75D9CA; Fri, 20 Jul 2018 02:24:49 +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 928D04A460; Fri, 20 Jul 2018 02:24:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6K2OkNB029764 for ; Thu, 19 Jul 2018 22:24:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6408660172; Fri, 20 Jul 2018 02:24:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4142E600C2; Fri, 20 Jul 2018 02:24:39 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 911D5C049E32; Fri, 20 Jul 2018 02:24:38 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2018 19:24:36 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.113]) by fmsmga002.fm.intel.com with ESMTP; 19 Jul 2018 19:24:30 -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,377,1526367600"; d="scan'208";a="68588735" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Fri, 20 Jul 2018 10:19:25 +0800 Message-Id: <20180720021928.15343-2-zhenyuw@linux.intel.com> In-Reply-To: <20180720021928.15343-1-zhenyuw@linux.intel.com> References: <20180620074039.10539-1-zhenyuw@linux.intel.com> <20180720021928.15343-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.31]); Fri, 20 Jul 2018 02:24:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 20 Jul 2018 02:24:39 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'zhenyuw@linux.intel.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: kevin.tian@intel.com, intel-gvt-dev@lists.freedesktop.org, kwankhede@nvidia.com Subject: [libvirt] [PATCH v2 1/4] vfio/mdev: Add new instances parameter 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 20 Jul 2018 02:24:50 +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. v2: create new create_with_instances operator for vendor driver Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Signed-off-by: Zhenyu Wang --- drivers/vfio/mdev/mdev_core.c | 18 +++++++++++++---- drivers/vfio/mdev/mdev_private.h | 5 ++++- drivers/vfio/mdev/mdev_sysfs.c | 34 ++++++++++++++++++++++++++------ include/linux/mdev.h | 10 ++++++++++ 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 0212f0ee8aea..e69db302a4f2 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -104,12 +104,16 @@ 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); + if (instances > 1) + ret =3D parent->ops->create_with_instances(kobj, mdev, instances); + else + ret =3D parent->ops->create(kobj, mdev); if (ret) return ret; =20 @@ -276,7 +280,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; @@ -287,6 +292,11 @@ int mdev_device_create(struct kobject *kobj, struct de= vice *dev, uuid_le uuid) if (!parent) return -EINVAL; =20 + if (instances > 1 && !parent->ops->create_with_instances) { + ret =3D -EINVAL; + goto mdev_fail; + } + mutex_lock(&mdev_list_lock); =20 /* Check for duplicate */ @@ -323,7 +333,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..c9d3fe04e273 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -52,13 +52,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..a06e5b7c69d3 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; } diff --git a/include/linux/mdev.h b/include/linux/mdev.h index b6e048e1045f..cfb702600f95 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -30,6 +30,13 @@ struct mdev_device; * @kobj: kobject of type for which 'create' is called. * @mdev: mdev_device structure on of mediated device * that is being created + * @create_with_instances: Allocate aggregated instances' resources in par= ent device's + * driver for a particular mediated device. It is optional + * if doesn't support aggregated resources. + * @kobj: kobject of type for which 'create' is called. + * @mdev: mdev_device structure on of mediated device + * that is being created + * @instances: number of instances to aggregate * Returns integer: success (0) or error (< 0) * @remove: Called to free resources in parent device's driver for a * a mediated device. It is mandatory to provide 'remove' @@ -71,6 +78,9 @@ struct mdev_parent_ops { struct attribute_group **supported_type_groups; =20 int (*create)(struct kobject *kobj, struct mdev_device *mdev); + int (*create_with_instances)(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); --=20 2.18.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 05:29:32 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 1539767381235465.4636872775378; Wed, 17 Oct 2018 02:09:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1151989E3; Wed, 17 Oct 2018 09:09:39 +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 B7C875C241; Wed, 17 Oct 2018 09:09:38 +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 5AC621808841; Wed, 17 Oct 2018 09:09:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9H96UT4016777 for ; Wed, 17 Oct 2018 05:06:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3DF0E5457E; Wed, 17 Oct 2018 09:06:30 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A1F05F7C9; Wed, 17 Oct 2018 09:06:22 +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 6C1473082144; Wed, 17 Oct 2018 09:06:20 +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:20 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.20]) by fmsmga007.fm.intel.com with ESMTP; 17 Oct 2018 02:06:18 -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="78678778" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Wed, 17 Oct 2018 17:00:03 +0800 Message-Id: <20181017090008.16282-2-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.42]); Wed, 17 Oct 2018 09:06:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 17 Oct 2018 09:06:20 +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.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Kevin Tian , Kirti Wankhede , Cornelia Huck , intel-gvt-dev@lists.freedesktop.org Subject: [libvirt] [PATCH v3 1/6] vfio/mdev: Add new "aggregate" parameter 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: , 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 17 Oct 2018 09:09:39 +0000 (UTC) X-ZohoMail: RDMRC_1 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 "aggregate=3Dxxx" parameter, which is passed to mdev device model to be able to create bundled number of instances for target mdev device. v2: create new create_with_instances operator for vendor driver v3: - Change parameter name as "aggregate=3D" - Fix new interface comments. - Parameter checking for new option, pass UUID string only to parse and properly end parameter for kstrtouint() conversion. Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Cc: Cornelia Huck Signed-off-by: Zhenyu Wang --- drivers/vfio/mdev/mdev_core.c | 21 +++++++++++++++++---- drivers/vfio/mdev/mdev_private.h | 4 +++- drivers/vfio/mdev/mdev_sysfs.c | 32 ++++++++++++++++++++++++++++---- include/linux/mdev.h | 11 +++++++++++ 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 0212f0ee8aea..545c52ec7618 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -104,12 +104,17 @@ 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); + if (instances > 1) { + ret =3D parent->ops->create_with_instances(kobj, mdev, + instances); + } else + ret =3D parent->ops->create(kobj, mdev); if (ret) return ret; =20 @@ -276,7 +281,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; @@ -287,6 +293,12 @@ int mdev_device_create(struct kobject *kobj, struct de= vice *dev, uuid_le uuid) if (!parent) return -EINVAL; =20 + if (instances > 1 && + !parent->ops->create_with_instances) { + ret =3D -EINVAL; + goto mdev_fail; + } + mutex_lock(&mdev_list_lock); =20 /* Check for duplicate */ @@ -316,6 +328,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 +336,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..e90d295d3927 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 @@ -58,7 +59,8 @@ void parent_remove_sysfs_files(struct mdev_parent *parent= ); 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..aefed0c8891b 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -54,14 +54,21 @@ 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, *param, *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; =20 - str =3D kstrndup(buf, count, GFP_KERNEL); + if ((param =3D strnchr(buf, count, ',')) =3D=3D NULL) { + if (count > UUID_STRING_LEN + 1) + return -EINVAL; + } else if (param - buf !=3D UUID_STRING_LEN) + return -EINVAL; + + str =3D kstrndup(buf, UUID_STRING_LEN, GFP_KERNEL); if (!str) return -ENOMEM; =20 @@ -70,7 +77,24 @@ static ssize_t create_store(struct kobject *kobj, struct= device *dev, if (ret) return ret; =20 - ret =3D mdev_device_create(kobj, dev, uuid); + if (param) { + opt =3D kstrndup(param + 1, count - UUID_STRING_LEN - 1, + GFP_KERNEL); + if (!opt) + return -ENOMEM; + if (strncmp(opt, "aggregate=3D", 10)) { + kfree(opt); + return -EINVAL; + } + opt +=3D 10; + if (kstrtouint(opt, 10, &instances)) { + kfree(opt); + return -EINVAL; + } + kfree(opt); + } + + ret =3D mdev_device_create(kobj, dev, uuid, instances); if (ret) return ret; =20 diff --git a/include/linux/mdev.h b/include/linux/mdev.h index b6e048e1045f..c12c0bfc5598 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -31,6 +31,14 @@ struct mdev_device; * @mdev: mdev_device structure on of mediated device * that is being created * Returns integer: success (0) or error (< 0) + * @create_with_instances: Allocate aggregated instances' resources in par= ent device's + * driver for a particular mediated device. Optional if aggregated + * resources are not supported. + * @kobj: kobject of type for which 'create' is called. + * @mdev: mdev_device structure on of mediated device + * that is being created + * @instances: number of instances to aggregate + * Returns integer: success (0) or error (< 0) * @remove: Called to free resources in parent device's driver for a * a mediated device. It is mandatory to provide 'remove' * ops. @@ -71,6 +79,9 @@ struct mdev_parent_ops { struct attribute_group **supported_type_groups; =20 int (*create)(struct kobject *kobj, struct mdev_device *mdev); + int (*create_with_instances)(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); --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 05:29:32 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 1539767420468655.0010550619093; Wed, 17 Oct 2018 02:10:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2FE0D30A5680; Wed, 17 Oct 2018 09:10:18 +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 E51EA1057047; Wed, 17 Oct 2018 09:10:17 +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 6CA45180B5B7; Wed, 17 Oct 2018 09:10:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9H972m4016862 for ; Wed, 17 Oct 2018 05:07:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 93D661057078; Wed, 17 Oct 2018 09:07:02 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71E471057076; Wed, 17 Oct 2018 09:06:23 +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 CC7E3C058CB9; Wed, 17 Oct 2018 09:06:21 +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:21 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.20]) by fmsmga007.fm.intel.com with ESMTP; 17 Oct 2018 02:06:20 -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="78678786" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Wed, 17 Oct 2018 17:00:04 +0800 Message-Id: <20181017090008.16282-3-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.32]); Wed, 17 Oct 2018 09:06:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 17 Oct 2018 09:06:22 +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.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Tian , Kirti Wankhede , Cornelia Huck , intel-gvt-dev@lists.freedesktop.org Subject: [libvirt] [PATCH v3 2/6] vfio/mdev: Add "aggregation" attribute for supported mdev 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: , 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 17 Oct 2018 09:10:19 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For supported mdev driver to create aggregated device, this creates new "aggregation" attribute for target type, which will show maximum number of instance resources that can be aggregated. Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Cc: Cornelia Huck Signed-off-by: Zhenyu Wang --- drivers/vfio/mdev/mdev_core.c | 19 +++++++++++++++++++ drivers/vfio/mdev/mdev_private.h | 2 ++ drivers/vfio/mdev/mdev_sysfs.c | 22 ++++++++++++++++++++++ include/linux/mdev.h | 8 ++++++++ 4 files changed, 51 insertions(+) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 545c52ec7618..8f8bbb72e5d9 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -161,6 +161,25 @@ static int mdev_device_remove_cb(struct device *dev, v= oid *data) return mdev_device_remove(dev, data ? *(bool *)data : true); } =20 +int mdev_max_aggregated_instances(struct kobject *kobj, struct device *dev, + unsigned int *m) +{ + struct mdev_parent *parent; + struct mdev_type *type =3D to_mdev_type(kobj); + int ret; + + parent =3D mdev_get_parent(type->parent); + if (!parent) + return -EINVAL; + + if (parent->ops->max_aggregated_instances) { + ret =3D parent->ops->max_aggregated_instances(kobj, dev, m); + } else + ret =3D -EINVAL; + mdev_put_parent(parent); + return ret; +} + /* * mdev_register_device : Register a device * @dev: device structure representing parent device. diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_priv= ate.h index e90d295d3927..f1289db75884 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -63,4 +63,6 @@ int mdev_device_create(struct kobject *kobj, struct devi= ce *dev, uuid_le uuid, unsigned int instances); int mdev_device_remove(struct device *dev, bool force_remove); =20 +int mdev_max_aggregated_instances(struct kobject *kobj, struct device *de= v, + unsigned int *m); #endif /* MDEV_PRIVATE_H */ diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index aefed0c8891b..a329d6ab6cb9 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -103,6 +103,18 @@ static ssize_t create_store(struct kobject *kobj, stru= ct device *dev, =20 MDEV_TYPE_ATTR_WO(create); =20 +static ssize_t +aggregation_show(struct kobject *kobj, struct device *dev, char *buf) +{ + unsigned int m; + + if (mdev_max_aggregated_instances(kobj, dev, &m)) + return sprintf(buf, "1\n"); + else + return sprintf(buf, "%u\n", m); +} +MDEV_TYPE_ATTR_RO(aggregation); + static void mdev_type_release(struct kobject *kobj) { struct mdev_type *type =3D to_mdev_type(kobj); @@ -145,6 +157,14 @@ struct mdev_type *add_mdev_supported_type(struct mdev_= parent *parent, if (ret) goto attr_create_failed; =20 + if (parent->ops->create_with_instances && + parent->ops->max_aggregated_instances) { + ret =3D sysfs_create_file(&type->kobj, + &mdev_type_attr_aggregation.attr); + if (ret) + goto attr_aggregate_failed; + } + type->devices_kobj =3D kobject_create_and_add("devices", &type->kobj); if (!type->devices_kobj) { ret =3D -ENOMEM; @@ -165,6 +185,8 @@ struct mdev_type *add_mdev_supported_type(struct mdev_p= arent *parent, attrs_failed: kobject_put(type->devices_kobj); attr_devices_failed: + sysfs_remove_file(&type->kobj, &mdev_type_attr_aggregation.attr); +attr_aggregate_failed: sysfs_remove_file(&type->kobj, &mdev_type_attr_create.attr); attr_create_failed: kobject_del(&type->kobj); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index c12c0bfc5598..66cfdb0bf0d6 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -39,6 +39,11 @@ struct mdev_device; * that is being created * @instances: number of instances to aggregate * Returns integer: success (0) or error (< 0) + * @max_aggregated_instances: Return max number for aggregated resources + * @kobj: kobject of type + * @dev: mdev parent device for target type + * @max: return max number of instances which can agg= regate + * Returns integer: success (0) or error (< 0) * @remove: Called to free resources in parent device's driver for a * a mediated device. It is mandatory to provide 'remove' * ops. @@ -82,6 +87,9 @@ struct mdev_parent_ops { int (*create_with_instances)(struct kobject *kobj, struct mdev_device *mdev, unsigned int instances); + int (*max_aggregated_instances)(struct kobject *kobj, + struct device *dev, + unsigned int *max); int (*remove)(struct mdev_device *mdev); int (*open)(struct mdev_device *mdev); void (*release)(struct mdev_device *mdev); --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 05:29:32 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 1532053492123422.8556512806831; Thu, 19 Jul 2018 19:24:52 -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 07262550D6; Fri, 20 Jul 2018 02:24:50 +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 BBF385D6A8; Fri, 20 Jul 2018 02:24: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 CD0DA18037ED; Fri, 20 Jul 2018 02:24:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6K2Oioo029743 for ; Thu, 19 Jul 2018 22:24:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id A9E1A177A6; Fri, 20 Jul 2018 02:24:44 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C9D2177B3; Fri, 20 Jul 2018 02:24:40 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 0432636A5C3; Fri, 20 Jul 2018 02:24:39 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2018 19:24:36 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.113]) by fmsmga002.fm.intel.com with ESMTP; 19 Jul 2018 19:24:31 -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,377,1526367600"; d="scan'208";a="68588747" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Fri, 20 Jul 2018 10:19:26 +0800 Message-Id: <20180720021928.15343-3-zhenyuw@linux.intel.com> In-Reply-To: <20180720021928.15343-1-zhenyuw@linux.intel.com> References: <20180620074039.10539-1-zhenyuw@linux.intel.com> <20180720021928.15343-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.29]); Fri, 20 Jul 2018 02:24:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 20 Jul 2018 02:24:39 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'zhenyuw@linux.intel.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: kevin.tian@intel.com, intel-gvt-dev@lists.freedesktop.org, kwankhede@nvidia.com Subject: [libvirt] [PATCH v2 2/4] vfio/mdev: Add mdev device instances attribute 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.29]); Fri, 20 Jul 2018 02:24:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For mdev device, create new sysfs attribute "instances" to show number of instances allocated for possible aggregation type. For compatibility default or without aggregated allocation, the number is 1. Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Signed-off-by: Zhenyu Wang --- drivers/vfio/mdev/mdev_core.c | 1 + drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/mdev_sysfs.c | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index e69db302a4f2..f0478fc372d8 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -326,6 +326,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) { diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_priv= ate.h index c9d3fe04e273..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 diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index a06e5b7c69d3..5a417a20e774 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -268,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 --=20 2.18.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 05:29:32 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 153205351648475.74832174662765; Thu, 19 Jul 2018 19:25:16 -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 BEEE68553C; Fri, 20 Jul 2018 02:25:14 +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 805B060170; Fri, 20 Jul 2018 02:25:14 +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 2640F4A465; Fri, 20 Jul 2018 02:25:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6K2OkGA029771 for ; Thu, 19 Jul 2018 22:24:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id DF73A60BE5; Fri, 20 Jul 2018 02:24:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BBDA60C8F; Fri, 20 Jul 2018 02:24:41 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 DF986C04AC5A; Fri, 20 Jul 2018 02:24:39 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2018 19:24:36 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.113]) by fmsmga002.fm.intel.com with ESMTP; 19 Jul 2018 19:24:33 -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,377,1526367600"; d="scan'208";a="68588769" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Fri, 20 Jul 2018 10:19:27 +0800 Message-Id: <20180720021928.15343-4-zhenyuw@linux.intel.com> In-Reply-To: <20180720021928.15343-1-zhenyuw@linux.intel.com> References: <20180620074039.10539-1-zhenyuw@linux.intel.com> <20180720021928.15343-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.31]); Fri, 20 Jul 2018 02:24:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 20 Jul 2018 02:24:40 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'zhenyuw@linux.intel.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: kevin.tian@intel.com, intel-gvt-dev@lists.freedesktop.org, kwankhede@nvidia.com Subject: [libvirt] [PATCH v2 3/4] drm/i915/gvt: Add new aggregation type 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: , 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.28]); Fri, 20 Jul 2018 02:25:15 +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. For KVMGT, aggregated resource is determined by memory and fence resource allocation for target number of instances. Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian 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 | 30 ++++++++++++++--- drivers/gpu/drm/i915/gvt/vgpu.c | 56 ++++++++++++++++++++++++++++---- 4 files changed, 104 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c index 712f9d14e720..21600447b029 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 9a9671522774..8848587f638f 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,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 { @@ -484,7 +488,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); @@ -562,15 +567,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 4d2f53ae9f0f..4f3a57b510fd 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -498,7 +498,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; @@ -517,7 +519,12 @@ 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 > 1 && !type->aggregation) { + 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); @@ -537,6 +544,20 @@ 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_remove(struct mdev_device *mdev) { struct intel_vgpu *vgpu =3D mdev_get_drvdata(mdev); @@ -1430,6 +1451,7 @@ 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, .remove =3D intel_vgpu_remove, =20 .open =3D intel_vgpu_open, @@ -1443,12 +1465,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 f6fa916517c3..5304b983a84b 100644 --- a/drivers/gpu/drm/i915/gvt/vgpu.c +++ b/drivers/gpu/drm/i915/gvt/vgpu.c @@ -125,11 +125,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 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) @@ -149,11 +152,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, @@ -164,7 +167,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 @@ -444,7 +472,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; @@ -461,6 +490,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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 05:29:32 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 1539767406785267.4964700614487; Wed, 17 Oct 2018 02:10:06 -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 9A83A31A334; Wed, 17 Oct 2018 09:10:04 +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 995AB63BA3; Wed, 17 Oct 2018 09:10:03 +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 D333E180B61F; Wed, 17 Oct 2018 09:10:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9H96dUw016808 for ; Wed, 17 Oct 2018 05:06:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3AD005C729; Wed, 17 Oct 2018 09:06:38 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AEF535C239; Wed, 17 Oct 2018 09:06:27 +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 671CF307C700; Wed, 17 Oct 2018 09:06:23 +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:23 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.20]) by fmsmga007.fm.intel.com with ESMTP; 17 Oct 2018 02:06:21 -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="78678813" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Wed, 17 Oct 2018 17:00:05 +0800 Message-Id: <20181017090008.16282-4-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.42]); Wed, 17 Oct 2018 09:06:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 17 Oct 2018 09:06:23 +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.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Kevin Tian , Kirti Wankhede , Cornelia Huck , intel-gvt-dev@lists.freedesktop.org Subject: [libvirt] [PATCH v3 3/6] vfio/mdev: Add "aggregated_instances" attribute for supported mdev device 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.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.29]); Wed, 17 Oct 2018 09:10:05 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For mdev device created by "aggregate" parameter, this creates new mdev device attribute "aggregated_instances" to show number of aggregated instances allocated. v2: - change attribute name as "aggregated_instances" v3: - create only for aggregated allocation Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Cc: Cornelia Huck Signed-off-by: Zhenyu Wang --- drivers/vfio/mdev/mdev_sysfs.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index a329d6ab6cb9..f03bdfbf5a42 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -292,7 +292,17 @@ static ssize_t remove_store(struct device *dev, struct= device_attribute *attr, return count; } =20 +static ssize_t +aggregated_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(aggregated_instances); =20 static const struct attribute *mdev_device_attrs[] =3D { &dev_attr_remove.attr, @@ -301,6 +311,7 @@ static const struct attribute *mdev_device_attrs[] =3D { =20 int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type) { + struct mdev_device *mdev =3D to_mdev_device(dev); int ret; =20 ret =3D sysfs_create_link(type->devices_kobj, &dev->kobj, dev_name(dev)); @@ -315,8 +326,17 @@ int mdev_create_sysfs_files(struct device *dev, struc= t mdev_type *type) if (ret) goto create_files_failed; =20 + if (mdev->type_instances > 1) { + ret =3D sysfs_create_file(&dev->kobj, + &dev_attr_aggregated_instances.attr); + if (ret) + goto create_aggregated_failed; + } + return ret; =20 +create_aggregated_failed: + sysfs_remove_files(&dev->kobj, mdev_device_attrs); create_files_failed: sysfs_remove_link(&dev->kobj, "mdev_type"); type_link_failed: --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 05:29:32 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 153205351993474.91309241893316; Thu, 19 Jul 2018 19:25:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3966C049E32; Fri, 20 Jul 2018 02:25:18 +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 6EC43308332E; Fri, 20 Jul 2018 02:25:18 +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 23B1A18037EC; Fri, 20 Jul 2018 02:25:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6K2OjRY029756 for ; Thu, 19 Jul 2018 22:24:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 91B445D9CB; Fri, 20 Jul 2018 02:24:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8B3F95D9C8; Fri, 20 Jul 2018 02:24:41 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 2EB1081DE1; Fri, 20 Jul 2018 02:24:40 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2018 19:24:36 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.113]) by fmsmga002.fm.intel.com with ESMTP; 19 Jul 2018 19:24:35 -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,377,1526367600"; d="scan'208";a="68588771" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Fri, 20 Jul 2018 10:19:28 +0800 Message-Id: <20180720021928.15343-5-zhenyuw@linux.intel.com> In-Reply-To: <20180720021928.15343-1-zhenyuw@linux.intel.com> References: <20180620074039.10539-1-zhenyuw@linux.intel.com> <20180720021928.15343-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.25]); Fri, 20 Jul 2018 02:24:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 20 Jul 2018 02:24:40 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'zhenyuw@linux.intel.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kevin.tian@intel.com, intel-gvt-dev@lists.freedesktop.org, kwankhede@nvidia.com Subject: [libvirt] [PATCH v2 4/4] Documentation/vfio-mediated-device.txt: update for aggregation attribute 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 20 Jul 2018 02:25:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Update mdev doc on new aggregration attribute and instances attribute for mdev. Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Signed-off-by: Zhenyu Wang --- Documentation/vfio-mediated-device.txt | 39 ++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/Documentation/vfio-mediated-device.txt b/Documentation/vfio-me= diated-device.txt index c3f69bcaf96e..9ec9495dcbe7 100644 --- a/Documentation/vfio-mediated-device.txt +++ b/Documentation/vfio-mediated-device.txt @@ -211,12 +211,20 @@ Directories and files under the sysfs for Each Physic= al Device | | |--- description | | |--- [devices] | |--- [] - | |--- create - | |--- name - | |--- available_instances - | |--- device_api - | |--- description - | |--- [devices] + | | |--- create + | | |--- name + | | |--- available_instances + | | |--- device_api + | | |--- description + | | |--- [devices] + | |--- [] + | | |--- create + | | |--- name + | | |--- available_instances + | | |--- device_api + | | |--- description + | | |--- + | | |--- [devices] =20 * [mdev_supported_types] =20 @@ -260,6 +268,19 @@ Directories and files under the sysfs for Each Physica= l Device This attribute should show brief features/description of the type. This = is optional attribute. =20 +* + + The description is to show feature for one instance of the type. + is an optional attributes to show that []'s instances can be + aggregated to be assigned for one mdev device. Set number of instances by + appending "instances=3DN" parameter for create. Instances number can't e= xceed + available_instances number. Without "instances=3DN" parameter will be de= fault + one instance to create. + +Example:: + + # echo ",instances=3DN" > create + Directories and Files Under the sysfs for Each mdev Device ---------------------------------------------------------- =20 @@ -268,6 +289,7 @@ Directories and Files Under the sysfs for Each mdev Dev= ice |- [parent phy device] |--- [$MDEV_UUID] |--- remove + |--- instances |--- mdev_type {link to its type} |--- vendor-specific-attributes [optional] =20 @@ -281,6 +303,11 @@ Example:: =20 # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove =20 +* instances + +For aggregation type show number of instances assigned for this mdev. For = normal +type or default will just show one instance. + Mediated device Hot plug ------------------------ =20 --=20 2.18.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 05:29:32 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 1539767393528791.3834667117594; Wed, 17 Oct 2018 02:09:53 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AB3588302; Wed, 17 Oct 2018 09:09:51 +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 CA8AE1057047; Wed, 17 Oct 2018 09:09:50 +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 69524180B5B7; Wed, 17 Oct 2018 09:09:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9H96hDK016826 for ; Wed, 17 Oct 2018 05:06:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED0A369FDD; Wed, 17 Oct 2018 09:06:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 363FC2B10C; Wed, 17 Oct 2018 09:06:26 +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 0C39AC02E62E; Wed, 17 Oct 2018 09:06:25 +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:24 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.20]) by fmsmga007.fm.intel.com with ESMTP; 17 Oct 2018 02:06:23 -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="78678819" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Wed, 17 Oct 2018 17:00:06 +0800 Message-Id: <20181017090008.16282-5-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.32]); Wed, 17 Oct 2018 09:06:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 17 Oct 2018 09:06:25 +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.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Kevin Tian , Kirti Wankhede , Cornelia Huck , intel-gvt-dev@lists.freedesktop.org Subject: [libvirt] [PATCH v3 4/6] Documentation/vfio-mediated-device.txt: Update for vfio/mdev 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 17 Oct 2018 09:09:51 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Update vfio/mdev doc on new "aggregate" create parameter, new "aggregation" attribute and "aggregated_instances" attribute for mdev device. Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Cc: Cornelia Huck Signed-off-by: Zhenyu Wang --- Documentation/vfio-mediated-device.txt | 44 ++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/Documentation/vfio-mediated-device.txt b/Documentation/vfio-me= diated-device.txt index c3f69bcaf96e..cf4849a34c9f 100644 --- a/Documentation/vfio-mediated-device.txt +++ b/Documentation/vfio-mediated-device.txt @@ -211,12 +211,20 @@ Directories and files under the sysfs for Each Physic= al Device | | |--- description | | |--- [devices] | |--- [] - | |--- create - | |--- name - | |--- available_instances - | |--- device_api - | |--- description - | |--- [devices] + | | |--- create + | | |--- name + | | |--- available_instances + | | |--- device_api + | | |--- description + | | |--- [devices] + | |--- [] + | | |--- create + | | |--- name + | | |--- available_instances + | | |--- device_api + | | |--- description + | | |--- + | | |--- [devices] =20 * [mdev_supported_types] =20 @@ -260,6 +268,23 @@ Directories and files under the sysfs for Each Physica= l Device This attribute should show brief features/description of the type. This = is optional attribute. =20 +* + + is an optional attributes to show max number that the + instance resources of [] can be aggregated to be assigned + for one mdev device. No attribute means driver doesn't + support to aggregate instance resoures for one mdev device. + may be less than available_instances which depends on + driver. number can't exceed available_instances. + + Set number of instances by appending "aggregate=3DN" parameter for + create attribute. By default without "aggregate=3DN" parameter it + will create one instance as normal. + +Example:: + + # echo ",aggregate=3DN" > create + Directories and Files Under the sysfs for Each mdev Device ---------------------------------------------------------- =20 @@ -268,6 +293,7 @@ Directories and Files Under the sysfs for Each mdev Dev= ice |- [parent phy device] |--- [$MDEV_UUID] |--- remove + |--- |--- mdev_type {link to its type} |--- vendor-specific-attributes [optional] =20 @@ -281,6 +307,12 @@ Example:: =20 # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove =20 +* (read only) + +For mdev created with aggregate parameter, this shows number of +instances assigned for this mdev. For normal type this attribute will +not exist. + Mediated device Hot plug ------------------------ =20 --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 05:29:32 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 1539767407132600.4143389784072; Wed, 17 Oct 2018 02:10:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92046307C941; Wed, 17 Oct 2018 09:10:04 +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 4C43D5C240; Wed, 17 Oct 2018 09:10:04 +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 89EEF3FADE; Wed, 17 Oct 2018 09:10:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9H96wMU016841 for ; Wed, 17 Oct 2018 05:06:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0DCE057C8A; Wed, 17 Oct 2018 09:06:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3C2F43FFE; Wed, 17 Oct 2018 09:06:28 +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 9C184C045758; Wed, 17 Oct 2018 09:06:26 +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:26 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.20]) by fmsmga007.fm.intel.com with ESMTP; 17 Oct 2018 02:06:25 -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="78678825" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Wed, 17 Oct 2018 17:00:07 +0800 Message-Id: <20181017090008.16282-6-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.32]); Wed, 17 Oct 2018 09:06:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 17 Oct 2018 09:06:26 +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.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Kevin Tian , Kirti Wankhede , Cornelia Huck , intel-gvt-dev@lists.freedesktop.org Subject: [libvirt] [PATCH v3 5/6] Documentation/ABI/testing/sysfs-bus-vfio-mdev: Update for vfio/mdev 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 17 Oct 2018 09:10:05 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Update vfio/mdev ABI description for new aggregation attributes. Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Cc: Cornelia Huck Signed-off-by: Zhenyu Wang --- Documentation/ABI/testing/sysfs-bus-vfio-mdev | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-vfio-mdev b/Documentation/= ABI/testing/sysfs-bus-vfio-mdev index 452dbe39270e..192fe06e60d0 100644 --- a/Documentation/ABI/testing/sysfs-bus-vfio-mdev +++ b/Documentation/ABI/testing/sysfs-bus-vfio-mdev @@ -85,6 +85,24 @@ Users: a particular that can help in understanding the features provided by that type of mediated device. =20 +What: /sys/.../mdev_supported_types//aggregation +Date: October 2018 +Contact: Zhenyu Wang +Description: + Reading this attribute will show number of mdev instances + that can be aggregated to assign for one mdev device. + This is optional attribute. If this attribute exists that + means driver supports to aggregate target mdev type's + resources assigned for one mdev device. +Users: + Userspace applications interested in creating mediated + device with aggregated type instances. Userspace application + should check the number of aggregation instances that could + be created before creating mediated device by applying this, + e.g + # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001,aggregate=3DXX" > \ + /sys/devices/foo/mdev_supported_types/foo-1/create + What: /sys/.../// Date: October 2016 Contact: Kirti Wankhede @@ -109,3 +127,10 @@ Description: is active and the vendor driver doesn't support hot unplug. Example: # echo 1 > /sys/bus/mdev/devices//remove + +What: /sys/...///aggregated_instances +Date: October 2018 +Contact: Zhenyu Wang +Description: + This attributes shows number of aggregated instances if this + mediated device was created with "aggregate" parameter. \ No newline at end of file --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 05:29:32 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 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