OK, so I setup different GDTs per processor-core in order to be able to retrieve the core selector that uniquely identifies the core to the OS. This seems to work most of the time (well, actually every time except at one specific occassion). I now have a crash-debugger report that is related to one core retrieving another core's core selector. It is evident that this had happened while the other core also was trying to get the core selector, because otherwise the scheduler-lock would not have failed (which was the reason the crash-debugger was invoked).
The code executed just before to get the core selector is very simple:
Code: Select all
push ax
mov ax,40h ; selector 40h is the core selector which has different GDT mappings per core.
mov fs,ax
mov fs,fs:ps_sel ; ps_sel is the core selector saved "within itself" which points to an unique selector.
pop ax
add fs:ps_nesting,1
jc lcDone
Crash ; this is the position the crash-debugger shows
lcDone:
ret
It would be possible to get to the present result in FS if using another core's GDT. Maybe AMD does not support having different GDTs per core? Or maybe nobody uses it, and AMD have made some optimizations that are broken when GDTs differ?
EDIT: In addition to this, the core which owed the selector loaded, also faults shortly afterwards when it's ps_nesting value is not the one expected (because the other core locked the wrong core).