All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: speck@linutronix.de
Subject: [MODERATED] Re: [PATCH v5 04/27] MDSv5 15
Date: Mon, 21 Jan 2019 23:33:53 -0500	[thread overview]
Message-ID: <20190122043353.GF12859@char.us.oracle.com> (raw)
In-Reply-To: <21244f88a3fad17a0bdbc48e085083590bb31ab0.1547858934.git.ak@linux.intel.com>

On Fri, Jan 18, 2019 at 04:50:19PM -0800, speck for Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
> Subject:  x86/speculation/mds: Support mds=full
> 
> Support a new command line option to support unconditional flushing
> on each kernel exit. This is not enabled by default.
> 
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> 
> ---
> 
> v2: Don't enable mds=full for MDS_NO because it will be a nop.

> ---
>  Documentation/admin-guide/kernel-parameters.txt | 5 +++++
>  arch/x86/entry/common.c                         | 7 ++++++-
>  arch/x86/include/asm/clearcpu.h                 | 2 ++
>  arch/x86/kernel/cpu/bugs.c                      | 5 +++++
>  4 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 9c967d0caeca..5f5a8808c475 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -2360,6 +2360,11 @@
>  	mds=off		[X86, Intel]
>  			Disable workarounds for Micro-architectural Data Sampling.
>  
> +	mds=full	[X86, Intel]
> +			Always flush cpu buffers when exiting kernel for MDS.

.. which implies that the microcode must be loaded. But right now you could do
'mds=full' on a machine _without_ the microcode and it would just do 'verw'.

And that unpatched 'verw' would most certainly _not_ flush CPU buffers. See below
in  mds_select_mitigation

> +			Normally the kernel decides dynamically when flushing is
> +			needed or not.

Can you follow the same standard as 'ssbd' and 'l1tf' - which is that this turns
in 'mds=[off,full] and then each one has an explanation please?

> +
>  	mem=nn[KMG]	[KNL,BOOT] Force usage of a specific amount of memory
>  			Amount of memory to be used when the kernel is not able
>  			to see the whole system memory or for test.
> diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
> index 924f8dab2068..66c08e1d493a 100644
> --- a/arch/x86/entry/common.c
> +++ b/arch/x86/entry/common.c
> @@ -173,7 +173,9 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
>  
>  		if (cached_flags & _TIF_CLEAR_CPU) {
>  			clear_thread_flag(TIF_CLEAR_CPU);
> -			clear_cpu();
> +			/* Don't do it twice if forced */
> +			if (!static_key_enabled(&force_cpu_clear))
> +				clear_cpu();
>  		}
>  
>  		/* Disable IRQs and retry */
> @@ -217,6 +219,9 @@ __visible inline void prepare_exit_to_usermode(struct pt_regs *regs)
>  	ti->status &= ~(TS_COMPAT|TS_I386_REGS_POKED);
>  #endif
>  
> +	if (static_key_enabled(&force_cpu_clear))
> +		clear_cpu();
> +
>  	user_enter_irqoff();
>  }
>  
> diff --git a/arch/x86/include/asm/clearcpu.h b/arch/x86/include/asm/clearcpu.h
> index 530ef619ac1b..3b8ee76b9c07 100644
> --- a/arch/x86/include/asm/clearcpu.h
> +++ b/arch/x86/include/asm/clearcpu.h
> @@ -20,4 +20,6 @@ static inline void clear_cpu(void)
>  		[kernelds] "m" (kernel_ds));
>  }
>  
> +DECLARE_STATIC_KEY_FALSE(force_cpu_clear);

'force_cpu_clear' sounds quite vague. As in in three months I will not remember the name
of this. Perhaps 'force_verw' ? Or 'force_mds_verw'?


> +
>  #endif
> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
> index 2fd8faa7e23a..ce0e367753ff 100644
> --- a/arch/x86/kernel/cpu/bugs.c
> +++ b/arch/x86/kernel/cpu/bugs.c
> @@ -1061,11 +1061,16 @@ early_param("l1tf", l1tf_cmdline);
>  
>  #undef pr_fmt
>  
> +DEFINE_STATIC_KEY_FALSE(force_cpu_clear);
> +
>  static void mds_select_mitigation(void)
>  {
>  	if (cmdline_find_option_bool(boot_command_line, "mds=off") ||
>  		!boot_cpu_has_bug(X86_BUG_MDS))
>  		setup_force_cpu_cap(X86_FEATURE_NO_VERW);
> +	if (cmdline_find_option_bool(boot_command_line, "mds=full") &&
> +		boot_cpu_has_bug(X86_BUG_MDS))
> +		static_branch_enable(&force_cpu_clear);

The 'mds=full' can be done on machines without the new microcode and it sets MDS
    (twice) and also does 'VERW' without any benefit. 

Why not make this:

if (!boot_cpu_has_bug(X86_BUG_MDS) {
	setup_force_cpu_cap(X86_FEATURE_NO_VERW);
	return;
} else {
	if (cmdline_find_option_bool(boot_command_line, "mds=off"))
		setup_force_cpu_cap(X86_FEATURE_NO_VERW);
	if (cmdline_find_option_bool(boot_command_line, "mds=full") && boot_cpu_has_bug(X86_BUG_MDS))
		static_branch_enable(&force_cpu_clear);
}

?


>  }
>  
>  #ifdef CONFIG_SYSFS
> -- 
> 2.17.2

  reply	other threads:[~2019-01-22  4:34 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-19  0:50 [MODERATED] [PATCH v5 00/27] MDSv5 19 Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 01/27] MDSv5 26 Andi Kleen
2019-01-22  4:17   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-22 12:46   ` Thomas Gleixner
2019-01-19  0:50 ` [MODERATED] [PATCH v5 02/27] MDSv5 14 Andi Kleen
2019-01-22  4:20   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-22 12:51   ` Thomas Gleixner
2019-01-19  0:50 ` [MODERATED] [PATCH v5 03/27] MDSv5 16 Andi Kleen
2019-01-22  4:23   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-22 12:55   ` Thomas Gleixner
2019-01-27 21:58   ` Thomas Gleixner
2019-01-28  3:30     ` [MODERATED] " Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 04/27] MDSv5 15 Andi Kleen
2019-01-22  4:33   ` Konrad Rzeszutek Wilk [this message]
2019-01-22 12:59   ` Thomas Gleixner
2019-01-19  0:50 ` [MODERATED] [PATCH v5 05/27] MDSv5 21 Andi Kleen
2019-01-22  4:35   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-22 13:01   ` Thomas Gleixner
2019-02-21 12:06   ` Thomas Gleixner
2019-01-19  0:50 ` [MODERATED] [PATCH v5 06/27] MDSv5 18 Andi Kleen
2019-01-21 22:41   ` [MODERATED] " Josh Poimboeuf
2019-01-22  1:16     ` Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 07/27] MDSv5 0 Andi Kleen
2019-01-22  4:39   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-27 22:09   ` Thomas Gleixner
2019-01-28  3:33     ` [MODERATED] " Andi Kleen
2019-01-28  8:29       ` Thomas Gleixner
2019-02-13 22:26   ` [MODERATED] " Tyler Hicks
2019-01-19  0:50 ` [MODERATED] [PATCH v5 08/27] MDSv5 13 Andi Kleen
2019-01-22  4:40   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-19  0:50 ` [MODERATED] [PATCH v5 09/27] MDSv5 23 Andi Kleen
2019-01-22  4:56   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-22  7:26   ` Greg KH
2019-01-22 13:07   ` Thomas Gleixner
2019-01-19  0:50 ` [MODERATED] [PATCH v5 10/27] MDSv5 7 Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 11/27] MDSv5 2 Andi Kleen
2019-01-22 13:11   ` Thomas Gleixner
2019-01-19  0:50 ` [MODERATED] [PATCH v5 12/27] MDSv5 6 Andi Kleen
2019-01-22 14:01   ` Thomas Gleixner
2019-01-22 15:42     ` Thomas Gleixner
2019-01-22 18:01     ` [MODERATED] " Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 13/27] MDSv5 17 Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 14/27] MDSv5 3 Andi Kleen
2019-01-22  4:48   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-22 15:58   ` Thomas Gleixner
2019-01-22 17:57     ` Thomas Gleixner
2019-01-23  1:35       ` [MODERATED] " Andi Kleen
2019-01-23  9:27         ` Thomas Gleixner
2019-01-23 16:02           ` [MODERATED] " Andi Kleen
2019-01-23 22:40             ` Josh Poimboeuf
2019-01-23 22:57               ` Josh Poimboeuf
2019-01-24  0:25                 ` Josh Poimboeuf
2019-01-24  2:26               ` Andi Kleen
2019-01-24 12:04             ` Thomas Gleixner
2019-01-28  3:42               ` [MODERATED] " Andi Kleen
2019-01-28  8:33                 ` Thomas Gleixner
2019-02-16  2:00       ` [MODERATED] " Andi Kleen
2019-02-16 10:32         ` Thomas Gleixner
2019-02-16 16:58           ` [MODERATED] " Andi Kleen
2019-02-16 17:12             ` Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 15/27] MDSv5 1 Andi Kleen
2019-01-22  4:48   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-19  0:50 ` [MODERATED] [PATCH v5 16/27] MDSv5 10 Andi Kleen
2019-01-22  4:54   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-22  7:33   ` Greg KH
2019-01-19  0:50 ` [MODERATED] [PATCH v5 17/27] MDSv5 9 Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 18/27] MDSv5 8 Andi Kleen
2019-01-22  5:07   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-19  0:50 ` [MODERATED] [PATCH v5 19/27] MDSv5 12 Andi Kleen
2019-01-22  5:09   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-19  0:50 ` [MODERATED] [PATCH v5 20/27] MDSv5 27 Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 21/27] MDSv5 20 Andi Kleen
2019-01-22  5:11   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-19  0:50 ` [MODERATED] [PATCH v5 22/27] MDSv5 24 Andi Kleen
2019-01-21 21:24   ` [MODERATED] " Linus Torvalds
2019-01-22  1:22     ` Andi Kleen
2019-01-22 16:09       ` Thomas Gleixner
2019-01-22 17:56         ` [MODERATED] " Andi Kleen
2019-01-22 18:56           ` Thomas Gleixner
2019-01-23  1:39             ` [MODERATED] " Andi Kleen
2019-01-23  6:39               ` Greg KH
2019-01-24  9:55               ` Thomas Gleixner
2019-01-19  0:50 ` [MODERATED] [PATCH v5 23/27] MDSv5 22 Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 24/27] MDSv5 5 Andi Kleen
2019-01-21 21:20   ` [MODERATED] " Linus Torvalds
2019-01-19  0:50 ` [MODERATED] [PATCH v5 25/27] MDSv5 4 Andi Kleen
2019-01-22  5:15   ` [MODERATED] " Konrad Rzeszutek Wilk
2019-01-19  0:50 ` [MODERATED] [PATCH v5 26/27] MDSv5 11 Andi Kleen
2019-01-19  0:50 ` [MODERATED] [PATCH v5 27/27] MDSv5 25 Andi Kleen
2019-01-21 21:18 ` [MODERATED] Re: [PATCH v5 00/27] MDSv5 19 Linus Torvalds
2019-01-22  1:14   ` Andi Kleen
2019-01-22  7:38     ` Greg KH
2019-01-28 11:34 ` Thomas Gleixner
2019-02-13 22:33   ` [MODERATED] " Tyler Hicks
2019-02-14 13:09     ` Jiri Kosina
2019-02-14 13:51       ` Greg KH
2019-02-14 16:53       ` Andi Kleen
2019-02-14 18:00         ` Greg KH
2019-02-14 18:05           ` Andrew Cooper
2019-02-14 18:33           ` Andi Kleen
2019-02-14 18:52             ` Greg KH
2019-02-14 19:50               ` Andi Kleen
2019-02-15  7:06                 ` Greg KH
2019-02-15 13:06                   ` Andi Kleen
2019-02-19 12:12                     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190122043353.GF12859@char.us.oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=speck@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.