From patchwork Wed Jun 7 18:19:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13271094 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 7BB34C7EE23 for ; Wed, 7 Jun 2023 18:20:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12C07900007; Wed, 7 Jun 2023 14:20:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B60D900004; Wed, 7 Jun 2023 14:20:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7364900007; Wed, 7 Jun 2023 14:20:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D04FD900004 for ; Wed, 7 Jun 2023 14:20:19 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 80D711C79A4 for ; Wed, 7 Jun 2023 18:20:19 +0000 (UTC) X-FDA: 80876766558.15.DD3BABD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id B8DD51C0013 for ; Wed, 7 Jun 2023 18:20:17 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IyQ7cMcy; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1686162017; 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=Xw9eDWXEwpwNsn0HYqixkrc65IaqtCUycHScIiVECUM=; b=zWEo2JEj3xIRu9h6ANiHUzrKTJopEkhlwTvx6TqoRDW2mbtrXOvR8soK5k3wFklH5alGJh RP/eqAMXupABt3pfxARrEPjdby1Ms+srH9pd/incfxr/AmtPSCSQX/URD1H6LSrqmF3vE2 26XZq/pVcM78Ovvh9fYy/F7d7feacTM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686162017; a=rsa-sha256; cv=none; b=ujq0+v9ptrswqa27K1iwf6nN4JYdaYHaOJfsrl13naiAeSs3mYetlNVlS7B2ysqK3URLrO xk0f7DMCU1dwdDJJogsgA+Bc6AISjYWyZB7ad4NLT4uF3Vy3vV525rzmEJYTwngIgRr7jW sJh2PsSf+ZYdDVOrIdIeF/lkICUr/GE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IyQ7cMcy; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686162016; 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=Xw9eDWXEwpwNsn0HYqixkrc65IaqtCUycHScIiVECUM=; b=IyQ7cMcyGOgiTco7GHXmd96vHiCp/2cONToNf6xX7l1hqo3pvZDK5/zYteEfC8ew6y6Ma+ pqZWpsoAyVUmY5DIGFTkQQO6hSa13jZ11oSwZNAd/SqfXgM2otgeEMvpCSqwsWPS4G1tA9 PMDAC9Fv274z3l+1OJOYxDOaVOkhNK8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-YaAi_LsyPgCqEao-0jof3A-1; Wed, 07 Jun 2023 14:20:13 -0400 X-MC-Unique: YaAi_LsyPgCqEao-0jof3A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DA1683806704; Wed, 7 Jun 2023 18:20:12 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9CA2403176; Wed, 7 Jun 2023 18:20:10 +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 v6 09/14] kcm: Use splice_eof() to flush Date: Wed, 7 Jun 2023 19:19:15 +0100 Message-ID: <20230607181920.2294972-10-dhowells@redhat.com> In-Reply-To: <20230607181920.2294972-1-dhowells@redhat.com> References: <20230607181920.2294972-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: B8DD51C0013 X-Rspam-User: X-Stat-Signature: 1j1r45xc4t3oatdyiqg4am33hhiy73q1 X-Rspamd-Server: rspam03 X-HE-Tag: 1686162017-557462 X-HE-Meta: U2FsdGVkX1+s702g4QZz6pslk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w9fc1BR8vnzTqkpl1MqTq3NTQtCOQdmbPk16sLKqJFf43zgUWL/KmTHl1n8BCOnBJvQh8blSgh0byxs5gynk0HGeJ+jQTDUDLtMEk5RrAsDJ+1MAfkYSeYtyQj7pktmKObch15z7HaKp3ltf0mP7+Y43VfZaI2kvlAbPmb3tQCRXBBJUVlPfIEm6hN47fJMJD6NomokjblefbwQgyg2Z9Y1tVWx+i6VWKbj3bo0Q63xYeXLQFwbncM2aJ4EVbk/3sbDe2b0Oi4TnXuODig+U85mQxzDBfUTmfAeOuFCqM2iofyDFEUD2JhHaYuZsFqfG102j456gPfmOmNhTaty+AkLOTqMqPrKR18/cw5SJPl50/J2vYanfhhSwEl36vEm927lPtobG2AHbf5/XpWizHs2e9jA0Vk4zSWvgCZ1CheHhQ3w/Nwr2cipKyoQdNbGbIRfyU2vO8GC3qWzJkUfuEcyZpOsNYH2PwcOD7Elm1IsH4mkjVR+doVrGHGDk/CTXvOjWtJE34Ga9aW3cauNE/oAMQCRlY7zrJNMOsxK9andM2dXYEOeGheMsJabbl3sr8FA6MKHqhUXIRMLUxUVwNHvI/yePHYq0HR5CgOImVaiw+qyxd812RAzvA89RSwTfKGPC5w== 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 --- Notes: ver #6) - In kcm_splice_eof(), use skb_queue_empty_lockless(). net/kcm/kcmsock.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index ba22af16b96d..7dee74430b59 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_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) @@ -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, };