From nobody Sun Sep 7 14:40:25 2025 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.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 C66A130AD1B for ; Thu, 28 Aug 2025 10:22:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756376568; cv=none; b=Ydxb9cRA/P/32aXrjxtc7zcsIFUgv6KBzgPfKBHzercURASLGxP4h26RIr3R18JWucCASzAHh9rkk3xgRcRJ9IeG9VlSCnK2uufiRgXni9DJeYBCa7ywlHnpq0K03eHbgPsVoaZwe5wqt7PMc8hKUQoZiMoxHZq1YIxBv8qez1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756376568; c=relaxed/simple; bh=kbRhLjsFsfQOfcNbfvEEZZaC8ogzs16ItYPudW2bum4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=f17k3DwN4gdW27XjwSowJHTjMfLpJ6QE7t8AQg4y3FdF04hS8C49EOCemNa3BCadMPSbteH+MzWYBZGgwd3u94LiMpwFFc7U5uFE7ZWw7W5x6iDPD+Ku1ik2mQe74eRN/SoWAU/klhV4W33Wa3d+zOMSyJt4Hi+b5o0kUmk/MYw= 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=eHOrFUXX; arc=none smtp.client-ip=209.85.218.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="eHOrFUXX" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-afe6216085aso60290166b.1 for ; Thu, 28 Aug 2025 03:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756376565; x=1756981365; 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=dNkCiWgoJXF1ru1y9bEItu48j6Mp/Zxq2OanWUzF0Jg=; b=eHOrFUXXV21Q6VifwZTz99mrbIomB7ihyp5s7KpYcHstyfYyGXdXFg/llYnqtmgXl6 vOGqs1I11o7ElbMGCKq0j1V6Cog0nlaKsuQ8Ft4xaUQJDDvLFTHg2JzvKJIoUixt01QG UvZ8ISv2svYK0BMvXs09hahW23PlcvWJY0Er/lSmnnq5GB77c/qunH4yLGXoBULqo5ps RRwLjIHWpJjBDReXuwdSsTumWpfhMZXe9toxEzw1CCK1noEtQj22zvraQCNYJvyRR5bz CQV0jVnMhTdGXYubAytoqkJpVGRXbpFeSIgr5X0j/0r32G0ZAzzGVt+DH0DeMvVDTAjJ TYew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756376565; x=1756981365; 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=dNkCiWgoJXF1ru1y9bEItu48j6Mp/Zxq2OanWUzF0Jg=; b=vxQsWVBbcym8x8iJ++CfH9VSNenVXK3YwVWGcamGadf3zS1TrxOcxCLIetjSaFonhn EEE3nsNoj+s0HbGUn//ZWlCHriSy+BkWDcXIEezyga92yZBrz+mOkHG5LzFtDpFm0Pl3 HzUyZH4uWh5PBJ3HpFzpqlhOsT5NZw6FaTjA4uyg+cRftOuPJwYaHfXrzl+HgKM4sM0J vNy38Z/i+FykRo6z3M8Kv1LRIuXR1060WsEbqbgnqwV47oUYgygL4wlnMStIZkr4tCHC v6jd3HeTEh1DbDBaN7ibo/c5ux3KUudhRO3hHDDocnQ2Xwu1hnCnoh2UJwkEHvxkdy68 0hiA== X-Gm-Message-State: AOJu0YzktN8bIwietzLoiK/Egw84e3it3As2UAPSyXAkztlM6ZCumDFJ jxetCyRU9vcLqO39dInCHv61N71slxY9818hIqo/dRzW95OBFsKh9Zf3QxKxp4cYlLE0cxpxW+X g47drlUQzArRePF/GipSGOHmVb4MDr6dNmHxWvSWOEEFaERkBa2BoTTnZnZosZQ3KtBGDcnv56H 56T0uuhoAIGJVnK21hPiERZdzbKsPQeZjtUQ== X-Google-Smtp-Source: AGHT+IEdv7mMg3gEVKaKZBtRemKkta4byG9MVxV52sHDkTP7r/nh6czwtsItRFYYNoPF1QZ7iWCCsV7a X-Received: from ejcug4.prod.google.com ([2002:a17:907:c8c4:b0:afe:96ea:180d]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:97cb:b0:afd:d9e3:953f with SMTP id a640c23a62f3a-afe296b14edmr2262708566b.63.1756376565039; Thu, 28 Aug 2025 03:22:45 -0700 (PDT) Date: Thu, 28 Aug 2025 12:22:12 +0200 In-Reply-To: <20250828102202.1849035-24-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: <20250828102202.1849035-24-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5360; i=ardb@kernel.org; h=from:subject; bh=C0q1ad84KjlSQtQ9LCyoiSGw3tyN88QelZe45Gf2aZQ=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIWOD7tWZ1t0um3+FGXO27vN0sQywvJAWl7qi+tFvpc5a7 q3N7R4dpSwMYlwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCKaqgz/Ey9vmrmW99ze48sS 4++9m1k4bffn+S8XNbkd27ks/+5UzWsM/+sf6Rhf05EUTWdzD5p3P9tE8Y5RWuK58zdmMvy+8YF RnB0A X-Mailer: git-send-email 2.51.0.268.g9569e192d0-goog Message-ID: <20250828102202.1849035-33-ardb+git@google.com> Subject: [PATCH v7 09/22] 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 , Kevin Loughlin , Tom Lendacky , Josh Poimboeuf , Peter Zijlstra , Nikunj A Dadhania 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-startup.c | 11 ++--- arch/x86/coco/sev/core.c | 47 +++++++++----------- arch/x86/include/asm/sev-internal.h | 16 ------- 4 files changed, 28 insertions(+), 59 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index dffe607e6d8b..de73da526577 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 u64 boot_svsm_caa_pa; - -struct svsm_ca *svsm_get_caa(void) -{ - /* The decompressor is mapped 1:1 so VA =3D=3D PA */ - return (struct svsm_ca *)boot_svsm_caa_pa; -} - -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-startup.c b/arch/x86/boot/startup/se= v-startup.c index 8009a37d53c1..b0fc63f8dee1 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -50,9 +50,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. @@ -153,7 +150,9 @@ void __head early_snp_set_memory_private(unsigned long = vaddr, unsigned long padd unsigned long npages) { struct psc_desc d =3D { - SNP_PAGE_STATE_PRIVATE, svsm_get_caa(), svsm_get_caa_pa() + SNP_PAGE_STATE_PRIVATE, + rip_rel_ptr(&boot_svsm_ca_page), + boot_svsm_caa_pa }; =20 /* @@ -176,7 +175,9 @@ void __head early_snp_set_memory_shared(unsigned long v= addr, unsigned long paddr unsigned long npages) { struct psc_desc d =3D { - SNP_PAGE_STATE_SHARED, svsm_get_caa(), svsm_get_caa_pa() + SNP_PAGE_STATE_SHARED, + rip_rel_ptr(&boot_svsm_ca_page), + boot_svsm_caa_pa }; =20 /* diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index a833b2b31d3d..9782ebe30675 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -46,6 +46,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 rip_rel_ptr(&boot_svsm_ca_page); +} + +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 @@ -1312,7 +1331,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_ca_page; =20 per_cpu(svsm_caa, cpu) =3D caa; per_cpu(svsm_caa_pa, cpu) =3D __pa(caa); @@ -1366,32 +1386,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 9ff824540b48..f98f080410ad 100644 --- a/arch/x86/include/asm/sev-internal.h +++ b/arch/x86/include/asm/sev-internal.h @@ -62,22 +62,6 @@ DECLARE_PER_CPU(u64, svsm_caa_pa); =20 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 rip_rel_ptr(&boot_svsm_ca_page); -} - -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.51.0.268.g9569e192d0-goog