From patchwork Mon May 15 09:33:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13241093 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 9146CC77B75 for ; Mon, 15 May 2023 09:34:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28BEC900010; Mon, 15 May 2023 05:34:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23C51900002; Mon, 15 May 2023 05:34:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B666900010; Mon, 15 May 2023 05:34:52 -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 E7163900002 for ; Mon, 15 May 2023 05:34:51 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B944D1A13C4 for ; Mon, 15 May 2023 09:34:51 +0000 (UTC) X-FDA: 80791979982.05.F3E7B95 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 0FD7540008 for ; Mon, 15 May 2023 09:34:49 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QILSxKlE; spf=pass (imf04.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=1684143290; 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=tIkAOtkPH6M/THbnTsk9oArHvLPjh18aSTPyNuwtCweCkFsi++3QjR357NbmCPt60DawRu 2gM/YBsiZXUShxVlHN0Ypu5AT58NJ79yBFClhGXkD0n4X7ySGRvLyBPXklxMp8zBpGGk+q w5xeVlAgVUWpP3YrdEINHNcqc0VlFwk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684143290; a=rsa-sha256; cv=none; b=r3qxTSHz9ba4m2Pw/UqZbgWxzYSlO9I3tSKZ1mKpYeDNrVIbcKuod6BxBEwNvSrg3Oj66O KgSywfVlSVTvCEADMMdu4DnS4dejMOMRrGjwnA1xI4oxu//5/BGHPuxo9SoFzn/j6IfwMi m9cGdMa4zh+AfHqMAgiXn/GDtbXZCsk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QILSxKlE; spf=pass (imf04.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684143289; 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=QILSxKlEeSwWm0hmyyvoF2yXz/+HBoJCLpssAx2yDeeQOw5sHxcKtj4sMhxxlK/2ivDnKw FprraD2KNpMruDWiY8FbA0EruqXd52dAqJa1K2I1cID5vyNk+MOw5rDJ3w4URiqvzIXXII 2ua8YGFV0f+zWrIYXqT6vxx0A2CnWKY= 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-66-s4PfbxzJO6eXzsD79oKorw-1; Mon, 15 May 2023 05:34:47 -0400 X-MC-Unique: s4PfbxzJO6eXzsD79oKorw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 23A9387082F; Mon, 15 May 2023 09:34:46 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40B9963F5F; Mon, 15 May 2023 09:34:43 +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 v7 13/16] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Mon, 15 May 2023 10:33:42 +0100 Message-Id: <20230515093345.396978-14-dhowells@redhat.com> In-Reply-To: <20230515093345.396978-1-dhowells@redhat.com> References: <20230515093345.396978-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Queue-Id: 0FD7540008 X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: efhh6wnbmg6p6k3j966f58arudjfkko8 X-HE-Tag: 1684143289-612761 X-HE-Meta: U2FsdGVkX18lCFdIlRQGJmHttefgvT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6a9XJrEWbDf9KVbJkoUxa5v2U1M+nSkpUIjlmpnHEaTM+jMQBhxQeJfp1WZ6nSDY//DIh7rhCAbqeeTTQ0n7L/gcBSGSHnfUTYQf9d77a1vOlnRBpOvRq7jySR3dwB1ci+4sHzLwnByhXvM/yebMdX7GyUBJSkQbxY+o3q1Hee7Z9FQ3b3gVRU57OvFiLq6uF9qX8tq8kAWfaDSZdg5mYwsWyQrVf9aqtYpvnx8qXyyzx0I1yVNvEyDEr0/UJ0S5HVGNkmVcKC2W3fJMFWCCeXmL450qLZrlKV/QSYXdNMI2yLGdWuFZJQS8gKAHTPOYbpigjUaSDKZVwPTTNcPtko9lH2nNRhVtUPVguo48WUK2IQ9nho0iprvSOX8VETPvfn12Ki3s1HIvZcTQNIuCJAqYqqo= 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