Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5939578rwd; Wed, 24 May 2023 08:42:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6qacEmYFjADt1PJNAiQqY/MT82iMIuKWZ9ajzzCJdcjv1hKkFdDB5p5uwjXVPH1GKC2H0g X-Received: by 2002:a17:90b:4d8c:b0:253:3dd9:79e2 with SMTP id oj12-20020a17090b4d8c00b002533dd979e2mr17683027pjb.5.1684942939641; Wed, 24 May 2023 08:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684942939; cv=none; d=google.com; s=arc-20160816; b=ExgK+KHQymkxi+YYj34npggG1nPGpNgsV5yeRFbL6o/h3Fng0wdM9CyGLYONi81QfC IJGlJ8zKqrn28lJqhivGzDVbdUqi5TwXsMxcjGTha0CH1S1aOR1XaG22Atl0L3xv1HKp NZvnI6AfKZ89A++4qPU5Qg2/YP9KYq78dnFNhL6HLaXqRvY8+KncW1wVB/JkzWaORvqe B2SCeX/Ub+pp7c6CgGINiVFk1GGwJo3CXdyOJvioThmuEw8V77pZ8LV4BVRI5xD8Q4sq ZC8Xndarqzup50w11LQoMWqYN62zjvAd+ocAoist2vo7YcAagmspgqEx0R5SF12MhN8m ddLg== 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=PZf0byHPp2E2QKGUTDTD+TlMjPhCnr7dpojTO1v28qY=; b=hfPrPWPS2tmVqmc1gS+i4ihg87PoJjWxcWDi7j42Dl7TVs1RtAkb8ptyaxcgIn35gx SzYv+GbgFWAyi2Ff4AlBfpL2HKlc4D9zDM2j2Pl6zwxdre+Zfh7dnzO8oeL23DC2ubsN mb3xYrQeVH3kT+c/1lcp9MFQwQ88Dx8wFGTC9jGnbODkxXimxT37f1OCXTiWESdAxTJg OycBi6IWZ9bFSk2Vyw57aLuZQ/IdDt65JFr4HJkGT7CUIRSQ0gMI+RXB3thGEJWDLPCk gxcuwMhXPy8t13b/7lcFPI4y4K4qvL2LVpkBYxPDeAv7FZxBrivHlRqoVUPuKoCecu06 LWMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jWzDHD7q; 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 e129-20020a636987000000b0051b1966e6b6si1187076pgc.521.2023.05.24.08.42.06; Wed, 24 May 2023 08:42:19 -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=jWzDHD7q; 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 S237109AbjEXPgT (ORCPT + 99 others); Wed, 24 May 2023 11:36:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236323AbjEXPfM (ORCPT ); Wed, 24 May 2023 11:35:12 -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 17F5E123 for ; Wed, 24 May 2023 08:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684942430; 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=PZf0byHPp2E2QKGUTDTD+TlMjPhCnr7dpojTO1v28qY=; b=jWzDHD7qRb45gP5eAEdveVXJvNr8sK15Oep6MRqqVvJ2Sovbdc5Sd7u6eODXgpIfZzpYO+ SlxXksB1FMqy7MtnvE8BFdOQN8hwzWz5zmTP/DyJITyMqPBNZzRK3je9LvwakkG2VZAwIg qS8l8D5yMR71WoeA6oF+EpBDVcXcgog= 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-26-wF7-Cb2KPtKxfSJZIAw0Dg-1; Wed, 24 May 2023 11:33:46 -0400 X-MC-Unique: wF7-Cb2KPtKxfSJZIAw0Dg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E46EB811E85; Wed, 24 May 2023 15:33:45 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4289240C6EC4; Wed, 24 May 2023 15:33:44 +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 Subject: [PATCH net-next 08/12] net: Copy slab data for sendmsg(MSG_SPLICE_PAGES) Date: Wed, 24 May 2023 16:33:07 +0100 Message-Id: <20230524153311.3625329-9-dhowells@redhat.com> In-Reply-To: <20230524153311.3625329-1-dhowells@redhat.com> References: <20230524153311.3625329-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 If sendmsg() is passed MSG_SPLICE_PAGES and is given a buffer that contains some data that's resident in the slab, copy/coalesce it rather than returning EIO. Signed-off-by: David Howells cc: Eric Dumazet cc: "David S. Miller" cc: David Ahern cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- include/linux/skbuff.h | 3 +++ net/core/skbuff.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index e11a765fe7fa..11d98990f5f1 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -5084,6 +5084,9 @@ static inline void skb_mark_for_recycle(struct sk_buff *skb) #endif } +ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, + ssize_t maxsize, gfp_t gfp); + ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, ssize_t maxsize, gfp_t gfp); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c2840b0dcad9..a16499b9942b 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6927,17 +6927,44 @@ ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, break; } + if (space == 0 && + !skb_can_coalesce(skb, skb_shinfo(skb)->nr_frags, + pages[0], off)) { + iov_iter_revert(iter, len); + break; + } + i = 0; do { struct page *page = pages[i++]; size_t part = min_t(size_t, PAGE_SIZE - off, len); - - ret = -EIO; - if (WARN_ON_ONCE(!sendpage_ok(page))) + bool put = false; + + if (PageSlab(page)) { + const void *p; + void *q; + + p = kmap_local_page(page); + q = page_frag_memdup(NULL, p + off, part, gfp, + ULONG_MAX); + kunmap_local(p); + if (!q) { + iov_iter_revert(iter, len); + ret = -ENOMEM; + goto out; + } + page = virt_to_page(q); + off = offset_in_page(q); + put = true; + } else if (WARN_ON_ONCE(!sendpage_ok(page))) { + ret = -EIO; goto out; + } ret = skb_append_pagefrags(skb, page, off, part, frag_limit); + if (put) + put_page(page); if (ret < 0) { iov_iter_revert(iter, len); goto out;