From patchwork Mon May 15 09:33:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13241091 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 AE469C77B75 for ; Mon, 15 May 2023 09:34:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 522D590000E; Mon, 15 May 2023 05:34:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D354900002; Mon, 15 May 2023 05:34:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39B3890000E; Mon, 15 May 2023 05:34:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 238FB900002 for ; Mon, 15 May 2023 05:34:46 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 01DEAC1425 for ; Mon, 15 May 2023 09:34:46 +0000 (UTC) X-FDA: 80791979772.10.CC8C2BF 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 5349618000F for ; Mon, 15 May 2023 09:34:44 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=E6ih37pJ; 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684143284; a=rsa-sha256; cv=none; b=ieWJFL634vgUBIOlHw+fChMgfggDN12QV04isWsMfKGTgLveYN1Nabr7vxni0jyuH6p7iR Hh7fpsD4W8aZwQL8dsT5orjH3Yfsf6tFhko2cVyoJVDwnaXVEaE88va/cuHqU7HROo8MSX jQFLP3dm3IX9qQfZtsN9WdbphlnLbA0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=E6ih37pJ; 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=1684143284; 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=Di14zlocOEDECmKOzgXOEyS4sjRLATonTy1WJdIXAUU=; b=6Qs1GXWA+U5lu1ois2QDEiYCZyXswn5aL8pGBgMZRlgAmkFUjU2lUMo2N7DQrSO+RCc6hU A5LzeQgDZPMQ/S75l1BMeTaF/gaQ2iKfCPAGXPNjo/1e7o0EwoGLom6m5n9kQewlGUFl+T N0z4sWe2SkmcC1ZdXH4Zs9rrytB2pWE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684143283; 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=Di14zlocOEDECmKOzgXOEyS4sjRLATonTy1WJdIXAUU=; b=E6ih37pJek0uvGPIfN1OdSG5M0C0KPTutTqd8Uhu9oZSO4WBQgRRIFY6M2z0H1vfcfjwPo wwQ+t0PM8YsI0UsUXlCyzVLCZbnmMXFyQKUFbw+syafuHdcjL4/05j1fTNFW0USEnn3W3X JEh+Bl2Wes8cM1ZlSW+qaWqra+yJbyw= 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-675-DqP9KNUYOT-s0mTetspL_g-1; Mon, 15 May 2023 05:34:39 -0400 X-MC-Unique: DqP9KNUYOT-s0mTetspL_g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6ABAF891750; Mon, 15 May 2023 09:34:38 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BC60C15BA0; Mon, 15 May 2023 09:34:35 +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 v7 11/16] ip, udp: Support MSG_SPLICE_PAGES Date: Mon, 15 May 2023 10:33:40 +0100 Message-Id: <20230515093345.396978-12-dhowells@redhat.com> In-Reply-To: <20230515093345.396978-1-dhowells@redhat.com> References: <20230515093345.396978-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Stat-Signature: tfni9kn9gs37hm353ex53c1pdnirk33r X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5349618000F X-HE-Tag: 1684143284-520450 X-HE-Meta: U2FsdGVkX1+MNOfdLLvHQzdKeCEoXwVg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yG6a5v617/DRGiYaMD2GtrfqM6irSAlddyXcQ4NIZZUeAxBLYRvpA/ehGIcWmMbDuFlnE+BwWZ6ds3aexAyFaODwc6EKsV552GmFot/2cOXAiqlESsWIwjEWd5X4nNFnZsS7b2Emo2OQSYSjc6ui1hG2Z5RtyxVWVuv4ANCFJpJz90yUR7Zxj0+/hezMKRxWY1DSPTsFMu/G+Q1kyUXbJ/97bpCHCT8YPCVaGlGLvrDKYn0tMrXG01frc2G4EiPKZ1vd/wZd64bIyaM+sGi/FaCJyUvVlltRkYmH6cD8um7TKmDVCzManVeHntD+vvyAGVNmmvynPhvlkXR77oCm2Pv/8xLPpzpis7e8tyYNgx0SDOV6nAiOjqF9q67N1ZPYBlwA3c0= 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: Make IP/UDP sendmsg() support MSG_SPLICE_PAGES. This causes pages to be spliced from the source iterator. 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) - Use common helper. net/ipv4/ip_output.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 52fc840898d8..c7db973b5d29 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1048,6 +1048,14 @@ static int __ip_append_data(struct sock *sk, skb_zcopy_set(skb, uarg, &extra_uref); } } + } else if ((flags & MSG_SPLICE_PAGES) && length) { + if (inet->hdrincl) + return -EPERM; + if (rt->dst.dev->features & NETIF_F_SG) + /* We need an empty buffer to attach stuff to */ + paged = true; + else + flags &= ~MSG_SPLICE_PAGES; } cork->length += length; @@ -1207,6 +1215,15 @@ static int __ip_append_data(struct sock *sk, err = -EFAULT; goto error; } + } else if (flags & MSG_SPLICE_PAGES) { + struct msghdr *msg = from; + + err = skb_splice_from_iter(skb, &msg->msg_iter, copy, + sk->sk_allocation); + if (err < 0) + goto error; + copy = err; + wmem_alloc_delta += copy; } else if (!zc) { int i = skb_shinfo(skb)->nr_frags;