Received: by 10.223.176.5 with SMTP id f5csp1023766wra; Fri, 2 Feb 2018 09:53:38 -0800 (PST) X-Google-Smtp-Source: AH8x227XnT17pLjK2uZaNvYQjE8lJj4TA6QD58tRDzcxv5LvyEIVL4KC7wWY0V9YFhPQAGwILgkr X-Received: by 2002:a17:902:6186:: with SMTP id u6-v6mr34960877plj.390.1517594018877; Fri, 02 Feb 2018 09:53:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517594018; cv=none; d=google.com; s=arc-20160816; b=wwiUoBOZq0icjxfPEfV24dREPIZzlciImrQ55P/LBE9EywWNyijvkdm7zgeuqMspia GnEZ0AF3eVgu2+s92JYaLntSmcQmEZGLKlxNs0qJ4XOVRQnxpNvwaFQguuxPvQCeSp1R cFk5FKtjmOrJM1C+ZTBZgmqM109sas/42TQ+2qiPras3W/2PDZBE8bWBbM6HECRThZuE Fz6V8lFU7+/Rskl8GiI2jokKJp46dZ6J9Wg5tveiyfHfz2nqdYe1AA1g4DLMQ5wv9a9J IhA8B4N/+n82xzeEO20OyvBp5KJMwR9z1kjfoJGCwoE+fClaSgBwo4QDNpl9kUp0Xmau t0Qg== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=cPxk20a4h7guAjMfgyCSItslKIEZgRwyPaeCHrsHUwk=; b=oJVGJdYq5D3O+P2F6LBe/RxAQXCRoyRtflnObTzLKvuEowlnM1UQSayephU5JVxIJN WvQORKdH2yd1OzclXsUwmXMDZ0DmUUafsn0ZA+1wlWIgCDdIUNKCp9uf7/OzQXRNcPGF sozoflDvu/vctzBMzUIIrKUhRIOznnuTIJOsWSmAwq+BUKQdYikJGEgRjVrKOrt6zxan tXK4BxMlggKdedlK5U2t+oWbGgKQStWOaDOEw9qMuzdDEF5JMw5WJuxA2IYzp0Mw96bK c8JXDJy0QTIYV+9CQRifRTtoNN4ziUpOt7slyptMv9xQzrHqGdTs0S+UFKI8a7O9QwKG YeQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=hi/hlihH; 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=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a63si1416691pfk.72.2018.02.02.09.53.23; Fri, 02 Feb 2018 09:53:38 -0800 (PST) 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=@oracle.com header.s=corp-2017-10-26 header.b=hi/hlihH; 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=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753495AbeBBRvD (ORCPT + 99 others); Fri, 2 Feb 2018 12:51:03 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:60532 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753685AbeBBRu0 (ORCPT ); Fri, 2 Feb 2018 12:50:26 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w12Hg4j7146184; Fri, 2 Feb 2018 17:49:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=cPxk20a4h7guAjMfgyCSItslKIEZgRwyPaeCHrsHUwk=; b=hi/hlihHXVoMIQDpt6O/J/v8c4/BGCj38BDcg7FN10clMHXzh+QJ9VUdC7NqAWifpZDT QFzeJ1LTQqNtVLbNMEOa8bVopkAfCoLBTJF+pmZ2XW7ZcWKuv0oOAiD+/LjUA+vwXzz8 pxrCzwA5LdvXQ5q9ql2jeCN9N1aoUzBUErg5I3/JvhAcvjbkjjyU2zQPUqMiUs4X1ZLI 3vL/SLPNrKWhAYmzwUNUthO1LeMgJk5CaotilWosoqUBARtq5mMkhjS2tDB1sioTj+5R r4WWXLIQ1tjn66Gmdz3IP+RWb3RbH9jIONpHpjgCVzH3Ang23pl4FdYhyo+Y58g+dN6m Ng== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2fvv5804xe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 02 Feb 2018 17:49:36 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w12HnZLJ012101 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 2 Feb 2018 17:49:35 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w12HnYFU009416; Fri, 2 Feb 2018 17:49:34 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 02 Feb 2018 09:49:34 -0800 Received: by char.us.oracle.com (Postfix, from userid 1000) id 2CFF66A0A42; Fri, 2 Feb 2018 12:49:32 -0500 (EST) Date: Fri, 2 Feb 2018 12:49:32 -0500 From: Konrad Rzeszutek Wilk To: KarimAllah Ahmed Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Ashok Raj , Asit Mallick , Dave Hansen , Arjan Van De Ven , Tim Chen , Linus Torvalds , Andrea Arcangeli , Andi Kleen , Thomas Gleixner , Dan Williams , Jun Nakajima , Andy Lutomirski , Greg KH , Paolo Bonzini , Peter Zijlstra , David Woodhouse Subject: Re: [PATCH v6 2/5] KVM: x86: Add IBPB support Message-ID: <20180202174932.GR28192@char.us.oracle.com> References: <1517522386-18410-1-git-send-email-karahmed@amazon.de> <1517522386-18410-3-git-send-email-karahmed@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1517522386-18410-3-git-send-email-karahmed@amazon.de> User-Agent: Mutt/1.8.3 (2017-05-23) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8793 signatures=668661 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802020216 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 01, 2018 at 10:59:43PM +0100, KarimAllah Ahmed wrote: > From: Ashok Raj > > The Indirect Branch Predictor Barrier (IBPB) is an indirect branch > control mechanism. It keeps earlier branches from influencing > later ones. > > Unlike IBRS and STIBP, IBPB does not define a new mode of operation. > It's a command that ensures predicted branch targets aren't used after > the barrier. Although IBRS and IBPB are enumerated by the same CPUID > enumeration, IBPB is very different. > > IBPB helps mitigate against three potential attacks: > > * Mitigate guests from being attacked by other guests. > - This is addressed by issing IBPB when we do a guest switch. > > * Mitigate attacks from guest/ring3->host/ring3. > These would require a IBPB during context switch in host, or after > VMEXIT. The host process has two ways to mitigate > - Either it can be compiled with retpoline > - If its going through context switch, and has set !dumpable then > there is a IBPB in that path. > (Tim's patch: https://patchwork.kernel.org/patch/10192871) > - The case where after a VMEXIT you return back to Qemu might make > Qemu attackable from guest when Qemu isn't compiled with retpoline. > There are issues reported when doing IBPB on every VMEXIT that resulted > in some tsc calibration woes in guest. > > * Mitigate guest/ring0->host/ring0 attacks. > When host kernel is using retpoline it is safe against these attacks. > If host kernel isn't using retpoline we might need to do a IBPB flush on > every VMEXIT. > > Even when using retpoline for indirect calls, in certain conditions 'ret' > can use the BTB on Skylake-era CPUs. There are other mitigations > available like RSB stuffing/clearing. > > * IBPB is issued only for SVM during svm_free_vcpu(). > VMX has a vmclear and SVM doesn't. Follow discussion here: > https://lkml.org/lkml/2018/1/15/146 > > Please refer to the following spec for more details on the enumeration > and control. > > Refer here to get documentation about mitigations. > > https://software.intel.com/en-us/side-channel-security-support > > [peterz: rebase and changelog rewrite] > [karahmed: - rebase > - vmx: expose PRED_CMD if guest has it in CPUID > - svm: only pass through IBPB if guest has it in CPUID > - vmx: support !cpu_has_vmx_msr_bitmap()] > - vmx: support nested] > [dwmw2: Expose CPUID bit too (AMD IBPB only for now as we lack IBRS) > PRED_CMD is a write-only MSR] > > Cc: Asit Mallick > Cc: Dave Hansen > Cc: Arjan Van De Ven > Cc: Tim Chen > Cc: Linus Torvalds > Cc: Andrea Arcangeli > Cc: Andi Kleen > Cc: Thomas Gleixner > Cc: Dan Williams > Cc: Jun Nakajima > Cc: Andy Lutomirski > Cc: Greg KH > Cc: Paolo Bonzini > Signed-off-by: Ashok Raj > Signed-off-by: Peter Zijlstra (Intel) > Link: http://lkml.kernel.org/r/1515720739-43819-6-git-send-email-ashok.raj@intel.com > Signed-off-by: David Woodhouse > Signed-off-by: KarimAllah Ahmed Reviewed-by: Konrad Rzeszutek Wilk with some small nits. > --- > v6: > - introduce msr_write_intercepted_l01 > > v5: > - Use MSR_TYPE_W instead of MSR_TYPE_R for the MSR. > - Always merge the bitmaps unconditionally. > - Add PRED_CMD to direct_access_msrs. > - Also check for X86_FEATURE_SPEC_CTRL for the msr reads/writes > - rewrite the commit message (from ashok.raj@) > --- > arch/x86/kvm/cpuid.c | 11 +++++++- > arch/x86/kvm/svm.c | 28 ++++++++++++++++++ > arch/x86/kvm/vmx.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++-- > 3 files changed, 116 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index c0eb337..033004d 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -365,6 +365,10 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, > F(3DNOWPREFETCH) | F(OSVW) | 0 /* IBS */ | F(XOP) | > 0 /* SKINIT, WDT, LWP */ | F(FMA4) | F(TBM); > > + /* cpuid 0x80000008.ebx */ > + const u32 kvm_cpuid_8000_0008_ebx_x86_features = > + F(IBPB); > + > /* cpuid 0xC0000001.edx */ > const u32 kvm_cpuid_C000_0001_edx_x86_features = > F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) | > @@ -625,7 +629,12 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, > if (!g_phys_as) > g_phys_as = phys_as; > entry->eax = g_phys_as | (virt_as << 8); > - entry->ebx = entry->edx = 0; > + entry->edx = 0; > + /* IBPB isn't necessarily present in hardware cpuid */ It is with x86/pti nowadays. I think you can remove that comment. ..snip.. > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index d46a61b..263eb1f 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -592,6 +592,7 @@ struct vcpu_vmx { > u64 msr_host_kernel_gs_base; > u64 msr_guest_kernel_gs_base; > #endif > + Spurious..