From patchwork Fri Mar 31 16:08:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13196181 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 0F8FDC761AF for ; Fri, 31 Mar 2023 16:10:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A371B6B009D; Fri, 31 Mar 2023 12:10:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 970F96B009E; Fri, 31 Mar 2023 12:10:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 838A86B009F; Fri, 31 Mar 2023 12:10:28 -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 73FBF6B009D for ; Fri, 31 Mar 2023 12:10:28 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 330C21404A0 for ; Fri, 31 Mar 2023 16:10:28 +0000 (UTC) X-FDA: 80629680936.15.72BD0DB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 614B820003 for ; Fri, 31 Mar 2023 16:10:26 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K1cA3h3w; spf=pass (imf03.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=1680279026; a=rsa-sha256; cv=none; b=A0yYdlySTe08pT0UzUKUvWzg1IrwVjfp3kVkS2y01VA5lGn8ybRreaB4ZoV+7k+HznZO7R U8QpMLOCLyNPHjJo4o/gduUI5/UoLORs5voknHTJIQPn2bExMEY4WKBUrXefSosXkLi8xl ZDvdg8Sc5Vxw2dOIotxigekG/8CDP3Q= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K1cA3h3w; spf=pass (imf03.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=1680279026; 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=lyush0ViuMN4qjWnnjaTjNQGyalIGfxBnP2JKfHTZO5KZG+ySzIT8CnSbYtWK8XCYLEWWi zjFfGkxcsYp/BAjKlowc1HBdXXitT4aLyOuTPjajFNuOUsjKo4i6iIRjBsSfv/ZyNRh2NG jXPXyal0tto6oAfkT7UJ4aSxgfhxkYI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680279025; 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=K1cA3h3wwHV95gaH9veWPOQc9gl3PayLJnV4p7n6zGKQrbu7Lxo4Ywu45Ju9WXJELMntBY xsZVFqXQGnFoZ9W9xFHWUY84b01Be5BLXK4yg+AbZh/wleb67tEQlu0LW4RZ5ZbKgwzuRo IhlGT/UhUxcjA6vFZX7aEAW95SNO6rc= 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-404-Y_P62SwVN4u6m6gIEWawdQ-1; Fri, 31 Mar 2023 12:10:15 -0400 X-MC-Unique: Y_P62SwVN4u6m6gIEWawdQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0ADB829ABA1E; Fri, 31 Mar 2023 16:10:12 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FB4014171B6; Fri, 31 Mar 2023 16:10:09 +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: [PATCH v3 18/55] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Fri, 31 Mar 2023 17:08:37 +0100 Message-Id: <20230331160914.1608208-19-dhowells@redhat.com> In-Reply-To: <20230331160914.1608208-1-dhowells@redhat.com> References: <20230331160914.1608208-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspam-User: X-Rspamd-Queue-Id: 614B820003 X-Rspamd-Server: rspam01 X-Stat-Signature: n6ye7mpmugm9bzga3xax67bdn3m5q137 X-HE-Tag: 1680279026-621916 X-HE-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iSwSX3ebiiGU6GCE6toru3zO/vOeFXfQTRyoLoXLKLVABTKtxieC4+kI9Dt7CXXESZkFykZ+/nGYjREhlBuIteWRAh7Jyg8iifB3DF/Njvo1MjXWy95peivOC7EPYTpqQHerJ23evNmKgAz9BBRqltjKok5Yibvma1jV2a44XI/n/4eg96RcLvrHUJIFUHuiN7IaVw6sLtDIW0jhdOdKJng3FE8PvCVH7eps0To0fR3jFprX9mb4XN2Kh4z5QF8wpGCMsPbsjYpMDho4pPEyON1juzT2v+kRczGT4cWE5z8qis5f/mKq7ogamIpAwNlx3FkQ2bvzi+y7f3a/GKLh87z4TAiSdIdpTTA7IkbdwtTEe6tiVOL8UM+tDlDltppvJO1UOyVSQCyxowwFeRi4rVHSqf0ODJqkmxh8cZ5KIJsFjGpg6CHi/VcTrRdLwjs5OR9g== 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; }