Received: by 10.223.176.46 with SMTP id f43csp1125395wra; Sat, 20 Jan 2018 11:25:32 -0800 (PST) X-Google-Smtp-Source: AH8x227A0b3j2rinA9IW1F4OrEuvyWUUaxIs/fjt57clCeTDDTJXWdrwmZd/bdtuhvo9iOHjuhqh X-Received: by 10.98.50.3 with SMTP id y3mr3202203pfy.98.1516476332609; Sat, 20 Jan 2018 11:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516476332; cv=none; d=google.com; s=arc-20160816; b=umB4K0V647tVTLeMLRFyE+3O/CAefg9cQWB6VyRXiq4N+wviluDnTTg2/HMRh6ij8M yMy1Njf37P3z2SK2uaOyiaD2T8Hqi9mf/SHZJrIKrVYG+tywNIVFasbgEuoGK0KNk0sp 5qos4wPtW7dgozppnf6mz4lB8qHhI949YHfVs5Y80eLmWbDCbgTZmm11/EYdFyA0w1cy zBWrMWIQF5iJ45/kbYgUR4veqQVC7VjVpCoSHl5sOmKh3TA6ZdYDlJM4Loem2XyizZBY +K6i6pCJFPtn1kC4h7MdmEkFJBfSr0nuZbghKF5I7OoQNd3KJ28vXxIzCBSCgVFK6L2t Drvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=p5LGbqGcRUykA6/Num4OC6zgDrkwPFm9KiMgshKcl2k=; b=W/BQcDPkVbMEQgZc9HYmU3T7RNVo4ajxDE+G4/401uGqCObOByqGpShfVhnoobCPi4 mNX9qa1NfYUiXDxcyO6+bV2QSzTHKYdC7Zw3aZ2LzWC5495upbCpEwVL801/aCIhca5R yeQo4k7Hj8rO2A+cO6hezFOtNLSE+HjoH3DXvSMoY6u1/7v0vUgCTPaagCNfZv1wrPgP Ru/4w8FXYmx4JnFOr40U+EdnMDuE3NM4LNBjtD0BPf8SWtI/qkZ2RrjWisvlRpdYI82f 3QFfsXlcyvMzEtxWYX2m6uE4wiIqS7kTnttkwNuazDKUpINzGuQuhJO18iPP42l4F9hK Jfhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=FZtgZYEn; 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 l132si11711558pfc.202.2018.01.20.11.24.57; Sat, 20 Jan 2018 11:25:32 -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=@amazon.de header.s=amazon201209 header.b=FZtgZYEn; 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 S932659AbeATTX7 (ORCPT + 99 others); Sat, 20 Jan 2018 14:23:59 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:1106 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932231AbeATTXj (ORCPT ); Sat, 20 Jan 2018 14:23:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1516476218; x=1548012218; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=p5LGbqGcRUykA6/Num4OC6zgDrkwPFm9KiMgshKcl2k=; b=FZtgZYEn9MO/sZa+TMG/2udAIztzPbARzjjG0tDSyX8UUCwyUxQ0PwZV 2bVRQJY+Xilk0tCy42pGU9J26tVhWOtG1a8TZZHTZIOTjFs7dIUtjnBob 6MvhCrYiUh9+a5Gfo8+NaOoaTkTeg+/33GT7UAkLAqLjz5QsbZG1ORBqE s=; X-IronPort-AV: E=Sophos;i="5.46,387,1511827200"; d="scan'208";a="588403208" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Jan 2018 19:23:35 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (iad1-ws-svc-lb91-vlan2.amazon.com [10.0.103.146]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w0KJNKn5114584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 20 Jan 2018 19:23:22 GMT Received: from u54e1ad5160425a4b64ea.ant.amazon.com (localhost [127.0.0.1]) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w0KJNHNR005244; Sat, 20 Jan 2018 20:23:17 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id w0KJNFMV005241; Sat, 20 Jan 2018 20:23:15 +0100 From: KarimAllah Ahmed To: linux-kernel@vger.kernel.org Cc: KarimAllah Ahmed , Andi Kleen , Andrea Arcangeli , Andy Lutomirski , Arjan van de Ven , Ashok Raj , Asit Mallick , Borislav Petkov , Dan Williams , Dave Hansen , David Woodhouse , Greg Kroah-Hartman , "H . Peter Anvin" , Ingo Molnar , Janakarajan Natarajan , Joerg Roedel , Jun Nakajima , Laura Abbott , Linus Torvalds , Masami Hiramatsu , Paolo Bonzini , Peter Zijlstra , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , Tim Chen , Tom Lendacky , kvm@vger.kernel.org, x86@kernel.org Subject: [RFC 01/10] x86/speculation: Add basic support for IBPB Date: Sat, 20 Jan 2018 20:22:52 +0100 Message-Id: <1516476182-5153-2-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516476182-5153-1-git-send-email-karahmed@amazon.de> References: <1516476182-5153-1-git-send-email-karahmed@amazon.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner Expose indirect_branch_prediction_barrier() for use in subsequent patches. [karahmed: remove the special-casing of skylake for using IBPB (wtf?), switch to using ALTERNATIVES instead of static_cpu_has] [dwmw2: set up ax/cx/dx in the asm too so it gets NOP'd out] Signed-off-by: Thomas Gleixner Signed-off-by: KarimAllah Ahmed Signed-off-by: David Woodhouse --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/nospec-branch.h | 16 ++++++++++++++++ arch/x86/kernel/cpu/bugs.c | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 624d978..8ec9588 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -207,6 +207,7 @@ #define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* AMD Retpoline mitigation for Spectre variant 2 */ #define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */ +#define X86_FEATURE_IBPB ( 7*32+16) /* Using Indirect Branch Prediction Barrier */ #define X86_FEATURE_AMD_PRED_CMD ( 7*32+17) /* Prediction Command MSR (AMD) */ #define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */ #define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* Fill RSB on context switches */ diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 4ad4108..c333c95 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -218,5 +218,21 @@ static inline void vmexit_fill_RSB(void) #endif } +static inline void indirect_branch_prediction_barrier(void) +{ + unsigned long ax, cx, dx; + + asm volatile(ALTERNATIVE("", + "movl %[msr], %%ecx\n\t" + "movl %[val], %%eax\n\t" + "movl $0, %%edx\n\t" + "wrmsr", + X86_FEATURE_IBPB) + : "=a" (ax), "=c" (cx), "=d" (dx) + : [msr] "i" (MSR_IA32_PRED_CMD), + [val] "i" (PRED_CMD_IBPB) + : "memory"); +} + #endif /* __ASSEMBLY__ */ #endif /* __NOSPEC_BRANCH_H__ */ diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 390b3dc..96548ff 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -249,6 +249,13 @@ static void __init spectre_v2_select_mitigation(void) setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW); pr_info("Filling RSB on context switch\n"); } + + /* Initialize Indirect Branch Prediction Barrier if supported */ + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL) || + boot_cpu_has(X86_FEATURE_AMD_PRED_CMD)) { + setup_force_cpu_cap(X86_FEATURE_IBPB); + pr_info("Enabling Indirect Branch Prediction Barrier\n"); + } } #undef pr_fmt -- 2.7.4