On Wed, May 29, 2024 at 08:00:43PM +0200, Bernd Schubert wrote: > Signed-off-by: Bernd Schubert <bschubert@xxxxxxx> > --- > fs/fuse/dev.c | 10 +++++ > fs/fuse/dev_uring.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++ > fs/fuse/dev_uring_i.h | 18 +++++++++ > fs/fuse/fuse_i.h | 3 ++ > include/uapi/linux/fuse.h | 26 +++++++++++++ > 5 files changed, 152 insertions(+) > > diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c > index 349c1d16b0df..78c05516da7f 100644 > --- a/fs/fuse/dev.c > +++ b/fs/fuse/dev.c > @@ -2395,6 +2395,12 @@ static long fuse_uring_ioctl(struct file *file, __u32 __user *argp) > if (res != 0) > return -EFAULT; > > + if (cfg.cmd == FUSE_URING_IOCTL_CMD_QUEUE_CFG) { > + res = _fuse_dev_ioctl_clone(file, cfg.qconf.control_fd); > + if (res != 0) > + return res; > + } > + > fud = fuse_get_dev(file); > if (fud == NULL) > return -ENODEV; > @@ -2424,6 +2430,10 @@ static long fuse_uring_ioctl(struct file *file, __u32 __user *argp) > if (res != 0) > return res; > break; > + case FUSE_URING_IOCTL_CMD_QUEUE_CFG: > + fud->uring_dev = 1; > + res = fuse_uring_queue_cfg(fc->ring, &cfg.qconf); > + break; > default: > res = -EINVAL; > } > diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c > index 9491bdaa5716..2c0ccb378908 100644 > --- a/fs/fuse/dev_uring.c > +++ b/fs/fuse/dev_uring.c > @@ -144,6 +144,39 @@ static char *fuse_uring_alloc_queue_buf(int size, int node) > return buf ? buf : ERR_PTR(-ENOMEM); > } > > +/* > + * mmaped allocated buffers, but does not know which queue that is for > + * This ioctl uses the userspace address as key to identify the kernel address > + * and assign it to the kernel side of the queue. > + */ > +static int fuse_uring_ioctl_mem_reg(struct fuse_ring *ring, > + struct fuse_ring_queue *queue, > + uint64_t uaddr) > +{ > + struct rb_node *node; > + struct fuse_uring_mbuf *entry; > + int tag; > + > + node = rb_find((const void *)uaddr, &ring->mem_buf_map, > + fuse_uring_rb_tree_buf_cmp); > + if (!node) > + return -ENOENT; > + entry = rb_entry(node, struct fuse_uring_mbuf, rb_node); > + > + rb_erase(node, &ring->mem_buf_map); > + > + queue->queue_req_buf = entry->kbuf; > + > + for (tag = 0; tag < ring->queue_depth; tag++) { > + struct fuse_ring_ent *ent = &queue->ring_ent[tag]; > + > + ent->rreq = entry->kbuf + tag * ring->req_buf_sz; > + } > + > + kfree(node); > + return 0; > +} > + > /** > * fuse uring mmap, per ring qeuue. > * Userpsace maps a kernel allocated ring/queue buffer. For numa awareness, > @@ -234,3 +267,65 @@ fuse_uring_mmap(struct file *filp, struct vm_area_struct *vma) > > return ret; > } > + > +int fuse_uring_queue_cfg(struct fuse_ring *ring, > + struct fuse_ring_queue_config *qcfg) > +{ > + int tag; > + struct fuse_ring_queue *queue; > + > + if (qcfg->qid >= ring->nr_queues) { > + pr_info("fuse ring queue config: qid=%u >= nr-queues=%zu\n", > + qcfg->qid, ring->nr_queues); > + return -EINVAL; > + } > + queue = fuse_uring_get_queue(ring, qcfg->qid); > + > + if (queue->configured) { > + pr_info("fuse ring qid=%u already configured!\n", queue->qid); > + return -EALREADY; > + } > + > + mutex_lock(&ring->start_stop_lock); > + fuse_uring_ioctl_mem_reg(ring, queue, qcfg->uaddr); > + mutex_unlock(&ring->start_stop_lock); You're not handling the error here. Thanks, Josef