Re: Question about qspinlock nest

From: Waiman Long
Date: Fri Jan 11 2019 - 11:59:41 EST


On 01/11/2019 12:06 AM, Zhenzhong Duan wrote:
>
>
> On 2019/1/10 22:43, Waiman Long wrote:
>> On 01/10/2019 03:02 AM, Zhenzhong Duan wrote:
>>> 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.
>>>
>>> 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
>>> Â* 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.
>>> Â*/
>>> 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
>> any debug and MCE exception handlers that need to take a spinlock for
>> synchronization?
> Not for debug exception, for MCE exception handler I found below two:
>
> do_machine_check->mce_report_event->schedule_work
> do_machine_check->force_sig->force_sig_info
>
> schedule_work() and force_sig_info() take spinlocks.
> --
> 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!

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.

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

Thanks,
Longman