Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1377684rwl; Wed, 12 Apr 2023 11:52:04 -0700 (PDT) X-Google-Smtp-Source: AKy350bxZl4ykrFFL5yjI3FawxnKrbiKXO61HFXDFOKZasr9DDykySqGydsejB0VADj5ndv5Fks4 X-Received: by 2002:a17:907:31c9:b0:94e:547b:6322 with SMTP id xf9-20020a17090731c900b0094e547b6322mr3743652ejb.25.1681325524380; Wed, 12 Apr 2023 11:52:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681325524; cv=none; d=google.com; s=arc-20160816; b=LtYGCMYIYdDcPPJ4lSyfyhTpDu4Bgrh9lTlLAxEGH9ZM91nYb8qdDwramBkuOhuL+4 qdNwy/UhCkQK3UOFjIFfk7gqxMvndMkw6+xpFK56gkbLQ+q3EXC7yNrk9Arg+xyYQpyP cbqVsKmh7rHIzrkZQSERtrvPCbtC/aL+QGr2yWiVLjlsBzi1itZJd1JG3kRyJOVNtH4G oc/w73szOCdQLzD3+Ht6dlD4/8JyvBd0cUrTD64WKMbIBj7W17GCILT167ceR9nYbNS3 Ee4NUZruw40CdjbzdNqH48cQo3c4EzWUXzEsiezuDR1K/beyhd/cFtvP4KdLd+8NQCBV zvtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/WxAOYQvB1/+zLeJWbAjVCxh3aoYklNTPW85OIPHgas=; b=X0c6IvPxUqdaaU5WdjjkIVP4jHILgD/0SqPIU3avsQ+0OBRz8f0bW3p9mBbPai1abU ZmCjD5bqap5YjV4xQg8a9abYteMUtICwDgnht5iID+k7T8bVvc5i3GurMNCazz7NJ2Og rbfHYdKDY1pEQW802y2p6yt2C4T/0VZhVXzFZvcHjMLEwTeLWNRf3ZnH4qi3+s+SIsc8 +IidqUPzOC8x5nC56nVk5tJAPGcuRfj9qsqzuYoGKFE8lQjira5lSr9JuDDYv1WS6ox5 VlOpe5RdZyzSS7PxpTuLZ+muC1tnJGtN2tb6mHUnQeasF6h50sWZun4OwAXcxCy3RkfC xJIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OVQrLlD7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s15-20020a17090699cf00b0094cea0b33besi3823105ejn.75.2023.04.12.11.51.16; Wed, 12 Apr 2023 11:52:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OVQrLlD7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229968AbjDLSpf (ORCPT + 99 others); Wed, 12 Apr 2023 14:45:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjDLSpX (ORCPT ); Wed, 12 Apr 2023 14:45:23 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D61E459C5 for ; Wed, 12 Apr 2023 11:45:15 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id i15-20020a9d610f000000b006a11f365d13so5253276otj.0 for ; Wed, 12 Apr 2023 11:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681325115; x=1683917115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/WxAOYQvB1/+zLeJWbAjVCxh3aoYklNTPW85OIPHgas=; b=OVQrLlD7CUCucbyt526lxhXpqj2jb03tYwsa6VKmMzp3SZ5Bv7OeZoh2U203GgurGr j4waufjf8DqD6BSm7Ia54o3w7PwG+R2chyOZq77K2DOTJ/ZTXUFiDBP05+BtIPwZVvPv IAq+qt1pN/Pwl0EQ29MzYFeX5KYJ1AQij3C35EATOFmfvzjccaGwqq38NareXFCRh1mM sLsUbwLllhT0QVPfbvBBY/O8CU9WOmBGzAf+dSt6N5aRkArRXlPUUw3DdMq+mqZMb+pD ZCGAg+QuImm0QsyVqj+TLXqr/8CpTte3db14IwhryHSfFV9pX9XXQhUfKv7ikkjOvhf0 2cPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681325115; x=1683917115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/WxAOYQvB1/+zLeJWbAjVCxh3aoYklNTPW85OIPHgas=; b=BgUjy0fB6vS1YyjrKc1tUMjzGV7qUE6GlHgGsmlt5a1RTVku++5+18gAhInOG6BqlH Zf/skzdgXnlZ5rrHAaNUX3MS1zflgJc/1hvS34c/8P49dVdwLMKEJkj3ZuHQ2/Cg/ERu KHrkHmKBOF/At30bFlh26V17FWC69tQOWXN68j95BvRYCU8JsissfoxGGpoW4ko63REh KBQWDvPsx2koG8XhQ7cq0EH9jbkvR2Bp3EXsCGmTYFZmk6N3SbpnpiloeydTPZOgMGsC b3ZWkL/UnF2HE1MGVf5oGY3AU3Wn7hTxaVwbam6UuMLScN04h7WU6YaZ1PJLUnEoXUAT xBLA== X-Gm-Message-State: AAQBX9f5ihHXFkJ62EwRundA3can+zkASKj4wX49acdMIsdHEXSG4wQE pOy835j+oxLNqh/gya8g2jHw09d+vw== X-Received: by 2002:a05:6830:12cd:b0:6a3:3655:b8a7 with SMTP id a13-20020a05683012cd00b006a33655b8a7mr75639otq.14.1681325115058; Wed, 12 Apr 2023 11:45:15 -0700 (PDT) Received: from citadel.. (075-129-116-198.res.spectrum.com. [75.129.116.198]) by smtp.gmail.com with ESMTPSA id w24-20020a9d77d8000000b00690e990e61asm6706020otl.14.2023.04.12.11.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 11:45:14 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Ingo Molnar , Brian Gerst Subject: [PATCH v2 6/6] x86/boot: Use copied boot data in sme_enable() Date: Wed, 12 Apr 2023 14:45:02 -0400 Message-Id: <20230412184502.145289-7-brgerst@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412184502.145289-1-brgerst@gmail.com> References: <20230412184502.145289-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the copied version instead of the original real mode data. Signed-off-by: Brian Gerst --- arch/x86/include/asm/mem_encrypt.h | 4 +-- arch/x86/kernel/head_64.S | 8 +----- arch/x86/mm/mem_encrypt_identity.c | 42 ++++++++++++++++-------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index b7126701574c..74f094eb88a6 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -40,7 +40,7 @@ void __init sme_early_init(void); void __init sev_setup_arch(void); void __init sme_encrypt_kernel(struct boot_params *bp); -void __init sme_enable(struct boot_params *bp); +void __init sme_enable(void); int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size); int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size); @@ -70,7 +70,7 @@ static inline void __init sme_early_init(void) { } static inline void __init sev_setup_arch(void) { } static inline void __init sme_encrypt_kernel(struct boot_params *bp) { } -static inline void __init sme_enable(struct boot_params *bp) { } +static inline void __init sme_enable(void) { } static inline void sev_es_init_vc_handling(void) { } diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index c7b2ef379f42..c6ea37712921 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -72,14 +72,11 @@ SYM_CODE_START_NOALIGN(startup_64) wrmsr leaq _text(%rip), %rdi - pushq %rsi + /* RSI contains address of real_mode_data */ call copy_bootdata - popq %rsi leaq _text(%rip), %rdi - pushq %rsi call startup_64_setup_env - popq %rsi #ifdef CONFIG_AMD_MEM_ENCRYPT /* @@ -88,10 +85,7 @@ SYM_CODE_START_NOALIGN(startup_64) * which needs to be done before any CPUID instructions are executed in * subsequent code. */ - movq %rsi, %rdi - pushq %rsi call sme_enable - popq %rsi #endif /* Now switch to __KERNEL_CS so IRET works reliably */ diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index c6efcf559d88..e75e4f5a8a71 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -502,8 +502,9 @@ void __init sme_encrypt_kernel(struct boot_params *bp) native_write_cr3(__native_read_cr3()); } -void __init sme_enable(struct boot_params *bp) +void __init sme_enable(void) { + struct boot_params *bp; const char *cmdline_ptr, *cmdline_arg, *cmdline_on, *cmdline_off; unsigned int eax, ebx, ecx, edx; unsigned long feature_mask; @@ -513,6 +514,27 @@ void __init sme_enable(struct boot_params *bp) bool snp; u64 msr; + /* + * Fixups have not been applied to phys_base yet and we're running + * identity mapped, so we must obtain the address to global data + * using rip-relative addressing. + */ + asm("lea sme_cmdline_arg(%%rip), %0" + : "=r" (cmdline_arg) + : "p" (sme_cmdline_arg)); + asm("lea sme_cmdline_on(%%rip), %0" + : "=r" (cmdline_on) + : "p" (sme_cmdline_on)); + asm("lea sme_cmdline_off(%%rip), %0" + : "=r" (cmdline_off) + : "p" (sme_cmdline_off)); + asm("lea boot_params(%%rip), %0" + : "=r" (bp) + : "m" (boot_params)); + asm("lea boot_command_line(%%rip), %0" + : "=r" (cmdline_ptr) + : "p" (boot_command_line)); + snp = snp_init(bp); /* Check for the SME/SEV support leaf */ @@ -577,29 +599,11 @@ void __init sme_enable(struct boot_params *bp) goto out; } - /* - * Fixups have not been applied to phys_base yet and we're running - * identity mapped, so we must obtain the address to the SME command - * line argument data using rip-relative addressing. - */ - asm ("lea sme_cmdline_arg(%%rip), %0" - : "=r" (cmdline_arg) - : "p" (sme_cmdline_arg)); - asm ("lea sme_cmdline_on(%%rip), %0" - : "=r" (cmdline_on) - : "p" (sme_cmdline_on)); - asm ("lea sme_cmdline_off(%%rip), %0" - : "=r" (cmdline_off) - : "p" (sme_cmdline_off)); - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT)) active_by_default = true; else active_by_default = false; - cmdline_ptr = (const char *)((u64)bp->hdr.cmd_line_ptr | - ((u64)bp->ext_cmd_line_ptr << 32)); - if (cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer)) < 0) return; -- 2.39.2