Re: Yet another KPTI regression with 4.14.x series in a VM

From: David Woodhouse
Date: Sat Jan 13 2018 - 09:14:27 EST


On Sat, 2018-01-13 at 14:10 +0100, Peter Zijlstra wrote:
> On Sat, Jan 13, 2018 at 12:30:11PM +0000, David Woodhouse wrote:
> >
> > On Sat, 2018-01-13 at 13:08 +0100, Peter Zijlstra wrote:
> > >
> > >
> > > ÂÂÂÂÂÂÂÂALTERNATIVE "orq $(PTI_SWITCH_PGTABLE_MASK), \scratch_reg",
> > > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "orq $(PTI_SWITCH_MASK), \scratch_reg", X86_FEATURE_PCID
> > >
> > > Is not wanting to compile though; probably that whole alternative vs
> > > macro thing again :/
> > Welcome to my world. Try
> >
> > ÂALTERNATIVE __stringify(orq $(PTI_SWITCH_PGTABLE_MASK), \scratch_reg), \
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂ__stringify(orq $(PTI_SWITCH_MASK), \scratch_reg), \
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂX86_FEATURE_PCID
> Doesn't seem to work, gets literal __stringy() crud in the .s file.

--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -1,5 +1,6 @@
Â/* SPDX-License-Identifier: GPL-2.0 */
Â#include <linux/jump_label.h>
+#include <linux/stringify.h>
Â#include <asm/unwind_hints.h>
Â#include <asm/cpufeatures.h>
Â#include <asm/page_types.h>
@@ -222,7 +223,10 @@ For 32-bit we have the following conventions - kernel is built with
Â#define THIS_CPU_user_pcid_flush_maskÂÂÂ\
ÂÂÂÂÂÂÂÂPER_CPU_VAR(cpu_tlbstate) + TLB_STATE_user_pcid_flush_mask
Â
-.macro SWITCH_TO_USER_CR3_NOSTACK scratch_reg:req scratch_reg2:req
+.macro SWITCH_TO_USER_CR3_NOSTACK scratch_reg:req scratch_reg2:req \
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂpti_sw_mask=__stringify(PTI_SWITCH_MASK) \
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂpti_sw_pgt_mask=PTI_SWITCH_PGTABLES_MASK
+
ÂÂÂÂÂÂÂÂALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
ÂÂÂÂÂÂÂÂmovÂÂÂÂÂ%cr3, \scratch_reg
Â
@@ -247,7 +251,9 @@ For 32-bit we have the following conventions - kernel is built with
Â
Â.Lwrcr3_\@:
ÂÂÂÂÂÂÂÂ/* Flip the PGD and ASID to the user version */
-ÂÂÂÂÂÂÂorqÂÂÂÂÂ$(PTI_SWITCH_MASK), \scratch_reg
+ÂÂÂÂÂÂÂALTERNATIVE __stringify(orq $\pti_sw_pgt_mask, \scratch_reg),ÂÂÂ\
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ__stringify(orq $\pti_sw_mask, \scratch_reg),ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ\
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂX86_FEATURE_PCID
ÂÂÂÂÂÂÂÂmovÂÂÂÂÂ\scratch_reg, %cr3
Â.Lend_\@:
Â.endm

Yeah you need to 'stringify' the first of the macro args (pti_sw_mask)
because its default value being in parens confuses the very primitive
.macro arg processing. The last arg is fine.

This shit makes my brain hurt.

Attachment: smime.p7s
Description: S/MIME cryptographic signature