Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5573062rdb; Wed, 13 Dec 2023 12:37:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+sFmkBftPze/sWSb5zL8DR53v907BmGzGpq8jbZSKcMegkjAVHafp76GRN9S5y0mnKQUw X-Received: by 2002:a05:6a20:6714:b0:190:3fd8:45b6 with SMTP id q20-20020a056a20671400b001903fd845b6mr4957269pzh.25.1702499839931; Wed, 13 Dec 2023 12:37:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702499839; cv=none; d=google.com; s=arc-20160816; b=HnL+XPYHzMOKmMh325xpt4gKGvRmKTV5+5VzLNsECnRnoz2LERoEcBhazxJQHNHm6l +1jTF81k7TWOUhRRP7qqSUs6sEAUZPixAfiukK3lFNn1CEweiObEE3djauC9xxxvSxuh 6lpjQFILB8B5yb/voRneKR6KOBbWO6fAU3JTmGtxaMWTrDtlRvgP1eRWWLaETxY9uMIa tbI+Glp1QQRmrN4+DC3H7D2mVG91+Kr9t0hy6vb2GqGw/WGGK+2ljW8eEJOewZycurIM 9/ckHIYvSVR1YDPUctmA4qg4Iw+8JfJ74eTR85FJv3oCPCycTXoSYCz04CJ/6uQzc82j Yaiw== 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 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id m8-20020a63ed48000000b005c6673e2c72si9766350pgk.213.2023.12.13.12.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 12:37:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; 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 23.128.96.33 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 5F21580C875E; Wed, 13 Dec 2023 12:37:17 -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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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:17 -0800 (PST) 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