From: Kefu Chai <k.chai@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH ceph tentacle-stable-9] patches: fix stale reads after cache invalidation on optimized EC pools
Date: Mon, 23 Nov 2026 19:26:05 +0800 [thread overview]
Message-ID: <20261123112605.6-1-k.chai@proxmox.com> (raw)
On pools with allow_ec_optimizations, a partial write queued behind a
clone, rollback or shrinking truncate can read the old shard contents.
The write merges those bytes into the object and calculates parity from
them, so the corruption can go undetected. An early read past the old
object size can also abort the primary OSD.
Carry both commits from the upstream Tentacle backport. The first keeps
holes pinned until the write that grows the object completes. The second
defers queued reads until the invalidating write has been issued and the
cache has its new size.
Link: https://tracker.ceph.com/issues/81754
Link: https://tracker.ceph.com/issues/81315
Link: https://github.com/ceph/ceph/pull/74172
Signed-off-by: Kefu Chai <k.chai@proxmox.com>
---
...-cache-line-covered-by-a-growth-hole.patch | 81 +++++++++++
...d-reads-until-the-invalidating-write.patch | 126 ++++++++++++++++++
patches/series | 2 +
3 files changed, 209 insertions(+)
create mode 100644 patches/0021-osd-pin-every-extent-cache-line-covered-by-a-growth-hole.patch
create mode 100644 patches/0022-osd-ECExtentCache-hold-replayed-reads-until-the-invalidating-write.patch
diff --git a/patches/0021-osd-pin-every-extent-cache-line-covered-by-a-growth-hole.patch b/patches/0021-osd-pin-every-extent-cache-line-covered-by-a-growth-hole.patch
new file mode 100644
index 0000000000..3bf7d9c872
--- /dev/null
+++ b/patches/0021-osd-pin-every-extent-cache-line-covered-by-a-growth-hole.patch
@@ -0,0 +1,81 @@
+From 17cc0a908286023cfb1c793240fc3f80b5463be6 Mon Sep 17 00:00:00 2001
+From: Alex Ainscow <aainscow@uk.ibm.com>
+Date: Fri, 2 Oct 2026 09:09:06 +0100
+Subject: [PATCH 1/2] osd: Pin every extent cache line covered by a growth hole
+
+When an op grows an object, Object::request() adds the gap between the
+old and new projected size to do_not_read, so later ops do not read
+data that is not yet on disk. do_not_read entries are erased a line at a
+time when the last op pinning the line dies, but the growing op only
+pinned the lines of its own reads and writes.
+
+An older op pinning a line inside the hole could therefore die first and
+erase that part of the hole while the growing op was still waiting for
+its cache_ready, before current_size was updated. A following op would
+then send reads in the hole with the old current_size, none survived the
+read mask, and do_read_op hit ceph_assert(reads_sent).
+
+Pin every line the hole spans, so that it lives until the growing op
+completes.
+
+Fixes: https://tracker.ceph.com/issues/81315
+Assisted-by: Claude Code
+Signed-off-by: Alex Ainscow <aainscow@uk.ibm.com>
+(cherry picked from commit 844125a0e51618a5491f8154bdceb094dc650b9a)
+---
+ src/osd/ECExtentCache.cc | 34 ++++++++++++++++++++--------------
+ 1 file changed, 20 insertions(+), 14 deletions(-)
+
+diff --git a/src/osd/ECExtentCache.cc b/src/osd/ECExtentCache.cc
+index b5c7e7636f24..8cf04e46237f 100644
+--- a/src/osd/ECExtentCache.cc
++++ b/src/osd/ECExtentCache.cc
+@@ -19,6 +19,25 @@ void ECExtentCache::Object::request(OpRef &op) {
+
+ extent_set eset = op->get_pin_eset(line_size);
+
++ shard_extent_set_t obj_hole(pg.sinfo.get_k_plus_m());
++ if (op->projected_size > projected_size) {
++ /* This write is growing the size of the object. This essentially counts
++ * as a write (although the cache will not get populated). Future reads
++ * to this area will be skipped, but this makes them essentially zero
++ * reads. The op pins every line in the hole so that erase_line() cannot
++ * discard it before this op completes.
++ */
++ shard_extent_set_t read_mask(pg.sinfo.get_k_plus_m());
++
++ pg.sinfo.ro_size_to_read_mask(op->projected_size, obj_hole);
++ pg.sinfo.ro_size_to_read_mask(projected_size, read_mask);
++ obj_hole.subtract(read_mask);
++
++ extent_set hole_eset = obj_hole.get_extent_superset();
++ hole_eset.align(line_size);
++ eset.union_of(hole_eset);
++ }
++
+ for (auto &&[start, len] : eset) {
+ for (uint64_t to_pin = start; to_pin < start + len; to_pin += line_size) {
+ LineRef l;
+@@ -73,20 +92,7 @@ void ECExtentCache::Object::request(OpRef &op) {
+ do_not_read.insert(requesting);
+ }
+ do_not_read.insert(op->writes);
+- if (op->projected_size > projected_size) {
+- /* This write is growing the size of the object. This essentially counts
+- * as a write (although the cache will not get populated). Future reads
+- * to this area will be skipped, but this makes them essentially zero
+- * reads.
+- */
+- shard_extent_set_t obj_hole(pg.sinfo.get_k_plus_m());
+- shard_extent_set_t read_mask(pg.sinfo.get_k_plus_m());
+-
+- pg.sinfo.ro_size_to_read_mask(op->projected_size, obj_hole);
+- pg.sinfo.ro_size_to_read_mask(projected_size, read_mask);
+- obj_hole.subtract(read_mask);
+- do_not_read.insert(obj_hole);
+- }
++ do_not_read.insert(obj_hole);
+
+ projected_size = op->projected_size;
+
+
diff --git a/patches/0022-osd-ECExtentCache-hold-replayed-reads-until-the-invalidating-write.patch b/patches/0022-osd-ECExtentCache-hold-replayed-reads-until-the-invalidating-write.patch
new file mode 100644
index 0000000000..d943699beb
--- /dev/null
+++ b/patches/0022-osd-ECExtentCache-hold-replayed-reads-until-the-invalidating-write.patch
@@ -0,0 +1,126 @@
+From d81512a27165feed373eba710c7b69f0244d6717 Mon Sep 17 00:00:00 2001
+From: Alex Ainscow <aainscow@uk.ibm.com>
+Date: Wed, 14 Oct 2026 09:10:14 +0100
+Subject: [PATCH 2/2] osd/ECExtentCache: hold replayed reads until the
+ invalidating write
+
+An op that invalidates the extent cache (a clone or rollback onto the
+object, a remove and recreate, a shrinking truncate) waits at the head of
+the queue for the object's reads, then invalidate() clears the cache and
+replays every op queued on the object. The replayed ops' reads are sent
+straight away, but the invalidating op's write is only issued once all
+the cache ops of its transaction are ready, after them. Unless the
+invalidating op has reads of its own, the queued ops therefore read the
+object as it was before it: the old data instead of the clone's, or
+instead of the zeros a truncate or recreate leaves, which they write back
+into the parts of their pages they do not overwrite. Reads past the old
+size are dropped by the read mask, so a queued op that only reads there
+hits ceph_assert(reads_sent).
+
+Hold the reads of the ops replayed behind the invalidating op until
+write_done() for it. That runs after its sub-writes have been sent, and
+sets current_size to the size the reads are made against.
+
+a970eae8efa (since reverted) avoided the assert by replaying from
+current_size, which makes the growth to the invalidating op's size a
+hole. For a clone or rollback that region holds the source's data, which
+the queued ops replaced with zeros.
+
+Fixes: https://tracker.ceph.com/issues/81754
+Assisted-by: Claude Code
+Signed-off-by: Alex Ainscow <aainscow@uk.ibm.com>
+(cherry picked from commit 367d236aa7564d796fe4a73a10562eadc7ac5f4a)
+---
+ src/osd/ECExtentCache.cc | 20 ++++++++++++++------
+ src/osd/ECExtentCache.h | 6 ++++--
+ 2 files changed, 18 insertions(+), 8 deletions(-)
+
+diff --git a/src/osd/ECExtentCache.cc b/src/osd/ECExtentCache.cc
+index 8cf04e46237f..ab4d8fa5c49d 100644
+--- a/src/osd/ECExtentCache.cc
++++ b/src/osd/ECExtentCache.cc
+@@ -105,7 +105,7 @@ void ECExtentCache::Object::request(OpRef &op) {
+ }
+
+ void ECExtentCache::Object::send_reads() {
+- if (reading || requesting.empty())
++ if (reading || invalidate_write_pending || requesting.empty())
+ return; // Read busy
+
+ reading_ops.swap(requesting_ops);
+@@ -152,9 +152,14 @@ void ECExtentCache::Object::insert(shard_extent_map_t const &buffers) const {
+ }
+
+ void ECExtentCache::Object::write_done(shard_extent_map_t const &buffers,
+- uint64_t new_size) {
++ uint64_t new_size,
++ bool did_invalidate) {
+ insert(buffers);
+ current_size = new_size;
++ if (did_invalidate) {
++ invalidate_write_pending = false;
++ send_reads();
++ }
+ }
+
+ void ECExtentCache::Object::unpin(Op &op) const {
+@@ -198,9 +203,9 @@ void ECExtentCache::Object::invalidate(const OpRef &invalidating_op) {
+ requesting_ops.clear();
+ reading_ops.clear();
+
+- /* Current size should reflect the actual size of the object, which was set
+- * by the previous write. We are going to replay all the writes now, so set
+- * the projected size to that of this op.
++ /* Replay from the size the invalidating op leaves. What it leaves (a clone,
++ * or the zeros of a truncate or recreate) is only on disk once its write
++ * has been issued, so the reads of the ops behind it wait for write_done().
+ */
+ projected_size = invalidating_op->projected_size;
+
+@@ -210,11 +215,14 @@ void ECExtentCache::Object::invalidate(const OpRef &invalidating_op) {
+
+ cache_invalidate_expected = false;
+
+- // We now need to reply all outstanding ops to regenerate the read
++ /* We now need to replay all outstanding ops to regenerate the read. The
++ * invalidating op is the first, and the only one whose reads are sent now.
++ */
+ for (auto &op : pg.waiting_ops) {
+ if (op->object.oid == oid) {
+ op->read_done = false;
+ request(op);
++ invalidate_write_pending = true;
+ }
+ }
+ }
+diff --git a/src/osd/ECExtentCache.h b/src/osd/ECExtentCache.h
+index 50e6e23c0fc2..c31af1d7a0b5 100644
+--- a/src/osd/ECExtentCache.h
++++ b/src/osd/ECExtentCache.h
+@@ -209,7 +209,7 @@ class ECExtentCache {
+ }
+
+ void write_done(ECUtil::shard_extent_map_t const &update) const {
+- object.write_done(update, projected_size);
++ object.write_done(update, projected_size, did_invalidate_cache);
+ for (auto &cb: on_write) {
+ cb();
+ }
+@@ -238,6 +238,7 @@ class ECExtentCache {
+ uint64_t line_size = 0;
+ bool reading = false;
+ bool cache_invalidate_expected = false;
++ bool invalidate_write_pending = false;
+
+ void request(OpRef &op);
+ void send_reads();
+@@ -260,7 +261,8 @@ class ECExtentCache {
+ }
+
+ void insert(ECUtil::shard_extent_map_t const &buffers) const;
+- void write_done(ECUtil::shard_extent_map_t const &buffers, uint64_t new_size);
++ void write_done(ECUtil::shard_extent_map_t const &buffers, uint64_t new_size,
++ bool did_invalidate);
+ void read_done(ECUtil::shard_extent_map_t const &result);
+ [[nodiscard]] uint64_t get_projected_size() const { return projected_size; }
+ ECUtil::shard_extent_map_t get_cache(
diff --git a/patches/series b/patches/series
index 35163af86a..1b293638e6 100644
--- a/patches/series
+++ b/patches/series
@@ -18,3 +18,5 @@
0018-mon-record-which-key-authenticated-a-session.patch
0019-osd-ECTransaction-truncate-padded-shards-of-legacy-E.patch
0020-mon-AuthMonitor-link-the-PVE-cephx-migration-docs-in.patch
+0021-osd-pin-every-extent-cache-line-covered-by-a-growth-hole.patch
+0022-osd-ECExtentCache-hold-replayed-reads-until-the-invalidating-write.patch
--
2.47.3
reply other threads:[~2026-11-23 11:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123112605.6-1-k.chai@proxmox.com \
--to=k.chai@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.