Re: [PATCH 1/1] usb: gadget: f_fs: Support zerocopy transfers via mmap.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 18, 2022 at 08:08:49PM +0100, Ingo Rohloff wrote:
> This patch implements the same functionality for USB Gadget FunctionFS as
> commit f7d34b445abc00e979b7 ("USB: Add support for usbfs zerocopy.")
> did for USB host devio.c
> 
> This patch allows user space to mmap USB transfer buffers via
> USB FunctionFS endpoint 0.
> 
> User space might then use these buffers in conjunction with
> Linux native AsyncIO (via libaio) to avoid data copying by the kernel.
> 
> Standard read() and write() operations to bulk USB endpoints will NOT be
> zerocopy.  Especially for reads, the expected USB transfer length is
> unclear; whereas an AsyncIO request clearly specifies the maximum transfer
> length.
> 
> Signed-off-by: Ingo Rohloff <ingo.rohloff@xxxxxxxxxxxxxx>
> ---
>  drivers/usb/gadget/function/f_fs.c | 230 ++++++++++++++++++++++++++++-
>  1 file changed, 226 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 25ad1e97a458..a8fac065b9b4 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -201,6 +201,16 @@ struct ffs_epfile {
>  	unsigned char			_pad;
>  };
>  
> +struct ffs_memory {
> +	struct list_head memlist;
> +	char *kmem;
> +	unsigned long vm_start;
> +	u32 size;
> +
> +	int vma_use_count;
> +	int aio_use_count;
> +};
> +
>  struct ffs_buffer {
>  	size_t length;
>  	char *data;
> @@ -227,6 +237,7 @@ struct ffs_io_data {
>  	bool use_sg;
>  
>  	struct ffs_data *ffs;
> +	struct ffs_memory *ffsm;
>  };
>  
>  struct ffs_desc_helper {
> @@ -262,6 +273,135 @@ static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
>  static char *ffs_prepare_buffer(const char __user *buf, size_t len)
>  	__attribute__((warn_unused_result, nonnull));
>  
> +/* Handling of mmapped transfers *******************************/
> +
> +static LIST_HEAD(ffsm_list);
> +static DEFINE_SPINLOCK(ffsm_lock);
> +
> +/* Limit on the total amount of memory ffs can allocate via mmap */
> +static u32 ffsm_memory_mb = 16;
> +module_param(ffsm_memory_mb, uint, 0644);
> +MODULE_PARM_DESC(ffsm_memory_mb,
> +		"maximum MB allowed for ffs mmap buffers (0 = no limit)");

No, sorry, this is not the 1990's, we can not add new module parameters
for stuff like this.  The code should "just work" without needing to be
tuned.

thanks,

greg k-h



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux