Skip to content

Commit 89721e3

Browse files
committed
Merge tag 'net-accept-more-20240515' of git://git.kernel.dk/linux
Pull more io_uring updates from Jens Axboe: "This adds support for IORING_CQE_F_SOCK_NONEMPTY for io_uring accept requests. This is very similar to previous work that enabled the same hint for doing receives on sockets. By far the majority of the work here is refactoring to enable the networking side to pass back whether or not the socket had more pending requests after accepting the current one, the last patch just wires it up for io_uring. Not only does this enable applications to know whether there are more connections to accept right now, it also enables smarter logic for io_uring multishot accept on whether to retry immediately or wait for a poll trigger" * tag 'net-accept-more-20240515' of git://git.kernel.dk/linux: io_uring/net: wire up IORING_CQE_F_SOCK_NONEMPTY for accept net: pass back whether socket was empty post accept net: have do_accept() take a struct proto_accept_arg argument net: change proto and proto_ops accept type
2 parents 4b377b4 + ac287da commit 89721e3

File tree

36 files changed

+156
-120
lines changed

36 files changed

+156
-120
lines changed

crypto/af_alg.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ static int alg_setsockopt(struct socket *sock, int level, int optname,
407407
return err;
408408
}
409409

410-
int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
410+
int af_alg_accept(struct sock *sk, struct socket *newsock,
411+
struct proto_accept_arg *arg)
411412
{
412413
struct alg_sock *ask = alg_sk(sk);
413414
const struct af_alg_type *type;
@@ -422,7 +423,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
422423
if (!type)
423424
goto unlock;
424425

425-
sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, kern);
426+
sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, arg->kern);
426427
err = -ENOMEM;
427428
if (!sk2)
428429
goto unlock;
@@ -468,10 +469,10 @@ int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
468469
}
469470
EXPORT_SYMBOL_GPL(af_alg_accept);
470471

471-
static int alg_accept(struct socket *sock, struct socket *newsock, int flags,
472-
bool kern)
472+
static int alg_accept(struct socket *sock, struct socket *newsock,
473+
struct proto_accept_arg *arg)
473474
{
474-
return af_alg_accept(sock->sk, newsock, kern);
475+
return af_alg_accept(sock->sk, newsock, arg);
475476
}
476477

477478
static const struct proto_ops alg_proto_ops = {

crypto/algif_hash.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
223223
return err ?: len;
224224
}
225225

226-
static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
227-
bool kern)
226+
static int hash_accept(struct socket *sock, struct socket *newsock,
227+
struct proto_accept_arg *arg)
228228
{
229229
struct sock *sk = sock->sk;
230230
struct alg_sock *ask = alg_sk(sk);
@@ -252,7 +252,7 @@ static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
252252
if (err)
253253
goto out_free_state;
254254

255-
err = af_alg_accept(ask->parent, newsock, kern);
255+
err = af_alg_accept(ask->parent, newsock, arg);
256256
if (err)
257257
goto out_free_state;
258258

@@ -355,15 +355,15 @@ static int hash_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
355355
}
356356

357357
static int hash_accept_nokey(struct socket *sock, struct socket *newsock,
358-
int flags, bool kern)
358+
struct proto_accept_arg *arg)
359359
{
360360
int err;
361361

362362
err = hash_check_key(sock);
363363
if (err)
364364
return err;
365365

366-
return hash_accept(sock, newsock, flags, kern);
366+
return hash_accept(sock, newsock, arg);
367367
}
368368

369369
static struct proto_ops algif_hash_ops_nokey = {

drivers/xen/pvcalls-back.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ static void __pvcalls_back_accept(struct work_struct *work)
517517
{
518518
struct sockpass_mapping *mappass = container_of(
519519
work, struct sockpass_mapping, register_work);
520+
struct proto_accept_arg arg = {
521+
.flags = O_NONBLOCK,
522+
.kern = true,
523+
};
520524
struct sock_mapping *map;
521525
struct pvcalls_ioworker *iow;
522526
struct pvcalls_fedata *fedata;
@@ -548,7 +552,7 @@ static void __pvcalls_back_accept(struct work_struct *work)
548552
sock->type = mappass->sock->type;
549553
sock->ops = mappass->sock->ops;
550554

551-
ret = inet_accept(mappass->sock, sock, O_NONBLOCK, true);
555+
ret = inet_accept(mappass->sock, sock, &arg);
552556
if (ret == -EAGAIN) {
553557
sock_release(sock);
554558
return;

fs/ocfs2/cluster/tcp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,9 @@ static int o2net_accept_one(struct socket *sock, int *more)
17841784
struct o2nm_node *node = NULL;
17851785
struct o2nm_node *local_node = NULL;
17861786
struct o2net_sock_container *sc = NULL;
1787+
struct proto_accept_arg arg = {
1788+
.flags = O_NONBLOCK,
1789+
};
17871790
struct o2net_node *nn;
17881791
unsigned int nofs_flag;
17891792

@@ -1802,7 +1805,7 @@ static int o2net_accept_one(struct socket *sock, int *more)
18021805

18031806
new_sock->type = sock->type;
18041807
new_sock->ops = sock->ops;
1805-
ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, false);
1808+
ret = sock->ops->accept(sock, new_sock, &arg);
18061809
if (ret < 0)
18071810
goto out;
18081811

include/crypto/if_alg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ int af_alg_unregister_type(const struct af_alg_type *type);
166166

167167
int af_alg_release(struct socket *sock);
168168
void af_alg_release_parent(struct sock *sk);
169-
int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern);
169+
int af_alg_accept(struct sock *sk, struct socket *newsock,
170+
struct proto_accept_arg *arg);
170171

171172
void af_alg_free_sg(struct af_alg_sgl *sgl);
172173

include/linux/net.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ struct sockaddr;
153153
struct msghdr;
154154
struct module;
155155
struct sk_buff;
156+
struct proto_accept_arg;
156157
typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *,
157158
unsigned int, size_t);
158159
typedef int (*skb_read_actor_t)(struct sock *, struct sk_buff *);
@@ -171,7 +172,8 @@ struct proto_ops {
171172
int (*socketpair)(struct socket *sock1,
172173
struct socket *sock2);
173174
int (*accept) (struct socket *sock,
174-
struct socket *newsock, int flags, bool kern);
175+
struct socket *newsock,
176+
struct proto_accept_arg *arg);
175177
int (*getname) (struct socket *sock,
176178
struct sockaddr *addr,
177179
int peer);

include/linux/socket.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct cred;
1616
struct socket;
1717
struct sock;
1818
struct sk_buff;
19+
struct proto_accept_arg;
1920

2021
#define __sockaddr_check_size(size) \
2122
BUILD_BUG_ON(((size) > sizeof(struct __kernel_sockaddr_storage)))
@@ -433,7 +434,7 @@ extern int __sys_recvfrom(int fd, void __user *ubuf, size_t size,
433434
extern int __sys_sendto(int fd, void __user *buff, size_t len,
434435
unsigned int flags, struct sockaddr __user *addr,
435436
int addr_len);
436-
extern struct file *do_accept(struct file *file, unsigned file_flags,
437+
extern struct file *do_accept(struct file *file, struct proto_accept_arg *arg,
437438
struct sockaddr __user *upeer_sockaddr,
438439
int __user *upeer_addrlen, int flags);
439440
extern int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,

include/net/inet_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ int __inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
2929
int addr_len, int flags, int is_sendmsg);
3030
int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
3131
int addr_len, int flags);
32-
int inet_accept(struct socket *sock, struct socket *newsock, int flags,
33-
bool kern);
32+
int inet_accept(struct socket *sock, struct socket *newsock,
33+
struct proto_accept_arg *arg);
3434
void __inet_accept(struct socket *sock, struct socket *newsock,
3535
struct sock *newsk);
3636
int inet_send_prepare(struct sock *sk);

include/net/inet_connection_sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ inet_csk_rto_backoff(const struct inet_connection_sock *icsk,
250250
return (unsigned long)min_t(u64, when, max_when);
251251
}
252252

253-
struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern);
253+
struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg);
254254

255255
int inet_csk_get_port(struct sock *sk, unsigned short snum);
256256

include/net/sock.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,13 @@ static inline void sk_prot_clear_nulls(struct sock *sk, int size)
11941194
size - offsetof(struct sock, sk_node.pprev));
11951195
}
11961196

1197+
struct proto_accept_arg {
1198+
int flags;
1199+
int err;
1200+
int is_empty;
1201+
bool kern;
1202+
};
1203+
11971204
/* Networking protocol blocks we attach to sockets.
11981205
* socket layer -> transport layer interface
11991206
*/
@@ -1208,8 +1215,8 @@ struct proto {
12081215
int addr_len);
12091216
int (*disconnect)(struct sock *sk, int flags);
12101217

1211-
struct sock * (*accept)(struct sock *sk, int flags, int *err,
1212-
bool kern);
1218+
struct sock * (*accept)(struct sock *sk,
1219+
struct proto_accept_arg *arg);
12131220

12141221
int (*ioctl)(struct sock *sk, int cmd,
12151222
int *karg);
@@ -1804,7 +1811,7 @@ int sock_cmsg_send(struct sock *sk, struct msghdr *msg,
18041811
int sock_no_bind(struct socket *, struct sockaddr *, int);
18051812
int sock_no_connect(struct socket *, struct sockaddr *, int, int);
18061813
int sock_no_socketpair(struct socket *, struct socket *);
1807-
int sock_no_accept(struct socket *, struct socket *, int, bool);
1814+
int sock_no_accept(struct socket *, struct socket *, struct proto_accept_arg *);
18081815
int sock_no_getname(struct socket *, struct sockaddr *, int);
18091816
int sock_no_ioctl(struct socket *, unsigned int, unsigned long);
18101817
int sock_no_listen(struct socket *, int);

0 commit comments

Comments
 (0)