Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1343025rbb; Mon, 26 Feb 2024 06:32:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+PLrP2bVoRp/tgBR4PcJwLJtt9sjFcfLIhan1cdYMUQaq4eH9Kv23rzTpwdNRUCpuqOZn895LkwFRtDvkNgZd687ro6+Ar9vZxYE3sA== X-Google-Smtp-Source: AGHT+IHVPyvTI5pNIzL7H8Hfv6UER/z5ETXXWJVjsQolgQ2U2SIAUQf+FeDPNiSNUgtNYgrgflg1 X-Received: by 2002:a17:906:e2cd:b0:a43:4d47:2022 with SMTP id gr13-20020a170906e2cd00b00a434d472022mr1952447ejb.44.1708957968718; Mon, 26 Feb 2024 06:32:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708957968; cv=pass; d=google.com; s=arc-20160816; b=mnnT8LLSJsl/ux3a7iVGqJWWXKU8Zi5LPc21HuRcco7Us9PXe84P9Z6vffjGEQy0v1 aEV9lOESkS8aeUrykY3p3mDFCt6+Fq5BcclMBKhM0KDuibB8xpZ8hWfn5BZu+oArxNZQ aiMax/UZ2/HWC1fEgi1DjWdJ5PizvAFkPiwY7UCH+wuwWp0YmPULvM2D1ovuftHIScpc ehrXHrJ8kIBmZfRKjqFFLkJ4BBGlJoxep73Edf9OphPP5r9e3jg7Wezo4WMsUslTF071 jG9erwTVkwuG86UTZeC1wrOmfIL5lLXGrFsnN9yk6+eEeudTwaBJbzf+00u+ogMJNCAE SuLw== 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=o1RTMbx8aPOdGUmQigoxFTqq7Alxv8e0fhW/7jCZ7hc=; fh=GwInpN0wyaUEy1HIz2WqUneHJB46QWkS/TNrezKinns=; b=LCqopL9YMMfanWXLh5qdi2F4/awsDdm6Un6g4VHXyjSdlnZToLI+qmtLryy/IJlGsG DkqGb/234MFFb6fyE7FrBFZrTBZhoWqN8l4DCkzESz9pwM5Su6fZdzgEYiRBx4UfOZGF 30vFBHK1E4gEUD1j7uiJ1cYUkx+1Z1nZGw1bFBUiIWnGLiRqEKjKdlBf1mdgX37XdmA2 jyE99StyZZprvF/UgU7GCwqRr3PQ9QxjdAfAx/OXOOEmdo1H5LewW0r0foEGb4tHG09Q 0Xgd1zOLO7D2TwpzPftmG5Pf160pNY03e4n9TKJj1WHGY0Gwk4rLYJkFljcozbxoAymd Sdmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=VJAJ4Ir4; 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-81631-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81631-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id la22-20020a170906ad9600b00a3f161d3bd9si2058888ejb.497.2024.02.26.06.32.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 06:32:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81631-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=VJAJ4Ir4; 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-81631-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81631-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8DD311F2411C for ; Mon, 26 Feb 2024 14:32:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB19212CD9C; Mon, 26 Feb 2024 14:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VJAJ4Ir4" 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 C732912C814 for ; Mon, 26 Feb 2024 14:30:22 +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=1708957824; cv=none; b=YCME1Q4PveDZcZSXX4XfnskoViZPfdsYTytXhXztrbfL8PdAHIwbJlBkaiyJELaGe+wV1jbaLq5C63GBp1pkpxei0kz1vKmiEM/ybM75Y1M8MF/t30qp99PmB1NDTPCX7LLHKJH6g72Jd8ZlcHUUyJqWroDjkH9IfxYtZ0RPrTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708957824; c=relaxed/simple; bh=dRE0REehaE79mQAOudLPe6thvzCULsyHIPQfD/woex8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U8fQZxZVgNDXIHLgOJ8B7jYW1ro7w5QPVuuSk/HOhLEmL8K6f5cY4zsSHtp9iHy8UVbIysl0gL6HdLsWIQZIAV0G1DCU2aWZWbSvZo43Rgyzb6CEZ64AQ0LSnAGyjmz+2PogiFa8mnv8EHFUnOJQuyUBWc2M/qIi3y3adZeojxM= 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=VJAJ4Ir4; 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 Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-40fb505c97aso17421905e9.3 for ; Mon, 26 Feb 2024 06:30:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708957821; x=1709562621; 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=o1RTMbx8aPOdGUmQigoxFTqq7Alxv8e0fhW/7jCZ7hc=; b=VJAJ4Ir4KQ0hqzPxYpopFaGL0bT4Q6ddxN4WKEppogdgYtPK2AZjUOMsGsXPKlbLqK y6bvx1UPDtyzv9X7z2ObEj7lo4TIjNj2fMbfSPj0urBMVn0H5SSAv6xb6NwLKc4/jF0d l6E040jd4ag89f/U92ODBBjB/YCFpDPPQmWphl6a4ygAS87VlA7nog4uFYfLZanowthC 38lK0hg0kZTnqA4Xr4lIwG1UtKmcdqIERCa5HqY/crrwkuw3o2hSqqyAEYFv8qAzzrcs /b418xGN03Q9hsZMXd4qj7Q9RDOYUKOn2njA5XMjQCcJcaRO6dqlZd1jUkUqiNybvLLv lc+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708957821; x=1709562621; 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=o1RTMbx8aPOdGUmQigoxFTqq7Alxv8e0fhW/7jCZ7hc=; b=Ztl6KLp97RZVDCXi5Ana2BwD1kiWPuRa6wyEOIf5/3rAgLZfXNWC0/Bb0/YAfzKTXE ro7H6xqVTeRR+u4yyKlcd1qh66kYuYyl94il7tm8ScpEeSyEOUrXFs/E5KPwKgsGUvbU Q4qr182H2GIxj4nrUy6bWZwCuA4HmKP/phqzu5I1itL/bZdbWlzy0Bebn0Tl2gL4AQsw 4vEr5ivvC2PcJlC+rhGD/TwEOZGVw/a5xzu1NHIR2kyvY5swaPexCRAd6g2czYkLNnIc VfPC0+PwoWhAVfUTB0qmYnnD5Bhs3Bh17P52Zh5eQQ4UeA5r4J79siZ0drBGFaIjb/ou EKnw== X-Gm-Message-State: AOJu0YwCG0PgDEez8+63v8b65klrwYKAXS7vXwpwV3p9zkwWF6Qu64kW LiknBqfz/DXvPsnSBL17xE1zemUPqgLO4I7nKbsvR2PBQA4nT4JKBLfNPT7za95NAhmSKqL9riN S0QNRmYQK8ctIGCrZbAAKe01efJkZlaVTAY11xz3w1zANOe/VzRgc505G8NM8S7Fp3UaGdjHGmz pboVMIFj2h4IwwS4OBo4rYvTDdoDuz2A== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:600c:5191:b0:412:a81e:dd7c with SMTP id fa17-20020a05600c519100b00412a81edd7cmr3324wmb.1.1708957820860; Mon, 26 Feb 2024 06:30:20 -0800 (PST) Date: Mon, 26 Feb 2024 15:30:02 +0100 In-Reply-To: <20240226142952.64769-12-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: <20240226142952.64769-12-ardb+git@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240226142952.64769-21-ardb+git@google.com> Subject: [PATCH v6 09/10] 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-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.44.0.rc0.258.g7320e95886-goog