Skip to contentSkip to conversation

One question about ghes_notify_nmi

DISCUSSION [email protected] 2 participants 2 messages Oct 30, 2020 ACPI

lore
Share & tools
lore
#0 lore raw

From: Aili Yao <[email protected]>

Hi!

Sorry for my ignorance,When I look in to this code, I am totally condused. The Line 1136 has guarranted that Only one NMI will enter following code I think, Is this right? if so, what is ghes_notify_lock_nmi going to pretect?
Can any one help correct me?

   1131 static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
   1132 {
   1133         static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi);
   1134         int ret = NMI_DONE;
   1135 
   1136         if (!atomic_add_unless(&ghes_in_nmi, 1, 1))
   1137                 return ret;
   1138 
   1139         raw_spin_lock(&ghes_notify_lock_nmi);
   1140         if (!ghes_in_nmi_spool_from_list(&ghes_nmi, FIX_APEI_GHES_NMI))
   1141                 ret = NMI_HANDLED;
   1142         raw_spin_unlock(&ghes_notify_lock_nmi);
   1143 
   1144         atomic_dec(&ghes_in_nmi);
   1145         return ret;
   1146 }

Thanks
Aili Yao

#1 lore raw

Hello,

Quoted 2 lines · On 30/10/2020 02:41, [email protected] wrote:

From: Aili Yao <[email protected]>
Sorry for my ignorance,When I look in to this code, I am totally condused.

No worries - this code is pretty confusing!

Quoted 2 lines

The Line 1136 has guarranted that Only one NMI will enter following code I think, Is this right? if so, what is ghes_notify_lock_nmi going to pretect?

Looking at one of the others like ghes_notify_sea() might be simpler. The lock protects the fixmap slot, in case the notification occurs on multiple CPUs.

notify_nmi is weird as it has this atomic_add_unless() which seems to throw away some of the CPUs if they arrive ~together. It was added by commit 6fe9e7c26a971 ("GHES: Make NMI handler have a single reader"), which describes the motivation.

I'm not familiar with how x86 CPUs trigger NMI. From the commit message I've assumed this means there is some broadcast source of NMI, that is never firmware-first. I thought the trip via SMM for firmware-first did 'something' to hold the other CPUs so only one CPU takes the NMI - but I couldn't find it last time I went looking.

As I've no idea how this works, I decided not to change it. I added the spinlock so that the the fixmap slot provided to ghes_in_nmi_spool_from_list() is always protected by a spinlock, but the atomic means that for notify_nmi, the lock will never be contended.

Thanks,

James