From patchwork Wed Dec 13 20:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 178297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8072306dys; Wed, 13 Dec 2023 12:37:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqUDgZCwdjxXI1EDxLuHVNXW62EjyLmrzQq0GmOrtCbcNEQzzcFM35XrHU+lhlaWq6ppvt X-Received: by 2002:a05:6a00:2ea7:b0:6ce:7343:f071 with SMTP id fd39-20020a056a002ea700b006ce7343f071mr5091666pfb.50.1702499835923; Wed, 13 Dec 2023 12:37:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702499835; cv=none; d=google.com; s=arc-20160816; b=k12xPXRs5nTqAz7O5zBwAJTGv+Fvv7D/pnPzk/VECr7zZqHPQXGTQpsp0c3K1VddxX ACunnFfMQ6noBo8vOGejjlhnHIrGOEfc7Vk4v56ENI5/WCzFXHfZMeMliqcI2UFdOlzn hLZI6/2c6+09w9csnQNqaVJtTvZ4D07fIr8Vu+ySTEXdtk4F3vZgvmMB+tZYwrTL16Ll OBDja/sGe1UrNeQ1ddp8uw2FmkqUdEoAGtWEwlZQp3csIPze1Tiupsz+pixS2m81q9EX 3HbLuuubWgMzR21YZgVA5Oeb38iF3VRqcuX9qrai4eFzYx+SdVVbl3YqNjELh6FYTmO3 eo5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=9tdgEFmJtgiJ/hsWpMo64wL16sVk4He/t45frB5SOHw=; fh=PHDPJwf1JiuHpUmCPT6qo//dmmqyBAKEilUlZrUacLU=; b=rpPoQQMRFu7YdJtstkVcA2CJmzyUOKhGv2r8l8xdR119OqUEigfHRofvOWg+KFM+50 uR/BnMIv+wM4oQOegjHO4eyX/RSDNN/NtchwS1eFbHpopGHiQuiuFfeGzQ8/3+U/mgsm J8YWa1iiUAUIXR0DDaErOTuvFa2GbfYonNT5F/qxdguEkwz7yUnYd8+2bC/yrFV1M6LU mwoohZ44rIMoKn8PwwA7/YWKJ81ljGGlInNfuqfQG2zUwC4uzCVt+eFlxdK48MKkFumL UmNjcvJ5myMIqyXgbxE2u+4jWLYFRnAga1h0D6uLGCB9egaQsh9yKpU+S8ArNenUYyZj /05g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=R+cuITri; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id eb3-20020a056a004c8300b006ce97669ff7si10316720pfb.364.2023.12.13.12.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 12:37:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=R+cuITri; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 89567802FA24; Wed, 13 Dec 2023 12:37:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442601AbjLMUhE (ORCPT + 99 others); Wed, 13 Dec 2023 15:37:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbjLMUhD (ORCPT ); Wed, 13 Dec 2023 15:37:03 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E2B99; Wed, 13 Dec 2023 12:37:09 -0800 (PST) Date: Wed, 13 Dec 2023 20:37:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702499827; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9tdgEFmJtgiJ/hsWpMo64wL16sVk4He/t45frB5SOHw=; b=R+cuITriSuDmpM32izQ4dtf2ecIG7/QtBgWUJujQeiM2KLrch6Ytc5Fzmvt2NmJRfBpwfj PPq9GAbu+SCC6LxtEHhz8U2Uaaaa07H3t7nSsYlSKYmT/JGu8TDg0Kg5fv5d6gzgG2VU8J 24D0tRrzwFP8/3jeYOsK/0iJT+HSBBSBsLrlXnnE1Fbq5KKNkTauhqioUJgc4nyE4WuSht epn6cLmGAWxu4GD15AXROHTZ3Y9BRfBno6J780UHGTPQtcyHA7A1HKALArmbgFBIAtMD99 yjZYBoTThhz6ElSu0MVXWaKMCZBJ7WsU7BJ9y0W3ZMmtRCxb4ifa0Z0Mu0KyTA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702499827; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9tdgEFmJtgiJ/hsWpMo64wL16sVk4He/t45frB5SOHw=; b=KlT+slEwlTUqXddfrYmCwENX1Vxkn9FkXTziZZ6+3CiQ+2VCoyNsd/YRLkAOZwGDVgVrW6 Ay+9NHZMHWEdcbCA== From: "tip-bot2 for Borislav Petkov (AMD)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sev] x86/sev: Do the C-bit verification only on the BSP Cc: "Borislav Petkov (AMD)" , Tom Lendacky , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231130132601.10317-1-bp@alien8.de> References: <20231130132601.10317-1-bp@alien8.de> MIME-Version: 1.0 Message-ID: <170249982674.398.5844405041679284531.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 12:37:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783995626077362302 X-GMAIL-MSGID: 1785200467956161419 The following commit has been merged into the x86/sev branch of tip: Commit-ID: 30579c8baa5b4bd986420a984dad2940f1ff65d3 Gitweb: https://git.kernel.org/tip/30579c8baa5b4bd986420a984dad2940f1ff65d3 Author: Borislav Petkov (AMD) AuthorDate: Thu, 30 Nov 2023 14:26:01 +01:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 13 Dec 2023 21:07:56 +01:00 x86/sev: Do the C-bit verification only on the BSP There's no need to do it on every AP. The C-bit value read on the BSP and also verified there, is used everywhere from now on. No functional changes - just a bit faster booting APs. Signed-off-by: Borislav Petkov (AMD) Acked-by: Tom Lendacky Link: https://lore.kernel.org/r/20231130132601.10317-1-bp@alien8.de --- arch/x86/kernel/head_64.S | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 086a2c3..d1dc39a 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -114,6 +114,28 @@ SYM_CODE_START_NOALIGN(startup_64) /* Form the CR3 value being sure to include the CR3 modifier */ addq $(early_top_pgt - __START_KERNEL_map), %rax + +#ifdef CONFIG_AMD_MEM_ENCRYPT + mov %rax, %rdi + mov %rax, %r14 + + addq phys_base(%rip), %rdi + + /* + * For SEV guests: Verify that the C-bit is correct. A malicious + * hypervisor could lie about the C-bit position to perform a ROP + * attack on the guest by writing to the unencrypted stack and wait for + * the next RET instruction. + */ + call sev_verify_cbit + + /* + * Restore CR3 value without the phys_base which will be added + * below, before writing %cr3. + */ + mov %r14, %rax +#endif + jmp 1f SYM_CODE_END(startup_64) @@ -193,15 +215,6 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL) addq phys_base(%rip), %rax /* - * For SEV guests: Verify that the C-bit is correct. A malicious - * hypervisor could lie about the C-bit position to perform a ROP - * attack on the guest by writing to the unencrypted stack and wait for - * the next RET instruction. - */ - movq %rax, %rdi - call sev_verify_cbit - - /* * Switch to new page-table * * For the boot CPU this switches to early_top_pgt which still has the