lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20171129114814.rait2d6u4gso5qqd@hirez.programming.kicks-ass.net>
Date:   Wed, 29 Nov 2017 12:48:14 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     linux-kernel@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>
Cc:     Dave Hansen <dave.hansen@...ux.intel.com>,
        Andy Lutomirski <luto@...nel.org>,
        Ingo Molnar <mingo@...nel.org>, Borislav Petkov <bp@...en8.de>,
        Brian Gerst <brgerst@...il.com>,
        Denys Vlasenko <dvlasenk@...hat.com>,
        "H. Peter Anvin" <hpa@...or.com>,
        Josh Poimboeuf <jpoimboe@...hat.com>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Rik van Riel <riel@...hat.com>, daniel.gruss@...k.tugraz.at,
        hughd@...gle.com, keescook@...gle.com, linux-mm@...ck.org,
        michael.schwarz@...k.tugraz.at, moritz.lipp@...k.tugraz.at,
        richard.fellner@...dent.tugraz.at,
        Andy Lutomirski <luto@...capital.net>
Subject: Re: [PATCH 4/6] x86/mm/kaiser: Support PCID without INVPCID

On Wed, Nov 29, 2017 at 11:33:05AM +0100, Peter Zijlstra wrote:

> XXX we could do a much larger ALTERNATIVE, there is no point in
> testing the mask if we don't have PCID support.

This.

> @@ -220,7 +215,27 @@ For 32-bit we have the following convent
>  .macro SWITCH_TO_USER_CR3 scratch_reg:req
>  	STATIC_JUMP_IF_FALSE .Lend_\@, kaiser_enabled_key, def=1
>  	mov	%cr3, \scratch_reg
> -	ADJUST_USER_CR3 \scratch_reg
> +
> +	/*
> +	 * Test if the ASID needs a flush.
> +	 */
> +	push	\scratch_reg			/* preserve CR3 */
> +	andq	$(0x7FF), \scratch_reg		/* mask ASID */
> +	bt	\scratch_reg, PER_CPU_VAR(user_asid_flush_mask)
> +	jnc	.Lnoflush_\@
> +
> +	/* Flush needed, clear the bit */
> +	btr	\scratch_reg, PER_CPU_VAR(user_asid_flush_mask)
> +	pop	\scratch_reg			/* original CR3 */
> +	jmp	.Ldo_\@
> +
> +.Lnoflush_\@:
> +	pop	\scratch_reg			/* original CR3 */
> +	ALTERNATIVE "", "bts $63, \scratch_reg", X86_FEATURE_PCID
> +
> +.Ldo_\@:
> +	/* Flip the PGD and ASID to the user version */
> +	orq     $(KAISER_SWITCH_MASK), \scratch_reg
>  	mov	\scratch_reg, %cr3
>  .Lend_\@:
>  .endm

Something like so seems to actually compile and generate sensible code,
not tested it though.


--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -216,6 +216,8 @@ For 32-bit we have the following convent
 	STATIC_JUMP_IF_FALSE .Lend_\@, kaiser_enabled_key, def=1
 	mov	%cr3, \scratch_reg
 
+	ALTERNATIVE "jmp .Ldo_\@", "", X86_FEATURE_PCID
+
 	/*
 	 * Test if the ASID needs a flush.
 	 */
@@ -231,7 +233,7 @@ For 32-bit we have the following convent
 
 .Lnoflush_\@:
 	pop	\scratch_reg			/* original CR3 */
-	ALTERNATIVE "", "bts $63, \scratch_reg", X86_FEATURE_PCID
+	bts	$63, \scratch_reg
 
 .Ldo_\@:
 	/* Flip the PGD and ASID to the user version */
@@ -266,6 +268,8 @@ For 32-bit we have the following convent
 .macro RESTORE_CR3 scratch_reg:req save_reg:req
 	STATIC_JUMP_IF_FALSE .Lend_\@, kaiser_enabled_key, def=1
 
+	ALTERNATIVE "jmp .Ldo_\@", "", X86_FEATURE_PCID
+
 	/* ASID bit 11 is for user */
 	bt	$11, \save_reg
 	/*
@@ -287,7 +291,7 @@ For 32-bit we have the following convent
 	jmp	.Ldo_\@
 
 .Lnoflush_\@:
-	ALTERNATIVE "", "bts $63, \save_reg", X86_FEATURE_PCID
+	bts	$63, \save_reg
 
 .Ldo_\@:
 	/*

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ