Message ID | 20221121162433.28070-1-jgross@suse.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1689871wrr; Mon, 21 Nov 2022 08:25:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf4FNrSyordxdPv2InwcqEFN+Cx6pePqe+F211ITdC6zK/68QeZq0YzbFxY7Kl8f6v8+HyKG X-Received: by 2002:a17:902:b283:b0:179:fe08:48da with SMTP id u3-20020a170902b28300b00179fe0848damr3836263plr.154.1669047925443; Mon, 21 Nov 2022 08:25:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669047925; cv=none; d=google.com; s=arc-20160816; b=yzsohlvGzKnCHWgjab1Pi6/Zc6c1yeeaK/ysknbp5bT0nxwcdY8Uf7gjlcGRl4nuiL HHfypYpXlt9fiyadje4s+69nBNw62Ad/RFBNe6KDfSG9N0M+xDMsgvUOENjfEHB0oG0i jlb1mvQsMSJ0RPnebCsNzbNqK6pQJ+1TN3ClHFeD6QzO7M1crBNy9x9+TeejdpaQZ+Fh /KW7F0SCkDc8nN2wpI8oaJswK4DSfczTamldxMZmQRLKULu0P//LuopMu193qcs7v3p1 rs5s/BPtjSRmdhLvjDa2Az7b0pgwb6Ewgs6fC1sz2jTBf342v32WB8IeJ7GoltZATBID rHqw== 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=vM7lsk8RXRK5rWKi3euFrZN65JTSYYzeLkaycP3+980=; b=v6dCOwVjiRZWOQHl2Rd2XYAG7Dxz9XS00QTKhwp5+omcyu+Mg8u48biBbo+AXVPfgK eaNQFk+LSd2a6He4Yh1Xxq0Fhxt38G7BXd10WtVjwxomEJLVcsFdUuDDGy9Fl47y44/T zVoqtcJgnvanTN7Xof/23e9zvwAADb3eaaSRSCKqf8lFveqzTsUIFKSGsg5NAjMDxSjN NBtn99PX3PAhnZPg7aukSIWibxkT4qPWUB8yPWn6wGMZZd+7z44xCzQKXP5bE7q9zMs+ 9n64YoqYyCP5FxpvhyCBbfsn4CQAuWgmd5ta9PFJJd8WtOc0bRI0mMq/iiv47fFJ4Tjf PqIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=lQb73Xmu; 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 u14-20020a170902714e00b0018916aae7cfsi4846780plm.450.2022.11.21.08.25.11; Mon, 21 Nov 2022 08:25:25 -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=lQb73Xmu; 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 S229647AbiKUQYj (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Mon, 21 Nov 2022 11:24:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiKUQYi (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 21 Nov 2022 11:24:38 -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 99ED6C8462 for <linux-kernel@vger.kernel.org>; Mon, 21 Nov 2022 08:24:36 -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 3D348220D0; Mon, 21 Nov 2022 16:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1669047875; 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=vM7lsk8RXRK5rWKi3euFrZN65JTSYYzeLkaycP3+980=; b=lQb73XmuRm9cAtopvVxw3SQmWht21QY4S171ZrLyfYCA9szFaF5WMaLQoFaaJ7cHRQwR3n nsupt0qTscoP313sDisopDmfcapC9h30V/Qz5P7dBh9GK3Kz6Px3C35142ZP3aWnXcYh2X VVD2FPS4NvnIK8XoAlO0pYandrnMQXg= 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 EB2E51377F; Mon, 21 Nov 2022 16:24:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5E3SN0Kme2NIYAAAMHmgww (envelope-from <jgross@suse.com>); Mon, 21 Nov 2022 16:24:34 +0000 From: Juergen Gross <jgross@suse.com> To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross <jgross@suse.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, "H. Peter Anvin" <hpa@zytor.com> Subject: [PATCH] x86/boot: skip realmode init code when running as Xen PV guest Date: Mon, 21 Nov 2022 17:24:33 +0100 Message-Id: <20221121162433.28070-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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750123597551160842?= X-GMAIL-MSGID: =?utf-8?q?1750123597551160842?= |
Series |
x86/boot: skip realmode init code when running as Xen PV guest
|
|
Commit Message
Juergen Gross
Nov. 21, 2022, 4:24 p.m. UTC
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).
Skip the trampoline setup code for Xen PV guests.
Fixes: 084ee1c641a0 ("x86, realmode: Relocator for realmode code")
Signed-off-by: Juergen Gross <jgross@suse.com>
---
arch/x86/include/asm/realmode.h | 4 ++--
arch/x86/realmode/init.c | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
Comments
On Mon, Nov 21, 2022 at 05:24:33PM +0100, Juergen Gross wrote: > 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). > > Skip the trampoline setup code for Xen PV guests. > > Fixes: 084ee1c641a0 ("x86, realmode: Relocator for realmode code") > Signed-off-by: Juergen Gross <jgross@suse.com> > --- > arch/x86/include/asm/realmode.h | 4 ++-- > arch/x86/realmode/init.c | 3 +++ > 2 files changed, 5 insertions(+), 2 deletions(-) > diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h > index fd6f6e5b755a..5bfce58f1bab 100644 > --- a/arch/x86/include/asm/realmode.h > +++ b/arch/x86/include/asm/realmode.h > @@ -78,8 +78,8 @@ 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. */ > + if (real_mode_header || cpu_feature_enabled(X86_FEATURE_XENPV)) > + return 0; /* already allocated or not needed. */ > > return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE); > } > diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c > index 41d7669a97ad..1826700b156e 100644 > --- a/arch/x86/realmode/init.c > +++ b/arch/x86/realmode/init.c > @@ -202,6 +202,9 @@ static void __init set_real_mode_permissions(void) > > static int __init init_real_mode(void) > { > + if (cpu_feature_enabled(X86_FEATURE_XENPV))a This reminds me of the notorious if (xen) sprinkling from years ago. Please don't do that.
On 21.11.22 20:08, Borislav Petkov wrote: > On Mon, Nov 21, 2022 at 05:24:33PM +0100, Juergen Gross wrote: >> 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). >> >> Skip the trampoline setup code for Xen PV guests. >> >> Fixes: 084ee1c641a0 ("x86, realmode: Relocator for realmode code") >> Signed-off-by: Juergen Gross <jgross@suse.com> >> --- >> arch/x86/include/asm/realmode.h | 4 ++-- >> arch/x86/realmode/init.c | 3 +++ >> 2 files changed, 5 insertions(+), 2 deletions(-) > >> diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h >> index fd6f6e5b755a..5bfce58f1bab 100644 >> --- a/arch/x86/include/asm/realmode.h >> +++ b/arch/x86/include/asm/realmode.h >> @@ -78,8 +78,8 @@ 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. */ >> + if (real_mode_header || cpu_feature_enabled(X86_FEATURE_XENPV)) >> + return 0; /* already allocated or not needed. */ >> >> return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE); >> } >> diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c >> index 41d7669a97ad..1826700b156e 100644 >> --- a/arch/x86/realmode/init.c >> +++ b/arch/x86/realmode/init.c >> @@ -202,6 +202,9 @@ static void __init set_real_mode_permissions(void) >> >> static int __init init_real_mode(void) >> { >> + if (cpu_feature_enabled(X86_FEATURE_XENPV))a > > This reminds me of the notorious if (xen) sprinkling from years ago. > Please don't do that. > Okay, what about plan B: - rework realmode/rm to: + replace header.S with main.c making it possible to initialize struct real_mode_header using the struct definition + optional: merge stack.S into main.c - include realmode/rm addresses needed outside of it in struct real_mode_header - setup a dummy struct real_mode_header in Xen PV code removing the need to skip init_real_mode(), but making it basically a nop Would you be fine with that? Juergen
On November 21, 2022 10:28:21 PM PST, Juergen Gross <jgross@suse.com> wrote: >On 21.11.22 20:08, Borislav Petkov wrote: >> On Mon, Nov 21, 2022 at 05:24:33PM +0100, Juergen Gross wrote: >>> 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). >>> >>> Skip the trampoline setup code for Xen PV guests. >>> >>> Fixes: 084ee1c641a0 ("x86, realmode: Relocator for realmode code") >>> Signed-off-by: Juergen Gross <jgross@suse.com> >>> --- >>> arch/x86/include/asm/realmode.h | 4 ++-- >>> arch/x86/realmode/init.c | 3 +++ >>> 2 files changed, 5 insertions(+), 2 deletions(-) >> >>> diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h >>> index fd6f6e5b755a..5bfce58f1bab 100644 >>> --- a/arch/x86/include/asm/realmode.h >>> +++ b/arch/x86/include/asm/realmode.h >>> @@ -78,8 +78,8 @@ 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. */ >>> + if (real_mode_header || cpu_feature_enabled(X86_FEATURE_XENPV)) >>> + return 0; /* already allocated or not needed. */ >>> return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE); >>> } >>> diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c >>> index 41d7669a97ad..1826700b156e 100644 >>> --- a/arch/x86/realmode/init.c >>> +++ b/arch/x86/realmode/init.c >>> @@ -202,6 +202,9 @@ static void __init set_real_mode_permissions(void) >>> static int __init init_real_mode(void) >>> { >>> + if (cpu_feature_enabled(X86_FEATURE_XENPV))a >> >> This reminds me of the notorious if (xen) sprinkling from years ago. >> Please don't do that. >> > >Okay, what about plan B: > >- rework realmode/rm to: > + replace header.S with main.c making it possible to initialize > struct real_mode_header using the struct definition > + optional: merge stack.S into main.c >- include realmode/rm addresses needed outside of it in struct > real_mode_header >- setup a dummy struct real_mode_header in Xen PV code removing the > need to skip init_real_mode(), but making it basically a nop > >Would you be fine with that? > > >Juergen I'm wondering if init_real_mode should not simply be part of the platform ops. It's called exactly twice per boot, it is hard to be less performance critical than that.
On 23.11.22 01:07, H. Peter Anvin wrote: > On November 21, 2022 10:28:21 PM PST, Juergen Gross <jgross@suse.com> wrote: >> On 21.11.22 20:08, Borislav Petkov wrote: >>> On Mon, Nov 21, 2022 at 05:24:33PM +0100, Juergen Gross wrote: >>>> 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). >>>> >>>> Skip the trampoline setup code for Xen PV guests. >>>> >>>> Fixes: 084ee1c641a0 ("x86, realmode: Relocator for realmode code") >>>> Signed-off-by: Juergen Gross <jgross@suse.com> >>>> --- >>>> arch/x86/include/asm/realmode.h | 4 ++-- >>>> arch/x86/realmode/init.c | 3 +++ >>>> 2 files changed, 5 insertions(+), 2 deletions(-) >>> >>>> diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h >>>> index fd6f6e5b755a..5bfce58f1bab 100644 >>>> --- a/arch/x86/include/asm/realmode.h >>>> +++ b/arch/x86/include/asm/realmode.h >>>> @@ -78,8 +78,8 @@ 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. */ >>>> + if (real_mode_header || cpu_feature_enabled(X86_FEATURE_XENPV)) >>>> + return 0; /* already allocated or not needed. */ >>>> return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE); >>>> } >>>> diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c >>>> index 41d7669a97ad..1826700b156e 100644 >>>> --- a/arch/x86/realmode/init.c >>>> +++ b/arch/x86/realmode/init.c >>>> @@ -202,6 +202,9 @@ static void __init set_real_mode_permissions(void) >>>> static int __init init_real_mode(void) >>>> { >>>> + if (cpu_feature_enabled(X86_FEATURE_XENPV))a >>> >>> This reminds me of the notorious if (xen) sprinkling from years ago. >>> Please don't do that. >>> >> >> Okay, what about plan B: >> >> - rework realmode/rm to: >> + replace header.S with main.c making it possible to initialize >> struct real_mode_header using the struct definition >> + optional: merge stack.S into main.c >> - include realmode/rm addresses needed outside of it in struct >> real_mode_header >> - setup a dummy struct real_mode_header in Xen PV code removing the >> need to skip init_real_mode(), but making it basically a nop >> >> Would you be fine with that? >> >> >> Juergen > > I'm wondering if init_real_mode should not simply be part of the platform ops. It's called exactly twice per boot, it is hard to be less performance critical than that. Actually, it is called only once. :-) Any preferences regarding the call hierarchy? I could either keep the early_initcall() and call the platform_op from that initcall, or I could introduce a small wrapper called by kernel_init_freeable(), which would be empty on all but the x86 architecture. Boris, if you agree, I can go that route. Juergen
diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h index fd6f6e5b755a..5bfce58f1bab 100644 --- a/arch/x86/include/asm/realmode.h +++ b/arch/x86/include/asm/realmode.h @@ -78,8 +78,8 @@ 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. */ + if (real_mode_header || cpu_feature_enabled(X86_FEATURE_XENPV)) + return 0; /* already allocated or not needed. */ return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE); } diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c index 41d7669a97ad..1826700b156e 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -202,6 +202,9 @@ static void __init set_real_mode_permissions(void) static int __init init_real_mode(void) { + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return 0; + if (!real_mode_header) panic("Real mode trampoline was not allocated");