From: Zhenyu Wang <zhenyuw@linux.intel.com>
To: kvm@vger.kernel.org
Cc: alex.williamson@redhat.com, kwankhede@nvidia.com,
kevin.tian@intel.com, cohuck@redhat.com
Subject: [PATCH 1/6] vfio/mdev: Add new "aggregate" parameter for mdev create
Date: Thu, 24 Oct 2019 13:08:24 +0800 [thread overview]
Message-ID: <20191024050829.4517-2-zhenyuw@linux.intel.com> (raw)
In-Reply-To: <20191024050829.4517-1-zhenyuw@linux.intel.com>
For special mdev type which can aggregate instances for mdev device,
this extends mdev create interface by allowing extra "aggregate=xxx"
parameter, which is passed to mdev device model to be able to create
bundled number of instances for target mdev device.
Cc: Kirti Wankhede <kwankhede@nvidia.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
---
v2: create new create_with_instances operator for vendor driver
v3:
- Change parameter name as "aggregate="
- Fix new interface comments.
- Parameter checking for new option, pass UUID string only to
parse and properly end parameter for kstrtouint() conversion.
v4:
- rebase
- just call create_with_instances if exists, otherwise call create
drivers/vfio/mdev/mdev_core.c | 17 +++++++++++++++--
drivers/vfio/mdev/mdev_private.h | 4 +++-
drivers/vfio/mdev/mdev_sysfs.c | 27 +++++++++++++++++++++++----
include/linux/mdev.h | 11 +++++++++++
4 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index b558d4cfd082..4926a99f664d 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -270,7 +270,8 @@ static void mdev_device_release(struct device *dev)
}
int mdev_device_create(struct kobject *kobj,
- struct device *dev, const guid_t *uuid)
+ struct device *dev, const guid_t *uuid,
+ unsigned int instances)
{
int ret;
struct mdev_device *mdev, *tmp;
@@ -281,6 +282,13 @@ int mdev_device_create(struct kobject *kobj,
if (!parent)
return -EINVAL;
+ if (instances > 1 &&
+ !parent->ops->create_with_instances) {
+ dev_warn(dev, "Non-supported aggregate instances create\n");
+ ret = -EINVAL;
+ goto mdev_fail;
+ }
+
mutex_lock(&mdev_list_lock);
/* Check for duplicate */
@@ -319,8 +327,13 @@ int mdev_device_create(struct kobject *kobj,
dev_set_name(&mdev->dev, "%pUl", uuid);
mdev->dev.groups = parent->ops->mdev_attr_groups;
mdev->type_kobj = kobj;
+ mdev->type_instances = instances;
- ret = parent->ops->create(kobj, mdev);
+ if (parent->ops->create_with_instances)
+ ret = parent->ops->create_with_instances(kobj, mdev,
+ instances);
+ else
+ ret = parent->ops->create(kobj, mdev);
if (ret)
goto ops_create_fail;
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index 7d922950caaf..56cbe9ea8817 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -33,6 +33,7 @@ struct mdev_device {
struct kobject *type_kobj;
struct device *iommu_device;
bool active;
+ unsigned int type_instances;
};
#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
@@ -58,7 +59,8 @@ int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
int mdev_device_create(struct kobject *kobj,
- struct device *dev, const guid_t *uuid);
+ struct device *dev, const guid_t *uuid,
+ unsigned int instances);
int mdev_device_remove(struct device *dev);
#endif /* MDEV_PRIVATE_H */
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index 7570c7602ab4..6c2693dd4022 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -48,17 +48,27 @@ static const struct sysfs_ops mdev_type_sysfs_ops = {
.store = mdev_type_attr_store,
};
+#define MDEV_CREATE_BUF 4096
static ssize_t create_store(struct kobject *kobj, struct device *dev,
const char *buf, size_t count)
{
- char *str;
+ char *str, *param;
guid_t uuid;
int ret;
+ unsigned int instances = 1;
- if ((count < UUID_STRING_LEN) || (count > UUID_STRING_LEN + 1))
+ if (count < UUID_STRING_LEN)
return -EINVAL;
+ if (count > MDEV_CREATE_BUF - 1)
+ return -E2BIG;
- str = kstrndup(buf, count, GFP_KERNEL);
+ if ((param = strnchr(buf, count, ',')) == NULL) {
+ if (count > UUID_STRING_LEN + 1)
+ return -EINVAL;
+ } else if (param - buf != UUID_STRING_LEN)
+ return -EINVAL;
+
+ str = kstrndup(buf, UUID_STRING_LEN, GFP_KERNEL);
if (!str)
return -ENOMEM;
@@ -67,7 +77,16 @@ static ssize_t create_store(struct kobject *kobj, struct device *dev,
if (ret)
return ret;
- ret = mdev_device_create(kobj, dev, &uuid);
+ if (param) {
+ param++;
+ if (strncmp(param, "aggregate=", 10))
+ return -EINVAL;
+ param += 10;
+ if (kstrtouint(param, 0, &instances))
+ return -EINVAL;
+ }
+
+ ret = mdev_device_create(kobj, dev, &uuid, instances);
if (ret)
return ret;
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index 0ce30ca78db0..0dbb7ec27009 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -42,6 +42,14 @@ struct device *mdev_get_iommu_device(struct device *dev);
* @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 parent 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 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.
@@ -82,6 +90,9 @@ struct mdev_parent_ops {
struct attribute_group **supported_type_groups;
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);
--
2.24.0.rc0
next prev parent reply other threads:[~2019-10-24 5:08 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-24 5:08 [PATCH 0/6] VFIO mdev aggregated resources handling Zhenyu Wang
2019-10-24 5:08 ` Zhenyu Wang [this message]
2019-10-24 5:08 ` [PATCH 2/6] vfio/mdev: Add "aggregation" attribute for supported mdev type Zhenyu Wang
2019-10-27 6:24 ` kbuild test robot
2019-10-27 6:24 ` kbuild test robot
2019-10-27 6:24 ` [RFC PATCH] vfio/mdev: mdev_type_attr_aggregation can be static kbuild test robot
2019-10-27 6:24 ` kbuild test robot
2019-10-24 5:08 ` [PATCH 3/6] vfio/mdev: Add "aggregated_instances" attribute for supported mdev device Zhenyu Wang
2019-10-24 5:08 ` [PATCH 4/6] Documentation/driver-api/vfio-mediated-device.rst: Update for vfio/mdev aggregation support Zhenyu Wang
2019-10-24 5:08 ` [PATCH 5/6] Documentation/ABI/testing/sysfs-bus-vfio-mdev: " Zhenyu Wang
2019-10-24 5:08 ` [PATCH 6/6] drm/i915/gvt: Add new type with " Zhenyu Wang
2019-11-05 21:10 ` [PATCH 0/6] VFIO mdev aggregated resources handling Alex Williamson
2019-11-06 4:20 ` Zhenyu Wang
2019-11-06 18:44 ` Alex Williamson
2019-11-07 13:02 ` Cornelia Huck
2019-11-15 4:24 ` Tian, Kevin
2019-11-19 22:58 ` Alex Williamson
2019-11-20 0:46 ` Tian, Kevin
2019-11-07 20:37 ` Parav Pandit
2019-11-08 8:19 ` Zhenyu Wang
2019-12-04 17:36 ` Parav Pandit
2019-12-05 6:06 ` Zhenyu Wang
2019-12-05 6:40 ` Jason Wang
2019-12-05 19:02 ` Parav Pandit
2019-12-05 18:59 ` Parav Pandit
2019-12-06 8:03 ` Zhenyu Wang
2019-12-06 17:33 ` Parav Pandit
2019-12-10 3:33 ` Tian, Kevin
2019-12-10 19:07 ` Alex Williamson
2019-12-10 21:08 ` Parav Pandit
2019-12-10 22:08 ` Alex Williamson
2019-12-10 22:40 ` Parav Pandit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191024050829.4517-2-zhenyuw@linux.intel.com \
--to=zhenyuw@linux.intel.com \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.