diff mbox series

For 5.20 or 5.19? net: wire up support for file_operations->uring_cmd()

Message ID bd2ad505-4d1c-ff13-de87-b4b3d397e159@samba.org (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series For 5.20 or 5.19? net: wire up support for file_operations->uring_cmd() | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply, async

Commit Message

Stefan Metzmacher June 28, 2022, 7:09 p.m. UTC
Hi Jens,

I'm wondering what happened to you patch passing file_ops->uring_cmd()
down to socket layers.

It was part of you work in progress branches...

The latest one I found was this:
https://git.kernel.dk/cgit/linux-block/commit/?h=nvme-passthru-wip.2&id=28b71b85831f5dd303acae12cfdc89e5aaae442b

And this one just having the generic parts were in a separate commit
https://git.kernel.dk/cgit/linux-block/commit/?h=io_uring-fops.v7&id=c2ba3bd8940ef0b7d1c09adf4bed01acc8171407
vs.
https://git.kernel.dk/cgit/linux-block/commit/?h=io_uring-fops.v7&id=542c38da58841097f97f710d1f05055c2f1039f0

I took this:
https://git.kernel.dk/cgit/linux-block/commit/?h=io_uring-fops.v7&id=c2ba3bd8940ef0b7d1c09adf4bed01acc8171407
adapted it on top of v5.19-rc4 and removed stuff that was not really needed.

Even if it's not used in tree, it would be good to have uring_cmd hooks in
struct proto_ops and struct proto, so that out of tree socket implementations
like my smbdirect driver are able to hook into it.

What do you think?

https://git.samba.org/?p=metze/linux/wip.git;a=commitdiff;h=7541d40a482a9f57d580ac05254c5a5982edff15

 From 7541d40a482a9f57d580ac05254c5a5982edff15 Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Fri, 18 Dec 2020 15:12:46 -0700
Subject: [PATCH] net: wire up support for file_operations->uring_cmd()

Pass it through the proto_ops->uring_cmd() handler, so we can plumb it
through all the way to the proto->uring_cmd() handler later
as required.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
  include/linux/net.h |  4 ++++
  include/net/sock.h  |  7 +++++++
  net/core/sock.c     | 12 ++++++++++++
  net/socket.c        | 13 +++++++++++++
  4 files changed, 36 insertions(+)

Comments

Jens Axboe June 28, 2022, 7:26 p.m. UTC | #1
On 6/28/22 1:09 PM, Stefan Metzmacher wrote:
> Hi Jens,
> 
> I'm wondering what happened to you patch passing file_ops->uring_cmd()
> down to socket layers.
> 
> It was part of you work in progress branches...
> 
> The latest one I found was this:
> https://git.kernel.dk/cgit/linux-block/commit/?h=nvme-passthru-wip.2&id=28b71b85831f5dd303acae12cfdc89e5aaae442b
> 
> And this one just having the generic parts were in a separate commit
> https://git.kernel.dk/cgit/linux-block/commit/?h=io_uring-fops.v7&id=c2ba3bd8940ef0b7d1c09adf4bed01acc8171407
> vs.
> https://git.kernel.dk/cgit/linux-block/commit/?h=io_uring-fops.v7&id=542c38da58841097f97f710d1f05055c2f1039f0
> 
> I took this:
> https://git.kernel.dk/cgit/linux-block/commit/?h=io_uring-fops.v7&id=c2ba3bd8940ef0b7d1c09adf4bed01acc8171407
> adapted it on top of v5.19-rc4 and removed stuff that was not really needed.
> 
> Even if it's not used in tree, it would be good to have uring_cmd hooks in
> struct proto_ops and struct proto, so that out of tree socket implementations
> like my smbdirect driver are able to hook into it.
> 
> What do you think?

We need to just finalize a format for this, don't think it'll be too
complicated. But for in-kernel users first and foremost, not for some
out of tree code! I've got various things I'd like to use it for
internally too. For example, returning number of bytes left in a socket
post receive rather than just a flag telling you there's more data.
diff mbox series

Patch

diff --git a/include/linux/net.h b/include/linux/net.h
index 12093f4db50c..59d37aade979 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -31,6 +31,7 @@  struct pipe_inode_info;
  struct inode;
  struct file;
  struct net;
+struct io_uring_cmd;

  /* Historically, SOCKWQ_ASYNC_NOSPACE & SOCKWQ_ASYNC_WAITDATA were located
   * in sock->flags, but moved into sk->sk_wq->flags to be RCU protected.
@@ -178,6 +179,9 @@  struct proto_ops {
  	int	 	(*compat_ioctl) (struct socket *sock, unsigned int cmd,
  				      unsigned long arg);
  #endif
+	int		(*uring_cmd)(struct socket *sock,
+				     struct io_uring_cmd *ioucmd,
+				     unsigned issue_flags);
  	int		(*gettstamp) (struct socket *sock, void __user *userstamp,
  				      bool timeval, bool time32);
  	int		(*listen)    (struct socket *sock, int len);
diff --git a/include/net/sock.h b/include/net/sock.h
index 72ca97ccb460..80fd3f45cd09 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -111,6 +111,7 @@  typedef struct {
  struct sock;
  struct proto;
  struct net;
+struct io_uring_cmd;

  typedef __u32 __bitwise __portpair;
  typedef __u64 __bitwise __addrpair;
@@ -1181,6 +1182,9 @@  struct proto {

  	int			(*ioctl)(struct sock *sk, int cmd,
  					 unsigned long arg);
+	int			(*uring_cmd)(struct sock *sk,
+					struct io_uring_cmd *ioucmd,
+					unsigned int issue_flags);
  	int			(*init)(struct sock *sk);
  	void			(*destroy)(struct sock *sk);
  	void			(*shutdown)(struct sock *sk, int how);
@@ -1886,6 +1890,9 @@  int sock_common_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
  int sock_common_setsockopt(struct socket *sock, int level, int optname,
  			   sockptr_t optval, unsigned int optlen);

+int sock_common_uring_cmd(struct socket *sock, struct io_uring_cmd *ioucmd,
+			  unsigned int issue_flags);
+
  void sk_common_release(struct sock *sk);

  /*
diff --git a/net/core/sock.c b/net/core/sock.c
index 2ff40dd0a7a6..42b3def01a5f 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3582,6 +3582,18 @@  int sock_common_setsockopt(struct socket *sock, int level, int optname,
  }
  EXPORT_SYMBOL(sock_common_setsockopt);

+int sock_common_uring_cmd(struct socket *sock, struct io_uring_cmd *ioucmd,
+			  unsigned int issue_flags)
+{
+	struct sock *sk = sock->sk;
+
+	if (!sk->sk_prot->uring_cmd)
+		return -EOPNOTSUPP;
+
+	return sk->sk_prot->uring_cmd(sk, ioucmd, issue_flags);
+}
+EXPORT_SYMBOL(sock_common_uring_cmd);
+
  void sk_common_release(struct sock *sk)
  {
  	if (sk->sk_prot->destroy)
diff --git a/net/socket.c b/net/socket.c
index 2bc8773d9dc5..67701c685921 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -87,6 +87,7 @@ 
  #include <linux/xattr.h>
  #include <linux/nospec.h>
  #include <linux/indirect_call_wrapper.h>
+#include <linux/io_uring.h>

  #include <linux/uaccess.h>
  #include <asm/unistd.h>
@@ -115,6 +116,7 @@  unsigned int sysctl_net_busy_poll __read_mostly;
  static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to);
  static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from);
  static int sock_mmap(struct file *file, struct vm_area_struct *vma);
+static int sock_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags);

  static int sock_close(struct inode *inode, struct file *file);
  static __poll_t sock_poll(struct file *file,
@@ -158,6 +160,7 @@  static const struct file_operations socket_file_ops = {
  #ifdef CONFIG_COMPAT
  	.compat_ioctl = compat_sock_ioctl,
  #endif
+	.uring_cmd =	sock_uring_cmd,
  	.mmap =		sock_mmap,
  	.release =	sock_close,
  	.fasync =	sock_fasync,
@@ -1289,6 +1292,16 @@  static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
  	return err;
  }

+static int sock_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags)
+{
+	struct socket *sock = ioucmd->file->private_data;
+
+	if (!sock->ops->uring_cmd)
+		return -EOPNOTSUPP;
+
+	return sock->ops->uring_cmd(sock, ioucmd, issue_flags);
+}
+
  /**
   *	sock_create_lite - creates a socket
   *	@family: protocol family (AF_INET, ...)