* [PATCH] zram: fix slot lock bit position on big-endian 64-bit
@ 2026-08-10 20:22 David Carlier
2026-08-11 2:06 ` Sergey Senozhatsky
0 siblings, 1 reply; 2+ messages in thread
From: David Carlier @ 2026-08-10 20:22 UTC (permalink / raw)
To: Minchan Kim, Sergey Senozhatsky
Cc: Andrew Morton, linux-kernel, linux-block, stable, David Carlier
The slot lock is a bit operation on the whole __lock word, which
flags and ac_time alias as two u32s. On little-endian the lock bit
lands in the position ZRAM_ENTRY_LOCK reserves in flags, so the
aliasing works out. On 64-bit big-endian it lands in ac_time
instead: with ZRAM_TRACK_ENTRY_ACTIME enabled, storing the access
time from mark_slot_accessed() or slot_free() wipes out the held
lock bit, letting another CPU take the same slot lock; an access
time value with that bit set makes the slot look locked forever.
Shift the lock bit into the flags half of the word on big-endian
64-bit.
Fixes: 2e8ff2f51dde ("zram: use u32 for entry ac_time tracking")
Cc: stable@vger.kernel.org
Signed-off-by: David Carlier <devnexen@gmail.com>
---
drivers/block/zram/zram_drv.c | 6 +++---
drivers/block/zram/zram_drv.h | 14 ++++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index d09fdca49cbd..a9b3bb1d3bef 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -74,7 +74,7 @@ static __must_check bool slot_trylock(struct zram *zram, unsigned long index)
{
unsigned long *lock = &zram->table[index].__lock;
- if (!test_and_set_bit_lock(ZRAM_ENTRY_LOCK, lock)) {
+ if (!test_and_set_bit_lock(ZRAM_ENTRY_LOCK_BIT, lock)) {
mutex_acquire(&zram->table_lock_map, 0, 1, _RET_IP_);
lock_acquired(&zram->table_lock_map, _RET_IP_);
return true;
@@ -88,7 +88,7 @@ static void slot_lock(struct zram *zram, unsigned long index)
unsigned long *lock = &zram->table[index].__lock;
mutex_acquire(&zram->table_lock_map, 0, 0, _RET_IP_);
- wait_on_bit_lock(lock, ZRAM_ENTRY_LOCK, TASK_UNINTERRUPTIBLE);
+ wait_on_bit_lock(lock, ZRAM_ENTRY_LOCK_BIT, TASK_UNINTERRUPTIBLE);
lock_acquired(&zram->table_lock_map, _RET_IP_);
}
@@ -97,7 +97,7 @@ static void slot_unlock(struct zram *zram, unsigned long index)
unsigned long *lock = &zram->table[index].__lock;
mutex_release(&zram->table_lock_map, _RET_IP_);
- clear_and_wake_up_bit(ZRAM_ENTRY_LOCK, lock);
+ clear_and_wake_up_bit(ZRAM_ENTRY_LOCK_BIT, lock);
}
static inline bool init_done(struct zram *zram)
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 4fddc582f3b8..7a55d751417e 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -15,6 +15,7 @@
#ifndef _ZRAM_DRV_H_
#define _ZRAM_DRV_H_
+#include <asm/byteorder.h>
#include <linux/rwsem.h>
#include <linux/zsmalloc.h>
@@ -57,6 +58,19 @@ enum zram_pageflags {
__NR_ZRAM_PAGEFLAGS,
};
+/*
+ * The slot lock is a bit-wait lock on the whole __lock word, while
+ * flags and ac_time alias that word as two u32s. The lock bit must
+ * land in the slot that ZRAM_ENTRY_LOCK reserves in attr.flags; on
+ * 64-bit big-endian the flags word maps to the upper half of __lock,
+ * so the bit position has to be shifted up.
+ */
+#if defined(CONFIG_64BIT) && defined(__BIG_ENDIAN)
+#define ZRAM_ENTRY_LOCK_BIT (ZRAM_ENTRY_LOCK + 32)
+#else
+#define ZRAM_ENTRY_LOCK_BIT ZRAM_ENTRY_LOCK
+#endif
+
/*
* Allocated for each disk page. We use bit-lock (ZRAM_ENTRY_LOCK bit
* of flags) to save memory. There can be plenty of entries and standard
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] zram: fix slot lock bit position on big-endian 64-bit
2026-08-10 20:22 [PATCH] zram: fix slot lock bit position on big-endian 64-bit David Carlier
@ 2026-08-11 2:06 ` Sergey Senozhatsky
0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2026-08-11 2:06 UTC (permalink / raw)
To: David Carlier
Cc: Minchan Kim, Sergey Senozhatsky, Andrew Morton, linux-kernel,
linux-block, stable
On (26/08/10 21:22), David Carlier wrote:
> The slot lock is a bit operation on the whole __lock word, which
> flags and ac_time alias as two u32s. On little-endian the lock bit
> lands in the position ZRAM_ENTRY_LOCK reserves in flags, so the
> aliasing works out. On 64-bit big-endian it lands in ac_time
> instead: with ZRAM_TRACK_ENTRY_ACTIME enabled, storing the access
> time from mark_slot_accessed() or slot_free() wipes out the held
> lock bit, letting another CPU take the same slot lock; an access
> time value with that bit set makes the slot look locked forever.
>
> Shift the lock bit into the flags half of the word on big-endian
> 64-bit.
>
> Fixes: 2e8ff2f51dde ("zram: use u32 for entry ac_time tracking")
> Cc: stable@vger.kernel.org
> Signed-off-by: David Carlier <devnexen@gmail.com>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-11 2:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-10 20:22 [PATCH] zram: fix slot lock bit position on big-endian 64-bit David Carlier
2026-08-11 2:06 ` Sergey Senozhatsky
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.