Message ID | 20230331160914.1608208-9-dhowells@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 79BADC761A6 for <linux-mm@archiver.kernel.org>; Fri, 31 Mar 2023 16:09:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 182D76B0081; Fri, 31 Mar 2023 12:09:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 133776B0082; Fri, 31 Mar 2023 12:09:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3D736B0083; Fri, 31 Mar 2023 12:09:52 -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 E13126B0081 for <linux-mm@kvack.org>; Fri, 31 Mar 2023 12:09:52 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BAEE1120D40 for <linux-mm@kvack.org>; Fri, 31 Mar 2023 16:09:52 +0000 (UTC) X-FDA: 80629679424.26.2AB34A1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id D944780026 for <linux-mm@kvack.org>; Fri, 31 Mar 2023 16:09:50 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="LGx1/oyd"; spf=pass (imf30.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=1680278990; 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=4TWX2aSvGOZ9Qof5Bdvg67w1lje6zmFD7Oc0vC/yB3w=; b=Ok50b5YRkMhZOTodGjCk236HW2/mTp201QMjpb00qI4SGU1monuUUFoDlb7UwTDnhTOkdZ cMqUrPNFeZulGuoUpuECf9fLvLghUPeee/t5a6M7sZFeAhW6RBJcAS57zF9dZx9/U7voTH xt4JMyFGY7e55JbRxuhDU2pzqkn8p20= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="LGx1/oyd"; spf=pass (imf30.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680278990; a=rsa-sha256; cv=none; b=0jXBCbvp+oClTu399oJ7aYE0yePUDfeePIT3cY4jAuPp234Er5wvYW7i6kzkNVg5XtUdo9 STgBTJf3F4YM1Lg6OrFJlx9N+yqtYc9TKBkENjicQfVSthuoHog2mxLXvEIolXbuNgiPgy 5tIa5scQuGi7xY7P8vEN8JuhiciPwZI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680278990; 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=4TWX2aSvGOZ9Qof5Bdvg67w1lje6zmFD7Oc0vC/yB3w=; b=LGx1/oydwBRFOMRKacTWCY/Jp6hyFPRNpEcwUHEwsB/CwiZZz4AGiXRQmI8qVt6qspuUTz pB10ldEqzoYartoOqbja+xWCQB2j4GRPIIwTh3AjqzDVl68jJyQ7fhqW6YJ9A2nOY6G/xY DUxciUifpbEFhpu9G/Ika9Fkrx5xodE= 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-496-oMyBzLXdOyeTBAtGXK8UWA-1; Fri, 31 Mar 2023 12:09:45 -0400 X-MC-Unique: oMyBzLXdOyeTBAtGXK8UWA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A431F85A5A3; Fri, 31 Mar 2023 16:09:44 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C01FC492C3E; Fri, 31 Mar 2023 16:09:42 +0000 (UTC) From: David Howells <dhowells@redhat.com> To: Matthew Wilcox <willy@infradead.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: David Howells <dhowells@redhat.com>, Al Viro <viro@zeniv.linux.org.uk>, Christoph Hellwig <hch@infradead.org>, Jens Axboe <axboe@kernel.dk>, Jeff Layton <jlayton@kernel.org>, Christian Brauner <brauner@kernel.org>, Chuck Lever III <chuck.lever@oracle.com>, Linus Torvalds <torvalds@linux-foundation.org>, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 08/55] tcp: Make sendmsg(MSG_SPLICE_PAGES) copy unspliceable data Date: Fri, 31 Mar 2023 17:08:27 +0100 Message-Id: <20230331160914.1608208-9-dhowells@redhat.com> In-Reply-To: <20230331160914.1608208-1-dhowells@redhat.com> References: <20230331160914.1608208-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D944780026 X-Stat-Signature: pr8999gyu1bctmiengdq44ugp5nc47kh X-Rspam-User: X-HE-Tag: 1680278990-809573 X-HE-Meta: U2FsdGVkX18yJ5ta8KEv5wMr0lwwzyf//LQIfiKd0FnwmP0if74WDgeOAnT3gyGeXp9x0cleISlyTZvMWWF6AoK0tnt7YTebvRpT6m8wyH3Y09CrIdT+qQ2e6aHP8x22jPpsz13CA2kFUTzEAkC5iEjEjJrUu9rpxmTL+cdJ0r0IweQlnbDPgePTCRjvqYkU/M5/cmvHpGMPiD5ix8lWVBSdykDbF1LMJDMEZqvxaCQIzyMlCTQ1OdRUyD4Wal39bW3LNPC2gfPplNU45RaA2cn3VgWO7S3tCmspNFqZ1tfceFEH0UmAldgqmSPBTAG1jBx/pB/605uk+7QvXQcQtuztmaGbV1WRvqPwJUB+tz6P4mwejRI+bv7rEqEJ4JkUqnZHFV2nZ/k3X4/A27zD7pSQtW1/qa8KoscZfDGXL77c/wABNSRT67GXr1j93VPeSCxykPkjPR9XQpiQtg04y/SGtjnu23YfaQnf/weC5orQ11Gily+XDq9CO7kqhZYOwfRjsQ6Rgm+/JMo4TZWztwkk2V00LaF5xIxIlAm01e6AGCXVWLvKK9+R8IYgUUGLy432uJtF+AbsfzLsY3nhIeym33pSWM/iCaK5ewoodWvKOhUy6u5Zf+Wo+L/21TNXUWt8nLMBR53Vive654fn3G0+8+Dt+7Riss2Fh/LlgksyikYKz2znfWwGI6LX7KCiLbJRruUkQkz2iKVlN5XMqoc/i2MzM4KP9ZYwfDy15r7FHuf3UNMcGEWGjGdW6ItxtczU21Vl2iHnBFgZoPZgwqGAlZHndmhYQUEKrNEvcaeihNpfySKkWs94+QfYw4REznWWv339KP3+8Md6RRYYeSp2utkUMalTjbs4PGto7M0IxhmjGhabEsQoksp2HX/2FkWyrtVPufxVqf2SmfWRnI+/N0JIuxxyd1F+k5jPyZQ9tpYa0cfKkeFEfdBs0Aun1s/CwE9e+JfMmoLNgMj 3fKE27Nk We3aiGx692jaSWPt4LSN5hA1SWnFPKvdz5LCC2kLSGnoqJM7CMXNSLxFasx1Sgl4j7e8bJpWhQKYH+wS/bzJFyXLG/sWEeEU5jJEXGbEaK03sxxyx4AHl7w2slW63UqPv2XtRBqBPD9hFvFaBLeSYeDfIRVILyweWbG3q5etMPwODJXlORt8WGRJtb3e2C7qzxSmACjO1YwJNCikNzd2Y6hVs1UX0ps5E4u5qlKaOUvz8OJ22Zwy+ToJ9U6aMvHlQOWdOYBMRqKh21banarzlP7ponft9CO1gU6GFI1NmKusmJSgtGXjVF1/gragaKICrjsM1l9Ot0mQ2M3kdhT410jjTITTxT1hNV69GYwQ9DLS5zAPawbmO0uc2URo3yq0rCppySihOMRs+tUNPV6x6XKMmzwaxOIFqojUeud+yRzaStRe0U5LPadCBxhrrt5InQjFi 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: <linux-mm.kvack.org> |
Series |
splice, net: Replace sendpage with sendmsg(MSG_SPLICE_PAGES)
|
expand
|
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 910b327c236e..6ef0518eb706 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1417,10 +1417,10 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) goto do_error; copy = err; } else if (zc == 2) { - /* Splice in data. */ + /* Splice in data if we can; copy if we can't. */ struct page *page = NULL, **pages = &page; size_t off = 0, part; - bool can_coalesce; + bool can_coalesce, put = false; int i = skb_shinfo(skb)->nr_frags; copy = iov_iter_extract_pages(&msg->msg_iter, &pages, @@ -1447,12 +1447,34 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) goto wait_for_space; copy = part; + if (!sendpage_ok(page)) { + const void *p = kmap_local_page(page); + void *q; + + q = page_frag_memdup(NULL, p + off, copy, + sk->sk_allocation, ULONG_MAX); + kunmap_local(p); + if (!q) { + iov_iter_revert(&msg->msg_iter, copy); + err = copy ?: -ENOMEM; + goto do_error; + } + page = virt_to_page(q); + off = offset_in_page(q); + put = true; + can_coalesce = false; + } + if (can_coalesce) { skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); } else { - get_page(page); + if (!put) + get_page(page); + put = false; skb_fill_page_desc_noacc(skb, i, page, off, copy); } + if (put) + put_page(page); page = NULL; if (!(flags & MSG_NO_SHARED_FRAGS))
If sendmsg() with MSG_SPLICE_PAGES encounters a page that shouldn't be spliced - a slab page, for instance, or one with a zero count - make tcp_sendmsg() copy it. Signed-off-by: David Howells <dhowells@redhat.com> cc: Eric Dumazet <edumazet@google.com> cc: "David S. Miller" <davem@davemloft.net> cc: Jakub Kicinski <kuba@kernel.org> cc: Paolo Abeni <pabeni@redhat.com> cc: Jens Axboe <axboe@kernel.dk> cc: Matthew Wilcox <willy@infradead.org> cc: netdev@vger.kernel.org --- net/ipv4/tcp.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)