Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp698325rwd; Wed, 31 May 2023 04:19:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5QPB0UgOK54/A2KUq/QNJUAYXq0DVhuGOshXL2BBb995rh5gTDobchIjwjMvyPFbiBm5hV X-Received: by 2002:a17:90a:d681:b0:255:7cb3:cdc5 with SMTP id x1-20020a17090ad68100b002557cb3cdc5mr4243320pju.14.1685531956477; Wed, 31 May 2023 04:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685531956; cv=none; d=google.com; s=arc-20160816; b=hmGjfbvtXtkrWPVLU25V5fJXaEaTTsg7YKpkQq2Gu/pa7bMIB7aZgmcTZPgj1ll8z2 d2jivtFBSF0gnFiO6tH6dj/OoG+ZAAeXjXra2hIrc3VjEpxKkJThSY5jSxj4rE4BebEl LSrLYLrvs4/y5dgirEJA+tSgl/NBJuGlCFjbDeGzagnQpqtYZBZtepFT2fhx2+ET2US6 /b1MjmIMzGohaLmLmueyo5sRnhbSTmsSzPW+spN2/iQNq1x5EZ3m4AX5rAL3F9t63O2b iBLf/WkcQBb5H54b51PTKw4Mf6Dmf8SIl2hvGOyzW0UV3Yc3Yx3TwdBFAffSFc17GOfS 9HOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oo2uxP/MzmHd10a5KbN5Oq58DgcC9fhPDz9XsE6LWiI=; b=rOIO3Ez+wH1DAkY6cXZJSUtglEE6h0Tvm+gMU0v64P6RiPV9beSsUwtpx6JoaART8T J8YKLX296b9TqG08afNKm0zIuV9wD0L3cnSdtKQcXLLJpnOuPa5gqlUVNxMMdtV8JLAr QITEj4HtKv41twsxkfTinxQ/HuVB2CyjIzbt6EPaS0nmVIeCk8cwtuT4F03OXgjYbG4w XBSsKhF0Uvh8x9q8TK17MFOgmnRAV3DTVThjNYZzJre50slysKT2k+dGqM8K85ajkKTf TL0h88iZS8EJVfFkMyzjVCe6KUl80NfAo/dVpXxTAcQw1RoQVyYNAuCBPAlM5vnQWP4e qgbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MCYDYhXw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fh5-20020a17090b034500b002568322e3d0si846585pjb.34.2023.05.31.04.19.04; Wed, 31 May 2023 04:19:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MCYDYhXw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235105AbjEaLGG (ORCPT + 99 others); Wed, 31 May 2023 07:06:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232226AbjEaLGE (ORCPT ); Wed, 31 May 2023 07:06:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2E66E52 for ; Wed, 31 May 2023 04:04:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685531074; 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=oo2uxP/MzmHd10a5KbN5Oq58DgcC9fhPDz9XsE6LWiI=; b=MCYDYhXw1c/wEc+USh+i2Ag+UmNzXMj7t2JTGX9nRyMxZOaKz7KUvAIOdi8BAmmc9XFD0o MkEO7gEq9gwkQ2hV5rd08ctRRL9cefU+moofg0FvkVzNwmaaa6mNhS8Yd4qUvlVtsGTqp8 s3SS/SnR0eS+Gp6jTOwGOyY03PweuWU= 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-210-5MnFPOU1Pei6bNTHzvR1rw-1; Wed, 31 May 2023 07:04:32 -0400 X-MC-Unique: 5MnFPOU1Pei6bNTHzvR1rw-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 015F4185A78B; Wed, 31 May 2023 11:04:32 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48C7A112132D; Wed, 31 May 2023 11:04:29 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Tom Herbert , Tom Herbert , Cong Wang , "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 Subject: [PATCH net-next v2 1/2] kcm: Support MSG_SPLICE_PAGES Date: Wed, 31 May 2023 12:04:21 +0100 Message-ID: <20230531110423.643196-2-dhowells@redhat.com> In-Reply-To: <20230531110423.643196-1-dhowells@redhat.com> References: <20230531110423.643196-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Cong Wang cc: Jakub Kicinski cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- Notes: ver #2) - Only account the amount actually copied. - Wrap at 80 chars. net/kcm/kcmsock.c | 57 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index cfe828bd7fc6..8555ede66333 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -989,29 +989,52 @@ 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; + copy = err; + 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;