From patchwork Wed Mar 29 14:13:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13192527 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 9DDB7C6FD18 for ; Wed, 29 Mar 2023 14:14:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 438F16B0095; Wed, 29 Mar 2023 10:14:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C2DB6B0096; Wed, 29 Mar 2023 10:14:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 289966B0098; Wed, 29 Mar 2023 10:14:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 11F8B6B0095 for ; Wed, 29 Mar 2023 10:14:57 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D96A7AB440 for ; Wed, 29 Mar 2023 14:14:56 +0000 (UTC) X-FDA: 80622132192.18.527774D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 389444001D for ; Wed, 29 Mar 2023 14:14:54 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i0U7Z07w; spf=pass (imf27.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=1680099295; 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=5bgiBObt8qBauZcUWYsV1T0v3n3OqeoexntQtIJIREA=; b=zRIfpJA02wZ1qto1A2DSW5z9bVvLIoviD798KYLDaZ4MTyWbyBYir2aaWOcbeyXIkH+Onw 4VOvVUrSVx6L/v9uLKHGIIcnhaKTgiaUiK74jSzKMwTwzSwXUWLnNo6ZhWrZ2jYZionTxb WhzN8awIANoSQr+ZIZtr9D0UoPd60zw= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i0U7Z07w; spf=pass (imf27.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680099295; a=rsa-sha256; cv=none; b=dV7UiyLJYit4RRSGbvCMFApzOeMzmN4zP62uXZJlswELvXrs4dUv+Zy1Twpx28G6si4lsp vJ5eQXXn/mB0ND9/1dn8tzpMZEXunR5AuFj37G4dB8DGQwlPzWUTE93nOhQctbz1ftsQ0l 3JVJCXkPV+EKnCx+BEDVXaEJsw29s5o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680099294; 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=5bgiBObt8qBauZcUWYsV1T0v3n3OqeoexntQtIJIREA=; b=i0U7Z07wk2ChCxv2RmIKltInZv5SBbsqvC5Is0Q4FH2+oZMUErGI8UnxLpz4otURL7gclh g2T27JayIp3/2Bk1pqHafBLYpDUTBg7yaGOESRS8BM8Qx3iFj66fyy3ZaGWaWzGcVGj72W GO0iIBJlJ0UxYG7g0U1eBC7SHzjDISc= 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-619-sSXFfrUjOyG56ONSjKtQ0A-1; Wed, 29 Mar 2023 10:14:50 -0400 X-MC-Unique: sSXFfrUjOyG56ONSjKtQ0A-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 0AB0B3C0ED6A; Wed, 29 Mar 2023 14:14:49 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 115CE492C3E; Wed, 29 Mar 2023 14:14:46 +0000 (UTC) From: David Howells To: Matthew Wilcox , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: David Howells , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Chuck Lever III , Linus Torvalds , netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Willem de Bruijn Subject: [RFC PATCH v2 18/48] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Wed, 29 Mar 2023 15:13:24 +0100 Message-Id: <20230329141354.516864-19-dhowells@redhat.com> In-Reply-To: <20230329141354.516864-1-dhowells@redhat.com> References: <20230329141354.516864-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 389444001D X-Stat-Signature: 1qo8imhckxxfnqg1ymoak4pxapua5awt X-Rspam-User: X-HE-Tag: 1680099294-503410 X-HE-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3lOQzyH6LQ9aYf12HhWH4Eeiha8mjtTAoxav7DbxHzImrQjCBGDusMeZ2IJa2KeZggJ3taoLJ2Kuqpynjv/3vZjJPu/G8R2tIIjeZM6kY6xVAwNR4P1yPIIt4lSLKyvuUsmg5BGTxybzsUtqJzMzZc1/9zNzfuCRnhhYxS6AtoBfPSEhNClsM3q8LYDrQGN/ZOOLWn2EGD95ZijTXex8XMxQCQyPDlwedz316tl/Mz0OYs3oN/UEyKLIEY/Rfd5A4NvWhje5rMWgK/rc0RrzR/R+OkSqN2m9yEi5QBENGs1qzkiMbduKFIX/Y+jgL+31eCzOgaNJiELfhOPM7tsC21YN2IfoZXi7HVCQGwk6vXS+sqpXIIPYak/284ATuBjub4HCgYoyz4GQSTWfcq+xGK68vWHFvF1R+NS5l26U+4Txo72beXBCdc3xgMaRmJBg== 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 S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- net/ipv4/udp.c | 50 +++++++++----------------------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index c605d171eb2d..097feb92e215 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1332,52 +1332,20 @@ 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); + struct bio_vec bvec; + struct msghdr msg = { + .msg_flags = flags | MSG_SPLICE_PAGES | MSG_MORE + }; int ret; - if (flags & MSG_SENDPAGE_NOTLAST) - flags |= MSG_MORE; + bvec_set_page(&bvec, page, size, offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); - 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; - } + if (flags & MSG_SENDPAGE_NOTLAST) + msg.msg_flags |= MSG_MORE; lock_sock(sk); - - 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: + ret = udp_sendmsg(sk, &msg, size); release_sock(sk); return ret; }