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