From nobody Sat Feb 7 05:01:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 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