Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1143639rwd; Wed, 7 Jun 2023 11:37:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5LFPDFGsXnyrSqq5MVO9StyyEzKbVKuNS0of5rGKJOriQYX26BGB9VxUORHofv1acuLTxf X-Received: by 2002:a05:6a00:24ca:b0:649:450f:3231 with SMTP id d10-20020a056a0024ca00b00649450f3231mr3199397pfv.9.1686163068949; Wed, 07 Jun 2023 11:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686163068; cv=none; d=google.com; s=arc-20160816; b=IQlNYKp2PX+UOCjfRXVeDhpYCJzR8ihpenK7MlMtxTQulYDmw6VzpCqdaVedy8ghwb uQkJg//bcyz9ECshHdk5TTZRA+D9BqUnXTvcIV6kzbLDi+nHrkjrRJUj+XxFuCglevVF U6nQDv5GTl9J58y3be6kspt3XUm60ZohXOhaP8dGM2NpfBxSv2OxcD2+rL6HTrzIo458 A+zY3+V8de6ns6moPPJMiTJTSXmkBZTGHVmLd7TIH4QBqbQsG/yzG4k9zy/upskgEXVu c4eHqHyZjaaLMCAqZnpthD1mcEUT9a1iVAU+96VAFnLW1pUgb89DpiVEGyKN2RMdx0Mc AIyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Xw9eDWXEwpwNsn0HYqixkrc65IaqtCUycHScIiVECUM=; b=GIHdgi3JRiF89KstL/kf19J+NzmBbEXpTV6L/ZNIKlkuzf0UYzD3X4CUyIUlFS1nvv +5naJ3/6SFVHF2YqgpJEUe2RNZ80lmVblTrTqPx8fE5QpgDSv7M7ptSGuEZ/I0KDbLl4 Oax0yECOHmiD+na9k36DQFOBgiqa5onipglfkoP/OqKGvW1BK5pzI+KmcVC6Xt7qA83c BEwBC7RM4epndIWwgkd94xKo+7rR0fZW3SBaWZ+lRV+5aEMGffsG6bDUl9LqbQNN80JO 8fW9IxFeNx3K52VOUxbnfiKbWLn+ksxG4KIUa96XsNsFqziUEq/TlMUWHY3GRiPOqvwz IAgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IyQ7cMcy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b18-20020a637152000000b0053fb7d0fa78si9215995pgn.812.2023.06.07.11.37.35; Wed, 07 Jun 2023 11:37:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IyQ7cMcy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232920AbjFGSVl (ORCPT + 99 others); Wed, 7 Jun 2023 14:21:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbjFGSVE (ORCPT ); Wed, 7 Jun 2023 14:21:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F5DF10EA for ; Wed, 7 Jun 2023 11:20:17 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, };