Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1183812ybh; Thu, 16 Jul 2020 05:39:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNy0b3Do3s8W3hfuns8dwoqB1EjoyiN/9X7oNxD0Ddc6Evve1ZZjwrD2VtSFYR1bvyeinY X-Received: by 2002:a17:906:ce32:: with SMTP id sd18mr3672017ejb.228.1594903188919; Thu, 16 Jul 2020 05:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594903188; cv=none; d=google.com; s=arc-20160816; b=XMDVsOoFyu4fSW39rOS9K0zgylId0FkqKVj3Da5ZJv3scq5vzdD3upT0EOK0+7J3M8 IWv6y820tNv43moKa/TiO8p1K7kVoMe2rajvKW1fW92faVsAFlC4Hk34v0LOJTwyvVz6 s6rvcZ/zcJIAYjwWlHO9wg4S1MdhPIZt9mK1qNQ08xUNF8k47gagp1YSz1/rD6r4CoNJ s07Zsyi3rhiTH/1M44MJciP0ZgXI01Abf/x1SxkKSRlYYDFmmXOi6xhi93Yj//e4bUyy AJD69q3stdk55TGfi+3tHROKZ8k+Xi3p7LplYUMzt2Roy0WgSZKQF3OZf48/7HXDLacu X0aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:git-commit:patch-mainline:references :references:in-reply-to:message-id:date:subject:cc:to:from; bh=topFdcWWLjRQafxNjlNHQGnrR7AJpF1hZUcM4hZa8AI=; b=DoFJmkimdEG49GbsXPY/p8xKUbQo5Xk8WLEvz//NcSssx2cSZPEngoqv2tWwW9c2Q+ TgVvSWdXIPqHVXeYL/nhKiCyMvVVk+6FA5poCoWDCvsuBxVMpnSkmgJkUkXpmP7lJ241 67EW4DMHyAO029m7K8W3u2fB8fPkhjbbcojkmAuwz2QGqlXMr+LCRPkOIqF4PPNaOS8K y6JXYiGLu3In26J62SaO1gu+uyr1yhV2REiA+U2rrUu6P0dLQ4cC04RRdn1wSbaSJveq cdN0yExT/xdLtsV71+g5m+mlUMEyNGB/saRen4K/6HLf/BTdJlUDWs4r69odUsImb1c+ mWhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m27si3242399edj.431.2020.07.16.05.39.26; Thu, 16 Jul 2020 05:39:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728839AbgGPMim (ORCPT + 99 others); Thu, 16 Jul 2020 08:38:42 -0400 Received: from mx2.suse.de ([195.135.220.15]:35944 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728822AbgGPMij (ORCPT ); Thu, 16 Jul 2020 08:38:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 59A4DB946; Thu, 16 Jul 2020 12:38:42 +0000 (UTC) From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, linux-mm@kvack.org, mike.kravetz@oracle.com, david@redhat.com, aneesh.kumar@linux.vnet.ibm.com, naoya.horiguchi@nec.com, linux-kernel@vger.kernel.org, David Woodhouse , KarimAllah Ahmed , gnomes@lxorguk.ukuu.org.uk, ak@linux.intel.com, ashok.raj@intel.com, dave.hansen@intel.com, arjan@linux.intel.com, torvalds@linux-foundation.org, peterz@infradead.org, bp@alien8.de, pbonzini@redhat.com, tim.c.chen@linux.intel.com, gregkh@linux-foundation.org, Greg Kroah-Hartman , "Srivatsa S . Bhat" , Jiri Slaby Subject: [PATCH] x86/speculation: Add basic IBPB (Indirect Branch Prediction Barrier) support Date: Thu, 16 Jul 2020 14:38:10 +0200 Message-Id: <20200716123810.25292-17-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20200716123810.25292-1-osalvador@suse.de> References: <20200716123810.25292-1-osalvador@suse.de> References: bnc#1012382 Patch-mainline: 4.4.144 Git-commit: 20ffa1caecca4db8f79fe665acdeaa5af815a24d Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Woodhouse (cherry picked from commit 20ffa1caecca4db8f79fe665acdeaa5af815a24d) Expose indirect_branch_prediction_barrier() for use in subsequent patches. [ tglx: Add IBPB status to spectre_v2 sysfs file ] Co-developed-by: KarimAllah Ahmed Signed-off-by: KarimAllah Ahmed Signed-off-by: David Woodhouse Cc: gnomes@lxorguk.ukuu.org.uk Cc: ak@linux.intel.com Cc: ashok.raj@intel.com Cc: dave.hansen@intel.com Cc: arjan@linux.intel.com Cc: torvalds@linux-foundation.org Cc: peterz@infradead.org Cc: bp@alien8.de Cc: pbonzini@redhat.com Cc: tim.c.chen@linux.intel.com Cc: gregkh@linux-foundation.org Link: https://lkml.kernel.org/r/1516896855-7642-8-git-send-email-dwmw@amazon.co.uk Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman Signed-off-by: Srivatsa S. Bhat Reviewed-by: Matt Helsley (VMware) Reviewed-by: Alexey Makhalov Reviewed-by: Bo Gan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Jiri Slaby --- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include/asm/nospec-branch.h | 13 +++++++++++++ arch/x86/kernel/cpu/bugs.c | 10 +++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index a5671b849837..b4e370b5b761 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -201,6 +201,8 @@ /* Because the ALTERNATIVE scheme is for members of the X86_FEATURE club... */ #define X86_FEATURE_KAISER ( 7*32+31) /* CONFIG_PAGE_TABLE_ISOLATION w/o nokaiser */ +#define X86_FEATURE_IBPB ( 7*32+21) /* Indirect Branch Prediction Barrier enabled*/ + /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ #define X86_FEATURE_VNMI ( 8*32+ 1) /* Intel Virtual NMI */ diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 8b910416243c..41851afd44af 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -194,6 +194,19 @@ static inline void vmexit_fill_RSB(void) #endif } +static inline void indirect_branch_prediction_barrier(void) +{ + asm volatile(ALTERNATIVE("", + "movl %[msr], %%ecx\n\t" + "movl %[val], %%eax\n\t" + "movl $0, %%edx\n\t" + "wrmsr", + X86_FEATURE_IBPB) + : : [msr] "i" (MSR_IA32_PRED_CMD), + [val] "i" (PRED_CMD_IBPB) + : "eax", "ecx", "edx", "memory"); +} + #endif /* __ASSEMBLY__ */ /* diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 2bbc74f8a4a8..7def33ada730 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -296,6 +296,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 @@ -325,7 +332,8 @@ ssize_t cpu_show_spectre_v2(struct device *dev, if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) return sprintf(buf, "Not affected\n"); - return sprintf(buf, "%s%s\n", spectre_v2_strings[spectre_v2_enabled], + return sprintf(buf, "%s%s%s\n", spectre_v2_strings[spectre_v2_enabled], + boot_cpu_has(X86_FEATURE_IBPB) ? ", IBPB" : "", spectre_v2_module_string()); } #endif -- 2.18.0