Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2841797rwd; Mon, 22 May 2023 05:16:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7MX4YXPjhkCQV0EUzbXyaEdjmY03ciBgvjaIeyx753fszBnM2HKy7eNovdA+tcO/HlRzqI X-Received: by 2002:a17:90a:d589:b0:253:4d6c:21e5 with SMTP id v9-20020a17090ad58900b002534d6c21e5mr15471844pju.15.1684757818206; Mon, 22 May 2023 05:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684757818; cv=none; d=google.com; s=arc-20160816; b=WNTRfgkoQPVPJ1qDWPlXSusD9HtAKo220errBs+qfo9uI5OpmfKjTXeineK4etTavU 8jkTJorzzNd41vVBxeTXpY+o4/fizAUeGZ5V9/KIpQVLY/h8B1Z2zxYizxuNLXYwZUuf 9Kp6x7ckufctmlkT1sKkT8wq5WzO34Ibi6MLlsl1MtSMjxRWPnYzKp5gyNOsYm5Oyk8/ UcYwQEi5+5Xl3yURZq1ICpBy4v15Q4uaKJfC72wLgn072kTTHwZp4Jz8sS4zViu2vtdo 78gcEYQy4y8jwlASnsD4xwhc9BfRyicxdgOPF393ogmzvXCU697K63mNkN/vgXhqnQQi RYsQ== 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=YySm5kj3xE5R9D9zKiDsr9d7VGmM0e1ybNMHqVGh/aJC7JvH0OYFpyCD5OerlQ+i2t ngTzyct94uggdiXh/R5qDFDlsRpuiFqNhriYvVnwKvrVy/MNhqy4V+zEfS9ZMQPlNeP9 OLhg1eOKXbILSD9nMD09X1RNvr3YRwvYgXluBUP7pwKhw3DxY8b02KxwhiYQYeN2qGrv 8k3grdDJcgBEf+FSJ7q7Mdk94fjUCRgpeMzfcQKEADzEjXw+jKOd7emyCTxXPqMJqZcf Pal7rjtobxlS/6/tvlf8z8V2mN6F2YGQjWRX4zBely2Nk47ZUJSq21VzgAchICGJYSSq TR8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gNEBrb2+; 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 ie2-20020a17090b400200b0024666c4e8d8si65500pjb.187.2023.05.22.05.16.43; Mon, 22 May 2023 05:16:58 -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=gNEBrb2+; 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 S232744AbjEVMOV (ORCPT + 99 others); Mon, 22 May 2023 08:14:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbjEVMNU (ORCPT ); Mon, 22 May 2023 08:13:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7C3E118 for ; Mon, 22 May 2023 05:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684757539; 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=gNEBrb2+7QCk6oqJRxymmU2zNQ1qUWvTbpjt4XQnlR97+GayVv49U4ZLO94yy6Vsxn0Vzu dE2e3/jN1bYNV+SXQaP9xlBlH8CLuLTQuILSXCI6aoz91yf3VxrPVhsHiucuIvd3uOMKf5 Yv1TbqZ7ZCI65CYoXM8EpicRj6Whbgg= 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-407-eMUMHyWdN1qeVHDjTVvlzg-1; Mon, 22 May 2023 08:12:17 -0400 X-MC-Unique: eMUMHyWdN1qeVHDjTVvlzg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF505185A78B; Mon, 22 May 2023 12:12:16 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4439120296C6; Mon, 22 May 2023 12:12:14 +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 v10 13/16] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Mon, 22 May 2023 13:11:22 +0100 Message-Id: <20230522121125.2595254-14-dhowells@redhat.com> In-Reply-To: <20230522121125.2595254-1-dhowells@redhat.com> References: <20230522121125.2595254-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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