devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Yunhong Jiang <yunhong.jiang@linux.intel.com>,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	x86@kernel.org, hpa@zytor.com, robh@kernel.org,
	krzk+dt@kernel.org, conor+dt@kernel.org, kys@microsoft.com,
	haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
	rafael@kernel.org, lenb@kernel.org,
	kirill.shutemov@linux.intel.com
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-hyperv@vger.kernel.org, linux-acpi@vger.kernel.org,
	yunhong.jiang@linux.intel.com
Subject: Re: [PATCH 6/7] x86/hyperv: Reserve real mode when ACPI wakeup mailbox is available
Date: Wed, 07 Aug 2024 19:33:26 +0200	[thread overview]
Message-ID: <87a5ho2q6x.ffs@tglx> (raw)
In-Reply-To: <20240806221237.1634126-7-yunhong.jiang@linux.intel.com>

On Tue, Aug 06 2024 at 15:12, Yunhong Jiang wrote:
> +static void __init hv_reserve_real_mode(void)
> +{
> +	phys_addr_t mem;
> +	size_t size = real_mode_size_needed();
> +
> +	/*
> +	 * We only need the memory to be <4GB since the 64-bit trampoline goes
> +	 * down to 32-bit mode.
> +	 */
> +	mem = memblock_phys_alloc_range(size, PAGE_SIZE, 0, SZ_4G);
> +	if (!mem)
> +		panic("No sub-4G memory is available for the trampoline\n");
> +	set_real_mode_mem(mem);
> +}

We really don't need another copy of reserve_real_mode(). See uncompiled
patch below. It does not panic when the allocation fails, but why do you
want to panic in that case? If it's not there then the system boots with
a single CPU, so what.

>  void __init hv_vtl_init_platform(void)
>  {
>  	pr_info("Linux runs in Hyper-V Virtual Trust Level\n");
>  
>  	if (wakeup_mailbox_addr) {
>  		x86_platform.hyper.is_private_mmio = hv_is_private_mmio_tdx;
> +		x86_platform.realmode_reserve = hv_reserve_real_mode;
>  	} else {
>  		x86_platform.realmode_reserve = x86_init_noop;
>  		x86_platform.realmode_init = x86_init_noop;
> @@ -259,7 +276,8 @@ int __init hv_vtl_early_init(void)
>  		panic("XSAVE has to be disabled as it is not supported by this module.\n"
>  			  "Please add 'noxsave' to the kernel command line.\n");
>  
> -	real_mode_header = &hv_vtl_real_mode_header;
> +	if (!wakeup_mailbox_addr)
> +		real_mode_header = &hv_vtl_real_mode_header;

Why is that not suffient to be done in hv_vtl_init_platform() inside the
condition which clears x86_platform.realmode_reserve/init?

x86_platform.realmode_init() is invoked from an early initcall while
hv_vtl_init_platform() is called during early boot.

Thanks,

        tglx
---
--- a/arch/x86/include/asm/x86_init.h
+++ b/arch/x86/include/asm/x86_init.h
@@ -31,12 +31,18 @@ struct x86_init_mpparse {
  *				platform
  * @memory_setup:		platform specific memory setup
  * @dmi_setup:			platform specific DMI setup
+ * @realmode_limit:		platform specific address limit for the realmode trampoline
+ *				(default 1M)
+ * @reserve_bios:		platform specific address limit for reserving the BIOS area
+ *				(default 1M)
  */
 struct x86_init_resources {
 	void (*probe_roms)(void);
 	void (*reserve_resources)(void);
 	char *(*memory_setup)(void);
 	void (*dmi_setup)(void);
+	unsigned long realmode_limit;
+	unsigned long reserve_bios;
 };
 
 /**
--- a/arch/x86/kernel/x86_init.c
+++ b/arch/x86/kernel/x86_init.c
@@ -8,6 +8,7 @@
 #include <linux/ioport.h>
 #include <linux/export.h>
 #include <linux/pci.h>
+#include <linux/sizes.h>
 
 #include <asm/acpi.h>
 #include <asm/bios_ebda.h>
@@ -68,6 +69,8 @@ struct x86_init_ops x86_init __initdata
 		.reserve_resources	= reserve_standard_io_resources,
 		.memory_setup		= e820__memory_setup_default,
 		.dmi_setup		= dmi_setup,
+		.realmode_limit		= SZ_1M,
+		.reserve_bios		= SZ_1M,
 	},
 
 	.mpparse = {
--- a/arch/x86/realmode/init.c
+++ b/arch/x86/realmode/init.c
@@ -45,7 +45,7 @@ void load_trampoline_pgtable(void)
 
 void __init reserve_real_mode(void)
 {
-	phys_addr_t mem;
+	phys_addr_t mem, limit = x86_init.resources.realmode_limit;
 	size_t size = real_mode_size_needed();
 
 	if (!size)
@@ -54,17 +54,15 @@ void __init reserve_real_mode(void)
 	WARN_ON(slab_is_available());
 
 	/* Has to be under 1M so we can execute real-mode AP code. */
-	mem = memblock_phys_alloc_range(size, PAGE_SIZE, 0, 1<<20);
+	mem = memblock_phys_alloc_range(size, PAGE_SIZE, 0, limit);
 	if (!mem)
-		pr_info("No sub-1M memory is available for the trampoline\n");
+		pr_info("No memory below %lluM for the real-mode trampoline\n", limit >> 20);
 	else
 		set_real_mode_mem(mem);
 
-	/*
-	 * Unconditionally reserve the entire first 1M, see comment in
-	 * setup_arch().
-	 */
-	memblock_reserve(0, SZ_1M);
+	/* Reserve the entire first 1M, if enabled. See comment in setup_arch(). */
+	if (x86_init.resources.reserve_bios)
+		memblock_reserve(0, x86_init.resources.reserve_bios);
 }
 
 static void __init sme_sev_setup_real_mode(struct trampoline_header *th)

  reply	other threads:[~2024-08-07 17:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06 22:12 [PATCH 0/7] x86/acpi: Move ACPI MADT wakeup to generic code Yunhong Jiang
2024-08-06 22:12 ` [PATCH 1/7] " Yunhong Jiang
2024-08-06 22:12 ` [PATCH 2/7] dt-bindings: x86: Add ACPI wakeup mailbox Yunhong Jiang
2024-08-06 23:38   ` Rob Herring (Arm)
2024-08-07 17:00     ` Yunhong Jiang
2024-08-07  5:57   ` Krzysztof Kozlowski
2024-08-07 16:56     ` Yunhong Jiang
2024-08-08  7:41       ` Krzysztof Kozlowski
2024-08-09 23:29         ` Yunhong Jiang
2024-08-06 22:12 ` [PATCH 3/7] x86/dt: Support the ACPI multiprocessor wakeup for device tree Yunhong Jiang
2024-08-07 16:50   ` Thomas Gleixner
2024-08-06 22:12 ` [PATCH 4/7] x86/hyperv: Parse the ACPI wakeup mailbox Yunhong Jiang
2024-08-06 22:12 ` [PATCH 5/7] x86/hyperv: Mark ACPI wakeup mailbox page as private Yunhong Jiang
2024-08-07 16:59   ` Thomas Gleixner
2024-08-09 23:17     ` Yunhong Jiang
2024-08-06 22:12 ` [PATCH 6/7] x86/hyperv: Reserve real mode when ACPI wakeup mailbox is available Yunhong Jiang
2024-08-07 17:33   ` Thomas Gleixner [this message]
2024-08-24  0:17     ` Yunhong Jiang
2024-08-06 22:12 ` [PATCH 7/7] x86/hyperv: Use the ACPI wakeup mailbox for VTL2 guests when available Yunhong Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a5ho2q6x.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=bp@alien8.de \
    --cc=conor+dt@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=devicetree@vger.kernel.org \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=krzk+dt@kernel.org \
    --cc=kys@microsoft.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    --cc=yunhong.jiang@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).