From nobody Tue Dec 16 08:52:51 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 AE0B11487D3 for ; Tue, 27 Feb 2024 15:19:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709047184; cv=none; b=daY1RcXB1AJOo17GCNadDXZRXxt1g1MMjlR+StADVGkRGX2sNl8eRnVqt33w20z9cFVOp7NiO1j7uDTs4yPWdCoxtauoe/UMM24V1ht9zkLBSSkRkbByyd29mHf8n3o8F10UHm353jYJMlEcsUQIP+qZWzQbiJF9sPpCHFYb2+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709047184; c=relaxed/simple; bh=6uCfH14imCu/66Z1+Fy+FGTIoV3qpsx11QnjUiEPzRU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LhJ1Qx1XfzwcfLmOL2nmoYvcPxbz/9nEE14KMQ54rmY0MSd6tDLu68s6K65Smz9LpoCDrjt/VtqkSRDfIHCXNdr6fWaRmt0BQqjj8yj29KprwHXwaoUZ3Z702ibx21+h2aRs8GTIks4HTPV2BzDA7QtrortBn88LaMs8o23ur7Y= 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=XxXr6N5J; arc=none smtp.client-ip=209.85.128.202 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="XxXr6N5J" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60810219282so52993047b3.0 for ; Tue, 27 Feb 2024 07:19:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709047181; x=1709651981; 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=UkoA/X/6iL1vFPkw1X4qRiTS802RjEN54BVOjq0PpUU=; b=XxXr6N5JFHCCCrMqDeowftOILg0K1Y02uPTFfPWmveqE+FnLjdTYBa78+9dj8E3iju l4ttlpW8GZh3uyEzFDMbvRFSvODVu5+r2h8NgO6kXSSmuZrl28OJ2TBcuF6JQf+cLZKj 3azqSCnzYTPHP1xhnMCWm8NIpHH63X6NzN2+D3lMEEeZ3T2uPY1CQV7MhO+J14/Kj1Ik uDGeGbPWYdx2bzrZ20PFhqL8z7f6sAC6kFEBEGRq7p9oi6hN4riioMh0K24/OIQ0N5ga vQMv7xfZIvbHv4JBq/N+nzPxD/el9FxyNAt9F5UGjAk/kxEP6TIQ5Qp27O+tAP+bICC2 M0UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709047181; x=1709651981; 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=UkoA/X/6iL1vFPkw1X4qRiTS802RjEN54BVOjq0PpUU=; b=VR/MdYSyozxz9jt31fZd3tb/XKe9V5Sj40G6VaW5QouBdDIQnJU3T7t4S3wbzMj8XF n+pOUdNGoFS5ojLkjx5Lii8rhsEKdpTwvIUZjRmXixqqFrTUzMLCk6A5mpfFCc5UDopx +AK+jcr5nrgnTRUUEjvoULjbEsQ5Do5XjU0NFyBqAdSbE70+4GGKDa8wIHcFMMw1fNPF lfiW2YU6WyDiVQDtRHjV5NP7K+W5vVK5uIXXlF175kvZTHu59wr5GAu8U6x5b5Mts/vy T9iUAzV6S3NCQE0ttqogRpy/m7YE0nStBRyTVPo+ilq71vgXJzm9NbFVVpN4TwJ8wx/u ZrcA== X-Gm-Message-State: AOJu0Yxl8QoDupJmpysr/mI4b4Cojbp1vbieEl3I9D3FOOlqyjqvTBuN cpigZIvZa3T/5Dp7rR6E15YxgHq52c1iafqlge60BO1XDAGh+JMbtVLpIPpPKq/CQLwvUNSEMDj r49tgN1YAGglj6H9JYhqwbSF8NJC52obWZXQPzSp+TwFk2attCOdMtKe3qp3vLBq+36Z2JTMcRH gJFQ+bH9sNmAWr2qI8usgcMuME/dko/g== X-Google-Smtp-Source: AGHT+IGDK2XBQSdveRnuxclAW+nINrx435sRojEoCnC21IFKS0zN/HBO3lLil/JoTpf1l6Z085EZo/OM X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:1889:b0:dc6:e20f:80cb with SMTP id cj9-20020a056902188900b00dc6e20f80cbmr97731ybb.3.1709047181682; Tue, 27 Feb 2024 07:19:41 -0800 (PST) Date: Tue, 27 Feb 2024 16:19:16 +0100 In-Reply-To: <20240227151907.387873-11-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: <20240227151907.387873-11-ardb+git@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240227151907.387873-19-ardb+git@google.com> Subject: [PATCH v7 8/9] x86/sev: Move early startup code into .head.text section From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Brian Gerst Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel In preparation for implementing rigorous build time checks to enforce that only code that can support it will be called from the early 1:1 mapping of memory, move SEV init code that is called in this manner to the .head.text section. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev.c | 3 +++ arch/x86/include/asm/sev.h | 10 ++++----- arch/x86/kernel/sev-shared.c | 23 +++++++++----------- arch/x86/kernel/sev.c | 14 +++++++----- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 073291832f44..bea0719d70f2 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -116,6 +116,9 @@ static bool fault_in_kernel_space(unsigned long address) #undef __init #define __init =20 +#undef __head +#define __head + #define __BOOT_COMPRESSED =20 /* Basic instruction decoding support needed */ diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index bed95e1f4d52..cf671138feef 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -213,16 +213,16 @@ static inline int pvalidate(unsigned long vaddr, bool= rmp_psize, bool validate) struct snp_guest_request_ioctl; =20 void setup_ghcb(void); -void __init early_snp_set_memory_private(unsigned long vaddr, unsigned lon= g paddr, - unsigned long npages); -void __init early_snp_set_memory_shared(unsigned long vaddr, unsigned long= paddr, - unsigned long npages); +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, + unsigned long npages); void __init snp_prep_memory(unsigned long paddr, unsigned int sz, enum psc= _op op); void snp_set_memory_shared(unsigned long vaddr, unsigned long npages); void snp_set_memory_private(unsigned long vaddr, unsigned long npages); void snp_set_wakeup_secondary_cpu(void); bool snp_init(struct boot_params *bp); -void __init __noreturn snp_abort(void); +void __noreturn snp_abort(void); int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, str= uct snp_guest_request_ioctl *rio); void snp_accept_memory(phys_addr_t start, phys_addr_t end); u64 snp_get_unsupported_features(u64 status); diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index ae79f9505298..0bd7ccbe8732 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -93,7 +93,8 @@ static bool __init sev_es_check_cpu_features(void) return true; } =20 -static void __noreturn sev_es_terminate(unsigned int set, unsigned int rea= son) +static void __head __noreturn +sev_es_terminate(unsigned int set, unsigned int reason) { u64 val =3D GHCB_MSR_TERM_REQ; =20 @@ -330,13 +331,7 @@ static int sev_cpuid_hv(struct ghcb *ghcb, struct es_e= m_ctxt *ctxt, struct cpuid */ static const struct snp_cpuid_table *snp_cpuid_get_table(void) { - void *ptr; - - asm ("lea cpuid_table_copy(%%rip), %0" - : "=3Dr" (ptr) - : "p" (&cpuid_table_copy)); - - return ptr; + return &RIP_REL_REF(cpuid_table_copy); } =20 /* @@ -395,7 +390,7 @@ static u32 snp_cpuid_calc_xsave_size(u64 xfeatures_en, = bool compacted) return xsave_size; } =20 -static bool +static bool __head snp_cpuid_get_validated_func(struct cpuid_leaf *leaf) { const struct snp_cpuid_table *cpuid_table =3D snp_cpuid_get_table(); @@ -532,7 +527,8 @@ static int snp_cpuid_postprocess(struct ghcb *ghcb, str= uct es_em_ctxt *ctxt, * Returns -EOPNOTSUPP if feature not enabled. Any other non-zero return v= alue * should be treated as fatal by caller. */ -static int snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cp= uid_leaf *leaf) +static int __head +snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid_leaf *l= eaf) { const struct snp_cpuid_table *cpuid_table =3D snp_cpuid_get_table(); =20 @@ -574,7 +570,7 @@ static int snp_cpuid(struct ghcb *ghcb, struct es_em_ct= xt *ctxt, struct cpuid_le * page yet, so it only supports the MSR based communication with the * hypervisor and only the CPUID exit-code. */ -void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code) +void __head 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); @@ -1025,7 +1021,8 @@ struct cc_setup_data { * Search for a Confidential Computing blob passed in as a setup_data entry * via the Linux Boot Protocol. */ -static struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_params= *bp) +static __head +struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_params *bp) { struct cc_setup_data *sd =3D NULL; struct setup_data *hdr; @@ -1052,7 +1049,7 @@ static struct cc_blob_sev_info *find_cc_blob_setup_da= ta(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 __init setup_cpuid_table(const struct cc_blob_sev_info *cc_inf= o) +static void __head setup_cpuid_table(const struct cc_blob_sev_info *cc_inf= o) { const struct snp_cpuid_table *cpuid_table_fw, *cpuid_table; int i; diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 1ef7ae806a01..33c14aa1f06c 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -25,6 +25,7 @@ #include #include =20 +#include #include #include #include @@ -682,8 +683,9 @@ static u64 __init get_jump_table_addr(void) return ret; } =20 -static void early_set_pages_state(unsigned long vaddr, unsigned long paddr, - unsigned long npages, enum psc_op op) +static void __head +early_set_pages_state(unsigned long vaddr, unsigned long paddr, + unsigned long npages, enum psc_op op) { unsigned long paddr_end; u64 val; @@ -739,7 +741,7 @@ static void early_set_pages_state(unsigned long vaddr, = unsigned long paddr, sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC); } =20 -void __init early_snp_set_memory_private(unsigned long vaddr, unsigned lon= g paddr, +void __head early_snp_set_memory_private(unsigned long vaddr, unsigned lon= g paddr, unsigned long npages) { /* @@ -2062,7 +2064,7 @@ bool __init handle_vc_boot_ghcb(struct pt_regs *regs) * * Scan for the blob in that order. */ -static __init struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) +static __head struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) { struct cc_blob_sev_info *cc_info; =20 @@ -2088,7 +2090,7 @@ static __init struct cc_blob_sev_info *find_cc_blob(s= truct boot_params *bp) return cc_info; } =20 -bool __init snp_init(struct boot_params *bp) +bool __head snp_init(struct boot_params *bp) { struct cc_blob_sev_info *cc_info; =20 @@ -2110,7 +2112,7 @@ bool __init snp_init(struct boot_params *bp) return true; } =20 -void __init __noreturn snp_abort(void) +void __head __noreturn snp_abort(void) { sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); } --=20 2.44.0.rc1.240.g4c46232300-goog