bcachefs-tools/include/linux
Brian Foster f76c449ec0 bcachefs-tools: fix endian problems between bit spinlocks and futexes
bcachefs format on a big-endian (s390x) machine crashes down in the
rhashtable code imported from the kernel. The reason this occurs
lies within the rht_lock() -> bit_spin_lock() code, the latter of
which casts bitmaps down to 32-bits to satisfy the requirements of
the futex interface.

The specific problem here is that a 64 -> 32 bit cast doesn't refer
to the lower 8 bytes on a big endian machine, which means setting
bit number 0 in the 32-bit map actually corresponds to bit 32 in the
64-bit map. The rhashtable code specifically uses bit zero of the
bucket pointer for exclusion and uses native bitops elsewhere (i.e.
__rht_ptr()) to identify NULL pointers. If bit 32 of the pointer is
set by the locking code instead of bit 0, an otherwise NULL pointer
looks like a non-NULL value and results in a segfault.

The bit spinlock code imported by the kernel is originally intended
to work with unsigned long. The kernel code is able to throttle the
cpu directly when under lock contention, while the userspace
implementation relies on the futex primitives to emulate reliable
blocking. Since the futex interface introduces the 32-bit
requirement, isolate the associated userspace hack to that
particular code.

Restore the native bitmap behavior of the bit spinlock code to
address the rhashtable problem described above. Since this is not
compatible with the futex interface, create a futex wrapper
specifically to convert the native bitmap type to a 32-bit virtual
address and mask value for the purposes of waiting/waking when under
lock contention.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-09-19 17:26:45 -04:00
..
sched Update closures from kernel source tree 2021-05-27 21:13:52 -04:00
unaligned Delete more shim layer code 2018-12-19 20:34:24 -05:00
atomic.h Update bcachefs sources to 7c0fe6f104 bcachefs: Fix bch2_fsck_ask_yn() 2023-06-04 18:10:29 -04:00
backing-dev-defs.h Update bcachefs sources to 5fd0c70102 bcachefs: Fix __remove_dirent() 2021-11-03 21:28:23 -04:00
backing-dev.h fixes for 32 bit builds/non x86 archs 2018-05-17 02:36:19 -04:00
bio.h Update bcachefs sources to 25de2b00dc bcachefs: Change check for invalid key types 2023-07-07 04:25:07 -04:00
bit_spinlock.h bcachefs-tools: fix endian problems between bit spinlocks and futexes 2023-09-19 17:26:45 -04:00
bitmap.h Update bcachefs sources to ed6b7f81a7 six locks: Disable percpu read lock mode in userspace 2023-06-10 22:15:00 -04:00
bitops.h hweight32() 2022-06-27 15:58:39 -04:00
blk_types.h cmd_dump: Use buffered IO for reading device metadata 2022-06-18 18:33:25 -04:00
blkdev.h Update bcachefs sources to e14d7c7195 bcachefs: Compression levels 2023-07-15 17:36:15 -04:00
bsearch.h Update bcachefs sources to 8d3093bd9b bcachefs: Evict btree nodes we're deleting 2021-04-26 20:18:47 -04:00
bug.h Update bcachefs sources to cd779e0cc5 bcachefs: Skip inode unpack/pack in bch2_extent_update() 2022-10-22 14:41:54 -04:00
bvec.h Update bcachefs sources to 84f132d569 bcachefs: fsck: Break walk_inode() up into multiple functions 2023-06-27 19:38:18 -04:00
byteorder.h Patches to support musl libc 2018-02-09 22:20:56 +01:00
cache.h fixes for 32 bit builds/non x86 archs 2018-05-17 02:36:19 -04:00
closure.h Update bcachefs sources to 171da96d76 bcachefs: Drop some anonymous structs, unions 2023-03-04 23:33:25 -05:00
compiler.h Fix build against musl libc. 2022-11-24 06:21:06 +02:00
completion.h Update bcachefs sources to d5e561b3cc bcachefs: BCH_DATA ioctl 2018-02-08 15:33:42 -05:00
console.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
cpumask.h Update bcachefs sources to 1d669389f7 bcachefs: use a radix tree for inum bitmap in fsck 2020-11-07 13:09:23 -05:00
crc32c.h Faster crc32c 2017-10-08 10:20:36 -08:00
crc64.h Update bcachefs sources to ef60854e99 bcachefs: More allocator startup improvements 2019-01-13 20:53:25 -05:00
crypto.h drop dead code 2018-05-17 07:24:39 -04:00
ctype.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
dcache.h Update bcachefs sources to 940d6ca657 bcachefs: acl code improvements 2018-07-13 00:45:28 -04:00
debugfs.h Delete more shim layer code 2018-12-19 20:34:24 -05:00
device.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
dynamic_fault.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
err.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
errname.h Update bcachefs sources to 90a9c61e2b bcachefs: Switch bch2_btree_delete_range() to bch2_trans_run() 2022-08-11 17:34:34 -04:00
export.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
freezer.h Update bcachefs sources to 171da96d76 bcachefs: Drop some anonymous structs, unions 2023-03-04 23:33:25 -05:00
generic-radix-tree.h Update bcachefs sources to 6ddf061e68 bcachefs: Use a genradix for reading journal entries 2022-04-08 19:26:30 -04:00
genhd.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
gfp.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
hash.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
idr.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
ioprio.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
jhash.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
jiffies.h Switch to CLOCK_MONOTONIC_COARSE 2023-06-18 14:32:28 -04:00
kernel.h Update bcachefs sources to 33a60d9b05 bcachefs: Assorted fixes for clang 2023-08-01 22:13:03 -04:00
key.h drop dead code 2018-05-17 07:24:39 -04:00
kmemleak.h Update bcachefs sources to cbccc6d869 bcachefs: Ratelimit ec error message 2022-10-09 02:33:05 -04:00
kobject.h Update bcachefs sources to fad6d13aa5 fixup! bcachefs: Add persistent counters 2022-05-30 23:24:10 -04:00
kthread.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
list_nulls.h Update bcachefs sources to 18686af684 bcachefs: Inode backpointers 2021-03-29 00:22:38 -04:00
list.h linux shim: hlist_unhashed() 2023-03-02 23:00:03 -05:00
llist.h Update llist code 2019-08-28 11:35:00 -04:00
lockdep.h Update bcachefs sources to 400c2f8d96 bcachefs: Mask out unknown compat features when going read-write 2021-07-11 13:57:11 -04:00
log2.h Update log2.h from linux kernel 2020-05-21 17:19:47 -04:00
lz4.h Update bcachefs sources to e14d7c7195 bcachefs: Compression levels 2023-07-15 17:36:15 -04:00
math64.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
math.h Update bcachefs sources to 33a60d9b05 bcachefs: Assorted fixes for clang 2023-08-01 22:13:03 -04:00
mean_and_variance.h Update bcachefs sources to 7c0fe6f104 bcachefs: Fix bch2_fsck_ask_yn() 2023-06-04 18:10:29 -04:00
mempool.h Add a real mempool implementation 2021-04-24 01:36:43 -04:00
mm.h Update bcachefs sources to 47ffed9fad bcachefs: bch2_btree_delete_range_trans() now uses peek_upto() 2022-10-10 00:10:45 -04:00
module.h Delete more shim layer code 2018-12-19 20:34:24 -05:00
mutex.h update bcache sources 2017-03-10 12:40:01 -09:00
osq_lock.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
overflow.h Update bcachefs sources to 18686af684 bcachefs: Inode backpointers 2021-03-29 00:22:38 -04:00
page.h Update bcachefs sources to b0788c47d9 bcachefs: Fix check_version_upgrade() 2023-08-11 22:25:12 -04:00
percpu-refcount.h fix percpu_ref_reinit() 2017-03-16 14:23:40 -08:00
percpu-rwsem.h Update bcachefs sources to 14f68409be bcachefs: Optimize fiemap 2019-08-27 17:37:03 -04:00
percpu.h Delete more shim layer code 2018-12-19 20:34:24 -05:00
poison.h Update bcachefs sources to 6a20aede29 bcachefs: Fix quotas + snapshots 2023-05-02 00:41:47 -04:00
posix_acl_xattr.h Update bcachefs sources to 84f132d569 bcachefs: fsck: Break walk_inode() up into multiple functions 2023-06-27 19:38:18 -04:00
posix_acl.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
prandom.h Update bcachefs sources to ea93c26e98 fixup! bcachefs: We can handle missing btree roots for all alloc btrees 2023-02-09 18:36:24 -05:00
preempt.h Change preempt_disable() etc. to use a recursive mutex. 2019-11-03 23:17:43 -05:00
prefetch.h Update bcachefs sources to cd779e0cc5 bcachefs: Skip inode unpack/pack in bch2_extent_update() 2022-10-22 14:41:54 -04:00
pretty-printers.h Update bcachefs sources to 24f7e08cd8 bcachefs: shrinker.to_text() methods 2022-06-09 15:07:25 -04:00
printk.h Fix printk_ratelimited() 2022-06-22 22:05:39 -04:00
random.h get_random_u32_below() 2023-06-27 19:45:40 -04:00
ratelimit.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
rculist.h drop dead code 2018-05-17 07:24:39 -04:00
rcupdate.h Update bcachefs sources to e14d7c7195 bcachefs: Compression levels 2023-07-15 17:36:15 -04:00
rhashtable-types.h Update bcachefs sources to 18686af684 bcachefs: Inode backpointers 2021-03-29 00:22:38 -04:00
rhashtable.h Update bcachefs sources to 33a60d9b05 bcachefs: Assorted fixes for clang 2023-08-01 22:13:03 -04:00
rwsem.h Update bcachefs sources to 47ffed9fad bcachefs: bch2_btree_delete_range_trans() now uses peek_upto() 2022-10-10 00:10:45 -04:00
scatterlist.h Delete more shim layer code 2018-12-19 20:34:24 -05:00
sched.h Update bcachefs sources to a8115093df bcachefs: Fix divide by zero in rebalance_work() 2023-08-17 17:11:27 -04:00
semaphore.h Update bcachefs sources to 4837f82ee1 bcachefs: Use cached iterators for alloc btree 2020-06-15 16:27:19 -04:00
seq_buf.h Update bcachefs sources to ea93c26e98 fixup! bcachefs: We can handle missing btree roots for all alloc btrees 2023-02-09 18:36:24 -05:00
seq_file.h Delete more shim layer code 2018-12-19 20:34:24 -05:00
seqlock.h Delete more shim layer code 2018-12-19 20:34:24 -05:00
shrinker.h Update bcachefs sources to ea93c26e98 fixup! bcachefs: We can handle missing btree roots for all alloc btrees 2023-02-09 18:36:24 -05:00
siphash.h Update bcachefs sources to ba398d2906 bcachefs: Fix reflink repair code 2022-02-13 04:08:33 -05:00
slab.h Update bcachefs sources to 33a60d9b05 bcachefs: Assorted fixes for clang 2023-08-01 22:13:03 -04:00
sort.h Delete more shim layer code 2018-12-19 20:34:24 -05:00
spinlock.h Fix printk_ratelimited() 2022-06-22 22:05:39 -04:00
srcu.h Update bcachefs sources to d1fd471830 bcachefs: Add more debug checks 2020-11-16 18:23:54 -05:00
stat.h Patches to support musl libc 2018-02-09 22:20:56 +01:00
string_helpers.h Update bcachefs sources to dfaf9a6ee2 lib/printbuf: Clean up headers 2022-08-18 12:49:48 -04:00
string.h Update bcachefs sources to cd779e0cc5 bcachefs: Skip inode unpack/pack in bch2_extent_update() 2022-10-22 14:41:54 -04:00
sysfs.h Update bcachefs sources to fad6d13aa5 fixup! bcachefs: Add persistent counters 2022-05-30 23:24:10 -04:00
time64.h Update bcachefs sources to 15f6e66e86 bcachefs: pass around bset_tree less 2018-08-15 20:00:21 -04:00
timer.h Update bcachefs sources to 0906b1fb49 bcachefs: fixes for 32 bit/big endian machines 2018-05-17 02:36:19 -04:00
tracepoint.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
typecheck.h bcache in userspace; userspace fsck 2017-01-20 09:07:08 -09:00
types.h Update bcachefs sources to 6a20aede29 bcachefs: Fix quotas + snapshots 2023-05-02 00:41:47 -04:00
uuid.h Update bcachefs sources to 84f132d569 bcachefs: fsck: Break walk_inode() up into multiple functions 2023-06-27 19:38:18 -04:00
vmalloc.h Update bcachefs sources to f638850417 bcachefs: bch2_trans_log_msg() 2022-03-30 17:40:37 -04:00
wait.h Update bcachefs sources to ea93c26e98 fixup! bcachefs: We can handle missing btree roots for all alloc btrees 2023-02-09 18:36:24 -05:00
workqueue.h Update bcachefs sources to 0906b1fb49 bcachefs: fixes for 32 bit/big endian machines 2018-05-17 02:36:19 -04:00
xattr.h Update bcachefs sources to 6a20aede29 bcachefs: Fix quotas + snapshots 2023-05-02 00:41:47 -04:00
xxhash.h Update bcachefs sources to dbee44d5ab bcachefs: add bcachefs xxhash support 2021-07-07 20:30:53 -04:00
zlib.h Delete more unused shim code, update bcache code 2017-03-03 23:17:31 -09:00
zstd_errors.h Update bcachefs sources to e48731a188 bcachefs: Fix BTREE_TRIGGER_WANTS_OLD_AND_NEW 2022-03-13 19:20:59 -04:00
zstd.h Update bcachefs sources to e48731a188 bcachefs: Fix BTREE_TRIGGER_WANTS_OLD_AND_NEW 2022-03-13 19:20:59 -04:00