From nobody Mon Feb 9 15:59:17 2026 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6F83214A74 for ; Wed, 16 Apr 2025 16:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744822685; cv=none; b=tABEHcDPG6OAZlgN7hfli8uPAx14HCdB85vtAsMQa/edAQRLx3Bkez197PY3R9Naaw/VtGVZ8+0v/STa5u2NsQGWBvz2rVdkm/oTlrbeU0YO+TepYjh6XisMSGlWegLPcpO7L6oQiDeCBes0bc3smZwUh+kmHdmakvvMnSH01Pk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744822685; c=relaxed/simple; bh=hLfvkW2dil561oNPEdZlU+Dh02P84Pkkg+e6wBeW1xs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VwTOgKEpTOcQJ4Oj4iFBr48M7m7BLOh/cOiNlAtF+rjf7va5nte3Pr5gXnEFIj8T5zGA8uHkOkg725Yaor/A26Hfnu51gxQO8hRsjDt19K6ZipcYDHY1CmxH4FnXYagTxkig5yDcqYGcGEQixixk+5jLmXa5wBOiUI/EYfEtgcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B74jDL48; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B74jDL48" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-3913aaf1e32so4000585f8f.0 for ; Wed, 16 Apr 2025 09:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744822682; x=1745427482; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=upqUq0Fa7EAF72jGlng+4tK3QC6Z7kLIehCFLXDq35M=; b=B74jDL48lJ/YoXD8IuAsPtH+uhi6wjwq2Qme8pKEKau6I+TvFSocreQQl9QoZl8eFW ZBiq5VN989I+3lbNFXldLWlMlBKQhrlMTGTC6vrJBUacdANa7NT4+Bg1BwRiQ8BbaGQ8 N+eFqIzQYgAgiUTtKakq5uGEkWh82m62TuMOBHtQKK+jxnxeYOAwJ3z3f4FbpsCGPApb laQgQxH+nyba8aTtBi3icw31Q9Z9aRC2AtrefgUfQf4Kr/i9jMdwiZ+wHr59MbKRO52Q N5ICfiJWwO5Q2YfvGdhkYmFUolBkCdDgktLz10+pwizku8sMWocdU5fcpJ9TC2wrLhcc +IFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744822682; x=1745427482; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=upqUq0Fa7EAF72jGlng+4tK3QC6Z7kLIehCFLXDq35M=; b=RH5Gak1RKDY10C3aUrvvv7LnHQ4DG/k57V5TJqWoohC5MghuZ/dR0lgwXrvHcSFlrq aXSovAdJr4QY3wcsLifWZhqNDv9wMDEg5Y30syV7e6b8Up6TMZj1spcBPffpsDZMvKSU bsWokW58HlhcTnt8G0AujbteJRUCuZ8p/1NPlCIvIwAswBuhrQ+DF76gK8BEa/9iQQ8e SXPkdvpuP0SzI5fdcApltvlyfMClHqD2TFt7Q38lVqv5ZuLtFW7+FutUPkqnsSxbiKIO Jhwwmp+f5Ve61cSAGQDmyMbJTE/426fs67IQ5MAZf/LUwcHx4yXzAkiUWcraYvjbPuXV y9bQ== X-Forwarded-Encrypted: i=1; AJvYcCUcu8q+mK5J7+CU9AQevYWQPzM7q4lcagt3xl3dQmoMha0sz8Isg0SrSImYzaIZ9pquEwuYvEeooqV/zms=@vger.kernel.org X-Gm-Message-State: AOJu0YwPtaK4qm9rAJTpCpUBPC/CObcsynlXIPPK9hYplYLHUFMKo95N cPwJXkpssKAuVo94Xf6oExTq9JgWyi3v/wstqPIVxWmV4WWo374gJbiSWLldjGeMszY7dw== X-Google-Smtp-Source: AGHT+IF3ubUXtqkFiF/bLP26+ML6WQicJcyTwlloYZXgaklZzd/7iVicbPvQV1q9gab5qSCOg9NeqFCb X-Received: from wmqh2.prod.google.com ([2002:a05:600c:3502:b0:440:595d:fba9]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:184e:b0:391:38a5:efa with SMTP id ffacd0b85a97d-39ee5b163c7mr2836685f8f.23.1744822682232; Wed, 16 Apr 2025 09:58:02 -0700 (PDT) Date: Wed, 16 Apr 2025 18:57:45 +0200 In-Reply-To: <20250416165743.4080995-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250416165743.4080995-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2196; i=ardb@kernel.org; h=from:subject; bh=zoTGlyeTZ8cicOcp90d6H9mDgz3rJQHzXOqjzEb0s/s=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf3/w84HUzf0W75LeWF6fdPR43GNi3/ptuSXe+kLTDEo1 bIzDnrQUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACZSw8HIsMm8LzPgTecT4ah5 Z3fsnVx5sk5v66fNH6+KfNivpLNgRjEjw957VcW3e6LKeRfFbxa6EbHW7738W/unGnsvPl7Hqua ygRkA X-Mailer: git-send-email 2.49.0.777.g153de2bbd5-goog Message-ID: <20250416165743.4080995-7-ardb+git@google.com> Subject: [PATCH v2 1/4] x86/efistub: Obtain SEV CC blob address from the stub From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, mingo@kernel.org, Ard Biesheuvel , Tom Lendacky , Borislav Petkov , Dionna Amalie Glaze , Kevin Loughlin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel The x86 EFI stub no longer boots via the traditional decompressor but jumps straight to the core kernel, avoiding all the page fault handling and other complexity that is entirely unnecessary when booting via EFI. The SEV startup code expects the address of the CC blob configuration table in boot_params, so store it there when booting with SEV-SNP enabled. This removes a dependency on the later call to sev_enable() (which is going to be removed), and permits the EFI stub to fail gracefully inside the guest rather than terminate it entirely. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/x86-stub.c | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index cafc90d4caaf..d9ae1a230d39 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -681,17 +681,28 @@ static efi_status_t exit_boot(struct boot_params *boo= t_params, void *handle) return EFI_SUCCESS; } =20 -static bool have_unsupported_snp_features(void) +static bool check_snp_features(struct boot_params *bp) { + u64 status =3D sev_get_status(); u64 unsupported; =20 - unsupported =3D snp_get_unsupported_features(sev_get_status()); + unsupported =3D snp_get_unsupported_features(status); if (unsupported) { efi_err("Unsupported SEV-SNP features detected: 0x%llx\n", unsupported); - return true; + return false; } - return false; + + if (status & MSR_AMD64_SEV_SNP_ENABLED) { + void *tbl =3D get_efi_config_table(EFI_CC_BLOB_GUID); + + if (!tbl) { + efi_err("SEV-SNP is enabled but CC blob not found\n"); + return false; + } + bp->cc_blob_address =3D (u32)(unsigned long)tbl; + } + return true; } =20 static void efi_get_seed(void *seed, int size) @@ -829,7 +840,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle, =20 hdr =3D &boot_params->hdr; =20 - if (have_unsupported_snp_features()) + if (!check_snp_features(boot_params)) efi_exit(handle, EFI_UNSUPPORTED); =20 if (IS_ENABLED(CONFIG_EFI_DXE_MEM_ATTRIBUTES)) { --=20 2.49.0.805.g082f7c87e0-goog From nobody Mon Feb 9 15:59:17 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA5002153C9 for ; Wed, 16 Apr 2025 16:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744822687; cv=none; b=SIjWLLKjFWuDgvtN6lzi7qkm16MSvmScLumY33G1ut2EfpuQLL1yIa2801bPPbkr6Vqbwjv/QfOQXSuLzauCO3IIir61A0Q4cPUaV1DLjkH70ogdU9gbbF4xnx0b0ph9KoTLxC638bNot2NdiVY7N1lKIPZOtuYOtMx0uUIJYEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744822687; c=relaxed/simple; bh=lRe9hLNbP/OaX7MwertBxcNmClmRysFfc7d6hRijpLE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZzvrKuQ1qFvAcIVrzJ+74vNKbhszB8Sbb+yo14LJG+RM/minsHh0Bm431I3DccCUIkimn07+fs21zjf/8QyVz9QL7VRBjGs/mc40VQtJJhhTUYJHD6gegC5END1NPzYrIvuve5GJAqCIkdBtAnoxSWa7KRd93w46vhJHePsUu+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bhVv7x/C; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bhVv7x/C" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-39141ffa913so4050755f8f.2 for ; Wed, 16 Apr 2025 09:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744822684; x=1745427484; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tTCjlI4jRJCYXW8u75vTgWDWUcDqLf34EMngrdWGbjQ=; b=bhVv7x/CKWnip8gzLTXFXVbMDBHkBKO+3wvFYzFi9uM7cEyLO7pzPo71Ys6Dff28OG flXBbV6lKJ9puiotuxVpBaW+d0oIknxoqFN0fuJydB97FxYwlGsl1S6gKwy5Llggmpdf p6GKI4/wcBBOvWpZa8yx6X6S/G6ADpHoHE96pEH2A/0WrkBVlO3YdjYbMSq+UHpeTu8v FBS3XAGHcAVTc9yI7cMByemb/U9OUblELetW16LCm6gZOIuaIdfeRiyCTM6WHi1d9jsP phHpRXSN9/7Y8O1kAqnXMSg39ocGwv/mpFS/ETjco7UDcIm++nO47vxZ36WRQOmWzLSP L0Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744822684; x=1745427484; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tTCjlI4jRJCYXW8u75vTgWDWUcDqLf34EMngrdWGbjQ=; b=c8OemniScfT0blWxvQcsBql5k/hg4u6rnObqyQZygofjru7BNJBUrKmfjLE3T8u1rj o3s366uA8BdfEAuU9Oo1zUTmFgKSK3qmVw9D8lmT/C2eu9HaRDPrTuHHSF/dYbOGJbVX H80U9Qeod1ejapc+Ha26/0+7suCjJGTY9bmyORJqIZG43/g2VJDZWHwBpTc1JjNP0kpp ubcnDO85QsoEM0D0yxzanVZXR8l4w+K1/edOXLyKxdEqkpqP/+8gz8jQojOaNR81/20o /xaVk6oo1IrGEyz0nRNQOFP1v9/tlXzjEY2FmL/eC5CB8DBAQQp/dLcwEujTr1ZIVjkk uZLg== X-Forwarded-Encrypted: i=1; AJvYcCWheilmqf5ob/OXePam960PuOIR+ofyTEDRxrR0EaWL5ydMgPjrnQQhR1pRlBYsCjX8AasnuISJWL2Km9A=@vger.kernel.org X-Gm-Message-State: AOJu0YxjRn5Qpj/xVZacgbVkYKu4XBtdsBmY0Dg+UZ56tsNdw966Xm7U /t7UdbbE8sFU6Z1uEzRR9WwxYlLLky5tAkjLqK4w6DnXS4/qz3a/Ip0vGAztVRcNTW2AuA== X-Google-Smtp-Source: AGHT+IFjJecSiikc6rQEhoneDuSkFJVjN+/qGiEBByEyYjO0q6UyVDW7J9WRNaZ2JfT+PQvbqLm0Nn/D X-Received: from wmqd11.prod.google.com ([2002:a05:600c:34cb:b0:43d:58c9:bb51]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:4308:b0:391:45e9:face with SMTP id ffacd0b85a97d-39ee5bafdf9mr2248386f8f.54.1744822684335; Wed, 16 Apr 2025 09:58:04 -0700 (PDT) Date: Wed, 16 Apr 2025 18:57:46 +0200 In-Reply-To: <20250416165743.4080995-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250416165743.4080995-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2029; i=ardb@kernel.org; h=from:subject; bh=10Qa3f8wkjUVpqoovejQoxb1J4k9EmK+vNsm5yY59B0=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf3/w66LT23T1O/2bvrhs2baJ5v3zy792NWsNPVOYMiss EU3/TPCOkpZGMQ4GGTFFFkEZv99t/P0RKla51myMHNYmUCGMHBxCsBE5PQZGd6nL8+J2Hy3tj3D bPL2xxKn7T54+YdKrZmrZc95k3tbvx4jw8atcg277qvr7nvT8fb7DlYp54xtVVarzBg85B1O1LU 9ZQQA X-Mailer: git-send-email 2.49.0.777.g153de2bbd5-goog Message-ID: <20250416165743.4080995-8-ardb+git@google.com> Subject: [PATCH v2 2/4] x86/boot: Drop redundant RMPADJUST in SEV SVSM presence check From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, mingo@kernel.org, Ard Biesheuvel , Tom Lendacky , Borislav Petkov , Dionna Amalie Glaze , Kevin Loughlin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel snp_vmpl will be assigned a non-zero value when executing at a VMPL other than 0, and this is inferred from a call to RMPADJUST, which only works when running at VMPL0. This means that testing snp_vmpl is sufficient, and there is no need to perform the same check again. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 6eadd790f4e5..26ba997c45fa 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -617,30 +617,16 @@ void sev_enable(struct boot_params *bp) */ if (sev_status & MSR_AMD64_SEV_SNP_ENABLED) { u64 hv_features; - int ret; =20 hv_features =3D get_hv_features(); if (!(hv_features & GHCB_HV_FT_SNP)) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); =20 /* - * Enforce running at VMPL0 or with an SVSM. - * - * Use RMPADJUST (see the rmpadjust() function for a description of - * what the instruction does) to update the VMPL1 permissions of a - * page. If the guest is running at VMPL0, this will succeed. If the - * guest is running at any other VMPL, this will fail. Linux SNP guests - * only ever run at a single VMPL level so permission mask changes of a - * lesser-privileged VMPL are a don't-care. + * Running at VMPL0 is required unless an SVSM is present and + * the hypervisor supports the required SVSM GHCB events. */ - ret =3D rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, 1); - - /* - * Running at VMPL0 is not required if an SVSM is present and the hyperv= isor - * supports the required SVSM GHCB events. - */ - if (ret && - !(snp_vmpl && (hv_features & GHCB_HV_FT_SNP_MULTI_VMPL))) + if (snp_vmpl > 0 && !(hv_features & GHCB_HV_FT_SNP_MULTI_VMPL)) sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); } =20 --=20 2.49.0.805.g082f7c87e0-goog From nobody Mon Feb 9 15:59:17 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE422215F6C for ; Wed, 16 Apr 2025 16:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744822689; cv=none; b=qYhjLyYOsznqsE8rtvdferO2v86LiSs8UtU6OM61o+cjtgb6RkXi/baqLYdCFRtTPydk19t6OvgHCpkTogLY2k2jrNUrFNM6n9A6mrBjeyxsERnllri9GSkg0gXVS8E9l7BAEejNrldfSEa7X9rKiqBMZO3/yaWa4o4ZVlwGixI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744822689; c=relaxed/simple; bh=PgEJaJgE0LXiQJDQNeoBnr/Xemmrs41II8OE/SAPKgE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=j0Att3m0BrIMXRDuyzWJc59z/ZLvKqpvY9qqkAfdXLu6N4ckFLoC7yg4fcR10nZBxb+LoV+7+dwEe88iFvPMnzaPLmJ4LZE6shPGcK95x/F7K57C9LWOTri8OuNUWxrYkvT0cwCWdqiSqALKfFV3chqdPLhSoxV5F4bg4bpxjns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AfEvETeU; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AfEvETeU" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-43d0830c3f7so53372825e9.2 for ; Wed, 16 Apr 2025 09:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744822686; x=1745427486; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+AXQAr6DEdb53aAovtH1m4o5iLjqGheV49k9eDzwzjU=; b=AfEvETeUuP+uvuWet7jyjKtftUuQ5Oe1E5JYDytxCC2eMArX2OWgCrhcZqPH2+R2CP rH04rRmankp0H6lQx0AzMbDWi9wgugbO75F67Z9xOLqVzTGXdDyiWn70fQF3yeaVluOZ ox56j/s8HLd+wMD9QinApsZakoOToMxjAa7js2TciLfW0xdvJj/TsFurgiaTVO+DUBVA EeE6F8Zxqt9wQIylQ5h4/Vh/w/kjZIcaceMqV60a1ZQVO/xW7jG/OMBeRcT0UvldD8W5 9OFLfdPrgZXidRQZG4UrFY80HKPGmdF82iZgm5zkJDZg0+Gq6YmQHruIiVc8cHzUHuTb hJCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744822686; x=1745427486; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+AXQAr6DEdb53aAovtH1m4o5iLjqGheV49k9eDzwzjU=; b=SUBGOGphc54cJ+0f9Y8+sH3Im9iqhvVI4PJubhtNRc23FXJAUZnGH4J1zNPZpA7YLM ZDAB0NILW74ryDpXscDJOB9AzIzCMdPiAfG/63RKF5pFvvJ1tKwPJ52slm/vh+B/68tc P/IoNHPZASdhL2GHnt4X1fVEkIsbaOtQxItoHOgujqsNGx3KEBS6mNdgV9srO6Axyjey K0jbB1XYw3E1DgqnELx2AuaP82LxlXS+2dJTb80Ndo2m409mEIYnVbkzpRIdpjKHqfkt BgAi286kGKiOobGjQQGXWt3CRuuiYUfxuw6g9KQCSLHLUkyBttCyuiLh6J8yspwdPLLk Vplw== X-Forwarded-Encrypted: i=1; AJvYcCWsWUXIv1EYU6byZFwXCQs1QLnv9663W6YHk6Ojb1pOPq2tRfDSolpYVlJ6iexju8NcyzY1Du5wlOcOaJs=@vger.kernel.org X-Gm-Message-State: AOJu0YxXWyS4dcdtzTe7TsUk48ILspPB+rBA8OyiC2KVUCinMkN5DKz6 ZkPXeafpjDemuhC9kBxTG0PmOvL4wH+suP7PWslaOnWGtlwZc5S5dGIFnfgYF6I3krY2MA== X-Google-Smtp-Source: AGHT+IHTV/3RUCyKhwGqdBj/wC/EfEt6jOyqE3Rh/VKi0y7pMFXpDis+ib55sXylrUCf9El9T3zmxV+y X-Received: from wmbh25.prod.google.com ([2002:a05:600c:a119:b0:43d:586a:9bcb]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:5020:b0:43d:83a:417d with SMTP id 5b1f17b1804b1-4405d625d68mr28618735e9.12.1744822686421; Wed, 16 Apr 2025 09:58:06 -0700 (PDT) Date: Wed, 16 Apr 2025 18:57:47 +0200 In-Reply-To: <20250416165743.4080995-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250416165743.4080995-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=6446; i=ardb@kernel.org; h=from:subject; bh=aJ31HuwoQHpuIXtoeQRHoQQiwMzqJa0G33NiTtuOfdc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf3/w57UIk4xtjCBaC7XkvoO3VPzv06dEFqe+EK8wW975 lW52R4dpSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCJckQz/c+s/6/e6357yw/+t +8V/NWd90ttm1zt7Xrnz37TUJHjpJkaGYxPMcrQ4f6vO3dwW+1Xh+uPSL3G8SotNv1vwTd+lnr6 MEQA= X-Mailer: git-send-email 2.49.0.777.g153de2bbd5-goog Message-ID: <20250416165743.4080995-9-ardb+git@google.com> Subject: [PATCH v2 3/4] x86/sev: Unify SEV-SNP hypervisor feature check From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, mingo@kernel.org, Ard Biesheuvel , Tom Lendacky , Borislav Petkov , Dionna Amalie Glaze , Kevin Loughlin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel The decompressor and the core kernel both check the hypervisor feature mask exposed by the hypervisor, but test it in slightly different ways. This disparity seems unintentional, and simply a result of the fact that the decompressor and the core kernel evolve differently over time when it comes to setting up the SEV-SNP execution context. So move the HV feature check into a helper function and call that instead. For the core kernel, move the check to an earlier boot stage, right after the point where it is established that the guest is executing in SEV-SNP mode. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev.c | 19 +---------- arch/x86/boot/startup/sme.c | 2 ++ arch/x86/coco/sev/core.c | 11 ------- arch/x86/coco/sev/shared.c | 33 +++++++++++++++----- arch/x86/include/asm/sev-internal.h | 3 +- arch/x86/include/asm/sev.h | 2 ++ 6 files changed, 32 insertions(+), 38 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 26ba997c45fa..aeee011a6486 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -611,24 +611,7 @@ void sev_enable(struct boot_params *bp) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_PROT_UNSUPPORTED); } =20 - /* - * SNP is supported in v2 of the GHCB spec which mandates support for HV - * features. - */ - if (sev_status & MSR_AMD64_SEV_SNP_ENABLED) { - u64 hv_features; - - hv_features =3D get_hv_features(); - if (!(hv_features & GHCB_HV_FT_SNP)) - sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); - - /* - * Running at VMPL0 is required unless an SVSM is present and - * the hypervisor supports the required SVSM GHCB events. - */ - if (snp_vmpl > 0 && !(hv_features & GHCB_HV_FT_SNP_MULTI_VMPL)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); - } + snp_check_hv_features(); =20 if (snp && !(sev_status & MSR_AMD64_SEV_SNP_ENABLED)) error("SEV-SNP supported indicated by CC blob, but not SEV status MSR."); diff --git a/arch/x86/boot/startup/sme.c b/arch/x86/boot/startup/sme.c index 5738b31c8e60..11caa343790d 100644 --- a/arch/x86/boot/startup/sme.c +++ b/arch/x86/boot/startup/sme.c @@ -533,6 +533,8 @@ void __head sme_enable(struct boot_params *bp) if (snp_en ^ !!(msr & MSR_AMD64_SEV_SNP_ENABLED)) snp_abort(); =20 + sev_hv_features =3D snp_check_hv_features(); + /* Check if memory encryption is enabled */ if (feature_mask =3D=3D AMD_SME_BIT) { if (!(bp->hdr.xloadflags & XLF_MEM_ENCRYPTION)) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index aeb7731862c0..4618ab64c767 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -1582,17 +1582,6 @@ void __init sev_es_init_vc_handling(void) if (!sev_es_check_cpu_features()) panic("SEV-ES CPU Features missing"); =20 - /* - * SNP is supported in v2 of the GHCB spec which mandates support for HV - * features. - */ - if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) { - sev_hv_features =3D get_hv_features(); - - if (!(sev_hv_features & GHCB_HV_FT_SNP)) - sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); - } - /* Initialize per-cpu GHCB pages */ for_each_possible_cpu(cpu) { alloc_runtime_data(cpu); diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c index a7c94020e384..514e2d42700b 100644 --- a/arch/x86/coco/sev/shared.c +++ b/arch/x86/coco/sev/shared.c @@ -99,16 +99,10 @@ sev_es_terminate(unsigned int set, unsigned int reason) asm volatile("hlt\n" : : : "memory"); } =20 -/* - * The hypervisor features are available from GHCB version 2 onward. - */ -u64 get_hv_features(void) +static u64 __head get_hv_features(void) { u64 val; =20 - if (ghcb_version < 2) - return 0; - sev_es_wr_ghcb_msr(GHCB_MSR_HV_FT_REQ); VMGEXIT(); =20 @@ -119,6 +113,31 @@ u64 get_hv_features(void) return GHCB_MSR_HV_FT_RESP_VAL(val); } =20 +u64 __head snp_check_hv_features(void) +{ + /* + * SNP is supported in v2 of the GHCB spec which mandates support for HV + * features. + */ + if (RIP_REL_REF(sev_status) & MSR_AMD64_SEV_SNP_ENABLED) { + u64 hv_features; + + hv_features =3D get_hv_features(); + if (!(hv_features & GHCB_HV_FT_SNP)) + sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); + + /* + * Running at VMPL0 is required unless an SVSM is present and + * the hypervisor supports the required SVSM GHCB events. + */ + if (snp_vmpl > 0 && !(hv_features & GHCB_HV_FT_SNP_MULTI_VMPL)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); + + return hv_features; + } + return 0; +} + void snp_register_ghcb_early(unsigned long paddr) { unsigned long pfn =3D paddr >> PAGE_SHIFT; diff --git a/arch/x86/include/asm/sev-internal.h b/arch/x86/include/asm/sev= -internal.h index 73cb774c3639..81abef86b1d0 100644 --- a/arch/x86/include/asm/sev-internal.h +++ b/arch/x86/include/asm/sev-internal.h @@ -4,7 +4,6 @@ =20 extern struct ghcb boot_ghcb_page; extern struct ghcb *boot_ghcb; -extern u64 sev_hv_features; =20 /* #VC handler runtime per-CPU data */ struct sev_es_runtime_data { @@ -117,6 +116,6 @@ enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, void snp_register_ghcb_early(unsigned long paddr); bool sev_es_negotiate_protocol(void); bool sev_es_check_cpu_features(void); -u64 get_hv_features(void); +void check_hv_features(void); =20 const struct snp_cpuid_table *snp_cpuid_get_table(void); diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index a8661dfc9a9a..8637a65973ef 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -418,6 +418,7 @@ struct svsm_call { #ifdef CONFIG_AMD_MEM_ENCRYPT =20 extern u8 snp_vmpl; +extern u64 sev_hv_features; =20 extern void __sev_es_ist_enter(struct pt_regs *regs); extern void __sev_es_ist_exit(void); @@ -494,6 +495,7 @@ void snp_set_memory_private(unsigned long vaddr, unsign= ed long npages); void snp_set_wakeup_secondary_cpu(void); bool snp_init(struct boot_params *bp); void __noreturn snp_abort(void); +u64 snp_check_hv_features(void); void snp_dmi_setup(void); int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call, struct = svsm_attest_call *input); void snp_accept_memory(phys_addr_t start, phys_addr_t end); --=20 2.49.0.805.g082f7c87e0-goog From nobody Mon Feb 9 15:59:17 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20CD6217663 for ; Wed, 16 Apr 2025 16:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744822691; cv=none; b=OEVZn+qvjGTwk2LppPYYMbS76hFFiug4B5HHVaD5Idv9YFjbSeVoO6cAczpNgxG3ZrKcEr8sn5NN9ZZEJr0v/ccSDWncdxD2ClrH3S/+VeQt4XIGc8mgIsDphIVWy7RM2XdWYAlQXOJKd+aM8kEVpfpFeH6v6x7g+Lcj70kXpfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744822691; c=relaxed/simple; bh=XBtyQHzEjNNgjgTe/YKXlSvf7rqCznV9aavmpW/Wb6k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fGsF8phGJT/AkcZTcD6au0ys58bBAxP62KrD4/WFkzgAF2048vZhbakSJJjOMd2gpczSfySN9ggAS4zA1gDNhCwufjkdhdL92m4smOdKjSFAKY4ZGzGT0EW19+QNysIpTnhk8RoG1V7PKaTKBJ+5A+bx0u+7nrXIHIJ+tDqQHqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1sppd8vZ; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1sppd8vZ" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-43cec217977so41817545e9.0 for ; Wed, 16 Apr 2025 09:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744822688; x=1745427488; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WnocHU1mfccFDedSoFZAIkdUs0QWEX0U3+1AYetVeiI=; b=1sppd8vZQuzWrmvn3nt85kx1a8OdOFmXcL1W7Sd7g9jZbwRP7/x9h9MlzybonQVl37 X2kByUNAViUL5dZFEc1PwxIZut6YaxpilddRYpEqv+dOUZy8l1xyNUf6M/7vU2m1xclB WiUekdrOyxMsoqXfS+gZHiDbdQSnia0aw4ClF6ppNrc87YOzQs5w0O7kh/Am4IdbR1Mq Za7C0Gw9aQH1Up5dMg4T98FWTJLnNWbg4T3cMg3mWmaSdSJkBU8HBELbJX2hQ3uPoMqb 5vQhPU7WpkpsAVpKForMMcNzHyu6KoioVFKsUMhz6e6BJ2xWz5KgrI9CrlNkFIJkqZyG /9Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744822688; x=1745427488; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WnocHU1mfccFDedSoFZAIkdUs0QWEX0U3+1AYetVeiI=; b=chFifKOTpoS54THyAdvUKANVQ+EBZuFRlwtqLm8afPc0wOwcwMe21QbelAYglmoxDA ztvHNYZM1jV1j+qaPFUvg90XnHOU+NWvHcdKFPb0/aXCgPvgX20w+btFAGJMf9aOGGZJ SUnY+24xK+cHQJdVYHPBSxOP9DcMHxkOZeuFNVcRTlCTBZHZAV2mEC/sox7jb0P/Fyv1 qjoZHxppwkr/Thoy+qPR2ML00fX22JaagWfjf8zGUhSWMtq6KA4+fs3wo7GcoSc/Ac1j q9DvLQSTRYY+/tZFJ4oxrnc3Pm/W66AWzXB3ss2hXEi7C59PDBgeGn6tUAnQr++wIuFC vpTA== X-Forwarded-Encrypted: i=1; AJvYcCUEdtMKFYFJALGxpsKk5YiDrHe9fMN/yp9x0U3jN4HeBmY1E6xZBAbKVhnyIZfSmaARrEGfGty9/LCYa8c=@vger.kernel.org X-Gm-Message-State: AOJu0YwudyJZ4uT/CI5FmwgiA3F6Pjwj4SOOUllq2w0FG+jj7Ul4KoII p1MGpAE2qArnNkJcg4SoXGLd7hF7z+APZaKwvL2z3F8U9kwj3NdTzxGX/ZSbpIdHZIvr3w== X-Google-Smtp-Source: AGHT+IHDioEa0asrZ6ktU/OURO4/16oUCUp0FKLWlZ90m8fNpNQzxk3VCdHZXCpqHBL07mSKMbNi7FOR X-Received: from wmbg21.prod.google.com ([2002:a05:600c:a415:b0:43d:1f28:b8bf]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:64c8:0:b0:391:43cb:43fa with SMTP id ffacd0b85a97d-39ee5badbdemr2741778f8f.51.1744822688464; Wed, 16 Apr 2025 09:58:08 -0700 (PDT) Date: Wed, 16 Apr 2025 18:57:48 +0200 In-Reply-To: <20250416165743.4080995-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250416165743.4080995-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2272; i=ardb@kernel.org; h=from:subject; bh=rtVhNZoNBTlEaY8pB6Ac8e2FfcEyp0oDiXBE2BvNGnU=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf3/w17N3x0v3PYc+yD95L9E/l2/F7cjXzz+afd1nsbJR K0Pv+b1dJSyMIhxMMiKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICLpDH8ZmEsPj3jjWjTgsRL +hXdz02sSrbVyyaZLCxX5vs7zczVgpFh5p2lfRf3hPO/vj3j71OtPZcnczp2aC4MdvufLLUvYms LBwA= X-Mailer: git-send-email 2.49.0.777.g153de2bbd5-goog Message-ID: <20250416165743.4080995-10-ardb+git@google.com> Subject: [PATCH v2 4/4] x86/efistub: Don't bother enabling SEV in the EFI stub From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, mingo@kernel.org, Ard Biesheuvel , Tom Lendacky , Borislav Petkov , Dionna Amalie Glaze , Kevin Loughlin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel One of the last things the EFI stub does before handing over to the core kernel when booting as a SEV guest is enabling SEV, even though this is mostly redundant: one of the first things the core kernel does is calling sme_enable(), after setting up the early GDT and IDT but before even setting up the kernel page tables. So let's just drop this call to sev_enable(), and rely on the core kernel to initiaize SEV correctly. Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/sev.h | 2 -- drivers/firmware/efi/libstub/x86-stub.c | 6 ------ 2 files changed, 8 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 8637a65973ef..d762cc0fd47e 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -443,7 +443,6 @@ static __always_inline void sev_es_nmi_complete(void) __sev_es_nmi_complete(); } extern int __init sev_es_efi_map_ghcbs(pgd_t *pgd); -extern void sev_enable(struct boot_params *bp); =20 /* * RMPADJUST modifies the RMP permissions of a page of a lesser- @@ -531,7 +530,6 @@ static inline void sev_es_ist_exit(void) { } static inline int sev_es_setup_ap_jump_table(struct real_mode_header *rmh)= { return 0; } static inline void sev_es_nmi_complete(void) { } static inline int sev_es_efi_map_ghcbs(pgd_t *pgd) { return 0; } -static inline void sev_enable(struct boot_params *bp) { } static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool vali= date) { return 0; } static inline int rmpadjust(unsigned long vaddr, bool rmp_psize, unsigned = long attrs) { return 0; } static inline void setup_ghcb(void) { } diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index d9ae1a230d39..6b4f5ac91e7f 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -936,12 +936,6 @@ void __noreturn efi_stub_entry(efi_handle_t handle, goto fail; } =20 - /* - * Call the SEV init code while still running with the firmware's - * GDT/IDT, so #VC exceptions will be handled by EFI. - */ - sev_enable(boot_params); - efi_5level_switch(); =20 enter_kernel(kernel_entry, boot_params); --=20 2.49.0.805.g082f7c87e0-goog