From patchwork Thu May 18 13:07:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13246754 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 DC39DC77B7D for ; Thu, 18 May 2023 13:08:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D61A900008; Thu, 18 May 2023 09:08:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75FDA900003; Thu, 18 May 2023 09:08:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58E3A900008; Thu, 18 May 2023 09:08:25 -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 3E9C3900003 for ; Thu, 18 May 2023 09:08:25 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AEFA1160837 for ; Thu, 18 May 2023 13:08:24 +0000 (UTC) X-FDA: 80803404528.05.E2AF4F9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id B178C80002 for ; Thu, 18 May 2023 13:08:21 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ANeiowsk; spf=pass (imf30.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=1684415301; 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=qI8KGC2W12EAkBMyfsn8UdagKfjDNIti+oPDzbBDciR90OMECEw51fqhff/Egu2zSyldwz AadcxeaRtl2njRi2uCpL+3DNuCn5z3em3E9DLEF+jb7au6e8t1SR+ebTebUJNLXhkGhX+S wV30R/9gzeYs2jKKirJI3p2FV4jVZ7U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684415301; a=rsa-sha256; cv=none; b=cIa1V8Q6UnahixRgv/bkzGQLVoctBug6Rf0XxACdKlAK89NL6eQmF6AmXG5DuLPMqIJYo/ AkDfJQrAwj3ur0ExxP/z/vqkALrqiDz72DEEUttUM3imp7DgqW0pa8IEd2zv6CpmxQ419F NgwZy6USBpxwkQwW67zYzE1+fnzlcSs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ANeiowsk; spf=pass (imf30.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=1684415300; 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=ANeiowskGyQlAkhOj2dfJRBdmPyn6iP1WBG+oUsgizrCVnazeGxEtCmA/n4F6v+MrRqpPh +80Alo0gz7ScVHQN6l3yVrBlNZ9zgu7UvqyZJ/piOpbmFYhcqbQTGmW7E0mgM08QEgP4vP Kgp/7GK8m6a/TAkzRpgV9Pza9TAkoL0= 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-122-MLznaae9M3inxRR4K92iug-1; Thu, 18 May 2023 09:08:19 -0400 X-MC-Unique: MLznaae9M3inxRR4K92iug-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7E93928237C3; Thu, 18 May 2023 13:08:18 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18F1E1121315; Thu, 18 May 2023 13:08:15 +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 v9 13/16] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Thu, 18 May 2023 14:07:10 +0100 Message-Id: <20230518130713.1515729-14-dhowells@redhat.com> In-Reply-To: <20230518130713.1515729-1-dhowells@redhat.com> References: <20230518130713.1515729-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: B178C80002 X-Stat-Signature: qx9y8fdadms4cy5rnx4dird1o7j5ouhg X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1684415301-205372 X-HE-Meta: U2FsdGVkX1+lo4Z/wYkrxSWIFcbGx+v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vWL7fpPE6eTzyNvakEK3PBfQmf+ZR/cKRftyPcC6DIV37w/C3V0IvRo3FLasAUo63Njc6frRSuiwzDwUgO6I24LhzWg60O1dzCsXaADw7LLoj68pj3u2het+3eeXFHg4Pyjm5AVSMgo40XNo6RG+V/nYGDQbJkg4m5o/NFFvI/fBmqTytTil4+p5z/AVdyMLFcSyHRrZ8nBjEH49fPI03fjnW5J8bTQU74UTL5x+yKo4C1LeGUnADanBkL7lN+PROq5aXilNlpzpbF92vZL08uYXqAw8DnxsZaj300Kd2EqzoRvilAbyIH2TbM0QDWytdOAFRH36qu7HJ++ZRH0UvEBUR/3tK/X9/iVzomeUIObjSVedFvUHrGYZqxCrAtE4ZKGlu9PL7LnjmhIonYm4= 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