From patchwork Mon May 15 09:33:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13241095 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 6B1AAC7EE2A for ; Mon, 15 May 2023 09:35:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01990900012; Mon, 15 May 2023 05:35:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0D0A900002; Mon, 15 May 2023 05:34:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5F1E900012; Mon, 15 May 2023 05:34:59 -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 C40DA900002 for ; Mon, 15 May 2023 05:34:59 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 978AC41430 for ; Mon, 15 May 2023 09:34:59 +0000 (UTC) X-FDA: 80791980318.12.0B1C652 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id D64C3120010 for ; Mon, 15 May 2023 09:34:57 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hbE2U9BC; spf=pass (imf29.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=1684143297; 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=Noer+xEcweIaxqI3Wp40eBeOHcad5oDERWfCtnu/+pPBIg07niPoAI9wrussf5DSXoJuXf rP4cTcDHoWdhBYd5xQSyBJuHgf94E8efqp6Wq9Tnoj7pEv+j3Htz5Vxu7N7kf7z8VtT8/e elL9PT+wkgPHKyp4ZwygrffphiHQQLc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684143297; a=rsa-sha256; cv=none; b=edK4+1UwWUmMLw2NDgXJwldi2jz0ngZVnFuCD2m9Qpvf8XbC/GlbAE+KGoaXPTqT1hsJ5O NdqqcPeGGsZZtRtyaJoftvl7rpm3xKNfdEJk3XffKk/zO9oquNHJQ+cJnn/D68p18mTTzR jahaAy8e+wa1U11v+4xbGS6zDJLILdM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hbE2U9BC; spf=pass (imf29.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=1684143297; 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=hbE2U9BC+0EyCMwSxQnEHXFrkYWeB58WJTvkgpeRQ7f8saAPNcHptIjT+xqctx5/Ptatf4 VbLH+9K9qpd2eQFlYVgnsyzpLklizarbH6m3W2H41DWz/FGgxDiFhxNYSZ7Vr5IL2hhm1t Tg8J4YF8TU8rFKhqOUfA4ioEEfmVuaY= 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-351-oLogL-wgMESbZ_pbZl0Txg-1; Mon, 15 May 2023 05:34:55 -0400 X-MC-Unique: oLogL-wgMESbZ_pbZl0Txg-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 DE904185A79C; Mon, 15 May 2023 09:34:54 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id E86781121314; Mon, 15 May 2023 09:34:51 +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 v7 15/16] af_unix: Support MSG_SPLICE_PAGES Date: Mon, 15 May 2023 10:33:44 +0100 Message-Id: <20230515093345.396978-16-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.3 X-Stat-Signature: 99amf7gyoct411om5j5toeidhddetu48 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D64C3120010 X-Rspam-User: X-HE-Tag: 1684143297-666522 X-HE-Meta: U2FsdGVkX19gHMsQ4s4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MfrJwqKoMvevQ8/oH0FG+NO070iGSvRF+YjmlGXbwxjHgbqF+JjIhxYCaIuiZpbe/rNyH9gVDI0640ZvZRJJ6i9nEUDRHsS6hEmjfEkx46VXJIwCOgG9AaoaSPIuqq2+fmrs/Ng0jhPdLWVPf50turlNDhVdcrYJj3KHVJiCgDcWw0MsMK8VK3iTE5rZNP/u6pw1ZRSnpTrQYqoYFF/ZVPxwmv1/OpRFXRUmSPjrnwsXS/QRV/8FHUarOxKVqPnaRlCVoOWBrJyy1Ju71+/mDs2CzkIyrzVkz4zpx2KTOox59gVkErr7Owt/6k3m4q28+rURVmOhqZ5h2UVkMiDmZymcqH5QTi6xbf2nwlNI7yKD+kx35YfZExTzt8ikIi4+tkAnS84WISDfQe3zdXxh3esQ= 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);