From nobody Mon Oct 6 11:55:36 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.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 425802C158E for ; Tue, 22 Jul 2025 07:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169394; cv=none; b=PF4XvlvZZbLN4tqzqV06vhbtLS/MBIfLqz2sZBt5o3o6heB0poaIdpVY1EBIe7xYDEvc1fviMij8pVDX1OzUQ25D38YizZB866Rog9utS22ZS+KwTcDMIyRqOYQ06ABFeGkcfzeIBmxJbYeUnRtJqfLvNtZJBA0oYWZY0sf/z/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169394; c=relaxed/simple; bh=pNlYdSPWJSc2Sjd1Rg21bRbL7xz44gMJD1OntgWPAFc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=G+pGqYgNGMWbB/cSV3p0FMFPae7Y9TgvnTgzZLY8EI1LLeyODdyU+NQYNzl6oy4dbwYn4P9QCIZdqXcO84OzrDopRaQVp53ox/cHSdmr2WSAnLcu9cziLHW/3BCbc8KPztJ5Eaz+lFYM2uCZFyyMSXUVkkHE41AaYT46+kdoUZ0= 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=DddsU1bt; arc=none smtp.client-ip=209.85.128.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="DddsU1bt" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-451d7de4ae3so28899675e9.2 for ; Tue, 22 Jul 2025 00:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169391; x=1753774191; 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=MU+D/CPMPjJsRbMsZGElOxQGyy4+8B4ya3pOCdnZVkw=; b=DddsU1btgLrPImySguIp4FJTtD/zN8/Eqb+E7NBdC5Tqiiq0CzbBFcfHAelRANRv/1 YDVn7zLM9zTa2RnFWtxhb/jBZJ48wT51ifTYccwHuZjNev+Inb3tq80UrrH+EZwQ0zxI xLvXLP9ajX1DBDyT8pGvPYug4Sx8SmLZy3OPySuEz7P9uvW8vTh3dl1FxElRh9Atbqe3 038fomoQG0IBIdhjWDvkBoWQz7Pa1L1Yu4paQDUYmCaz2bcvLmn+Qwty5ZPNWe9cAow+ R+NN1u4BT01rrhjzavh+i/z9ZTOE9TpU6FHNDeIzcqPPXpZvPZb+0PzjuyHRy/Akfibj /SHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169391; x=1753774191; 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=MU+D/CPMPjJsRbMsZGElOxQGyy4+8B4ya3pOCdnZVkw=; b=c1k9dnqqjDv9SGn5BMSfoocwLUcEKnOWocwX8WdKU7jkBDYrarjFoarrKBisAG+oZs FodHaqW2e4UCSulYuoS2dQEqbUqa1PRYK5F2hkzcKvHsgWkTUgtg45Ahs3+9ze0B+3sj yZuOPdQyMqwHHSTAVmoXJdl0Zq+rmtCtuipsL+JsWWI4p2G89wICArFGNpLXX5bi4Qrb 70t2raL7y/fZlLaFMBLdE5ejrMyuv2rDFfQh8VnOW0BMGEVEoBwhnKGEb6u+quWTZv1U l5SpmbtK69OqsjRyBXgPmBofbuJbnd81RnUTj6lLA2a2q7j/ZYrEZ+uMxZUIX+PjQium 7FQA== X-Gm-Message-State: AOJu0Ywemr5iop3ypx4AsXXFl5V5WbCuOYVHR0JcLod4wr1o3l3RJiLE kQ4SSEY7dtyBLKL9EKWlXE//M0gkrm3U5XrhuILkhiozGs7jy2w+GJe9IzKAJBRH6GGPPQbvsA/ FjEu4F0xQZc0PLbBnkOgwnPRHBrQpN6pvNCi6BStNdRvgvFEyr5SeGOEMwwLCWJiTdMXG5lTus1 1KZQ4c/wOGE3a5TphkSKLKuy3VEAgBaq/yaw== X-Google-Smtp-Source: AGHT+IGOnO1RjG2/8oG3w56s9VfKH34J95TpqenGdctnfrw8bldh+tHmzXbH7YzHpE2LScTfkRPrIikt X-Received: from wmbeq12.prod.google.com ([2002:a05:600c:848c:b0:456:c7c:3165]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e8e:b0:456:1b8b:b8ab with SMTP id 5b1f17b1804b1-4563b8fca24mr154363935e9.30.1753169390664; Tue, 22 Jul 2025 00:29:50 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:10 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=7420; i=ardb@kernel.org; h=from:subject; bh=d/TVkAXlOWDHbewpJxXD5/3KvG5R7cnCMDZ8fMf9M4g=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPeNkTzdt/pR1P0EpfzvWOa9nORrS4H38JYxxrxY8LFq hETj//tKGVhEONikBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABN5d5KRYVGznudLHlsvUZOH ymu95bvtHbaL7JAI6ef6/OlAvq/jPYa/Ugv5Gla867rEFz6jKGkHc42S9I9qaQ22oycvrbnPr8D DBQA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-25-ardb+git@google.com> Subject: [PATCH v6 01/22] x86/sev: Separate MSR and GHCB based snp_cpuid() via a callback 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 There are two distinct callers of snp_cpuid(): one where the MSR protocol is always used, and one where the GHCB page based interface is always used. The snp_cpuid() logic does not care about the distinction, which only matters at a lower level. But the fact that it supports both interfaces means that the GHCB page based logic is pulled into the early startup code where PA to VA conversions are problematic, given that it runs from the 1:1 mapping of memory. So keep snp_cpuid() itself in the startup code, but factor out the hypervisor calls via a callback, so that the GHCB page handling can be moved out. Code refactoring only - no functional change intended. Signed-off-by: Ard Biesheuvel Reviewed-by: Tom Lendacky --- arch/x86/boot/startup/sev-shared.c | 59 ++++---------------- arch/x86/coco/sev/vc-shared.c | 49 +++++++++++++++- arch/x86/include/asm/sev.h | 3 +- 3 files changed, 61 insertions(+), 50 deletions(-) diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 7a706db87b93..a1e211e0000c 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -342,44 +342,7 @@ static int __sev_cpuid_hv_msr(struct cpuid_leaf *leaf) return ret; } =20 -static int __sev_cpuid_hv_ghcb(struct ghcb *ghcb, struct es_em_ctxt *ctxt,= struct cpuid_leaf *leaf) -{ - u32 cr4 =3D native_read_cr4(); - int ret; - - ghcb_set_rax(ghcb, leaf->fn); - ghcb_set_rcx(ghcb, leaf->subfn); - - if (cr4 & X86_CR4_OSXSAVE) - /* Safe to read xcr0 */ - ghcb_set_xcr0(ghcb, xgetbv(XCR_XFEATURE_ENABLED_MASK)); - else - /* xgetbv will cause #UD - use reset value for xcr0 */ - ghcb_set_xcr0(ghcb, 1); - - ret =3D sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_CPUID, 0, 0); - if (ret !=3D ES_OK) - return ret; - - if (!(ghcb_rax_is_valid(ghcb) && - ghcb_rbx_is_valid(ghcb) && - ghcb_rcx_is_valid(ghcb) && - ghcb_rdx_is_valid(ghcb))) - return ES_VMM_ERROR; =20 - leaf->eax =3D ghcb->save.rax; - leaf->ebx =3D ghcb->save.rbx; - leaf->ecx =3D ghcb->save.rcx; - leaf->edx =3D ghcb->save.rdx; - - return ES_OK; -} - -static int sev_cpuid_hv(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct= cpuid_leaf *leaf) -{ - return ghcb ? __sev_cpuid_hv_ghcb(ghcb, ctxt, leaf) - : __sev_cpuid_hv_msr(leaf); -} =20 /* * This may be called early while still running on the initial identity @@ -484,21 +447,21 @@ snp_cpuid_get_validated_func(struct cpuid_leaf *leaf) return false; } =20 -static void snp_cpuid_hv(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struc= t cpuid_leaf *leaf) +static void snp_cpuid_hv_msr(void *ctx, struct cpuid_leaf *leaf) { - if (sev_cpuid_hv(ghcb, ctxt, leaf)) + if (__sev_cpuid_hv_msr(leaf)) sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID_HV); } =20 static int __head -snp_cpuid_postprocess(struct ghcb *ghcb, struct es_em_ctxt *ctxt, - struct cpuid_leaf *leaf) +snp_cpuid_postprocess(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf), + void *ctx, struct cpuid_leaf *leaf) { struct cpuid_leaf leaf_hv =3D *leaf; =20 switch (leaf->fn) { case 0x1: - snp_cpuid_hv(ghcb, ctxt, &leaf_hv); + cpuid_fn(ctx, &leaf_hv); =20 /* initial APIC ID */ leaf->ebx =3D (leaf_hv.ebx & GENMASK(31, 24)) | (leaf->ebx & GENMASK(23,= 0)); @@ -517,7 +480,7 @@ snp_cpuid_postprocess(struct ghcb *ghcb, struct es_em_c= txt *ctxt, break; case 0xB: leaf_hv.subfn =3D 0; - snp_cpuid_hv(ghcb, ctxt, &leaf_hv); + cpuid_fn(ctx, &leaf_hv); =20 /* extended APIC ID */ leaf->edx =3D leaf_hv.edx; @@ -565,7 +528,7 @@ snp_cpuid_postprocess(struct ghcb *ghcb, struct es_em_c= txt *ctxt, } break; case 0x8000001E: - snp_cpuid_hv(ghcb, ctxt, &leaf_hv); + cpuid_fn(ctx, &leaf_hv); =20 /* extended APIC ID */ leaf->eax =3D leaf_hv.eax; @@ -586,8 +549,8 @@ snp_cpuid_postprocess(struct ghcb *ghcb, struct es_em_c= txt *ctxt, * Returns -EOPNOTSUPP if feature not enabled. Any other non-zero return v= alue * should be treated as fatal by caller. */ -int __head -snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid_leaf *l= eaf) +int __head snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf), + void *ctx, struct cpuid_leaf *leaf) { const struct snp_cpuid_table *cpuid_table =3D snp_cpuid_get_table(); =20 @@ -621,7 +584,7 @@ snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, s= truct cpuid_leaf *leaf) return 0; } =20 - return snp_cpuid_postprocess(ghcb, ctxt, leaf); + return snp_cpuid_postprocess(cpuid_fn, ctx, leaf); } =20 /* @@ -648,7 +611,7 @@ void __head do_vc_no_ghcb(struct pt_regs *regs, unsigne= d long exit_code) leaf.fn =3D fn; leaf.subfn =3D subfn; =20 - ret =3D snp_cpuid(NULL, NULL, &leaf); + ret =3D snp_cpuid(snp_cpuid_hv_msr, NULL, &leaf); if (!ret) goto cpuid_done; =20 diff --git a/arch/x86/coco/sev/vc-shared.c b/arch/x86/coco/sev/vc-shared.c index 2c0ab0fdc060..b4688f69102e 100644 --- a/arch/x86/coco/sev/vc-shared.c +++ b/arch/x86/coco/sev/vc-shared.c @@ -409,15 +409,62 @@ static enum es_result vc_handle_ioio(struct ghcb *ghc= b, struct es_em_ctxt *ctxt) return ret; } =20 +static int __sev_cpuid_hv_ghcb(struct ghcb *ghcb, struct es_em_ctxt *ctxt,= struct cpuid_leaf *leaf) +{ + u32 cr4 =3D native_read_cr4(); + int ret; + + ghcb_set_rax(ghcb, leaf->fn); + ghcb_set_rcx(ghcb, leaf->subfn); + + if (cr4 & X86_CR4_OSXSAVE) + /* Safe to read xcr0 */ + ghcb_set_xcr0(ghcb, xgetbv(XCR_XFEATURE_ENABLED_MASK)); + else + /* xgetbv will cause #UD - use reset value for xcr0 */ + ghcb_set_xcr0(ghcb, 1); + + ret =3D sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_CPUID, 0, 0); + if (ret !=3D ES_OK) + return ret; + + if (!(ghcb_rax_is_valid(ghcb) && + ghcb_rbx_is_valid(ghcb) && + ghcb_rcx_is_valid(ghcb) && + ghcb_rdx_is_valid(ghcb))) + return ES_VMM_ERROR; + + leaf->eax =3D ghcb->save.rax; + leaf->ebx =3D ghcb->save.rbx; + leaf->ecx =3D ghcb->save.rcx; + leaf->edx =3D ghcb->save.rdx; + + return ES_OK; +} + +struct cpuid_ctx { + struct ghcb *ghcb; + struct es_em_ctxt *ctxt; +}; + +static void snp_cpuid_hv_ghcb(void *p, struct cpuid_leaf *leaf) +{ + struct cpuid_ctx *ctx =3D p; + + if (__sev_cpuid_hv_ghcb(ctx->ghcb, ctx->ctxt, leaf)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID_HV); +} + static int vc_handle_cpuid_snp(struct ghcb *ghcb, struct es_em_ctxt *ctxt) { + struct cpuid_ctx ctx =3D { ghcb, ctxt }; struct pt_regs *regs =3D ctxt->regs; struct cpuid_leaf leaf; int ret; =20 leaf.fn =3D regs->ax; leaf.subfn =3D regs->cx; - ret =3D snp_cpuid(ghcb, ctxt, &leaf); + ret =3D snp_cpuid(snp_cpuid_hv_ghcb, &ctx, &leaf); if (!ret) { regs->ax =3D leaf.eax; regs->bx =3D leaf.ebx; diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 89075ff19afa..9086b1ff1fdc 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -552,7 +552,8 @@ struct cpuid_leaf { u32 edx; }; =20 -int snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid_lea= f *leaf); +int snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf), + void *ctx, struct cpuid_leaf *leaf); =20 void __noreturn sev_es_terminate(unsigned int set, unsigned int reason); enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 BC2462C15B3 for ; Tue, 22 Jul 2025 07:29:53 +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=1753169395; cv=none; b=E8CGjOJrp0CFOjVkSEkfZ5GIyreZ+7w8V1vp3zV3ME8MxHUF3qxutjK1vJSyPXcuFtL98UsdSwtp1S6yXqItLURFJLZgHFg+xfF9KIJfTyATomVl1Wif3BLTNyuDiJMD57UV8FNUuxZSIcb4KN9YRJA2OF/1g8QbcX+hWj0zwnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169395; c=relaxed/simple; bh=JUHAkipg3EAWRigg95o0oDZv/aTDkXQTohagQF+Jgqw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EH11eB5uiyyGVOs5ZBYhZw1LlPnwj31Sr7prOisqUHFXpFQPVM2btD7baMWP5cvi5q4+q3MrrKLNPsiIH3CRcHn/E8b2EvWjaJIhQfOeVN3zlOjp5K5bFJgkLbARuzK3Y+XItT6SEETte3uoozgyLDc1rrXfGON6V4BNhTLVMTM= 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=CxxPdHVr; 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="CxxPdHVr" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3a4eeed54c2so3313261f8f.3 for ; Tue, 22 Jul 2025 00:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169392; x=1753774192; 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=Z3StoCFGTVKHcmu3it2Teel6mdHgsbdfG3fJy5aNQEI=; b=CxxPdHVrrqxBk9L2KutKAFrv6poY818kv4s0/pG9FYMo7bhbd/up62tk2tR8fKIoIl G+G81Eza+eLMUJRdbZcaOywLSI4Snp0JE/wvnCBBsvzjY+HM+QtbUntEN+ep/i7QCziD 4ULY9CFWMilV3A3fEYkjYuAeO+N5vqRT4ixytUcEwCNSmJv21UYm1P4C9/LwepUPE099 I7auX07tbZY4hrTruTV6oroVrODDZddPF64lVNHvXbJH54ntGoTgC2GuDESz8ZEBeKDe j9M08DRjR6x1PPIpdfWbrO5pMDQdY4tl895WpO3QUmqRaWH12QSx8gBR9JaSnSpiZFcO PzqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169392; x=1753774192; 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=Z3StoCFGTVKHcmu3it2Teel6mdHgsbdfG3fJy5aNQEI=; b=cnwTsCM2wEkvBV2akt/wa4wDDfpjmf74Q2wMxGBqyhaSydhDrlOa0B8ZePZ67QGoJO M+qPBZu6ctQ7CUMZCU0AxcfX1HpoDFWKXRr7hlVDjYG9M+Poj/aGwhGpsyiPdNlFdism xK43r8vH4MOnYnRLtDccT7BiGgSPckgEEfj7WVeMhghGItSyeEESzYiRn7C42EE7PPtC XNfnCeQRRgcv7NrE1bgfwz6YIO8HpOyzSNiYpd06424NXY8g02W7Mg94Aa/zxjF9RYoP rervEJQBW76L5k0ItEGQPt6/9ItYE7y945kYTJj2RjUUPA9ZlFgwL5yjrQyy+kXIfEIM wtzw== X-Gm-Message-State: AOJu0YyN6tEu0vcWbKug9gSaJO2VlOgqC3fadGIXW30Epv2JusWgoo/F t9YpXXMH2ZluPFYZqDQGm+Ve+RfYMI5zLnHvWoTkI8v+7jbLFFENqfODRYQpotpGyXVicw+fOa4 aSD/M2ymOAZMdt5bZKUYmpkvebks+tmrqago8HN/j/g8TkpMpQ0r0Zw2Hh1olj38kuYwsO0zibV aD2TmhRStWnbZhxTSKIZfa5UPtWrMAK1Q2Zg== X-Google-Smtp-Source: AGHT+IEA8ROGNkNmSHtQT4zFRMHm9eM6qEUhvSlk0z+MCALyHBYlA2/EZonoCvsLaHf3lJAKRK7RcgfX X-Received: from wrnl8.prod.google.com ([2002:adf:e9c8:0:b0:3a5:75f:1fb7]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5d0c:0:b0:3b6:463:d886 with SMTP id ffacd0b85a97d-3b60e4ccea6mr20386959f8f.20.1753169391932; Tue, 22 Jul 2025 00:29:51 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:11 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=2215; i=ardb@kernel.org; h=from:subject; bh=cO87Xko990PxM0uCuqTN+gjd/OGjzTrbKtnIRx9uufk=; b=kA0DAAoWMG4JVi59LVwByyZiAGh/PVmhjv/xfnUVNnQmz3R4nT1oRIf0snLyTiTfh9k8oGqx4 Yh1BAAWCgAdFiEEEJv97rnLkRp9Q5odMG4JVi59LVwFAmh/PVkACgkQMG4JVi59LVzEggEAxPdz v4I5KJTZA1I8yjO2+ZZHz07pRMqeDB7XZCcFJM0A/0qLymr+h8gmCBl/Ei3vA7pZ3aAhdS0XQ2X DPTO9RSkF X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-26-ardb+git@google.com> Subject: [PATCH v6 02/22] x86/sev: Use MSR protocol for remapping SVSM calling area 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 As the preceding code comment already indicates, remapping the SVSM calling area occurs long before the GHCB page is configured, and so calling svsm_perform_call_protocol() is guaranteed to result in a call to svsm_perform_msr_protocol(). So just call the latter directly. This allows most of the GHCB based API infrastructure to be moved out of the startup code in a subsequent patch. Signed-off-by: Ard Biesheuvel Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Tom Lendacky --- arch/x86/boot/startup/sev-shared.c | 11 +++++++++++ arch/x86/boot/startup/sev-startup.c | 5 ++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index a1e211e0000c..4b958d03834b 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -724,6 +724,17 @@ static void __head setup_cpuid_table(const struct cc_b= lob_sev_info *cc_info) } } =20 +static int __head svsm_call_msr_protocol(struct svsm_call *call) +{ + int ret; + + do { + ret =3D svsm_perform_msr_protocol(call); + } while (ret =3D=3D -EAGAIN); + + return ret; +} + static void __head svsm_pval_4k_page(unsigned long paddr, bool validate) { struct svsm_pvalidate_call *pc; diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index 0b7e3b950183..8412807a865c 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -295,7 +295,6 @@ static __head struct cc_blob_sev_info *find_cc_blob(str= uct boot_params *bp) static __head void svsm_setup(struct cc_blob_sev_info *cc_info) { struct svsm_call call =3D {}; - int ret; u64 pa; =20 /* @@ -325,8 +324,8 @@ static __head void svsm_setup(struct cc_blob_sev_info *= cc_info) call.caa =3D svsm_get_caa(); call.rax =3D SVSM_CORE_CALL(SVSM_CORE_REMAP_CA); call.rcx =3D pa; - ret =3D svsm_perform_call_protocol(&call); - if (ret) + + if (svsm_call_msr_protocol(&call)) sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_CA_REMAP_FAIL); =20 boot_svsm_caa =3D (struct svsm_ca *)pa; --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.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 A5C9E2C15B5 for ; Tue, 22 Jul 2025 07:29:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169396; cv=none; b=USyGBiDiFlbAp81gBVljN4tDli/+6I6+me5N40K/kYkXDmhbpEQ5NrZ9O3mLMm1flJbOYJugPnFdKuDQquiGWsWjsKbo8Ar0qckN5X0KaSI9ZAv0b8+Ip4M7msjTEfxxj4r1+9W408yjJBfBoYyQbfGQqhZjyPhJWpqnYSFeBjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169396; c=relaxed/simple; bh=EWWd5cHpjrNbMBSNP1ciIHw/g0kHLDH9rKssUQ1iAoQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HI76sghmdK2CP06Xbk2QLyaIDz6DUtijeoFNGDnG8+7oPwEat3SNWe0e6/SS10WCRjPsYz7xv4XC3fa+hkuJaLp0v4pX4mREym/SuNTvIbNqj2CoPDkUiVY99ZSdwTkGdGgX7e7S1ZqD4t9mGu9k+ADaaR9EXBVW/682D/VcQbI= 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=ctAkEImU; arc=none smtp.client-ip=209.85.128.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="ctAkEImU" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-455e9e09afeso22566195e9.2 for ; Tue, 22 Jul 2025 00:29:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169393; x=1753774193; 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=1chRYU4FzgQvRn+5SDUrYs6JkTXrZgQrTSya3WLFvLA=; b=ctAkEImUNZP0jK/6+ABmXR5EkfRc2cohw9kG3GvnIP27zrnwf0QIhv8iXZFJWRvp89 bgjwVj053AzeGmA8yEe0B1o3QAR4CkM2AXel7QBrc1nJg0A4FCY8VcTUQiXUb18FZol2 oIKMrcUrBvDcsKe2i4xqMozHwV2R495RJqegs9qEgGxPdaHWqAPg1rP0G2qkuTVy7Mef J+P/187cAK6Zn+yWz9TlDGk1f7ckOxj5S1lSHlb1hmeeKOIQXP+TWBkD8kVLsHsbEj/V hhbN8aqoKXnGCPb3FTAE/TNCSjTJ4s62lCXQCtzi/22l1JYzs/XWecOiJUmsaU8U0L8J m/zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169393; x=1753774193; 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=1chRYU4FzgQvRn+5SDUrYs6JkTXrZgQrTSya3WLFvLA=; b=dbwutQLc2JERWXKvQxEEoFqjt/0GSH0plzj5pDoab39mjXs+5qm/dexcx3oQFUPGO8 JYb1F7w3KDxTq2uipZWfn1OLX77BP5NUooTbITtZFqQ32Mg0/2xJLF6RxLyb840rasjX qDKS0ZVzDE8X9p0UF5EkjbCNorNbxkZiCryiyKOWyX1LAvidEEUplbxO1I9jKjSo/aEN lJd7upcszIK9jVTlTI+FFn03Krk7+8hfkIv2hJKHbItdUdF5ljhvNbCWrzEEEg/CD0An EENfgZoHcBt1EuYBaa/xuYJuE3r4AcQHrAMK+PC1Faia8Ibm16JEUAY1vP5rSia7BsMc O/PA== X-Gm-Message-State: AOJu0YzOOajpjK5+s7kE+oZPwErJKiPknHoLQjQIPOXbcG2drlyCzTLd xer6jxK5k2oVja/U66CtFsqIbKoBfdccJtbNG7sCYdK9ANEzObkRO9U2+sPKWD0ViiENtO/w3va EzkwKNwLx5yYN/EfOedpZjXLC+sBWYLpc0mWy+V5D8J4zNfhlT8/bxR/lLj8KeixKLgZzFCtDR6 smIo3k/b+O9jG6iqg2MQB1PPNV+8efW8UAAw== X-Google-Smtp-Source: AGHT+IELfZOomDJMkNnSn4FhZMs27VHLSAvBqMJeqptoxBknSUKVJkwBRLuzEaxbIMum6F1Q6VbUs2h8 X-Received: from wmbdr7.prod.google.com ([2002:a05:600c:6087:b0:455:fdc1:e6]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:190e:b0:456:173c:8a53 with SMTP id 5b1f17b1804b1-4562e330eb7mr272404165e9.2.1753169392961; Tue, 22 Jul 2025 00:29:52 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:12 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=2785; i=ardb@kernel.org; h=from:subject; bh=5QW2Sku5zKlevp2pwL0Rqd9e3Xe6wKAp+z+ISnuyQ60=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPeNs7tk/XepHt3fVZK7Tj+u+PViwKrKXc0Z79oD9R4u n47Q51URykLgxgXg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjIZk+G/0WcqlU3j5ydd8dj Y1DroePbuOcdSvC/GPZFUvmtv0J8kSIjw0nz+pD3sZqhWVZL3Lv3LD/V/08+wv9pjtYPD4NZ1Se 0+QE= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-27-ardb+git@google.com> Subject: [PATCH v6 03/22] x86/sev: Use MSR protocol only for early SVSM PVALIDATE call 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 The early page state change API performs an SVSM call to PVALIDATE each page when running under a SVSM, and this involves either a GHCB page based call or a call based on the MSR protocol. The GHCB page based variant involves VA to PA translation of the GHCB address, and this is best avoided in the startup code, where virtual addresses are ambiguous (1:1 or kernel virtual). As this is the last remaining occurrence of svsm_perform_call_protocol() in the startup code, switch to the MSR protocol exclusively in this particular case, so that the GHCB based plumbing can be moved out of the startup code entirely in a subsequent patch. Signed-off-by: Ard Biesheuvel Reviewed-by: Tom Lendacky --- arch/x86/boot/compressed/sev.c | 20 -------------------- arch/x86/boot/startup/sev-shared.c | 9 ++++++--- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index fd1b67dfea22..b71c1ab6a282 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -50,31 +50,11 @@ u64 svsm_get_caa_pa(void) return boot_svsm_caa_pa; } =20 -int svsm_perform_call_protocol(struct svsm_call *call); - u8 snp_vmpl; =20 /* Include code for early handlers */ #include "../../boot/startup/sev-shared.c" =20 -int svsm_perform_call_protocol(struct svsm_call *call) -{ - struct ghcb *ghcb; - int ret; - - if (boot_ghcb) - ghcb =3D boot_ghcb; - else - ghcb =3D NULL; - - do { - ret =3D ghcb ? svsm_perform_ghcb_protocol(ghcb, call) - : svsm_perform_msr_protocol(call); - } while (ret =3D=3D -EAGAIN); - - return ret; -} - static bool sev_snp_enabled(void) { return sev_status & MSR_AMD64_SEV_SNP_ENABLED; diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 4b958d03834b..9a5fd194101b 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -741,7 +741,6 @@ static void __head svsm_pval_4k_page(unsigned long padd= r, bool validate) struct svsm_call call =3D {}; unsigned long flags; u64 pc_pa; - int ret; =20 /* * This can be called very early in the boot, use native functions in @@ -765,8 +764,12 @@ static void __head svsm_pval_4k_page(unsigned long pad= dr, bool validate) call.rax =3D SVSM_CORE_CALL(SVSM_CORE_PVALIDATE); call.rcx =3D pc_pa; =20 - ret =3D svsm_perform_call_protocol(&call); - if (ret) + /* + * Use the MSR protocol exclusively, so that this code is usable in + * startup code where VA/PA translations of the GHCB page's address may + * be problematic. + */ + if (svsm_call_msr_protocol(&call)) sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE); =20 native_local_irq_restore(flags); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.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 9C1CE2C325B for ; Tue, 22 Jul 2025 07:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169397; cv=none; b=YYsx4yqv0h55D9zrXf9xH9a8WYEUpCeV/rsVfRpqAdhmr1MP33WsL+SOlg//PGo8rF9XnWabv/sJMmtvRifKvZeK/Hiv04zrkoFHs4zQUE0pVXq5WFmvcphiIiKj2r2QUTdUBf1/qJsY7g8Z71zFoQmvNwMkLIELS7RTsftjU5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169397; c=relaxed/simple; bh=7vCshM9AqcDcWchmk6oN0McNjx72mT2fiuTk/2btq/0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GVgkO4AaviJ59pErH0cSdtzo01yOVAalsNnJa0GyYsidvxBi2Mi6duh6uhmnfJCFzwhtrW7xdjjV3zR40n1l0X7kKGsv0Oc10ptIDzNlN9BXY0DbTKxCX2G9kuv4l8OvLlfbVHTGwg1Sp0sOcxR7BMW06FTSoZJsJbLbadEU6Oo= 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=xLzC4cmK; arc=none smtp.client-ip=209.85.128.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="xLzC4cmK" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-455e918d690so36441115e9.1 for ; Tue, 22 Jul 2025 00:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169394; x=1753774194; 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=bLRM8tJZNrwYw9h12oKwz7c3JnI0avSh0N6ERG9kJB4=; b=xLzC4cmKYhv9LOaQY1QIuLhdtYiLYUlocbcASIDeZkpDE/2/zkLBrmTyMJ/R+pL1FW FW5xelJnDzX7BX6+eNHU4mV6nbB3hwkQeK1SzSUYml79sw1akITzxpP32zoinEAm6SfV hl2mjr+XwseJy3cQmB+ajcGCXqzNuOSWayXLNa8idBvi8Fgf36Ucfr2Z3pCoUjitNUiZ DNF7zIcqt6PC9XiyhOAK5z+rD34XpGjbwzU1mOUoHAPVitIkv16uR58J1ZGW9cs+DYD7 SnQyAqE3lrKdayJkM1IlYAtprdu2gL1qU37MzHu/dd/yPDdOFmcoJPiIsdsV+R8bK5jC 33mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169394; x=1753774194; 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=bLRM8tJZNrwYw9h12oKwz7c3JnI0avSh0N6ERG9kJB4=; b=WM33JYT+cITQwdGRDwg/f/RlYWjBhcMsGkx0dSosvID4OVDVWmOHeF4e1kZl+6Fdl0 j+SBQ5qHlXG5UAg09cO35M0Wi9pQLABicVJ159Ky+eTnmWc1a7Hb8vFpAT1jSorSkA4j w8IIF5lsiW22konjbiVEW1iqpsRL/Q310lGKotVtfoOevE2HF0y/FfG+lcT09PPr2VcX M8TEuEFBMd6R/gAJCUAArlcqS4NGy+yvWbrLesiKUt0X9YYDkVPEliJ1Kr1hjbksNsCh SDUMaadnlYT713YybixcziUQaPY1kFnlNVAxHOfUD98YvGU25wF+n7ADDIweSkgWSkoZ EFmQ== X-Gm-Message-State: AOJu0YwQjQBUwS49jI5hThxT3oa16USlueaiKLUGuakEMprATGrdjCux STAi+ejb+KQRnioy30wkhyms+dnDtBtoM13oU0Iy5KF9r4vosAqCCalNQX5qFDuKYpoWHjTyf27 tRpL5oE2iqlzFHhr26TWvi3+SlxRTg4BMr8v9nKZhI+JAMh6yu70LTe/Sx4uhXMMFJ7OxAgR6Mn 6soHdBHylr80g6ut5IWQ+IRGIk0XMlAJ6JIA== X-Google-Smtp-Source: AGHT+IEeL7axw2yiEjJd6+64L7kFT1vmPPUh4ItpiPQmLRhOlCBN4tHEyhfcoBECNf7D7yljPBxv3shZ X-Received: from wmdd25.prod.google.com ([2002:a05:600c:a219:b0:456:ddf:4040]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:590c:b0:456:e8c:325 with SMTP id 5b1f17b1804b1-458627137c7mr15268145e9.6.1753169393892; Tue, 22 Jul 2025 00:29:53 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:13 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=2885; i=ardb@kernel.org; h=from:subject; bh=gOSEACH7m/GcABV6nTbfH8lpEkMKzjPOqp9AyQqVxME=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPeNqn0QoHmnFxtuUQb/qeJFmtsnSLS3nul8uQyMB7bH ZDo7ttRysIgxsUgK6bIIjD777udpydK1TrPkoWZw8oEMoSBi1MAJhKexMhwJjbD7M8h3sMuU/r8 Or6s/pLvMqkv+d6R42U5+26wWZTvYmT4JrJmSq7wlQ2fFrzc1lXxPIwnXUf244aXtsdqZu1fEmn HAwA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-28-ardb+git@google.com> Subject: [PATCH v6 04/22] x86/sev: Run RMPADJUST on SVSM calling area page to test VMPL 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 Determining the VMPL at which the kernel runs involves performing a RMPADJUST operation on an arbitrary page of memory, and observing whether it succeeds. The use of boot_ghcb_page in the core kernel in this case is completely arbitrary, but results in the need to provide a PIC alias for it. So use boot_svsm_ca_page instead, which already needs this alias for other reasons. Signed-off-by: Ard Biesheuvel Reviewed-by: Tom Lendacky --- arch/x86/boot/compressed/sev.c | 2 +- arch/x86/boot/startup/sev-shared.c | 5 +++-- arch/x86/boot/startup/sev-startup.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index b71c1ab6a282..3628e9bddc6a 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -327,7 +327,7 @@ static bool early_snp_init(struct boot_params *bp) * running at VMPL0. The CA will be used to communicate with the * SVSM and request its services. */ - svsm_setup_ca(cc_info); + svsm_setup_ca(cc_info, rip_rel_ptr(&boot_ghcb_page)); =20 /* * Pass run-time kernel a pointer to CC info via boot_params so EFI diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 9a5fd194101b..7ac5c50722b4 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -793,7 +793,8 @@ static void __head pvalidate_4k_page(unsigned long vadd= r, unsigned long paddr, * Maintain the GPA of the SVSM Calling Area (CA) in order to utilize the = SVSM * services needed when not running in VMPL0. */ -static bool __head svsm_setup_ca(const struct cc_blob_sev_info *cc_info) +static bool __head svsm_setup_ca(const struct cc_blob_sev_info *cc_info, + void *page) { struct snp_secrets_page *secrets_page; struct snp_cpuid_table *cpuid_table; @@ -816,7 +817,7 @@ static bool __head svsm_setup_ca(const struct cc_blob_s= ev_info *cc_info) * routine is running identity mapped when called, both by the decompress= or * code and the early kernel code. */ - if (!rmpadjust((unsigned long)rip_rel_ptr(&boot_ghcb_page), RMP_PG_SIZE_4= K, 1)) + if (!rmpadjust((unsigned long)page, RMP_PG_SIZE_4K, 1)) return false; =20 /* diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index 8412807a865c..3da04a715831 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -302,7 +302,7 @@ static __head void svsm_setup(struct cc_blob_sev_info *= cc_info) * running at VMPL0. The CA will be used to communicate with the * SVSM to perform the SVSM services. */ - if (!svsm_setup_ca(cc_info)) + if (!svsm_setup_ca(cc_info, rip_rel_ptr(&boot_svsm_ca_page))) return; =20 /* --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 6C77917C224 for ; Tue, 22 Jul 2025 07:29:56 +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=1753169399; cv=none; b=XS3MYxRJDO5X/lBW7x5ch5kghpENAZTNDz76P/Yaq+60W3kntlpkv0m36a026yHURSwbb3qT+f/SfvXeCR0pTGCjQx/pTUb7ym47KqppB/NIkzWco8bawTav8J2OvbIq+H6qT0yimrZEqTzV/2n1k7CwerM60Cw46zT3z4CyzlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169399; c=relaxed/simple; bh=em05Ao0X+988Rx27r9ifMjZbhTq3sqBWRERRZTRIpeU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=m5beyCwyYdTwN0U43z79YXKIkQmvbQWmSYCBHG8UuIJr+cteAtzoCLoM43TZdWlPfBrnmK+/AXKlTOHyWl9qXkyH/n/L5KO6fDkUtN7EHTguAY2WuP0VlXweiT3nqIvUtM7su4yK5BrKwHiFV0LSrMx3FXAVicS9n+t/MZzF3Ko= 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=hjF33V3R; 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="hjF33V3R" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-456013b59c1so30891645e9.3 for ; Tue, 22 Jul 2025 00:29:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169395; x=1753774195; 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=4GnkBb4/k/vxVCLyuNfYANHPRTp0EkiPrOD+zqQUHEQ=; b=hjF33V3ROXVk+yRIy296CHTURkVWOS3rS2m4T1TJauOnLhGrIghZWDveJOElQaJWZs 8TCJanxzLJDW5VJokXAajlD2fp+SmlYwMq+O/Rj0YmR2edkLEdakqkT8l53USrZhRw3X c+gcWaDSj28a18VNtPPSb1fm/V7aM6wToliht1eHCQ+Y8gPNVYHntnukMcqAFaaiqN92 glJOZVi1E7Lro7ny4NkGZLi1pF9pWpWmsduviGf48oQeDUmJfMaf1sxP1D8T2pGetKUc jYmhs0dZbx4SNt3SBDRoBTuFJFOcUDexJJyAV6UHm+6Es6KVbve1ZGeoZe41N46Q5Doo byVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169395; x=1753774195; 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=4GnkBb4/k/vxVCLyuNfYANHPRTp0EkiPrOD+zqQUHEQ=; b=hcNIxneLJ7/Ed0tERLyXungcKhN4VJVdzZ6YnqdKFELypdlNUrRs1KlAVONyhpnr9r KMz1A9PYLJu0trldIjVlutVjs/ef94i/NJE5LEJ0TNKlFNpTzuwemgek4DSRXjzUCIuS GpQ4khkr1P8jlUhjTnWfz2svNlbO3Fkonu6KidH+8GgcMb/YtqSuPJ+rUMzSH27NlAs2 U/VU0OPi9XlAoxOaXjeyNjFs0kPYe2Nq5MF7hUJwqogl65K/TxcRODAP3c88VjhC17Qr tKsSaqxEmKgjjV4apOGi5icvqn0D9OteCQDQtHFuFnA/4yEkYBUEb40dQ3tHmx7nBXgo 1CWg== X-Gm-Message-State: AOJu0YxOpEQtmUmOu+Gj7TlE5hphqwAqLj81MExJYdawv89R2eUM0vQD zF1QhOlIUbQm0v/cweyX+Es9Z8CIZx7Xwu01qS0OO+slTl2KJ+iLv9MopQrUDy/4UUZfrGcmycT dZZXnXjjX1vXntV1HUxxugRHhN/dTktKIZG6wBMNdccxUHWOf8K9L0YO8I5QsroU2BWOyEWSSZL p5NGZJn7kOLP0W/ZbWimv3hddhkraKjyLGmg== X-Google-Smtp-Source: AGHT+IF1ZOzyF0TPi/rpHWhB80/efXDtu2QKF9n3CdneZZ8sqx9jX0TW0ddpAQ3jmhBY7S4kzjaccpRW X-Received: from wmbhj13.prod.google.com ([2002:a05:600c:528d:b0:453:7edf:24ff]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1c10:b0:456:1f09:6846 with SMTP id 5b1f17b1804b1-4562e3771e4mr179827045e9.25.1753169394897; Tue, 22 Jul 2025 00:29:54 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:14 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=18268; i=ardb@kernel.org; h=from:subject; bh=YRA/T4YmhF/V08WNebNIbBN3O2hG2Um9WdQYseKpPBc=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPeNr1cMDund4p7uUhRwz/fBTULfxQWeBhUS5zdNHW51 Ha2iw87SlkYxLgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwEQSSxgZttxPfDnV1srUQuS9 q7O0tnXmjQoPh8fXsjbxxlleVm3Yx8jwR9PObNVy2d1LLH8cXqGsp/XPyXbrvk9Rtyfw15yc3Kr JCwA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-29-ardb+git@google.com> Subject: [PATCH v6 05/22] x86/sev: Move GHCB page based HV communication out of startup 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 Both the decompressor and the core kernel implement an early #VC handler, which only deals with CPUID instructions, and full featured one, which can handle any #VC exception. The former communicates with the hypervisor using the MSR based protocol, whereas the latter uses a shared GHCB page, which is configured a bit later during the boot, when the kernel runs from its ordinary virtual mapping, rather than the 1:1 mapping that the startup code uses. Accessing this shared GHCB page from the core kernel's startup code is problematic, because it involves converting the GHCB address provided by the caller to a physical address. In the startup code, virtual to physical address translations are problematic, given that the virtual address might be a 1:1 mapped address, and such translations should therefore be avoided. This means that exposing startup code dealing with the GHCB to callers that execute from the ordinary kernel virtual mapping should be avoided too. So move all GHCB page based communication out of the startup code, now that all communication occurring before the kernel virtual mapping is up relies on the MSR protocol only. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev-handle-vc.c | 3 + arch/x86/boot/startup/sev-shared.c | 143 +------------------- arch/x86/boot/startup/sev-startup.c | 42 ------ arch/x86/coco/sev/core.c | 76 +++++++++++ arch/x86/coco/sev/vc-handle.c | 2 + arch/x86/coco/sev/vc-shared.c | 94 +++++++++++++ arch/x86/include/asm/sev-internal.h | 7 +- arch/x86/include/asm/sev.h | 11 +- 8 files changed, 190 insertions(+), 188 deletions(-) diff --git a/arch/x86/boot/compressed/sev-handle-vc.c b/arch/x86/boot/compr= essed/sev-handle-vc.c index 89dd02de2a0f..7530ad8b768b 100644 --- a/arch/x86/boot/compressed/sev-handle-vc.c +++ b/arch/x86/boot/compressed/sev-handle-vc.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 =20 #include "misc.h" +#include "error.h" #include "sev.h" =20 #include @@ -14,6 +15,8 @@ #include =20 #define __BOOT_COMPRESSED +#undef __init +#define __init =20 /* Basic instruction decoding support needed */ #include "../../lib/inat.c" diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 7ac5c50722b4..351a1ac7953f 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -13,12 +13,9 @@ =20 #ifndef __BOOT_COMPRESSED #define error(v) pr_err(v) -#define has_cpuflag(f) boot_cpu_has(f) #else #undef WARN #define WARN(condition, format...) (!!(condition)) -#undef vc_forward_exception -#define vc_forward_exception(c) panic("SNP: Hypervisor requested exceptio= n\n") #endif =20 /* @@ -39,7 +36,7 @@ u64 boot_svsm_caa_pa __ro_after_init; * * GHCB protocol version negotiated with the hypervisor. */ -static u16 ghcb_version __ro_after_init; +u16 ghcb_version __ro_after_init; =20 /* Copy of the SNP firmware's CPUID page. */ static struct snp_cpuid_table cpuid_table_copy __ro_after_init; @@ -54,16 +51,6 @@ static u32 cpuid_std_range_max __ro_after_init; static u32 cpuid_hyp_range_max __ro_after_init; static u32 cpuid_ext_range_max __ro_after_init; =20 -bool __init sev_es_check_cpu_features(void) -{ - if (!has_cpuflag(X86_FEATURE_RDRAND)) { - error("RDRAND instruction not supported - no trusted source of randomnes= s available\n"); - return false; - } - - return true; -} - void __head __noreturn sev_es_terminate(unsigned int set, unsigned int reason) { @@ -100,72 +87,7 @@ u64 get_hv_features(void) return GHCB_MSR_HV_FT_RESP_VAL(val); } =20 -void snp_register_ghcb_early(unsigned long paddr) -{ - unsigned long pfn =3D paddr >> PAGE_SHIFT; - u64 val; - - sev_es_wr_ghcb_msr(GHCB_MSR_REG_GPA_REQ_VAL(pfn)); - VMGEXIT(); - - val =3D sev_es_rd_ghcb_msr(); - - /* If the response GPA is not ours then abort the guest */ - if ((GHCB_RESP_CODE(val) !=3D GHCB_MSR_REG_GPA_RESP) || - (GHCB_MSR_REG_GPA_RESP_VAL(val) !=3D pfn)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_REGISTER); -} - -bool sev_es_negotiate_protocol(void) -{ - u64 val; - - /* Do the GHCB protocol version negotiation */ - sev_es_wr_ghcb_msr(GHCB_MSR_SEV_INFO_REQ); - VMGEXIT(); - val =3D sev_es_rd_ghcb_msr(); - - if (GHCB_MSR_INFO(val) !=3D GHCB_MSR_SEV_INFO_RESP) - return false; - - if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTOCOL_MIN || - GHCB_MSR_PROTO_MIN(val) > GHCB_PROTOCOL_MAX) - return false; - - ghcb_version =3D min_t(size_t, GHCB_MSR_PROTO_MAX(val), GHCB_PROTOCOL_MAX= ); - - return true; -} - -static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_e= m_ctxt *ctxt) -{ - u32 ret; - - ret =3D ghcb->save.sw_exit_info_1 & GENMASK_ULL(31, 0); - if (!ret) - return ES_OK; - - if (ret =3D=3D 1) { - u64 info =3D ghcb->save.sw_exit_info_2; - unsigned long v =3D info & SVM_EVTINJ_VEC_MASK; - - /* Check if exception information from hypervisor is sane. */ - if ((info & SVM_EVTINJ_VALID) && - ((v =3D=3D X86_TRAP_GP) || (v =3D=3D X86_TRAP_UD)) && - ((info & SVM_EVTINJ_TYPE_MASK) =3D=3D SVM_EVTINJ_TYPE_EXEPT)) { - ctxt->fi.vector =3D v; - - if (info & SVM_EVTINJ_VALID_ERR) - ctxt->fi.error_code =3D info >> 32; - - return ES_EXCEPTION; - } - } - - return ES_VMM_ERROR; -} - -static inline int svsm_process_result_codes(struct svsm_call *call) +int svsm_process_result_codes(struct svsm_call *call) { switch (call->rax_out) { case SVSM_SUCCESS: @@ -193,7 +115,7 @@ static inline int svsm_process_result_codes(struct svsm= _call *call) * - RAX specifies the SVSM protocol/callid as input and the return co= de * as output. */ -static __always_inline void svsm_issue_call(struct svsm_call *call, u8 *pe= nding) +void svsm_issue_call(struct svsm_call *call, u8 *pending) { register unsigned long rax asm("rax") =3D call->rax; register unsigned long rcx asm("rcx") =3D call->rcx; @@ -216,7 +138,7 @@ static __always_inline void svsm_issue_call(struct svsm= _call *call, u8 *pending) call->r9_out =3D r9; } =20 -static int svsm_perform_msr_protocol(struct svsm_call *call) +int svsm_perform_msr_protocol(struct svsm_call *call) { u8 pending =3D 0; u64 val, resp; @@ -247,63 +169,6 @@ static int svsm_perform_msr_protocol(struct svsm_call = *call) return svsm_process_result_codes(call); } =20 -static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call = *call) -{ - struct es_em_ctxt ctxt; - u8 pending =3D 0; - - vc_ghcb_invalidate(ghcb); - - /* - * Fill in protocol and format specifiers. This can be called very early - * in the boot, so use rip-relative references as needed. - */ - ghcb->protocol_version =3D ghcb_version; - ghcb->ghcb_usage =3D GHCB_DEFAULT_USAGE; - - ghcb_set_sw_exit_code(ghcb, SVM_VMGEXIT_SNP_RUN_VMPL); - ghcb_set_sw_exit_info_1(ghcb, 0); - ghcb_set_sw_exit_info_2(ghcb, 0); - - sev_es_wr_ghcb_msr(__pa(ghcb)); - - svsm_issue_call(call, &pending); - - if (pending) - return -EINVAL; - - switch (verify_exception_info(ghcb, &ctxt)) { - case ES_OK: - break; - case ES_EXCEPTION: - vc_forward_exception(&ctxt); - fallthrough; - default: - return -EINVAL; - } - - return svsm_process_result_codes(call); -} - -enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, - struct es_em_ctxt *ctxt, - u64 exit_code, u64 exit_info_1, - u64 exit_info_2) -{ - /* Fill in protocol and format specifiers */ - ghcb->protocol_version =3D ghcb_version; - ghcb->ghcb_usage =3D GHCB_DEFAULT_USAGE; - - ghcb_set_sw_exit_code(ghcb, exit_code); - ghcb_set_sw_exit_info_1(ghcb, exit_info_1); - ghcb_set_sw_exit_info_2(ghcb, exit_info_2); - - sev_es_wr_ghcb_msr(__pa(ghcb)); - VMGEXIT(); - - return verify_exception_info(ghcb, ctxt); -} - static int __sev_cpuid_hv(u32 fn, int reg_idx, u32 *reg) { u64 val; diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index 3da04a715831..fd18a00f000e 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -41,15 +41,6 @@ #include #include =20 -/* For early boot hypervisor communication in SEV-ES enabled guests */ -struct ghcb boot_ghcb_page __bss_decrypted __aligned(PAGE_SIZE); - -/* - * Needs to be in the .data section because we need it NULL before bss is - * cleared - */ -struct ghcb *boot_ghcb __section(".data"); - /* Bitmap of SEV features supported by the hypervisor */ u64 sev_hv_features __ro_after_init; =20 @@ -139,39 +130,6 @@ noinstr void __sev_put_ghcb(struct ghcb_state *state) } } =20 -int svsm_perform_call_protocol(struct svsm_call *call) -{ - struct ghcb_state state; - unsigned long flags; - struct ghcb *ghcb; - int ret; - - /* - * This can be called very early in the boot, use native functions in - * order to avoid paravirt issues. - */ - flags =3D native_local_irq_save(); - - if (sev_cfg.ghcbs_initialized) - ghcb =3D __sev_get_ghcb(&state); - else if (boot_ghcb) - ghcb =3D boot_ghcb; - else - ghcb =3D NULL; - - do { - ret =3D ghcb ? svsm_perform_ghcb_protocol(ghcb, call) - : svsm_perform_msr_protocol(call); - } while (ret =3D=3D -EAGAIN); - - if (sev_cfg.ghcbs_initialized) - __sev_put_ghcb(&state); - - native_local_irq_restore(flags); - - return ret; -} - void __head early_set_pages_state(unsigned long vaddr, unsigned long paddr, unsigned long npages, enum psc_op op) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index fc59ce78c477..15be9e52848d 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -101,6 +101,15 @@ DEFINE_PER_CPU(struct sev_es_save_area *, sev_vmsa); u8 snp_vmpl __ro_after_init; EXPORT_SYMBOL_GPL(snp_vmpl); =20 +/* For early boot hypervisor communication in SEV-ES enabled guests */ +static struct ghcb boot_ghcb_page __bss_decrypted __aligned(PAGE_SIZE); + +/* + * Needs to be in the .data section because we need it NULL before bss is + * cleared + */ +struct ghcb *boot_ghcb __section(".data"); + static u64 __init get_snp_jump_table_addr(void) { struct snp_secrets_page *secrets; @@ -154,6 +163,73 @@ static u64 __init get_jump_table_addr(void) return ret; } =20 +static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call = *call) +{ + struct es_em_ctxt ctxt; + u8 pending =3D 0; + + vc_ghcb_invalidate(ghcb); + + /* + * Fill in protocol and format specifiers. This can be called very early + * in the boot, so use rip-relative references as needed. + */ + ghcb->protocol_version =3D ghcb_version; + ghcb->ghcb_usage =3D GHCB_DEFAULT_USAGE; + + ghcb_set_sw_exit_code(ghcb, SVM_VMGEXIT_SNP_RUN_VMPL); + ghcb_set_sw_exit_info_1(ghcb, 0); + ghcb_set_sw_exit_info_2(ghcb, 0); + + sev_es_wr_ghcb_msr(__pa(ghcb)); + + svsm_issue_call(call, &pending); + + if (pending) + return -EINVAL; + + switch (verify_exception_info(ghcb, &ctxt)) { + case ES_OK: + break; + case ES_EXCEPTION: + vc_forward_exception(&ctxt); + fallthrough; + default: + return -EINVAL; + } + + return svsm_process_result_codes(call); +} + +static int svsm_perform_call_protocol(struct svsm_call *call) +{ + struct ghcb_state state; + unsigned long flags; + struct ghcb *ghcb; + int ret; + + flags =3D native_local_irq_save(); + + if (sev_cfg.ghcbs_initialized) + ghcb =3D __sev_get_ghcb(&state); + else if (boot_ghcb) + ghcb =3D boot_ghcb; + else + ghcb =3D NULL; + + do { + ret =3D ghcb ? svsm_perform_ghcb_protocol(ghcb, call) + : svsm_perform_msr_protocol(call); + } while (ret =3D=3D -EAGAIN); + + if (sev_cfg.ghcbs_initialized) + __sev_put_ghcb(&state); + + native_local_irq_restore(flags); + + return ret; +} + static inline void __pval_terminate(u64 pfn, bool action, unsigned int pag= e_size, int ret, u64 svsm_ret) { diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c index faf1fce89ed4..9a5e16f70e83 100644 --- a/arch/x86/coco/sev/vc-handle.c +++ b/arch/x86/coco/sev/vc-handle.c @@ -351,6 +351,8 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ct= xt, } =20 #define sev_printk(fmt, ...) printk(fmt, ##__VA_ARGS__) +#define error(v) +#define has_cpuflag(f) boot_cpu_has(f) =20 #include "vc-shared.c" =20 diff --git a/arch/x86/coco/sev/vc-shared.c b/arch/x86/coco/sev/vc-shared.c index b4688f69102e..9b01c9ad81be 100644 --- a/arch/x86/coco/sev/vc-shared.c +++ b/arch/x86/coco/sev/vc-shared.c @@ -409,6 +409,53 @@ static enum es_result vc_handle_ioio(struct ghcb *ghcb= , struct es_em_ctxt *ctxt) return ret; } =20 +enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt = *ctxt) +{ + u32 ret; + + ret =3D ghcb->save.sw_exit_info_1 & GENMASK_ULL(31, 0); + if (!ret) + return ES_OK; + + if (ret =3D=3D 1) { + u64 info =3D ghcb->save.sw_exit_info_2; + unsigned long v =3D info & SVM_EVTINJ_VEC_MASK; + + /* Check if exception information from hypervisor is sane. */ + if ((info & SVM_EVTINJ_VALID) && + ((v =3D=3D X86_TRAP_GP) || (v =3D=3D X86_TRAP_UD)) && + ((info & SVM_EVTINJ_TYPE_MASK) =3D=3D SVM_EVTINJ_TYPE_EXEPT)) { + ctxt->fi.vector =3D v; + + if (info & SVM_EVTINJ_VALID_ERR) + ctxt->fi.error_code =3D info >> 32; + + return ES_EXCEPTION; + } + } + + return ES_VMM_ERROR; +} + +enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, + struct es_em_ctxt *ctxt, + u64 exit_code, u64 exit_info_1, + u64 exit_info_2) +{ + /* Fill in protocol and format specifiers */ + ghcb->protocol_version =3D ghcb_version; + ghcb->ghcb_usage =3D GHCB_DEFAULT_USAGE; + + ghcb_set_sw_exit_code(ghcb, exit_code); + ghcb_set_sw_exit_info_1(ghcb, exit_info_1); + ghcb_set_sw_exit_info_2(ghcb, exit_info_2); + + sev_es_wr_ghcb_msr(__pa(ghcb)); + VMGEXIT(); + + return verify_exception_info(ghcb, ctxt); +} + static int __sev_cpuid_hv_ghcb(struct ghcb *ghcb, struct es_em_ctxt *ctxt,= struct cpuid_leaf *leaf) { u32 cr4 =3D native_read_cr4(); @@ -549,3 +596,50 @@ static enum es_result vc_handle_rdtsc(struct ghcb *ghc= b, =20 return ES_OK; } + +void snp_register_ghcb_early(unsigned long paddr) +{ + unsigned long pfn =3D paddr >> PAGE_SHIFT; + u64 val; + + sev_es_wr_ghcb_msr(GHCB_MSR_REG_GPA_REQ_VAL(pfn)); + VMGEXIT(); + + val =3D sev_es_rd_ghcb_msr(); + + /* If the response GPA is not ours then abort the guest */ + if ((GHCB_RESP_CODE(val) !=3D GHCB_MSR_REG_GPA_RESP) || + (GHCB_MSR_REG_GPA_RESP_VAL(val) !=3D pfn)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_REGISTER); +} + +bool __init sev_es_check_cpu_features(void) +{ + if (!has_cpuflag(X86_FEATURE_RDRAND)) { + error("RDRAND instruction not supported - no trusted source of randomnes= s available\n"); + return false; + } + + return true; +} + +bool sev_es_negotiate_protocol(void) +{ + u64 val; + + /* Do the GHCB protocol version negotiation */ + sev_es_wr_ghcb_msr(GHCB_MSR_SEV_INFO_REQ); + VMGEXIT(); + val =3D sev_es_rd_ghcb_msr(); + + if (GHCB_MSR_INFO(val) !=3D GHCB_MSR_SEV_INFO_RESP) + return false; + + if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTOCOL_MIN || + GHCB_MSR_PROTO_MIN(val) > GHCB_PROTOCOL_MAX) + return false; + + ghcb_version =3D min_t(size_t, GHCB_MSR_PROTO_MAX(val), GHCB_PROTOCOL_MAX= ); + + return true; +} diff --git a/arch/x86/include/asm/sev-internal.h b/arch/x86/include/asm/sev= -internal.h index 3dfd306d1c9e..6199b35a82e4 100644 --- a/arch/x86/include/asm/sev-internal.h +++ b/arch/x86/include/asm/sev-internal.h @@ -2,7 +2,6 @@ =20 #define DR7_RESET_VALUE 0x400 =20 -extern struct ghcb boot_ghcb_page; extern u64 sev_hv_features; extern u64 sev_secrets_pa; =20 @@ -80,7 +79,8 @@ static __always_inline u64 svsm_get_caa_pa(void) return boot_svsm_caa_pa; } =20 -int svsm_perform_call_protocol(struct svsm_call *call); +enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt = *ctxt); +void vc_forward_exception(struct es_em_ctxt *ctxt); =20 static inline u64 sev_es_rd_ghcb_msr(void) { @@ -97,9 +97,6 @@ static __always_inline void sev_es_wr_ghcb_msr(u64 val) native_wrmsr(MSR_AMD64_SEV_ES_GHCB, low, high); } =20 -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); =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 9086b1ff1fdc..c38d3910c887 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -503,6 +503,7 @@ static inline int pvalidate(unsigned long vaddr, bool r= mp_psize, bool validate) } =20 void setup_ghcb(void); +void snp_register_ghcb_early(unsigned long paddr); void early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr, unsigned long npages); void early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr, @@ -540,8 +541,6 @@ static __always_inline void vc_ghcb_invalidate(struct g= hcb *ghcb) __builtin_memset(ghcb->save.valid_bitmap, 0, sizeof(ghcb->save.valid_bitm= ap)); } =20 -void vc_forward_exception(struct es_em_ctxt *ctxt); - /* I/O parameters for CPUID-related helpers */ struct cpuid_leaf { u32 fn; @@ -552,15 +551,23 @@ struct cpuid_leaf { u32 edx; }; =20 +int svsm_perform_msr_protocol(struct svsm_call *call); int snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf), void *ctx, struct cpuid_leaf *leaf); =20 +void svsm_issue_call(struct svsm_call *call, u8 *pending); +int svsm_process_result_codes(struct svsm_call *call); + void __noreturn sev_es_terminate(unsigned int set, unsigned int reason); enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, struct es_em_ctxt *ctxt, u64 exit_code, u64 exit_info_1, u64 exit_info_2); =20 +bool sev_es_negotiate_protocol(void); +bool sev_es_check_cpu_features(void); + +extern u16 ghcb_version; extern struct ghcb *boot_ghcb; =20 #else /* !CONFIG_AMD_MEM_ENCRYPT */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 7ED512D5A01 for ; Tue, 22 Jul 2025 07:29:57 +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=1753169399; cv=none; b=WsUBIXHTjWHRR8fhUMjYTMXU8MBSA1z37us042NOdKOyMEsCWAPQS49aU+2FwQ5I7nFGbh3CxuZS1BBVGmY6g7vH250aSEfdd0ayRfP1bbMvlmKb/VcSW+RyZcVX8o6xxYSunVg/FA1SkB21QYue7FsAtp98DKe6HT2UIetdg+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169399; c=relaxed/simple; bh=Y0IHeIoLe1evACqd65dSCkfGFmBNRWv0i5KiuUj/qMw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UxKFAVJdciqD4io7jPGjcpDqf/vsJd2bN5QKuZ+aE1BKrj5xk3xZAYOKr3aYXBaZ4zA+3fUeIHIncgLEDas1OHAYHZIm0qoEgd3y6lNeZxTWsrrHNDJxseZSEHAKRrivvb6leGxA/HT3CPU0cjxunVX3BVYhQts5EJ7tuQsrwYs= 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=KJz/4K2H; 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="KJz/4K2H" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-455e9daab1cso10838955e9.1 for ; Tue, 22 Jul 2025 00:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169396; x=1753774196; 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=MJQ2mIdZYhey+l1UllIfx9Zu+COU5laKSxAdjnGmRT0=; b=KJz/4K2HfVgwz1hS0hPG0rXXZRJwdQNBw8I1SqUGYR4nMMWsfzbVGZH6k5q8fxxuFg whwxMVBpv+DqhrLD0m9pe+lJzgrtc7CNMcHlkPajBWmXnMwuxdK/7TvuSkQqxPz5Hqg7 Ru4NDhJdo+bKk66KE9Ce+geTRUewSRgSu+M9R8BWAd08srl0+GGlJ+IQOllwA3BxPQG5 Jwwzh8PKWkDZ8ZD7ubLWrdtO+9vAPfPeL4wyziujEgc+xgsverwxKIhlx4mYDqPanVGd TK/FgeYVqSFSmMS2BKwTAvctbar6qPRtwmVEuyr5WgU0hB1FEhxScJ/ibMF9Q0rA7qVv D5xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169396; x=1753774196; 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=MJQ2mIdZYhey+l1UllIfx9Zu+COU5laKSxAdjnGmRT0=; b=epJQyBLoGV9w6M2hpiiQsosI0nV/ELYafdX/hXH5mRT35YjwedhFvp8hwq1kDC/1ta 49GBibYTWny3M1vqOJVyKmQbxUWk2vn4iTNAlPyqNBfcn2ovjyJ7pI/utlJyoJ339Xaq aflZcjfKl1o9bDgV1SXPKfG8J8wKW8FiVdTZmoyCUiqrtNE9A2Jzh/zXepYG2mY2QMgI SYnFA7GFPGo6n7CRg9SpPrvnKmGlKuPRJMXfsHgH5poccKwR++zwsZwLeFQ9XH1keDmt LwIgnQkTRCDgPLAKs7Z07eJzXAlek5MNmJl2C5UwWAa4v1m5IH2BJ68WCL4FTaxWPHEO uSUA== X-Gm-Message-State: AOJu0Yw11BsLWwHZoXQV399C+h9oSE3noyPNIXgG/1VzRMECoPSY+zAU dAv2Qn1+JTbYNi//hrqaBZ1DmogbODJM9DTRs5jm+9Dj8O4GxM0hEkjSyEc3/hIIJdp/X2zJ7+o nRz9VYT3vKQL8MSMmjyPUidmCRAGhi4X9VBh8tOovPFg4JEYmnUhgUIUS2cNUfjG8TaEFo05BJ5 zjK9X00fTiWpqH9vIlZEEg/HmaRPOeCiHc2g== X-Google-Smtp-Source: AGHT+IFGLXUJmOG4RcWMRNtmFE3q2mZgDQoYouEQoSm/qRTBSq3JhUWa8/05N8gyMiB61WXN1XLRTSXn X-Received: from wmbdr12.prod.google.com ([2002:a05:600c:608c:b0:456:21f4:7a98]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3491:b0:439:9b2a:1b2f with SMTP id 5b1f17b1804b1-4562e039d93mr223163365e9.3.1753169395940; Tue, 22 Jul 2025 00:29:55 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:15 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=7323; i=ardb@kernel.org; h=from:subject; bh=i+HzCacfacxHhMjJSDwButIGhq5RneNUUFLF9E79teU=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPeNud1k2vgrYnnu1r9e3d+OSvkUzxHqKOzO6Rd4Pmhn S0H96Z2lLIwiHExyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgImcuMXwz1RKSc98Tp3sBu4s R6Wv221lbzPsXrigJmnxvu3eZhw5PxkZLsxrXn3Qax7Di38pR9buu/qxZsmlQ5q1BkxF13NeFd2 z4wcA X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-30-ardb+git@google.com> Subject: [PATCH v6 06/22] x86/sev: Avoid global variable to store virtual address of SVSM area 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 The boottime SVSM calling area is used both by the startup code running from a 1:1 mapping, and potentially later on running from the ordinary kernel mapping. This SVSM calling area is statically allocated, and so its physical address doesn't change. However, its virtual address depends on the calling context (1:1 mapping or kernel virtual mapping), and even though the variable that holds the virtual address of this calling area gets updated from 1:1 address to kernel address during the boot, it is hard to reason about why this is guaranteed to be safe. So instead, take the RIP-relative address of the boottime SVSM calling area whenever its virtual address is required, and only use a global variable for the physical address. Signed-off-by: Ard Biesheuvel Reviewed-by: Tom Lendacky --- arch/x86/boot/compressed/sev.c | 5 ++--- arch/x86/boot/startup/sev-shared.c | 6 ------ arch/x86/boot/startup/sev-startup.c | 9 +++++---- arch/x86/coco/sev/core.c | 9 --------- arch/x86/include/asm/sev-internal.h | 3 +-- arch/x86/include/asm/sev.h | 2 -- arch/x86/mm/mem_encrypt_amd.c | 6 ------ 7 files changed, 8 insertions(+), 32 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 3628e9bddc6a..6c0f91d38595 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -37,12 +37,12 @@ struct ghcb *boot_ghcb; =20 #define __BOOT_COMPRESSED =20 -extern struct svsm_ca *boot_svsm_caa; extern u64 boot_svsm_caa_pa; =20 struct svsm_ca *svsm_get_caa(void) { - return boot_svsm_caa; + /* The decompressor is mapped 1:1 so VA =3D=3D PA */ + return (struct svsm_ca *)boot_svsm_caa_pa; } =20 u64 svsm_get_caa_pa(void) @@ -530,7 +530,6 @@ bool early_is_sevsnp_guest(void) =20 /* Obtain the address of the calling area to use */ boot_rdmsr(MSR_SVSM_CAA, &m); - boot_svsm_caa =3D (void *)m.q; boot_svsm_caa_pa =3D m.q; =20 /* diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 351a1ac7953f..852c8443ed1a 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -26,7 +26,6 @@ * early boot, both with identity mapped virtual addresses and proper ke= rnel * virtual addresses. */ -struct svsm_ca *boot_svsm_caa __ro_after_init; u64 boot_svsm_caa_pa __ro_after_init; =20 /* @@ -710,11 +709,6 @@ static bool __head svsm_setup_ca(const struct cc_blob_= sev_info *cc_info, if (caa & (PAGE_SIZE - 1)) sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_CAA); =20 - /* - * The CA is identity mapped when this routine is called, both by the - * decompressor code and the early kernel code. - */ - boot_svsm_caa =3D (struct svsm_ca *)caa; boot_svsm_caa_pa =3D caa; =20 /* Advertise the SVSM presence via CPUID. */ diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index fd18a00f000e..8a06f6026101 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -252,6 +252,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 {}; u64 pa; =20 @@ -272,21 +273,21 @@ static __head void svsm_setup(struct cc_blob_sev_info= *cc_info) pa =3D (u64)rip_rel_ptr(&boot_svsm_ca_page); =20 /* - * Switch over to the boot SVSM CA while the current CA is still - * addressable. There is no GHCB at this point so use the MSR protocol. + * Switch over to the boot SVSM CA while the current CA is still 1:1 + * mapped and thus addressable with VA =3D=3D PA. There is no GHCB at this + * point so use the MSR protocol. * * SVSM_CORE_REMAP_CA call: * 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; =20 if (svsm_call_msr_protocol(&call)) sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_CA_REMAP_FAIL); =20 - boot_svsm_caa =3D (struct svsm_ca *)pa; boot_svsm_caa_pa =3D pa; } =20 diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 15be9e52848d..bea67d017bf0 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -1643,15 +1643,6 @@ void sev_show_status(void) pr_cont("\n"); } =20 -void __init snp_update_svsm_ca(void) -{ - if (!snp_vmpl) - return; - - /* Update the CAA to a proper kernel address */ - boot_svsm_caa =3D &boot_svsm_ca_page; -} - #ifdef CONFIG_SYSFS static ssize_t vmpl_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) diff --git a/arch/x86/include/asm/sev-internal.h b/arch/x86/include/asm/sev= -internal.h index 6199b35a82e4..ffe4755962fe 100644 --- a/arch/x86/include/asm/sev-internal.h +++ b/arch/x86/include/asm/sev-internal.h @@ -60,7 +60,6 @@ void early_set_pages_state(unsigned long vaddr, unsigned = long paddr, DECLARE_PER_CPU(struct svsm_ca *, svsm_caa); DECLARE_PER_CPU(u64, svsm_caa_pa); =20 -extern struct svsm_ca *boot_svsm_caa; extern u64 boot_svsm_caa_pa; =20 static __always_inline struct svsm_ca *svsm_get_caa(void) @@ -68,7 +67,7 @@ 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; + return rip_rel_ptr(&boot_svsm_ca_page); } =20 static __always_inline u64 svsm_get_caa_pa(void) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index c38d3910c887..bc1d7b32e4f4 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -519,7 +519,6 @@ void snp_accept_memory(phys_addr_t start, phys_addr_t e= nd); u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); void sev_show_status(void); -void snp_update_svsm_ca(void); int prepare_pte_enc(struct pte_enc_desc *d); void set_pte_enc_mask(pte_t *kpte, unsigned long pfn, pgprot_t new_prot); void snp_kexec_finish(void); @@ -600,7 +599,6 @@ static inline void snp_accept_memory(phys_addr_t start,= phys_addr_t end) { } static inline u64 snp_get_unsupported_features(u64 status) { return 0; } static inline u64 sev_get_status(void) { return 0; } static inline void sev_show_status(void) { } -static inline void snp_update_svsm_ca(void) { } static inline int prepare_pte_enc(struct pte_enc_desc *d) { return 0; } static inline void set_pte_enc_mask(pte_t *kpte, unsigned long pfn, pgprot= _t new_prot) { } static inline void snp_kexec_finish(void) { } diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index faf3a13fb6ba..2f8c32173972 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -536,12 +536,6 @@ void __init sme_early_init(void) x86_init.resources.dmi_setup =3D snp_dmi_setup; } =20 - /* - * Switch the SVSM CA mapping (if active) from identity mapped to - * kernel mapped. - */ - snp_update_svsm_ca(); - if (sev_status & MSR_AMD64_SNP_SECURE_TSC) setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); } --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 8B2DA2D94A3 for ; Tue, 22 Jul 2025 07:29:58 +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=1753169400; cv=none; b=qJ7Q+FaSomuVT2xYyAbJjABHMeetdw/o5gLz2Bl1Pw/lh/CVPAu0Je8unzNahm8g8aFj6PM1lgiKC9Th8jF7FehUm0j6eVnG7sq12+J+jYVC6x1A2EA4Uwz54tP9HT0gmFqdft3M4mtpW4FuJ+BCklUEUUKWMVVodermXQuSkAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169400; c=relaxed/simple; bh=ldtqyx89ZKOrYRSSDmGEqyM2yCsaGPrtjSFBO5qwqQ4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HOPoAuT220N7Mduu01bcrFGf4PkYfKvuZg4tlSYF1ZsdkPvcsUbBM3KWglwEa+k/QpvjkcMeOsU/5AB/N5Tua+RX/Lg4vyVNofIHQjksZ99O+v9+C0tI5E+x4t+h7lGN1wEPl3Rks/HyOwtUJ07ybKBN77SkxJW7fBfz3dndK8E= 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=SyTSAmiH; 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="SyTSAmiH" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-3b604541741so3876698f8f.3 for ; Tue, 22 Jul 2025 00:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169397; x=1753774197; 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=AnIyIP+8xABAcHb3glWQZIu3Z146M5cuD0atVAZd87Y=; b=SyTSAmiHws6dulDU5gTLNNGWlZbUxBzynJu8243bRURfi8pl1CMzVPrbR2EcXl6fIN mNcnh9dz7DxGEpn/N2XKTmlnTQlogRfSzknIQp31LUW21EqxEbDCyNdn1myWzBp9udsj z2ITFcd6FBCtIER2HX4QwKKRB4LI6anylippsUeJsLkYKU+yjgxYr0fubT31BdkHLZt0 YGoBttnlm/uvu6njjdrsXb8R2bDEdfvUa59qc69SDDwTFhgph9QHT6q/SoGEmW1OYCdN BVCR6+xU+5RdKqZ2xlhDjqUoIeuGbtqsyYo+XB/HlPAfQIf2547Emhz0uzzXGzCR5Yrn L4dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169397; x=1753774197; 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=AnIyIP+8xABAcHb3glWQZIu3Z146M5cuD0atVAZd87Y=; b=eK9//k6SVkgwMfhfwSoKjNQ8dUVsfBIvAnbGoYfEFsKA8lYW+KT3DslTgArHrQvuUy 5pQB9N2T7pJ093eUTa1Xswyyk4mYtUi48QHO+1XKCs7sd6GtcBEsi0zYl4GDpPMiiNYH TcJD2SLMnoZ/LyrXmILGmZDGs62dm3srdtbUsN8cmeFLjbyzppsgevYKE3IhBJteOZ+a KrPVMC4nomYA1HaGACwgObLkV/PBE0+BLpxwyiuIjvxPU62IHu/PJGWTmv+0x+3MYHd6 xpPO30r+JKV7w0XYfVLF8Puz6sv+rX6B0nBzI7L6fAAPs6uiaivVhNyaj927+teXiXJk b/hA== X-Gm-Message-State: AOJu0YznIcjfgWlMHWw8GkBglLYV1YGsWxeq4eGMyS1It69EzlNCP3Mx EqkHNeHOdMuoarucT3uk70zdv2II9b9cgv/tTa+D84puZE3hoiZXdOOSwkmX6KrLd2zAh95uk8i 2Y946sTSCfYXgZ/xCZg5jSnb7Ahu136VBXYCX+wVawFWRGBZ12+2NXlsbNZsvn779ndb5P0prFe AdpkrhYoaV3/F/uoppKbhvGKQLDqAfd3aQ6A== X-Google-Smtp-Source: AGHT+IEQ6PzJYCYSF1PTyhHuT7n5DPmk0+BNDw8KvvW3YZpez5kUzMtjspN7IAXcd29BHkrYgi+N5IG0 X-Received: from wmcq4.prod.google.com ([2002:a05:600c:c104:b0:456:1ba0:c8ac]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2dc6:b0:3a6:e6c3:6d95 with SMTP id ffacd0b85a97d-3b60e523e58mr16260822f8f.41.1753169396852; Tue, 22 Jul 2025 00:29:56 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:16 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=5890; i=ardb@kernel.org; h=from:subject; bh=Xu3nJVJSBr+OOcY1i2lptxUFYocnqV8hTyJhBKvJwXs=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPetjA88pCy2hqGazLZv19LJifOt1JIfcj+esHStjJd/ ZuXN07tKGVhEONikBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABOZvIyR4UTHPKWmLSJfj9+K XDQ79jPL/hdrp815ZS+Y/eNM9PxIBmFGhubz+ZdWLXRvvMI+K0z7/H7BCPsbQvcfTWT3NKu9rto cyw0A X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-31-ardb+git@google.com> Subject: [PATCH v6 07/22] x86/sev: Share implementation of MSR-based page state change 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 Both the decompressor and the SEV startup code implement the exact same sequence for invoking the MSR based communication protocol to effectuate a page state change. Before tweaking the internal APIs used in both versions, merge them and share them so those tweaks are only needed in a single place. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev.c | 40 ++------------------ arch/x86/boot/startup/sev-shared.c | 35 +++++++++++++++++ arch/x86/boot/startup/sev-startup.c | 29 +------------- 3 files changed, 39 insertions(+), 65 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 6c0f91d38595..f714235d3222 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -60,46 +60,12 @@ static bool sev_snp_enabled(void) return sev_status & MSR_AMD64_SEV_SNP_ENABLED; } =20 -static void __page_state_change(unsigned long paddr, enum psc_op op) -{ - u64 val, msr; - - /* - * If private -> shared then invalidate the page before requesting the - * state change in the RMP table. - */ - if (op =3D=3D SNP_PAGE_STATE_SHARED) - pvalidate_4k_page(paddr, paddr, false); - - /* Save the current GHCB MSR value */ - msr =3D sev_es_rd_ghcb_msr(); - - /* Issue VMGEXIT to change the page state in RMP table. */ - sev_es_wr_ghcb_msr(GHCB_MSR_PSC_REQ_GFN(paddr >> PAGE_SHIFT, op)); - VMGEXIT(); - - /* Read the response of the VMGEXIT. */ - val =3D sev_es_rd_ghcb_msr(); - if ((GHCB_RESP_CODE(val) !=3D GHCB_MSR_PSC_RESP) || GHCB_MSR_PSC_RESP_VAL= (val)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC); - - /* Restore the GHCB MSR value */ - sev_es_wr_ghcb_msr(msr); - - /* - * Now that page state is changed in the RMP table, validate it so that i= t is - * consistent with the RMP entry. - */ - if (op =3D=3D SNP_PAGE_STATE_PRIVATE) - pvalidate_4k_page(paddr, paddr, true); -} - void snp_set_page_private(unsigned long paddr) { if (!sev_snp_enabled()) return; =20 - __page_state_change(paddr, SNP_PAGE_STATE_PRIVATE); + __page_state_change(paddr, paddr, SNP_PAGE_STATE_PRIVATE); } =20 void snp_set_page_shared(unsigned long paddr) @@ -107,7 +73,7 @@ void snp_set_page_shared(unsigned long paddr) if (!sev_snp_enabled()) return; =20 - __page_state_change(paddr, SNP_PAGE_STATE_SHARED); + __page_state_change(paddr, paddr, SNP_PAGE_STATE_SHARED); } =20 bool early_setup_ghcb(void) @@ -133,7 +99,7 @@ bool early_setup_ghcb(void) void snp_accept_memory(phys_addr_t start, phys_addr_t end) { for (phys_addr_t pa =3D start; pa < end; pa +=3D PAGE_SIZE) - __page_state_change(pa, SNP_PAGE_STATE_PRIVATE); + __page_state_change(pa, pa, SNP_PAGE_STATE_PRIVATE); } =20 void sev_es_shutdown_ghcb(void) diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 852c8443ed1a..1da1afa8677a 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -653,6 +653,41 @@ static void __head pvalidate_4k_page(unsigned long vad= dr, unsigned long paddr, } } =20 +static void __head __page_state_change(unsigned long vaddr, unsigned long = paddr, + enum psc_op op) +{ + u64 val, msr; + + /* + * If private -> shared then invalidate the page before requesting the + * state change in the RMP table. + */ + if (op =3D=3D SNP_PAGE_STATE_SHARED) + pvalidate_4k_page(vaddr, paddr, false); + + /* Save the current GHCB MSR value */ + msr =3D sev_es_rd_ghcb_msr(); + + /* Issue VMGEXIT to change the page state in RMP table. */ + sev_es_wr_ghcb_msr(GHCB_MSR_PSC_REQ_GFN(paddr >> PAGE_SHIFT, op)); + VMGEXIT(); + + /* Read the response of the VMGEXIT. */ + val =3D sev_es_rd_ghcb_msr(); + if ((GHCB_RESP_CODE(val) !=3D GHCB_MSR_PSC_RESP) || GHCB_MSR_PSC_RESP_VAL= (val)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC); + + /* Restore the GHCB MSR value */ + sev_es_wr_ghcb_msr(msr); + + /* + * Now that page state is changed in the RMP table, validate it so that i= t is + * consistent with the RMP entry. + */ + if (op =3D=3D SNP_PAGE_STATE_PRIVATE) + pvalidate_4k_page(vaddr, paddr, true); +} + /* * Maintain the GPA of the SVSM Calling Area (CA) in order to utilize the = SVSM * services needed when not running in VMPL0. diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index 8a06f6026101..5eb7d939ebd3 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -135,7 +135,6 @@ early_set_pages_state(unsigned long vaddr, unsigned lon= g paddr, unsigned long npages, enum psc_op op) { unsigned long paddr_end; - u64 val; =20 vaddr =3D vaddr & PAGE_MASK; =20 @@ -143,37 +142,11 @@ early_set_pages_state(unsigned long vaddr, unsigned l= ong paddr, paddr_end =3D paddr + (npages << PAGE_SHIFT); =20 while (paddr < paddr_end) { - /* Page validation must be rescinded before changing to shared */ - if (op =3D=3D SNP_PAGE_STATE_SHARED) - pvalidate_4k_page(vaddr, paddr, false); - - /* - * Use the MSR protocol because this function can be called before - * the GHCB is established. - */ - sev_es_wr_ghcb_msr(GHCB_MSR_PSC_REQ_GFN(paddr >> PAGE_SHIFT, op)); - VMGEXIT(); - - val =3D sev_es_rd_ghcb_msr(); - - if (GHCB_RESP_CODE(val) !=3D GHCB_MSR_PSC_RESP) - goto e_term; - - if (GHCB_MSR_PSC_RESP_VAL(val)) - goto e_term; - - /* Page validation must be performed after changing to private */ - if (op =3D=3D SNP_PAGE_STATE_PRIVATE) - pvalidate_4k_page(vaddr, paddr, true); + __page_state_change(vaddr, paddr, op); =20 vaddr +=3D PAGE_SIZE; paddr +=3D PAGE_SIZE; } - - return; - -e_term: - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC); } =20 void __head early_snp_set_memory_private(unsigned long vaddr, unsigned lon= g paddr, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 904422D3EFF for ; Tue, 22 Jul 2025 07:29:59 +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=1753169401; cv=none; b=Rwidx5dAXz/rQN1/DQblSoiwCcX2VaFXzuDr6KIqH9+8wS6PnkhidD6Jes5gJyNUzIO1S9+tOcecwXmMO3+sfHEfC/NO6rn+kkZ6+aiVnc3cGkcl5JuorBTrII99En9D/pJnQgqgKKydflCNsOXnBJmtZQp/T+N47nVyjY8clYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169401; c=relaxed/simple; bh=4fA/3jUJ6zj7k5uvYOOJQ0pRZCt2PaXp+jR/8krEmo8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WKq1GG4PvtifBNlIDirtzbTgbFqeEQCW+KJvQptcFMXnUSzF4xKOREwNc0/2il3TRKEVgJB6gu5fy4tEz8oj+3FLJVBK6xwFUF2NXkoVWalkgcmf15hyfiUH8e3F3vQnS7Ak5hnpGBUTSgWusK0CeX8zvkuq/k6/hJtQe+b2vcM= 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=jmfAN8GL; 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="jmfAN8GL" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3b5fe97af5fso2160593f8f.2 for ; Tue, 22 Jul 2025 00:29:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169398; x=1753774198; 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=QL6EcrfjzsGpyxx4RdNqdRqQCUuAPIThcF8MuxlBsx8=; b=jmfAN8GLSTQG7TrsPGq8hh3PGgUUgRftSIohmEwUyWKNTkvhW8yrFHHR2BrqUgzXEa fCXAZrQx1yDhm23SqpOvWM/ZtPaMhwownsq2e2eW3ionojbJDeTTMdxcziNEKGXZEkbu 1AVT0/GHpUgR87Np4gdvr97Wd+QPXiuvk1One4R2jDhUcPfDPnPF/Kx+kDywPhhkBfLZ wxYp7WqUwgI5rcF5l95LoSinU6o7fHUpoOBXRemxt1AyNadQIo3hcraNJSDvSdC2OuGT oGxmV+ZhDur4+GNquiw5cWAbIjQJqm+gLO5szYitV1g4ec7PYSSpegx2Y6vJvJEagLBB 1vmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169398; x=1753774198; 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=QL6EcrfjzsGpyxx4RdNqdRqQCUuAPIThcF8MuxlBsx8=; b=UZpKEuJU+8QySshXjFEwJGOBT+SLQB1yHbG36514YmkrJp5v4gTN/DDsjwkC4TNb30 xcHf1OEsYI5F+6jLoNC/vNQX1BHRCKmLSs/wtwI8RkpXrAuwD6VPbIVguQZpBstVB5T2 YAxzYsIKRhEGlwuykM2XWTqUaY7OQvX+9CztNGD21OF+BtiNt96eAU8k2VkYop7/QYrL ILrf9z+PG+3WLpi0pRSsWEeGUYvOGgqh+ZTOmHXMGzdaXRdAtvGJ5UMCV4UFPv/J3xs8 DoXemRcUwVI1BMQCvWz7rSIE22JtqfyPk6oYG9rzJRJZWP5hFXxg5DH5/wjFj30mhXLH yfwg== X-Gm-Message-State: AOJu0Yx1HAc0pzwtt6YJh6KWzEc8NN6zQQ4N7nJBI/E+OkiuQqII9jCK TdnZ8iEUtLMM3ZxdZh6o0IFWvAiwTqIltIEhFPCkEHg1IPMd82fZcsuxMAg85U33uAplEdw2GsY tm9rMAPOtT6+/H/oHNarXadXkO7tdIpO4u20oY1+9rw9xRnNmxnG0NHWz4SkZtZFz7n1T1hainx x4JvRkkB5wRx8AjvZdMPppjByz24r4XWWEAA== X-Google-Smtp-Source: AGHT+IE0baTcNVeiZy4pavD88v4Cu6Po7vw8UnqpAdLO4ZzSpg+xDJKOEammOnC2ugQTcaUAaNo1vUlE X-Received: from wroi16.prod.google.com ([2002:adf:f310:0:b0:3b3:9c56:9547]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:230e:b0:3b3:9cb4:43f9 with SMTP id ffacd0b85a97d-3b60e4d0135mr18273497f8f.16.1753169397888; Tue, 22 Jul 2025 00:29:57 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:17 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=7692; i=ardb@kernel.org; h=from:subject; bh=pJz4SrafHjQuXPeBtx71UqIsmXAoLC/0qFiDEMr9UIA=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPetnSqV5CO2qf/5+/8ejDfaV73RW/d/ZsNXHn31RbkP d2wXHZnRykLgxgXg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZhIZiUjw03HyrBbjG+nLi/8 vnLm1vOf9jEJSDy6cnZh4ZmXqe4sd4QYGSZ0RhRsORsckMqYlF5//cxlRj1f8xmfHiVHGOt8mNv mxQQA X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-32-ardb+git@google.com> Subject: [PATCH v6 08/22] x86/sev: Pass SVSM calling area down to early page state change API 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 The early page state change API is mostly only used very early, when only the boot time SVSM calling area is in use. However, this API is also called by the kexec finishing code, which runs very late, and potentially from a different CPU (which uses a different calling area). To avoid pulling the per-CPU SVSM calling area pointers and related SEV state into the startup code, refactor the page state change API so the SVSM calling area virtual and physical addresses can be provided by the caller. No functional change intended. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev.c | 12 +++++++++--- arch/x86/boot/startup/sev-shared.c | 17 +++++++++-------- arch/x86/boot/startup/sev-startup.c | 11 +++++++---- arch/x86/coco/sev/core.c | 3 ++- arch/x86/include/asm/sev-internal.h | 3 ++- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index f714235d3222..18b0ccf517eb 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -65,7 +65,9 @@ void snp_set_page_private(unsigned long paddr) if (!sev_snp_enabled()) return; =20 - __page_state_change(paddr, paddr, SNP_PAGE_STATE_PRIVATE); + __page_state_change(paddr, paddr, SNP_PAGE_STATE_PRIVATE, + (struct svsm_ca *)boot_svsm_caa_pa, + boot_svsm_caa_pa); } =20 void snp_set_page_shared(unsigned long paddr) @@ -73,7 +75,9 @@ void snp_set_page_shared(unsigned long paddr) if (!sev_snp_enabled()) return; =20 - __page_state_change(paddr, paddr, SNP_PAGE_STATE_SHARED); + __page_state_change(paddr, paddr, SNP_PAGE_STATE_SHARED, + (struct svsm_ca *)boot_svsm_caa_pa, + boot_svsm_caa_pa); } =20 bool early_setup_ghcb(void) @@ -99,7 +103,9 @@ bool early_setup_ghcb(void) void snp_accept_memory(phys_addr_t start, phys_addr_t end) { for (phys_addr_t pa =3D start; pa < end; pa +=3D PAGE_SIZE) - __page_state_change(pa, pa, SNP_PAGE_STATE_PRIVATE); + __page_state_change(pa, pa, SNP_PAGE_STATE_PRIVATE, + (struct svsm_ca *)boot_svsm_caa_pa, + boot_svsm_caa_pa); } =20 void sev_es_shutdown_ghcb(void) diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 1da1afa8677a..5992c82572d1 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -599,7 +599,8 @@ static int __head svsm_call_msr_protocol(struct svsm_ca= ll *call) return ret; } =20 -static void __head svsm_pval_4k_page(unsigned long paddr, bool validate) +static void __head svsm_pval_4k_page(unsigned long paddr, bool validate, + struct svsm_ca *caa, u64 caa_pa) { struct svsm_pvalidate_call *pc; struct svsm_call call =3D {}; @@ -612,10 +613,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 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 caa_pa + offsetof(struct svsm_ca, svsm_buffer); =20 pc->num_entries =3D 1; pc->cur_index =3D 0; @@ -640,12 +641,12 @@ static void __head svsm_pval_4k_page(unsigned long pa= ddr, bool validate) } =20 static void __head pvalidate_4k_page(unsigned long vaddr, unsigned long pa= ddr, - bool validate) + bool validate, struct svsm_ca *caa, u64 caa_pa) { int ret; =20 if (snp_vmpl) { - svsm_pval_4k_page(paddr, validate); + svsm_pval_4k_page(paddr, validate, caa, caa_pa); } else { ret =3D pvalidate(vaddr, RMP_PG_SIZE_4K, validate); if (ret) @@ -654,7 +655,7 @@ static void __head pvalidate_4k_page(unsigned long vadd= r, unsigned long paddr, } =20 static void __head __page_state_change(unsigned long vaddr, unsigned long = paddr, - enum psc_op op) + enum psc_op op, struct svsm_ca *caa, u64 caa_pa) { u64 val, msr; =20 @@ -663,7 +664,7 @@ static void __head __page_state_change(unsigned long va= ddr, unsigned long paddr, * state change in the RMP table. */ if (op =3D=3D SNP_PAGE_STATE_SHARED) - pvalidate_4k_page(vaddr, paddr, false); + pvalidate_4k_page(vaddr, paddr, false, caa, caa_pa); =20 /* Save the current GHCB MSR value */ msr =3D sev_es_rd_ghcb_msr(); @@ -685,7 +686,7 @@ static void __head __page_state_change(unsigned long va= ddr, unsigned long paddr, * consistent with the RMP entry. */ if (op =3D=3D SNP_PAGE_STATE_PRIVATE) - pvalidate_4k_page(vaddr, paddr, true); + pvalidate_4k_page(vaddr, paddr, true, caa, caa_pa); } =20 /* diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index 5eb7d939ebd3..22b8667310d5 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -132,7 +132,8 @@ noinstr void __sev_put_ghcb(struct ghcb_state *state) =20 void __head early_set_pages_state(unsigned long vaddr, unsigned long paddr, - unsigned long npages, enum psc_op op) + unsigned long npages, enum psc_op op, + struct svsm_ca *caa, u64 caa_pa) { unsigned long paddr_end; =20 @@ -142,7 +143,7 @@ early_set_pages_state(unsigned long vaddr, unsigned lon= g paddr, paddr_end =3D paddr + (npages << PAGE_SHIFT); =20 while (paddr < paddr_end) { - __page_state_change(vaddr, paddr, op); + __page_state_change(vaddr, paddr, op, caa, caa_pa); =20 vaddr +=3D PAGE_SIZE; paddr +=3D PAGE_SIZE; @@ -165,7 +166,8 @@ void __head early_snp_set_memory_private(unsigned long = vaddr, unsigned long padd * Ask the hypervisor to mark the memory pages as private in the RMP * table. */ - early_set_pages_state(vaddr, paddr, npages, SNP_PAGE_STATE_PRIVATE); + early_set_pages_state(vaddr, paddr, npages, SNP_PAGE_STATE_PRIVATE, + svsm_get_caa(), svsm_get_caa_pa()); } =20 void __head early_snp_set_memory_shared(unsigned long vaddr, unsigned long= paddr, @@ -181,7 +183,8 @@ void __head early_snp_set_memory_shared(unsigned long v= addr, unsigned long paddr return; =20 /* Ask hypervisor to mark the memory pages shared in the RMP table. */ - early_set_pages_state(vaddr, paddr, npages, SNP_PAGE_STATE_SHARED); + early_set_pages_state(vaddr, paddr, npages, SNP_PAGE_STATE_SHARED, + svsm_get_caa(), svsm_get_caa_pa()); } =20 /* diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index bea67d017bf0..7a86a2fe494d 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -585,7 +585,8 @@ static void set_pages_state(unsigned long vaddr, unsign= ed long npages, int op) =20 /* Use the MSR protocol when a GHCB is not available. */ if (!boot_ghcb) - return early_set_pages_state(vaddr, __pa(vaddr), npages, op); + return early_set_pages_state(vaddr, __pa(vaddr), npages, op, + svsm_get_caa(), svsm_get_caa_pa()); =20 vaddr =3D vaddr & PAGE_MASK; vaddr_end =3D vaddr + (npages << PAGE_SHIFT); diff --git a/arch/x86/include/asm/sev-internal.h b/arch/x86/include/asm/sev= -internal.h index ffe4755962fe..3b72d8217827 100644 --- a/arch/x86/include/asm/sev-internal.h +++ b/arch/x86/include/asm/sev-internal.h @@ -55,7 +55,8 @@ DECLARE_PER_CPU(struct sev_es_runtime_data*, runtime_data= ); DECLARE_PER_CPU(struct sev_es_save_area *, sev_vmsa); =20 void early_set_pages_state(unsigned long vaddr, unsigned long paddr, - unsigned long npages, enum psc_op op); + unsigned long npages, enum psc_op op, + struct svsm_ca *ca, u64 caa_pa); =20 DECLARE_PER_CPU(struct svsm_ca *, svsm_caa); DECLARE_PER_CPU(u64, svsm_caa_pa); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 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 749A22DAFB2 for ; Tue, 22 Jul 2025 07:30:00 +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=1753169402; cv=none; b=jXtJPqkqIemdjSouh4lfCwGIF85UH23RrJSpjsJd91hHIOZGtDKuQDTMqXryxoIOwo1Yc1c7y5CUC6xTn+MKTal6cuO19tXTq8+L4BgLz4wBnECz428gUT0O+Ap65BtcWXnKXWrwzu62HG3hISaXtjfHMwq4oodDt+3pFXuB9F4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169402; c=relaxed/simple; bh=F4GGrXQWJpn+IE4X0hI0Q7l6iGGha3gkPT7tK9TWOE0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NRVLYon/qm8yVo2PeS/7ydtU/Q3jvHXhbQg/uRe2LIyeHPYjYcNQzVNEqN7STpvwXVL++pLk4wVVUq9UiMSvzfyFhIcqjl+cQvIfl0PVQeC/6DHL72marHfXNVSymct3GfZAhtm1WYDXx44p9h0jDRlNfFb3Cs6qWrUwOnEpWmw= 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=q6I5RBFL; 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="q6I5RBFL" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-aef68ca533aso166279866b.2 for ; Tue, 22 Jul 2025 00:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169399; x=1753774199; 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=Dc7ioZTDG8dak/c8Dymf0TAZzxDxWJ7AYZQNsj1jaTY=; b=q6I5RBFLPMQPMCxVROf/WEGCYLEg6F0YH+TViUGUwGgea15+DB5qCj/IO7vISSCImw L1UdjQu5WH5iVQ9jyCZP07MvE9t5taf1lJZlsWh/ESLw0nQJLIHnEd2gyFU1lTllttSK N0xFrgkNob6goZTsTdkhX2/XgNYRs7kTGOrgZzIL6Yydfz6e1ahJZSk407WRhiQurm6H exVa3bWKOYtue9pcze89Q0ZkLWC7WdroOgsIiS2rbr6RpCJpa8LbxH3zQ+kONfVcCKEu JWQFuPlAVzoIyV4ejW0dz2KYEM+Oyp5LxoKouV3fA6smALK3nO9za+3yZQz74jVh2R0a tE8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169399; x=1753774199; 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=Dc7ioZTDG8dak/c8Dymf0TAZzxDxWJ7AYZQNsj1jaTY=; b=GIgbCWC9I0UCyIOsjXvdrlBjxX+k8v3c8/4GggesMnehbjbqKuUXTQO+oV5d6oa+L4 GUjBN8wA0WDAPNGiw6PC4iQHxox6eqnSx6suqq2Fl0jdJ90gMncFkU82NvYX9+H9bxq1 vudRxyznS7wfs4b/SLPL6gcuIc9iA3a4bL+c97Tzx2GuCnlAgH2nbUo8gqUO1egxMBQQ uVrXS16i88DFTwd+cFroxcNxH3iroNjWSxMuDaVb0t2Lji35yIo+2eSpsKlJ+j6BnhN/ zgebn077r9oZse+p1WUIPhqpRDxj6h6i+ep01WgiL/gWAONeuQhDLw54bpXXVxx5av4v dNTg== X-Gm-Message-State: AOJu0YzYZgXHLYAu8alx/sNvy969D6PpV+4Oupf1u4C27soq9ZFaIOpC XTabzt4G9KQPkj6xfGp969H487njdrkrhPJGV/9JQdxl3EQ7/OMzriY0ZNw1XiuQgEhJFi80vkt AnWa4HWN5jIDLTS+eHLE9qzX2w6o3ESM+mOhTEmwj5LLF4q5WGuaHPdghjWVbsGSb8g3Y3FcjBq f8l38zG76XUzShBCna+bFrazbTmmmCH+n1KA== X-Google-Smtp-Source: AGHT+IGFC3i6TV46/FHVJ7XlKvlXXseDbsOWjOBT2bwYV8b0c9a09n+NkEFxzJUxUmUh9w15L4cyCxyH X-Received: from ejczh18.prod.google.com ([2002:a17:907:e912:b0:ae9:ba12:ebd1]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:501e:b0:ae3:8c9b:bd61 with SMTP id a640c23a62f3a-aec4fa438c3mr1257714766b.12.1753169398866; Tue, 22 Jul 2025 00:29:58 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:18 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=5481; i=ardb@kernel.org; h=from:subject; bh=U5+R57w6urjcMH6V7vXc1AZ3AS7l8D6IN1d+7fzQ4zE=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPetkqz8zGn1tmMtLJM1d21qSfz2UsFeHekhusJfa164 RVj9rSjlIVBjItBVkyRRWD233c7T0+UqnWeJQszh5UJZAgDF6cATKT5CcM/zYU7F9WZWSi0z154 M0PJ6J/HTHGWQznnrv2xftvicEpVk+G/T+dj/XdKH//OfK30RFrondclc/fZ/+Uv+W223Ve6cU4 OMwA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-33-ardb+git@google.com> Subject: [PATCH v6 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 | 7 +-- arch/x86/coco/sev/core.c | 47 +++++++++----------- arch/x86/include/asm/sev-internal.h | 16 ------- 4 files changed, 24 insertions(+), 59 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 18b0ccf517eb..4bdf5595ed96 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 22b8667310d5..55fc6d0641d3 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. @@ -167,7 +164,7 @@ void __head early_snp_set_memory_private(unsigned long = vaddr, unsigned long padd * table. */ early_set_pages_state(vaddr, paddr, npages, SNP_PAGE_STATE_PRIVATE, - svsm_get_caa(), svsm_get_caa_pa()); + rip_rel_ptr(&boot_svsm_ca_page), boot_svsm_caa_pa); } =20 void __head early_snp_set_memory_shared(unsigned long vaddr, unsigned long= paddr, @@ -184,7 +181,7 @@ void __head early_snp_set_memory_shared(unsigned long v= addr, unsigned long paddr =20 /* Ask hypervisor to mark the memory pages shared in the RMP table. */ early_set_pages_state(vaddr, paddr, npages, SNP_PAGE_STATE_SHARED, - svsm_get_caa(), svsm_get_caa_pa()); + 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 7a86a2fe494d..4fe0928bc0ad 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 @@ -1287,7 +1306,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); @@ -1341,32 +1361,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 3b72d8217827..bdfe008120f3 100644 --- a/arch/x86/include/asm/sev-internal.h +++ b/arch/x86/include/asm/sev-internal.h @@ -63,22 +63,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.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 5DFF52DBF51 for ; Tue, 22 Jul 2025 07:30:01 +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=1753169403; cv=none; b=MTrIYfg4CBCJErkwD+A7SI5y7mp+yTM/HbcHGLQ542hzML5uZ0WrIo8/SftU4gSDvuFQTz4Wt/XJb0REwXh7bRG61X/DHrW/WY4XXOO3CBcmsxjGgSNlVkK4cfOKzwJOCvE1a13Qvc/VHFGkCLVu8w4IRIVCEUS+aU5akSOomgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169403; c=relaxed/simple; bh=P+SavC1Q4loaZ05B2JeU5aX7Yb4NSzAVm0w85qvgUIE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UIEMo/t4bdPXgK68+7S2YS9z6bMz52MhXMEC/S0JCxzTJ/6bMR8oqObZq0rucbwfQKjGU0OVApk30VhW0KzYXSQ4GgHNhByLbliAjIxP6Q9eLAN2kWPevgnQAuHOjN1qqvGbXWGrZP0KjNRpsFVodWebQsK034CuDUp8FDh3gQc= 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=4OUR1yOh; 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="4OUR1yOh" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3a4eb6fcd88so3265609f8f.1 for ; Tue, 22 Jul 2025 00:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169400; x=1753774200; 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=STRKiSzXX1+CE+9MYrQYA3rHLqTvbwqnLZ3WYtaLrpw=; b=4OUR1yOh3/wD3XSreFRbdSaDyvChojjHCb311ZXilj3/qqLBupRicDL3EhEiyGcbDg 4gTIQY1f1MlmrzxBWAk+qECYjazLzaJiV6qqjA6MtIcMowIqWFXediYrCNvmSTvOPnC4 nHa5on2sP08+sI0ghmomzL6mBtBS1pe7UuX+Z4zRu+SB1bzUD1+7AJjaWoclIBo/EM1U 118OoMmWO9cTqZIe70s/NO++D204x5vDZ1RgAwJbBKmMDpLPn5FKeV2irZ5DJe/+oWV9 9eXcaG4JTV6ErVUX8txrcqv5EPLuaBmD45M9cwBJESYzeQ4+0Z7v/aJ3mwM8ZzpbnFmt NPSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169400; x=1753774200; 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=STRKiSzXX1+CE+9MYrQYA3rHLqTvbwqnLZ3WYtaLrpw=; b=OkoK842hH0FaKs1CQgK3X1KTnyn1uQz5z0ZRQHCxrt/pVFw7+cMBg0DflBkKk7c9h+ GB+Cta8hfUGsWyPjKABnM3wlv4z6V9zdTj/95JdL+5YQXDEU0Q7lpp4WSdmWL+J+n3FO QXZdc4TmLJ6e8gMSJ/cczSHupNYcsajJUoHnXXdGDDwfsgtIVgiXSDnKaqapvFfANxhH d5CDBigFiFpRGTe/I/OCeJonBCstIJky+eYXKP95s+wYgKoacUq6nHLSZOrbQAz0e20L YH4vgYfJATpin7zFA8cMvtKaBuo6oskT0PQSpfRGCQs5Jcx+jOwKa/ezvzCHgquxkcpQ L6lw== X-Gm-Message-State: AOJu0YwNuB+3fldRihbDtRx5rqLPUQXcb/mWGf2NoQjfpHBGou7b5fbU qw6253XPGnD4HdFVoCQ2Lqel0y9GA3ghhOs0FyPZvnJGqt2i4tGQRpk86SI3O7r+V78oR6zYpzz awNSrgg/paeqSl+y8/49tkHYa1tv+VmI04nP9unBbxNIeSMoqs17QOMDt83fOWS6235RMTvkkos a/UBmJyVvyWn97ZYvPYw72KTuZ65fn2ATx4w== X-Google-Smtp-Source: AGHT+IGjz6zhqXhqlc8/UMaZoyjJAPocp5Myl5vQjjn+usgxw8N6Vu5vkkJMW2RGVHNzNJPvtrKIkNgw X-Received: from wrwa2.prod.google.com ([2002:a5d:53c2:0:b0:3a5:7de1:2a54]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:460b:b0:3a5:21c8:af31 with SMTP id ffacd0b85a97d-3b60e4c237emr16602272f8f.16.1753169399893; Tue, 22 Jul 2025 00:29:59 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:19 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=2029; i=ardb@kernel.org; h=from:subject; bh=G4tJuVGhrB+QDvBjEiKr0P/IsteAttDK9B09Q2K0XSU=; b=kA0DAAoWMG4JVi59LVwByyZiAGh/PX+g/nam2Ohsxh3Tt6drdPM2tZgpWjGEl6V6qivK94zT3 Ih1BAAWCgAdFiEEEJv97rnLkRp9Q5odMG4JVi59LVwFAmh/PX8ACgkQMG4JVi59LVywNAD/fiT/ WKYz9vWu3ZIIQeaOQ1//uhmkD9Mpfe0o6UvTuRoBAJ5MGLCyLPw+XvuhmhT0hySKPIRJvMRkiKS XdbYejOAG X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-34-ardb+git@google.com> Subject: [PATCH v6 10/22] x86/boot: Drop redundant RMPADJUST in SEV SVSM presence check 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 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 4bdf5595ed96..d62722dd2de1 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -392,30 +392,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.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 BE8652DCF5B for ; Tue, 22 Jul 2025 07:30:02 +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=1753169404; cv=none; b=fLcaph2EBv0yel/HQeGsu6FBVTOrJlQAJZDaQLabCPlnCCl5bAQM5BbhvELy86gVeT+tSSXxa+hmI6yEETShixOAfK46WyNOsL7l5DVeZCRQotO9cFVk8haMw92nlXt6YE00kynye5eLQ0oOq4+HyqdF4Y7MvpQLxKYpHbWC0k0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169404; c=relaxed/simple; bh=88wIbnPP1a1dLhlXMR2D52W04CjhXmRtjIuSBBT1WeQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PATZSEX3Xpxb2jjQHYOQveRfu55paU4LFeZyYkOlfxU0DVA06jchTm6EUDCqihn4VIGjd/yeYL8R16Rr1zm7oUWfsfxbR+3M1BPYqrHxfGF/EXA9i1WdZmbyUFCVAFLlBiOE+V2kwOWVQplTbMXojgzyobkhaj0K+ycCl4Mtwz0= 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=OnNX+jio; 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="OnNX+jio" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3a4eee2398bso2109822f8f.1 for ; Tue, 22 Jul 2025 00:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169401; x=1753774201; 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=AgqR5avhQu9i9Y4o0xvmYEmE5OaurZWopQxiw2YEL3s=; b=OnNX+jiokZaqpVdU1aKIN0BR4txptgQkcC1UbbEhuabFZvvq4OTIGbWS8Egu3C8R6j 8V5ySX9uHjJrXoaWthVQuG/qrcEIg7bKi8LARmxoV3Ge1VDdRxAoSkVppHjsCU8zK6bX ix6FGs5rm8c4/goBi8Vou9aYTUXMNT11nSMrcD1Nf9eiOMhhLqTo3Fn/rC63LG0lyMTZ vTprentHoy1Q5RIM0mcRQHpIHpBaWCkLL8nP5WMt3O98+G80gZaqcvJM2lGvXtmpTssR 6LOGgp++Jz+xtjGCkZ2wWv2oN2pzsRuTh6LOyIuv0tyG2UDea3/WE/HZehK+StWPavEK BXmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169401; x=1753774201; 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=AgqR5avhQu9i9Y4o0xvmYEmE5OaurZWopQxiw2YEL3s=; b=CQb2TV2DByOoqEaWvOiKth4KcgDzJLELqvO6zrfE64AwNRNwyDrPHps3+5+teWYgG9 eaBOeWyFJWniA9ByqwOvqR0DYr3W/pIz+8sBRzMGBwA03uFcFuziVK0egxDvempLWxsx g2WGeDxhOjs+z05VSt+gfAiip+0SP1kr1/A88gABZwuuX/ToB0S+Kodx8hFVJ9L2bQ/C YVlFpXnWosyiKUD+9cgULBzgIgaA9NlNEPSbTI/wOjyKHT4jfaozFR7hOGOxv/kKMW+h GGJBH55/5jJt98Ebb6dRdRUVvnyMKtHwSxyAUEB0N5To1nRn3UDchx6XG5+yYvCzYAlr Ek5w== X-Gm-Message-State: AOJu0YyYk+LsM+H9TRxv0bdUs5E6Uy76sKSK0xfykLL8enKXmAMhrthb BYcjshjfPYBxItKCnbS4K+gd3vz9mCVmaCMrHVov80dx7N0JfyRFOP8Xx3Ljc72q6s+/x5tbgep 8930kYvuz9/pSA7BFH//fbmsiAINQuTzgY+fX6kZqBeEJ9bPmywXgaazjbLKbb6/QoGnw1Dik9S HJ1QLin+jaJVgahpCpvdR+hS9I7W+78PBTUA== X-Google-Smtp-Source: AGHT+IGCqMKG4sGv9H7gbMZ1XZ+2/FhEzlXHBTMD/rugj0ALKPXeNFjqm6AE32QViBixAzLnaDHRef5G X-Received: from wrsy4.prod.google.com ([2002:a5d:4ac4:0:b0:3a5:260b:656e]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:18a4:b0:3aa:c95b:d1d9 with SMTP id ffacd0b85a97d-3b60dd643f2mr15394927f8f.6.1753169400968; Tue, 22 Jul 2025 00:30:00 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:20 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=1051; i=ardb@kernel.org; h=from:subject; bh=/aZ0V2A8zhGGvGqcdFjf+IBZLj2TZ6Tesp02RBGOQMc=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPetnmSWNjG0OSpmodPnfpsJmdVO9v7Ro+IyR6mOx6pA ZbXUg93lLIwiHExyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgImo3WL4n5ie0SD874F4qHnp nZi+R29O/5rpojvV9ejC+s0zlp6yqWT476lyaD57svt/k5YpbFcPHDweZp14d9bThI8V5cd/xK3 fyQ4A X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-35-ardb+git@google.com> Subject: [PATCH v6 11/22] x86/boot: Provide PIC aliases for 5-level paging related constants 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 Provide PIC aliases for the global variables related to 5-level paging, so that the startup code can access them in order to populate the kernel page tables. Signed-off-by: Ard Biesheuvel --- arch/x86/kernel/head64.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 533fcf5636fc..1bc40d0785ee 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -52,10 +52,13 @@ SYM_PIC_ALIAS(next_early_pgt); pmdval_t early_pmd_flags =3D __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_= NX); =20 unsigned int __pgtable_l5_enabled __ro_after_init; +SYM_PIC_ALIAS(__pgtable_l5_enabled); unsigned int pgdir_shift __ro_after_init =3D 39; EXPORT_SYMBOL(pgdir_shift); +SYM_PIC_ALIAS(pgdir_shift); unsigned int ptrs_per_p4d __ro_after_init =3D 1; EXPORT_SYMBOL(ptrs_per_p4d); +SYM_PIC_ALIAS(ptrs_per_p4d); =20 unsigned long page_offset_base __ro_after_init =3D __PAGE_OFFSET_BASE_L4; EXPORT_SYMBOL(page_offset_base); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 776052DC33A for ; Tue, 22 Jul 2025 07:30:03 +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=1753169405; cv=none; b=XUTIiBCvVhaw5lusGtD4JY6RaeWZefmoClp/ul5+9QZjkHr9Q+GhhEk7++ZToKoKkGmyiZFF0+i8jGqbekwh7/zkB0t/iD6l/k/A6KyGI+zkRw366t0ib/GrUSkFuAtdq6Br/y6jmU9FRqK7CoxV5qQRLTwntHAF2E1APQTVr1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169405; c=relaxed/simple; bh=vVDlZJWB8lTREumuuuCk8x8cUtPXtifS8mSDN5W3fHw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MLx7rgb8Pm90N2yBgBy7RYi6NtgoQeVWpgACxckbiC+jA5ZbM8CLYuayLt7xSZ32ayFED1UQBS268EB9MO5orviEJxGgEJ7nr6uOoEl3ykhGP9V6TyQn3Yple6D/qE1XDGLdPhSkhj7lJkjGqhgnq/s2QPDymf2HO2NQ5sw6RBM= 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=0D92re6O; 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="0D92re6O" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-451d30992bcso39765265e9.2 for ; Tue, 22 Jul 2025 00:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169402; x=1753774202; 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=/ssokY+T+YDq1a+CqfE2fX/+m7rLK9V2q5R+I/D2Aug=; b=0D92re6Om1ftgb/KOEPnAAddvgg0XwQm7xOeq7D2Y9DCbiTF+PgYF6hBjFANyD+gaA WCPNYYukmqyX0f4yAoXLqPP8n1RiSx84FT4uZ6io5GHBVJrkqOBQMn2iLrqhO7/sEjfj srKpfNtIDMI5sXFbcIDuWhz3NsixITzwtbcmvJo+qXZa2S2jmJHM7ALV4JlnPir7791F zotpl9taX1K+Px4S9MmaqIFHDrQ1jcyiLbehe9bqo8geG1vx8kVEDvIlSG4OfcD7tqB+ wy/IO9giIcDfulbGY0I9kv0ZMtzXx3vj0N1sydLZdPISozXnQP+6nULFY0Nq669j+NXI 4mvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169402; x=1753774202; 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=/ssokY+T+YDq1a+CqfE2fX/+m7rLK9V2q5R+I/D2Aug=; b=kUMeZbKhoMRTxbdbFsVHy3GG4Mqrvoaa7ynVncL+LBeSEPkClzGagJlaAbp1JHUhvx x7aCutBeEFK+XY2gqba25nx6cNOzcXDfv1UVDBJPnppjyMNYOTvbHamyVTnjiE2tco6c EIKmLlA+vkJ0fIlTNw6g7i74PWmHYnkNd9JXwZCKSdvyVvPp7Y5x3sL0msGqbm7t8A5N 4xXXEQoXYYVANJgU8u1zO1dgyjXejKD9o/mYiSwanTXqCeWUHLw09UKbYfehw2EJ2Qz9 WLnYro3GwoCGZTZXK3vLITYVkGBw1Y5Fl++EERPAMfHbCBFXf0iPvYaguK0xXAu/iiIy 8eSA== X-Gm-Message-State: AOJu0YybKNUOfwGUkih2PwUE/NWhNwQTOxewCwKcg/0WG6A2s+Pv7L1G UpnNe/P/kZeVvhLYSqITSHP/n3OgrPib2E7arXiOc+LBR2KAzZzzC4EYsc/BCGqjFN1Q87C4847 3dCKn5RYUVrt1gN7Ry9eIFrnx/kD8USB2h7Sn4X8UYDYuj4cwkVDRDKeYZ1Q3x++uUJ7/xuzA2a C3Opr4Q/FlVRgfR5Csb3zSckJdPSIfZ/21FA== X-Google-Smtp-Source: AGHT+IG/4zN7M//CwPnYk92e0p11tFN35Cq/WJ/jnNU/sDvvsIT38SSaLPcmjgAttXwOZXMOQ4OgAm/y X-Received: from wmbej14.prod.google.com ([2002:a05:600c:3e8e:b0:456:1bf2:2be2]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:6097:b0:43c:fdbe:4398 with SMTP id 5b1f17b1804b1-4562e37a142mr200900425e9.6.1753169401971; Tue, 22 Jul 2025 00:30:01 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:21 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=5030; i=ardb@kernel.org; h=from:subject; bh=h5zR543qP1ICC4eRdLkDvBg4EKO+Wsvsmo2bjjjiAxc=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPetuMm75QkdtZC/uq/PyoL/WZNS1fZsuDS9hkXzolPz CycbPK3o5SFQYyLQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEzk7jRGhgOlTZmbUj63mnxT WaB1YTFLeabhSjs1RZMwgbOrErNmJjP8s7IKs/2j/X+D2Rmn34lZWapvnRU5ZeOZOa4YpT3w5FV jAQA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-36-ardb+git@google.com> Subject: [PATCH v6 12/22] x86/sev: Provide PIC aliases for SEV related data objects 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 Provide PIC aliases for data objects that are shared between the SEV startup code and the SEV code that executes later. This is needed so that the confined startup code is permitted to access them. This requires some of these variables to be moved into a source file that is not part of the startup code, as the PIC alias is already implied, and exporting variables in the opposite direction is not supported. Move ghcb_version as well, but don't provide a PIC alias as it is not actually needed. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev.c | 3 ++ arch/x86/boot/startup/sev-shared.c | 19 ----------- arch/x86/boot/startup/sev-startup.c | 9 ------ arch/x86/coco/sev/core.c | 34 ++++++++++++++++++++ 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index d62722dd2de1..faa6cc2f9990 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -38,6 +38,9 @@ struct ghcb *boot_ghcb; #define __BOOT_COMPRESSED =20 u8 snp_vmpl; +u16 ghcb_version; + +u64 boot_svsm_caa_pa; =20 /* Include code for early handlers */ #include "../../boot/startup/sev-shared.c" diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 5992c82572d1..1044a50ac3d3 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -18,25 +18,6 @@ #define WARN(condition, format...) (!!(condition)) #endif =20 -/* - * SVSM related information: - * During boot, the page tables are set up as identity mapped and later - * changed to use kernel virtual addresses. Maintain separate virtual and - * physical addresses for the CAA to allow SVSM functions to be used dur= ing - * early boot, both with identity mapped virtual addresses and proper ke= rnel - * virtual addresses. - */ -u64 boot_svsm_caa_pa __ro_after_init; - -/* - * Since feature negotiation related variables are set early in the boot - * process they must reside in the .data section so as not to be zeroed - * out when the .bss section is later cleared. - * - * GHCB protocol version negotiated with the hypervisor. - */ -u16 ghcb_version __ro_after_init; - /* Copy of the SNP firmware's CPUID page. */ static struct snp_cpuid_table cpuid_table_copy __ro_after_init; =20 diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index 55fc6d0641d3..76d40e381d41 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -41,15 +41,6 @@ #include #include =20 -/* Bitmap of SEV features supported by the hypervisor */ -u64 sev_hv_features __ro_after_init; - -/* Secrets page physical address from the CC blob */ -u64 sev_secrets_pa __ro_after_init; - -/* For early boot SVSM communication */ -struct svsm_ca boot_svsm_ca_page __aligned(PAGE_SIZE); - /* * Nothing shall interrupt this code path while holding the per-CPU * GHCB. The backup GHCB is only for NMIs interrupting this path. diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 4fe0928bc0ad..be89f0a4a28f 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -46,6 +46,29 @@ #include #include =20 +/* Bitmap of SEV features supported by the hypervisor */ +u64 sev_hv_features __ro_after_init; +SYM_PIC_ALIAS(sev_hv_features); + +/* Secrets page physical address from the CC blob */ +u64 sev_secrets_pa __ro_after_init; +SYM_PIC_ALIAS(sev_secrets_pa); + +/* For early boot SVSM communication */ +struct svsm_ca boot_svsm_ca_page __aligned(PAGE_SIZE); +SYM_PIC_ALIAS(boot_svsm_ca_page); + +/* + * SVSM related information: + * During boot, the page tables are set up as identity mapped and later + * changed to use kernel virtual addresses. Maintain separate virtual and + * physical addresses for the CAA to allow SVSM functions to be used dur= ing + * early boot, both with identity mapped virtual addresses and proper ke= rnel + * virtual addresses. + */ +u64 boot_svsm_caa_pa __ro_after_init; +SYM_PIC_ALIAS(boot_svsm_caa_pa); + DEFINE_PER_CPU(struct svsm_ca *, svsm_caa); DEFINE_PER_CPU(u64, svsm_caa_pa); =20 @@ -119,6 +142,17 @@ DEFINE_PER_CPU(struct sev_es_save_area *, sev_vmsa); */ u8 snp_vmpl __ro_after_init; EXPORT_SYMBOL_GPL(snp_vmpl); +SYM_PIC_ALIAS(snp_vmpl); + +/* + * Since feature negotiation related variables are set early in the boot + * process they must reside in the .data section so as not to be zeroed + * out when the .bss section is later cleared. + * + * GHCB protocol version negotiated with the hypervisor. + */ +u16 ghcb_version __ro_after_init; +SYM_PIC_ALIAS(ghcb_version); =20 /* For early boot hypervisor communication in SEV-ES enabled guests */ static struct ghcb boot_ghcb_page __bss_decrypted __aligned(PAGE_SIZE); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.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 D0BAE2DF3E8 for ; Tue, 22 Jul 2025 07:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169409; cv=none; b=DKwqUtG2IXgjbVMCuo2E8j0gbcXKgqLCkD0r8mhfu/BDNqbApg/kUpl65J0EQ2CM9fOi5LUclMIRKwwTE96Rc7FUWTIg9MjR3f55MXE106XyS5PPl9aK58D7USbRUbNg+bpcieMnFgwMPL9IO7rixHrtsFzD4kwQFOk7No7d5Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169409; c=relaxed/simple; bh=m+AA9YnrLD0iUVWnbGpAkFXJWtq3QSsvd+u3h67S7DA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fttV+lQimyjkSJ28nsGsN0qof99Y8q322Jk+D2thVTTZOHtnBVDtKynIRHBtM+bxGwBW0mgMfCgCQeuNcCSj/5e0CCkhkSb0opWUxjZxRhusc+eYCsFJRvTXgoFwcc2H/STMVoiRIaPpypdiJIhtoBaA2KBgQWVDXiR5AARrClk= 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=sAJacNzu; arc=none smtp.client-ip=209.85.208.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="sAJacNzu" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-612b6aa7ed2so4597971a12.0 for ; Tue, 22 Jul 2025 00:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169405; x=1753774205; 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=joWJVM2i9LyAMlJmIbS+61T1iNRyCZpWQH9FF0KYFxg=; b=sAJacNzuCWHCk+nmhbHQsDmjW60540vhAz/yTFm/FEbR5RuFLPdGArevtj75BuDTE4 WyWvKYibR7BsBvhf9h4IrHg6H1qdwQ5SI/K2byGfmjKmz/6Zlq/x3e/Q2Wykpt3vZB2N DMSA2wu+K3y2zUQaP9hpzKuCebL0dsdvLoM4YIi0AYULzeTOaw0ZIUwD+3w08t+Q5xto mtSSdYTjjiY1WWRrhiH2md9vOmL9CxhuAKc2vlMGsAkLklL1TLAvUXoth40WKckVPR9H wgJjMoc6qsFVFkJ+OmBXfiYYtihAVJUAyG4IVdk9DkYYEKBQ4bc8rVcWzh/3VJyMO7NV lxQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169405; x=1753774205; 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=joWJVM2i9LyAMlJmIbS+61T1iNRyCZpWQH9FF0KYFxg=; b=M409RxgDBx1Iat4hL8UOOAIQvygS46JT10YsJj6pzlAdTnaKj3CDvNUaGhnKAKB8ww VXWvJvgWZjgzSC83H7csaZ0zXrG3wEZoxRpUe3XZSGjUZZifJ5BFE2ybNfHgBUeKeQil lyYGw7RwwqhpyChZ8G6Lyoe0Q12Cl0dmHOE1L+rpHjkH6hShNqBbevCdqT0SXGhwZ4qi aft+7ffWuVz2mEidRwFoCnDSCJybJFuuBGYKU5i96Scx1dxpxWactv6nVzbnPuVJvcS+ /kGchAtKNIkrOUsOGjX2dipYYrzfc6AwNV57GxfO122dqtm+oR7IWvQs0iOd0IBD69QN ObCA== X-Gm-Message-State: AOJu0YytAB9ZzFbRUtXHpoNZUfRlgyMg3dl/uYF0CfrWvh+cqPwwyylA S7nwVSZbVa7DoKJwhH7eARB7iFbVXRPE7pNE8tvt5uCE8rVmyU/GWaTryyZFJ7XF5FRcOOXQda1 JjN9za/KBGYeGVKRfGp8/E7ougWiWxyPciq1Q6qKMvG+8ZzHb4gYYLgDEdFNu7yEkP8aw6oU7XD /sENgqYe48UWQhW0B53WZjQNtXks5a+wEDHQ== X-Google-Smtp-Source: AGHT+IHBFkra3DT9d/Jz54hyx9X9Sbb5UtTq/QCThPQD9dIL+tW4Ej2jMl0lcTj1D0bBSsI+igZS8dIu X-Received: from edbdh15.prod.google.com ([2002:a05:6402:1d2f:b0:612:bb19:6d36]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:4407:b0:611:fdb4:1dc1 with SMTP id 4fb4d7f45d1cf-612a4d17913mr19148358a12.7.1753169402910; Tue, 22 Jul 2025 00:30:02 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:22 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=6028; i=ardb@kernel.org; h=from:subject; bh=VRS61oLaIqj8kKv/u+4je9bg+LB91FkrmM3QiYMrk/A=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPetndtuc28T9VbDA/9LDLdalZ0R/Dkasl9252F79rJP NnbnGvbUcrCIMbFICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACZyqIiR4YPexKszT2+5EL2G ecOrwD7jA3nrV4UcXswZx/Xk/ymtc/4M/+NVIl47nDwjVHtDyG93fGB/wD2BFsM3rTO89J4LPpy 4ihUA X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-37-ardb+git@google.com> Subject: [PATCH v6 13/22] x86/sev: Move __sev_[get|put]_ghcb() into separate noinstr object 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 Rename sev-nmi.c to noinstr.c, and move the get/put GHCB routines into it too, which are also annotated as 'noinstr' and suffer from the same problem as the NMI code, i.e., that GCC may ignore the __no_sanitize_address__ function attribute implied by 'noinstr' and insert KASAN instrumentation anyway. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/startup/sev-startup.c | 74 -------------------- arch/x86/coco/sev/Makefile | 8 +-- arch/x86/coco/sev/{sev-nmi.c =3D> noinstr.c} | 74 ++++++++++++++++++++ 3 files changed, 78 insertions(+), 78 deletions(-) diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index 76d40e381d41..2f7d21660cdf 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -41,83 +41,9 @@ #include #include =20 -/* - * Nothing shall interrupt this code path while holding the per-CPU - * GHCB. The backup GHCB is only for NMIs interrupting this path. - * - * Callers must disable local interrupts around it. - */ -noinstr struct ghcb *__sev_get_ghcb(struct ghcb_state *state) -{ - struct sev_es_runtime_data *data; - struct ghcb *ghcb; - - WARN_ON(!irqs_disabled()); - - data =3D this_cpu_read(runtime_data); - ghcb =3D &data->ghcb_page; - - if (unlikely(data->ghcb_active)) { - /* GHCB is already in use - save its contents */ - - if (unlikely(data->backup_ghcb_active)) { - /* - * Backup-GHCB is also already in use. There is no way - * to continue here so just kill the machine. To make - * panic() work, mark GHCBs inactive so that messages - * can be printed out. - */ - data->ghcb_active =3D false; - data->backup_ghcb_active =3D false; - - instrumentation_begin(); - panic("Unable to handle #VC exception! GHCB and Backup GHCB are already= in use"); - instrumentation_end(); - } - - /* Mark backup_ghcb active before writing to it */ - data->backup_ghcb_active =3D true; - - state->ghcb =3D &data->backup_ghcb; - - /* Backup GHCB content */ - *state->ghcb =3D *ghcb; - } else { - state->ghcb =3D NULL; - data->ghcb_active =3D true; - } - - return ghcb; -} - /* Include code shared with pre-decompression boot stage */ #include "sev-shared.c" =20 -noinstr void __sev_put_ghcb(struct ghcb_state *state) -{ - struct sev_es_runtime_data *data; - struct ghcb *ghcb; - - WARN_ON(!irqs_disabled()); - - data =3D this_cpu_read(runtime_data); - ghcb =3D &data->ghcb_page; - - if (state->ghcb) { - /* Restore GHCB from Backup */ - *ghcb =3D *state->ghcb; - data->backup_ghcb_active =3D false; - state->ghcb =3D NULL; - } else { - /* - * Invalidate the GHCB so a VMGEXIT instruction issued - * from userspace won't appear to be valid. - */ - vc_ghcb_invalidate(ghcb); - data->ghcb_active =3D false; - } -} - void __head early_set_pages_state(unsigned long vaddr, unsigned long paddr, unsigned long npages, enum psc_op op, diff --git a/arch/x86/coco/sev/Makefile b/arch/x86/coco/sev/Makefile index 342d79f0ab6a..3b8ae214a6a6 100644 --- a/arch/x86/coco/sev/Makefile +++ b/arch/x86/coco/sev/Makefile @@ -1,10 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 =20 -obj-y +=3D core.o sev-nmi.o vc-handle.o +obj-y +=3D core.o noinstr.o vc-handle.o =20 # Clang 14 and older may fail to respect __no_sanitize_undefined when inli= ning -UBSAN_SANITIZE_sev-nmi.o :=3D n +UBSAN_SANITIZE_noinstr.o :=3D n =20 # GCC may fail to respect __no_sanitize_address or __no_kcsan when inlining -KASAN_SANITIZE_sev-nmi.o :=3D n -KCSAN_SANITIZE_sev-nmi.o :=3D n +KASAN_SANITIZE_noinstr.o :=3D n +KCSAN_SANITIZE_noinstr.o :=3D n diff --git a/arch/x86/coco/sev/sev-nmi.c b/arch/x86/coco/sev/noinstr.c similarity index 61% rename from arch/x86/coco/sev/sev-nmi.c rename to arch/x86/coco/sev/noinstr.c index d8dfaddfb367..b527eafb6312 100644 --- a/arch/x86/coco/sev/sev-nmi.c +++ b/arch/x86/coco/sev/noinstr.c @@ -106,3 +106,77 @@ void noinstr __sev_es_nmi_complete(void) =20 __sev_put_ghcb(&state); } + +/* + * Nothing shall interrupt this code path while holding the per-CPU + * GHCB. The backup GHCB is only for NMIs interrupting this path. + * + * Callers must disable local interrupts around it. + */ +noinstr struct ghcb *__sev_get_ghcb(struct ghcb_state *state) +{ + struct sev_es_runtime_data *data; + struct ghcb *ghcb; + + WARN_ON(!irqs_disabled()); + + data =3D this_cpu_read(runtime_data); + ghcb =3D &data->ghcb_page; + + if (unlikely(data->ghcb_active)) { + /* GHCB is already in use - save its contents */ + + if (unlikely(data->backup_ghcb_active)) { + /* + * Backup-GHCB is also already in use. There is no way + * to continue here so just kill the machine. To make + * panic() work, mark GHCBs inactive so that messages + * can be printed out. + */ + data->ghcb_active =3D false; + data->backup_ghcb_active =3D false; + + instrumentation_begin(); + panic("Unable to handle #VC exception! GHCB and Backup GHCB are already= in use"); + instrumentation_end(); + } + + /* Mark backup_ghcb active before writing to it */ + data->backup_ghcb_active =3D true; + + state->ghcb =3D &data->backup_ghcb; + + /* Backup GHCB content */ + *state->ghcb =3D *ghcb; + } else { + state->ghcb =3D NULL; + data->ghcb_active =3D true; + } + + return ghcb; +} + +noinstr void __sev_put_ghcb(struct ghcb_state *state) +{ + struct sev_es_runtime_data *data; + struct ghcb *ghcb; + + WARN_ON(!irqs_disabled()); + + data =3D this_cpu_read(runtime_data); + ghcb =3D &data->ghcb_page; + + if (state->ghcb) { + /* Restore GHCB from Backup */ + *ghcb =3D *state->ghcb; + data->backup_ghcb_active =3D false; + state->ghcb =3D NULL; + } else { + /* + * Invalidate the GHCB so a VMGEXIT instruction issued + * from userspace won't appear to be valid. + */ + vc_ghcb_invalidate(ghcb); + data->ghcb_active =3D false; + } +} --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 6F0C42DECB4 for ; Tue, 22 Jul 2025 07:30:05 +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=1753169407; cv=none; b=gwSVAliDRvZqCFh0oBcfy0uPtpcSdwaCQ41VYZPkf7uey8OdkWbp6I/K5kfJtmGX+Z0YJIzDSJ3gzSKwsVIs3ntHbtuFjBn+RiCtn/3rnCEUIv6kcSLyI3g92t/flLjydSsnTi89qaugGDfx7zAAbKfG9n5ie+9vG8pn+rBVzaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169407; c=relaxed/simple; bh=AziSCYrqEKp3iXhsTCzhbJczPEzyYFFzm0EbdakEq+k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jlUu09rN9ZH6R1fc4PWGWNiYeIITG5peHUC/1DvYe2jcyL9BM+J0iHjByySkp+v3oL795KFocEAh0azvn6jWu7+Yf3F+Gh58EDCS1RuILhcM5qkAZglhsgprvntFfCDUHHmpNyq7NbpI5anaPAptnKmARuu+IMxETNWQDySsMsA= 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=xDQ4irDe; 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="xDQ4irDe" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-3a50816ccc6so3308738f8f.1 for ; Tue, 22 Jul 2025 00:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169404; x=1753774204; 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=mW4f9PE0jE0e9wTTI8oFMDAAeEX2PGjVbeFJW21fiSw=; b=xDQ4irDe6gaGiGIN1JIk73aO1qf4wT7LOnQUJm1cYtW0wqSe7akPvGjM16onzDcS9T 3owml4wx2yIJzREx6KcDQ22wHcgKuF6cMJLx3P/F8bmGMFFbaBNz9zmGCNszwcb6nh0H fCC4dIghKtT9BgoXBCOw8ZGrYn9/miJsD+jVWVDUnLF1en3lv0WiTHsKELGJYGrFmY8u LzFFK/t8fd/gUPq9uHze5VRMXpkF76bK6grhiCx6pnWqlZCmydx2NzDQ6WUjyWDlWkgV SWvm8xhStLaF1sFG3KHJ+TP6awkY+ERidMB2MmOeYqc+dE7k/YZe3cdveX2l7Eck8QUH 4UrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169404; x=1753774204; 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=mW4f9PE0jE0e9wTTI8oFMDAAeEX2PGjVbeFJW21fiSw=; b=NF2rkBJ5ki97d2JXFwwRwde0kNaEgPPsXdi2cuhbMwPTm2Nq17U+q1Mnj2/lrQNEnF kEZFlknxZPxTBXnYeJXfRkJQ65TMYE2dsf09mOEl6rls1j9FwN5TpUvjx3gStFh7bh7D Xe0L4gxw2y32LKzu/m5k0iHOnHNQC0Jq7egI8V8cXU4N3GuG/WH5Nm7kUalnJB645W+M T0bky7imwUEsSCF9IbvVDZRAUT9+1i7GBJ4Ay3biriBdtXLc1fSUXd+QrAuyJ2V/DT1Y mxDHmCPkaGNH3+P0TE/wch9O2Bjy4iVmAL1cUEOonPJa3Uj35XgkQznWDN4wt4SaT1Pc sjTw== X-Gm-Message-State: AOJu0YzaDQ2Yq1yy0ObYUbCtwNxvgUhmqaLycZM8ULdpx/I0b1HyoWM3 w2br8owIJ8b9AZanjoixp4GIs3tXHP8pgGI5hg34vKEBXRozroZREpoNJAD2SKGSMN5MFQbuWlo 38pId9cS5DY2H6JI0HrnTFhEegWGVx3pckBb0lN6oCbY2JOiDlIVRDqfa1r6B/p0+ILhWS2//0p SOH61UPx/6HbPnhxHaXjyKNLunA9Q4O6z/iw== X-Google-Smtp-Source: AGHT+IEqIkZaOA4ogOixIf+RDEwpmHqpgza/utnNCA+SqSYOa7J9XOgt60L+JaEZqIQWwlBBUCl7IbnY X-Received: from wmbeq12.prod.google.com ([2002:a05:600c:848c:b0:456:2437:14d6]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:adf:e19d:0:b0:3a6:f2d7:e22b with SMTP id ffacd0b85a97d-3b60e4d2a3bmr14390472f8f.18.1753169403918; Tue, 22 Jul 2025 00:30:03 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:23 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=1696; i=ardb@kernel.org; h=from:subject; bh=kOQMYaSiu+ZXQWR7MbRw268I2y+/O3YrdyRKP8LesAE=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPedpKM88n9Sbzbf+1YeWOdnNHSbVutr83/+Jjr9Feb8 59Mpy5m7ChlYRDjYpAVU2QRmP333c7TE6VqnWfJwsxhZQIZwsDFKQATabrH8E+VpXzK6RRBrWyV R6k5uQELpfobyuznpr93imm7u+rhQVVGhvVucifUTC8oiDx+eULzbbNri2CBK/ODmzEpSgxZvFf r2AA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-38-ardb+git@google.com> Subject: [PATCH v6 14/22] x86/sev: Export startup routines for later use 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 Create aliases that expose routines that are part of the startup code to other code in the core kernel, so that they can be called later as well. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/startup/exports.h | 14 ++++++++++++++ arch/x86/kernel/vmlinux.lds.S | 2 ++ 2 files changed, 16 insertions(+) diff --git a/arch/x86/boot/startup/exports.h b/arch/x86/boot/startup/export= s.h new file mode 100644 index 000000000000..01d2363dc445 --- /dev/null +++ b/arch/x86/boot/startup/exports.h @@ -0,0 +1,14 @@ + +/* + * The symbols below are functions that are implemented by the startup cod= e, + * but called at runtime by the SEV code residing in the core kernel. + */ +PROVIDE(early_set_pages_state =3D __pi_early_set_pages_state); +PROVIDE(early_snp_set_memory_private =3D __pi_early_snp_set_memory_private= ); +PROVIDE(early_snp_set_memory_shared =3D __pi_early_snp_set_memory_shared); +PROVIDE(get_hv_features =3D __pi_get_hv_features); +PROVIDE(sev_es_terminate =3D __pi_sev_es_terminate); +PROVIDE(snp_cpuid =3D __pi_snp_cpuid); +PROVIDE(snp_cpuid_get_table =3D __pi_snp_cpuid_get_table); +PROVIDE(svsm_issue_call =3D __pi_svsm_issue_call); +PROVIDE(svsm_process_result_codes =3D __pi_svsm_process_result_codes); diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 4fa0be732af1..5d5e3a95e1f9 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -535,3 +535,5 @@ xen_elfnote_entry_value =3D xen_elfnote_phys32_entry_value =3D ABSOLUTE(xen_elfnote_phys32_entry) + ABSOLUTE(pvh_start_xen - LOAD_OFFSET= ); #endif + +#include "../boot/startup/exports.h" --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.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 ACAB22DEA89 for ; Tue, 22 Jul 2025 07:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169408; cv=none; b=q18GtZ0GSQldUmjd+AHmHHyVidhWIt/Uzjxe43+AvtsaH6iNcHFDBuHQ4H7fZx8P9VCmiteIgp7153Q8lyKdZkEqc4IemguvwUIsxZusjl8ClcnlEf5RBD5ePhYILFSd9T4+dzn/yhHmA95eliT42AUYOPHl5ndOuzAg1Pwav90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169408; c=relaxed/simple; bh=MyZTAiJr+Bsb8d3CwPrhu4xTfGVOEyYfojg4l7en/cU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jhFUetMaWS5h1nP0yx0U9dOIDQnTYlAjeMEdXMUuBdIR5ryFM8OZQy5YqVOy4UpDz19bSbYd5BmMTJA6+xeWEiCkSFZ9ouZ3P3z6q7F+92U9tEPsq1KigrXOCSsk2HlFg8lLy9dw/kkW31cGD8978HQl8nP9L6/nXYulPlj5K+8= 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=u/RbT0m0; arc=none smtp.client-ip=209.85.208.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="u/RbT0m0" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-612b700c54eso3718942a12.0 for ; Tue, 22 Jul 2025 00:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169405; x=1753774205; 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=52lfpv9ab+7Fp/DJuYZoJNKtIAyZpbxccywOTdHmzlM=; b=u/RbT0m0qlPvQb7A7sOj111epPO6OCT8z1sFhSdZi1gImuowA/KNMHHOuEqce/dCuE Ox9L2Bqj5PiLyV69dPcfCgZcljiNcWEfyGVVtwfwlEm7v3M1QjsZ7eEhUfqtJRgagn0h UgtJc/5XTXAiYaKW2S+57ozuYGZ+/hSV+hM45PPNZSDJS3ohoV0t+H/vHaHD2jTXJWNP LemMESt0AhjT/t0W4mYoFnP9v0LU3Z/P0zrUr5ZauFqm4ftjtUfJw975qpMrbWHci4b8 Ms38dMyNI46nTdLAXJNMQIcsqttW358FoJQi58yA/kcchn6GaDytka0sk5welqxJqm6J i2zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169405; x=1753774205; 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=52lfpv9ab+7Fp/DJuYZoJNKtIAyZpbxccywOTdHmzlM=; b=iZ5JnhyUSFvrfbIxutChVIUouRGdQ6Lv5e6nqYOxw5zpNHr8uB0eCIGvzjf02Kqwla yMs2srgCjiBT91ipcHOClwHPgSmISlK8mJYEIpc0Df9eGddlow27sZ5h8eY03bUFLtl5 LtbYBBrJvfng4bGzYYyO15HlJgrLjwUtCjzHC2vFD9vzduHMX50DLFtZHcpsBJpkwXfo V/m7yAVuTwXBB+0NGSOmw2Fi/yMmOZDCUZ6OkpNpuOIBFfOYX2ZpDhd2hYe7xQ5b4ivB Ut0WTZGDYIZdcreNwQP2Htd2lAcBbx0nUSCG7E2AOM2YlIvzArGIF7qs0VvAFRpJ+HX1 tzyg== X-Gm-Message-State: AOJu0Yx7zN9wkFtubgnrVCdv4eP4MpQUQD2n4Jr0Mtxi7B81YhwJxbmG yHx7zoPsJHWO6/pHVy/BwKgyG5AzXgtRqMsf6BqV180sLlLjF1uNt9uUJKUgBclxrx2PWrPAs2u aJbQn4aEwT8BGdN8T1DqFqoXwybd88z939k+JblDFkVS29iecaoRZazLrSskZ61zDw9a55F8xeJ X8PP9C01EsS7iGnH//tNnPFG6E3RLkQ/bBow== X-Google-Smtp-Source: AGHT+IHy5RMb8PZS2he9xh0aZxXUWnim89SQJ5wJPxOgV1ugy/IeTIYbaDRsSQQ/sT7HMKC1Zo7aa8Ru X-Received: from edbcz18.prod.google.com ([2002:a05:6402:1cb2:b0:609:7d11:b264]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:4406:b0:60c:60f7:ec9b with SMTP id 4fb4d7f45d1cf-61285941924mr19981767a12.12.1753169404874; Tue, 22 Jul 2025 00:30:04 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:24 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=4933; i=ardb@kernel.org; h=from:subject; bh=EpqpIG8BTEB9OqQVtVUL6zLybgK4ckBL4+6u1Wlvzuc=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPedlrJK8P7+g80LhaJuQa6TbQr/ni8tvvKBK5Lfv6GT 0Vq3gl0lLIwiHExyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIn8jWZkOP3r7+ToCVKpLU77 HjD8a5hhbJCzNXHika/zExKT2KzOnmJkePU/5MoVQW3lVNHz+fUdr6aol62y/tI9L0IkvWWxs+Z GbgA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-39-ardb+git@google.com> Subject: [PATCH v6 15/22] objtool: Add action to check for absence of absolute relocations 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 The x86 startup code must not use absolute references to code or data, as it executes before the kernel virtual mapping is up. Add an action to objtool to check all allocatable sections (with the exception of __patchable_function_entries, which uses absolute references for nebulous reasons) and raise an error if any absolute references are found. Note that debug sections typically contain lots of absolute references too, but those are not allocatable so they will be ignored. Signed-off-by: Ard Biesheuvel --- tools/objtool/arch/x86/decode.c | 12 ++++++ tools/objtool/builtin-check.c | 2 + tools/objtool/check.c | 44 ++++++++++++++++++++ tools/objtool/include/objtool/arch.h | 1 + tools/objtool/include/objtool/builtin.h | 1 + 5 files changed, 60 insertions(+) diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 98c4713c1b09..0ad5cc70ecbe 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -880,3 +880,15 @@ unsigned int arch_reloc_size(struct reloc *reloc) return 8; } } + +bool arch_absolute_reloc(struct elf *elf, struct reloc *reloc) +{ + switch (reloc_type(reloc)) { + case R_X86_64_32: + case R_X86_64_32S: + case R_X86_64_64: + return true; + default: + return false; + } +} diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 80239843e9f0..0f6b197cfcb0 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -87,6 +87,7 @@ static const struct option check_options[] =3D { OPT_BOOLEAN('t', "static-call", &opts.static_call, "annotate static calls= "), OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), OPT_BOOLEAN(0 , "cfi", &opts.cfi, "annotate kernel control flow integrit= y (kCFI) function preambles"), + OPT_BOOLEAN(0 , "noabs", &opts.noabs, "reject absolute references in all= ocatable sections"), OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_= dump), =20 OPT_GROUP("Options:"), @@ -162,6 +163,7 @@ static bool opts_valid(void) opts.hack_noinstr || opts.ibt || opts.mcount || + opts.noabs || opts.noinstr || opts.orc || opts.retpoline || diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 67d76f3a1dce..c34331ec1d71 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4644,6 +4644,47 @@ static void disas_warned_funcs(struct objtool_file *= file) disas_funcs(funcs); } =20 +__weak bool arch_absolute_reloc(struct elf *elf, struct reloc *reloc) +{ + unsigned int type =3D reloc_type(reloc); + size_t sz =3D elf_addr_size(elf); + + return (sz =3D=3D 8) ? (type =3D=3D R_ABS64) : (type =3D=3D R_ABS32); +} + +static int check_abs_references(struct objtool_file *file) +{ + struct section *sec; + struct reloc *reloc; + int ret =3D 0; + + for_each_sec(file, sec) { + /* absolute references in non-loadable sections are fine */ + if (!(sec->sh.sh_flags & SHF_ALLOC)) + continue; + + /* section must have an associated .rela section */ + if (!sec->rsec) + continue; + + /* + * Special case for compiler generated metadata that is not + * consumed until after boot. + */ + if (!strcmp(sec->name, "__patchable_function_entries")) + continue; + + for_each_reloc(sec->rsec, reloc) { + if (arch_absolute_reloc(file->elf, reloc)) { + WARN("section %s has absolute relocation at offset 0x%lx", + sec->name, reloc_offset(reloc)); + ret++; + } + } + } + return ret; +} + struct insn_chunk { void *addr; struct insn_chunk *next; @@ -4777,6 +4818,9 @@ int check(struct objtool_file *file) goto out; } =20 + if (opts.noabs) + warnings +=3D check_abs_references(file); + if (opts.orc && nr_insns) { ret =3D orc_create(file); if (ret) diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index 01ef6f415adf..be33c7b43180 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -97,6 +97,7 @@ bool arch_is_embedded_insn(struct symbol *sym); int arch_rewrite_retpolines(struct objtool_file *file); =20 bool arch_pc_relative_reloc(struct reloc *reloc); +bool arch_absolute_reloc(struct elf *elf, struct reloc *reloc); =20 unsigned int arch_reloc_size(struct reloc *reloc); unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc= *table); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 6b08666fa69d..ab22673862e1 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -26,6 +26,7 @@ struct opts { bool uaccess; int prefix; bool cfi; + bool noabs; =20 /* options: */ bool backtrace; --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.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 ABF8A2E041C for ; Tue, 22 Jul 2025 07:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169409; cv=none; b=Z4b04dGAuzNLJcImdxt5XL3dBEQc1iWWnPdpwdIyahV6h5iQfUs5J9FyKErnY3m+qB+4h9AzJI2fY9hYTjF+WyfMnYpktPMC50UXZmU7zZvdCO5eOCoheughKA29lP2UpIYP9SWg3HBhGzj0ihfCy3ka5guLG7u8EiCO9gVZrbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169409; c=relaxed/simple; bh=L0nuKM1iOS5J1LrRXwl6oFJ2k3UoNAHOTrQqnHSBepc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gk6ZQJ/D9wbZYm6beXuap6BuTvpgdJ5G8OX2ygu6tB7eMhKo+tVuJwhCqxhIjY3yBhHIEsff7OTA1l02wU3TfpehQqcvlhvtqiebyEIwBi6jGYkMyYF3qNMNjaj763yF6I3sQofB1XsD1VD+XqD6Qv9STnSYQsOwMqVevS3F8gE= 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=noD/b8ju; arc=none smtp.client-ip=209.85.128.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="noD/b8ju" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-451d7de4ae3so28901105e9.2 for ; Tue, 22 Jul 2025 00:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169406; x=1753774206; 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=AJj7BKcgkJOUpVILvlutzG3sQyBRFRydGJczKsiTn/M=; b=noD/b8juAxSt6DvNWlan/K+IV1lw7QJKL0mDhBbeyQlyAP8Amed4BW/WJawuwCWgx2 Fapy2I21fOD8xIZja8uvR6MvrhxWvA87sNBJwn0LsZ38K+0hj9WvE1cQlIyPIQOLhJrg 5sXFvjW5soqygUZpdvw6Mxa/B6k76QJa09cdeVd46R0V9VtZPfi2KPTkvbp6cU3cDEpb aoyOOaIkyziUef7BKJHN+b4teY1yoxFftX9bYMXmde6lrVScgfCE0BitoXWMxK0z1dam ShlMaAPqRLY3eeZyguAV9PTBy70he9KYljz5xbCipcBnR1e1DalUUjP3YfYPjvU+KtkM g8kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169406; x=1753774206; 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=AJj7BKcgkJOUpVILvlutzG3sQyBRFRydGJczKsiTn/M=; b=M2xweWpn7VvAt5nA9CG55St3O4l/MQ62X2w+9aoBYJ8bHemeBEe0IVp5d6iSFHaBO8 GOPy9XnwnWdB92gc4Cea4XQCrxNQlcGF9XJIJK3DEhf2oyEc4bI0CATJvL2am6aOvvop Zjj5UQ+ScfE+k056uQmgchplz7ATzbsCPp5sn3XAlZXUgUc+bPpbA9qJ9Z8AwkB0hRpB RZR6zdjKn43oXutpdT9hMcA+XFGfHlFEZvaH+odw4m3mxQP61UN5y1Q9y9FMhm25yZhC HtOoDtFtho9tbUV9ZLDZmwNywQSuCN2FOCu/5b6zpPqZKTevlUxbLpwsSebe0L71stx3 h+ig== X-Gm-Message-State: AOJu0Yw6Xekw/VZH6oGk0dEIImcCSXeGKtrC0zkYRX2xksNwgODqflTg R/AryzZfN2pJ1gTDhsIR0Dlu9QEyeq1Jj+znN6MAI6JTeGA4oM2LoEi73sbHbQCcFVvofTOKWIq JpOZjREbEDGBsijUCsEcOa0j9MEat6yMM4mCL+LA0/5TcVxTAB0nq8EnMyYd0kZc6hq97u599n3 46BXUlb+d6n6d6pl8vAqSjyo6hrNK5LNgrbg== X-Google-Smtp-Source: AGHT+IGLWlgWa6RzVmCAyoMlmr3VIPZ+jJqUabm06ARqHBLvdkCPayHMIQ+HOYsB4R8ZUt+WXLNEYOV1 X-Received: from wmsp39.prod.google.com ([2002:a05:600c:1da7:b0:456:1ccb:7fbc]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:a310:b0:450:d4a6:799e with SMTP id 5b1f17b1804b1-4563c231876mr99156905e9.20.1753169406218; Tue, 22 Jul 2025 00:30:06 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:25 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=1894; i=ardb@kernel.org; h=from:subject; bh=L4jffg2+Vf1ZB+P16ZYKMMQDycf2VYvq95i2j0U/b58=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPednaFo4ujna9JaX+z4FKNR2WPIq71tO+/tuedpeOpj 6pP9vztKGVhEONikBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABPZ58XIcHmWWlK2Q+uyqnM+ /7R1OkSimm8UsscYrC7U+HB+hhNLOSND07Ivx3ktG6qfL5EoD9oWlpvVXpO19jerp6G9rdmTnPe cAA== X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-40-ardb+git@google.com> Subject: [PATCH v6 16/22] x86/boot: Check startup code for absence of absolute relocations 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 Invoke objtool on each startup code object individually to check for the absence of absolute relocations. This is needed because this code will be invoked from the 1:1 mapping of memory before those absolute virtual addresses (which are derived from the kernel virtual base address provided to the linker and possibly shifted at boot) are mapped. Only objects built under arch/x86/boot/startup/ have this restriction, and once they have been incorporated into vmlinux.o, this distinction is difficult to make. So force the invocation of objtool for each object file individually, even if objtool is deferred to vmlinux.o for the rest of the build. In the latter case, only pass --noabs and nothing else; otherwise, append it to the existing objtool command line. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/startup/Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile index b514f7e81332..32737f4ab5a8 100644 --- a/arch/x86/boot/startup/Makefile +++ b/arch/x86/boot/startup/Makefile @@ -19,6 +19,7 @@ KCOV_INSTRUMENT :=3D n =20 obj-$(CONFIG_X86_64) +=3D gdt_idt.o map_kernel.o obj-$(CONFIG_AMD_MEM_ENCRYPT) +=3D sme.o sev-startup.o +pi-objs :=3D $(patsubst %.o,$(obj)/%.o,$(obj-y)) =20 lib-$(CONFIG_X86_64) +=3D la57toggle.o lib-$(CONFIG_EFI_MIXED) +=3D efi-mixed.o @@ -28,3 +29,10 @@ lib-$(CONFIG_EFI_MIXED) +=3D efi-mixed.o # to be linked into the decompressor or the EFI stub but not vmlinux # $(patsubst %.o,$(obj)/%.o,$(lib-y)): OBJECT_FILES_NON_STANDARD :=3D y + +# +# Invoke objtool for each object individually to check for absolute +# relocations, even if other objtool actions are being deferred. +# +$(pi-objs): objtool-enabled =3D 1 +$(pi-objs): objtool-args =3D $(if $(delay-objtool),,$(objtool-args-y)) --n= oabs --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 A92482DFF17 for ; Tue, 22 Jul 2025 07:30:08 +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=1753169410; cv=none; b=penupVDizjFtsKknGSgPQ2U9GGw+DbGRZxuSf1Juh1p/SZAALqFbnebELu4yoVVSqZbN9HSssqaBJ6Lx6Nb/mqHLOpFUNlRGbRh/ARk8Q/QRaVh0iBeH4k8IDoPPxOdvWuIxj7W4NJgYPIG9Qi5lQNbsf3cNn/F+/CmTnrL3k4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169410; c=relaxed/simple; bh=AmlKbu8zJYacssviYCi6dbWYnFwBdiRVNUViWOcbTcY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=REUsNhqkDTa8pirLFExfg+AH0tlEGGuos3b9kfkiVautp4SFplBonyHj3lzV/dzGpwpLaEmVg1H2SFaOGznovjE3mU2jp2OfMMegujCwdtKxvgx2LDGoOwrdmFBGri7PyY+kVYH15ESXq2+VFAIP+YIbNrFMbP/B+TpDDUDccD4= 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=h1McUssu; 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="h1McUssu" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-455ea9cb0beso39397635e9.0 for ; Tue, 22 Jul 2025 00:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169407; x=1753774207; 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=1hVGKhMjRai/1mEd80T8Cu2AXSEmjXsghMoyzlOM7Mo=; b=h1McUssuqcyorn+NuOBkhLpkIY0vxGShWGq0jSVOVtMlyvAJzcftFfPNP33qdGTJGJ xbb0+ti2oyvad2DXSmqmNaGyIii1sUgIH13zZ48y6XoHJ1E2+Wlgvqmzphq4x42u8Tap N+9jLYO9OZ+BdwRGj4A9vNcsxoR9J7nQnNrB1+nNIzgQFwlWojSzDD6LoGsdTX5JjlSO sbh9/i5Fy4NMAM9P+R3bxoVF7/LUdhzapb9EmnFz8pRCHbyiL1EEO/xmk2sERUAujxM/ HXez9svkqHKZr2XWdS/6bVwL+AoisBDJeE/I4f4aJvC0dHnkPunCsIY1wb0EX0Tat5aE c2mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169407; x=1753774207; 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=1hVGKhMjRai/1mEd80T8Cu2AXSEmjXsghMoyzlOM7Mo=; b=oNbC7zbfSWO4kVcnMcjGXtoCXTrAsA1YSlrOMBTDaHiPZMm/wlinZsWqJOSfyyFL/P sdTAbbXW+xq5TmywwJw7Po5cILP5pSTzA951ymIF4zyGTldu5xDuj65RbNCB965ZoC1R NXh3+mlf5uAyd3chOr4jsvLYk3GGelXqUChKwEY3Ql5gZHFVlWkPcQF4+X3Y3fy0MBhs J/u5dYG4I8oCZPnwuY4OqGbxQdHQ9TJ9weEJroIwNsekri90yn51YvVa+p3njK78jJNQ bq31izRfuBqKXY/fP2YNbiyHQhwkP8d+GmGGE+ySrOQdtzR3c2ZCQbzvX1UxTgGnuEF+ YY4g== X-Gm-Message-State: AOJu0Yz1E0JSERQLwaTnvzQb91yhV4Dne7bGl9F0a+FZqO1vaSHNNICt q7uACH9iGpWBPHiDlBdnIewDy+ndJAnj4qXxSGenLk3cyCQnSf4vOQt0sQ1z3/0wOQkSi8Z//u8 P44GjZTiFK2NHmzzC95heHVlLtvg/yxG3bOqflz+IMN1Bm/LZsbomaVLPn4Qp6qxzWF0Gm/9ODu wkqyWJRx/KvUEekwjzte6/8Z9iF3vKJyKrfg== X-Google-Smtp-Source: AGHT+IFQw1Gt8sUpFzMar6liYIqnbqdSLilgtBw3ziaxa7IURJrbu9o4g8gA0aKs7L4TBcN3/wJxdWqh X-Received: from wmbeq10.prod.google.com ([2002:a05:600c:848a:b0:455:e7b2:5b41]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1d1e:b0:455:f59e:fd9b with SMTP id 5b1f17b1804b1-45636aedcddmr160591825e9.24.1753169407156; Tue, 22 Jul 2025 00:30:07 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:26 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=1469; i=ardb@kernel.org; h=from:subject; bh=KDAfcfWDoK0sbR/OM+7rDP0GR1LPKwd+fvJZ7QocPEE=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPedsGkQgan7xqbSkIF0hdzz6n3zFXxXK64M+1k127F+ AqLpwc6SlkYxLgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwEQsTBj+WQdt+HQuNuDJ595N Jr1pAavkmi1eFgadlZ76xjYk+uSXCwz/657JBqc/OLl6jUrt2h/pH3///CN+2PODX9eG4J0BXBK fGAA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-41-ardb+git@google.com> Subject: [PATCH v6 17/22] x86/boot: Revert "Reject absolute references in .head.text" 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 This reverts commit faf0ed487415 ("x86/boot: Reject absolute references in .head.text") The startup code is checked directly for the absence of absolute symbol references, so checking the .head.text section in the relocs tool is no longer needed. Signed-off-by: Ard Biesheuvel --- arch/x86/tools/relocs.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 5778bc498415..e5a2b9a912d1 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -740,10 +740,10 @@ static void walk_relocs(int (*process)(struct section= *sec, Elf_Rel *rel, static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, const char *symname) { - int headtext =3D !strcmp(sec_name(sec->shdr.sh_info), ".head.text"); unsigned r_type =3D ELF64_R_TYPE(rel->r_info); ElfW(Addr) offset =3D rel->r_offset; int shn_abs =3D (sym->st_shndx =3D=3D SHN_ABS) && !is_reloc(S_REL, symnam= e); + if (sym->st_shndx =3D=3D SHN_UNDEF) return 0; =20 @@ -783,12 +783,6 @@ static int do_reloc64(struct section *sec, Elf_Rel *re= l, ElfW(Sym) *sym, break; } =20 - if (headtext) { - die("Absolute reference to symbol '%s' not permitted in .head.text\n", - symname); - break; - } - /* * Relocation offsets for 64 bit kernels are output * as 32 bits and sign extended back to 64 bits when --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 8EC742DEA65 for ; Tue, 22 Jul 2025 07:30: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=1753169411; cv=none; b=oswy8tuFLL+MMVG0n+D3Ewzo8nxcePmuJc1JS+CNaZ0z8VijIK++ua6w+JdfZXf4HhdtW8i3GXlIZZTIfksV97VsbdwX5JFyfe21O6AMntJt9XRxNx5f5BGDDEygkPDbxVeEBS97ApM76apbLnM7+kuMx12GvgtDylYxSe1O064= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169411; c=relaxed/simple; bh=qi/XSlH/3m0Py+I72AmudGPp6EWjqjC8xYfnH6HfggU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Z5bNiBg9qxsEqq0EU/uWxMMdUcvdkK0BITpIK2gukuCxbYG/63RubEiAbB3Khp1JqZc/3EGA6HaWedxoTaO0MH1obm+7YLBcmcvsG1NJBbYU7ekBAzTynINTrc95rrF1DIpYWCNDU2xdyi3344KX5wwaYpe/q93iPVIas0nSVcU= 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=gfot8Ue/; 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="gfot8Ue/" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-456175dba68so40805395e9.2 for ; Tue, 22 Jul 2025 00:30:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169408; x=1753774208; 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=HHREQvw4opT+z1wL8T5wjMmNHsYkeJcC/ePiz2KgcJA=; b=gfot8Ue/zHTK4+15kIeIwxJ25lvTOj0IhtyUqz8SqSdoOY3EIq3MO3rDgVxgHAOWfS wyJCsj6lF6qx6i0H+cHpppDWN0xtWPJqZ6cQNgN3gCzJ1wyhDviqFhPkJS+I6UamsUIW mnUpKgA/JL9J3oJwNX7qQucmU4RSQXm3LUVGSnWsE29C9DFDq58zP7Nd42EAf9j6JF83 c4LLa755njee2HQMYIGvqRpRIIG5P5Kvd+uwvqoz+9f7Hh4yJkPYVD5VUPojEj7jL6OF xDb5ABKFbpBAh5tT7SxcHgEG9eBcM0X1zXMJ0Ru3yFGoZakmGfsM/YtVy5yCq5iQGizs JgnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169408; x=1753774208; 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=HHREQvw4opT+z1wL8T5wjMmNHsYkeJcC/ePiz2KgcJA=; b=kOSlHOjt9TBD2t0V448iYsc9aT6z1uUcFrYH4am95c+D9Syznt0bjztpKR0dJDsPhI NB9Xb5ajhbFTYz8fWImd8UVLe1O6gT/b8MUHef+Hje9YIfwAEMJLTbdurime0e/+mtbn EW8eTHo20GZ6ZAJpgOPos9U/NcVVpM/cbYe+3oFme//2I3IiRM1L6mxLTHKNpavD+dy+ OgWwzUUlEgzMApnKga+vGGH/iRGwL0UuTD5fmaW244BCxayMridCi66pUUBSxnA+yaXG Apf0B38typp0MxH3G7cD8VxMqaacbIq56+Vym4phcTMzNSvCbNhmWv4aEk3RjVg1Gc84 7VfA== X-Gm-Message-State: AOJu0YwCv7lBau42FNSjVFw4haCFVI88AzTuEY6CMDkZMeR5e9Qfx15E JZlQN3DeOrdfoS+7uWUHd7VUN38Nb0OKr/eMnXU8riQuueY8NYKNvx50X7iDHIWcIHwS/HUPXtn FI2jELLlQN9nsE/hLGy+dqqlGn62F9DqagHFzSijvCzdzO2hfXM+B+gPVtz1MVrILXNYRCLcf9V ngf8DmivXtl9t05NpNXw7gKWxkU2YiqYPuoQ== X-Google-Smtp-Source: AGHT+IGtTAwtrVkEXe4/+Avmxv1YumQI8ZJGkeN8nTyEw6Kzmo+/2fxJfm3J/QfwTU9abxwdnRUnL0d9 X-Received: from wmcq26.prod.google.com ([2002:a05:600c:c11a:b0:456:293d:55c5]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4709:b0:456:f1e:205c with SMTP id 5b1f17b1804b1-4562e32e598mr202752595e9.4.1753169408066; Tue, 22 Jul 2025 00:30:08 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:27 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=1689; i=ardb@kernel.org; h=from:subject; bh=N6Uq2lVfV25Jk1mFXhfGvG4B+EmaRioUjXHyXI14Co0=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPedun2HZmrn0YdLv3GUvkjNmKXRvDZ3VM+ii77lLF5k 4iTRvmGjlIWBjEuBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjCRnEmMDLdyBb9b3tpcZLhu 67rch5YM16y+Ol30bfM4Wm7dvKdkmQMjQ78gr/zzE/pKIeb+y44+OSa88JB67JRd3xRCJ++ZfT5 EiQcA X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-42-ardb+git@google.com> Subject: [PATCH v6 18/22] x86/kbuild: Incorporate boot/startup/ via Kbuild makefile 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 Using core-y is not the correct way to get kbuild to descend into arch/x86/boot/startup. For instance, building an individual object does not work as expected when the pattern rule is local to the Makefile $ make arch/x86/boot/startup/map_kernel.pi.o GEN Makefile CALL /home/ardb/linux/scripts/checksyscalls.sh DESCEND objtool INSTALL libsubcmd_headers make[3]: *** No rule to make target 'arch/x86/boot/startup/map_kernel.pi.= o'. Stop. make[2]: *** [/home/ardb/linux/scripts/Makefile.build:461: arch/x86] Erro= r 2 make[1]: *** [/home/ardb/linux/Makefile:2011: .] Error 2 make: *** [/home/ardb/linux/Makefile:248: __sub-make] Error 2 So use obj-y from arch.x86/Kbuild instead, which makes things work as expected. Signed-off-by: Ard Biesheuvel --- arch/x86/Kbuild | 2 ++ arch/x86/Makefile | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/Kbuild b/arch/x86/Kbuild index f7fb3d88c57b..36b985d0e7bf 100644 --- a/arch/x86/Kbuild +++ b/arch/x86/Kbuild @@ -3,6 +3,8 @@ # Branch profiling isn't noinstr-safe. Disable it for arch/x86/* subdir-ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) +=3D -DDISABLE_BRANCH_PROF= ILING =20 +obj-y +=3D boot/startup/ + obj-$(CONFIG_ARCH_HAS_CC_PLATFORM) +=3D coco/ =20 obj-y +=3D entry/ diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 1913d342969b..9b76e77ff7f7 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -286,7 +286,6 @@ archprepare: $(cpufeaturemasks.hdr) ### # Kernel objects =20 -core-y +=3D arch/x86/boot/startup/ libs-y +=3D arch/x86/lib/ =20 # drivers-y are linked after core-y --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.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 0D00F2E11DA for ; Tue, 22 Jul 2025 07:30:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169413; cv=none; b=WVCg9DeGKRTnmV7wA9D58vhzQaGyWN+DyavLToIpWyS898TaZgJVDAiXFJbWh3lJMrjqVtdG0girMiw2G5NAr/LtaCROvbGqZqAQXKO5K35HyIhEr0jzLQ+kJ/6ZLKmhfudObaUnJowc9Nkx4i+l45GRj9DMidEPj2zVy8azVAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169413; c=relaxed/simple; bh=0FS7MLD0aawoqK43saTKFtpB7pewnLMeRWFtQgwClKE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FYobV4M2tOfPy53HLuuB0iT63jwhO/klWLWzMGa00UZSv0x0hVolMENPgUZuLWI6L7Zmcm5b0YcOufVQjqP0GMqgrqZ/1UkvoMHkh9rFLuHofCavjRmCEh9mFft8ArPu3h5zZv5wiwjZaPWUMl/rgJLSSlA6Xwgs1TNNfCG0QiU= 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=AJd73Xwb; arc=none smtp.client-ip=209.85.208.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="AJd73Xwb" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-60c9d8a169cso5460106a12.0 for ; Tue, 22 Jul 2025 00:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169409; x=1753774209; 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=KTbS3XaJJn2gG4CFImDKsTK73tqCPQGtne6y7vzBEfY=; b=AJd73Xwb+BjTkk27h+8r3HZvUisHrp0ZxjbKM2WoNMc3btQWaFC0k2n4xQ79f+sLic yXdVPTKCxEUQ1S8R5/zBWPnJob9mG7dC2/zPAqsLmhNPYcqTGiQtkingdpslWHYTvPJp 8jV+aGQxp30aGrIonapscqgVRnEyoek/WB9M0fCQg8d/yfCVKC7oazjjOFACqpaHbn+X kM1m7yE2L+hGp0s8xTpHo9hcgmlLJwMyIOfwKmqMgcN3YnJuMV1HY+1P6Axusi9Shmxe v8Z6L5Ki9i2cRuMzbJFhVCMDiXmg0qcahxhtAE+E/9eX5G8L1ZUNdyzBmqMxhG18YJhk FOGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169409; x=1753774209; 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=KTbS3XaJJn2gG4CFImDKsTK73tqCPQGtne6y7vzBEfY=; b=dA7r9IpD50uSlOCSRfWsaLdNvwDFySxhu3IfVZI3lL/u1fVSQCXGDy3cOOBmKRhg7X k48q/8di96ab03h8+IwbYiPKm6TWF1IqMv9/cy8ilTEbj26JjcxCQWxhnnyXI/fM8IVf Bus9o3VsdSaiOTEnMxrAG9laBC/tYrXikcyCcKeRLvVOpmL3a35dW5RUOAVoYB8TW3Ea J9NMDcbLi+tejKMiDmsoqwmBqEX7ZFJFW1PXtE2lA+4+sDi89mt6d2yfZD7TNkhM1Tvs DF6ucOUoFFBWS+Q9O2sPxV6eruobG1M/g5i6bgg9fA4sgjc/oIJpG/Z8A9l8ogYOcEoz 4vXA== X-Gm-Message-State: AOJu0YwIolsn6WWBKu1pV31Ksc3c9NLMgH7TXAHnF9xrsHT7U8RPAoMw 2SvKyuKphP3MGAR9kYsV6/snpDmjnm/4joGaJTrZ0QEv2mgIdU4yApRwwpIUTLdJa9RSNy0vzYP F80fxaTGvUsFsk5yzH5gZSPc9nFPHhJMvZrx050ZPurzKPSjrGOHepnhrawhgv6iStP42F3IAFp Nu2DILkEKm4r7Ap52GiKW26EIy6xFTqGinKA== X-Google-Smtp-Source: AGHT+IHSHrQLpePc1GBh93t7fQ62I7U75LBLDkgvjv9qIidLFOIho5xmm5kiy8Xz0Lg1/uxysv7Tr1tW X-Received: from edbcy10.prod.google.com ([2002:a05:6402:1c8a:b0:611:f9c0:1914]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:50cc:b0:611:f4b2:379a with SMTP id 4fb4d7f45d1cf-61285be2463mr22030047a12.27.1753169409269; Tue, 22 Jul 2025 00:30:09 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:28 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=7468; i=ardb@kernel.org; h=from:subject; bh=Lr8Ks0uf2ivgorJCA6iP5JcTFwh3mU0lfyYiaD5vVK8=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPedqXLoy7D+l+av15ZLvo3te6Ljmqt94dPwXN+V5soH 47TP1TQUcrCIMbFICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACbC68PI8P79UlPmtT0NVf6L nigV7bLa9fTHJsWsXdIORh0zRbSPzWJkuCF2WI8h+nBg+OaaiE/7m8WjWUN5Py2PZAsv//ku7kU oFwA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-43-ardb+git@google.com> Subject: [PATCH v6 19/22] x86/boot: Create a confined code area for startup 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 In order to be able to have tight control over which code may execute from the early 1:1 mapping of memory, but still link vmlinux as a single executable, prefix all symbol references in startup code with __pi_, and invoke it from outside using the __pi_ prefix. Use objtool to check that no absolute symbol references are present in the startup code, as these cannot be used from code running from the 1:1 mapping. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/startup/Makefile | 14 ++++++++++++++ arch/x86/boot/startup/sev-shared.c | 4 +--- arch/x86/boot/startup/sme.c | 1 - arch/x86/coco/sev/core.c | 2 +- arch/x86/include/asm/setup.h | 1 + arch/x86/include/asm/sev.h | 1 + arch/x86/kernel/head64.c | 2 +- arch/x86/kernel/head_64.S | 8 ++++---- arch/x86/mm/mem_encrypt_boot.S | 6 +++--- tools/objtool/check.c | 3 ++- 10 files changed, 28 insertions(+), 14 deletions(-) diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile index 32737f4ab5a8..e8fdf020b422 100644 --- a/arch/x86/boot/startup/Makefile +++ b/arch/x86/boot/startup/Makefile @@ -4,6 +4,7 @@ KBUILD_AFLAGS +=3D -D__DISABLE_EXPORTS KBUILD_CFLAGS +=3D -D__DISABLE_EXPORTS -mcmodel=3Dsmall -fPIC \ -Os -DDISABLE_BRANCH_PROFILING \ $(DISABLE_STACKLEAK_PLUGIN) \ + $(DISABLE_LATENT_ENTROPY_PLUGIN) \ -fno-stack-protector -D__NO_FORTIFY \ -fno-jump-tables \ -include $(srctree)/include/linux/hidden.h @@ -36,3 +37,16 @@ $(patsubst %.o,$(obj)/%.o,$(lib-y)): OBJECT_FILES_NON_ST= ANDARD :=3D y # $(pi-objs): objtool-enabled =3D 1 $(pi-objs): objtool-args =3D $(if $(delay-objtool),,$(objtool-args-y)) --n= oabs + +# +# Confine the startup code by prefixing all symbols with __pi_ (for positi= on +# independent). This ensures that startup code can only call other startup +# code, or code that has explicitly been made accessible to it via a symbol +# alias. +# +$(obj)/%.pi.o: OBJCOPYFLAGS :=3D --prefix-symbols=3D__pi_ +$(obj)/%.pi.o: $(obj)/%.o FORCE + $(call if_changed,objcopy) + +targets +=3D $(obj-y) +obj-y :=3D $(patsubst %.o,%.pi.o,$(obj-y)) diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 1044a50ac3d3..98c2fcb43279 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -11,9 +11,7 @@ =20 #include =20 -#ifndef __BOOT_COMPRESSED -#define error(v) pr_err(v) -#else +#ifdef __BOOT_COMPRESSED #undef WARN #define WARN(condition, format...) (!!(condition)) #endif diff --git a/arch/x86/boot/startup/sme.c b/arch/x86/boot/startup/sme.c index 70ea1748c0a7..eb6a758ba660 100644 --- a/arch/x86/boot/startup/sme.c +++ b/arch/x86/boot/startup/sme.c @@ -567,7 +567,6 @@ void __head sme_enable(struct boot_params *bp) =20 #ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION /* Local version for startup code, which never operates on user page table= s */ -__weak pgd_t __pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd) { return pgd; diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index be89f0a4a28f..fbed1651f6d8 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -272,7 +272,7 @@ static int svsm_perform_call_protocol(struct svsm_call = *call) =20 do { ret =3D ghcb ? svsm_perform_ghcb_protocol(ghcb, call) - : svsm_perform_msr_protocol(call); + : __pi_svsm_perform_msr_protocol(call); } while (ret =3D=3D -EAGAIN); =20 if (sev_cfg.ghcbs_initialized) diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h index 692af46603a1..914eb32581c7 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -53,6 +53,7 @@ extern void i386_reserve_resources(void); extern unsigned long __startup_64(unsigned long p2v_offset, struct boot_pa= rams *bp); extern void startup_64_setup_gdt_idt(void); extern void startup_64_load_idt(void *vc_handler); +extern void __pi_startup_64_load_idt(void *vc_handler); extern void early_setup_idt(void); extern void __init do_early_exception(struct pt_regs *regs, int trapnr); =20 diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index bc1d7b32e4f4..2b8a779f1477 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -551,6 +551,7 @@ struct cpuid_leaf { }; =20 int svsm_perform_msr_protocol(struct svsm_call *call); +int __pi_svsm_perform_msr_protocol(struct svsm_call *call); int snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf), void *ctx, struct cpuid_leaf *leaf); =20 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 1bc40d0785ee..fd28b53dbac5 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -319,5 +319,5 @@ void early_setup_idt(void) handler =3D vc_boot_ghcb; } =20 - startup_64_load_idt(handler); + __pi_startup_64_load_idt(handler); } diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 3e9b3a3bd039..d219963ecb60 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -71,7 +71,7 @@ SYM_CODE_START_NOALIGN(startup_64) xorl %edx, %edx wrmsr =20 - call startup_64_setup_gdt_idt + call __pi_startup_64_setup_gdt_idt =20 /* Now switch to __KERNEL_CS so IRET works reliably */ pushq $__KERNEL_CS @@ -91,7 +91,7 @@ SYM_CODE_START_NOALIGN(startup_64) * subsequent code. Pass the boot_params pointer as the first argument. */ movq %r15, %rdi - call sme_enable + call __pi_sme_enable #endif =20 /* Sanitize CPU configuration */ @@ -111,7 +111,7 @@ SYM_CODE_START_NOALIGN(startup_64) * programmed into CR3. */ movq %r15, %rsi - call __startup_64 + call __pi___startup_64 =20 /* Form the CR3 value being sure to include the CR3 modifier */ leaq early_top_pgt(%rip), %rcx @@ -562,7 +562,7 @@ SYM_CODE_START_NOALIGN(vc_no_ghcb) /* Call C handler */ movq %rsp, %rdi movq ORIG_RAX(%rsp), %rsi - call do_vc_no_ghcb + call __pi_do_vc_no_ghcb =20 /* Unwind pt_regs */ POP_REGS diff --git a/arch/x86/mm/mem_encrypt_boot.S b/arch/x86/mm/mem_encrypt_boot.S index f8a33b25ae86..edbf9c998848 100644 --- a/arch/x86/mm/mem_encrypt_boot.S +++ b/arch/x86/mm/mem_encrypt_boot.S @@ -16,7 +16,7 @@ =20 .text .code64 -SYM_FUNC_START(sme_encrypt_execute) +SYM_FUNC_START(__pi_sme_encrypt_execute) =20 /* * Entry parameters: @@ -69,9 +69,9 @@ SYM_FUNC_START(sme_encrypt_execute) ANNOTATE_UNRET_SAFE ret int3 -SYM_FUNC_END(sme_encrypt_execute) +SYM_FUNC_END(__pi_sme_encrypt_execute) =20 -SYM_FUNC_START(__enc_copy) +SYM_FUNC_START_LOCAL(__enc_copy) ANNOTATE_NOENDBR /* * Routine used to encrypt memory in place. diff --git a/tools/objtool/check.c b/tools/objtool/check.c index c34331ec1d71..33e2fd8a97a3 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3564,7 +3564,8 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, if (func && insn_func(insn) && func !=3D insn_func(insn)->pfunc) { /* Ignore KCFI type preambles, which always fall through */ if (!strncmp(func->name, "__cfi_", 6) || - !strncmp(func->name, "__pfx_", 6)) + !strncmp(func->name, "__pfx_", 6) || + !strncmp(func->name, "__pi___pfx_", 11)) return 0; =20 if (file->ignore_unreachables) --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 B131A2E1C53 for ; Tue, 22 Jul 2025 07:30:11 +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=1753169413; cv=none; b=DtNTKwOHzRbtx/p4SmbgTR9Rq/i0TYpgPube6KAMeuu9aebyhy2Sa/fwbdv30MrprjskR14mj/1KeU+3CXgGZYsZkJgmcsDf8aZsCCZbylB9wBYYqhzahBBaY7KrV6pKrIH8NUJjo+aeKQN0kvricmHY4ktdF7UDXoiGK40BnVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169413; c=relaxed/simple; bh=RfO7bxnrvkm3EAfuN+XVxgry6A3ikIVlIqCUVBjfqOE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sEO57w95c25PH/4jR+wyRXkgQ4pvWHefTiVuAkgF7S+kjhZ1LS4fnxdc5kgT1RyFxrjNNLjI24gGjOkfQ9cs6DDZtCOCdbHV/gATNtA4SXgNuwhZ1ll3RlFS63bHYQlgDN9RNif9W+w3Kd6ILhC6g+nziXyHbrGIbyjAvDeOaKU= 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=a73XFqX4; 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="a73XFqX4" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3a4fac7fa27so1809266f8f.0 for ; Tue, 22 Jul 2025 00:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169410; x=1753774210; 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=9nImemBj0j8fFHCvjMkwHMba165ZYb0Bk8vw2Jekgh0=; b=a73XFqX4Yo3wTcWDDPUjR9c1RIdgImY6eJkpUvH3SgAv1vQ0Fd4AzAuBUW3pgA2Xdl 32R5qZlwP57tYmB+OgXLQLwTenYKwnYsQlyLykP88fdBbzwIJoy0bh9q1pdJqe6UoG09 bm6NqxvLd1rKPBIhfhS7fp1sLBYNQshY4fzxAChtnb8ARqYlkZSThZHnpgU19WaUJstg UNaJ6eFH+t/qS/mCUm+xKTOBRm3XT11T4M3yvL+Joycwc8l19JNxsyhFEibCH2ZxRrPB 7DdK62IUaKJ20q/V0k6kjtfVv1nYFWf/c0wGpXZHiqVZ1miKfKOd+A6ScRF+5JHiUm5W tfJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169410; x=1753774210; 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=9nImemBj0j8fFHCvjMkwHMba165ZYb0Bk8vw2Jekgh0=; b=RQ6CKpaav+BR7g5eAmihlfxXjd9DoqXNMCGfAW4iiAECa+s2YU7qEcVO3JvlM8s5dM NUUEoOKPBInOhggJGhDgnlrMV/r6KbYvPSySkSmJz1gLHnen9+TpXpmrh0hX8XPwfo8J KM83tUcrF41m2S/1xKJpWorIK0B8YwW52Oe5pAdi6PKA7SbOXeQtSUzc7FK232WMtTs+ Z4pesNNJYd+brY/qzJj4taRVxV/pOy20ZF+fVZfmQvuktwDaggomRrfOKbZAQrQVcuNx 9iJ3I9sLDOMobYl+QihxBGBhqvsOrQyNN68M/OMgSLyOisqfbnWEp2Kr9rAyj4BiCQm/ jP+w== X-Gm-Message-State: AOJu0Yxsev8gTHCFI1ukL55nNOGMfOz9z9Twl6oadcaa1trXU2Aqb8qT U2nMv8Ra4XRGgLMz6BPddtma+tKCxq8jqQbOk97byBtIVilfLQaKH428GLyLcyKsaGEUb33e8hQ i7LWrrvGDrpJf9xtP5WuoXCU9/LqStH4aSY52rPsMPgEu1v7fgJU1VIiF/s8O0V2i6quGzfdZPB uOcS3bByrQ1k2qK7Vs0kes0YZ3hVylSHzGAQ== X-Google-Smtp-Source: AGHT+IH5xwjHFcnT9ZTssnfXE3Q1P32gK3BQqmZs4PrBrGP+O6OvsYUUxIAm+s6cVuFs0g46W4zb2E/D X-Received: from wmbes26.prod.google.com ([2002:a05:600c:811a:b0:442:f9fc:2a02]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:490c:b0:3a4:d02e:84af with SMTP id ffacd0b85a97d-3b60e5531d6mr15630107f8f.58.1753169410298; Tue, 22 Jul 2025 00:30:10 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:29 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=3785; i=ardb@kernel.org; h=from:subject; bh=GtM5Ky3cWjJjWfzB1UFTM+fqdT7qquH5JBfrdp2rkyg=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPedt3MCbvLrIrClJuMlGRn2KplntZQi+Z87D3b1OO4X NiBKyodpSwMYlwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCLmEgz/FA9WuPzLcGyS/bnn xoLH/Wvc2RzWcc8/IHH80g7b+9nfbjL8r7t/zONsd+U/J6YtdmYuTUWp2q82zvzzPnnXyaqsIhY mRgA= X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-44-ardb+git@google.com> Subject: [PATCH v6 20/22] efistub/x86: Remap inittext read-execute when needed 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 Recent EFI x86 systems are more strict when it comes to mapping boot images, and require that mappings are either read-write or read-execute. Now that the boot code is being cleaned up and refactored, most of it is being moved into .init.text [where it arguably belongs] but that implies that when booting on such strict EFI firmware, we need to take care to map .init.text (and the .altinstr_aux section that follows it) read-execute as well. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/boot/compressed/misc.c | 2 ++ arch/x86/include/asm/boot.h | 2 ++ arch/x86/kernel/vmlinux.lds.S | 2 ++ drivers/firmware/efi/libstub/x86-stub.c | 4 +++- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/M= akefile index 3a38fdcdb9bd..74657589264d 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -73,7 +73,7 @@ LDFLAGS_vmlinux +=3D -T hostprogs :=3D mkpiggy HOST_EXTRACFLAGS +=3D -I$(srctree)/tools/include =20 -sed-voffset :=3D -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_r= odata\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' +sed-voffset :=3D -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_r= odata\|_sinittext\|__inittext_end\|__bss_start\|_end\)$$/\#define VO_\2 _AC= (0x\1,UL)/p' =20 quiet_cmd_voffset =3D VOFFSET $@ cmd_voffset =3D $(NM) $< | sed -n $(sed-voffset) > $@ diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index 94b5991da001..0f41ca0e52c0 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -332,6 +332,8 @@ static size_t parse_elf(void *output) } =20 const unsigned long kernel_text_size =3D VO___start_rodata - VO__text; +const unsigned long kernel_inittext_offset =3D VO__sinittext - VO__text; +const unsigned long kernel_inittext_size =3D VO___inittext_end - VO__sinit= text; const unsigned long kernel_total_size =3D VO__end - VO__text; =20 static u8 boot_heap[BOOT_HEAP_SIZE] __aligned(4); diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h index 02b23aa78955..f7b67cb73915 100644 --- a/arch/x86/include/asm/boot.h +++ b/arch/x86/include/asm/boot.h @@ -82,6 +82,8 @@ #ifndef __ASSEMBLER__ extern unsigned int output_len; extern const unsigned long kernel_text_size; +extern const unsigned long kernel_inittext_offset; +extern const unsigned long kernel_inittext_size; extern const unsigned long kernel_total_size; =20 unsigned long decompress_kernel(unsigned char *outbuf, unsigned long virt_= addr, diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 5d5e3a95e1f9..4277efb26358 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -227,6 +227,8 @@ SECTIONS */ .altinstr_aux : AT(ADDR(.altinstr_aux) - LOAD_OFFSET) { *(.altinstr_aux) + . =3D ALIGN(PAGE_SIZE); + __inittext_end =3D .; } =20 INIT_DATA_SECTION(16) diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index cafc90d4caaf..0d05eac7c72b 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -788,7 +788,9 @@ static efi_status_t efi_decompress_kernel(unsigned long= *kernel_entry, =20 *kernel_entry =3D addr + entry; =20 - return efi_adjust_memory_range_protection(addr, kernel_text_size); + return efi_adjust_memory_range_protection(addr, kernel_text_size) ?: + efi_adjust_memory_range_protection(addr + kernel_inittext_offset, + kernel_inittext_size); } =20 static void __noreturn enter_kernel(unsigned long kernel_addr, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.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 E5AEA2E267C for ; Tue, 22 Jul 2025 07:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169415; cv=none; b=eI+6f3sZn6HvlDPBPJXQyp1Zz6UCodoWbtUBcRewLNf4slv5W2+Bs5n0I7eikCP8lN+nDWAe9nUy2ZgwcM8Ki4uMWBtm9AFjSlKtXxkLMI+R8Bo9/EDUXxl/Z0qYQlAISSGnP2IMaaogwx7lc80B5mmuCAM6kEe5GpCi4of+hQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169415; c=relaxed/simple; bh=D2+Y7r7H2sVJXcnR1p0ys98qc4aT1PZtQQS0BqgzfiA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bVgnC32w/vvLqIy98Y1d7BWIe1W6UbuUtHIn9CNRfkiF2XXGe0Q7gV+hoZuLYPZX7SsnlaZvs7E4InJsKyuPOH9vBW5buB/XprWTxDT6wxBBmUPETqVH/E5HK6zZSpHtejLU+v9ybb/Ea13g8bGCMCYw39sLG98IJ+Dnmnk5h4E= 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=oqvbm4M9; arc=none smtp.client-ip=209.85.128.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="oqvbm4M9" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-456267c79deso17172945e9.1 for ; Tue, 22 Jul 2025 00:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169411; x=1753774211; 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=95KZ7KPc9RuBbOZhiroeW5u4B9Eal8DNK7n8iONh/nI=; b=oqvbm4M97MYhceP4H3hL6FbaPCpgnlubfaLQyWK6gPqEMskwG3Nrw0kOuA/uM/eden y/52yfTtO7E8nwEknHafqVB+dZqfYOnBOKM/7gAVaFVLs2uI5ZZRYCUpf2fXwFRipiAU MmEpDPD6/cbFaF9jRnm/Y1M20tzs4tyQvrDtmGt5zadESy6uT4eBK1TDXYSB7A9dXPcw QniS6sly3V+rUwQcw9bgWUciylVWubnnrgxoaI0qzbZdT3vImzMt1z+aM1WC8YmfhXss 8SUMRQ7aGOAy1dgzHutWnJ1S76OjFKvd9BeXC0/sbWr/z2cwGXSeQZIoZtT+DLLMiEfD Ju2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169411; x=1753774211; 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=95KZ7KPc9RuBbOZhiroeW5u4B9Eal8DNK7n8iONh/nI=; b=Tdhn70+sYhxfnSBCJbgr5q1JNSn1KrObuyMMitS0REdmlWGqZd3I6LamPHc6eo1vUJ a8BKuiNGL8Rl4ydUGHJ4cye2FHAvRtTG9u6e94ggEZfg96hlfxIBMqnTOVBZXkOh1v25 BT4X3Lqm/DdZQe0q1AMwgrHZAZLV77F1WgtiyD+I6L1CbZ1TPuBdP1o0bTL0Sc62STKn fZRuue+PSJJjo3oOxzFKLueV8eSV9wAMBa8MfwlFt2IV3lFLidzJlQx+84OysSbjOmFR LVoL7Mhky9X26kahZ2Hasm6JMoyou5KFHqzG7LpoprWuwazAMvmcy0upyx5ruaxmNvOK R7Fg== X-Gm-Message-State: AOJu0YzWTkZAh2o/aUHtaJBsZJd/f4Ckp2y+UTWnrDm58bWlr/SS0Deh P+0uPdo9ymTaMWZUKFEk2RlB3mvsu+UuOCO5XyYx5ZxD0N+0q0UMDnqP5J37W0BWSxHF3lA8Z5q XrDM1GkYxXyuy/4JRmIElOEJZmTVh4nT/zybV1ivKjpJKqRjejtLsXBqvr7RzGBcRwsjjcNkpeg S1u250P/o3HaDIZsfdh3ZCIebp+v4P4b9ZsQ== X-Google-Smtp-Source: AGHT+IGpekCQ/PcS5gWOvkz3YMBfuG7L/RGZQhsW8Wl19jImtcOlAfgxDpSsFOk3Ryiidmiok30u0pQc X-Received: from wrrv11.prod.google.com ([2002:a5d:43cb:0:b0:3a5:751c:a327]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2d0f:b0:3b6:1174:a963 with SMTP id ffacd0b85a97d-3b61174a9a8mr12445196f8f.25.1753169411195; Tue, 22 Jul 2025 00:30:11 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:30 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=16950; i=ardb@kernel.org; h=from:subject; bh=fVeLnhMcK1b3fU8c1eD0VKUbOMlV6w0sSzTBkjDFK34=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPedvPDufqet4tOhbvsfFUuPbk9+sGJ2PRmdZdrpydY3 9x/VDupo5SFQYyLQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEzkVDPD/8qv80IP73V0e7xm 54PpcQabQ2ac2Nt0evm+2UdrVDZOcprO8Ffo/M2c+a5HZr/c0nBjzalV+76IxExxf5/P7P9ovUL 7eT02AA== X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-45-ardb+git@google.com> Subject: [PATCH v6 21/22] x86/boot: Move startup code out of __head section 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 Move startup code out of the __head section, now that this no longer has a special significance. Move everything into .text or .init.text as appropriate, so that startup code is not kept around unnecessarily. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev.c | 3 -- arch/x86/boot/startup/gdt_idt.c | 4 +-- arch/x86/boot/startup/map_kernel.c | 4 +-- arch/x86/boot/startup/sev-shared.c | 36 ++++++++++---------- arch/x86/boot/startup/sev-startup.c | 14 ++++---- arch/x86/boot/startup/sme.c | 26 +++++++------- arch/x86/include/asm/init.h | 6 ---- arch/x86/kernel/head_32.S | 2 +- arch/x86/kernel/head_64.S | 2 +- arch/x86/platform/pvh/head.S | 2 +- 10 files changed, 45 insertions(+), 54 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index faa6cc2f9990..a7af906145e8 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -32,9 +32,6 @@ struct ghcb *boot_ghcb; #undef __init #define __init =20 -#undef __head -#define __head - #define __BOOT_COMPRESSED =20 u8 snp_vmpl; diff --git a/arch/x86/boot/startup/gdt_idt.c b/arch/x86/boot/startup/gdt_id= t.c index a3112a69b06a..d16102abdaec 100644 --- a/arch/x86/boot/startup/gdt_idt.c +++ b/arch/x86/boot/startup/gdt_idt.c @@ -24,7 +24,7 @@ static gate_desc bringup_idt_table[NUM_EXCEPTION_VECTORS] __page_aligned_d= ata; =20 /* This may run while still in the direct mapping */ -void __head startup_64_load_idt(void *vc_handler) +void startup_64_load_idt(void *vc_handler) { struct desc_ptr desc =3D { .address =3D (unsigned long)rip_rel_ptr(bringup_idt_table), @@ -46,7 +46,7 @@ void __head startup_64_load_idt(void *vc_handler) /* * Setup boot CPU state needed before kernel switches to virtual addresses. */ -void __head startup_64_setup_gdt_idt(void) +void __init startup_64_setup_gdt_idt(void) { struct gdt_page *gp =3D rip_rel_ptr((void *)(__force unsigned long)&gdt_p= age); void *handler =3D NULL; diff --git a/arch/x86/boot/startup/map_kernel.c b/arch/x86/boot/startup/map= _kernel.c index 332dbe6688c4..83ba98d61572 100644 --- a/arch/x86/boot/startup/map_kernel.c +++ b/arch/x86/boot/startup/map_kernel.c @@ -30,7 +30,7 @@ static inline bool check_la57_support(void) return true; } =20 -static unsigned long __head sme_postprocess_startup(struct boot_params *bp, +static unsigned long __init sme_postprocess_startup(struct boot_params *bp, pmdval_t *pmd, unsigned long p2v_offset) { @@ -84,7 +84,7 @@ static unsigned long __head sme_postprocess_startup(struc= t boot_params *bp, * the 1:1 mapping of memory. Kernel virtual addresses can be determined by * subtracting p2v_offset from the RIP-relative address. */ -unsigned long __head __startup_64(unsigned long p2v_offset, +unsigned long __init __startup_64(unsigned long p2v_offset, struct boot_params *bp) { pmd_t (*early_pgts)[PTRS_PER_PMD] =3D rip_rel_ptr(early_dynamic_pgts); diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev= -shared.c index 98c2fcb43279..768c80363386 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -29,7 +29,7 @@ static u32 cpuid_std_range_max __ro_after_init; static u32 cpuid_hyp_range_max __ro_after_init; static u32 cpuid_ext_range_max __ro_after_init; =20 -void __head __noreturn +void __noreturn sev_es_terminate(unsigned int set, unsigned int reason) { u64 val =3D GHCB_MSR_TERM_REQ; @@ -48,7 +48,7 @@ sev_es_terminate(unsigned int set, unsigned int reason) /* * The hypervisor features are available from GHCB version 2 onward. */ -u64 get_hv_features(void) +u64 __init get_hv_features(void) { u64 val; =20 @@ -218,7 +218,7 @@ const struct snp_cpuid_table *snp_cpuid_get_table(void) * * Return: XSAVE area size on success, 0 otherwise. */ -static u32 __head snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compact= ed) +static u32 snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compacted) { const struct snp_cpuid_table *cpuid_table =3D snp_cpuid_get_table(); u64 xfeatures_found =3D 0; @@ -254,7 +254,7 @@ static u32 __head snp_cpuid_calc_xsave_size(u64 xfeatur= es_en, bool compacted) return xsave_size; } =20 -static bool __head +static bool snp_cpuid_get_validated_func(struct cpuid_leaf *leaf) { const struct snp_cpuid_table *cpuid_table =3D snp_cpuid_get_table(); @@ -296,7 +296,7 @@ static void snp_cpuid_hv_msr(void *ctx, struct cpuid_le= af *leaf) sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID_HV); } =20 -static int __head +static int snp_cpuid_postprocess(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf), void *ctx, struct cpuid_leaf *leaf) { @@ -392,8 +392,8 @@ snp_cpuid_postprocess(void (*cpuid_fn)(void *ctx, struc= t cpuid_leaf *leaf), * Returns -EOPNOTSUPP if feature not enabled. Any other non-zero return v= alue * should be treated as fatal by caller. */ -int __head snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf), - void *ctx, struct cpuid_leaf *leaf) +int snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf), + void *ctx, struct cpuid_leaf *leaf) { const struct snp_cpuid_table *cpuid_table =3D snp_cpuid_get_table(); =20 @@ -435,7 +435,7 @@ int __head snp_cpuid(void (*cpuid_fn)(void *ctx, struct= cpuid_leaf *leaf), * page yet, so it only supports the MSR based communication with the * hypervisor and only the CPUID exit-code. */ -void __head do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code) +void do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code) { unsigned int subfn =3D lower_bits(regs->cx, 32); unsigned int fn =3D lower_bits(regs->ax, 32); @@ -511,7 +511,7 @@ struct cc_setup_data { * Search for a Confidential Computing blob passed in as a setup_data entry * via the Linux Boot Protocol. */ -static __head +static __init struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_params *bp) { struct cc_setup_data *sd =3D NULL; @@ -539,7 +539,7 @@ struct cc_blob_sev_info *find_cc_blob_setup_data(struct= boot_params *bp) * mapping needs to be updated in sync with all the changes to virtual mem= ory * layout and related mapping facilities throughout the boot process. */ -static void __head setup_cpuid_table(const struct cc_blob_sev_info *cc_inf= o) +static void __init setup_cpuid_table(const struct cc_blob_sev_info *cc_inf= o) { const struct snp_cpuid_table *cpuid_table_fw, *cpuid_table; int i; @@ -567,7 +567,7 @@ static void __head setup_cpuid_table(const struct cc_bl= ob_sev_info *cc_info) } } =20 -static int __head svsm_call_msr_protocol(struct svsm_call *call) +static int svsm_call_msr_protocol(struct svsm_call *call) { int ret; =20 @@ -578,8 +578,8 @@ static int __head svsm_call_msr_protocol(struct svsm_ca= ll *call) return ret; } =20 -static void __head svsm_pval_4k_page(unsigned long paddr, bool validate, - struct svsm_ca *caa, u64 caa_pa) +static void svsm_pval_4k_page(unsigned long paddr, bool validate, + struct svsm_ca *caa, u64 caa_pa) { struct svsm_pvalidate_call *pc; struct svsm_call call =3D {}; @@ -619,8 +619,8 @@ static void __head svsm_pval_4k_page(unsigned long padd= r, bool validate, native_local_irq_restore(flags); } =20 -static void __head pvalidate_4k_page(unsigned long vaddr, unsigned long pa= ddr, - bool validate, struct svsm_ca *caa, u64 caa_pa) +static void pvalidate_4k_page(unsigned long vaddr, unsigned long paddr, + bool validate, struct svsm_ca *caa, u64 caa_pa) { int ret; =20 @@ -633,8 +633,8 @@ static void __head pvalidate_4k_page(unsigned long vadd= r, unsigned long paddr, } } =20 -static void __head __page_state_change(unsigned long vaddr, unsigned long = paddr, - enum psc_op op, struct svsm_ca *caa, u64 caa_pa) +static void __page_state_change(unsigned long vaddr, unsigned long paddr, + enum psc_op op, struct svsm_ca *caa, u64 caa_pa) { u64 val, msr; =20 @@ -672,7 +672,7 @@ static void __head __page_state_change(unsigned long va= ddr, unsigned long paddr, * Maintain the GPA of the SVSM Calling Area (CA) in order to utilize the = SVSM * services needed when not running in VMPL0. */ -static bool __head svsm_setup_ca(const struct cc_blob_sev_info *cc_info, +static bool __init svsm_setup_ca(const struct cc_blob_sev_info *cc_info, void *page) { struct snp_secrets_page *secrets_page; diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/se= v-startup.c index 2f7d21660cdf..7a8128dc076e 100644 --- a/arch/x86/boot/startup/sev-startup.c +++ b/arch/x86/boot/startup/sev-startup.c @@ -44,7 +44,7 @@ /* Include code shared with pre-decompression boot stage */ #include "sev-shared.c" =20 -void __head +void __init early_set_pages_state(unsigned long vaddr, unsigned long paddr, unsigned long npages, enum psc_op op, struct svsm_ca *caa, u64 caa_pa) @@ -64,7 +64,7 @@ early_set_pages_state(unsigned long vaddr, unsigned long = paddr, } } =20 -void __head early_snp_set_memory_private(unsigned long vaddr, unsigned lon= g paddr, +void __init early_snp_set_memory_private(unsigned long vaddr, unsigned lon= g paddr, unsigned long npages) { /* @@ -84,7 +84,7 @@ void __head early_snp_set_memory_private(unsigned long va= ddr, unsigned long padd rip_rel_ptr(&boot_svsm_ca_page), boot_svsm_caa_pa); } =20 -void __head early_snp_set_memory_shared(unsigned long vaddr, unsigned long= paddr, +void __init early_snp_set_memory_shared(unsigned long vaddr, unsigned long= paddr, unsigned long npages) { /* @@ -114,7 +114,7 @@ void __head early_snp_set_memory_shared(unsigned long v= addr, unsigned long paddr * * Scan for the blob in that order. */ -static __head struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) +static struct cc_blob_sev_info *__init find_cc_blob(struct boot_params *bp) { struct cc_blob_sev_info *cc_info; =20 @@ -140,7 +140,7 @@ static __head struct cc_blob_sev_info *find_cc_blob(str= uct boot_params *bp) return cc_info; } =20 -static __head void svsm_setup(struct cc_blob_sev_info *cc_info) +static void __init 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 {}; @@ -181,7 +181,7 @@ static __head void svsm_setup(struct cc_blob_sev_info *= cc_info) boot_svsm_caa_pa =3D pa; } =20 -bool __head snp_init(struct boot_params *bp) +bool __init snp_init(struct boot_params *bp) { struct cc_blob_sev_info *cc_info; =20 @@ -210,7 +210,7 @@ bool __head snp_init(struct boot_params *bp) return true; } =20 -void __head __noreturn snp_abort(void) +void __init __noreturn snp_abort(void) { sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); } diff --git a/arch/x86/boot/startup/sme.c b/arch/x86/boot/startup/sme.c index eb6a758ba660..39e7e9d18974 100644 --- a/arch/x86/boot/startup/sme.c +++ b/arch/x86/boot/startup/sme.c @@ -91,7 +91,7 @@ struct sme_populate_pgd_data { */ static char sme_workarea[2 * PMD_SIZE] __section(".init.scratch"); =20 -static void __head sme_clear_pgd(struct sme_populate_pgd_data *ppd) +static void __init sme_clear_pgd(struct sme_populate_pgd_data *ppd) { unsigned long pgd_start, pgd_end, pgd_size; pgd_t *pgd_p; @@ -106,7 +106,7 @@ static void __head sme_clear_pgd(struct sme_populate_pg= d_data *ppd) memset(pgd_p, 0, pgd_size); } =20 -static pud_t __head *sme_prepare_pgd(struct sme_populate_pgd_data *ppd) +static pud_t __init *sme_prepare_pgd(struct sme_populate_pgd_data *ppd) { pgd_t *pgd; p4d_t *p4d; @@ -143,7 +143,7 @@ static pud_t __head *sme_prepare_pgd(struct sme_populat= e_pgd_data *ppd) return pud; } =20 -static void __head sme_populate_pgd_large(struct sme_populate_pgd_data *pp= d) +static void __init sme_populate_pgd_large(struct sme_populate_pgd_data *pp= d) { pud_t *pud; pmd_t *pmd; @@ -159,7 +159,7 @@ static void __head sme_populate_pgd_large(struct sme_po= pulate_pgd_data *ppd) set_pmd(pmd, __pmd(ppd->paddr | ppd->pmd_flags)); } =20 -static void __head sme_populate_pgd(struct sme_populate_pgd_data *ppd) +static void __init sme_populate_pgd(struct sme_populate_pgd_data *ppd) { pud_t *pud; pmd_t *pmd; @@ -185,7 +185,7 @@ static void __head sme_populate_pgd(struct sme_populate= _pgd_data *ppd) set_pte(pte, __pte(ppd->paddr | ppd->pte_flags)); } =20 -static void __head __sme_map_range_pmd(struct sme_populate_pgd_data *ppd) +static void __init __sme_map_range_pmd(struct sme_populate_pgd_data *ppd) { while (ppd->vaddr < ppd->vaddr_end) { sme_populate_pgd_large(ppd); @@ -195,7 +195,7 @@ static void __head __sme_map_range_pmd(struct sme_popul= ate_pgd_data *ppd) } } =20 -static void __head __sme_map_range_pte(struct sme_populate_pgd_data *ppd) +static void __init __sme_map_range_pte(struct sme_populate_pgd_data *ppd) { while (ppd->vaddr < ppd->vaddr_end) { sme_populate_pgd(ppd); @@ -205,7 +205,7 @@ static void __head __sme_map_range_pte(struct sme_popul= ate_pgd_data *ppd) } } =20 -static void __head __sme_map_range(struct sme_populate_pgd_data *ppd, +static void __init __sme_map_range(struct sme_populate_pgd_data *ppd, pmdval_t pmd_flags, pteval_t pte_flags) { unsigned long vaddr_end; @@ -229,22 +229,22 @@ static void __head __sme_map_range(struct sme_populat= e_pgd_data *ppd, __sme_map_range_pte(ppd); } =20 -static void __head sme_map_range_encrypted(struct sme_populate_pgd_data *p= pd) +static void __init sme_map_range_encrypted(struct sme_populate_pgd_data *p= pd) { __sme_map_range(ppd, PMD_FLAGS_ENC, PTE_FLAGS_ENC); } =20 -static void __head sme_map_range_decrypted(struct sme_populate_pgd_data *p= pd) +static void __init sme_map_range_decrypted(struct sme_populate_pgd_data *p= pd) { __sme_map_range(ppd, PMD_FLAGS_DEC, PTE_FLAGS_DEC); } =20 -static void __head sme_map_range_decrypted_wp(struct sme_populate_pgd_data= *ppd) +static void __init sme_map_range_decrypted_wp(struct sme_populate_pgd_data= *ppd) { __sme_map_range(ppd, PMD_FLAGS_DEC_WP, PTE_FLAGS_DEC_WP); } =20 -static unsigned long __head sme_pgtable_calc(unsigned long len) +static unsigned long __init sme_pgtable_calc(unsigned long len) { unsigned long entries =3D 0, tables =3D 0; =20 @@ -281,7 +281,7 @@ static unsigned long __head sme_pgtable_calc(unsigned l= ong len) return entries + tables; } =20 -void __head sme_encrypt_kernel(struct boot_params *bp) +void __init sme_encrypt_kernel(struct boot_params *bp) { unsigned long workarea_start, workarea_end, workarea_len; unsigned long execute_start, execute_end, execute_len; @@ -485,7 +485,7 @@ void __head sme_encrypt_kernel(struct boot_params *bp) native_write_cr3(__native_read_cr3()); } =20 -void __head sme_enable(struct boot_params *bp) +void __init sme_enable(struct boot_params *bp) { unsigned int eax, ebx, ecx, edx; unsigned long feature_mask; diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h index 8b1b1abcef15..01ccdd168df0 100644 --- a/arch/x86/include/asm/init.h +++ b/arch/x86/include/asm/init.h @@ -2,12 +2,6 @@ #ifndef _ASM_X86_INIT_H #define _ASM_X86_INIT_H =20 -#if defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 170000 -#define __head __section(".head.text") __no_sanitize_undefined __no_stack_= protector -#else -#define __head __section(".head.text") __no_sanitize_undefined -#endif - struct x86_mapping_info { void *(*alloc_pgt_page)(void *); /* allocate buf for page table */ void (*free_pgt_page)(void *, void *); /* free buf for page table */ diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S index 76743dfad6ab..437effb1ef03 100644 --- a/arch/x86/kernel/head_32.S +++ b/arch/x86/kernel/head_32.S @@ -61,7 +61,7 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE) * any particular GDT layout, because we load our own as soon as we * can. */ -__HEAD + __INIT SYM_CODE_START(startup_32) movl pa(initial_stack),%ecx =09 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index d219963ecb60..21816b48537c 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -33,7 +33,7 @@ * because we need identity-mapped pages. */ =20 - __HEAD + __INIT .code64 SYM_CODE_START_NOALIGN(startup_64) UNWIND_HINT_END_OF_STACK diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index 1d78e5631bb8..344030c1a81d 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -24,7 +24,7 @@ #include #include =20 - __HEAD + __INIT =20 /* * Entry point for PVH guests. --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 11:55:36 2025 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 DB5862E3382 for ; Tue, 22 Jul 2025 07:30:13 +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=1753169415; cv=none; b=QD4w0JIFhrt0kgDGEAPaaJXE7N4gQCUYaxlqgcpdjb+lpL/CJIsTHK6Ksldzlii/JRNRcg5+ehKf7+AmE+NC1o3nL0agmNTT9lIIhINt0nnw1O8mnMgY81nkWAfiQJgX8PZvk92o+L6cp8GGlXo+cg1E0rQFOxqvTkxo/812WUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753169415; c=relaxed/simple; bh=MlIRBxRaja7ZlU2OXFrbRrUPNNl74/HsMd4o37sL9hE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hLjhnXSzFqITN1FbJF8m3iaY09PAmWGvh/9YytGPlDqOgfLu8MooXXaktahsEqLDTDUMqQJXTJvZ1ECkoaKXCtSJUQPeJARD26eXk1D+aQJUm5uXDsokjCxBaz88PwKixnPbU2UIkohUyD0WCmoes3l6NCsH/3V6JLKi2cIQav4= 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=IPCZT3UU; 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="IPCZT3UU" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-455e9daab1cso10840505e9.1 for ; Tue, 22 Jul 2025 00:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753169412; x=1753774212; 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=sRQugI64DfH4l5motO7Op00/v3FgIyII8TOhMD/41k4=; b=IPCZT3UUPCUicdgRendY75IhkzSoJHNjsfb4VPfAv1pGutN2BQvgjnfUtMYbU94iTW ZGzKPKRUmrYDi6vELbHEZQ9j5jJWjraNJvcpLJi0TxgXQiFPprHq8DUbSFDT90SEW0ta a6z4Hri6oORrHPSN3kge+OS+8BIX3NR18JvFdX+yoQvDqlXO0sg3+oCti+GLZFqFsndQ mEqdAqWcDwHIM7uiquDZAlbpFbz3/xOMv9MMvcI7TEU6GLn1nwIGOTcCtCZAi7oILmk2 4arIYhjdp3gFtx5E33OrdaYtJ5l3p1orU0IPjLvi1PgnSra28PodSH6kMUpKbiW6j4In P0SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753169412; x=1753774212; 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=sRQugI64DfH4l5motO7Op00/v3FgIyII8TOhMD/41k4=; b=qQ0i1AGFqBfrycDg/CDPKOYvWXgNxqfk4RZnDPfcWNqiKHK6C4PTnxXX7sHaNWamx0 MHN2OD+6m2Pi5PWUTz9oWQ5SoNU9LWYB4FCnAgNu6KbNInER3AkwU4hSoV3aXz6xfQQ+ Gv5v3JFc2FFOuhiDMDTvN6gb1kJgWLGF/+ZYqpkQKDdFXOxTpLozTIwBRDyguGxBbQLn c/iPjfOeeUhJzo10jwyK/4no0ZrcvAJJdHRTPJoZNbqfNim33nRQ8utKqsQ9cREQuIWc i87jWMWik1fp8SBi2dgSe27uYO1F7KZXf8Je722ZgY0iVoClKl4hWszNc2F76Lx3DpeY 9A/g== X-Gm-Message-State: AOJu0YwZkIVuSly9Bbnx8Z25z3Hf2e1Z3LdkGFDlKjj1rcaR13ZxIHjE F+70vdGW38VXSL2AjZwd0g3tIkX/P8h66N9zow7z2g68+A48/OX8UDu8AQwMZ0Jt7+Rm5/w1vJX uAoafuDyiPMBcE8O5yHupbSXz2tOgDhnRBU9fuZMean58jPRHn5j8+HGfHlvRXJuHbOo62FoftS kQlGD/a6gxv8k/+76Tx1Gum7LQQEDT8SZkKA== X-Google-Smtp-Source: AGHT+IFHQkrfJj9WX8KbnmcOtmg/6CDYAHe6Xbecpjb7ImR9En+2bUK1m4cqvZAIzJuTNGaHE6HnMSMz X-Received: from wmqb14.prod.google.com ([2002:a05:600c:4e0e:b0:456:1e7:c024]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4fc1:b0:454:ccd6:327 with SMTP id 5b1f17b1804b1-4562e039d10mr224727535e9.1.1753169412279; Tue, 22 Jul 2025 00:30:12 -0700 (PDT) Date: Tue, 22 Jul 2025 09:27:31 +0200 In-Reply-To: <20250722072708.2079165-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: <20250722072708.2079165-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=737; i=ardb@kernel.org; h=from:subject; bh=2wDANTljMa+3l9R4Cw8PAic5NzJMQu4mfQTgCSM10MY=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIaPedscv7sVf5+tNDPLYtDlYzOSK1yfL44x1l4WeK/9+V nE+ImdGRykLgxgXg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZhIWhsjw7ZFh2580rgz5RJj o2hfkkLwj6C4DSzu8yOVV6zZqf9/XiUjw+yKpsIdB99nr5ozVVn9dPwF7xjxzVzSxlPvKfxzunF PmhkA X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722072708.2079165-46-ardb+git@google.com> Subject: [PATCH v6 22/22] x86/boot: Get rid of the .head.text section 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 The .head.text section is now empty, so it can be dropped from the linker script. Signed-off-by: Ard Biesheuvel --- arch/x86/kernel/vmlinux.lds.S | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 4277efb26358..d7af4a64c211 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -160,11 +160,6 @@ SECTIONS =20 } :text =3D 0xcccccccc =20 - /* bootstrapping code */ - .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { - HEAD_TEXT - } :text =3D 0xcccccccc - /* End of text section, which should occupy whole number of pages */ _etext =3D .; . =3D ALIGN(PAGE_SIZE); --=20 2.50.0.727.gbf7dc18ff4-goog