Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86-32: Start out eflags and cr4 clean

%cr4 is supposed to reflect a set of features into which the operating
system is opting in. If the BIOS or bootloader leaks bits here, this
is not desirable. Consider a bootloader passing in %cr4.pae set to a
legacy paging kernel, for example -- it will not have any immediate
effect, but the kernel would crash when turning paging on.

A similar argument applies to %eflags, and since we have to look for
%eflags.id being settable we can use a sequence which clears %eflags
as a side effect.

Note that we already do this for x86-64.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Link: http://lkml.kernel.org/r/1348529239-17943-1-git-send-email-hpa@linux.intel.com

+16 -15
+16 -15
arch/x86/kernel/head_32.S
··· 287 287 leal -__PAGE_OFFSET(%ecx),%esp 288 288 289 289 default_entry: 290 - 291 290 /* 292 291 * New page tables may be in 4Mbyte page mode and may 293 292 * be using the global pages. 294 293 * 295 294 * NOTE! If we are on a 486 we may have no cr4 at all! 296 - * So we do not try to touch it unless we really have 297 - * some bits in it to set. This won't work if the BSP 298 - * implements cr4 but this AP does not -- very unlikely 299 - * but be warned! The same applies to the pse feature 300 - * if not equally supported. --macro 301 - * 302 - * NOTE! We have to correct for the fact that we're 303 - * not yet offset PAGE_OFFSET.. 295 + * Specifically, cr4 exists if and only if CPUID exists, 296 + * which in turn exists if and only if EFLAGS.ID exists. 304 297 */ 305 - #define cr4_bits pa(mmu_cr4_features) 306 - movl cr4_bits,%edx 307 - andl %edx,%edx 308 - jz 6f 309 - movl %cr4,%eax # Turn on paging options (PSE,PAE,..) 310 - orl %edx,%eax 298 + movl $X86_EFLAGS_ID,%ecx 299 + pushl %ecx 300 + popfl 301 + pushfl 302 + popl %eax 303 + pushl $0 304 + popfl 305 + pushfl 306 + popl %edx 307 + xorl %edx,%eax 308 + testl %ecx,%eax 309 + jz 6f # No ID flag = no CPUID = no CR4 310 + 311 + movl pa(mmu_cr4_features),%eax 311 312 movl %eax,%cr4 312 313 313 314 testb $X86_CR4_PAE, %al # check if PAE is enabled