From nobody Sat Dec 21 18:06:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1727244117; cv=none; d=zohomail.com; s=zohoarc; b=kmuJ/WM1Swrh+yNdb+zf/b+l5Q/Uk+NLt2CaD3Q/K3OqEP2fmAjrJX7C+wwhNdXJQkwELpYiu9p2JsffiRJLv22A3/IrtPcqbNif4hnBXllqLIDZah+nOMjUrJK7T5jv7Ui2CAX778pa8vzwo7riyvg7ggyOiGEyCGOsr/5FFUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727244117; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mMG64X3mGJaWpXbh6pb/sJ7+eBsDVLEV1JYMeayeiaU=; b=fo3t4VH5XtJfToJfxHk7QC1oiJ7SQZdziK+x0s9pZrMTfosviALAkFfiidOcsIT7KmZySBtAeeMWs1Id0fVKR2qvE9iFW0RsZMqmp3pZ2jQNU0m9PT1yx904YPEJH+Yo0lRSO0KXeZhrtIWsqV3hdxpKZQWApFr7Sbl3veud7Ic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727244117300486.4995980039474; Tue, 24 Sep 2024 23:01:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803446.1214001 (Exim 4.92) (envelope-from ) id 1stL5T-0002fN-QV; Wed, 25 Sep 2024 06:01:19 +0000 Received: by outflank-mailman (output) from mailman id 803446.1214001; Wed, 25 Sep 2024 06:01:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stL5T-0002fG-MZ; Wed, 25 Sep 2024 06:01:19 +0000 Received: by outflank-mailman (input) for mailman id 803446; Wed, 25 Sep 2024 06:01:18 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stL5S-0002f4-DH for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 06:01:18 +0000 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [2a00:1450:4864:20::530]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 93d9c229-7b03-11ef-a0ba-8be0dac302b0; Wed, 25 Sep 2024 08:01:17 +0200 (CEST) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5c2561e8041so8723927a12.2 for ; Tue, 24 Sep 2024 23:01:16 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf49de00sm1498937a12.55.2024.09.24.23.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 23:01:14 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 93d9c229-7b03-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1727244075; x=1727848875; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mMG64X3mGJaWpXbh6pb/sJ7+eBsDVLEV1JYMeayeiaU=; b=OapMj+7LW0vRmwRhKkWfRRxTXr7qetLhCF1T1FXpkgFYhY2oh42Ox0eOKtJckttaku ny2YmZIn6vZQsGZkJIz0TIk+0Z5GwwKkxrhS9Gp4dxZgPodGItpbvBSruauE0KRKtIP3 09VCZk7l1vhbyWSx69LtHMYtPkORdq0O0sE6U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727244075; x=1727848875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mMG64X3mGJaWpXbh6pb/sJ7+eBsDVLEV1JYMeayeiaU=; b=JgtaOfwVf9N+Mt+WrXnb20vR0nVrxYH4eIJlKCiVW7e8xRq0lY3y3SPf/0c+Gj5Xzh BzLoR8mKN+GuK3jFY29zBhdb8/fsJh4w9vwI1HBoG3QC5O9WK2TY8wX/bAOxfBqPoi+o w2UgSDYAllcZjefYzpuOXQ7ejuZd5u4KXV/7i7NEVFbQqVZWo4ZcEA/VxHZmxaDn2G+J M+iYassgNBdUDuIw8yK6nOA4rbAcOFQ4DXQO6JTO9Cx8AF28iIbrSy0vaHpwacmeJxVd MaAObS7qN1i5cJuJbWgO5T+QrnKX3FkSy5dUGKL/qvpIcE99xKcUi2GgPAosi6W8Zp9q EzGQ== X-Gm-Message-State: AOJu0Yxms3tGZGwx+1KWavxkIor2grUm7IzW6lEfWuERyqwT+0NVYR31 O+JJ7rgLBNQpwhLlEGD5QUIzA0KI9HZdJqQvYp8Uiu3y+g7t9lRC/rvxd/ovJinQL5h/bE7yAp4 a X-Google-Smtp-Source: AGHT+IGaiik3wO5yXHiW2A7GgsgCLSXHRDsnxs6vG8aPj6Uho48WYhVMhoOtM0QBwH9VlQlAAnyc/A== X-Received: by 2002:a05:6402:500a:b0:5c3:d18e:fc27 with SMTP id 4fb4d7f45d1cf-5c720750e89mr984809a12.33.1727244075460; Tue, 24 Sep 2024 23:01:15 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v4 1/4] x86/boot: Initialise BSS sooner Date: Wed, 25 Sep 2024 07:00:58 +0100 Message-Id: <20240925060101.259244-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925060101.259244-1-frediano.ziglio@cloud.com> References: <20240925060101.259244-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1727244117991116600 Content-Type: text/plain; charset="utf-8" Allows to call C code earlier. In order to safely call C code we need to setup stack, selectors and BSS. Signed-off-by: Frediano Ziglio Reviewed-by: Andrew Cooper --- Changes since v1: - improve commit message; - improve some comments; - fix some code style (spacing); - set trampoline_phys as 32 bit value; - use PAGE_SIZE mnemonic instead of 0x1000; - use local label. Changes since v3: - improved comment; - fixed indentation. --- xen/arch/x86/boot/head.S | 77 ++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index cfc5a7b47d..267207e5a2 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -231,6 +231,27 @@ __efi64_mb2_start: /* VGA is not available on EFI platforms. */ movl $0,vga_text_buffer(%rip) =20 + /* + * Align the stack as UEFI spec requires. Keep it aligned + * before efi_multiboot2() call by pushing/popping even + * numbers of items on it. + */ + and $~15, %rsp + + /* + * Initialize BSS (no nasty surprises!). + * It must be done earlier than in BIOS case + * because efi_multiboot2() touches it. + */ + mov %eax, %edx + lea __bss_start(%rip), %edi + lea __bss_end(%rip), %ecx + sub %edi, %ecx + shr $3, %ecx + xor %eax, %eax + rep stosq + mov %edx, %eax + /* Check for Multiboot2 bootloader. */ cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax je .Lefi_multiboot2_proto @@ -321,34 +342,12 @@ __efi64_mb2_start: lea .Lmb2_no_ih(%rip),%r15 jz x86_32_switch =20 - /* - * Align the stack as UEFI spec requires. Keep it aligned - * before efi_multiboot2() call by pushing/popping even - * numbers of items on it. - */ - and $~15,%rsp - /* Save Multiboot2 magic on the stack. */ push %rax =20 /* Save EFI ImageHandle on the stack. */ push %rdi =20 - /* - * Initialize BSS (no nasty surprises!). - * It must be done earlier than in BIOS case - * because efi_multiboot2() touches it. - */ - lea __bss_start(%rip),%edi - lea __bss_end(%rip),%ecx - sub %edi,%ecx - shr $3,%ecx - xor %eax,%eax - rep stosq - - /* Keep the stack aligned. Do not pop a single item off it. */ - mov (%rsp),%rdi - /* * efi_multiboot2() is called according to System V AMD64 ABI: * - IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable, @@ -434,6 +433,8 @@ __pvh_start: /* Set up stack. */ lea STACK_SIZE - CPUINFO_sizeof + sym_esi(cpu0_stack), %esp =20 + call .Linitialise_bss + mov %ebx, sym_esi(pvh_start_info_pa) =20 /* Force xen console. Will revert to user choice in init code. */ @@ -459,6 +460,20 @@ __pvh_start: =20 #endif /* CONFIG_PVH_GUEST */ =20 +.Linitialise_bss: + /* Initialise the BSS. Preserve %eax (BOOTLOADER_MAGIC). */ + mov %eax, %ebp + + lea sym_esi(__bss_start), %edi + lea sym_esi(__bss_end), %ecx + sub %edi, %ecx + xor %eax, %eax + shr $2, %ecx + rep stosl + + mov %ebp, %eax + ret + __start: cld cli @@ -489,6 +504,8 @@ __start: /* Set up stack. */ lea STACK_SIZE - CPUINFO_sizeof + sym_esi(cpu0_stack), %esp =20 + call .Linitialise_bss + /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value= . */ xor %edx,%edx =20 @@ -645,22 +662,6 @@ trampoline_setup: * reserved for trampoline code and data. */ =20 - /* - * Do not zero BSS on EFI platform here. - * It was initialized earlier. - */ - cmpb $0, sym_esi(efi_platform) - jnz 1f - - /* Initialise the BSS. */ - lea sym_esi(__bss_start), %edi - lea sym_esi(__bss_end), %ecx - sub %edi,%ecx - xor %eax,%eax - shr $2,%ecx - rep stosl - -1: /* Interrogate CPU extended features via CPUID. */ mov $1, %eax cpuid --=20 2.34.1