Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp950048rwd; Thu, 18 May 2023 06:12:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ46ipJgdrjjPp3DVoR8OtEZv1GAfMnmdWx0Xe8V/LRuX0Qenx2Uhha72tQfE818GaryNsj+ X-Received: by 2002:aa7:88cb:0:b0:646:e940:c2c4 with SMTP id k11-20020aa788cb000000b00646e940c2c4mr4756599pff.14.1684415521692; Thu, 18 May 2023 06:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684415521; cv=none; d=google.com; s=arc-20160816; b=uqFaDZuRZvnC0SGFsaG2tfyP60wMrrrnpMFUTcnCj3QOZle9qb0M2jkSiF8QlYS4/O lOAYUSJXzEOc7a+X1oRlKQFFiw7SXj2DG+jJGsFIdK3uJj9L+7P2kK7quwMXcE83VuK1 B0/f8gZUSFVkK/1Zbmwtgfb67T4kfk8LiPLUAUcjmjtwvBZ3Ghst/x2rEgljH8JKRVa3 Id+/9/RiWxkOXAsRpayKwr1IjAnOi5WUEIZwyFZEP0Fw+WV8r8TtjtJDAyZ7IY58X7D3 nxP1NV2cIlL1DwrTrRVMEt79EN3HUM9J5OpLmMsq+692ZA3cTJBdBcSqgmCHFp8gsDak SiJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=arPLIYOMzcdUPWLjuF22tHo0vP4jVzFFThikgCzP+CE=; b=x+O61mNYb/0hAzlWMl9WZVfzeP8Fj34m9ceu1R1cKuZ0ravOO7QSxEjAEbBQa6RxYT MxLZw65v4MY8y008/EWjDa1ykcDx7zBvdj6R6l/OMz3k2TM+gPvHluTBnSnWzQgIc0Ti flvGmW/pEOFONhgt92HDEeq+NeYLIEy6q/ann54ZnJ5BX7DxPN7M7ZoBWPnZHIm2mfa6 xdi98UIpLDgH8Ae5uEBcsExSESnoFHL8YaTwUQkpTKDJMk86Uj3RcW7kSZxvDVSa3Lm+ 8SDHeh8INhsIjlrM4Bo0HYKPWKBY/dtpt2xHUXqV1bc4B0dVF/ByWW43mF70XvEOwDAg B/zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LYzg1Z8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x23-20020aa78f17000000b0063b7bb98251si1575939pfr.216.2023.05.18.06.11.48; Thu, 18 May 2023 06:12:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LYzg1Z8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231512AbjERNKQ (ORCPT + 99 others); Thu, 18 May 2023 09:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbjERNJf (ORCPT ); Thu, 18 May 2023 09:09:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F163B19A5 for ; Thu, 18 May 2023 06:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684415302; 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=LYzg1Z8M7W1ijB1N4wPMu1mUCFV+AOkQl37EnTSvrB+XeEM7ceBYfqQcw/dUEODqxWMVjm SVt+JMj+pqzFYyuBU0OHPExmuL6mPVS6hYz9XSUa0o6Tz3JEDxTDZqW98HfRfdGG1wCbHI m6tHu2qfzZIgNt6E2lsx6GGKtqRGY/s= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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