From patchwork Thu May 18 13:07:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13246760 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 7239EC77B7A for ; Thu, 18 May 2023 13:09:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1EDC90000D; Thu, 18 May 2023 09:09:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F503900003; Thu, 18 May 2023 09:09:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8488190000D; Thu, 18 May 2023 09:09:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 68504900003 for ; Thu, 18 May 2023 09:09:02 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EE0B5A085A for ; Thu, 18 May 2023 13:09:00 +0000 (UTC) X-FDA: 80803406040.30.DAA0E9B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 4A6521400B0 for ; Thu, 18 May 2023 13:08:30 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aq+POVWb; spf=pass (imf09.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=1684415310; 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=lvlSLroEEg1VGuCDCeQ4xc3xFi52IK9mce9FvjeI+YDPm5ysx2CrU/OPLhTg1wHBlrZkEm ARMxflLv475tL+Iu5B62zn+o7mDzc5alYbpQEBsEi+CUmfraNFR5Yq0KUp5bTRMCmJVdpt qhPrKnEtixsMMYD4PoWz3hytLHNDuqM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684415310; a=rsa-sha256; cv=none; b=wND1JMGZ9J7M2NAwn98RegPxvodFWDadT+u4fvPK68IPInwwpAMonta7LIeyDKidVOsG/U N3ewk779dtx7cydRTQr5clIPjGSCnchsOHfR+9gtFWSqgsNLKL0k9hrnzL/eAtBqJPsubG aPx4cZXy73x/Xoyb3FB+7bzu/fURzC8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aq+POVWb; spf=pass (imf09.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=1684415309; 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=aq+POVWbHkFInjUvPgnDwRjNUmXiO5qO+7Bj2k358/i6HJ/c2vOcGXhHYjcKDHb+nSBDlo iFFjfYEsLVskcsh3ZbfOtAOdVbqesegTE/U8EWZd+kQDWuaAWhMLqrihZCRNes1ELlmUkE J6v1ruAQQAnnhvkYZPKk3bjRzkCzl+4= 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-189-jUFF3OsoPBixAzERtA42UA-1; Thu, 18 May 2023 09:08:28 -0400 X-MC-Unique: jUFF3OsoPBixAzERtA42UA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1BD65101A551; Thu, 18 May 2023 13:08:27 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DFAB63F5F; Thu, 18 May 2023 13:08:23 +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 v9 15/16] af_unix: Support MSG_SPLICE_PAGES Date: Thu, 18 May 2023 14:07:12 +0100 Message-Id: <20230518130713.1515729-16-dhowells@redhat.com> In-Reply-To: <20230518130713.1515729-1-dhowells@redhat.com> References: <20230518130713.1515729-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Stat-Signature: 5j89c7z4rhqpf7e8d8f5ognnozscgcga X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 4A6521400B0 X-HE-Tag: 1684415310-321145 X-HE-Meta: U2FsdGVkX1/8falWH6X5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sZOlAAi80KGwRbRsjAFF78my40wUykUxt3Sjn17ef0jMhQRXlMBjsWetLHQRonjzm5YQzCilxLXf3Mi5XrARr3attjeXg0iiaEnMDGQ9n7Prc1sltouZYM3aob8OKalyggC7WGhpBgW5oBP1JbKjUibdZ7qycVDktkCGeCdqWjRkVFV4OXcfvq5k8Ww9mHS4v0fiD6B6s0cVHAHm22Ii9FOImjitJmO5CfkYcDAcU4fRzFi0m3tP0cOl9og41ydUngITo56OCYBjxNxSEJB7uuwEjZXApqZ/6Xiv57p0aa5gVPfiqON1b8KtbRqKbME13ZsQlW5XWKADWzR64M3oK0krvHs6Pzni+Cy67GNeiOqOxZPm5ao/Qysc4s4t3RVj+4/kY1xd4Uyc9twHfgCRfYsI= 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);