Linux CXL
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Andy Gospodarek <andrew.gospodarek@broadcom.com>,
	Aron Silverton <aron.silverton@oracle.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	David Ahern <dsahern@kernel.org>,
	Andy Gospodarek <gospo@broadcom.com>,
	Christoph Hellwig <hch@infradead.org>,
	Itay Avraham <itayavr@nvidia.com>, Jiri Pirko <jiri@nvidia.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Leonid Bloch <lbloch@nvidia.com>,
	Leon Romanovsky <leonro@nvidia.com>,
	linux-cxl@vger.kernel.org, linux-rdma@vger.kernel.org,
	netdev@vger.kernel.org, Saeed Mahameed <saeedm@nvidia.com>,
	"Nelson, Shannon" <shannon.nelson@amd.com>
Subject: Re: [PATCH v4 03/10] fwctl: FWCTL_INFO to return basic information about the device
Date: Fri, 7 Feb 2025 17:21:08 -0700	[thread overview]
Message-ID: <761f0f12-417e-400d-b8f1-ccb9c8766c09@intel.com> (raw)
In-Reply-To: <3-v4-0cf4ec3b8143+4995-fwctl_jgg@nvidia.com>



On 2/6/25 5:13 PM, Jason Gunthorpe wrote:
> Userspace will need to know some details about the fwctl interface being
> used to locate the correct userspace code to communicate with the
> kernel. Provide a simple device_type enum indicating what the kernel
> driver is.
> 
> Allow the device to provide a device specific info struct that contains
> any additional information that the driver may need to provide to
> userspace.
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  drivers/fwctl/main.c       | 51 ++++++++++++++++++++++++++++++++++++++
>  include/linux/fwctl.h      | 12 +++++++++
>  include/uapi/fwctl/fwctl.h | 32 ++++++++++++++++++++++++
>  3 files changed, 95 insertions(+)
> 
> diff --git a/drivers/fwctl/main.c b/drivers/fwctl/main.c
> index d561deaf2b86d8..4b6792f2031e86 100644
> --- a/drivers/fwctl/main.c
> +++ b/drivers/fwctl/main.c
> @@ -27,8 +27,58 @@ struct fwctl_ucmd {
>  	u32 user_size;
>  };
>  
> +static int ucmd_respond(struct fwctl_ucmd *ucmd, size_t cmd_len)
> +{
> +	if (copy_to_user(ucmd->ubuffer, ucmd->cmd,
> +			 min_t(size_t, ucmd->user_size, cmd_len)))
> +		return -EFAULT;
> +	return 0;
> +}
> +
> +static int copy_to_user_zero_pad(void __user *to, const void *from,
> +				 size_t from_len, size_t user_len)
> +{
> +	size_t copy_len;
> +
> +	copy_len = min(from_len, user_len);
> +	if (copy_to_user(to, from, copy_len))
> +		return -EFAULT;
> +	if (copy_len < user_len) {
> +		if (clear_user(to + copy_len, user_len - copy_len))
> +			return -EFAULT;
> +	}
> +	return 0;
> +}
> +
> +static int fwctl_cmd_info(struct fwctl_ucmd *ucmd)
> +{
> +	struct fwctl_device *fwctl = ucmd->uctx->fwctl;
> +	struct fwctl_info *cmd = ucmd->cmd;
> +	size_t driver_info_len = 0;
> +
> +	if (cmd->flags)
> +		return -EOPNOTSUPP;
> +
> +	if (cmd->device_data_len) {
> +		void *driver_info __free(kfree) =
> +			fwctl->ops->info(ucmd->uctx, &driver_info_len);
> +		if (IS_ERR(driver_info))
> +			return PTR_ERR(driver_info);
> +
> +		if (copy_to_user_zero_pad(u64_to_user_ptr(cmd->out_device_data),
> +					  driver_info, driver_info_len,
> +					  cmd->device_data_len))
> +			return -EFAULT;
> +	}
> +
> +	cmd->out_device_type = fwctl->ops->device_type;
> +	cmd->device_data_len = driver_info_len;
> +	return ucmd_respond(ucmd, sizeof(*cmd));
> +}
> +
>  /* On stack memory for the ioctl structs */
>  union ucmd_buffer {
> +	struct fwctl_info info;
>  };
>  
>  struct fwctl_ioctl_op {
> @@ -48,6 +98,7 @@ struct fwctl_ioctl_op {
>  		.execute = _fn,                                       \
>  	}
>  static const struct fwctl_ioctl_op fwctl_ioctl_ops[] = {
> +	IOCTL_OP(FWCTL_INFO, fwctl_cmd_info, struct fwctl_info, out_device_data),
>  };
>  
>  static long fwctl_fops_ioctl(struct file *filp, unsigned int cmd,
> diff --git a/include/linux/fwctl.h b/include/linux/fwctl.h
> index 93b470efb9dbc3..9b6cc8ae1aa0ca 100644
> --- a/include/linux/fwctl.h
> +++ b/include/linux/fwctl.h
> @@ -7,6 +7,7 @@
>  #include <linux/device.h>
>  #include <linux/cdev.h>
>  #include <linux/cleanup.h>
> +#include <uapi/fwctl/fwctl.h>
>  
>  struct fwctl_device;
>  struct fwctl_uctx;
> @@ -19,6 +20,10 @@ struct fwctl_uctx;
>   * it will block device hot unplug and module unloading.
>   */
>  struct fwctl_ops {
> +	/**
> +	 * @device_type: The drivers assigned device_type number. This is uABI.
> +	 */
> +	enum fwctl_device_type device_type;
>  	/**
>  	 * @uctx_size: The size of the fwctl_uctx struct to allocate. The first
>  	 * bytes of this memory will be a fwctl_uctx. The driver can use the
> @@ -35,6 +40,13 @@ struct fwctl_ops {
>  	 * is closed.
>  	 */
>  	void (*close_uctx)(struct fwctl_uctx *uctx);
> +	/**
> +	 * @info: Implement FWCTL_INFO. Return a kmalloc() memory that is copied
> +	 * to out_device_data. On input length indicates the size of the user
> +	 * buffer on output it indicates the size of the memory. The driver can
> +	 * ignore length on input, the core code will handle everything.
> +	 */
> +	void *(*info)(struct fwctl_uctx *uctx, size_t *length);
>  };
>  
>  /**
> diff --git a/include/uapi/fwctl/fwctl.h b/include/uapi/fwctl/fwctl.h
> index f4718a6240f281..ac66853200a5a8 100644
> --- a/include/uapi/fwctl/fwctl.h
> +++ b/include/uapi/fwctl/fwctl.h
> @@ -4,6 +4,9 @@
>  #ifndef _UAPI_FWCTL_H
>  #define _UAPI_FWCTL_H
>  
> +#include <linux/types.h>
> +#include <linux/ioctl.h>
> +
>  #define FWCTL_TYPE 0x9A
>  
>  /**
> @@ -33,6 +36,35 @@
>   */
>  enum {
>  	FWCTL_CMD_BASE = 0,
> +	FWCTL_CMD_INFO = 0,
> +	FWCTL_CMD_RPC = 1,
>  };
>  
> +enum fwctl_device_type {
> +	FWCTL_DEVICE_TYPE_ERROR = 0,
> +};
> +
> +/**
> + * struct fwctl_info - ioctl(FWCTL_INFO)
> + * @size: sizeof(struct fwctl_info)
> + * @flags: Must be 0
> + * @out_device_type: Returns the type of the device from enum fwctl_device_type
> + * @device_data_len: On input the length of the out_device_data memory. On
> + *	output the size of the kernel's device_data which may be larger or
> + *	smaller than the input. Maybe 0 on input.
> + * @out_device_data: Pointer to a memory of device_data_len bytes. Kernel will
> + *	fill the entire memory, zeroing as required.
> + *
> + * Returns basic information about this fwctl instance, particularly what driver
> + * is being used to define the device_data format.
> + */
> +struct fwctl_info {
> +	__u32 size;
> +	__u32 flags;
> +	__u32 out_device_type;
> +	__u32 device_data_len;
> +	__aligned_u64 out_device_data;
> +};
> +#define FWCTL_INFO _IO(FWCTL_TYPE, FWCTL_CMD_INFO)
> +
>  #endif


  parent reply	other threads:[~2025-02-08  0:21 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-07  0:13 [PATCH v4 00/10] Introduce fwctl subystem Jason Gunthorpe
2025-02-07  0:13 ` [PATCH v4 01/10] fwctl: Add basic structure for a class subsystem with a cdev Jason Gunthorpe
2025-02-07 23:32   ` Dan Williams
2025-02-07 23:55     ` Jason Gunthorpe
2025-02-08  0:08   ` Dave Jiang
2025-02-07  0:13 ` [PATCH v4 02/10] fwctl: Basic ioctl dispatch for the character device Jason Gunthorpe
2025-02-07 12:59   ` Jonathan Cameron
2025-02-07 13:52     ` Jason Gunthorpe
2025-02-08  0:16   ` Dave Jiang
2025-02-10 15:24     ` Jason Gunthorpe
2025-02-13 12:42   ` Przemek Kitszel
2025-02-13 18:52     ` Jason Gunthorpe
2025-02-07  0:13 ` [PATCH v4 03/10] fwctl: FWCTL_INFO to return basic information about the device Jason Gunthorpe
2025-02-07 13:06   ` Jonathan Cameron
2025-02-07 14:23     ` Jason Gunthorpe
2025-02-08  0:21   ` Dave Jiang [this message]
2025-02-07  0:13 ` [PATCH v4 04/10] taint: Add TAINT_FWCTL Jason Gunthorpe
2025-02-07 13:09   ` Jonathan Cameron
2025-02-08  0:24   ` Dave Jiang
2025-02-07  0:13 ` [PATCH v4 05/10] fwctl: FWCTL_RPC to execute a Remote Procedure Call to device firmware Jason Gunthorpe
2025-02-08  0:28   ` Dave Jiang
2025-02-07  0:13 ` [PATCH v4 06/10] fwctl: Add documentation Jason Gunthorpe
2025-02-07 14:42   ` Jonathan Cameron
2025-02-10 15:17     ` Jason Gunthorpe
2025-02-08  0:40   ` Dave Jiang
2025-02-07  0:13 ` [PATCH v4 07/10] fwctl/mlx5: Support for communicating with mlx5 fw Jason Gunthorpe
2025-02-13 13:19   ` Przemek Kitszel
2025-02-13 14:25     ` Leon Romanovsky
2025-02-13 19:18     ` Jason Gunthorpe
2025-02-07  0:13 ` [PATCH v4 08/10] mlx5: Create an auxiliary device for fwctl_mlx5 Jason Gunthorpe
2025-02-07  0:13 ` [PATCH v4 09/10] fwctl/bnxt: Support communicating with bnxt fw Jason Gunthorpe
2025-02-07 14:59   ` Jonathan Cameron
2025-02-07 15:03     ` Jason Gunthorpe
2025-02-07  0:13 ` [PATCH v4 10/10] bnxt: Create an auxiliary device for fwctl_bnxt Jason Gunthorpe
2025-02-07  0:44   ` Jakub Kicinski
2025-02-07  3:17     ` Andy Gospodarek
2025-02-07 12:46       ` Jason Gunthorpe
2025-02-07 15:36       ` Jakub Kicinski
2025-02-07 20:25         ` Saeed Mahameed
2025-02-07 21:51           ` Jakub Kicinski
2025-02-08  1:10             ` Saeed Mahameed
2025-02-08  1:16             ` Jason Gunthorpe
2025-02-08  3:24               ` Andy Gospodarek
2025-02-11  1:04               ` Jakub Kicinski
2025-02-11  7:55                 ` Leon Romanovsky
2025-02-11 14:27                   ` Andy Gospodarek
2025-02-12 14:20                     ` Leon Romanovsky
2025-02-11 18:36                   ` Nelson, Shannon
2025-02-12 13:22                     ` Leon Romanovsky
2025-02-14  1:03                       ` Saeed Mahameed
2025-02-17 12:49                         ` Jiri Pirko
2025-02-17 19:02                           ` Leon Romanovsky
2025-02-11 16:24                 ` David Ahern
2025-02-18 20:05                   ` Jason Gunthorpe
2025-02-18 21:42                     ` David Ahern
2025-02-18 23:31                       ` Jakub Kicinski
2025-02-24 22:34                         ` Saeed Mahameed
2025-02-07 23:29         ` Andy Gospodarek
2025-02-08  0:08           ` Jakub Kicinski
2025-02-07 21:41 ` [PATCH v4 00/10] Introduce fwctl subystem Dan Williams
2025-02-07 21:58 ` Dave Jiang
2025-02-11  9:33   ` Jonathan Cameron
2025-02-13 17:55     ` Jason Gunthorpe
2025-02-13 17:52   ` Jason Gunthorpe
2025-02-12 22:21 ` Zhu Yanjun
2025-02-13  2:30 ` Nelson, Shannon
2025-02-13 18:02   ` Jason Gunthorpe

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=761f0f12-417e-400d-b8f1-ccb9c8766c09@intel.com \
    --to=dave.jiang@intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=aron.silverton@oracle.com \
    --cc=dan.j.williams@intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dsahern@kernel.org \
    --cc=gospo@broadcom.com \
    --cc=hch@infradead.org \
    --cc=itayavr@nvidia.com \
    --cc=jgg@nvidia.com \
    --cc=jiri@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=lbloch@nvidia.com \
    --cc=leonro@nvidia.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@nvidia.com \
    --cc=shannon.nelson@amd.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox