From patchwork Thu Mar 16 15:26:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13177811 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 15FA2C7618D for ; Thu, 16 Mar 2023 15:27:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A00BA940007; Thu, 16 Mar 2023 11:27:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 965CB94000F; Thu, 16 Mar 2023 11:27:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A57D940007; Thu, 16 Mar 2023 11:27:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4FDC094000D for ; Thu, 16 Mar 2023 11:27:00 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2D50D1A0827 for ; Thu, 16 Mar 2023 15:27:00 +0000 (UTC) X-FDA: 80575139400.04.926DE05 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 294FA140018 for ; Thu, 16 Mar 2023 15:26:57 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="YKsn3kU/"; spf=pass (imf26.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=1678980418; 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=laeUsLmjTagEpDVgDutbyJSYZjGXzAiWxumwBIG+GLHrNcCjbiLvFgUieT40+rAkH+QV0N O8O5KoatnD0NMICZBSstmChshT1E0uumBtQSQX2jACwSOxi6SDFDBywNJc6GdN7bMxNCke gZnbZSRTCnM6WJf6TpJQLdsk5AN9hGg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="YKsn3kU/"; spf=pass (imf26.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=1678980418; a=rsa-sha256; cv=none; b=bdRYqKN7AXcKzXeFjGcSWwN5tkPZchv1qksomfcEsL8bwlMs7V2a97g2aXMIpb4/EHrckx drzqtnqJxeiaUDJPz4sdCLE0pv7PIDqRV1+GtN5WEyRYzLbXKJLeMF2ItZYlSpIGhEYiHA NaAW4nhidEFJC7HqdNaZgu9DQ6B2DDo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678980417; 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=YKsn3kU/5PAlFOh9yEwDxs3M4b8ejujkcrxpyXBn3SKGESmwhe6klFskkLAuOqzr+0SumB gPv2Dz2y6zYjRFYEnu7iMILDf3qLM/M79idct75Rwiw+Ke4TRNDmcbcHSiYsq+68eHMFHa do4VQIpP9cZkbwp5P912PX9Oay7wV5Q= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-383-a51AlkUUOb-NXl1w0lE3CA-1; Thu, 16 Mar 2023 11:26:53 -0400 X-MC-Unique: a51AlkUUOb-NXl1w0lE3CA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 568E3185A7A7; Thu, 16 Mar 2023 15:26:52 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id D49BC492B02; Thu, 16 Mar 2023 15:26:49 +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 , 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 11/28] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Thu, 16 Mar 2023 15:26:01 +0000 Message-Id: <20230316152618.711970-12-dhowells@redhat.com> In-Reply-To: <20230316152618.711970-1-dhowells@redhat.com> References: <20230316152618.711970-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: 294FA140018 X-Stat-Signature: qso8zffq6fpium5koex58pzmag9m4xn3 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678980417-653430 X-HE-Meta: U2FsdGVkX1+dO/Wi71VgvJy+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AvMGHz2FX6TgRvwguVC3W5WVKhYEuANPctOXr0YPtkR8vdcglxF05bwmZvvyySyxSfCTTzgXkVpuyVS7csV+oLUM62+jrF+4DtVOlL1VluRy2U9Exg74MnbyTTR1DY7s5eWw8z2z40MdoZU43LhxuFr+ymPvC8YffQ26ZVD3wcvS6iG0OTLdJln17R4fZJdsnio2SKVVEqZa/RuIQJb7XKPaUQVkVE8ZP4WJGx83vJFWjxiOUZvvlSNjMDrgurQcezJgE3rnLyLSKO4Y7QZL870stO6kia9O4TcpY9u3yzvWAi6rtOcSuTL7CEoJSsh2gN09QO5AiUfut1NPGUmwCOTXDAYTzmHAObKAZmMzkBSx8hRSIkdcYP4ewF+nlMEd7KwXFByk70qx0Dba4ZQIJ+omYkaM/3xPNQ4JjZkVKQw== 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; }