All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: speck@linutronix.de
Subject: [patch V5 02/10] KVM magic # 2
Date: Mon, 02 Jul 2018 17:44:28 +0200	[thread overview]
Message-ID: <20180702160528.648412830@linutronix.de> (raw)
In-Reply-To: 20180702154426.910579106@linutronix.de

From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [patch V5 02/10] x86/KVM/VMX: Add module argument for L1TF mitigation

Add a mitigation mode parameter "vmentry_l1d_flush" for CVE-2018-3620, aka
L1 terminal fault. The valid arguments are:

 - "always" 	L1D cache flush on every VMENTER.
 - "cond"	Conditional L1D cache flush, explained below
 - "never"	Disable the L1D cache flush mitigation

"cond" is trying to avoid L1D cache flushes on VMENTER if the code executed
between VMEXIT and VMENTER is considered safe, i.e. is not bringing any
interesting information into L1D which might exploited.

[ tglx: Split out from a larger patch ]

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 Documentation/admin-guide/kernel-parameters.txt |   12 ++++
 arch/x86/kvm/vmx.c                              |   59 ++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1973,6 +1973,18 @@
 			(virtualized real and unpaged mode) on capable
 			Intel chips. Default is 1 (enabled)
 
+	kvm-intel.vmentry_l1d_flush=[KVM,Intel] Mitigation for L1 Terminal Fault
+			CVE-2018-3620.
+
+			Valid arguments: never, cond, always
+
+			always: L1D cache flush on every VMENTER.
+			cond:	Flush L1D on VMENTER only when the code between
+				VMEXIT and VMENTER can leak host memory.
+			never:	Disables the mitigation
+
+			Default is cond (do L1 cache flush in specific instances)
+
 	kvm-intel.vpid=	[KVM,Intel] Disable Virtual Processor Identification
 			feature (tagged TLBs) on capable Intel chips.
 			Default is 1 (enabled)
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -191,6 +191,54 @@ module_param(ple_window_max, uint, 0444)
 
 extern const ulong vmx_return;
 
+static DEFINE_STATIC_KEY_FALSE(vmx_l1d_should_flush);
+
+/* These MUST be in sync with vmentry_l1d_param order. */
+enum vmx_l1d_flush_state {
+	VMENTER_L1D_FLUSH_NEVER,
+	VMENTER_L1D_FLUSH_COND,
+	VMENTER_L1D_FLUSH_ALWAYS,
+};
+
+static enum vmx_l1d_flush_state __read_mostly vmentry_l1d_flush = VMENTER_L1D_FLUSH_COND;
+
+static const struct {
+	const char *option;
+	enum vmx_l1d_flush_state cmd;
+} vmentry_l1d_param[] = {
+	{"never",	VMENTER_L1D_FLUSH_NEVER},
+	{"cond",	VMENTER_L1D_FLUSH_COND},
+	{"always",	VMENTER_L1D_FLUSH_ALWAYS},
+};
+
+static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp)
+{
+	unsigned int i;
+
+	if (!s)
+		return -EINVAL;
+
+	for (i = 0; i < ARRAY_SIZE(vmentry_l1d_param); i++) {
+		if (!strcmp(s, vmentry_l1d_param[i].option)) {
+			vmentry_l1d_flush = vmentry_l1d_param[i].cmd;
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int vmentry_l1d_flush_get(char *s, const struct kernel_param *kp)
+{
+	return sprintf(s, "%s\n", vmentry_l1d_param[vmentry_l1d_flush].option);
+}
+
+static const struct kernel_param_ops vmentry_l1d_flush_ops = {
+	.set = vmentry_l1d_flush_set,
+	.get = vmentry_l1d_flush_get,
+};
+module_param_cb(vmentry_l1d_flush, &vmentry_l1d_flush_ops, &vmentry_l1d_flush, S_IRUGO);
+
 struct kvm_vmx {
 	struct kvm kvm;
 
@@ -13062,6 +13110,15 @@ static struct kvm_x86_ops vmx_x86_ops __
 	.enable_smi_window = enable_smi_window,
 };
 
+static void __init vmx_setup_l1d_flush(void)
+{
+	if (vmentry_l1d_flush == VMENTER_L1D_FLUSH_NEVER ||
+	    !boot_cpu_has_bug(X86_BUG_L1TF))
+		return;
+
+	static_branch_enable(&vmx_l1d_should_flush);
+}
+
 static int __init vmx_init(void)
 {
 	int r;
@@ -13095,6 +13152,8 @@ static int __init vmx_init(void)
 	}
 #endif
 
+	vmx_setup_l1d_flush();
+
 	r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx),
                      __alignof__(struct vcpu_vmx), THIS_MODULE);
 	if (r)

  parent reply	other threads:[~2018-07-02 16:11 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-02 15:44 [patch V5 00/10] KVM magic # 0 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 01/10] KVM magic # 1 Thomas Gleixner
2018-07-02 16:22   ` [MODERATED] " Konrad Rzeszutek Wilk
2018-07-02 17:10     ` Thomas Gleixner
2018-07-02 16:25   ` [MODERATED] " Borislav Petkov
2018-07-02 15:44 ` Thomas Gleixner [this message]
2018-07-02 15:44 ` [patch V5 03/10] KVM magic # 3 Thomas Gleixner
2018-07-02 23:42   ` [MODERATED] " Jon Masters
2018-07-02 15:44 ` [patch V5 04/10] KVM magic # 4 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 05/10] KVM magic # 5 Thomas Gleixner
2018-07-02 16:35   ` [MODERATED] " Konrad Rzeszutek Wilk
2018-07-02 17:01     ` Thomas Gleixner
2018-07-02 17:24   ` [MODERATED] " Paolo Bonzini
2018-07-03 15:21     ` Thomas Gleixner
2018-07-02 21:19   ` [MODERATED] Re: ***UNCHECKED*** " Alexander Graf
2018-07-02 23:45     ` Andrew Cooper
2018-07-03  1:33       ` Linus Torvalds
2018-07-03  8:23     ` Paolo Bonzini
2018-07-03 14:29       ` [MODERATED] Re: ***UNCHECKED*** " Alexander Graf
2018-07-05 19:08         ` Jon Masters
2018-07-05 21:43         ` Paolo Bonzini
2018-07-05 21:50           ` Linus Torvalds
2018-07-02 15:44 ` [patch V5 06/10] KVM magic # 6 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 07/10] KVM magic # 7 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 08/10] KVM magic # 8 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 09/10] KVM magic # 9 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 10/10] KVM magic # 10 Thomas Gleixner
2018-07-02 17:29   ` [MODERATED] " Paolo Bonzini
2018-07-02 17:41     ` Thomas Gleixner
2018-07-02 22:11       ` Thomas Gleixner
2018-07-03  9:05         ` [MODERATED] " Paolo Bonzini
2018-07-02 16:25 ` [patch V5 00/10] KVM magic # 0 Thomas Gleixner
2018-07-02 22:14 ` [MODERATED] [patch v5 11/10] Linux+KVM magic # 1 Jiri Kosina
2018-07-05 23:56   ` [MODERATED] " Josh Poimboeuf
2018-07-06 11:54     ` Jiri Kosina
2018-07-06 13:05       ` Konrad Rzeszutek Wilk
2018-07-06 15:11       ` Jon Masters

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=20180702160528.648412830@linutronix.de \
    --to=tglx@linutronix.de \
    --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.