From nobody Sun Feb 8 17:43:21 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 8FC611C6FE9 for ; Sun, 4 May 2025 09:53:26 +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=1746352408; cv=none; b=WKWp1LnFvmH3D6/ILY0T1GtBvExf9Ox4ix6HmGZ6UUdnpbMkf9yOEIgTxmQTX9yjori56JtlRnQBtbDGJg3leZFV3iDisot/yBoRGyItmxeRJiAZuRJjCpHFxo37Odczxa4zZ/kFa9s6ibzhHi/gSuZFS/CkM6JkqZcAzyxJWPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746352408; c=relaxed/simple; bh=Da8gefPc/MkvKcwMBiYhIH1VS9MQxWYpqqsM/kBWj2k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rHZnQdmm0QAKDEfyJeTvrKdPk5rBGQnBd3eKqXrQgESaROGG0OzzUPQ+L4Ib7WDJG1AyIfrlW5AACVTFD5v9hWv/omoaTaiSF8rDl0loJHR6uyLjwzPo+4kqWY6BLBQIWeNZYPL8sAFkGvtYw9yxk2AbJcRO5dXNeMH26I3Xb/g= 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=BuSWy7FD; 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="BuSWy7FD" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-43f251dc364so19246505e9.2 for ; Sun, 04 May 2025 02:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746352405; x=1746957205; 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=wX4/+1PkJw6Jnyy4g/DPm+Tnx+UM3RROZEvunHorr8w=; b=BuSWy7FDncgofHjWoRwDC6CE6TfX0rM0sSqhhTgOWasCHGF5vfUpoW2keBrQhAk54I LIAGVpTK6agyN/80oP+5NaC7KJWKg2/LEoUHZaHQU7c7x0I2mYTUjBwGHfKX68ujlGvN 1tAs3IAXg7+O/jr7NXS2bcq/izZ0xrF8NicJGKj1mY2QyAoHzAAlXB1CWhGhSD5AEEWx oYv/5xQCmGpwJzUqte7IIMWoAvFBN6vKuDczp04Uf40TABhm5qjaHbVlEdvC+5VOtjD2 uhSRR35gEB238FUeR1iG7xK5zPN0QYkHGa61lD4MwfucKHQrpCz7gdpXqqVir8XnvhiY +xXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746352405; x=1746957205; 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=wX4/+1PkJw6Jnyy4g/DPm+Tnx+UM3RROZEvunHorr8w=; b=Rm+ZLU7UHkeEtW9r2RiyZtkg9uxuUTgEnRv8lDwxBKjyG2IpSKnUiwuleHnjYQJGVm tTCsi0Vcq2141wA2oLUAWRIC5tRFLFMMssQcooJO42GPa0VqCUi9z/Q1htP3ICn2sqKz KIr/hS3HEsx7Ff+hobKEPuuxccKv+lVlH8+UZajdZMtFAnnk2SqjAmj4DFKhr4zxPr4N /yGBQ5CBxNnnwaVxM4q/GWx+ENYxBi4ryAbHd31ogjElIKc/PB/Kj+PR8tLlyRRrohHf dMlTezTsfCgR5C6vy/fmaFUQZuKVqY8e0ukziM5Ama8SvH2FxZ6+6Q9q/dpaMrFV1vhH 95Zg== X-Gm-Message-State: AOJu0YwaHVgLa5zFow+dwBD4laSsX0hRjoMz1gvOhn9svHduk8fTKXp3 iEUHmFHiwuVMxADV//el6Q8qzC4fEaXF2sCcgbpRR/gOfFVsdl60OoVFYiwb7Did6K7J7vIv1NP Uu32EVud1W7SUUtbDm2vA/QVcebZc46Mo1A7ziI7t19XntNT6txFs3cG4TlprN8n/FzSbkpV44P E9miDYJyH/oPjgY548Vlfj59VB+4N5LA== X-Google-Smtp-Source: AGHT+IFjslrWfCH+uAS9ty2elKHdVUzc19rUudtpTn5fWKEmJz4qLk7mVsC2Sil+38bd4AnXTSXFQj40 X-Received: from wmbfl15.prod.google.com ([2002:a05:600c:b8f:b0:441:b38b:9cc3]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1d8d:b0:440:66a4:8d1a with SMTP id 5b1f17b1804b1-441c48aa302mr27049065e9.7.1746352405226; Sun, 04 May 2025 02:53:25 -0700 (PDT) Date: Sun, 4 May 2025 11:52:40 +0200 In-Reply-To: <20250504095230.2932860-25-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: <20250504095230.2932860-25-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=6031; i=ardb@kernel.org; h=from:subject; bh=xk86JG/R04sMdF0/gJrtMthpOxFG4UyGc1tpigbLlgU=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIUPc4nXQ9wjJM+pm/4+6GIS8y/m44eIDBXutlHcub7IXH l8sKfOxo5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEzkeCkjwxPBGXFRQZWr93Ou K6rOal3zYdcLX4buK8Vc0ywtby55YMbIMLM5YiYPz5uIVVcC3mlr3HloMslq0/TtAZ777abPy8m /wwwA X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250504095230.2932860-35-ardb+git@google.com> Subject: [RFT PATCH v2 10/23] x86/sev: Use boot SVSM CA for all startup and init code From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-efi@vger.kernel.org, x86@kernel.org, Ard Biesheuvel , Borislav Petkov , Ingo Molnar , Dionna Amalie Glaze , Kevin Loughlin , Tom Lendacky Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel To avoid having to reason about whether or not to use the per-CPU SVSM calling area when running startup and init code on the boot CPU, reuse the boot SVSM calling area as the per-CPU area for CPU #0. This removes the need to make the per-CPU variables and associated state in sev_cfg accessible to the startup code once confined. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev.c | 13 ------ arch/x86/boot/startup/sev-shared.c | 4 +- arch/x86/boot/startup/sev-startup.c | 6 +-- arch/x86/coco/sev/core.c | 47 +++++++++----------- arch/x86/include/asm/sev-internal.h | 16 ------- 5 files changed, 26 insertions(+), 60 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 9b6eebc24e78..91e8140250f6 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -37,19 +37,6 @@ struct ghcb *boot_ghcb; =20 #define __BOOT_COMPRESSED =20 -extern struct svsm_ca *boot_svsm_caa; -extern u64 boot_svsm_caa_pa; - -struct svsm_ca *svsm_get_caa(void) -{ - return boot_svsm_caa; -} - -u64 svsm_get_caa_pa(void) -{ - return boot_svsm_caa_pa; -} - u8 snp_vmpl; =20 /* Include code for early handlers */ diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 0709c8a8655a..b1f4b9b15045 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -585,10 +585,10 @@ static void __head svsm_pval_4k_page(unsigned long pa= ddr, bool validate) */ flags =3D native_local_irq_save(); =20 - call.caa =3D svsm_get_caa(); + call.caa =3D boot_svsm_caa; =20 pc =3D (struct svsm_pvalidate_call *)call.caa->svsm_buffer; - pc_pa =3D svsm_get_caa_pa() + offsetof(struct svsm_ca, svsm_buffer); + pc_pa =3D boot_svsm_caa_pa + offsetof(struct svsm_ca, svsm_buffer); =20 pc->num_entries =3D 1; pc->cur_index =3D 0; diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index 797ca3e29b12..ca6a9863ffab 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -59,9 +59,6 @@ u64 sev_secrets_pa __ro_after_init; /* For early boot SVSM communication */ struct svsm_ca boot_svsm_ca_page __aligned(PAGE_SIZE); =20 -DEFINE_PER_CPU(struct svsm_ca *, svsm_caa); -DEFINE_PER_CPU(u64, svsm_caa_pa); - /* * Nothing shall interrupt this code path while holding the per-CPU * GHCB. The backup GHCB is only for NMIs interrupting this path. @@ -261,6 +258,7 @@ static __head struct cc_blob_sev_info *find_cc_blob(str= uct boot_params *bp) =20 static __head void svsm_setup(struct cc_blob_sev_info *cc_info) { + struct snp_secrets_page *secrets =3D (void *)cc_info->secrets_phys; struct svsm_call call =3D {}; int ret; u64 pa; @@ -289,7 +287,7 @@ static __head void svsm_setup(struct cc_blob_sev_info *= cc_info) * RAX =3D 0 (Protocol=3D0, CallID=3D0) * RCX =3D New CA GPA */ - call.caa =3D svsm_get_caa(); + call.caa =3D (struct svsm_ca *)secrets->svsm_caa; call.rax =3D SVSM_CORE_CALL(SVSM_CORE_REMAP_CA); call.rcx =3D pa; ret =3D svsm_perform_msr_protocol(&call); diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 883b2719986d..36edf670ff19 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -45,6 +45,25 @@ #include #include =20 +DEFINE_PER_CPU(struct svsm_ca *, svsm_caa); +DEFINE_PER_CPU(u64, svsm_caa_pa); + +static inline struct svsm_ca *svsm_get_caa(void) +{ + if (sev_cfg.use_cas) + return this_cpu_read(svsm_caa); + else + return boot_svsm_caa; +} + +static inline u64 svsm_get_caa_pa(void) +{ + if (sev_cfg.use_cas) + return this_cpu_read(svsm_caa_pa); + else + return boot_svsm_caa_pa; +} + /* AP INIT values as documented in the APM2 section "Processor Initializa= tion State" */ #define AP_INIT_CS_LIMIT 0xffff #define AP_INIT_DS_LIMIT 0xffff @@ -1207,7 +1226,8 @@ static void __init alloc_runtime_data(int cpu) struct svsm_ca *caa; =20 /* Allocate the SVSM CA page if an SVSM is present */ - caa =3D memblock_alloc_or_panic(sizeof(*caa), PAGE_SIZE); + caa =3D cpu ? memblock_alloc_or_panic(sizeof(*caa), PAGE_SIZE) + : boot_svsm_caa; =20 per_cpu(svsm_caa, cpu) =3D caa; per_cpu(svsm_caa_pa, cpu) =3D __pa(caa); @@ -1261,32 +1281,9 @@ void __init sev_es_init_vc_handling(void) init_ghcb(cpu); } =20 - /* If running under an SVSM, switch to the per-cpu CA */ - if (snp_vmpl) { - struct svsm_call call =3D {}; - unsigned long flags; - int ret; - - local_irq_save(flags); - - /* - * SVSM_CORE_REMAP_CA call: - * RAX =3D 0 (Protocol=3D0, CallID=3D0) - * RCX =3D New CA GPA - */ - call.caa =3D svsm_get_caa(); - call.rax =3D SVSM_CORE_CALL(SVSM_CORE_REMAP_CA); - call.rcx =3D this_cpu_read(svsm_caa_pa); - ret =3D svsm_perform_call_protocol(&call); - if (ret) - panic("Can't remap the SVSM CA, ret=3D%d, rax_out=3D0x%llx\n", - ret, call.rax_out); - + if (snp_vmpl) sev_cfg.use_cas =3D true; =20 - local_irq_restore(flags); - } - sev_es_setup_play_dead(); =20 /* Secondary CPUs use the runtime #VC handler */ diff --git a/arch/x86/include/asm/sev-internal.h b/arch/x86/include/asm/sev= -internal.h index 0d02e780beb3..4335711274e3 100644 --- a/arch/x86/include/asm/sev-internal.h +++ b/arch/x86/include/asm/sev-internal.h @@ -64,22 +64,6 @@ DECLARE_PER_CPU(u64, svsm_caa_pa); extern struct svsm_ca *boot_svsm_caa; extern u64 boot_svsm_caa_pa; =20 -static __always_inline struct svsm_ca *svsm_get_caa(void) -{ - if (sev_cfg.use_cas) - return this_cpu_read(svsm_caa); - else - return boot_svsm_caa; -} - -static __always_inline u64 svsm_get_caa_pa(void) -{ - if (sev_cfg.use_cas) - return this_cpu_read(svsm_caa_pa); - else - return boot_svsm_caa_pa; -} - enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt = *ctxt); void vc_forward_exception(struct es_em_ctxt *ctxt); =20 --=20 2.49.0.906.g1f30a19c02-goog