From nobody Fri Apr 19 09:11:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1578570746; cv=none; d=zohomail.com; s=zohoarc; b=Rz06C7v9kHYOlnR39lDDES/zU26nneo5UGn7WQQCeXiiCGv+lCUXxQYc6RHLZi1V1Qk4azg9cmUJTjzqheOe14yErZIOfajGVZEK+PT+BLIc4/WDpSe8zEyyay7uKA9SfkMed6PFeGop3BJTHjWh1IrkUdKyjkW03U+lnjmQbb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578570746; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CtqaCWGrzzwixRFV58fLCWwSE9XbQMcx4OCRN5pE3Kw=; b=oDjZVMADuEUC7Cd4GF6psLtBRE5ekOtaHZ9yJEAEvLM/4wknjm9Tfpg+f7f5Xmfse3zrZeR+lXE3716tQ+rjopgzFrSD84D3ykNjFJhQHgE4oGug3EjxP9RYTfUCMtTCXiZmywu3nkyY39yuFVv9nmL1s95bHNslFSN+WyVaaOE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1578570746309392.922699773605; Thu, 9 Jan 2020 03:52:26 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipWLn-0001bm-Gj; Thu, 09 Jan 2020 11:51:43 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipWLl-0001ba-Sc for xen-devel@lists.xenproject.org; Thu, 09 Jan 2020 11:51:41 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 659ffc40-32d6-11ea-b9ab-12813bfff9fa; Thu, 09 Jan 2020 11:51:40 +0000 (UTC) X-Inumbo-ID: 659ffc40-32d6-11ea-b9ab-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1578570700; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F/gXdzQ7+mkv3MfNccj8HEJ0PYfBrNpE7mhjowxHvyk=; b=CQiHRQEa+cGFW1bTPnJYk9hSmizBxEhTARtg83rJEbJ+0q1C3FnfwN3L yldosdthVR0b6SkGWz7mBGI7gqldmL6LTRMu1n0NUQSZbSOoEE/xfUpXq CtE1VHD+iYzfZ9hd2eugFT/Qazxp4e9mKBWmMH80f25WnaicLZ/F9fJor E=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: uvG1uML1Jhn9EBhjz7NzUG8+iXATPCwKeEWx/LrNvtyObTouwDGAEVe3dsFf0h0aOQCK//ovGA 3YExU05Y2/VR3qevkpQ+FtM/HHFWrOQgll4H658AkngqO12LESX7/30TrFz4hdArk7Vshw0hNl 1gkSdvRnqjJor1sMmP2u45WoJNKlZwhUdwK9VBalr7822x+fIzNCIg38oIgwqzzTNMcZNOM6Fr YYnclVuhvrg6mC3plpEU+9RpBXcG/9hAPVCZxvSIYSIdRHnaM5/RT7z2LDHa/rec+/0JsXg09b s+c= X-SBRS: 2.7 X-MesageID: 11262614 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,413,1571716800"; d="scan'208";a="11262614" From: Andrew Cooper To: Xen-devel Date: Thu, 9 Jan 2020 11:51:33 +0000 Message-ID: <20200109115133.24176-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200108170040.7728-1-andrew.cooper3@citrix.com> References: <20200108170040.7728-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] x86/boot: Rationalise stack handling during early boot X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The top (numerically higher addresses) of cpu0_stack[] contains the BSP's cpu_info block. Logic in Xen expects this to be initialised to 0, but this area of stack is also used during early boot. Update the head.S code to avoid using the cpu_info block. Additionally, update the stack_start variable to match, which avoids __high_start() and efi_arch_post_exit_boot() needing to make the adjustment manually. Finally, leave a big warning by the BIOS BSS initialisation, because it is = by no means obvious that the stack doesn't survive the REP STOS. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * Use 'i' rather than 'ir' for [cs] * Adjust stack_base[0] calculation in smp_prepare_cpus() --- xen/arch/x86/boot/head.S | 10 +++++++--- xen/arch/x86/boot/x86_64.S | 3 +-- xen/arch/x86/efi/efi-boot.h | 15 ++++++++------- xen/arch/x86/smpboot.c | 4 ++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index c730810461..250587fdf0 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -400,7 +400,7 @@ __pvh_start: sub $sym_offs(1b), %esi =20 /* Set up stack. */ - lea STACK_SIZE + sym_esi(cpu0_stack), %esp + lea STACK_SIZE - CPUINFO_sizeof + sym_esi(cpu0_stack), %esp =20 mov %ebx, sym_esi(pvh_start_info_pa) =20 @@ -447,7 +447,7 @@ __start: sub $sym_offs(1b), %esi =20 /* Set up stack. */ - lea STACK_SIZE + sym_esi(cpu0_stack), %esp + lea STACK_SIZE - CPUINFO_sizeof + sym_esi(cpu0_stack), %esp =20 /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value= . */ xor %edx,%edx @@ -616,7 +616,11 @@ trampoline_setup: cmpb $0,sym_fs(efi_platform) jnz 1f =20 - /* Initialize BSS (no nasty surprises!). */ + /* + * Initialise the BSS. + * + * !!! WARNING - also zeroes the current stack !!! + */ lea sym_esi(__bss_start), %edi lea sym_esi(__bss_end), %ecx sub %edi,%ecx diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S index b54d3aceea..0acf5e860c 100644 --- a/xen/arch/x86/boot/x86_64.S +++ b/xen/arch/x86/boot/x86_64.S @@ -16,7 +16,6 @@ ENTRY(__high_start) mov %rcx,%cr4 =20 mov stack_start(%rip),%rsp - or $(STACK_SIZE-CPUINFO_sizeof),%rsp =20 /* Reset EFLAGS (subsumes CLI and CLD). */ pushq $0 @@ -42,7 +41,7 @@ multiboot_ptr: .long 0 =20 GLOBAL(stack_start) - .quad cpu0_stack + .quad cpu0_stack + STACK_SIZE - CPUINFO_sizeof =20 .section .data.page_aligned, "aw", @progbits .align PAGE_SIZE, 0 diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 676d616ff8..9c036d5f4c 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -249,23 +249,24 @@ static void __init noreturn efi_arch_post_exit_boot(v= oid) "or $"__stringify(X86_CR4_PGE)", %[cr4]\n\t" "mov %[cr4], %%cr4\n\t" #endif - "movabs $__start_xen, %[rip]\n\t" "lgdt boot_gdtr(%%rip)\n\t" - "mov stack_start(%%rip), %%rsp\n\t" "mov %[ds], %%ss\n\t" "mov %[ds], %%ds\n\t" "mov %[ds], %%es\n\t" "mov %[ds], %%fs\n\t" "mov %[ds], %%gs\n\t" - "movl %[cs], 8(%%rsp)\n\t" - "mov %[rip], (%%rsp)\n\t" - "lretq %[stkoff]-16" + + /* Jump to higher mappings. */ + "mov stack_start(%%rip), %%rsp\n\t" + "movabs $__start_xen, %[rip]\n\t" + "push %[cs]\n\t" + "push %[rip]\n\t" + "lretq" : [rip] "=3D&r" (efer/* any dead 64-bit variable */), [cr4] "+&r" (cr4) : [cr3] "r" (idle_pg_table), - [cs] "ir" (__HYPERVISOR_CS), + [cs] "i" (__HYPERVISOR_CS), [ds] "r" (__HYPERVISOR_DS), - [stkoff] "i" (STACK_SIZE - sizeof(struct cpu_info)), "D" (&mbi) : "memory" ); unreachable(); diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 301f746979..c9d1ab4423 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -554,7 +554,7 @@ static int do_boot_cpu(int apicid, int cpu) printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip); =20 - stack_start =3D stack_base[cpu]; + stack_start =3D stack_base[cpu] + STACK_SIZE - sizeof(struct cpu_info); =20 /* This grunge runs the startup process for the targeted processor. */ =20 @@ -1084,7 +1084,7 @@ void __init smp_prepare_cpus(void) boot_cpu_physical_apicid =3D get_apic_id(); x86_cpu_to_apicid[0] =3D boot_cpu_physical_apicid; =20 - stack_base[0] =3D stack_start; + stack_base[0] =3D (void *)((unsigned long)stack_start & ~(STACK_SIZE -= 1)); =20 rc =3D setup_cpu_root_pgt(0); if ( rc ) --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel