From patchwork Wed Jun 7 14:05:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13270818 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DCC0C77B7A for ; Wed, 7 Jun 2023 14:53:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12A6A900003; Wed, 7 Jun 2023 10:53:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DA4D8E0001; Wed, 7 Jun 2023 10:53:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC8BB900003; Wed, 7 Jun 2023 10:53:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DA78A8E0001 for ; Wed, 7 Jun 2023 10:53:13 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9D9251602C1 for ; Wed, 7 Jun 2023 14:53:13 +0000 (UTC) X-FDA: 80876244666.03.440D47F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 603A91A000B for ; Wed, 7 Jun 2023 14:53:10 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MYHBhwG4; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686149590; a=rsa-sha256; cv=none; b=SE45imA1mwbKsTLlGLjQtO7eT5UFIY7lW+mggEOhcFKyJIDwXXdg95dLgA2MW0PCrTOVFN W77ffNeuQQvwG03LmZ24CxnqTAJmBKcTDmm2mmHT5JddIyBupBK/jCOUPUjp+P7vnLnd9l nzNFugX21TYLF+TxjUPIfVMLXuRPodM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MYHBhwG4; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686149590; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YYh07r9nLp9Gj3Ft6ZNJdfT/+HiAyQEDDAL/yG5YQDg=; b=xrKmh6kSX+1JRFM+oEJ5LwPhQvrY8Bzpooz2Zr6YGUC2PltdbXMcGOOKxTlZ4F/RWHgERx sejVv8b6KyxCV2wNUqFWo9kAOTGQTzlqCouYTttChAi5sJWnWk3zKdbM3UBkBr6yVlXW+6 96QTu3I09bRsL47nvVXHxuW6p+/qAhw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686149589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YYh07r9nLp9Gj3Ft6ZNJdfT/+HiAyQEDDAL/yG5YQDg=; b=MYHBhwG4k7TLciovXSdWPVX8JSNXAWL6z45gWnPJRAignTATPxNXhMWEgfRAYCKk9DfEKV ZoT9x2RrwMW5uo7EAJW9jY36qBgGy9M+01iHuNc8F02IBKb1Rg0uKA07Pxnqo1+pFZi0PD QaemOT++0HZg8w9ZVqfEeCFkp6qq7uw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-134-blPYcdEnN0m5yZ91Tl7iqQ-1; Wed, 07 Jun 2023 10:06:44 -0400 X-MC-Unique: blPYcdEnN0m5yZ91Tl7iqQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E47528028B1; Wed, 7 Jun 2023 14:06:42 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id C031E4021AA; Wed, 7 Jun 2023 14:06:39 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org, Linus Torvalds Cc: David Howells , Chuck Lever , Boris Pismenny , John Fastabend , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tom Herbert , Tom Herbert , Cong Wang Subject: [PATCH net-next v5 09/14] kcm: Use splice_eof() to flush Date: Wed, 7 Jun 2023 15:05:54 +0100 Message-ID: <20230607140559.2263470-10-dhowells@redhat.com> In-Reply-To: <20230607140559.2263470-1-dhowells@redhat.com> References: <20230607140559.2263470-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 603A91A000B X-Stat-Signature: s65ftddn1i6673uio1dack85bau5jjq4 X-Rspam-User: X-HE-Tag: 1686149590-554026 X-HE-Meta: U2FsdGV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Po3B3TkXX2FkPV19hgJ4S/cMnzD9RnIGXi5OQ0RGsAAT/r2z/L7xQEfjdSz0iUbiaxvogSyNqokLe++Vf4gtLPV95XvxIFQT6qCzSJCDPGaIuzi5ocGR7RLIkcFWXuOVmnS2oF/ZaG9/Vq+fzbjguwmbAIJrFsQfUTZVNsa+uwPWx8MwV/SDYEsmK8uyv7Jnugn3MQeEGJgr6qL0mFgmoMzKHHdv5HFu92X5DGUgmVQNEZxA72K8rYLvgfEUPMhS2eDrSkmV1q2/2udh4ZxXEi0EUP/gnRzukzYPpTpEuHYE+Pac9qKE0urlvHLJ87lwizFQX0Uy6kAEEj5nIUXr0Q9JyjKy3rnJMmWPVBhjCjkgfQIxxQ/mKRujIYmVcgKgiJOM+nbJnkRxMwCDhlG3y075hRaxPBIZiqICClk9UDETrOl7sNa/m2Rh9Dnfe1M/4bg+oFvrO+Ydqy1lQShP/brDdt55rqpe1kbsFeh+8h8fbcE9MAKA59yZvfEuG8Uq1Es19L44PiRvbyrG7Bbbx4+RPEEdGHVBh+a2LJuoGhk4oFz92h+Jj9zgFIv11aBDt16wlA1wulNvpRJiwp9yCkw5P31nYxo/bBDXMgy3TJcfG1p2JP7o2WRj4TKSc0jwzRvavoBcTg1Rs7+sd/68WFPw8A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Link: https://lore.kernel.org/r/CAHk-=wh=V579PDYvkpnTobCLGczbgxpMgGmmhqiTyE34Cpi5Gg@mail.gmail.com/ Signed-off-by: David Howells cc: Tom Herbert cc: Tom Herbert cc: Cong Wang cc: Jakub Kicinski cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- net/kcm/kcmsock.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index ba22af16b96d..d0d8c54562d6 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -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(&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) @@ -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, }; @@ -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, };