From patchwork Thu May 18 11:34:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13246574 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 9DFEAC77B7A for ; Thu, 18 May 2023 11:36:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35F2228000A; Thu, 18 May 2023 07:36:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30F22900003; Thu, 18 May 2023 07:36:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1890490000D; Thu, 18 May 2023 07:36:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 09990900003 for ; Thu, 18 May 2023 07:36:04 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B2C481C75F6 for ; Thu, 18 May 2023 11:36:03 +0000 (UTC) X-FDA: 80803171806.27.7DA3CD1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 0C622180015 for ; Thu, 18 May 2023 11:36:01 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=I7FHcbAM; spf=pass (imf06.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=1684409762; 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=1sVW2QTlhw29Tkhrh9I6N8TqZ/F2m3qaPjkFmZ13QGxHQfMGIO/oedMveF/rmcugHgO/gm Ya2WbdJLmmB/yUfS4AL/dxaPYI+SR4/OVJdF2SFR0GtnPKWX/R8blBdmJ/R4ktIkxgsotI tyeV/8vlDI/a6u8xqP5y7luNu5AHkq4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684409762; a=rsa-sha256; cv=none; b=phBMVg0stddF2983daQKR5q/J1kWBi0b5qkc9eE2og9wCluZQovOc8Tnrqu1+KS6e3OXkQ QogXc2hKMSKIYIgUHOPMfs1ekSGO9AZeIbOUYJEiDCMq97rHRfhsDKXYMkL6JP4iRFTkAz viwbmQpVigZl1rnJJhRA0gpp9ccQ6jQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=I7FHcbAM; spf=pass (imf06.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684409761; 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=I7FHcbAMnATRGpSiON5mihkHy/Tk1MmKq+RITgCMrKym+/ncZOxuCoqleD/qKtadiaizro MJ+hvsa5DbTxNicRiwmBBKilXaH5rGoPwUOzEijDAaQ9/CCCp9PSMFnKARCTTbV8bk02Kc zSRGj5+AQ1GVYxAe8iWfM6otUsuQwPY= 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-253-zr9gaF3vOCeYO5wuwbnLTQ-1; Thu, 18 May 2023 07:35:58 -0400 X-MC-Unique: zr9gaF3vOCeYO5wuwbnLTQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 19F6086C60D; Thu, 18 May 2023 11:35:57 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6844440C206F; Thu, 18 May 2023 11:35:54 +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 v8 13/16] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Thu, 18 May 2023 12:34:50 +0100 Message-Id: <20230518113453.1350757-14-dhowells@redhat.com> In-Reply-To: <20230518113453.1350757-1-dhowells@redhat.com> References: <20230518113453.1350757-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: 0C622180015 X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: 7hehchejspa6jg7njfoxnz7e4oc7rfnh X-HE-Tag: 1684409761-966786 X-HE-Meta: U2FsdGVkX1/3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leTS2M8OOB9kc80V6Q+mmI2Xozw+EeDB15CFzBnpvvv9Gi0RTOtZ0CkDN3EZ4zQfHabtE9PI8jBmHPojk1C7Fu/YA7f5WOXEn8lpUpYS6bv2DuAMJn96F5uAdFVExeoo37sbOeBai3wUOtq1Hviz1r1kf4Ys6QV4kRgd5EeRHZScowd4p6IrmQdc9CNVp9Fe8uPRw1+WxM/uG3UFDWYkDxDjzcGMpBQe/HAp6VFzvhHn3DMjZnenVNVa6lLfhmxXCYUhcj/ctMesReaXez6ofwmEt1X81DHzVAoa70TNI/ItAleOA3qzM28JyFE/4v9aNp/yaI7wZz4nCVI6tzEYirX0mpSq1YCD8xdsZJShPfE6jB1VaBbGAwt5+DoO+hCb6nCsMyOa33Q/lqTRF8V8L2RIH15ezzy5yP0Pxzf6d4k= 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