From patchwork Tue Jun 13 23:39:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 107625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp893581vqr; Tue, 13 Jun 2023 16:48:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ44c8gZvZXXP/vHqMfdG+5fkFZSJXF+nhiz0siWjlQZLOnYIjapM0Utg2I14U3b+sBUFtHR X-Received: by 2002:a17:906:fd8e:b0:974:1eeb:1ab7 with SMTP id xa14-20020a170906fd8e00b009741eeb1ab7mr15001438ejb.24.1686700093822; Tue, 13 Jun 2023 16:48:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686700093; cv=none; d=google.com; s=arc-20160816; b=mN1yE4qgBftBAhoyRycB9ckqP9aAkYieq5yJE3B+QUvwH2T34lCcwdAmGN0aCgBWQG NKEx9BAgQaj3PhxFLvopH6hjT9OWW5WmyJeGhWpQP6SlSNRL9SDwSrbNk9YfRzedLNRp jYDBeYRq4PPnG6CPsD7tuthWVuhVipp3JBl3r6QKEiH51EQ6uvKEp1ycmf3ZM9Zhy7TY xrIjw3+rgxISuz5gbdukiDl11K5BTK930IfR2Icuf1hAg2lgG5uFG7XTqeCTBV4nx0Ow ejMPIul9cv3hjKQZy4dfsDtxTW8lSxlev6t2vAAszcGx861lI1JQNxYRu8O+gut1Bh39 fiGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=lNQFIv9giVxLbCumZPShd6fBwItl7AKDfIjQdD1B1ok=; b=CwPpTsPdmHafpX9jBmGF+JUhHQEgF8lZek0N5HqtrYp4Jmsvz5F1TZDs4FquWrU6R9 CFTcFlWbJ8eJnsGlqHR6rplFlzuYdxEqJoxfqlFi3VaUH4A0Z47LubWxDup75Bzp/Zse BwYIjZm3IPiANHnEDMgwO61QSO4mHo4Uz7KhhFUmnycgzXj9KlKpJnjyMqkkJUE84ZjB rWKC+JMsPFZanqzWHh1dLXmAdQAirn09wtSoYc1cLNVdvWLNkXtSMdc1+y4W8r7ckQaG 8h6kKGyzHdgH3lo8P+rMX569XrOPSjBY/olIiLa+TgwtJuozvgWl0fPgZakWcbMYv1JG 4+Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NhwOjp0v; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=gfCfRi6t; 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=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx22-20020a170906af1600b00973c1e1bc46si7055836ejb.616.2023.06.13.16.47.49; Tue, 13 Jun 2023 16:48:13 -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=@linutronix.de header.s=2020 header.b=NhwOjp0v; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=gfCfRi6t; 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=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241578AbjFMXlM (ORCPT + 99 others); Tue, 13 Jun 2023 19:41:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241562AbjFMXkF (ORCPT ); Tue, 13 Jun 2023 19:40:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 126CD2108; Tue, 13 Jun 2023 16:39:43 -0700 (PDT) Message-ID: <20230613224545.670360645@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686699581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=lNQFIv9giVxLbCumZPShd6fBwItl7AKDfIjQdD1B1ok=; b=NhwOjp0vdKWOrteRuFiTOkExTiGFZ+1X3uZu8Sf9fdyrIPm2q/gN4MmPHkCZJSMuDFIyau 62b1YEZwJdmoo/8iAGDMB+f2rfpJWTxhz280VlrOWuVI8kMlClaNhFnA/HnrvxfThhq2Y7 LrmEMnVJ5d25Djkc3MZjVW/Fmz2axOYQ++mr4C8i7V8xhsVuiDO0UcuAgoIZ2LkpjNgGiP 7dqi2bz7PCyBpzzyh/htAgssbDnwJDTyEbGU2gqgSCoXYtobvOXRW69yEXXCETLnzJzHvQ dbG14Dx6omVuOO5nyZKPQvEOw9jwwdikXGwasbUA2D71OPAp4CjnptBqSSwaHw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686699581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=lNQFIv9giVxLbCumZPShd6fBwItl7AKDfIjQdD1B1ok=; b=gfCfRi6taulCsvO42taqM4pd4hXtC0EjIZYTeRqyo9lKyT8xnwcJ0CXF+9O/JENzPKmB+i pT1TJrwh+wATGyAA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Linus Torvalds , Nikolay Borisov , "Ahmed S. Darwish" , Arnd Bergmann , Tom Lendacky , Russell King , linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org, Thomas Bogendoerfer , linux-mips@vger.kernel.org, Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , linux-sh@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org, Richard Henderson , "James E.J. Bottomley" , Michael Ellerman , Chris Zankel Subject: [patch 13/17] init, x86: Move mem_encrypt_init() into arch_cpu_finalize_init() References: <20230613223827.532680283@linutronix.de> MIME-Version: 1.0 Date: Wed, 14 Jun 2023 01:39:41 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768633237326742715?= X-GMAIL-MSGID: =?utf-8?q?1768633237326742715?= Invoke the X86ism mem_encrypt_init() from X86 arch_cpu_finalize_init() and remove the weak fallback from the core code. No functional change. Signed-off-by: Thomas Gleixner Cc: Tom Lendacky Reviewed-by: Tom Lendacky --- arch/x86/include/asm/mem_encrypt.h | 7 ++++--- arch/x86/kernel/cpu/common.c | 11 +++++++++++ init/main.c | 13 ------------- 3 files changed, 15 insertions(+), 16 deletions(-) --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -51,6 +51,8 @@ void __init mem_encrypt_free_decrypted_m void __init sev_es_init_vc_handling(void); +void __init mem_encrypt_init(void); + #define __bss_decrypted __section(".bss..decrypted") #else /* !CONFIG_AMD_MEM_ENCRYPT */ @@ -83,13 +85,12 @@ early_set_mem_enc_dec_hypercall(unsigned static inline void mem_encrypt_free_decrypted_mem(void) { } +static inline void mem_encrypt_init(void) { } + #define __bss_decrypted #endif /* CONFIG_AMD_MEM_ENCRYPT */ -/* Architecture __weak replacement functions */ -void __init mem_encrypt_init(void); - void add_encrypt_protection_map(void); /* --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -2417,4 +2418,14 @@ void __init arch_cpu_finalize_init(void) } else { fpu__init_check_bugs(); } + + /* + * This needs to be called before any devices perform DMA + * operations that might use the SWIOTLB bounce buffers. It will + * mark the bounce buffers as decrypted so that their usage will + * not cause "plain-text" data to be decrypted when accessed. It + * must be called after late_time_init() so that Hyper-V x86/x64 + * hypercalls work when the SWIOTLB bounce buffers are decrypted. + */ + mem_encrypt_init(); } --- a/init/main.c +++ b/init/main.c @@ -95,7 +95,6 @@ #include #include #include -#include #include #include #include @@ -786,8 +785,6 @@ void __init __weak thread_stack_cache_in } #endif -void __init __weak mem_encrypt_init(void) { } - void __init __weak poking_init(void) { } void __init __weak pgtable_cache_init(void) { } @@ -1043,16 +1040,6 @@ asmlinkage __visible void __init __no_sa arch_cpu_finalize_init(); - /* - * This needs to be called before any devices perform DMA - * operations that might use the SWIOTLB bounce buffers. It will - * mark the bounce buffers as decrypted so that their usage will - * not cause "plain-text" data to be decrypted when accessed. It - * must be called after late_time_init() so that Hyper-V x86/x64 - * hypercalls work when the SWIOTLB bounce buffers are decrypted. - */ - mem_encrypt_init(); - pid_idr_init(); anon_vma_init(); #ifdef CONFIG_X86