From patchwork Tue Feb 13 01:23:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawan Gupta X-Patchwork-Id: 200277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp407645dyb; Tue, 13 Feb 2024 00:56:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUzeC+R8C+fiE2eyXYvuiRLy2zazh0eufBdrCFgbK4QEL6ZWo4ndp+vhXYn/l3zj6CzHZrk4aPmKu49XVLaOmam5U4qQA== X-Google-Smtp-Source: AGHT+IHILge1uX/9yTDfGBSxuOzhxvpAZrfgYyOH4NScBh8PHmCGi/1ka2Dx7HUbZ9isGTWgyPPu X-Received: by 2002:a05:6402:1293:b0:560:be95:aa64 with SMTP id w19-20020a056402129300b00560be95aa64mr6281882edv.37.1707814616411; Tue, 13 Feb 2024 00:56:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707814616; cv=pass; d=google.com; s=arc-20160816; b=F0GdUXmzABLMwmpnkeigY1v5JQjBPro86S05fyfSTxEyXayFZNlXzMYRtbHzE+1sOI sqxv09JDB0D5nnNCxdsQ+qjrD6bxZ4mHCA7BVdr5gBIeMi5iAz79KaxbQGo30vJdgeGB 7szBcV88M2Dn6nCYRfyVd420xcmGhKKI0YNWe9oap/RE2eDPTjY2UVVmTVQdM3CsY1SX pCIadhMRHiQLbvBExu18I6qA/J0A+wE6Xo0dneHuRXjEIM90uJew4VB2nG/KtfNY1ohK OyDKMgBPxMKVZvhhOApLqA9SB7qdhrjVChY0GjbWLSD8a6ziv98/ExuUu/GNajDD1SVV SUOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=c1galDDs5v2qjdL9fgI8H94BTkQJTCZ+51eEJciXeiw=; fh=qEIq47uWxzGOWJh6gNmmDBsRB4Vgs3LXegM0KtsPWRM=; b=tySl6QZh7DlL1wuFnkwu0toIovkjaOtSfOwqUaimF5vsiAjICXqWA1lthBOQudR8Jo T3D1E0CubUuhWwI6IKleEY+OZBBkUNEuYbWqyIOkMPsTSpmPZz9BURLuziRdZacMMEFI Bl9lcujAbnSxmB4Gq6ogG9pDJqDtq0qA59QmqmOpI+Fm/TeaQXBstrWZtgjZJx/wih6Y zx0+05Km2JPa8c5VL/pQZn3gr3hZvCBYgeThdEUjvkudR/5xk+tM3M9itcaXAbUaeeA/ 7rTu0KPOw41/wBUOWbeEO1b/1SZQkqNdYOnck/3bl6ob8fUU4+TPBLbhP/z81dJchfMv NtwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nVViXDGu; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62858-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62858-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVCiaB/bWzNKV7uzH9TAEmL9G+RVlka/D0oKqrFK1trWbLVf2NmJIP3MHE/fWYy3wPdj5qdt0G5TJHJDp+AYausiRogaQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y25-20020a50e619000000b00561d0de3e07si1167070edm.255.2024.02.13.00.56.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:56:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62858-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nVViXDGu; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62858-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62858-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 17C031F25ABB for ; Tue, 13 Feb 2024 01:47:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F007C128; Tue, 13 Feb 2024 01:23:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nVViXDGu" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 033B08BF9 for ; Tue, 13 Feb 2024 01:23:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707787405; cv=none; b=kXgVZ5eRKDf54nIgM6qkoWk8+38ah+nH//zaH6Kt6KIFgz4zWztuAL6T596kKxxM1usLlcwDdCnEjLLZyhjrEZjvwxbR5yaeUbWsaA0a+JCwAdofwqh14NButM/fRoVwOMhSKfF8/dHGBabwae08w0e0ZRAtQiM5bpIhB+E2lZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707787405; c=relaxed/simple; bh=nmnR+ST6s7h48SKCc39ApFjSVEWr4cUjiZrKgk/KB/g=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=cnyilTeP/gfVQ/JIUb1k3r8cCoUUVzVAtzc7H6ZvfkPlMmGu0RGzJ547lz/Z10CWRtnp0tOWfjzkeiYDccSD3f0bZL55ExByvcKPNPfb9OdpHcNdiSEXKWoSvVgIursNcK7j+PgLFYVOY7+ae3eiVoWhdiW0v9I6uOP+L9qcyzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=nVViXDGu; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707787404; x=1739323404; h=date:from:to:cc:subject:message-id:mime-version; bh=nmnR+ST6s7h48SKCc39ApFjSVEWr4cUjiZrKgk/KB/g=; b=nVViXDGupTP66f7Tp6cVlpM7+GqYw7zFPz8iQdYJE67a7J/FcM5hS/uV ER4sDARfUiz6bHIF1axCJda0yW6uaakvBc9R26KMq3QydheDSh+HDyMfH 5WYjAtJnKfFRHs1Z+7aqivSofQZBd4ZNaa6Sb2e6vlidl/5T/DdWZ2q+g wa3jwDknqyd2/BIVyyqHZnSOYRI66MCg9K22kxhRhq6vkQIOSVZbLWDtv RoRLyn9nk1g49rNcFeio5LFoe6VlbspQTRaHUHynaWj3DBthqbeD2+9VQ mhRbeksD0HkzK5oW0QZWR2JdaoPSKNXaT/67ceTbZT43DX9BoHjKCYbG4 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="13169748" X-IronPort-AV: E=Sophos;i="6.06,155,1705392000"; d="scan'208";a="13169748" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 17:23:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,155,1705392000"; d="scan'208";a="25939430" Received: from mpai-mobl1.amr.corp.intel.com (HELO desk) ([10.209.55.176]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 17:23:22 -0800 Date: Mon, 12 Feb 2024 17:23:21 -0800 From: Pawan Gupta To: Thomas Gleixner , Borislav Petkov , Peter Zijlstra , Josh Poimboeuf , Ingo Molnar , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: Daniel Sneddon , antonio.gomez.iglesias@linux.intel.com, alyssa.milburn@linux.intel.com, andrew.cooper3@citrix.com, linux-kernel@vger.kernel.org Subject: [PATCH v2] x86/bugs: Default retbleed to =stuff when retpoline is enabled Message-ID: <20240212-retbleed-auto-stuff-v2-1-89401649341a@linux.intel.com> X-B4-Tracking: v=1; b=H4sIAGvDymUC/32NTQ6CMBBGr0Jm7ZD+CEFX3sOwQJjKJNiatjQY0 rtbOYDL95LvfTsE8kwBrtUOnhIHdraAOlUwzoN9EvJUGJRQZ6FEh57iYyGacFijwxBXY7DRJMx wkVo0BGX59mR4O6r3vvDMITr/OU6S/Nn/vSRRYmukokbqru3MbWG7bjXbSEs9uhf0OecvuP6He LwAAAA= X-Mailer: b4 0.12.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790771814206001441 X-GMAIL-MSGID: 1790773419085629057 On Intel systems when retpoline mitigation is enabled for spectre-v2, retbleed=auto does not enable RSB stuffing. This may make the system vulnerable to retbleed. Retpoline is not the default mitigation when IBRS is present, but in virtualized cases a VMM can hide IBRS from guests, resulting in guest deploying retpoline by default. Even if IBRS is enumerated, a user can still select spectre_v2=retpoline. As with other mitigations, mitigate retbleed by default. On Intel systems when retpoline is enabled, and retbleed mitigation is set to auto, enable Call Depth Tracking and RSB stuffing i.e. retbleed=stuff mitigation. For AMD/Hygon auto mode already selects the appropriate mitigation. Reported-by: Alyssa Milburn Cc: stable@kernel.org Signed-off-by: Pawan Gupta --- v2: - Mitigate retbleed by default for spectre_v2=retpoline. (Josh) - Add the missing ',' in the comment. (Josh) - Rebased to v6.8-rc4 v1: https://lore.kernel.org/r/20240208-retbleed-auto-stuff-v1-1-6f12e513868f@linux.intel.com --- arch/x86/kernel/cpu/bugs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- base-commit: 841c35169323cd833294798e58b9bf63fa4fa1de change-id: 20240208-retbleed-auto-stuff-53e0fa91305e diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index bb0ab8466b91..3aa473b08d6e 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1025,11 +1025,17 @@ static void __init retbleed_select_mitigation(void) retbleed_mitigation = RETBLEED_MITIGATION_UNRET; else if (IS_ENABLED(CONFIG_CPU_IBPB_ENTRY) && boot_cpu_has(X86_FEATURE_IBPB)) retbleed_mitigation = RETBLEED_MITIGATION_IBPB; + } else if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && + spectre_v2_enabled == SPECTRE_V2_RETPOLINE) { + if (IS_ENABLED(CONFIG_CALL_DEPTH_TRACKING)) + retbleed_mitigation = RETBLEED_MITIGATION_STUFF; + else + pr_err("WARNING: Retpoline enabled, but kernel not compiled with CALL_DEPTH_TRACKING.\n"); } /* - * The Intel mitigation (IBRS or eIBRS) was already selected in - * spectre_v2_select_mitigation(). 'retbleed_mitigation' will + * If Intel mitigation (IBRS or eIBRS) was already selected in + * spectre_v2_select_mitigation(), 'retbleed_mitigation' will * be set accordingly below. */