Re: [tip:locking/core 6/10] arch/x86/include/asm/rmwcc.h:23:17: error: jump into statement expression

From: Peter Zijlstra
Date: Mon Oct 22 2018 - 06:14:15 EST


On Sat, Oct 20, 2018 at 11:05:11AM +0800, kbuild test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/core
> head: 01a14bda11add9dcd4a59200f13834d634559935
> commit: 7aa54be2976550f17c11a1c3e3630002dea39303 [6/10] locking/qspinlock, x86: Provide liveness guarantee
> config: x86_64-randconfig-u0-10201040 (attached as .config)
> compiler: gcc-5 (Debian 5.5.0-3) 5.4.1 20171010
> reproduce:
> git checkout 7aa54be2976550f17c11a1c3e3630002dea39303
> # save the attached .config to linux build tree
> make ARCH=x86_64
>
> All errors (new ones prefixed by >>):
>
> In file included from arch/x86/include/asm/atomic.h:5:0,
> from include/linux/atomic.h:7,
> from include/linux/crypto.h:20,
> from arch/x86/kernel/asm-offsets.c:9:
> arch/x86/include/asm/qspinlock.h: In function 'queued_fetch_set_pending_acquire':
> >> arch/x86/include/asm/rmwcc.h:23:17: error: jump into statement expression
> : clobbers : cc_label); \
> ^
> include/linux/compiler.h:58:42: note: in definition of macro '__trace_if'
> if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
> ^

ARGH; so, this:

#define __GEN_RMWcc(fullop, _var, cc, clobbers, ...) \
({ \
bool c = false; \
asm_volatile_goto (fullop "; j" #cc " %l[cc_label]" \
: : [var] "m" (_var), ## __VA_ARGS__ \
: clobbers : cc_label); \
if (0) { \
cc_label: c = true; \
} \
c; \
})

static __always_inline u32 queued_fetch_set_pending_acquire(struct qspinlock *lock)
{
u32 val = 0;

if (GEN_BINARY_RMWcc(LOCK_PREFIX "btsl", lock->val.counter, c,
"I", _Q_PENDING_OFFSET))
val |= _Q_PENDING_VAL;

val |= atomic_read(&lock->val) & ~_Q_PENDING_MASK;

return val;
}

fails to compile when combined with this:

#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
#define __trace_if(cond) \
if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
({ \
int ______r; \
static struct ftrace_branch_data \
__attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_branch"))) \
______f = { \
.func = __func__, \
.file = __FILE__, \
.line = __LINE__, \
}; \
______r = !!(cond); \
______f.miss_hit[______r]++; \
______r; \
}))

Because that moves the __GEN_RMWcc into a statement expression and GCC
apparently doesn't like labels inside statement expressions.

If we avoid if() and rewrite queued_fetch_set_pending_acquire() like so:

static __always_inline u32 queued_fetch_set_pending_acquire(struct qspinlock *lock)
{
bool pending;
u32 val;

pending = GEN_BINARY_RMWcc(LOCK_PREFIX "btsl", lock->val.counter, c,
"I", _Q_PENDING_OFFSET);

val = pending * _Q_PENDING_VAL;
val |= atomic_read(&lock->val) & ~_Q_PENDING_MASK;

return val;
}

then it compiles again; but urgh.

Anybody see a better solution?