From nobody Thu Jul 3 23:36:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1529480742405982.3315735592025; Wed, 20 Jun 2018 00:45:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 658C430820CD; Wed, 20 Jun 2018 07:45:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A63015D755; Wed, 20 Jun 2018 07:45:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 464351800537; Wed, 20 Jun 2018 07:45:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5K7ja0m030685 for ; Wed, 20 Jun 2018 03:45:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 571F886EFA; Wed, 20 Jun 2018 07:45:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B853FB1A17; Wed, 20 Jun 2018 07:45:31 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EEF7C87622; Wed, 20 Jun 2018 07:45:29 +0000 (UTC) Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jun 2018 00:45:28 -0700 Received: from debian-nuc.sh.intel.com ([10.239.13.10]) by orsmga007.jf.intel.com with ESMTP; 20 Jun 2018 00:45:14 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,246,1526367600"; d="scan'208";a="50418467" From: Zhenyu Wang To: libvirt-list@redhat.com, kvm@vger.kernel.org Date: Wed, 20 Jun 2018 15:40:38 +0800 Message-Id: <20180620074039.10539-2-zhenyuw@linux.intel.com> In-Reply-To: <20180620074039.10539-1-zhenyuw@linux.intel.com> References: <20180620074039.10539-1-zhenyuw@linux.intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Jun 2018 07:45:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Jun 2018 07:45:30 +0000 (UTC) for IP:'134.134.136.126' DOMAIN:'mga18.intel.com' HELO:'mga18.intel.com' FROM:'zhenyuw@linux.intel.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED) 134.134.136.126 mga18.intel.com 134.134.136.126 mga18.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: intel-gvt-dev@lists.freedesktop.org, kevin.tian@intel.com, kwankhede@nvidia.com Subject: [libvirt] [RFC PATCH 1/2] vfio/mdev: Add new instances parameters for mdev create X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 20 Jun 2018 07:45:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For special mdev type which can aggregate instances for mdev device, this extends mdev create interface by allowing extra "instances=3Dxxx" parameter, which is passed to mdev device model to be able to create arbitrary bundled number of instances for target mdev device. For created mdev device, also create new sysfs attr "instances" to show. For compatibility, current default instances is 1. Cc: Alex Williamson Cc: Kirti Wankhede Signed-off-by: Zhenyu Wang --- drivers/gpu/drm/i915/gvt/kvmgt.c | 3 ++- drivers/s390/cio/vfio_ccw_ops.c | 3 ++- drivers/vfio/mdev/mdev_core.c | 11 ++++++--- drivers/vfio/mdev/mdev_private.h | 6 ++++- drivers/vfio/mdev/mdev_sysfs.c | 42 +++++++++++++++++++++++++++----- include/linux/mdev.h | 3 ++- samples/vfio-mdev/mbochs.c | 3 ++- samples/vfio-mdev/mdpy.c | 3 ++- samples/vfio-mdev/mtty.c | 3 ++- 9 files changed, 60 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kv= mgt.c index df4e4a07db3d..4a543e23b9a0 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -444,7 +444,8 @@ static void kvmgt_put_vfio_device(void *vgpu) vfio_device_put(((struct intel_vgpu *)vgpu)->vdev.vfio_device); } =20 -static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mde= v) +static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mde= v, + unsigned int instances) { struct intel_vgpu *vgpu =3D NULL; struct intel_vgpu_type *type; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_op= s.c index 41eeb57d68a3..4c37826ec9d0 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -106,7 +106,8 @@ static struct attribute_group *mdev_type_groups[] =3D { NULL, }; =20 -static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *= mdev) +static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *= mdev, + unsigned int instances) { struct vfio_ccw_private *private =3D dev_get_drvdata(mdev_parent_dev(mdev)); diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 0212f0ee8aea..98b0a78e6832 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -104,12 +104,13 @@ static inline void mdev_put_parent(struct mdev_parent= *parent) } =20 static int mdev_device_create_ops(struct kobject *kobj, - struct mdev_device *mdev) + struct mdev_device *mdev, + unsigned int instances) { struct mdev_parent *parent =3D mdev->parent; int ret; =20 - ret =3D parent->ops->create(kobj, mdev); + ret =3D parent->ops->create(kobj, mdev, instances); if (ret) return ret; =20 @@ -276,7 +277,8 @@ static void mdev_device_release(struct device *dev) kfree(mdev); } =20 -int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le u= uid) +int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le u= uid, + unsigned int instances) { int ret; struct mdev_device *mdev, *tmp; @@ -316,6 +318,7 @@ int mdev_device_create(struct kobject *kobj, struct dev= ice *dev, uuid_le uuid) mdev->dev.bus =3D &mdev_bus_type; mdev->dev.release =3D mdev_device_release; dev_set_name(&mdev->dev, "%pUl", uuid.b); + mdev->type_instances =3D instances; =20 ret =3D device_register(&mdev->dev); if (ret) { @@ -323,7 +326,7 @@ int mdev_device_create(struct kobject *kobj, struct dev= ice *dev, uuid_le uuid) goto mdev_fail; } =20 - ret =3D mdev_device_create_ops(kobj, mdev); + ret =3D mdev_device_create_ops(kobj, mdev, instances); if (ret) goto create_fail; =20 diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_priv= ate.h index b5819b7d7ef7..aa0b4b64c503 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -33,6 +33,7 @@ struct mdev_device { struct kref ref; struct list_head next; struct kobject *type_kobj; + unsigned int type_instances; bool active; }; =20 @@ -52,13 +53,16 @@ struct mdev_type { #define to_mdev_type(_kobj) \ container_of(_kobj, struct mdev_type, kobj) =20 +#define MDEV_CREATE_OPT_LEN 32 + int parent_create_sysfs_files(struct mdev_parent *parent); void parent_remove_sysfs_files(struct mdev_parent *parent); =20 int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type); void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type); =20 -int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le = uuid); +int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le = uuid, + unsigned int instances); int mdev_device_remove(struct device *dev, bool force_remove); =20 #endif /* MDEV_PRIVATE_H */ diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 249472f05509..5a417a20e774 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -54,11 +54,15 @@ static const struct sysfs_ops mdev_type_sysfs_ops =3D { static ssize_t create_store(struct kobject *kobj, struct device *dev, const char *buf, size_t count) { - char *str; + char *str, *opt =3D NULL; uuid_le uuid; int ret; + unsigned int instances =3D 1; =20 - if ((count < UUID_STRING_LEN) || (count > UUID_STRING_LEN + 1)) + if (count < UUID_STRING_LEN) + return -EINVAL; + + if (count > UUID_STRING_LEN + 1 + MDEV_CREATE_OPT_LEN) return -EINVAL; =20 str =3D kstrndup(buf, count, GFP_KERNEL); @@ -66,13 +70,31 @@ static ssize_t create_store(struct kobject *kobj, struc= t device *dev, return -ENOMEM; =20 ret =3D uuid_le_to_bin(str, &uuid); - kfree(str); - if (ret) + if (ret) { + kfree(str); return ret; + } =20 - ret =3D mdev_device_create(kobj, dev, uuid); - if (ret) + if (count > UUID_STRING_LEN + 1) { + opt =3D str + UUID_STRING_LEN; + if (*opt++ !=3D ',' || + strncmp(opt, "instances=3D", 10)) { + kfree(str); + return -EINVAL; + } + opt +=3D 10; + if (kstrtouint(opt, 10, &instances)) { + kfree(str); + return -EINVAL; + } + } + + ret =3D mdev_device_create(kobj, dev, uuid, instances); + if (ret) { + kfree(str); return ret; + } + kfree(str); =20 return count; } @@ -246,10 +268,18 @@ static ssize_t remove_store(struct device *dev, struc= t device_attribute *attr, return count; } =20 +static ssize_t instances_show(struct device *dev, struct device_attribute = *attr, char *buf) +{ + struct mdev_device *mdev =3D to_mdev_device(dev); + return sprintf(buf, "%u\n", mdev->type_instances); +} + static DEVICE_ATTR_WO(remove); +static DEVICE_ATTR_RO(instances); =20 static const struct attribute *mdev_device_attrs[] =3D { &dev_attr_remove.attr, + &dev_attr_instances.attr, NULL, }; =20 diff --git a/include/linux/mdev.h b/include/linux/mdev.h index b6e048e1045f..12d42aa30f81 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -70,7 +70,8 @@ struct mdev_parent_ops { const struct attribute_group **mdev_attr_groups; struct attribute_group **supported_type_groups; =20 - int (*create)(struct kobject *kobj, struct mdev_device *mdev); + int (*create)(struct kobject *kobj, struct mdev_device *mdev, + unsigned int instances); int (*remove)(struct mdev_device *mdev); int (*open)(struct mdev_device *mdev); void (*release)(struct mdev_device *mdev); diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 2960e26c6ea4..8b2a9e98c587 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -432,7 +432,8 @@ static int mbochs_reset(struct mdev_device *mdev) return 0; } =20 -static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev) +static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev, + unsigned int instances) { const struct mbochs_type *type =3D mbochs_find_type(kobj); struct device *dev =3D mdev_dev(mdev); diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 96e7969c473a..0ec48ea5225a 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -226,7 +226,8 @@ static int mdpy_reset(struct mdev_device *mdev) return 0; } =20 -static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) +static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev, + unsigned int instances) { const struct mdpy_type *type =3D mdpy_find_type(kobj); struct device *dev =3D mdev_dev(mdev); diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 7abb79d8313d..ff2eaffa1155 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -727,7 +727,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, ch= ar *buf, size_t count, return ret; } =20 -int mtty_create(struct kobject *kobj, struct mdev_device *mdev) +int mtty_create(struct kobject *kobj, struct mdev_device *mdev, + unsigned int instances) { struct mdev_state *mdev_state; char name[MTTY_STRING_LEN]; --=20 2.18.0.rc2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list