Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3546406imd; Mon, 29 Oct 2018 08:42:20 -0700 (PDT) X-Google-Smtp-Source: AJdET5fPVPdn0RAU4KUrLNABJz+ra+VzoHOLteEDyuPhTadzLFBuz1lyy8DJo44uA4LokIBLvtez X-Received: by 2002:a63:413:: with SMTP id 19mr14200437pge.7.1540827740831; Mon, 29 Oct 2018 08:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540827740; cv=none; d=google.com; s=arc-20160816; b=PXEgBuWDWkOKcCNgAm70SzZifXzVUmMx0NfEdCFhg0K5BhkAka3+t3l810qR4lruhT IYDJXDh/2e2g89oFW22GBSpKp6qSEKe3/PaIrMg8LazOPc9WCGqGL2FerphUqQdeU/gl /SJ+LdcYt9BGsgGufj1Ihz8cbr6LwIbN7WaO/3TiiC1zaHcP4MSBNVB0CwIua4ZbX/Zf DLutuL3ucSLmADU6wsxZoBL5BXhVFvBfphh6oKKvXjkD738RB3qRLmW0AuJ6sbKvZM98 K3aTMPnwKV0Kg+5IofFa6QyAfXSX31QS3vX5hZQzqzgsRIhd8wY4J9xVdMbypy02Q1O5 Knzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=BZyxgBHLGH4Lg47rL08aS0lODyuUZeuDeiy+P3SGpnA=; b=e7TPLyKRAZ9v0kGguz3oy3w1tyYTyUUANPf5GZXGnZZG2YMd1uuN4DVUAxOpqhWYSI /tHPlx+qDuU8UOYps7aT8T1PImD7gaDvJX763H2WCy/26jF5CSLHzlelS851Yhs9jvvg Vng/0WaLDMOnej4RVkLdlVeVGJSbF1mSrCPAwcjbogum6vgsi3SZaXkAB7/kqTtajeLw sjdIggZ6J7SKBMxJC27gxOcA6wF/n/NmmzrBY0WVvagWZ5XunTnxz8ywrCrOYZoGUZXX Tq/099TchFDxDUH1i2Na5LhqfU0kowLqNhfRsyUe8c9wQL8IRJuERoue1Q8HKUgY+LwR I/zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=e5YeeAWD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si3311371pls.0.2018.10.29.08.42.05; Mon, 29 Oct 2018 08:42:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=e5YeeAWD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727651AbeJ3Aab (ORCPT + 99 others); Mon, 29 Oct 2018 20:30:31 -0400 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:64039 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727085AbeJ3Aab (ORCPT ); Mon, 29 Oct 2018 20:30:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1540827682; x=1572363682; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BZyxgBHLGH4Lg47rL08aS0lODyuUZeuDeiy+P3SGpnA=; b=e5YeeAWDpf5Bt816v8RA5LK6bM9un/9A6WyS1jekUTtowkV1pDQKtyeM 7jxyfV8YIxcsgyiPYwd9h6V9AGEvxgjrj0Frjfp/VppQe8o6sF2inQojv rLzM0eyaRDZENin4YAg22WTbYhTVbXTmkP1a7DGOwykbSU5A+KOE0Wlke k=; X-IronPort-AV: E=Sophos;i="5.54,440,1534809600"; d="scan'208";a="365610272" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-69849ee2.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Oct 2018 15:41:20 +0000 Received: from u54ee758033e858cfa736.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2a-69849ee2.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w9TFfGIp038342 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 29 Oct 2018 15:41:17 GMT Received: from u54ee758033e858cfa736.ant.amazon.com (localhost [127.0.0.1]) by u54ee758033e858cfa736.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w9TFfFcH000667; Mon, 29 Oct 2018 16:41:15 +0100 Received: (from jsteckli@localhost) by u54ee758033e858cfa736.ant.amazon.com (8.15.2/8.15.2/Submit) id w9TFfFJH000666; Mon, 29 Oct 2018 16:41:15 +0100 From: Julian Stecklina To: kvm@vger.kernel.org, Paolo Bonzini Cc: Julian Stecklina , Julian Stecklina , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] kvm, vmx: move register clearing out of assembly path Date: Mon, 29 Oct 2018 16:40:43 +0100 Message-Id: <33085f6c98496ed8094ce68855b49851abb86406.1540822350.git.jsteckli@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <74fa3809ea293cc05d37b1449b16e08480c4ddbd.1540822350.git.jsteckli@amazon.de> References: <74fa3809ea293cc05d37b1449b16e08480c4ddbd.1540822350.git.jsteckli@amazon.de> In-Reply-To: <74fa3809ea293cc05d37b1449b16e08480c4ddbd.1540822350.git.jsteckli@amazon.de> References: <74fa3809ea293cc05d37b1449b16e08480c4ddbd.1540822350.git.jsteckli@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split the security related register clearing out of the large inline assembly VM entry path. This results in two slightly less complicated inline assembly statements, where it is clearer what each one does. Signed-off-by: Julian Stecklina Reviewed-by: Jan H. Schönherr Reviewed-by: Konrad Jan Miller Reviewed-by: Jim Mattson --- arch/x86/kvm/vmx.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index a6e5a5c..29a2ee7 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -11281,24 +11281,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) "mov %%r13, %c[r13](%0) \n\t" "mov %%r14, %c[r14](%0) \n\t" "mov %%r15, %c[r15](%0) \n\t" - /* - * Clear host registers marked as clobbered to prevent - * speculative use. - */ - "xor %%r8d, %%r8d \n\t" - "xor %%r9d, %%r9d \n\t" - "xor %%r10d, %%r10d \n\t" - "xor %%r11d, %%r11d \n\t" - "xor %%r12d, %%r12d \n\t" - "xor %%r13d, %%r13d \n\t" - "xor %%r14d, %%r14d \n\t" - "xor %%r15d, %%r15d \n\t" #endif - - "xor %%eax, %%eax \n\t" - "xor %%ebx, %%ebx \n\t" - "xor %%esi, %%esi \n\t" - "xor %%edi, %%edi \n\t" "pop %%" _ASM_BP "; pop %%" _ASM_DX " \n\t" ".pushsection .rodata \n\t" ".global vmx_return \n\t" @@ -11336,6 +11319,34 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) ); /* + * Don't let guest register values survive. Registers that cannot + * contain guest values anymore are not touched. + */ + asm volatile ( + "xor %%eax, %%eax \n\t" + "xor %%ebx, %%ebx \n\t" + "xor %%esi, %%esi \n\t" + "xor %%edi, %%edi \n\t" +#ifdef CONFIG_X86_64 + "xor %%r8d, %%r8d \n\t" + "xor %%r9d, %%r9d \n\t" + "xor %%r10d, %%r10d \n\t" + "xor %%r11d, %%r11d \n\t" + "xor %%r12d, %%r12d \n\t" + "xor %%r13d, %%r13d \n\t" + "xor %%r14d, %%r14d \n\t" + "xor %%r15d, %%r15d \n\t" +#endif + ::: "cc" +#ifdef CONFIG_X86_64 + , "rax", "rbx", "rsi", "rdi" + , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" +#else + , "eax", "ebx", "esi", "edi" +#endif + ); + + /* * We do not use IBRS in the kernel. If this vCPU has used the * SPEC_CTRL MSR it may have left it on; save the value and * turn it off. This is much more efficient than blindly adding -- 2.7.4