From patchwork Thu May 18 11:34:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13246576 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 64A41C7EE23 for ; Thu, 18 May 2023 11:36:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 02A6628000C; Thu, 18 May 2023 07:36:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1D25900003; Thu, 18 May 2023 07:36:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0B6128000C; Thu, 18 May 2023 07:36:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CE609900003 for ; Thu, 18 May 2023 07:36:13 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A38ABAE1CB for ; Thu, 18 May 2023 11:36:13 +0000 (UTC) X-FDA: 80803172226.15.FAB029B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id EC8D31A0017 for ; Thu, 18 May 2023 11:36:11 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=b3uGA1jf; spf=pass (imf19.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=1684409772; 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=4sbDm+4sgaynAjmiQFVbDl+OyfXvG2vWGJtRH+IAST4=; b=d5pH3Rf9Az1rT/o+dk5h7S4O3OTsZbNI52mz6tb7Sp55ymo8YuW78GPgWOgCO8MuMFrBwy sLHE/lANB0b1YNAYhP8MoEyM83VvSvaZlYFGDrKrEg+NO2Xcvl0CO9kT9jGMhHfuO3XT2t /OiLF3vvPp+cTxlnHA16PK4aF7QS/Aw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684409772; a=rsa-sha256; cv=none; b=J7NYzEdZc6jBzqhjUyzP4DioJ3gCo7MA4rmVIRLc+FBL/vNR2QIDtf5VmiC6jXCII8mAxN J00QIvLEbUEb07hqG4orDgWKvGPiD1PUGoHiHIrofqUNRmqKQSWGwSluZQCCRdjspqb7DZ YDRIgW8Llr9Dmt9GtYc7QZROBINNXjo= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=b3uGA1jf; spf=pass (imf19.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684409771; 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=4sbDm+4sgaynAjmiQFVbDl+OyfXvG2vWGJtRH+IAST4=; b=b3uGA1jft/K4VwXzui8owpcLpNXIYj5OLn1RjgLewPgyxwdO6ed+o8DewMxb4SQ2eFZp3J BqpghkjUqwt3z96PYKtRxwO8PyxALYB4ane+CiUHS9oiceczit/X5TUkHpWquVtLjQXz+V 3oUQX6qlSxFKvJGVmjQaAadgsZ4jpSs= 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-497-sU7nZ7tANKyeN_LLALrjqw-1; Thu, 18 May 2023 07:36:05 -0400 X-MC-Unique: sU7nZ7tANKyeN_LLALrjqw-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 121C787DC27; Thu, 18 May 2023 11:36:04 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8346BC0297C; Thu, 18 May 2023 11:36:01 +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, Kuniyuki Iwashima Subject: [PATCH net-next v8 15/16] af_unix: Support MSG_SPLICE_PAGES Date: Thu, 18 May 2023 12:34:52 +0100 Message-Id: <20230518113453.1350757-16-dhowells@redhat.com> In-Reply-To: <20230518113453.1350757-1-dhowells@redhat.com> References: <20230518113453.1350757-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: EC8D31A0017 X-Stat-Signature: oz165u5n4qnzjp8ej7duq9xf1aphs7di X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1684409771-531404 X-HE-Meta: U2FsdG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5gNeAokUH+Z1j8omplczfOBKCVZXMVx9vNTbABWVP+khpXlin8pYDS+U7QtAs6fI6aFqT+7i4PrHi6Lfwj50V4rL2QbaWBhKdqfORRPcEVHKE7nlwViskHqBss9t0Rq4LtFpuYuoFOLFq2CNEerm5P3fn+J1oeT7QYkXzyMMBIX5Q57Vh4unYyzZxpHvi3wuUBYwdsP8o4AmGj/C/x7n0iFn9UB6iUlHSayxG76e6zs6nOyq6HKqlrese0hhDJE6R5K+0vchFC87Kz/U8E4PMXODxSqOnnwMR8DZRavdriJLDvFXN1v6C1jZSDc1qVJ6bSWik0tZbKKXxig01AewCsKIHVfgfYMGrUFZVlG5B0IcWeyHFE9EteFN06AgHOO1HmwTqzRPr1JF+44P32Ls6jjFwBJlEtWST1hLMHLyAWzn4OBM= 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_UNIX sendmsg() support MSG_SPLICE_PAGES, splicing in pages from the source iterator if possible and copying the data in otherwise. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Kuniyuki Iwashima cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- Notes: ver #6) - Use common helper. net/unix/af_unix.c | 49 +++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index dd55506b4632..976bc1c5e11b 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2200,19 +2200,25 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg, while (sent < len) { size = len - sent; - /* Keep two messages in the pipe so it schedules better */ - size = min_t(int, size, (sk->sk_sndbuf >> 1) - 64); + if (unlikely(msg->msg_flags & MSG_SPLICE_PAGES)) { + skb = sock_alloc_send_pskb(sk, 0, 0, + msg->msg_flags & MSG_DONTWAIT, + &err, 0); + } else { + /* Keep two messages in the pipe so it schedules better */ + size = min_t(int, size, (sk->sk_sndbuf >> 1) - 64); - /* allow fallback to order-0 allocations */ - size = min_t(int, size, SKB_MAX_HEAD(0) + UNIX_SKB_FRAGS_SZ); + /* allow fallback to order-0 allocations */ + size = min_t(int, size, SKB_MAX_HEAD(0) + UNIX_SKB_FRAGS_SZ); - data_len = max_t(int, 0, size - SKB_MAX_HEAD(0)); + data_len = max_t(int, 0, size - SKB_MAX_HEAD(0)); - data_len = min_t(size_t, size, PAGE_ALIGN(data_len)); + data_len = min_t(size_t, size, PAGE_ALIGN(data_len)); - skb = sock_alloc_send_pskb(sk, size - data_len, data_len, - msg->msg_flags & MSG_DONTWAIT, &err, - get_order(UNIX_SKB_FRAGS_SZ)); + skb = sock_alloc_send_pskb(sk, size - data_len, data_len, + msg->msg_flags & MSG_DONTWAIT, &err, + get_order(UNIX_SKB_FRAGS_SZ)); + } if (!skb) goto out_err; @@ -2224,13 +2230,24 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg, } fds_sent = true; - skb_put(skb, size - data_len); - skb->data_len = data_len; - skb->len = size; - err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, size); - if (err) { - kfree_skb(skb); - goto out_err; + if (unlikely(msg->msg_flags & MSG_SPLICE_PAGES)) { + err = skb_splice_from_iter(skb, &msg->msg_iter, size, + sk->sk_allocation); + if (err < 0) { + kfree_skb(skb); + goto out_err; + } + size = err; + refcount_add(size, &sk->sk_wmem_alloc); + } else { + skb_put(skb, size - data_len); + skb->data_len = data_len; + skb->len = size; + err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, size); + if (err) { + kfree_skb(skb); + goto out_err; + } } unix_state_lock(other);