Skip to contentSkip to conversation

Question about qspinlock nest

DISCUSSION Zhenzhong Duan 1 participant 1 message Jan 14, 2019

lore
Share & tools
lore
#0 lore raw
Quoted 54 lines · ----- [email protected] wrote:
Quoted 12 lines · Zhenzhong Duan
Quoted 9 lines · Waiman Long
Quoted 8 lines · Zhenzhong Duan

Hi Maintainer,

There is a question confused me for days. Appreciate an answer.

In below code, the comment says we never have more than 4 nested contexts.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

What happen if debug and mce exceptions nest with the four, or we ensure it never happen?

/*
 * Per-CPU queue node structures; we can never have more than 4

nested

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

 * contexts: task, softirq, hardirq, nmi.
 *
 * Exactly fits one 64-byte cacheline on a 64-bit architecture. *
 * PV doubles the storage and uses the second cacheline for PV

state.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

 */
static DEFINE_PER_CPU_ALIGNED(struct qnode, qnodes[MAX_NODES]);

Yes, both debug and mce exceptions are some kind of NMIs. So theoretically, it is possible to have more than four. Are you aware

of

Quoted 1 line
Quoted 1 line

any debug and MCE exception handlers that need to take a spinlock

for

Quoted 2 lines
Quoted 1 line

synchronization?

Not for debug exception, for MCE exception handler I found below

two:

Quoted 8 lines

do_machine_check->mce_report_event->schedule_work
do_machine_check->force_sig->force_sig_info

schedule_work() and force_sig_info() take spinlocks.

Signature · 2 lines
Thanks
Zhenzhong

The comment for do_machine_scheck() has already state that:

 * This is executed in NMI context not subject to normal locking rules. This
 * implies that most kernel services cannot be safely used. Don't even
 * think about putting a printk in there!

Quoted 4 lines

So even if it doesn't exceed the MAX_NODES limit, it could hit deadlock
and other kind of locking hazards. So supporting MCE is not a reason strong enough to extend MAX_NODES.

Agree.

Quoted 4 lines

In hindsight, we should have added a "BUG_ON(idx >= MAX_NODES);" check
to avoid silent corruption because of that issue.

Looks a good idea if it's hard to avoid using spinlock in MCE handler.

Thanks
Zhenzhong