Add an ioctl to allow VDUSE instances to query the available features
supported by the kernel module.

Signed-off-by: Eugenio Pérez <[email protected]>
---
A simple u64 bitmap is used for feature flags. While a flexible array
could support indefinite expansion, 64 bits is sufficient for the
foreseeable future and simplifies the implementation.

Also, dev_dbg is used for logging rather than dev_err as these can be
triggered from userspace.
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 28 ++++++++++++++++++++++++++++
 include/uapi/linux/vduse.h         |  7 ++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c 
b/drivers/vdpa/vdpa_user/vduse_dev.c
index 551ccde0b856..e7da69c2ad71 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -52,6 +52,9 @@
 
 #define IRQ_UNBOUND -1
 
+/* Supported VDUSE features */
+static const uint64_t vduse_features;
+
 /*
  * VDUSE instance have not asked the vduse API version, so assume 0.
  *
@@ -1977,6 +1980,19 @@ static bool vduse_validate_config(struct 
vduse_dev_config *config,
                         sizeof(config->reserved)))
                return false;
 
+       if (api_version < VDUSE_API_VERSION_2) {
+               if (config->vduse_features) {
+                       dev_dbg(vduse_ctrl_dev,
+                               "config->vduse_features with version %llu",
+                               api_version);
+                       return false;
+               }
+       } else {
+               if (config->vduse_features & ~vduse_features)
+                       return false;
+       }
+
+
        if (api_version < VDUSE_API_VERSION_1 &&
            (config->ngroups || config->nas))
                return false;
@@ -2237,6 +2253,18 @@ static long vduse_ioctl(struct file *file, unsigned int 
cmd,
                ret = vduse_destroy_dev(name);
                break;
        }
+       case VDUSE_GET_FEATURES:
+               if (control->api_version < VDUSE_API_VERSION_2) {
+                       dev_dbg(vduse_ctrl_dev,
+                               "VDUSE_GET_FEATURES ioctl with version %llu",
+                               control->api_version);
+                       ret = -ENOIOCTLCMD;
+                       break;
+               }
+
+               ret = put_user(vduse_features, (u64 __user *)argp);
+               break;
+
        default:
                ret = -EINVAL;
                break;
diff --git a/include/uapi/linux/vduse.h b/include/uapi/linux/vduse.h
index dea89ed281a7..1f68e556cbf2 100644
--- a/include/uapi/linux/vduse.h
+++ b/include/uapi/linux/vduse.h
@@ -37,6 +37,7 @@
  * @vq_align: the allocation alignment of virtqueue's metadata
  * @ngroups: number of vq groups that VDUSE device declares
  * @nas: number of address spaces that VDUSE device declares
+ * @vduse_features: VDUSE features
  * @reserved: for future use, needs to be initialized to zero
  * @config_size: the size of the configuration space
  * @config: the buffer of the configuration space
@@ -53,7 +54,8 @@ struct vduse_dev_config {
        __u32 vq_align;
        __u32 ngroups; /* if VDUSE_API_VERSION >= 1 */
        __u32 nas; /* if VDUSE_API_VERSION >= 1 */
-       __u32 reserved[11];
+       __u64 vduse_features;
+       __u32 reserved[9];
        __u32 config_size;
        __u8 config[];
 };
@@ -67,6 +69,9 @@ struct vduse_dev_config {
  */
 #define VDUSE_DESTROY_DEV      _IOW(VDUSE_BASE, 0x03, char[VDUSE_NAME_MAX])
 
+/* Get the VDUSE supported features */
+#define VDUSE_GET_FEATURES     _IOR(VDUSE_BASE, 0x04, __u64)
+
 /* The ioctls for VDUSE device (/dev/vduse/$NAME) */
 
 /**
-- 
2.52.0


Reply via email to