Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7254843rwb; Wed, 23 Nov 2022 04:24:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf6bTyq7saXzKzQGzKA9XexA+EK8ZwWOMjNDPWwv0CbcBGerliocSE2bgZCyRKhE/8Jx49nq X-Received: by 2002:a05:6a00:cd5:b0:56d:7aaa:f1ea with SMTP id b21-20020a056a000cd500b0056d7aaaf1eamr9377251pfv.69.1669206249479; Wed, 23 Nov 2022 04:24:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669206249; cv=none; d=google.com; s=arc-20160816; b=H/kYGTCuXbSa3sD5mESUXlPB76tDAG9UicUqfY8tAQrPAXzgW0QTkr+rkuEX437zYW Ea30bXxFx+5lh9kOrtQhghsjdcY2C0uVIOsgpId/ipuhKZX2Nv0vqpgh0vWBVJfaomEg L3+Rf/V2NZzA9R1sy8NJ8fxpClBZ+i75tWWEeztiML1M+vTISLUzbZ9PmZmSzLAIzLAj lwfmZKRsOKVz8YsmvWQIqzWhrAaFKYC0jAI9bCJjHUB+JaQy9fe422hlAfStzC/0jaI+ sEQUVOY5bA0PaehFI/+Kew9MuhlpgVY6fqqrMuTfhfXoZMsJ5KnlXPhjwTbjPb0DMvrq KipQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=AyhBQAsNxho2kk1GfKGx6zDLyWYyV1QLz+gDG7NJTZA=; b=ex8V1eHrb2Fyov6aIY0NuG+32WlXpTWfk1pdWbL3l8MczliQ9s8VmeLdD//J4rd+s1 hFhTT0SzrvwFjzLOvQYcQVDkqiGnBq9VrHETIZDbGtz3MAlEa2s3SYPEQcFCWaTdOnfp vnbL25kuEAE0de60slaxSX8czvCkL5MrO4+4QVL2wIwTgUnIbDxsQFyMmmokkQEs7agr b27vhcosmZjkrmciiVpeMYgSLyOOgK6sjmdunDgVEDW5QoTHZMF0/7IfWV9FcZDou/2r QUYmxx1KFxcyqxllgfh9y6jWQJ2/sEQ/VYb0R004TJH/+JJInTWiHFCEckVD9S5wE7u6 z4GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Zkn7ZzDp; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a11-20020a17090a854b00b00215dedefc32si1466746pjw.163.2022.11.23.04.23.57; Wed, 23 Nov 2022 04:24:09 -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=Zkn7ZzDp; 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 S237032AbiKWLpc (ORCPT + 89 others); Wed, 23 Nov 2022 06:45:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237217AbiKWLp1 (ORCPT ); Wed, 23 Nov 2022 06:45:27 -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 A1B611255DB for ; Wed, 23 Nov 2022 03:45:26 -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 48CE221F33; Wed, 23 Nov 2022 11:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1669203925; 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; bh=AyhBQAsNxho2kk1GfKGx6zDLyWYyV1QLz+gDG7NJTZA=; b=Zkn7ZzDpoCCf/JgfLleT4uX7j1LVB22KCBz2YLwsoyCKxzEJYFLn6dS2KCoYG/ZDbmrWKd M6vUekyG/a2ld98xp97yxvtjLIwhLz4IRtOgVFz2nFKxZyiNNfQBdi3lyMXNpdB8zeg/Yc ejYMSHpqTF7xKsKSpz0Z4TJdktOrVNE= 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 E31CB13A37; Wed, 23 Nov 2022 11:45:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6+UDNtQHfmPTUwAAMHmgww (envelope-from ); Wed, 23 Nov 2022 11:45:24 +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 v3] x86/boot: skip realmode init code when running as Xen PV guest Date: Wed, 23 Nov 2022 12:45:23 +0100 Message-Id: <20221123114523.3467-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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). Introduce new x86_platform_ops operations for that purpose, which can be set to a nop by the Xen PV specific kernel boot code. Fixes: 084ee1c641a0 ("x86, realmode: Relocator for realmode code") Suggested-by: H. Peter Anvin Signed-off-by: Juergen Gross --- V3: - and yet another approach (H. Peter Anvin) --- arch/x86/include/asm/realmode.h | 1 + arch/x86/include/asm/x86_init.h | 4 ++++ arch/x86/kernel/setup.c | 2 +- arch/x86/kernel/x86_init.c | 3 +++ arch/x86/realmode/init.c | 8 ++++++-- arch/x86/xen/enlighten_pv.c | 2 ++ 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h index fd6f6e5b755a..a336feef0af1 100644 --- a/arch/x86/include/asm/realmode.h +++ b/arch/x86/include/asm/realmode.h @@ -91,6 +91,7 @@ static inline void set_real_mode_mem(phys_addr_t mem) void reserve_real_mode(void); void load_trampoline_pgtable(void); +void init_real_mode(void); #endif /* __ASSEMBLY__ */ diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index e9170457697e..c1c8c581759d 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -285,6 +285,8 @@ struct x86_hyper_runtime { * possible in x86_early_init_platform_quirks() by * only using the current x86_hardware_subarch * semantics. + * @realmode_reserve: reserve memory for realmode trampoline + * @realmode_init: initialize realmode trampoline * @hyper: x86 hypervisor specific runtime callbacks */ struct x86_platform_ops { @@ -301,6 +303,8 @@ struct x86_platform_ops { void (*apic_post_init)(void); struct x86_legacy_features legacy; void (*set_legacy_features)(void); + void (*realmode_reserve)(void); + void (*realmode_init)(void); struct x86_hyper_runtime hyper; struct x86_guest guest; }; diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 216fee7144ee..892609cde4a2 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -1175,7 +1175,7 @@ void __init setup_arch(char **cmdline_p) * Moreover, on machines with SandyBridge graphics or in setups that use * crashkernel the entire 1M is reserved anyway. */ - reserve_real_mode(); + x86_platform.realmode_reserve(); init_mem_mapping(); diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index 57353519bc11..ef80d361b463 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -25,6 +25,7 @@ #include #include #include +#include void x86_init_noop(void) { } void __init x86_init_uint_noop(unsigned int unused) { } @@ -145,6 +146,8 @@ struct x86_platform_ops x86_platform __ro_after_init = { .get_nmi_reason = default_get_nmi_reason, .save_sched_clock_state = tsc_save_sched_clock_state, .restore_sched_clock_state = tsc_restore_sched_clock_state, + .realmode_reserve = reserve_real_mode, + .realmode_init = init_real_mode, .hyper.pin_vcpu = x86_op_int_noop, .guest = { diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c index 41d7669a97ad..247aca9f8ed1 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -200,14 +200,18 @@ static void __init set_real_mode_permissions(void) set_memory_x((unsigned long) text_start, text_size >> PAGE_SHIFT); } -static int __init init_real_mode(void) +void __init init_real_mode(void) { if (!real_mode_header) panic("Real mode trampoline was not allocated"); setup_real_mode(); set_real_mode_permissions(); +} +static int __init call_init_real_mode(void) +{ + x86_platform.realmode_init(); return 0; } -early_initcall(init_real_mode); +early_initcall(call_init_real_mode); diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 038da45f057a..8944726255c9 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -1266,6 +1266,8 @@ asmlinkage __visible void __init xen_start_kernel(struct start_info *si) xen_vcpu_info_reset(0); x86_platform.get_nmi_reason = xen_get_nmi_reason; + x86_platform.realmode_reserve = x86_init_noop; + x86_platform.realmode_init = x86_init_noop; x86_init.resources.memory_setup = xen_memory_setup; x86_init.irqs.intr_mode_select = x86_init_noop; -- 2.35.3