From patchwork Wed Apr 5 16:53:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13202267 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 2E50AC76188 for ; Wed, 5 Apr 2023 16:54:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C52CF6B0088; Wed, 5 Apr 2023 12:54:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB4806B0089; Wed, 5 Apr 2023 12:54:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7D276B008A; Wed, 5 Apr 2023 12:54:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9078F6B0088 for ; Wed, 5 Apr 2023 12:54:32 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 72740AC116 for ; Wed, 5 Apr 2023 16:54:32 +0000 (UTC) X-FDA: 80647935984.02.7411CB3 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 AB1B52001C for ; Wed, 5 Apr 2023 16:54:30 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=I1Cu3WGJ; 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=1680713670; 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=rczukz9qV63hFuelx2DCwDUOgKVDzUk5rK7clppjA7k=; b=N8x9N1rFT/Hf2SLUOUYYssePkoUiYbl4WcFvFLaSEDv6/5tpiazm/STKP6F6KNcsk5RKMY n4IelFB0VD39/+Axqjvvbjf/ysaIk5AjWdz8A+3TEq4m937QavdV6Y8XiRKP3f8OdkME9b YpGLukTHKBmQqcc9DxB2BIINlQ2iOQ0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=I1Cu3WGJ; 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=1680713670; a=rsa-sha256; cv=none; b=Hn7qDJVsta8O22FyFAFi102zFWc7TaHAWxkxl5eHSaFrRaVelgM9DZfTvtrsk+F+jBAGDb ssSiWuWV8lhGTo/uWzDrxrCgonwRns7e1Xs5oaaugmVuOgQtWXvm5cjn0Z15vL5l6Zrvr5 LRIbF9CMMJNmJ2kqwayYThzoh57hfZg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680713670; 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=rczukz9qV63hFuelx2DCwDUOgKVDzUk5rK7clppjA7k=; b=I1Cu3WGJOpD9T1ukLGQJLQ89iXKr0DrBgxnH1AEb0xlnGNZaNsINEcVbCfjRHsNVxyfRXW xifpxh5yebdg+Bpni8TZcmngrRobgGmnFdDs3oUbQ6Vl3o2idjNgir8R8M6drx/rH1c6X4 PmDw6E4POvrfimdTLjm1XbrEqe9pL1s= 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-224-KG6uRlhrMeKauli9V7lJyg-1; Wed, 05 Apr 2023 12:54:26 -0400 X-MC-Unique: KG6uRlhrMeKauli9V7lJyg-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 CC15D858F09; Wed, 5 Apr 2023 16:54:25 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7AD1400F4F; Wed, 5 Apr 2023 16:54:23 +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 , 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 v4 14/20] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Wed, 5 Apr 2023 17:53:33 +0100 Message-Id: <20230405165339.3468808-15-dhowells@redhat.com> In-Reply-To: <20230405165339.3468808-1-dhowells@redhat.com> References: <20230405165339.3468808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Stat-Signature: mfhhx7wzjyim9jrgmujqdiu8e9di7oq7 X-Rspam-User: X-Rspamd-Queue-Id: AB1B52001C X-Rspamd-Server: rspam06 X-HE-Tag: 1680713670-156837 X-HE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f9Px122vpHTBwvYy9q+WoSWWVWC//26OSY+T7e49HxMMu3+PZoOiXFWMEjn50isEn8DAVxUs0qVfOOuxjQbzx6EJ9PHwMWX+f1lN79+oWOY59W0KhjuzKeYFPBe2+a3W83ZWIkA8Bpmod/dJ6jn0aZsVi9t6Px9ziDHnfpX8c4TKhRjE9oK+5E9bsbKs3LHZSZUq0s5KH/KlKYbKk0DETAC8ebWSylzITbYEoBcDoUyDQHXQ4lMEgNQODIlMTP9Rq0J7tASs0ZOr82dVoGCe03kDRJrEU2mLTYd1z102GGLuawiNlzS7GzsIiZKtJFuv/kwnsfVCo3bJDk062lLIkoBL7A9WyJmDELJEOW2V5+1Khgpr+jEt9lCSw9kT4vB2+GJkWJGPRAVPJRnZmM+xt0KDUBlr5VC3uT4eAOJd54k6G42hfYeQq46w== 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 aa32afd871ee..0d3e78a65f51 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; }