Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp309106lqh; Mon, 6 May 2024 22:30:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWvLWgSaCl5cJtkX2j/l1C9HV4wTgBtZ5ro2nw/i4r+Lx6fc33WKzNjRzLPUzK/9IXU4MAqsvjuu5x4S/k59/y8kY3OClSWrTVVWIXLUw== X-Google-Smtp-Source: AGHT+IFY33k8f/5yk7A0Nl837AAdAmwUjNUVef94KGO9ZvBJpDLOsMBHP7LZ2cEoHsRQpBCfc2bm X-Received: by 2002:a17:906:3ec2:b0:a58:c80e:edd8 with SMTP id d2-20020a1709063ec200b00a58c80eedd8mr6743501ejj.70.1715059847950; Mon, 06 May 2024 22:30:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715059847; cv=pass; d=google.com; s=arc-20160816; b=PyC0v3k89Jr0oqmkZeDNDfbC3Gvyt4J1Q2f8vaQninBeWuTeUKeyOAN55AfyYAxDHc DjC6B/++MOwBO9hMSMw+pSHTxDESE+/1RYHAmmozb4gs3PGZkqIQw6dMXUxI4QH2KAnP vpT6iuLIvWxPUipuBlMAQh6CTASspseedjYxY1FaImVtXwOhCxxgsIUgNgXkgUJP3y5O mNOjmMQ7I1Cef4ip5xfwfR9azSZVsw9NehPme/sIBrI/RKEjSH7NO+uXT+dMjbQjFeDY Ka1i9Yq1fkbiWiU4bOQkeriEq3sPyFFg2c6QjVeEd6G1l6AdoP/I75oCjmDGL2nQoCL0 Ma/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zslO32LAR1+Gak4F9kLhPt9/uPuNHB5nYucjzNILXX8=; fh=PVXqZf7leYzR1rlT2l8BErWPJHwJEVWxPdveWWy0efU=; b=Jtpm7lRiP8iC2bu3u4oaAjxS/5HUxaIL1z0HhCiizt4hsPpx/+s/Q3ae8IQcee2xjV qI9yywewidXVkd7raKG1VNPDvGOLNqnIJkWvwv3x4ANPiK+Vn8aq0kRht/4HU8pVP4Kh 3aP/wop2SNsNT20cbrPK9Qy4htRpXR8sSiHj0JXEevHWnEg+LPJq/XdtIt4y5o5fcq/3 PiIhC2AQo82jPk0K02sC5dBXGDnfnFuDk9WxIFBMgAMFqXYYqpznPl4c4NmrE3rtzSHm zvKIlthYQfDihlMbh7qJziJnw2J0dKpVLl3981RxoKJqkuseuURaX3F0d/mkVcy/QV2Z ZhVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=prRdCP2g; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-170695-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170695-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id xo23-20020a170907bb9700b00a59aa07bb42si3386976ejc.287.2024.05.06.22.30.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 22:30:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170695-linux.lists.archive=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=@kernel.org header.s=k20201202 header.b=prRdCP2g; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-170695-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170695-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 7B6D21F24F20 for ; Tue, 7 May 2024 05:30:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD4406F06F; Tue, 7 May 2024 05:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="prRdCP2g" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CBE576E602 for ; Tue, 7 May 2024 05:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715059817; cv=none; b=RhmYhY7L8I+pPRZZHrW1mbGWou0h8uSpXBdOoi3eVt8HD199V1LyWj7HpqyI4Q2rVx3dtjSINMn3JIJlwabNzJV1Yv4sQigtuwrP3CfGTzmPYXQFbVMkyHz+dwb73c87dVhQQuNdo0u3ajJ2lzJeegP5wUILVwFNhQkhl/Nzjtk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715059817; c=relaxed/simple; bh=rjjbb87qU0Az3V5tnqRivUixNJ5fK4IwNpaXSwSoEyg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qHj6Jsum50M97HoKti/tR+BeUX8U1Ov49g8pDkz/kpGFE5GOE9fbVMswY8/GkTKeEJV0+pFFaGoShGzqTVUrAKGXGDrKC0qQ2DmWbXA1f5+rNTG+uJ5RdSi9cQ2NSohjA92eiUw3Hc0WtPo2cPU3TaOEwpxKODKe9D5I/bdMEvw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=prRdCP2g; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 958C1C4AF65; Tue, 7 May 2024 05:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715059817; bh=rjjbb87qU0Az3V5tnqRivUixNJ5fK4IwNpaXSwSoEyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=prRdCP2g1WIHQ6TnRGJ6c13LybTEElCD1qSCXAh1DwIp1eLggps4Ipp1zdZ/QCsLG Zlj29uzTwEjaAXplnphLtVCnNc0NMpvhlAPk11Rsx/fQBesEl0feWPHW1uY/OI4sBD jzUbNKk1xIr/tPPFe/k4JMHudCfCXtUGlP28GjTaAKc5FNs+cIsvMo9I4bxNlSdhjJ PihDmFqvhphN1nXSiZpnNPUhb65kkKPt1SdaQMpWkLf+tsora9Mf0ekmuMJs2ji6Ol WoFy0nh7J6I7W/CQq3Y5gVis5sJMfHmOKStLF3BvNB7H5esJ9GRIm/VToFvtgrn7hj x42M3c+sU1wwg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Daniel Sneddon , Pawan Gupta , Thomas Gleixner , Alexandre Chartre , Konrad Rzeszutek Wilk , Peter Zijlstra , Greg Kroah-Hartman , Sean Christopherson , Andrew Cooper , Dave Hansen , Nikolay Borisov , KP Singh , Waiman Long , Borislav Petkov , Ingo Molnar , Maksim Davydov Subject: [PATCH v5 3/3] x86/bugs: Add 'spectre_bhi=vmexit' cmdline option Date: Mon, 6 May 2024 22:30:06 -0700 Message-ID: <66327dcf87284a09ed17ac24227695ea3ba1f287.1715059256.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In cloud environments it can be useful to *only* enable the vmexit mitigation and leave syscalls vulnerable. Add that as an option. This is similar to the old spectre_bhi=auto option which was removed with the following commit: 36d4fe147c87 ("x86/bugs: Remove CONFIG_BHI_MITIGATION_AUTO and spectre_bhi=auto") with the main difference being that this has a more descriptive name and is disabled by default. Requested-by: Maksim Davydov Signed-off-by: Josh Poimboeuf --- Documentation/admin-guide/kernel-parameters.txt | 12 +++++++++--- arch/x86/kernel/cpu/bugs.c | 16 +++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 213d0719e2b7..9c1f63f04502 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6072,9 +6072,15 @@ deployment of the HW BHI control and the SW BHB clearing sequence. - on - (default) Enable the HW or SW mitigation - as needed. - off - Disable the mitigation. + on - (default) Enable the HW or SW mitigation as + needed. This protects the kernel from + both syscalls and VMs. + vmexit - On systems which don't have the HW mitigation + available, enable the SW mitigation on vmexit + ONLY. On such systems, the host kernel is + protected from VM-originated BHI attacks, but + may still be vulnerable to syscall attacks. + off - Disable the mitigation. spectre_v2= [X86,EARLY] Control mitigation of Spectre variant 2 (indirect branch speculation) vulnerability. diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index ab18185894df..6974c8c9792d 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1625,6 +1625,7 @@ static bool __init spec_ctrl_bhi_dis(void) enum bhi_mitigations { BHI_MITIGATION_OFF, BHI_MITIGATION_ON, + BHI_MITIGATION_VMEXIT_ONLY, }; static enum bhi_mitigations bhi_mitigation __ro_after_init = @@ -1639,6 +1640,8 @@ static int __init spectre_bhi_parse_cmdline(char *str) bhi_mitigation = BHI_MITIGATION_OFF; else if (!strcmp(str, "on")) bhi_mitigation = BHI_MITIGATION_ON; + else if (!strcmp(str, "vmexit")) + bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY; else pr_err("Ignoring unknown spectre_bhi option (%s)", str); @@ -1659,19 +1662,22 @@ static void __init bhi_select_mitigation(void) return; } + /* Mitigate in hardware if supported */ if (spec_ctrl_bhi_dis()) return; if (!IS_ENABLED(CONFIG_X86_64)) return; - /* Mitigate KVM by default */ - setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT); - pr_info("Spectre BHI mitigation: SW BHB clearing on vm exit\n"); + if (bhi_mitigation == BHI_MITIGATION_VMEXIT_ONLY) { + pr_info("Spectre BHI mitigation: SW BHB clearing on vm exit only\n"); + setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT); + return; + } - /* Mitigate syscalls when the mitigation is forced =on */ + pr_info("Spectre BHI mitigation: SW BHB clearing on syscall and vm exit\n"); setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP); - pr_info("Spectre BHI mitigation: SW BHB clearing on syscall\n"); + setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT); } static void __init spectre_v2_select_mitigation(void) -- 2.44.0