From patchwork Mon Feb 27 14:23:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13153635 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 AB96AC64ED8 for ; Mon, 27 Feb 2023 14:23:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3785D6B0074; Mon, 27 Feb 2023 09:23:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3287D6B0075; Mon, 27 Feb 2023 09:23:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 216A86B0078; Mon, 27 Feb 2023 09:23:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 126A16B0074 for ; Mon, 27 Feb 2023 09:23:42 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D85A3120A91 for ; Mon, 27 Feb 2023 14:23:41 +0000 (UTC) X-FDA: 80513290242.17.EC25CBF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 01E3440027 for ; Mon, 27 Feb 2023 14:23:38 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aR09RFZW; spf=pass (imf04.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=1677507819; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=yg76FnkX04HHXW1mHvn8i4mIGRu2T9NZWGFYq1EPWQo=; b=aB4OcdPpvlexpbJnO+VLp8CFS1t3JtcwwI79ONTB74+IjZO3UF4aprO6e3PvpFLQPydFYJ 9N/kd+sP9u3dXXh8WlcNPWySroxu0pwK0+9omayEfBq5hC/dHNd6tk3s9q7Ll1NcF3O21I uIyF9RwdKyQ6XO437xnY3Qrg9ow0Exs= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aR09RFZW; spf=pass (imf04.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=1677507819; a=rsa-sha256; cv=none; b=hVVkSN8ZgLYw4vlIusUWmkrUaH7kAd7/9EJXrvra4cYn5mdco5GoqLUxxoIV/YtdemZAAN uoDS4HaJffDE1dHTdj+6jyFfC6cxBPTmMv898AP6XrOTIHoJAamcns08u2CK65gaqrM3qb JsLwhAR5GXdCUooDVFOyvt6oXHoEqJY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677507818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yg76FnkX04HHXW1mHvn8i4mIGRu2T9NZWGFYq1EPWQo=; b=aR09RFZWrkjcDe/YOiY9MZhnVZLZMXBpgMJeJN2MtsUtKHaItzNyGTeANxcBcilmAdDssD SitUDqmAOPJyAAEkKF5Rlz7gUN9/lPB8itijd7G8SpivoTT6c6/M0e/D8hOaAwKxKffNL5 MsebBCCBVPukHFJQtWZUfsgoV2GXVbs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-7dPZkuwNNC6edyeI5CsAig-1; Mon, 27 Feb 2023 09:23:35 -0500 X-MC-Unique: 7dPZkuwNNC6edyeI5CsAig-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A5291C0418D; Mon, 27 Feb 2023 14:23:34 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FFABC15BAD; Mon, 27 Feb 2023 14:23:33 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells To: Matthew Wilcox , Miklos Szeredi , Amit Shah cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC][PATCH] splice: Prevent gifting of multipage folios MIME-Version: 1.0 Content-ID: <2734057.1677507812.1@warthog.procyon.org.uk> Date: Mon, 27 Feb 2023 14:23:32 +0000 Message-ID: <2734058.1677507812@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: 01E3440027 X-Stat-Signature: idz6hmi49smy8ytuqj4yjksit9i9j7eb X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677507818-740362 X-HE-Meta: U2FsdGVkX19wLAJ6we2WgKvdm2uWx/zfAIdbDFtM0Ple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YL4njiFZklP8XVNhdRxdy5WdSrce8C9kKoZDkoRsNrlJIlvu7yn4IcLESjy1QYwLLOS3avWpnT5fmeFL7PZIDiHynp1fw4dY9tyWqScQsTHAanA+SDVAwyRzXvaJiIQbEwavYWnV+RANvEGD1N3jQCXrX9pYRnbUzBmpkZNJK7cU+p1ABl4wU1FdwFgp2o/fXpAfNpKBcJ6XajbxLShdu8qcg5RqO0Gxs0+IdMQBp0a/qywuwd7/BP+w5dJrXOzBEaJqlHO1TFyRo5u9qNml1jgdHz5C6r62zVrj8v/bTXA= 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: Don't let parts of multipage folios be gifted by (vm)splice into a pipe as the other end may only be expecting single-page gifts (fuse and virtio console for example). replace_page_cache_folio(), for example, will do the wrong thing if it tries to replace a single paged folio with a multipage folio. Try to avoid this by making add_to_pipe() remove the gift flag on multipage folios. Signed-off-by: David Howells cc: Matthew Wilcox cc: Miklos Szeredi cc: Amit Shah cc: linux-fsdevel@vger.kernel.org cc: virtualization@lists.linux-foundation.org cc: linux-mm@kvack.org --- fs/splice.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/splice.c b/fs/splice.c index 2e76dbb81a8f..33caa28a86e4 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -240,6 +240,8 @@ ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf) } else if (pipe_full(head, tail, pipe->max_usage)) { ret = -EAGAIN; } else { + if (folio_nr_pages(page_folio(buf->page)) > 1) + buf->flags &= ~PIPE_BUF_FLAG_GIFT; pipe->bufs[head & mask] = *buf; pipe->head = head + 1; return buf->len;