From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796217520; b=xJqfz9iKMtIyCkY6M1moTfT3i4Tob8T62pfMi4KqiilMLUw6v2Av2WyEB8vOIfn80qcs RjGQ0e3uw2xh/prC9LLYFG31UgYP0uET/ofEdz3lk148eyrCX0bMOTrh5sMIUYJap7cs/ HzQOnfk96/wpBxgC8oehfo8Rh1RCTg6IuKxrHlOdAhlYzyTqac5wVsyJtCT5PidVJoGX2 rsyf4dGcW7qPGL7RNa518cCFXfu0u6dftRcvrzD/gbe2RKTeKsMct3DtdFKPH5sCBBA0W Iz2lwk/zVZT+Y1WzVjduMc1vYq8i8/nfgsFIDdlaKCoJii613DYkfUN9w2nlhZIa6yg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796217520; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=WU/V+SEnzzrCKRGjvaFaM2QJb29RSfms1VQquZEBMtQ=; b=ZmrFKsZwK21a1/eT9qUBJVET93IFIp7z6cLY50aZamKVx17zkn0T6GBVDdNOgHcJ2ZTH JL02exx+8oWKIN5C6U9JMt1VJW99PqchUvGy+tbFuGNykZ14mPOsH1DgxTmooh+R5bloq JM+JySqaw0ms+6uLUpo82ZIocJfT3TDGAm8uI1xBxeVbLWE6GdlARfMW+cxkP7KwpYotb VE2HacoTNWy6bv9VOm8Pw7WqxTg3SJV7JxdhTwXYwz6id6d/fBIQOTjjAh8PQcYJhskhe WRtonvhj83gPNFWWaAAeKV0WFiQObr7x/CNvBifwWD3cRXPa5q/GtolmYUk/Thqipxw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eTjYnhAZ; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E7C4606A337; Wed, 2 Dec 2026 13:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eTjYnhAZ Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796217520; b=asqn/6DeIiJ4XERtLtHIjKn8liQGczfvLM9571zsG4qYSQpsN+cDM/qt0TvSVp2R1sLK W5UY1/X8xvnoUOzBJk2LHU7h8gvM/BYMQmaTfpeDPUUa0Wom8bAdVvB6mIHErUc7Pn99P /djxyKpzgrLV6w0/re+1c1CVP6WuL/TrvmtEbVRSaehMyDZBDcZmO/AvAlhGOKM8UUCWd kptYHo5HLLXinYvx+zWH30X+IAqwDvk4EWGPpJOicwZ7s/LRxpotvkJda1DDcGRovL09x quHlWuIdIEvXgFb5PzmEeP6r1E0P5n6ha/uhVRcuCY7eRzJKmum6hRTFDg4DNVXyAoQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796217520; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=WU/V+SEnzzrCKRGjvaFaM2QJb29RSfms1VQquZEBMtQ=; b=z9ejIR49mYi4e3oyfCjARi1NiHiwzllBLBz4Kf0/kssmJu7+rUARbJbXwfwkt/Z6Ktc9 JVd9TecEvYp+tiNTidFJsu4KuzggLzZzveltmiDYAdGc7JKzzkdKgL6PR9zzNGY/x9Pt5 9JzJBD+iIuv34NWfZ36K72XqejZaxXZVmz9ZoC/bX2HIf43pOVENyCddWfPJSxnsiwtRR Y8Yu7YU5+r6kqIQ/OXB90K9auhgrpASIFx6bZNf2VkOmUNZlDCG4ZmI1eVH4zewrgFYzs wEGWGZQMPN/OZgcyY2K+zPabUROH6n1T1NnAe8f8Io2nTz2bJ1nzzbAwTbcJ7tFN+CQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 7B76F1F000C1; Wed, 2 Dec 2026 13:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796217520; bh=WU/V+SEnzzrCKRGjvaFaM2QJb29RSfms1VQquZEBMtQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=eTjYnhAZEyMkwUDETVhfpG1+p8kU4180mJqWAmFm46Un74oft17CYoxXEjxDz43ks mFZy5NfVBba2rp34Z7YnBwy1SU5Ds42x40U9OIookRAQa8i0w3n9IktUyk64Fnm45F JPlYRvLzyUl2ZezqmsJlOe9xDug2oGRC4s1dEMwSg7gzpFCcSHvI5M5Ts67bbF23yl sx4nzsxm069hxADr5+h933QpTTf0HIzA4qWrWmKlNHP5YW5I8l/ZSw0th0tz88KFIL jQdbdJH/S79HF0dfG0pWPWuCQZx5fW7E1MepR0lScum98LwMBru57CO//mor4frP9R INg+AAnXS8Apg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 0A7EB4F41B; Wed, 2 Dec 2026 13:18:32 +0000 (UTC) From: Xiubo Li via B4 Relay Date: Wed, 02 Dec 2026 14:18:20 +0100 Subject: [PATCH v3 1/3] ceph: do not read ahead on an mmap fault without Fc X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261202-ceph-append-excl-v3-1-68fdbef33f32@clyso.com> References: <20261202-ceph-append-excl-v3-0-68fdbef33f32@clyso.com> In-Reply-To: <20261202-ceph-append-excl-v3-0-68fdbef33f32@clyso.com> To: Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Anthony D'Atri , Xiubo Li X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796217507; l=3437; i=xiubo.li@clyso.com; s=20260625; h=from:subject:message-id; bh=BBAFrI3BKcwBa18DsjULW6cdSvYY9YQs79FFqzdS5gA=; b=7aq5uzcuXFlQ89NVZxtenk0dNkiVG3IIS2NMcVrT2nqiP6OUgj6bghGMW8IHwNrKyzkkBWkqT xCbGgKhMi0aDK4G/e9uasUwuczBsJlXfBibkHm9KkQFLHzW5OLGHlGD X-Developer-Key: i=xiubo.li@clyso.com; a=ed25519; pk=V3NGr0AgAopiUhaLY51ipBkLN5LlcLhjOEfLEq1RoZ8= X-Endpoint-Received: by B4 Relay for xiubo.li@clyso.com/20260625 with auth_id=840 X-Original-From: Xiubo Li Reply-To: xiubo.li@clyso.com Content-Transfer-Encoding: 7bit From: Xiubo Li ceph_filemap_fault() faults a page in through filemap_fault() also when it got Fr but not Fc, e.g. while another client writes the file and the filelock is in MIX. It registers an rw context first, and ceph_init_request() lets every request with such a context through, so the read-around of that fault fills the page cache with the folios next to the faulting one as well, without Fc. Nothing drops those folios: we do not hold Fc, so no revoke of it invalidates them when another client writes the file. Once we get Fc and Fb again, a buffered write into one of them uses it as it is and writes the whole folio back, with the old data over what the other client wrote in between. Seen with an mmap writer on one client while two clients took turns appending to the file: on every turn change a few records of the other client were overwritten with zeroes; with MADV_RANDOM on the mapping (no read-around) none were. Fail the readahead of a request whose rw context holds neither Fc nor LAZYIO, as when there is no rw context at all: the fault then reads only the folio it needs. Tested on a vstart cluster, KASAN and lockdep enabled, two mounts, 4 O_APPEND writers on each taking turns on Fx (patch 3 of this series), 150 records of 64 bytes per writer, and an mmap writer rewriting the first page of the file on one of the mounts: +--------------------------------------+------+-------------------+ | case | runs | records zeroed | +--------------------------------------+------+-------------------+ | without this patch | 12 | 62-88 of 1200 | | without this patch, MADV_RANDOM | 4 | 0 | | with this patch | 3 | 0 | +--------------------------------------+------+-------------------+ Signed-off-by: Xiubo Li --- fs/ceph/addr.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 49b58f85dc17..d14121694051 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -754,6 +754,7 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file) struct ceph_file_info *fi = file ? file->private_data : NULL; int got = 0, want = CEPH_CAP_FILE_CACHE; struct ceph_netfs_request_data *priv; + struct ceph_rw_context *rw_ctx; int ret = 0; /* [DEPRECATED] Use PG_private_2 to mark folio being written to the cache. */ @@ -775,7 +776,22 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file) * ceph_read_iter() and ceph_filemap_fault() hold caps and * register an rw context before entering the page cache. */ - if (ceph_find_rw_context(fi)) { + rw_ctx = ceph_find_rw_context(fi); + if (rw_ctx) { + /* + * ceph_filemap_fault() may hold Fr only. Then read + * just the folio that faulted, not ahead of it: no + * revoke of Fc would drop the folios read ahead when + * another client writes the file, and once we get + * Fc and Fb a buffered write would write them back + * stale over that client's data. + */ + if (rreq->origin == NETFS_READAHEAD && + !(rw_ctx->caps & (CEPH_CAP_FILE_CACHE | + CEPH_CAP_FILE_LAZYIO))) { + ret = -EACCES; + goto out; + } rreq->netfs_priv = priv; return 0; } -- 2.53.0