bcachefs out-of-tree series
Subsystems (5)
Kent Overstreet
maintainercover bcachefs out-of-tree series
A few patches for out-of-tree bcachefs.
Since bcachefs was dropped from mainline, the kconfig tweaks for lib/ are needed for it to build out of tree; they just give a few config options names, so that distros can ensure they are enabled.
Also included is a bugfix patch series for closures for an issue with unwinding closure_sync_timeout().
Kent Overstreet (7):
closures: Improve closure_put_after_sub_checks
closures: closure_sub() uses cmpxchg
closures: CLOSURE_SLEEPING
closures: kill closure.closure_get_happened
lib: Give closures, min_heap config opts names
lib: Give XOR_BLOCKS, RAID6_PQ config opts names
lib: Give compression, checksum, crypto config opts names
crypto/Kconfig | 2 +- fs/bcachefs/alloc_foreground.h | 2 +- fs/bcachefs/fs-io-direct.c | 1 - include/linux/closure.h | 33 +++--- lib/Kconfig | 24 ++-- lib/closure.c | 203 +++++++++++++++++---------------- lib/crc/Kconfig | 4 +- lib/crypto/Kconfig | 4 +- 8 files changed, 136 insertions(+), 137 deletions(-)
Signature · 1 line
2.51.0
Kent Overstreet
maintainerPATCH 1/7 closures: Improve closure_put_after_sub_checks
Add a guard bit for CLOSURE_DESTRUCTOR underflow, print the full cl->remaining value, and rename variables for clarity.
--- include/linux/closure.h | 2 +- lib/closure.c | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-)
include/linux/closure.h +1 -1
@@ -135,7 +135,7 @@ enum closure_state { };#define CLOSURE_GUARD_MASK \ - ((CLOSURE_DESTRUCTOR|CLOSURE_WAITING|CLOSURE_RUNNING) << 1) + (((CLOSURE_DESTRUCTOR|CLOSURE_WAITING|CLOSURE_RUNNING) << 1)|(CLOSURE_BITS_START >> 1))#define CLOSURE_REMAINING_MASK (CLOSURE_BITS_START - 1)#define CLOSURE_REMAINING_INITIALIZER (1|CLOSURE_RUNNING)
lib/closure.c +15 -13
@@ -13,23 +13,25 @@#include <linux/seq_file.h> #include <linux/sched/debug.h> -static inline void closure_put_after_sub_checks (int flags) +static void closure_val_checks (struct closure *cl,unsigned new) { -int r = flags &CLOSURE_REMAINING_MASK ; - -if (WARN (flags &CLOSURE_GUARD_MASK , -"closure has guard bits set: %x (%u)" , - flags &CLOSURE_GUARD_MASK , (unsigned )__fls (r))) - r &= ~CLOSURE_GUARD_MASK ; - -WARN (!r && (flags & ~CLOSURE_DESTRUCTOR ), -"closure ref hit 0 with incorrect flags set: %x (%u)" , - flags & ~CLOSURE_DESTRUCTOR , (unsigned )__fls (flags)); +unsigned count = new &CLOSURE_REMAINING_MASK ; + +if (WARN (new &CLOSURE_GUARD_MASK , +"closure %ps has guard bits set: %x (%u)" , + cl->fn, + new, (unsigned )__fls (new &CLOSURE_GUARD_MASK ))) + new &= ~CLOSURE_GUARD_MASK ; + +WARN (!count && (new & ~CLOSURE_DESTRUCTOR ), +"closure %ps ref hit 0 with incorrect flags set: %x (%u)" , + cl->fn, + new, (unsigned )__fls (new)); }static inline void closure_put_after_sub (struct closure *cl,int flags) { -closure_put_after_sub_checks (flags); +closure_val_checks (cl, flags);if (!(flags &CLOSURE_REMAINING_MASK )) {smp_acquire__after_ctrl_dep ();
@@ -167,7 +169,7 @@ void __sched closure_return_sync(struct closure *cl)unsigned flags =atomic_sub_return_release (1 +CLOSURE_RUNNING -CLOSURE_DESTRUCTOR , &cl->remaining); -closure_put_after_sub_checks (flags); +closure_val_checks (cl, flags);if (unlikely (flags &CLOSURE_REMAINING_MASK )) {while (1 ) {
Signature · 1 line
2.51.0
Kent Overstreet
maintainerPATCH 2/7 closures: closure_sub() uses cmpxchg
In reply to Kent OverstreetPart one of fixing a race in __closure_sync_timeout().
lib/closure.c was initially designed with the assumption that refs only hit 0 once, and when they hit 0 the thread that caused it to hit 0 now owns it - which avoids many races without the need for cmpxchg.
But __closure_sync_timeout() broke this, because the timeout may elapse and the thread doing the sync may race with the final put.
Switch to cmpxchg for manipulating cl->remaining; the next patch will fix some issues with the other thread's closure_put() accessing variables in struct closure after that final put.
--- include/linux/closure.h | 9 ++++- lib/closure.c | 79 ++++++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 38 deletions(-)
include/linux/closure.h +8 -1
@@ -169,11 +169,18 @@ struct closure { };void closure_sub (struct closure *cl,int v); -void closure_put (struct closure *cl);void __closure_wake_up (struct closure_waitlist *list);bool closure_wait (struct closure_waitlist *list,struct closure *cl);void __closure_sync (struct closure *cl); +/* +* closure_put - decrement a closure's refcount +*/ +static inline void closure_put (struct closure *cl) +{ +closure_sub (cl,1 ); +} +static inline unsigned closure_nr_remaining (struct closure *cl) {return atomic_read (&cl->remaining) &CLOSURE_REMAINING_MASK ;
lib/closure.c +42 -37
112 lines not on this page · raw message
Signature · 1 line
2.51.0
Kent Overstreet
maintainerPATCH 3/7 closures: CLOSURE_SLEEPING
In reply to Kent OverstreetPart two of fixing __closure_sync_timeout().
Add a bit in cl->remaining (protected by cmpxchg()) for indicating whether a closure has a sleeper that should be woken up after the final put; we can now read the pointer to the waiting task_struct before the final put
This elimating accesses to another thread's closure after the final put, which are racy because it may be unwinding after the timeout elapses.
--- include/linux/closure.h | 9 +-- lib/closure.c | 118 +++++++++++++++++++--------------------- 2 files changed, 62 insertions(+), 65 deletions(-)
include/linux/closure.h +5 -4
@@ -128,14 +128,15 @@ enum closure_state {* annotate where references are being transferred. */ -CLOSURE_BITS_START = (1U <<26 ), -CLOSURE_DESTRUCTOR = (1U <<26 ), +CLOSURE_BITS_START = (1U <<24 ), +CLOSURE_DESTRUCTOR = (1U <<24 ), +CLOSURE_SLEEPING = (1U <<26 ),CLOSURE_WAITING = (1U <<28 ), CLOSURE_RUNNING = (1U << 30), };#define CLOSURE_GUARD_MASK \ - (((CLOSURE_DESTRUCTOR|CLOSURE_WAITING|CLOSURE_RUNNING) << 1)|(CLOSURE_BITS_START >> 1)) + (((CLOSURE_DESTRUCTOR|CLOSURE_SLEEPING|CLOSURE_WAITING|CLOSURE_RUNNING) << 1)|(CLOSURE_BITS_START >> 1))#define CLOSURE_REMAINING_MASK (CLOSURE_BITS_START - 1)#define CLOSURE_REMAINING_INITIALIZER (1|CLOSURE_RUNNING)
@@ -144,7 +145,7 @@ struct closure {union {struct {struct workqueue_struct *wq; -struct closure_syncer *s; +struct task_struct *sleeper;struct llist_node list;closure_fn *fn; };
lib/closure.c +57 -61
192 lines not on this page · raw message
Signature · 1 line
2.51.0
Kent Overstreet
maintainerPATCH 4/7 closures: kill closure.closure_get_happened
In reply to Kent OverstreetWith closure_put() now using cmpxchg, this is no longer needed.
--- fs/bcachefs/alloc_foreground.h | 2 +- fs/bcachefs/fs-io-direct.c | 1 - include/linux/closure.h | 15 ++------------- lib/closure.c | 2 -- 4 files changed, 3 insertions(+), 17 deletions(-)
fs/bcachefs/alloc_foreground.h +1 -1
@@ -311,7 +311,7 @@ void bch2_dev_alloc_debug_to_text(struct printbuf *, struct bch_dev *);void __bch2_wait_on_allocator (struct bch_fs *,struct closure *);static inline void bch2_wait_on_allocator (struct bch_fs *c,struct closure *cl) { -if (cl->closure_get_happened) +if (closure_nr_remaining (cl) >1 )__bch2_wait_on_allocator (c, cl); }
fs/bcachefs/fs-io-direct.c +0 -1
@@ -117,7 +117,6 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter) }else {atomic_set (&dio->cl.remaining,CLOSURE_REMAINING_INITIALIZER +1 ); - dio->cl.closure_get_happened = true; } dio->req = req;
include/linux/closure.h +2 -13
@@ -155,7 +155,6 @@ struct closure {struct closure *parent;atomic_t remaining; -bool closure_get_happened;#ifdef CONFIG_DEBUG_CLOSURES #define CLOSURE_MAGIC_DEAD 0xc054dead
@@ -195,11 +194,7 @@ static inline unsigned closure_nr_remaining(struct closure *cl)*/ static inline void closure_sync (struct closure *cl) { -#ifdef CONFIG_DEBUG_CLOSURES -BUG_ON (closure_nr_remaining (cl) !=1 && !cl->closure_get_happened); -#endif - -if (cl->closure_get_happened) +if (closure_nr_remaining (cl) >1 )__closure_sync (cl); }
@@ -207,10 +202,7 @@ int __closure_sync_timeout(struct closure *cl, unsigned long timeout);static inline int closure_sync_timeout (struct closure *cl,unsigned long timeout) { -#ifdef CONFIG_DEBUG_CLOSURES -BUG_ON (closure_nr_remaining (cl) !=1 && !cl->closure_get_happened); -#endif -return cl->closure_get_happened +return closure_nr_remaining (cl) >1 ?__closure_sync_timeout (cl, timeout) :0 ; }
@@ -283,8 +275,6 @@ static inline void closure_queue(struct closure *cl)*/ static inline void closure_get (struct closure *cl) { - cl->closure_get_happened = true; -#ifdef CONFIG_DEBUG_CLOSURES BUG_ON ((atomic_inc_return (&cl->remaining) &CLOSURE_REMAINING_MASK ) <=1 );
@@ -322,7 +312,6 @@ static inline void closure_init(struct closure *cl, struct closure *parent)closure_get (parent);atomic_set (&cl->remaining,CLOSURE_REMAINING_INITIALIZER ); - cl->closure_get_happened = false;closure_debug_create (cl);closure_set_ip (cl);
lib/closure.c +0 -2
@@ -75,7 +75,6 @@ void closure_sub(struct closure *cl, int v) }if (s == CLOSURE_requeue) { - cl->closure_get_happened = false;closure_queue (cl); }else {struct closure *parent = cl->parent;
@@ -126,7 +125,6 @@ bool closure_wait(struct closure_waitlist *waitlist, struct closure *cl)if (atomic_read (&cl->remaining) &CLOSURE_WAITING )return false; - cl->closure_get_happened = true;closure_set_waiting (cl, _RET_IP_);unsigned r =atomic_add_return (CLOSURE_WAITING +1 , &cl->remaining);closure_val_checks (cl, r,CLOSURE_WAITING +1 );
Signature · 1 line
2.51.0
Kent Overstreet
maintainerPATCH 5/7 lib: Give closures, min_heap config opts names
In reply to Kent OverstreetGive these config options names so that they show up under the "Library routes" kernel configuration menu, and can be enabled by distributions.
These are needed for bcachefs to be built out of tree.
The closures and min_heap code originates from bcache and bcachefs.
--- lib/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/Kconfig +2 -2
@@ -367,7 +367,7 @@ config ASSOCIATIVE_ARRAY for more information. config CLOSURES - bool + bool "bcache/bcachefs async widgets" config HAS_IOMEM bool
@@ -646,4 +646,4 @@ config UNION_FIND bool config MIN_HEAP - bool + bool "Generic minheap algorithm"
Signature · 1 line
2.51.0
Kent Overstreet
maintainerPATCH 6/7 lib: Give XOR_BLOCKS, RAID6_PQ config opts names
In reply to Kent OverstreetGive these config options names so that they show up under the "Library routes" kernel configuration menu, and can be enabled by distributions.
These are needed for bcachefs to be built out of tree.
These libraries are both for RAID5/6.
--- crypto/Kconfig | 2 +- lib/Kconfig | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
crypto/Kconfig +1 -1
@@ -3,7 +3,7 @@ # Generic algorithms support # config XOR_BLOCKS - tristate + tristate "Accelerated block xor algorithm" # # async_tx api: hardware offloaded memory transfer/transform support
lib/Kconfig +3 -1
@@ -9,7 +9,9 @@ config BINARY_PRINTF menu "Library routines" config RAID6_PQ - tristate + tristate "Reed-solomon RAID5/6 algorithms" + help + Provides routines for block level reed-solomon, for RAID5/6 config RAID6_PQ_BENCHMARK bool "Automatically choose fastest RAID6 PQ functions"
Signature · 1 line
2.51.0
Re: [PATCH 6/7] lib: Give XOR_BLOCKS, RAID6_PQ config opts names
Quoted 4 lines · Kent Overstreet
Give these config options names so that they show up under the "Library routes" kernel configuration menu, and can be enabled by distributions.
These are needed for bcachefs to be built out of tree.
We do not add hooks for out of tree code, and this applies to you just like for everyone else.
Kent Overstreet
maintainerRe: [PATCH 6/7] lib: Give XOR_BLOCKS, RAID6_PQ config opts names
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Kent Overstreet
Give these config options names so that they show up under the "Library routes" kernel configuration menu, and can be enabled by distributions.
These are needed for bcachefs to be built out of tree.
We do not add hooks for out of tree code, and this applies to you just like for everyone else.
That's been the primary purpose of the lib/ kconfig menu. The current language is no longer quite as explicit as it used to be, but here's a recent example:
config CRC16
tristate "CRC16 functions"
help
This option is provided for the case where no in-kernel-tree modules require CRC16 functions, but a module built outside the kernel tree does. Such modules that use library CRC16 functions require M here.
Re: [PATCH 6/7] lib: Give XOR_BLOCKS, RAID6_PQ config opts names
Quoted 3 lines · Kent Overstreet
That's been the primary purpose of the
lib/kconfig menu. The current language is no longer quite as explicit as it used to be, but here's a recent example:
It's not the current kernel where this got fixed. If you find others instances, we can fix them as well.
Kent Overstreet
maintainerRe: [PATCH 6/7] lib: Give XOR_BLOCKS, RAID6_PQ config opts names
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Kent Overstreet
That's been the primary purpose of the
lib/kconfig menu. The current language is no longer quite as explicit as it used to be, but here's a recent example:It's not the current kernel where this got fixed. If you find others instances, we can fix them as well.
The current language is only slightly less explicit, but the underlying purpose remains the same.
Re: [PATCH 6/7] lib: Give XOR_BLOCKS, RAID6_PQ config opts names
Quoted 11 lines · Kent Overstreet
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Kent Overstreet
That's been the primary purpose of the
lib/kconfig menu. The current language is no longer quite as explicit as it used to be, but here's a recent example:It's not the current kernel where this got fixed. If you find others instances, we can fix them as well.
The current language is only slightly less explicit, but the underlying purpose remains the same.
There is no such current language. It is a non-selectable symbol with this standard help text used by all CRC helpers:
The CRC16 library functions. Select this if your module uses any of the functions from <linux/crc16.h>.
Re: [PATCH 6/7] lib: Give XOR_BLOCKS, RAID6_PQ config opts names
In reply to Kent OverstreetQuoted 2 lines · Kent Overstreet
Give these config options names so that they show up under the "Library routes" kernel configuration menu, and can be enabled by distributions.
A distribution specifies a kernel configuration. A distribution that ships a given out-of-tree module can arrange for all its dependencies to be met.
Quoted 17 lines
These are needed for bcachefs to be built out of tree.
These libraries are both for RAID5/6.
Cc Andrew Morton <[email protected]>Cc Eric Biggers <[email protected]>Signed-off-by Kent Overstreet <[email protected]>--- crypto/Kconfig | 2 +- lib/Kconfig | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)crypto/Kconfig +0
-0
crypto/Kconfig line 6
Quoted 5 lines
crypto/Kconfig +1
-1@@ -3,7 +3,7 @@ # Generic algorithms support # config XOR_BLOCKS - tristate + tristate "Accelerated block xor algorithm"
For example, the approach taken with the CXL unit test modules in tools/testing/ is to have them assert all their dependencies. Specifically, tools/testing/cxl/config_check.c validates the test environment rather than giving the out-of-tree module the ability to select symbols.
Now in this specific case of XOR_BLOCKS, if a distribution really wants CONFIG_XOR_BLOCKS=n in its main config *and* wants to ship an out-of-tree module that depends on CONFIG_XOR_BLOCKS=m, then that distribution needs to provide an xor.ko to meet that dependency. Not make upstream carry a patch to make that symbol configurable with no upstream consumer.
tools/testing/cxl/Kbuild is an example of building a set of in-tree modules as out-of-tree modules.
Kent Overstreet
maintainerPATCH 7/7 lib: Give compression, checksum, crypto config opts names
In reply to Kent OverstreetGive these config options names so that they show up under the "Library routes" kernel configuration menu, and can be enabled by distributions.
These are needed for bcachefs to be built out of tree.
Most (but not all, notably CRC64) of these libraries have crypto API wrappers which are already selectable under the "Cryptographic API" configuration menu; however, Eric Biggers has been working to reduce usage of the cryptographic API in favor of much more lightweight direct APIs.
--- lib/Kconfig | 16 ++++++++-------- lib/crc/Kconfig | 4 ++-- lib/crypto/Kconfig | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-)
lib/Kconfig +8 -8
@@ -142,7 +142,7 @@ source "lib/crc/Kconfig" source "lib/crypto/Kconfig" config XXHASH - tristate + tristate "XXHASH checksum algorithm" config AUDIT_GENERIC bool
@@ -176,10 +176,10 @@ config 842_DECOMPRESS tristate config ZLIB_INFLATE - tristate + tristate "Zlib decompression" config ZLIB_DEFLATE - tristate + tristate "Zlib compression" select BITREVERSE config ZLIB_DFLTCC
@@ -196,13 +196,13 @@ config LZO_DECOMPRESS tristate config LZ4_COMPRESS - tristate + tristate "LZ4 compression" config LZ4HC_COMPRESS - tristate + tristate "LZ4HC compression" config LZ4_DECOMPRESS - tristate + tristate "LZC decompression" config ZSTD_COMMON select XXHASH
@@ -210,11 +210,11 @@ config ZSTD_COMMON config ZSTD_COMPRESS select ZSTD_COMMON - tristate + tristate "ZSTD compression" config ZSTD_DECOMPRESS select ZSTD_COMMON - tristate + tristate "ZSTD decompression" source "lib/xz/Kconfig"
lib/crc/Kconfig +2 -2
@@ -54,7 +54,7 @@ config CRC_T10DIF_ARCH default y if X86 config CRC32 - tristate + tristate "CRC32 algorithm" select BITREVERSE help The CRC32 library functions. Select this if your module uses any of
@@ -74,7 +74,7 @@ config CRC32_ARCH default y if X86 config CRC64 - tristate + tristate "CRC64 algorithm" help The CRC64 library functions. Select this if your module uses any of the functions from <linux/crc64.h>.
lib/crypto/Kconfig +2 -2
@@ -62,7 +62,7 @@ config CRYPTO_LIB_CHACHA_GENERIC enabled, this implementation serves the users of CRYPTO_LIB_CHACHA. config CRYPTO_LIB_CHACHA - tristate + tristate "Chacha encryption algorithm" help Enable the ChaCha library interface. This interface may be fulfilled by either the generic implementation or an arch-specific one, if one
@@ -125,7 +125,7 @@ config CRYPTO_LIB_POLY1305_GENERIC enabled, this implementation serves the users of CRYPTO_LIB_POLY1305. config CRYPTO_LIB_POLY1305 - tristate + tristate "Poly1305 authentication algorithm" help Enable the Poly1305 library interface. This interface may be fulfilled by either the generic implementation or an arch-specific one, if one
Signature · 1 line
2.51.0
Quoted 5 lines · Kent Overstreet
A few patches for out-of-tree bcachefs.
Since bcachefs was dropped from mainline, the kconfig tweaks for
lib/are needed for it to build out of tree; they just give a few config options names, so that distros can ensure they are enabled.
No. The Linux kernel is about in-tree stuff. There are not exports, or especially Kconfigs that make things confusing for out of tree code. Just like everyone else you'll have to live with what people do in-tree for in-tree users.