From patchwork Thu Apr 6 09:42:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13203063 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 8B164C77B6E for ; Thu, 6 Apr 2023 09:43:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D1BF6B0088; Thu, 6 Apr 2023 05:43:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 281AC6B009C; Thu, 6 Apr 2023 05:43:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 122E36B009D; Thu, 6 Apr 2023 05:43:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 00B0B6B009C for ; Thu, 6 Apr 2023 05:43:48 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CB976811AD for ; Thu, 6 Apr 2023 09:43:48 +0000 (UTC) X-FDA: 80650479336.19.338823B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 1CB87A0006 for ; Thu, 6 Apr 2023 09:43:46 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=T+M8ttna; spf=pass (imf15.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=1680774227; 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=HO5c6fWLbjU5UW9pwObE4TQgRDIF6vfHUazrp9mJO98=; b=TysE7mlb0ha1wWpIhHkzYhdr78jBRlPFwbcL5JURqpuM0KuZFCraH+ojGpyF43fjbO8Ytj sy+tL79p27d326LZJtOVq1/PPMUgh9fuBuH36Jo2RI7k3cEY/D7VlXiOslUc16CKaYgJ5T 7uLubT8lU4mV/GcKB4e/gfXlry6dcDQ= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=T+M8ttna; spf=pass (imf15.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=1680774227; a=rsa-sha256; cv=none; b=tB+2HpCWN/EP0Rxk+u7l28J6XrivvV14Th9sjPtgrr42tsUwK+OcX3LlowuFSBNTjE0Yb+ yyKqn1IE5VHkzQx/njiCxsAOvHo8uoKsjhkr5qKyARDtdhEu/g2ruvMaDyQho/lvNt0TQ8 eQaGhrr0vlXqr1ZJ9LJJTMyqYV0wsuk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680774226; 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=HO5c6fWLbjU5UW9pwObE4TQgRDIF6vfHUazrp9mJO98=; b=T+M8ttnay6jMPN8FBKAMSSCHStGoURSAZCVOdba9pl5CCrXFH3Woir5kWSC1Pg2AMXbULw j5trnGmOd8BwiN6VUh+CRVzkJaGk0Ii2AZUOXVezQhpkTFWpuL+kfBJJZQ2YwlS2vSozpy /qDcUEGuzYZiiTLD+XwXjHHZ1JMDJ34= 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-122-QJgl81CHMCS3cOzCa4PB8g-1; Thu, 06 Apr 2023 05:43:40 -0400 X-MC-Unique: QJgl81CHMCS3cOzCa4PB8g-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 4BC24884340; Thu, 6 Apr 2023 09:43:39 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C6221121314; Thu, 6 Apr 2023 09:43:37 +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, David Ahern Subject: [PATCH net-next v5 16/19] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES Date: Thu, 6 Apr 2023 10:42:42 +0100 Message-Id: <20230406094245.3633290-17-dhowells@redhat.com> In-Reply-To: <20230406094245.3633290-1-dhowells@redhat.com> References: <20230406094245.3633290-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1CB87A0006 X-Stat-Signature: ya3854dihg1zy7fn4ziop55wzsmfugqj X-HE-Tag: 1680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B5/tDjP6HlTigIaJFKcdop6/yPW5kt+WwQmE1WDDtJ/g3+uxtLdtC+YJ2+42/G4Y6IhJ4Gm5gv/mnCdCgxUqSd5naDab1SYSOvxj721+BY3Wh7TfEMxcMtObl6X0pCXmMQHFQc5y998EMO8/GVmxfG7SG65/ANc+6t8O/fu1cUIxSxrLmV+1G9DxI2/gPS9Dm3gnxyQbm6f7q5sAcUzkjSZpxaTXEfPGmT6xzZQv0IGz+EUYTJ0AMm0WhU8zEHbBNP+x0J8xeDE3POQXls05yws6gA86kPc+mHe0DVlydfh5P8pLS7gwJC+ZZpwC5xUQKfSNiJs4DIzDCFUtQPlCXa2xFncd7V8I7ISyVuw/1lD92p+eY3IhbMhvWaPnyIXrCZ0oDxENTrnaR039h1rejkh3q5Zii2ZvLZtwSY/T4RIyvGLY3brB+Q8bK4ra0VVK0PJWdYteji2ABzZCs4mQQ== 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 --- 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; }