Skip to content

Commit a945928

Browse files
committed
xen: Do not enable spinlocks before jump_label_init() has executed
xen_init_spinlocks() currently calls static_key_slow_inc() before jump_label_init() is invoked. When CONFIG_JUMP_LABEL is set (which usually is the case) the effect of this static_key_slow_inc() is deferred until after jump_label_init(). This is different from when CONFIG_JUMP_LABEL is not set, in which case the key is set immediately. Thus, depending on the value of config option, we may observe different behavior. In addition, when we come to __jump_label_transform() from jump_label_init(), the key (paravirt_ticketlocks_enabled) is already enabled. On processors where ideal_nop is not the same as default_nop this will cause a BUG() since it is expected that before a key is enabled the latter is replaced by the former during initialization. To address this problem we need to move static_key_slow_inc(&paravirt_ticketlocks_enabled) so that it is called after jump_label_init(). We also need to make sure that this is done before other cpus start to boot. early_initcall appears to be a good place to do so. (Note that we cannot move whole xen_init_spinlocks() there since pv_lock_ops need to be set before alternative_instructions() runs.) Signed-off-by: Konrad Rzeszutek Wilk <[email protected]> [v2: Added extra comments in the code] Signed-off-by: Boris Ostrovsky <[email protected]> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]> Reviewed-by: Steven Rostedt <[email protected]>
1 parent bf4a7c0 commit a945928

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

arch/x86/xen/spinlock.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ void xen_uninit_lock_cpu(int cpu)
259259
}
260260

261261

262+
/*
263+
* Our init of PV spinlocks is split in two init functions due to us
264+
* using paravirt patching and jump labels patching and having to do
265+
* all of this before SMP code is invoked.
266+
*
267+
* The paravirt patching needs to be done _before_ the alternative asm code
268+
* is started, otherwise we would not patch the core kernel code.
269+
*/
262270
void __init xen_init_spinlocks(void)
263271
{
264272

@@ -267,12 +275,26 @@ void __init xen_init_spinlocks(void)
267275
return;
268276
}
269277

270-
static_key_slow_inc(&paravirt_ticketlocks_enabled);
271-
272278
pv_lock_ops.lock_spinning = PV_CALLEE_SAVE(xen_lock_spinning);
273279
pv_lock_ops.unlock_kick = xen_unlock_kick;
274280
}
275281

282+
/*
283+
* While the jump_label init code needs to happend _after_ the jump labels are
284+
* enabled and before SMP is started. Hence we use pre-SMP initcall level
285+
* init. We cannot do it in xen_init_spinlocks as that is done before
286+
* jump labels are activated.
287+
*/
288+
static __init int xen_init_spinlocks_jump(void)
289+
{
290+
if (!xen_pvspin)
291+
return 0;
292+
293+
static_key_slow_inc(&paravirt_ticketlocks_enabled);
294+
return 0;
295+
}
296+
early_initcall(xen_init_spinlocks_jump);
297+
276298
static __init int xen_parse_nopvspin(char *arg)
277299
{
278300
xen_pvspin = false;

0 commit comments

Comments
 (0)