Skip to content

Commit

Permalink
kcm: Use splice_eof() to flush
Browse files Browse the repository at this point in the history
Allow splice to undo the effects of MSG_MORE after prematurely ending a
splice/sendfile due to getting an EOF condition (->splice_read() returned
0) after splice had called sendmsg() with MSG_MORE set when the user didn't
set MSG_MORE.

Suggested-by: Linus Torvalds <[email protected]>
Link: https://lore.kernel.org/r/CAHk-=wh=V579PDYvkpnTobCLGczbgxpMgGmmhqiTyE34Cpi5Gg@mail.gmail.com/
Signed-off-by: David Howells <[email protected]>
cc: Tom Herbert <[email protected]>
cc: Tom Herbert <[email protected]>
cc: Cong Wang <[email protected]>
cc: Jens Axboe <[email protected]>
cc: Matthew Wilcox <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
dhowells authored and kuba-moo committed Jun 9, 2023
1 parent c289a16 commit 951ace9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions net/kcm/kcmsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,19 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
return err;
}

static void kcm_splice_eof(struct socket *sock)
{
struct sock *sk = sock->sk;
struct kcm_sock *kcm = kcm_sk(sk);

if (skb_queue_empty_lockless(&sk->sk_write_queue))
return;

lock_sock(sk);
kcm_write_msgs(kcm);
release_sock(sk);
}

static ssize_t kcm_sendpage(struct socket *sock, struct page *page,
int offset, size_t size, int flags)

Expand Down Expand Up @@ -1773,6 +1786,7 @@ static const struct proto_ops kcm_dgram_ops = {
.sendmsg = kcm_sendmsg,
.recvmsg = kcm_recvmsg,
.mmap = sock_no_mmap,
.splice_eof = kcm_splice_eof,
.sendpage = kcm_sendpage,
};

Expand All @@ -1794,6 +1808,7 @@ static const struct proto_ops kcm_seqpacket_ops = {
.sendmsg = kcm_sendmsg,
.recvmsg = kcm_recvmsg,
.mmap = sock_no_mmap,
.splice_eof = kcm_splice_eof,
.sendpage = kcm_sendpage,
.splice_read = kcm_splice_read,
};
Expand Down

0 comments on commit 951ace9

Please sign in to comment.