From patchwork Tue Apr 11 16:09:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13207822 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 505DDC77B6F for ; Tue, 11 Apr 2023 16:10:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D69AD90000C; Tue, 11 Apr 2023 12:10:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF397900005; Tue, 11 Apr 2023 12:10:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA99C90000C; Tue, 11 Apr 2023 12:10:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 93DEB900005 for ; Tue, 11 Apr 2023 12:10:07 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 21205A0D10 for ; Tue, 11 Apr 2023 16:10:07 +0000 (UTC) X-FDA: 80669596854.25.7F860E2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 1562FC000B for ; Tue, 11 Apr 2023 16:10:04 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LV1JTcfR; spf=pass (imf28.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=1681229405; a=rsa-sha256; cv=none; b=eNqE4l9ctkACrryVfw1Z2S4KPwkb6ePuD2VCLlVAbCR+Jv0IJZ3nju13OKG5drT8+15X7I XsyN8ktocvd0r/nLLUrsBaRePdAPy/6nOUhjzMWE+6s21NaaKDQSoXG7bNZASt64XGpI/O 6txaxFWB7wktAKB2hkPHaKTYKF9gvYA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LV1JTcfR; spf=pass (imf28.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=1681229405; 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=arPLIYOMzcdUPWLjuF22tHo0vP4jVzFFThikgCzP+CE=; b=2CuPZo+CKFoPD9dtCl++UYutcfpCtHs7pLfhqvXeAG5Ntf6o8mD8Nbt69DS7KREGk5TmIn UpUTGyY10gBL/6XeeqVDXwLsHAuKpoZ0oRhsuUMqiBBkg9cQph28Hji/Sh1G4Ol68WIpE7 6NBweumM7ZT17TAByP5RzeKL7vWccEs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681229404; 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=arPLIYOMzcdUPWLjuF22tHo0vP4jVzFFThikgCzP+CE=; b=LV1JTcfR/6Kw0N4Gd/STvV8OTD269CDWekAmtJN0Nydjtd5P79JyuoFEPp2i4QkjBeGYcK qTt0FXfN7rqGFqpgRWdezSlGq58IxHK5696uzJpRRH+m/KqYc3v239FHGlothX7o5AW+by /G9t2roaXkMODoFfK4MPLmYZdHnpqNs= 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-224-FiOc-vDHMJaCmdO7Voy_uA-1; Tue, 11 Apr 2023 12:10:01 -0400 X-MC-Unique: FiOc-vDHMJaCmdO7Voy_uA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FEBC38149AF; Tue, 11 Apr 2023 16:09:58 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75192C15BB8; Tue, 11 Apr 2023 16:09:56 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Chuck Lever III , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH net-next v6 16/18] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Tue, 11 Apr 2023 17:09:00 +0100 Message-Id: <20230411160902.4134381-17-dhowells@redhat.com> In-Reply-To: <20230411160902.4134381-1-dhowells@redhat.com> References: <20230411160902.4134381-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Queue-Id: 1562FC000B X-Rspamd-Server: rspam01 X-Stat-Signature: s7eprinuxyoo6gnjgyqbwc7osfui3d4q X-HE-Tag: 1681229404-623992 X-HE-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x56chD/QUNhtt/jvewGfzu4GZ5qbyPiW5tSUqXbO6pIUp9kvoDNPvYGf+lyVgSD4Lg5rsqYTxzjNbqJo0A/fM9K3k3nRAjJ0Q/w1BLbwX66b28/JeQ4A2XJkhQIaBl3CqaKjTpL9xyydM6/ilk73qjD6NRlI37JXJGMqqxuFo+qG4rQkcUjuME3zZIt8FaEA4Z+dfpPerS78Qrihfy5ioBoC7ZPomXElXCS+gQs8syMGlDmzHqxs2G7lLAwgiSulwjhxidE8AfwKaCCpKni5CHky3CmNm9lItKB9Fu+EgeFLjvBboCwVeIpHU5txpwcnOccSX3vCtxDdmQp7RAa30Ik4YpeMH2G4hwC1C1FiX74WPnPQWxFnBosOhMRPmpRy9NtEQCvZs3R5vozbObyKZWudn/6ex5GO5xV+xzQTrD6/1lyWlpdt+A8goJN+ESjtboFzA== 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: Convert udp_sendpage() to use sendmsg() with MSG_SPLICE_PAGES rather than directly splicing in the pages itself. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Willem de Bruijn cc: David Ahern cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- Notes: ver #6) - udp_sendpage() shouldn't lock the socket around udp_sendpage(). - udp_sendpage() should only set MSG_MORE if MSG_SENDPAGE_NOTLAST is set. net/ipv4/udp.c | 51 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index aa32afd871ee..2879dc6d66ea 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1332,54 +1332,15 @@ EXPORT_SYMBOL(udp_sendmsg); int udp_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags) { - struct inet_sock *inet = inet_sk(sk); - struct udp_sock *up = udp_sk(sk); - int ret; + struct bio_vec bvec; + struct msghdr msg = { .msg_flags = flags | MSG_SPLICE_PAGES }; if (flags & MSG_SENDPAGE_NOTLAST) - flags |= MSG_MORE; - - if (!up->pending) { - struct msghdr msg = { .msg_flags = flags|MSG_MORE }; - - /* Call udp_sendmsg to specify destination address which - * sendpage interface can't pass. - * This will succeed only when the socket is connected. - */ - ret = udp_sendmsg(sk, &msg, 0); - if (ret < 0) - return ret; - } - - lock_sock(sk); + msg.msg_flags |= MSG_MORE; - if (unlikely(!up->pending)) { - release_sock(sk); - - net_dbg_ratelimited("cork failed\n"); - return -EINVAL; - } - - ret = ip_append_page(sk, &inet->cork.fl.u.ip4, - page, offset, size, flags); - if (ret == -EOPNOTSUPP) { - release_sock(sk); - return sock_no_sendpage(sk->sk_socket, page, offset, - size, flags); - } - if (ret < 0) { - udp_flush_pending_frames(sk); - goto out; - } - - up->len += size; - if (!(READ_ONCE(up->corkflag) || (flags&MSG_MORE))) - ret = udp_push_pending_frames(sk); - if (!ret) - ret = size; -out: - release_sock(sk); - return ret; + bvec_set_page(&bvec, page, size, offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); + return udp_sendmsg(sk, &msg, size); } #define UDP_SKB_IS_STATELESS 0x80000000