From patchwork Wed May 24 15:33:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254202 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 6B6D0C77B7C for ; Wed, 24 May 2023 15:33:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEC0A900017; Wed, 24 May 2023 11:33:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9C5A900007; Wed, 24 May 2023 11:33:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3D23900017; Wed, 24 May 2023 11:33:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C222F900007 for ; Wed, 24 May 2023 11:33:52 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6CCFC160A47 for ; Wed, 24 May 2023 15:33:52 +0000 (UTC) X-FDA: 80825543904.05.7D4C953 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id ACBCB40002 for ; Wed, 24 May 2023 15:33:50 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QP6BAEVx; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1684942430; 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=PZf0byHPp2E2QKGUTDTD+TlMjPhCnr7dpojTO1v28qY=; b=kbd6/L9mV4fOFkAS+N8UXX9IfmASRJ2mYiUKD8AnC5XO2s38frgjTyGc2kzlevLP2Y/vfM gcg/Bs4wvOTohX5sWamXFIUbceF9OctRxTw8nL+mgtu7jtqrlbXRt8+PR8PHd6BA1VjHgK N4wQGg7ntXl2YHYKIUPVqorkgVJvcjo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684942430; a=rsa-sha256; cv=none; b=AzN1RJ4ZoWosRVyw+fwSAkeE8G2UODweo8P/fgRX/WJAnFkOi8BKKG38TxP4SWdTpP47mR VpBs/r39/SmVUZgIn/i4X6ZZt/5FmjgFaHkmzMG2WfWZ2NS+dgizOiwoaPrZb3waETSrGY KPvWHCQzcA5Pz0N1liD1fTh7BzwPaqA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QP6BAEVx; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1684942429; 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=QP6BAEVxhqStJDRIg9Zth49eUjEOhXJ9poYwY1oF0Jz1xXTMrLuHNgGdlH4ykykXCaBNZG IqTUC72W8bSihIpjAzgMScHkWCVAlPXKpUis7LEQ9XtJ8oBXe4iEg3aPfzdVlfWb5Ih0G2 F+OzZvMHtiAKlxi4HLV16IJWWtErmJs= 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 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Stat-Signature: 4ucprwpjso8ds5pbibmws67wbe4fmgmw X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: ACBCB40002 X-Rspam-User: X-HE-Tag: 1684942430-555625 X-HE-Meta: U2FsdGVkX1+U3ZgJ5zIn6BmUBdwiOQzMckQJ6RM7sa9SbPJSWzkoMZOUrLIsPk4arpS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j1bWbMhTg6u1iaaYTRRXvEz8vP8T41SbTjyDnDMajJqBUiKSsZK208C0/RW7S75sz44UBxW+sSyAL4CKW5ADbkD/o4S9RMjfnPqwDuibou24piOrd9L5s1LsxSmU8hwC3IYSwkchLt+yZCU6vyCN57Y1sbi2lxvSKNWW36b7dEHg7B1faxJ7xuejIGfHv4ifCNtZnfBMjNzVSvPcEby5rsQPO0W3hgrLBlNF2fzwYEFn14CpJARyO9pU5YTlZvRUxEVUptNUAdFGrBmaRiiE0Bku3O1c+geF0eyvnpzUN1HvkH0fGHkWZVvRoufWWuTvrRz7bPbfe8DfX66uJns2xcbR32BQk8zvS8Q== 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: 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;