LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask'
@ 2018-05-08 16:28 Alexander Potapenko
  2018-05-08 16:49 ` Dave Hansen
  2018-05-08 21:44 ` Kirill A. Shutemov
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander Potapenko @ 2018-05-08 16:28 UTC (permalink / raw)
  To: dave.hansen, mingo, kirill.shutemov
  Cc: linux-mm, linux-kernel, mka, dvyukov, md

Clang builds with defconfig started crashing after commit fb43d6cb91ef
("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 <glider@google.com>
Fixes: fb43d6cb91ef ("x86/mm: Do not auto-massage page protections")
---
 v2: better patch description, added a comment to __startup_64()
---
 arch/x86/kernel/head64.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 0c408f8c4ed4..9223792f6d0e 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -104,6 +104,13 @@ 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)
 {
@@ -113,6 +120,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;
@@ -196,7 +204,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 = (pteval_t *)fixup_pointer(&__supported_pte_mask, physaddr);
+	pmd_entry &= *mask_ptr;
 	pmd_entry += sme_get_me_mask();
 	pmd_entry +=  physaddr;
 
-- 
2.17.0.441.gb46fe60e1d-goog

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask'
  2018-05-08 16:28 [PATCH v2] x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask' Alexander Potapenko
@ 2018-05-08 16:49 ` Dave Hansen
  2018-05-08 21:44 ` Kirill A. Shutemov
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Hansen @ 2018-05-08 16:49 UTC (permalink / raw)
  To: Alexander Potapenko, mingo, kirill.shutemov
  Cc: linux-mm, linux-kernel, mka, dvyukov, md

On 05/08/2018 09:28 AM, Alexander Potapenko wrote:
> Clang builds with defconfig started crashing after commit fb43d6cb91ef
> ("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().

Looks good to me.  Thanks for adding the comment, especially!

Reviewed-by: Dave Hansen <dave.hansen@intel.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask'
  2018-05-08 16:28 [PATCH v2] x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask' Alexander Potapenko
  2018-05-08 16:49 ` Dave Hansen
@ 2018-05-08 21:44 ` Kirill A. Shutemov
  2018-05-09  9:16   ` Alexander Potapenko
  1 sibling, 1 reply; 4+ messages in thread
From: Kirill A. Shutemov @ 2018-05-08 21:44 UTC (permalink / raw)
  To: Alexander Potapenko
  Cc: dave.hansen, mingo, linux-mm, linux-kernel, mka, dvyukov, md

On Tue, May 08, 2018 at 04:28:29PM +0000, Alexander Potapenko wrote:
> @@ -196,7 +204,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 = (pteval_t *)fixup_pointer(&__supported_pte_mask, physaddr);

Do we really need the cast here?

-- 
 Kirill A. Shutemov

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask'
  2018-05-08 21:44 ` Kirill A. Shutemov
@ 2018-05-09  9:16   ` Alexander Potapenko
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Potapenko @ 2018-05-09  9:16 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: dave.hansen, Ingo Molnar, Linux Memory Management List, LKML,
	Matthias Kaehlcke, Dmitriy Vyukov, Michael Davidson

On Tue, May 8, 2018 at 11:44 PM Kirill A. Shutemov <
kirill.shutemov@linux.intel.com> wrote:

> On Tue, May 08, 2018 at 04:28:29PM +0000, Alexander Potapenko wrote:
> > @@ -196,7 +204,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 = (pteval_t *)fixup_pointer(&__supported_pte_mask,
physaddr);

> Do we really need the cast here?
Correct, we do not.

> --
>   Kirill A. Shutemov



-- 
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-09  9:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-08 16:28 [PATCH v2] x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask' Alexander Potapenko
2018-05-08 16:49 ` Dave Hansen
2018-05-08 21:44 ` Kirill A. Shutemov
2018-05-09  9:16   ` Alexander Potapenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).