The usage of Intel GS segment
在阅读KVM-Unit-Tests过程中,看到了asm ("mov %0, %%gs:0" : : "r"(apic_id()) : "memory");,不是很明白,因此,特此写一篇文章记录下Intel GS segment的相关用法。
1. Description in SDM

2. Usage
- The GS segment can be used for thread local storage.
- The GS segment can be used for per-CPU data.
3. Source code in KVM-Unit-Tests
commit id: ca785dae0dd343b1de4b3f5d6c1223d41fbc39e7

1 | MSR_GS_BASE = 0xc0000101 |
MSR_GS_BASE MSR的描述如下:
stack的layout可以以stacktop为关键字,在cstart64.S中搜索。
Here’re the example to use GS segment to access per-CPU data:
1 | int smp_id(void) |
参考资料: