Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp303117imd; Fri, 26 Oct 2018 08:47:16 -0700 (PDT) X-Google-Smtp-Source: AJdET5cQuxdwQeLWm/gQzfu5ql71MV8sW1F3ug5e7x5WFoeWu3WTpsQM5uptCLt8PQwulnq3e33K X-Received: by 2002:a62:5e02:: with SMTP id s2-v6mr4394426pfb.146.1540568836544; Fri, 26 Oct 2018 08:47:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540568836; cv=none; d=google.com; s=arc-20160816; b=HaTVcb+3tC2nKvA40H+XHDNgDDNDBGi199YxsslKDOAUrti7aLt+NWrvGkq48VWJHJ F/WwjZibkA9Ip9JOaUB+XbJqHTgzbbJ6nenIMcTNjs0H3JvBXCAzi0kh3/yxBRM6WQdu vdP/KQ+CWbWz+kRc4ggb4s5/k+8s2/ucoFtI0mZGsVcs1HRMi2EBLeyEo462CInd8eCJ GDRTnhC+iALjq1MpV/f3wg2HuI1Yrw3dKTxPabO4/nmwFpMyFkYBfuOlVO6TvVNSWLFU Zl3/vODAVphQ/hl/Aor+ICtYRdU+4vDWBFfFOfjcRyugH2Zu713WI5OnE5hOMQXQRr/8 zTAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=TDVOfKHdPX9ENJsQEHnx3D4ML6ByiLv/A6ECYgfKsqg=; b=clD7a05j404bEN8Au8GQ+KdKMjISLTJo9uqyi8tUdmy4WD0mxS9agGv22kZJzdrycU agOvHoLgkkXtgMOGKPCs38B9WobaM/FnwmfksSGnMrLPAJucCV7WhLSXWB8RdcRBDOWG 1awMnjo8F9Awtxyc95qex5FngcQWlpa/x2BvtJw+QGPeEpJRtMhC48rtVaimGxMmW6nV KKrdrOk44AhRp3CelNsRPPQBUqA3Z0K6d9nyTBmEkMzo1hzZMBA6e7EI79TuwFODzo4F jsrtkETvyqksiG+Z/tZhqGMr6wtQdM8XDungpXAzo4m0Hc1ZH83fFjhzuOhldHbZtlL/ 9kTQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h17-v6si10703068pfi.84.2018.10.26.08.47.00; Fri, 26 Oct 2018 08:47:16 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727581AbeJ0AXu (ORCPT + 99 others); Fri, 26 Oct 2018 20:23:50 -0400 Received: from mga03.intel.com ([134.134.136.65]:31218 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbeJ0AXu (ORCPT ); Fri, 26 Oct 2018 20:23:50 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Oct 2018 08:46:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,428,1534834800"; d="scan'208";a="84404096" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.193]) by orsmga007.jf.intel.com with ESMTP; 26 Oct 2018 08:46:17 -0700 Date: Fri, 26 Oct 2018 08:46:17 -0700 From: Sean Christopherson To: Julian Stecklina Cc: kvm@vger.kernel.org, Paolo Bonzini , js@alien8.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] kvm, vmx: move register clearing out of assembly path Message-ID: <20181026154617.GA23663@linux.intel.com> References: <09986c98c9655f1542768ecfda644ac821e67a57.1540369608.git.jsteckli@amazon.de> <558fea0b4df498eefcaea5ae07a089ad9706c1a2.1540369608.git.jsteckli@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <558fea0b4df498eefcaea5ae07a089ad9706c1a2.1540369608.git.jsteckli@amazon.de> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 24, 2018 at 10:28:57AM +0200, Julian Stecklina wrote: > 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 > --- > arch/x86/kvm/vmx.c | 33 ++++++++++++++++++++------------- > 1 file changed, 20 insertions(+), 13 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 93562d5..9225099 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -10797,20 +10797,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" > - "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" > @@ -10847,6 +10834,26 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) > #endif > ); > > + /* Don't let guest register values survive. */ > + asm volatile ( > + "" > +#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 > + :: "a" (0), "b" (0), "S" (0), "D" (0) Since clearing the GPRs exists to mitigate speculation junk, I think we should keep the explicit XOR zeroing instead of deferring to the compiler. Explicit XORs will ensure the resulting assembly is the same regardless of compiler, version, target arch, etc..., whereas the compiler could theoretically use different zeroing methods[1], e.g. on my system it generates "mov r32,r32" for EBX, ESI and EDI (loading from EAX after EAX is zeroed). And FWIW, I find the original code to be more readable since all GRPs are zeroed with the same method. [1] As an aside, I was expecting gcc to generate "xor r32,r32" with -mtune=sandybridge as sandybridge can do mov elimination on xors that explicitly zero a register but not on generic reg-to-reg mov, but I was unable to coerce gcc into using xor. > + : "cc" > +#ifdef CONFIG_X86_64 > + , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" > +#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 > -- > 2.7.4 >