Skip to content

Commit dea8fcc

Browse files
dcpleungnashif
authored andcommitted
x86: clear GS at boot for x86_64
On Intel processors, if GS is not zero and is being set to zero, GS_BASE is also being set to zero. This would interfere with the actual use of GS_BASE for usespace. To avoid accidentally clearing GS_BASE, simply set GS to 0 at boot, so any subsequent clearing of GS will not clear GS_BASE. The clearing of GS_BASE was discovered while trying to figure out why the mem_protect test would hang within 10-20 repeated runs. GDB revealed that both GS and GS_BASE was set to zero when the tests hanged. After setting GS to zero at boot, the mem_protect tests were running repeated for 5,000+ times without hanging. Signed-off-by: Daniel Leung <[email protected]>
1 parent 8595a39 commit dea8fcc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

arch/x86/core/intel64/locore.S

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ enter_code64:
182182
movw %ax, %ss
183183
movw %ax, %fs
184184

185+
/* On Intel processors, if GS is not zero and is being set to
186+
* zero, GS_BASE is also being set to zero. This would interfere
187+
* with the actual use of GS_BASE for usespace. To avoid accidentally
188+
* clearing GS_BASE, simply set GS to 0 at boot, so any subsequent
189+
* clearing of GS will not clear GS_BASE.
190+
*/
191+
mov $0, %eax
192+
movw %ax, %gs
193+
185194
movw __x86_cpuboot_t_tr_OFFSET(%rbp), %ax
186195
ltr %ax
187196

0 commit comments

Comments
 (0)