Skip to content

Commit

Permalink
x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask'
Browse files Browse the repository at this point in the history
Clang builds with defconfig started crashing after the following
commit:

  fb43d6c ("x86/mm: Do not auto-massage page protections")

This was caused by introducing a new global access in __startup_64().

Code in __startup_64() can be relocated during execution, but the compiler
doesn't have to generate PC-relative relocations when accessing globals
from that function. Clang actually does not generate them, which leads
to boot-time crashes. To work around this problem, every global pointer
must be adjusted using fixup_pointer().

Signed-off-by: Alexander Potapenko <[email protected]>
Reviewed-by: Dave Hansen <[email protected]>
Acked-by: Thomas Gleixner <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Fixes: fb43d6c ("x86/mm: Do not auto-massage page protections")
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
ramosian-glider authored and Ingo Molnar committed May 14, 2018
1 parent 4fe875e commit 4a09f02
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion arch/x86/kernel/head64.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ static bool __head check_la57_support(unsigned long physaddr)
}
#endif

/* Code in __startup_64() can be relocated during execution, but the compiler
* doesn't have to generate PC-relative relocations when accessing globals from
* that function. Clang actually does not generate them, which leads to
* boot-time crashes. To work around this problem, every global pointer must
* be adjusted using fixup_pointer().
*/
unsigned long __head __startup_64(unsigned long physaddr,
struct boot_params *bp)
{
Expand All @@ -113,6 +119,7 @@ unsigned long __head __startup_64(unsigned long physaddr,
p4dval_t *p4d;
pudval_t *pud;
pmdval_t *pmd, pmd_entry;
pteval_t *mask_ptr;
bool la57;
int i;
unsigned int *next_pgt_ptr;
Expand Down Expand Up @@ -196,7 +203,8 @@ unsigned long __head __startup_64(unsigned long physaddr,

pmd_entry = __PAGE_KERNEL_LARGE_EXEC & ~_PAGE_GLOBAL;
/* Filter out unsupported __PAGE_KERNEL_* bits: */
pmd_entry &= __supported_pte_mask;
mask_ptr = fixup_pointer(&__supported_pte_mask, physaddr);
pmd_entry &= *mask_ptr;
pmd_entry += sme_get_me_mask();
pmd_entry += physaddr;

Expand Down

0 comments on commit 4a09f02

Please sign in to comment.