From patchwork Tue Nov 22 16:38:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 24469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2321300wrr; Tue, 22 Nov 2022 08:44:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf6VEEhFtpOjusn9esPTlZ/Ej8oFtMPL5VkxMDcxBJ3nyGXj9kQzQKwHVpBZL4p6myAKIq5q X-Received: by 2002:a17:902:b942:b0:187:1b89:52da with SMTP id h2-20020a170902b94200b001871b8952damr8237392pls.172.1669135491085; Tue, 22 Nov 2022 08:44:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669135491; cv=none; d=google.com; s=arc-20160816; b=mNsCSMINKhv/6YyHFScz0T/N0cvI9xb7NujqWfBOT3H4Fj83WFc0uzT7Voqbx0KZaD /Y5dkfm2jLfLSs6k9xAOisRxLAwg+XO2YIkc91DCcxzEd3i1dMQa+qDWB3FM6ydMG74Q 6aLpXBPda3Cm7Z/NXgHBPJrAYLXojFTCfT5dnqtO265WI6thF4GceTCAUcXHo70mPDVq +mWaw8DECrZDaqGSGLweO2QhqrJQTlqp2OYEAbOyHFhJupmivtV1Mcq9N08sN7tCD2Ko KmnemebO1T8XBwR54BqLLlwuh69CnBAnZdoipA1CRxvLzmZZnCuFXquW+LgPSu0weL02 ZpKQ== 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=ijZzk37OXai+jGE+66RqH2CbOPjTrghJ/VVtjn87O6o=; b=DKue4dEfNMydFK8VI5uhQI2XbjMU+2/P9C6/uNNnqIkV61lJAsY8NRK+RwRR+y6o/E 0uMfTiP/WIxYEpFHqE85bSK2rXgYc5WRu91pBHsHhtq+rCQksm3vEDWseSBJXcUCc61E hFSTAVjdLH8WJNYlRy+2WHVBVE8jLF1A+ziX/HZ8wqbyBT4sYFZKGA9lVKMXcfe7Cbf8 sqMJgRkGE4ScLZFCej64xcFLxH8wObHc9yNu0u0VJi06R0NndxGVie+0rTaFE1FHzGER HIQeTpcmzQEXtsMdt4Le2+q6Rj5M4+Ej1etwAixJ7osKeLitCEfh0q5djoGL6v1M3u+w SraQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=XioRDaqY; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m11-20020a170902db0b00b0018919169bc4si8837137plx.430.2022.11.22.08.44.37; Tue, 22 Nov 2022 08:44:51 -0800 (PST) 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=@suse.com header.s=susede1 header.b=XioRDaqY; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233983AbiKVQiZ (ORCPT + 99 others); Tue, 22 Nov 2022 11:38:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234269AbiKVQiX (ORCPT ); Tue, 22 Nov 2022 11:38:23 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CBEF1F629; Tue, 22 Nov 2022 08:38:21 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 387B21F86B; Tue, 22 Nov 2022 16:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1669135100; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ijZzk37OXai+jGE+66RqH2CbOPjTrghJ/VVtjn87O6o=; b=XioRDaqYtGYbNEWh/ik6eRxv0gzn3AnafIr6/RKaxSGQxsRaIU+yR3G+bTNKuRfJDUQV1t DiF0dXt5wE1/eK/HbLWuXYWHcWAofp3zL+V77IALMa2StJ3omO/efbwi1tbBIFoeB5FU0u /YzzK5LAVtXuZtCjvg04QfQ6xewmQhk= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D190E13AA1; Tue, 22 Nov 2022 16:38:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id lpDPMfv6fGMXPgAAMHmgww (envelope-from ); Tue, 22 Nov 2022 16:38:19 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ard Biesheuvel , Darren Hart , Andy Shevchenko Subject: [PATCH v2 1/3] x86/realmode: test real_mode_header outside of real_mode_size_needed() Date: Tue, 22 Nov 2022 17:38:08 +0100 Message-Id: <20221122163810.29752-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221122163810.29752-1-jgross@suse.com> References: <20221122163810.29752-1-jgross@suse.com> MIME-Version: 1.0 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750215417141371779?= X-GMAIL-MSGID: =?utf-8?q?1750215417141371779?= Move the test for the realmode trampoline memory having been allocated already to the callers of real_mode_size_needed(). This allows to use that function in setup_real_mode() and set_real_mode_permissions(), too. While at it change the size calculation to use PAGE_ALIGN() instead of open coding it. Signed-off-by: Juergen Gross --- arch/x86/include/asm/realmode.h | 5 +---- arch/x86/platform/efi/quirks.c | 3 ++- arch/x86/realmode/init.c | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h index fd6f6e5b755a..1eb3d4232e81 100644 --- a/arch/x86/include/asm/realmode.h +++ b/arch/x86/include/asm/realmode.h @@ -78,10 +78,7 @@ extern unsigned char secondary_startup_64_no_verify[]; static inline size_t real_mode_size_needed(void) { - if (real_mode_header) - return 0; /* already allocated. */ - - return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE); + return PAGE_ALIGN(real_mode_blob_end - real_mode_blob); } static inline void set_real_mode_mem(phys_addr_t mem) diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index b0b848d6933a..7c18ca720eee 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -445,7 +445,8 @@ void __init efi_free_boot_services(void) * panicking early.) */ rm_size = real_mode_size_needed(); - if (rm_size && (start + rm_size) < (1<<20) && size >= rm_size) { + if (!real_mode_header && rm_size && + (start + rm_size) < (1<<20) && size >= rm_size) { set_real_mode_mem(start); start += rm_size; size -= rm_size; diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c index 41d7669a97ad..37a3658efaa0 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -48,7 +48,7 @@ void __init reserve_real_mode(void) phys_addr_t mem; size_t size = real_mode_size_needed(); - if (!size) + if (real_mode_header || !size) return; WARN_ON(slab_is_available()); @@ -94,7 +94,7 @@ static void __init setup_real_mode(void) unsigned char *base; unsigned long phys_base; struct trampoline_header *trampoline_header; - size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob); + size_t size = real_mode_size_needed(); #ifdef CONFIG_X86_64 u64 *trampoline_pgd; u64 efer; @@ -182,7 +182,7 @@ static void __init setup_real_mode(void) static void __init set_real_mode_permissions(void) { unsigned char *base = (unsigned char *) real_mode_header; - size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob); + size_t size = real_mode_size_needed(); size_t ro_size = PAGE_ALIGN(real_mode_header->ro_end) -