From patchwork Wed May 24 14:49:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254100 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 BE433C7EE23 for ; Wed, 24 May 2023 14:49:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55FF4280002; Wed, 24 May 2023 10:49:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E941280001; Wed, 24 May 2023 10:49:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 361FE280002; Wed, 24 May 2023 10:49:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 23139280001 for ; Wed, 24 May 2023 10:49:45 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EE5E012096C for ; Wed, 24 May 2023 14:49:44 +0000 (UTC) X-FDA: 80825432688.05.739C32E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id F1700140009 for ; Wed, 24 May 2023 14:49:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AdA2jPmG; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684939783; 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=BBjfMnLRdPLaOtZKQ3MfDk6Q85OlEId07NY6t+N1kv8=; b=jAK48zIhDda+RlEg7eNDDidEOXfgz3HWDwuzuB5Qyl5XSz4x3PAbC1lcQYNXblucWMfT7R ccOeXZ3BrDTf6YSovw0PPyn2PmijYq93AdWjYT1DsYPqCqqSkcg/I31BJIEQZxciCINGqp CfXeWN0fYFQgs0DV/Dk8x+NN82oGYQY= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AdA2jPmG; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684939783; a=rsa-sha256; cv=none; b=kGTHWu7bYRvVIOBKL0wwbfINRy/E1ti/b16wKfa4UOywxObcoNDlnZsarh9oydX0vSKV1Z xVJ0S7gJiqKrW3YYHmZTcmAGWfULVK9BrAD5XV+8Wk7F7BB2hTzvs3+3vRBWdH/vspzDxq 73w2xNai3gyg3vuBoyp4P0Kc31MzZFk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684939782; 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=BBjfMnLRdPLaOtZKQ3MfDk6Q85OlEId07NY6t+N1kv8=; b=AdA2jPmGhYnd2oBS42BqR7w5xG5pYZzAte4bDyexV0kpdc2Fs1H0Z17/8ZZ7xFAm6Utx1x rMu+uNqDOsBc8iFlFs4M7PrRt9aH38I6kUVRDJpxfA6knMr/pQeB12qlzzoMdEwnasnoJw sSOgGEFt3FKc8ljRr6+yZwKdnLMgBcg= 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-586-WIiQwQthN-adX17FR81rFw-1; Wed, 24 May 2023 10:49:36 -0400 X-MC-Unique: WIiQwQthN-adX17FR81rFw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2C9785A5B5; Wed, 24 May 2023 14:49:35 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2BDC407DEC6; Wed, 24 May 2023 14:49:33 +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 , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tom Herbert , Tom Herbert Subject: [PATCH net-next 3/4] kcm: Support MSG_SPLICE_PAGES Date: Wed, 24 May 2023 15:49:22 +0100 Message-Id: <20230524144923.3623536-4-dhowells@redhat.com> In-Reply-To: <20230524144923.3623536-1-dhowells@redhat.com> References: <20230524144923.3623536-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: F1700140009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4oew1bg7t4c7ehwej9cz3qdaanqxbaes X-HE-Tag: 1684939782-311307 X-HE-Meta: U2FsdGVkX1/bIhTkvmwsNkt3zk8DMRK/J7bxKgzooybEU/aZ7sjIYOjZi/t/41XzODVwiG9Dz5zWzC1NMV0r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6sFx5T1/UI5Ysgl6QefnZTZkZZWfEl793eriijnHf1vdnb0K6p2SERmx2YOIFKzZnPlBIpVDPrza/7DeX6s1sDoohpAZLfsZF8mvNPcuCCHs0OT6hajtl3JxT1oBmu2IdhhYPu3FJrcINyptWbxagQz7tMg2za+1j6kENtCVs4V+vmfeJV7eO72nImOe7IE3H3o5zKVyrnYmN8KWBYzkkS9tdW8UWM3JYcWAkzi3N+oRqtlTEOTmVaf/pPTjlsRr5IbbZdgUkqZHPc9sfaV4Q3Llxa0juR4siOO852cbi6osYT6Z01UjQOQYuZQpfKQn7ToRhWuDINMjzKDlGIKCK9exrPbTtn4ICqyKiCdFBFgv0X6FCVP1J141v+QA+Ca2DUeQaQV7PMgJfvElIr2Tqj5j0+INab8J4kCz0JRZVpnCOh62t4BDYO8UvXhWtcC5H2g= 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 AF_KCM sendmsg() support MSG_SPLICE_PAGES. This causes pages to be spliced from the source iterator if possible. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Tom Herbert cc: Tom Herbert cc: Jakub Kicinski cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- net/kcm/kcmsock.c | 55 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index cfe828bd7fc6..411726d830c0 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -989,29 +989,50 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) merge = false; } - copy = min_t(int, msg_data_left(msg), - pfrag->size - pfrag->offset); + if (msg->msg_flags & MSG_SPLICE_PAGES) { + copy = msg_data_left(msg); + if (!sk_wmem_schedule(sk, copy)) + goto wait_for_memory; - if (!sk_wmem_schedule(sk, copy)) - goto wait_for_memory; + err = skb_splice_from_iter(skb, &msg->msg_iter, copy, + sk->sk_allocation); + if (err < 0) { + if (err == -EMSGSIZE) + goto wait_for_memory; + goto out_error; + } - err = skb_copy_to_page_nocache(sk, &msg->msg_iter, skb, - pfrag->page, - pfrag->offset, - copy); - if (err) - goto out_error; + skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG; + sk_wmem_queued_add(sk, copy); + sk_mem_charge(sk, copy); - /* Update the skb. */ - if (merge) { - skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); + if (head != skb) + head->truesize += copy; } else { - skb_fill_page_desc(skb, i, pfrag->page, - pfrag->offset, copy); - get_page(pfrag->page); + copy = min_t(int, msg_data_left(msg), + pfrag->size - pfrag->offset); + if (!sk_wmem_schedule(sk, copy)) + goto wait_for_memory; + + err = skb_copy_to_page_nocache(sk, &msg->msg_iter, skb, + pfrag->page, + pfrag->offset, + copy); + if (err) + goto out_error; + + /* Update the skb. */ + if (merge) { + skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); + } else { + skb_fill_page_desc(skb, i, pfrag->page, + pfrag->offset, copy); + get_page(pfrag->page); + } + + pfrag->offset += copy; } - pfrag->offset += copy; copied += copy; if (head != skb) { head->len += copy;