static assertion failed in fs/bcachefs/journal_io.c
Hi all,
I am not really sure where to go with this, so I figured I would loop some people in and see if we can figure out what is going on here.
After commit 67a8e7de7ef0 ("bcachefs: Clamp replicas_required to replicas") in linux-next, I see a massive error occur when building for ARCH=arm64 with both CONFIG_BCACHEFS_FS and CONFIG_LTO enabled, which is important because arm64 defines its own __READ_ONCE() with LTO enabled. The error appears to be related to the minmax.h changes that went into 6.7; I think it is specifically around commit d03eba99f5bf ("minmax:
allow min()/max()/clamp() if the arguments have the same signedness.").
As far as I can tell, replicas_want and the metadata_replicas_required member in struct bch_opts should have the same signedness, unless the __READ_ONCE() macro is messing something up, which is kind of hard to tell at this point...
I'll keep poking at this tomorrow unless someone else beats me to it.
Cheers,
Nathan
$ echo 'CONFIG_BCACHEFS_FS=y CONFIG_LTO_NONE=n CONFIG_LTO_CLANG_THIN=y' >kernel/configs/repro.config
$ make -skj"$(nproc)" ARCH=arm64 LLVM=1 clean defconfig repro.config fs/bcachefs/journal_io.o
fs/bcachefs/journal_io.c:1509:27: error: static assertion failed due to requirement '__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) || __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) || (__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)(replicas_want) * 0L)) : (int *)8))) && __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0), replicas_want, -1) >= 0) || (__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)(({
do {
extern void __compiletime_assert_578(void);
if (!((sizeof (c->opts.metadata_replicas_required) == sizeof(char) || sizeof (c->opts.metadata_replicas_required) == sizeof(short) || sizeof (c->opts.metadata_replicas_required) == sizeof(int) || sizeof (c->opts.metadata_replicas_required) == sizeof(long)) || sizeof (c->opts.metadata_replicas_required) == sizeof(long long)))
__compiletime_assert_578();
} while (0);
({
unsigned char *__x = &(c->opts.metadata_replicas_required);
int atomic = 1;
union {
unsigned char __val;
char __c[1];
} __u;
switch (sizeof (c->opts.metadata_replicas_required)) {
case 1:
asm volatile (".if 1 == 1\n661:\n\tldarb\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldaprb\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned char *)__u.__c) : "Q" (*__x) : "memory");
break;
case 2:
asm volatile (".if 1 == 1\n661:\n\tldarh\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldaprh\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned short *)__u.__c) : "Q" (*__x) : "memory");
break;
case 4:
asm volatile (".if 1 == 1\n661:\n\tldar\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldapr\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned int *)__u.__c) : "Q" (*__x) : "memory");
break;
case 8:
asm volatile (".if 1 == 1\n661:\n\tldar\t%0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldapr\t%0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned long long *)__u.__c) : "Q" (*__x) : "memory");
break;
default:
atomic = 0;
}
atomic ? (unsigned char)__u.__val : (*(unsigned char *volatile)__x);
});
})) * 0L)) : (int *)8))) && __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0), ({
do {
extern void __compiletime_assert_578(void);
if (!((sizeof (c->opts.metadata_replicas_required) == sizeof(char) || sizeof (c->opts.metadata_replicas_required) == sizeof(short) || sizeof (c->opts.metadata_replicas_required) == sizeof(int) || sizeof (c->opts.metadata_replicas_required) == sizeof(long)) || sizeof (c->opts.metadata_replicas_required) == sizeof(long long)))
__compiletime_assert_578();
} while (0);
({
unsigned char *__x = &(c->opts.metadata_replicas_required);
int atomic = 1;
union {
unsigned char __val;
char __c[1];
} __u;
switch (sizeof (c->opts.metadata_replicas_required)) {
case 1:
asm volatile (".if 1 == 1\n661:\n\tldarb\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldaprb\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned char *)__u.__c) : "Q" (*__x) : "memory");
break;
case 2:
asm volatile (".if 1 == 1\n661:\n\tldarh\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldaprh\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned short *)__u.__c) : "Q" (*__x) : "memory");
break;
case 4:
asm volatile (".if 1 == 1\n661:\n\tldar\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldapr\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned int *)__u.__c) : "Q" (*__x) : "memory");
break;
case 8:
asm volatile (".if 1 == 1\n661:\n\tldar\t%0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldapr\t%0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned long long *)__u.__c) : "Q" (*__x) : "memory");
break;
default:
atomic = 0;
}
atomic ? (unsigned char)__u.__val : (*(unsigned char *volatile)__x);
});
}), -1) >= 0)': min(replicas_want, ({ do { __attribute__((__noreturn__)) extern void __compiletime_assert_578(void) __attribute__((__error__("Unsupported access size for {READ,WRITE}_ONCE()."))); if (!((sizeof(c->opts.metadata_replicas_required) == sizeof(char) || sizeof(c->opts.metadata_replicas_required) == sizeof(short) || sizeof(c->opts.metadata_replicas_required) == sizeof(int) || sizeof(c->opts.metadata_replicas_required) == sizeof(long)) || sizeof(c->opts.metadata_replicas_required) == sizeof(long long))) __compiletime_assert_578(); } while (0); ({ typeof(&(c->opts.metadata_replicas_required)) __x = &(c->opts.metadata_replicas_required); int atomic = 1; union { typeof( _Generic((*__x), char: (char)0, unsigned char: (unsigned char)0, signed char: (signed char)0, unsigned short: (unsigned short)0, signed short: (signed short)0, unsigned int: (unsigned int)0, signed int: (signed int)0, unsigned long: (unsigned long)0, signed long: (signed long)0, unsigned long long: (unsigned long long)0, signed long long: (signed long long)0, default: (*__x))) __val; char __c[1]; } __u; switch (sizeof(c->opts.metadata_replicas_required)) { case 1: asm volatile(".if ""1"" == 1\n" "661:\n\t" "ldar" "b" "\t" "%w0, %1" "\n" "662:\n" ".pushsection .altinstructions,\"a\"\n" " .word 661b - .\n" " .word 663f - .\n" " .hword " "34" "\n" " .byte 662b-661b\n" " .byte 664f-663f\n" ".popsection\n" ".subsection 1\n" "663:\n\t" ".arch_extension rcpc\n" "ldapr" "b" "\t" "%w0, %1" "\n" "664:\n\t" ".org . - (664b-663b) + (662b-661b)\n\t" ".org . - (662b-661b) + (664b-663b)\n\t" ".previous\n" ".endif\n" : "=r" (*(__u8 *)__u.__c) : "Q" (*__x) : "memory"); break; case 2: asm volatile(".if ""1"" == 1\n" "661:\n\t" "ldar" "h" "\t" "%w0, %1" "\n" "662:\n" ".pushsection .altinstructions,\"a\"\n" " .word 661b - .\n" " .word 663f - .\n" " .hword " "34" "\n" " .byte 662b-661b\n" " .byte 664f-663f\n" ".popsection\n" ".subsection 1\n" "663:\n\t" ".arch_extension rcpc\n" "ldapr" "h" "\t" "%w0, %1" "\n" "664:\n\t" ".org . - (664b-663b) + (662b-661b)\n\t" ".org . - (662b-661b) + (664b-663b)\n\t" ".previous\n" ".endif\n" : "=r" (*(__u16 *)__u.__c) : "Q" (*__x) : "memory"); break; case 4: asm volatile(".if ""1"" == 1\n" "661:\n\t" "ldar" "" "\t" "%w0, %1" "\n" "662:\n" ".pushsection .altinstructions,\"a\"\n" " .word 661b - .\n" " .word 663f - .\n" " .hword " "34" "\n" " .byte 662b-661b\n" " .byte 664f-663f\n" ".popsection\n" ".subsection 1\n" "663:\n\t" ".arch_extension rcpc\n" "ldapr" "" "\t" "%w0, %1" "\n" "664:\n\t" ".org . - (664b-663b) + (662b-661b)\n\t" ".org . - (662b-661b) + (664b-663b)\n\t" ".previous\n" ".endif\n" : "=r" (*(__u32 *)__u.__c) : "Q" (*__x) : "memory"); break; case 8: asm volatile(".if ""1"" == 1\n" "661:\n\t" "ldar" "" "\t" "%0, %1" "\n" "662:\n" ".pushsection .altinstructions,\"a\"\n" " .word 661b - .\n" " .word 663f - .\n" " .hword " "34" "\n" " .byte 662b-661b\n" " .byte 664f-663f\n" ".popsection\n" ".subsection 1\n" "663:\n\t" ".arch_extension rcpc\n" "ldapr" "" "\t" "%0, %1" "\n" "664:\n\t" ".org . - (664b-663b) + (662b-661b)\n\t" ".org . - (662b-661b) + (664b-663b)\n\t" ".previous\n" ".endif\n" : "=r" (*(__u64 *)__u.__c) : "Q" (*__x) : "memory"); break; default: atomic = 0; } atomic ? (typeof(*__x))__u.__val : (*(volatile typeof(__x))__x);}); })) signedness error, fix types or consider umin() before min_t()
1509 | unsigned replicas_need = min(replicas_want,
| ^~~~~~~~~~~~~~~~~~
1510 | READ_ONCE(c->opts.metadata_replicas_required));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/minmax.h:85:19: note: expanded from macro 'min'
85 | #define min(x, y) __careful_cmp(min, x, y)
| ^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/minmax.h:58:3: note: expanded from macro '__careful_cmp'
58 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/minmax.h:51:16: note: expanded from macro '__cmp_once'
51 | static_assert(__types_ok(x, y), \
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52 | #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/minmax.h:31:2: note: expanded from macro '__is_signed'
31 | __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \
| ^
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
1 error generated.bcachefs bugs should go to the bcachefs mailing list; I assume this is just a case where we need min_t instead of min, if so I'll fix it shortly
Quoted 117 lines · Nathan Chancellor
Hi all,
I am not really sure where to go with this, so I figured I would loop some people in and see if we can figure out what is going on here.
After commit
67a8e7de7ef0("bcachefs: Clampreplicas_requiredto replicas") in linux-next, I see a massive error occur when building for ARCH=arm64 with bothCONFIG_BCACHEFS_FSandCONFIG_LTOenabled, which is important because arm64 defines its own__READ_ONCE()with LTO enabled. The error appears to be related to theminmax.hchanges that went into 6.7; I think it is specifically around commitd03eba99f5bf("minmax:
allow min()/max()/clamp() if the arguments have the same signedness.").As far as I can tell,
replicas_wantand themetadata_replicas_requiredmember in structbch_optsshould have the same signedness, unless the__READ_ONCE()macro is messing something up, which is kind of hard to tell at this point...I'll keep poking at this tomorrow unless someone else beats me to it.
Cheers,
Nathan$ echo 'CONFIG_BCACHEFS_FS=y CONFIG_LTO_NONE=n CONFIG_LTO_CLANG_THIN=y' >kernel/configs/repro.config$ make -skj"$(nproc)" ARCH=arm64 LLVM=1 clean defconfig repro.config fs/bcachefs/journal_io.o fs/bcachefs/journal_io.c:1509:27: error: static assertion failed due to requirement '__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) || __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) || (__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)(replicas_want) * 0L)) : (int *)8))) && __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0), replicas_want, -1) >= 0) || (__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)(({ do { extern void __compiletime_assert_578(void); if (!((sizeof (c->opts.metadata_replicas_required) == sizeof(char) || sizeof (c->opts.metadata_replicas_required) == sizeof(short) || sizeof (c->opts.metadata_replicas_required) == sizeof(int) || sizeof (c->opts.metadata_replicas_required) == sizeof(long)) || sizeof (c->opts.metadata_replicas_required) == sizeof(long long))) __compiletime_assert_578(); } while (0); ({ unsigned char *__x = &(c->opts.metadata_replicas_required); int atomic = 1; union { unsigned char __val; char __c[1]; } __u; switch (sizeof (c->opts.metadata_replicas_required)) { case 1: asm volatile (".if 1 == 1\n661:\n\tldarb\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldaprb\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned char *)__u.__c) : "Q" (*__x) : "memory"); break; case 2: asm volatile (".if 1 == 1\n661:\n\tldarh\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldaprh\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned short *)__u.__c) : "Q" (*__x) : "memory"); break; case 4: asm volatile (".if 1 == 1\n661:\n\tldar\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldapr\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned int *)__u.__c) : "Q" (*__x) : "memory"); break; case 8: asm volatile (".if 1 == 1\n661:\n\tldar\t%0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldapr\t%0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned long long *)__u.__c) : "Q" (*__x) : "memory"); break; default: atomic = 0; } atomic ? (unsigned char)__u.__val : (*(unsigned char *volatile)__x); }); })) * 0L)) : (int *)8))) && __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0), ({ do { extern void __compiletime_assert_578(void); if (!((sizeof (c->opts.metadata_replicas_required) == sizeof(char) || sizeof (c->opts.metadata_replicas_required) == sizeof(short) || sizeof (c->opts.metadata_replicas_required) == sizeof(int) || sizeof (c->opts.metadata_replicas_required) == sizeof(long)) || sizeof (c->opts.metadata_replicas_required) == sizeof(long long))) __compiletime_assert_578(); } while (0); ({ unsigned char *__x = &(c->opts.metadata_replicas_required); int atomic = 1; union { unsigned char __val; char __c[1]; } __u; switch (sizeof (c->opts.metadata_replicas_required)) { case 1: asm volatile (".if 1 == 1\n661:\n\tldarb\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldaprb\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned char *)__u.__c) : "Q" (*__x) : "memory"); break; case 2: asm volatile (".if 1 == 1\n661:\n\tldarh\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldaprh\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned short *)__u.__c) : "Q" (*__x) : "memory"); break; case 4: asm volatile (".if 1 == 1\n661:\n\tldar\t%w0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldapr\t%w0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned int *)__u.__c) : "Q" (*__x) : "memory"); break; case 8: asm volatile (".if 1 == 1\n661:\n\tldar\t%0, %1\n662:\n.pushsection .altinstructions,\"a\"\n .word 661b - .\n .word 663f - .\n .hword 34\n .byte 662b-661b\n .byte 664f-663f\n.popsection\n.subsection 1\n663:\n\t.arch_extension rcpc\nldapr\t%0, %1\n664:\n\t.org\t. - (664b-663b) + (662b-661b)\n\t.org\t. - (662b-661b) + (664b-663b)\n\t.previous\n.endif\n" : "=r" (*(unsigned long long *)__u.__c) : "Q" (*__x) : "memory"); break; default: atomic = 0; } atomic ? (unsigned char)__u.__val : (*(unsigned char *volatile)__x); }); }), -1) >= 0)': min(replicas_want, ({ do { __attribute__((__noreturn__)) extern void __compiletime_assert_578(void) __attribute__((__error__("Unsupported access size for {READ,WRITE}_ONCE()."))); if (!((sizeof(c->opts.metadata_replicas_required) == sizeof(char) || sizeof(c->opts.metadata_replicas_required) == sizeof(short) || sizeof(c->opts.metadata_replicas_required) == sizeof(int) || sizeof(c->opts.metadata_replicas_required) == sizeof(long)) || sizeof(c->opts.metadata_replicas_required) == sizeof(long long))) __compiletime_assert_578(); } while (0); ({ typeof(&(c->opts.metadata_replicas_required)) __x = &(c->opts.metadata_replicas_required); int atomic = 1; union { typeof( _Generic((*__x), char: (char)0, unsigned char: (unsigned char)0, signed char: (signed char)0, unsigned short: (unsigned short)0, signed short: (signed short)0, unsigned int: (unsigned int)0, signed int: (signed int)0, unsigned long: (unsigned long)0, signed long: (signed long)0, unsigned long long: (unsigned long long)0, signed long long: (signed long long)0, default: (*__x))) __val; char __c[1]; } __u; switch (sizeof(c->opts.metadata_replicas_required)) { case 1: asm volatile(".if ""1"" == 1\n" "661:\n\t" "ldar" "b" "\t" "%w0, %1" "\n" "662:\n" ".pushsection .altinstructions,\"a\"\n" " .word 661b - .\n" " .word 663f - .\n" " .hword " "34" "\n" " .byte 662b-661b\n" " .byte 664f-663f\n" ".popsection\n" ".subsection 1\n" "663:\n\t" ".arch_extension rcpc\n" "ldapr" "b" "\t" "%w0, %1" "\n" "664:\n\t" ".org . - (664b-663b) + (662b-661b)\n\t" ".org . - (662b-661b) + (664b-663b)\n\t" ".previous\n" ".endif\n" : "=r" (*(__u8 *)__u.__c) : "Q" (*__x) : "memory"); break; case 2: asm volatile(".if ""1"" == 1\n" "661:\n\t" "ldar" "h" "\t" "%w0, %1" "\n" "662:\n" ".pushsection .altinstructions,\"a\"\n" " .word 661b - .\n" " .word 663f - .\n" " .hword " "34" "\n" " .byte 662b-661b\n" " .byte 664f-663f\n" ".popsection\n" ".subsection 1\n" "663:\n\t" ".arch_extension rcpc\n" "ldapr" "h" "\t" "%w0, %1" "\n" "664:\n\t" ".org . - (664b-663b) + (662b-661b)\n\t" ".org . - (662b-661b) + (664b-663b)\n\t" ".previous\n" ".endif\n" : "=r" (*(__u16 *)__u.__c) : "Q" (*__x) : "memory"); break; case 4: asm volatile(".if ""1"" == 1\n" "661:\n\t" "ldar" "" "\t" "%w0, %1" "\n" "662:\n" ".pushsection .altinstructions,\"a\"\n" " .word 661b - .\n" " .word 663f - .\n" " .hword " "34" "\n" " .byte 662b-661b\n" " .byte 664f-663f\n" ".popsection\n" ".subsection 1\n" "663:\n\t" ".arch_extension rcpc\n" "ldapr" "" "\t" "%w0, %1" "\n" "664:\n\t" ".org . - (664b-663b) + (662b-661b)\n\t" ".org . - (662b-661b) + (664b-663b)\n\t" ".previous\n" ".endif\n" : "=r" (*(__u32 *)__u.__c) : "Q" (*__x) : "memory"); break; case 8: asm volatile(".if ""1"" == 1\n" "661:\n\t" "ldar" "" "\t" "%0, %1" "\n" "662:\n" ".pushsection .altinstructions,\"a\"\n" " .word 661b - .\n" " .word 663f - .\n" " .hword " "34" "\n" " .byte 662b-661b\n" " .byte 664f-663f\n" ".popsection\n" ".subsection 1\n" "663:\n\t" ".arch_extension rcpc\n" "ldapr" "" "\t" "%0, %1" "\n" "664:\n\t" ".org . - (664b-663b) + (662b-661b)\n\t" ".org . - (662b-661b) + (664b-663b)\n\t" ".previous\n" ".endif\n" : "=r" (*(__u64 *)__u.__c) : "Q" (*__x) : "memory"); break; default: atomic = 0; } atomic ? (typeof(*__x))__u.__val : (*(volatile typeof(__x))__x);}); })) signedness error, fix types or consider umin() before min_t() 1509 | unsigned replicas_need = min(replicas_want, | ^~~~~~~~~~~~~~~~~~ 1510 | READ_ONCE(c->opts.metadata_replicas_required)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:85:19: note: expanded from macro 'min' 85 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:58:3: note: expanded from macro '__careful_cmp' 58 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:51:16: note: expanded from macro '__cmp_once' 51 | static_assert(__types_ok(x, y), \ | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 | #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all) include/linux/minmax.h:31:2: note: expanded from macro '__is_signed' 31 | __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \ | ^ include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert' 77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr) | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ 1 error generated.
From: Kent Overstreet
Quoted 5 lines
Sent: 14 February 2024 01:17
bcachefs bugs should go to the bcachefs mailing list; I assume this is just a case where we need
min_tinstead of min, if so I'll fix it shortly
You should pretty much never use min_t() - it contains casts that are just waiting to cause grief.
I'm sure a bug got raised on clang so it outputting the source of the _Static_assert() when there is a message.
That just makes the error message worse.
Hacking at the error message, it comes from (expanded by min()):
min(replicas_want, ({
do {
__attribute__((__noreturn__))
extern void __compiletime_assert_578(void)
__attribute__((__error__("Unsupported access size for {READ,WRITE}_ONCE().")));
if (...)
__compiletime_assert_578();
} while (0);
({
typeof(&(c->opts.metadata_replicas_required)) __x = &(c->opts.metadata_replicas_required);
int atomic = 1;
union {
typeof( _Generic((*__x),
char: (char)0,
unsigned char: (unsigned char)0,
signed char: (signed char)0,
unsigned short: (unsigned short)0,
signed short: (signed short)0,
unsigned int: (unsigned int)0,
signed int: (signed int)0,
unsigned long: (unsigned long)0,
signed long: (signed long)0,
unsigned long long: (unsigned long long)0,
signed long long: (signed long long)0,
default: (*__x))) __val;
char __c[1];
} __u;
switch (sizeof(c->opts.metadata_replicas_required)) {
case 1: asm volatile("..." : "=r" (*(__u8 *)__u.__c) : "Q" (*__x) : "memory");
break;
case 2: asm volatile("..." : "=r" (*(__u16 *)__u.__c) : "Q" (*__x) : "memory");
break;
case 4: asm volatile("..." : "=r" (*(__u32 *)__u.__c) : "Q" (*__x) : "memory");
break;
case 8: asm volatile("..." : "=r" (*(__u64 *)__u.__c) : "Q" (*__x) : "memory");
break;
default:
atomic = 0;
}
atomic ? (typeof(*__x))__u.__val : (*(volatile typeof(__x))__x);
});
}))So I suspect it is min(replicas_want, READ_ONCE(replices_required)). I think replicas_want is unsigned (int) and replicas_required u8.
Quoted 15 lines · Nathan Chancellor
Quoted 13 lines
Hi all,
I am not really sure where to go with this, so I figured I would loop some people in and see if we can figure out what is going on here.
After commit
67a8e7de7ef0("bcachefs: Clampreplicas_requiredto replicas") in linux-next, I see a massive error occur when building for ARCH=arm64 with bothCONFIG_BCACHEFS_FSandCONFIG_LTOenabled, which is important because arm64 defines its own__READ_ONCE()with LTO enabled. The error appears to be related to theminmax.hchanges that went into 6.7; I think it is specifically around commitd03eba99f5bf("minmax:
allow min()/max()/clamp() if the arguments have the same signedness.").
Quoted 4 lines
Quoted 4 lines
As far as I can tell,
replicas_wantand themetadata_replicas_requiredmember in structbch_optsshould have the same signedness, unless the__READ_ONCE()macro is messing something up, which is kind of hard to tell at this point...
The last line of that READ_ONCE() expansion looks dubious to me. The result type is independent of 'atomic' and I suspect ?: counts as an arithmetic operation and u8 gets promoted to int.
That would fail the old min() as well as the new one. Is this code new? I can see it online in 6.8.4-rc4.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
From: Nathan Chancellor
Quoted 15 lines
Sent: 13 February 2024 21:57
Hi all,
I am not really sure where to go with this, so I figured I would loop some people in and see if we can figure out what is going on here.
After commit
67a8e7de7ef0("bcachefs: Clampreplicas_requiredto replicas") in linux-next, I see a massive error occur when building for ARCH=arm64 with bothCONFIG_BCACHEFS_FSandCONFIG_LTOenabled, which is important because arm64 defines its own__READ_ONCE()with LTO enabled. The error appears to be related to theminmax.hchanges that went into 6.7; I think it is specifically around commitd03eba99f5bf("minmax:
allow min()/max()/clamp() if the arguments have the same signedness.").
Quoted 6 lines
As far as I can tell,
replicas_wantand themetadata_replicas_requiredmember in structbch_optsshould have the same signedness, unless the__READ_ONCE()macro is messing something up, which is kind of hard to tell at this point...I'll keep poking at this tomorrow unless someone else beats me to it.
...
(Spotted in the main list - I've replied before!)
I've done another check, it is all down to:
Quoted 1 line
atomic ? (unsigned char)__u.__val : (*(unsigned char *volatile)__x);
A quick test shows that:
int q(int z)
{
return sizeof (z ? (char)z : (char)z);
}returns 4 - so the type will be 'int' and your min() has a signed v unsigned mismatch.
So READ_ONCE() is (sort of) broken.
Although I thought I'd added a '+ 0' and rechecked. That would convert the LHS (u8) to 'int' and a signed compare would then pass - but that might only have been for constants?
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)