Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp3020292rdb; Tue, 13 Feb 2024 04:46:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdU/PrLz7Kq3q8DuKiBwUjL9LJudUY05St+u7OLRA6B4IVUzI4Pe0bIz823TbYetdSlak6 X-Received: by 2002:a05:6358:7e42:b0:178:fd13:d6e4 with SMTP id p2-20020a0563587e4200b00178fd13d6e4mr10443429rwm.25.1707828399589; Tue, 13 Feb 2024 04:46:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707828399; cv=pass; d=google.com; s=arc-20160816; b=H2cZyfFcji7WdXqla5uGBbbWsknRKpXCU9VLa9Pb4e+ELlRzQASOPyezVJ5I7IVQVM sUBQzGorm9kgNbLjVsqO8eBmsSDnWjAfr28g89A98hTesreERiXpVTjTZE1CjQNvmjd6 StZ32usd8onveQ31w3aauszJXpy8bob3tJp4yaWcO3JOAnTh5iK9mtK23S9mSJJgdgy4 df3WBnajZ4Q9ryyWLTm01rpAZmBUK8DbssA9Osa+Q/+GhA6+yvspkIHJRMhNaaU6fMcY EPeMy+NJOw7hE/mDE7ipzvWLQFKcwD9McFsBNhu+sPl7fYnLvuAw9dmwLn6xiAGaRIIm g67A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=vDwWzx+ZIZln/anz+aVU2C0rhpdbzTDoyUXdax0Fzpk=; fh=Cstuq8Ul4+tlt1tZXFCWy38FwRv9SCaXyqgO6txe8fw=; b=06nKyqW0zNwXaCKz48833ocqaLPNPnh4ZxVVL1vKOD3MRbGeBts6eFEunKyUdJk2XV UMl/jG9RIM+wlgubhXOIMGid7cUyCwm7IsjWcRE+L0gk7HacN3256kYhJTvJFD8No+hM X84DmA6TZ5etABneoqVOoNYOttRf9FLGpc2ccdLY+7z0v1+0b/KoWV/fe5/fSIa32WxU UT6PJ/sf3oCrQXqqNVPYFLA6cHiY4bIPVnyTyE5dLoMlAh28ehfGtuduDtsgUKQ5j9oW XOHxkB2rpwJwfL9Yf7zns/sozBkbui5u2lBc4Ck110itRN/VLwePUMEY9QRU73PcB1LX aoJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OI+Sua7s; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-63531-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63531-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCXVfZBMVOE4orCVFmA9eg19+o44gEC61AEjBdiVu0JOh1z5IpTik5O/LUt0g1Z5rXgG1yB7F+5F6gzkKqCUGE3J1f2ylOLfbJxwwuBtbQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ay7-20020a05622a228700b0042c143e9fdesi2879161qtb.504.2024.02.13.04.46.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 04:46:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63531-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OI+Sua7s; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-63531-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63531-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7D48F1C2627E for ; Tue, 13 Feb 2024 12:45:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BEF754F9A; Tue, 13 Feb 2024 12:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OI+Sua7s" 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 58E9C54BD7 for ; Tue, 13 Feb 2024 12:42:26 +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=1707828149; cv=none; b=nhQ8O7UvKHSm8IXGaR1Gv9sVb9SZpnDosb/U3O1CxlKxB/9iCi56AODnSP80DeCGjrb/J0Q9u5kmYNEV8oiTMH/qbh9D2KwivSwrh1fyYiQJ44O70bOKnXRGs72IW5Se/o/nFhSNek1eFheb5EllQ3ZIqOfh9DyAETiEGVigLac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707828149; c=relaxed/simple; bh=CKqAkVncBI5L3gG4K3ZJpuo/XUJZHNhpt3gf71HxdC0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JyCCg+AEN04CXrycLSPI51x35D9/hiABaLlZnA/qma4I1Ntc34QSmhcnUS0MuyHvs4ZuPv6t6bWCH6JAw3UfYEiJHHe5OYNsoYsGNCd9Ksw1Rk/4Ep+xsDi7FLm9LXoJgNrTFPg+njNs/p6Z9DPtjV9kUEBcCviksu0rVwV+M78= 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=OI+Sua7s; 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 Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4102b934ba0so24892045e9.2 for ; Tue, 13 Feb 2024 04:42:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707828144; x=1708432944; 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=vDwWzx+ZIZln/anz+aVU2C0rhpdbzTDoyUXdax0Fzpk=; b=OI+Sua7sUU4PKsaALvZwj2d7Pgsbhjr0vEAw1fcZi6Ri16fqRDSrHNTYge2vXXccys lpqEhTLKSaAgJvDmFyaS1UEpMFvKf/+wvHY0Jc+hrYxjC3wnQw6PXJn5b5Umtfn3Cnhj 9CJiAbzOS+1E1xZGhCFjkh030z+n6gjc0WdNkqYthCIbwwuDFQOYQNLD+IoAEMmV7X4W FxOs8nzpZOeRO3ul6251ZnXRHfTPcGCPqNTIjZ1WAmF9WkIQVHCedGh8MxdGb3ZIS9IA kJmyN5ElWVvs9RLpf1NQ7v76PsPYsgsCKX+L5ORsp2rTKk5XdVYD6B2ETaVU1R7fm5aB Srqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707828144; x=1708432944; 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=vDwWzx+ZIZln/anz+aVU2C0rhpdbzTDoyUXdax0Fzpk=; b=EG7VlEKFCQ20B/O5Jyn+7aXCmJcXQBAd/K5gTycrt258O5gbQpH8+IwYb88swQrbzk ENbYsWhPjkNq80pAavt0rq4QY1weOdEjn+5QRRLrWSaAfKoi8dm6o9jS9LMeyDjpTM+j XTD1Pv4NatNPMznX0fMAW38uzqOTVYeKQ+BockEUiz99fbj1SutYFxmx6AdVJC96UKmL 0SKmfmKBOrpQjyOk8OxJ+AaAo3ZlmPxPU84FAnsQHJM6Q9gDq8RHrqZpyr1IbgOy7RFX TzotVXS0S7/IxOM6XgegUrOQylDfr+66M+PREfbHa4djCOUOhoRJR5KG0Soq8qIzd6CB klBA== X-Gm-Message-State: AOJu0Yyja9PW8XEvSeSoPdEM2d33s8cFXCnzH+lfNNxnx1ClhbOmYcyb zv5iNoT+GD9jxSjlqZZzWPn/3W4qpulYgM3rFfTaKaCR4/CZmevL+Fy9QNZ5pYagK86Y8okD9oZ p2fPQA1QsRSnrayAasW/jpb0eh2Ze+86c16tpxtdFrFfezIx8KqbTmtnLNUBVWFFcHS7RqoPjXc 9HsR7rjbyVdptIZdnn7kweHjUlr/S+VQ== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6000:1753:b0:33b:5e9f:c62e with SMTP id m19-20020a056000175300b0033b5e9fc62emr31121wrf.0.1707828144184; Tue, 13 Feb 2024 04:42:24 -0800 (PST) Date: Tue, 13 Feb 2024 13:41:54 +0100 In-Reply-To: <20240213124143.1484862-13-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: <20240213124143.1484862-13-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=7378; i=ardb@kernel.org; h=from:subject; bh=2k7RKXQoIArwBAJHl4Eso59xaiH+DoTxxKoPT8FFXXc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfV08mQmR4fd8z7E76yaGqsvWu+xtGCDSmZwRVt3ZkcSQ 23ygpSOUhYGMQ4GWTFFFoHZf9/tPD1RqtZ5lizMHFYmkCEMXJwCMJGXcxj+F1rbm+Ys9sk+liz3 Najh2WTd8973Vi88d7rsM/8CHi3No4wMfYv09jxksrsQ/uDhXafWzeYaO5tW/jDyaTO8tF5Akuc XOwA= X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240213124143.1484862-23-ardb+git@google.com> Subject: [PATCH v4 10/11] 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 , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Justin Stitt , Kees Cook , Brian Gerst , linux-arch@vger.kernel.org, llvm@lists.linux.dev 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 +#undef __head +#define __head + #define __BOOT_COMPRESSED /* 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; void setup_ghcb(void); -void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long 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, struct 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; } -static void __noreturn sev_es_terminate(unsigned int set, unsigned int reason) +static void __head __noreturn +sev_es_terminate(unsigned int set, unsigned int reason) { u64 val = GHCB_MSR_TERM_REQ; @@ -330,13 +331,7 @@ static int sev_cpuid_hv(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid */ static const struct snp_cpuid_table *snp_cpuid_get_table(void) { - void *ptr; - - asm ("lea cpuid_table_copy(%%rip), %0" - : "=r" (ptr) - : "p" (&cpuid_table_copy)); - - return ptr; + return &RIP_REL_REF(cpuid_table_copy); } /* @@ -395,7 +390,7 @@ static u32 snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compacted) return xsave_size; } -static bool +static bool __head snp_cpuid_get_validated_func(struct cpuid_leaf *leaf) { const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table(); @@ -532,7 +527,8 @@ static int snp_cpuid_postprocess(struct ghcb *ghcb, struct es_em_ctxt *ctxt, * Returns -EOPNOTSUPP if feature not enabled. Any other non-zero return value * should be treated as fatal by caller. */ -static int snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid_leaf *leaf) +static int __head +snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid_leaf *leaf) { const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table(); @@ -574,7 +570,7 @@ static int snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *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 = lower_bits(regs->cx, 32); unsigned int fn = 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 = NULL; struct setup_data *hdr; @@ -1052,7 +1049,7 @@ static 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 memory * layout and related mapping facilities throughout the boot process. */ -static void __init setup_cpuid_table(const struct cc_blob_sev_info *cc_info) +static void __head setup_cpuid_table(const struct cc_blob_sev_info *cc_info) { 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 +#include #include #include #include @@ -682,8 +683,9 @@ static u64 __init get_jump_table_addr(void) return ret; } -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); } -void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr, +void __head early_snp_set_memory_private(unsigned long vaddr, unsigned long 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; @@ -2088,7 +2090,7 @@ static __init struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) return cc_info; } -bool __init snp_init(struct boot_params *bp) +bool __head snp_init(struct boot_params *bp) { struct cc_blob_sev_info *cc_info; @@ -2110,7 +2112,7 @@ bool __init snp_init(struct boot_params *bp) return true; } -void __init __noreturn snp_abort(void) +void __head __noreturn snp_abort(void) { sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); } -- 2.43.0.687.g38aa6559b0-goog