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) - From patchwork Tue Nov 22 16:38:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 24468 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2320534wrr; Tue, 22 Nov 2022 08:43:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf7LtVjF+SNt9tQ0bxwbTd7+NDl+ZezYoSiXbfgsY7iVoAJ/Yk07FrM65u5AEOkV3hMgZ5tx X-Received: by 2002:a63:230e:0:b0:43b:f03d:b0fe with SMTP id j14-20020a63230e000000b0043bf03db0femr4159579pgj.338.1669135397191; Tue, 22 Nov 2022 08:43:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669135397; cv=none; d=google.com; s=arc-20160816; b=eZVphW3XTjRHeOErFwIuDEgf7jsznAR3Q9NDnOyUDnHrTaG+KzOZtXdiQL60cytFNE GHlu7opeRocA+QwSwNNlyyobWwyQk8VggE8i4ovbssLoBSUED6Xs0xAz1pM52LZBf4b8 CNnUIKs9Gk37vsphGA2mM2V17uQObIbAhi+cpGE1AKViJ5rjqCu+Ra0ZnhKoEMoz0njl cEV7wciJM3fHk3CU85xZ/XWevXtY+Ai3/RTTNOj0BwTeAmuKxfEUhIYGnC1/VGph9eJH +8twK+Q/UGSWhiSsg4KfWvvuMWzT4i0KxbYIJlEYBugQxQ9c2UTZ5QKJ5jGBKbbR1oPy ByUg== 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=+I+NFNsrgPcwpbYEM36avO5tqcTUKJxcOE3LZCYPOzk=; b=P1xc5CU2I3X3IsdEccKgOjDSjZ/4KvoZk/ZDsCiTXgPpPdfdaxrDLYOyUosVcndHnK vqVnk1qKiHpkbG7No/7PxwRbogBKKl2K3Y0gf9i0Qk5nwfAw54edGsOmyiC29aHDks+I r+TKGJ4TAFjTlGblv0eCorPZXmhzHYHSZKxVB3f+hCBPKcCLPbfwzDCiSLYHWlQ+m6NM 2PGWsRlEswnFmhccYWM1e3/3WgG9OrDX70+Wm0oDn2F0c625AqaBuaPNnSR/Zh0WnWFA EmM4iEs9f2HKopbhy86bghLUinX3bKNRzeb3cJ+pHGmVRumhmQIC8J6s8OmXCZSH1jhw ZfUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=mIeCRU+e; 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 x2-20020a170902ec8200b001781e393237si771507plg.443.2022.11.22.08.42.59; Tue, 22 Nov 2022 08:43:17 -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=mIeCRU+e; 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 S234272AbiKVQie (ORCPT + 99 others); Tue, 22 Nov 2022 11:38:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233162AbiKVQi3 (ORCPT ); Tue, 22 Nov 2022 11:38:29 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10B101F2E4 for ; Tue, 22 Nov 2022 08:38:27 -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-out1.suse.de (Postfix) with ESMTPS id D479D220D2; Tue, 22 Nov 2022 16:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1669135105; 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=+I+NFNsrgPcwpbYEM36avO5tqcTUKJxcOE3LZCYPOzk=; b=mIeCRU+eOEDZ+OxRe+gCqjBZczpRwBm/KW58ozh1UH86f5tQUWNDvcunZtdRU/vZhsghVv 5Qyx86hbts/r7eOFaBgz4LnhJvZifALmN1l/dwRLsQGJ6xZYKkZhA/NnS2QQQOLKWFa25m bI3AF5u5BQU60zoM+MW/P+MiIhpuBwA= 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 974BC13AA1; Tue, 22 Nov 2022 16:38:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8I+QIwH7fGM0PgAAMHmgww (envelope-from ); Tue, 22 Nov 2022 16:38:25 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 2/3] x86/realmode: add trampoline reference structure Date: Tue, 22 Nov 2022 17:38:09 +0100 Message-Id: <20221122163810.29752-3-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?1750215318351125867?= X-GMAIL-MSGID: =?utf-8?q?1750215318351125867?= Add a new struct trampoline_ref containing the relevant pointers for handling the realmode trampoline. Use a central pointer for accessing this new structure in preparation of adding support of replacing it with a dummy trampoline. Signed-off-by: Juergen Gross --- arch/x86/include/asm/realmode.h | 12 +++++++++++- arch/x86/realmode/init.c | 13 +++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h index 1eb3d4232e81..778d6cb1db6c 100644 --- a/arch/x86/include/asm/realmode.h +++ b/arch/x86/include/asm/realmode.h @@ -14,6 +14,13 @@ #include #include +/* Pointers for installing the realmode trampoline. */ +struct trampoline_ref { + unsigned char *blob; + unsigned char *blob_end; + unsigned char *relocs; +}; + /* This must match data at realmode/rm/header.S */ struct real_mode_header { u32 text_start; @@ -56,6 +63,8 @@ struct trampoline_header { }; extern struct real_mode_header *real_mode_header; +extern struct trampoline_ref *real_mode_trampoline __initdata; + extern unsigned char real_mode_blob_end[]; extern unsigned long initial_code; @@ -78,7 +87,8 @@ extern unsigned char secondary_startup_64_no_verify[]; static inline size_t real_mode_size_needed(void) { - return PAGE_ALIGN(real_mode_blob_end - real_mode_blob); + return PAGE_ALIGN(real_mode_trampoline->blob_end - + real_mode_trampoline->blob); } static inline void set_real_mode_mem(phys_addr_t mem) diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c index 37a3658efaa0..5a670a9ed2f7 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -12,6 +12,15 @@ #include struct real_mode_header *real_mode_header; + +static __initdata struct trampoline_ref realmode_trampoline = { + .blob = real_mode_blob, + .blob_end = real_mode_blob_end, + .relocs = real_mode_relocs, +}; + +struct trampoline_ref *real_mode_trampoline __initdata = &realmode_trampoline; + u32 *trampoline_cr4_features; /* Hold the pgd entry used on booting additional CPUs */ @@ -111,12 +120,12 @@ static void __init setup_real_mode(void) if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) set_memory_decrypted((unsigned long)base, size >> PAGE_SHIFT); - memcpy(base, real_mode_blob, size); + memcpy(base, real_mode_trampoline->blob, size); phys_base = __pa(base); real_mode_seg = phys_base >> 4; - rel = (u32 *) real_mode_relocs; + rel = (u32 *) real_mode_trampoline->relocs; /* 16-bit segment relocations. */ count = *rel++; From patchwork Tue Nov 22 16:38:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 24471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2323664wrr; Tue, 22 Nov 2022 08:49:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf52S5S7MSpp/ZWff+7CcrLLJQH4PkruAVylTDOczul9+/bQyQk/HBdxjZP5HSALQ9B2JP7n X-Received: by 2002:a05:6402:1f87:b0:468:7df:c38c with SMTP id c7-20020a0564021f8700b0046807dfc38cmr21729164edc.150.1669135774671; Tue, 22 Nov 2022 08:49:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669135774; cv=none; d=google.com; s=arc-20160816; b=T/f7xihoWKxjyDCCFvV2AEvp2bdJNXwKFpBeMoeWdTygTTMeYqOsH0sbrlPnju1WoC /C5Orrk+Qibqd8d5/XjuOr2zk0OA8bL/5QvTKYNnzsU+7nDWWmuNHTzUTFMVNU+yrnFv ir3II9ZMLIV8K7vimeqKkTww+l275jydoWTW8TPtKCVhnv74UhZtZ6jWY8F6ImPPib95 rsNeoNeFftZ9W/6onEVkgihay4qpOzCWJlRPPzmxA/xUeEn/sLNLZDAVeZO7+yqLg8FT OJQgX01lxCZlK+lv8ugsJYN2aV1pRXwlx7iPH83jsZVxneUSbtt/w4CS8SJMI/Si+kF6 Elvg== 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=W81+a3w29o+2kJo/uKGKHkjczRGs9DSxwdSixl+/5NM=; b=F/Jt3UsAgeApxEfGus7tTg2JoksWf5gmiruVOoUdwI6fWb8YaUiP1O30voPahPOom0 XG5Mb5ZGr8RfYivPz6UzpnXgUUUsMFyn+7PLcuWqQFoXmfXeDjsPwp8agVrxqPsNFq/t //WBObhFlOAoeLTLB9m2nEqO0kgTMNQByMJP/l+YOXIRarlh+o+tVFJKBkg1mKl/5vdE KVRCQPemZW5qSu3W7atcsZiFv1GmUr7m3DngQrPVorRaROXnydW+WdJGaL85gDnoGJV/ WT+LRNpDuauL7sMXlpqfxY4F5Wz4A6Rm+27Oa1zursd3amofbsgc6b/9AYkzC4ZN0vpW S4Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ffdpOp0+; 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 dp17-20020a170906c15100b007aeec2bf18esi12450154ejc.529.2022.11.22.08.49.09; Tue, 22 Nov 2022 08:49:34 -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=ffdpOp0+; 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 S234322AbiKVQim (ORCPT + 99 others); Tue, 22 Nov 2022 11:38:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234312AbiKVQif (ORCPT ); Tue, 22 Nov 2022 11:38:35 -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 D4C1F1DDEF for ; Tue, 22 Nov 2022 08:38:32 -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 8E9571F86C; Tue, 22 Nov 2022 16:38:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1669135111; 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=W81+a3w29o+2kJo/uKGKHkjczRGs9DSxwdSixl+/5NM=; b=ffdpOp0+DsrHVZg8DrFMLNS7LXGnNIErwkB8BlJypLISgN8W9iGkeM7HIK10YTkOSpFqti pgU9/Yo32npE4wwk3YyPZs7oaRSNolja4Mz2ZfRz198hqR3BYTFqlZFdnS3P5wKS9+v8Mp 5K+UqxdHbt3Zlq2PMITyuUNGwM6uXyU= 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 42D6413AA1; Tue, 22 Nov 2022 16:38:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id stvRDgf7fGM7PgAAMHmgww (envelope-from ); Tue, 22 Nov 2022 16:38:31 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Boris Ostrovsky , xen-devel@lists.xenproject.org Subject: [PATCH v2 3/3] x86/xen: add a dummy trampoline for Xen PV guests Date: Tue, 22 Nov 2022 17:38:10 +0100 Message-Id: <20221122163810.29752-4-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?1750215713651525667?= X-GMAIL-MSGID: =?utf-8?q?1750215713651525667?= When running as a Xen PV guest there is no need for setting up the realmode trampoline, as realmode isn't supported in this environment. Trying to setup the trampoline has been proven to be problematic in some cases, especially when trying to debug early boot problems with Xen requiring to keep the EFI boot-services memory mapped (some firmware variants seem to claim basically all memory below 1M for boot services). Setup a dummy trampoline in order to make init_real_mode() happy. In order to avoid too tight coupling between the Xen PV specific code and the trampoline handling, modify the trampoline handling to do nothing if the detected trampoline size is 0. Fixes: 084ee1c641a0 ("x86, realmode: Relocator for realmode code") Signed-off-by: Juergen Gross --- arch/x86/realmode/init.c | 6 ++++++ arch/x86/xen/enlighten_pv.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c index 5a670a9ed2f7..538328ce5ff5 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -110,6 +110,9 @@ static void __init setup_real_mode(void) int i; #endif + if (!size) + return; + base = (unsigned char *)real_mode_header; /* @@ -204,6 +207,9 @@ static void __init set_real_mode_permissions(void) unsigned long text_start = (unsigned long) __va(real_mode_header->text_start); + if (!size) + return; + set_memory_nx((unsigned long) base, size >> PAGE_SHIFT); set_memory_ro((unsigned long) base, ro_size >> PAGE_SHIFT); set_memory_x((unsigned long) text_start, text_size >> PAGE_SHIFT); diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 038da45f057a..a6194a6a6806 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -71,6 +71,7 @@ #include #include #include +#include #ifdef CONFIG_X86_IOPL_IOPERM #include #endif @@ -137,12 +138,28 @@ static void __init xen_pv_init_platform(void) xen_init_time_ops(); } +static struct real_mode_header xen_rm_header; + +static __initdata struct trampoline_ref xen_dummy_trampoline = { + .blob = (unsigned char *)&xen_rm_header, + .blob_end = (unsigned char *)&xen_rm_header, +}; + +/* Setup dummy trampoline of size 0 with no relocations. */ +static void __init xen_setup_trampoline(void) +{ + real_mode_header = &xen_rm_header; + real_mode_trampoline = &xen_dummy_trampoline; +} + static void __init xen_pv_guest_late_init(void) { #ifndef CONFIG_SMP /* Setup shared vcpu info for non-smp configurations */ xen_setup_vcpu_info_placement(); #endif + + xen_setup_trampoline(); } static __read_mostly unsigned int cpuid_leaf5_ecx_val;