From nobody Sun Feb 8 09:09:27 2026 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 From nobody Sun Feb 8 09:09:27 2026 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=1727244108; cv=none; d=zohomail.com; s=zohoarc; b=kYK+0oKf8TWqSmE7GVwF22L+IphAlpSA6YV2CPFvdxFRAebC/eWW3T5Lb691i93vGLrNXkrOswun1r51YI5fExX3yE4vlzpAKTNbq/uWNzouXM18H4dVtQ62AitixlZyX0L+qbnsDtfRPVeJaP/QU+v2A0+GHIWLPwUbsoj2mMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727244108; 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=kPTBonMqIKr1Gh1WSmKkngmOhz6efABUMJImPAurUOk=; b=QAMqnVk5vwc5zihmOxvq2ZQzyxFICKHkihadr+UGv3fAydqjo/MgMAdTdR+piLPEP0y7OirUm852da9nDPDjKLJgm1Frwu2GPBlsz/Iir4EpNtGq3xOSURjrzf4od5vEshbhDUCmTc/tBg5CTgX+l7d+iY+BgbiQJcFtBrUOhvI= 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 1727244108547391.06270386925144; Tue, 24 Sep 2024 23:01:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803448.1214020 (Exim 4.92) (envelope-from ) id 1stL5W-00037o-9z; Wed, 25 Sep 2024 06:01:22 +0000 Received: by outflank-mailman (output) from mailman id 803448.1214020; Wed, 25 Sep 2024 06:01:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stL5W-00037h-6r; Wed, 25 Sep 2024 06:01:22 +0000 Received: by outflank-mailman (input) for mailman id 803448; Wed, 25 Sep 2024 06:01:20 +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 1stL5T-0002f4-Vx for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 06:01:19 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 955e1273-7b03-11ef-a0ba-8be0dac302b0; Wed, 25 Sep 2024 08:01:19 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5356bb55224so8557881e87.0 for ; Tue, 24 Sep 2024 23:01:19 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 23:01:15 -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: 955e1273-7b03-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1727244078; x=1727848878; 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=kPTBonMqIKr1Gh1WSmKkngmOhz6efABUMJImPAurUOk=; b=aXLjztczSTa3ba2gYWA7jzQvb/f8e3Gcrna5kr87EffZUZD5lUvhxzK5SSx0mHx1YK trvN4H6W9BYsL33YDEu3NlRv+IZ3S53XvuSrkEJV8G3/04zfXnFm5fXGXkZouxpQjVT4 iLf+zKqdJWXXKVd0rcnMMkARYjsheCE1CFc7s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727244078; x=1727848878; 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=kPTBonMqIKr1Gh1WSmKkngmOhz6efABUMJImPAurUOk=; b=TLcWrbnEin53ffjXlYi9v5C1Lp4ecqS0bbjg3n5YaS/7T77ALwb8TnPS6dCit7CTPU JwzYETD+R8EHeTJ0juH51AxuERSpvWLGOd16HP1tVgnnlE5kG4C2Y3TxjxGoAvL0M5W4 OFrnh7TU1AD04xm3gcoAp8I4QIcah/6YvKdyiDbck9jf/DgpoIlFrdY/ppAZflrFXEpE GNxUoYw3PRa5zVDYdyGbEfSzlJC97MfGqROGB9uZ7BdRSmwMz599FOtN6pii23NITC8n Mx7yokQ/YcwCCKDYmaBXG7oLCNIUyh3+skY1agd65suihcDj/ySzW8RJspn3d7BZP1BG ziuQ== X-Gm-Message-State: AOJu0YxX7nN6XBTybmlumtFbKd0UBrTKNxNzteqXLcGcu8/GTpZTbX8k LYvLOKtrNqduei8IyU6yiu3A5vnxdgzkoaD2zs7ZoL88RbO4PAI8mnSHhujWkzudbuh8G1hrzh6 p X-Google-Smtp-Source: AGHT+IGfxAPkHF82/MgXoJ0SIUMRhoH0ZoSo/6R1zTW8wQLGgoZoF07X2qgHKuSEX7bfmgdR477DDg== X-Received: by 2002:a05:6512:e8c:b0:533:4817:7280 with SMTP id 2adb3069b0e04-53877537533mr856227e87.35.1727244077586; Tue, 24 Sep 2024 23:01:17 -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 2/4] x86/boot: Refactor BIOS/PVH start Date: Wed, 25 Sep 2024 07:00:59 +0100 Message-Id: <20240925060101.259244-3-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: 1727244109984116600 Content-Type: text/plain; charset="utf-8" The 2 code paths were sharing quite some common code, reuse it instead of having duplications. Use %dl register to store boot type before running common code. Using a 8 bit register reduces code size. Signed-off-by: Frediano Ziglio --- Changes since v1: - use %dl instead of %ebp to reduce code size; - fold cli instruction; - update some comments. Changes since v3: - dropped %dl and constant, distinguish entry by magic. --- xen/arch/x86/boot/head.S | 108 +++++++++++++++------------------------ 1 file changed, 40 insertions(+), 68 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 267207e5a2..2d2f56ad22 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -25,6 +25,8 @@ #define MB2_HT(name) (MULTIBOOT2_HEADER_TAG_##name) #define MB2_TT(name) (MULTIBOOT2_TAG_TYPE_##name) =20 +#define XEN_HVM_START_MAGIC_VALUE 0x336ec578 + .macro mb2ht_args arg:req, args:vararg .long \arg .ifnb \args @@ -409,13 +411,27 @@ cs32_switch: ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .long sym_offs(__pvh_start)) =20 __pvh_start: - cld + mov (%ebx), %eax /* mov $XEN_HVM_START_MAGIC_VALUE, %eax */ + /* + * Fall through into BIOS code. + * We will use %eax to distinguish we came from PHV entry point. + */ +#endif /* CONFIG_PVH_GUEST */ + +__start: cli + cld =20 /* - * We need one call (i.e. push) to determine the load address. See - * __start for a discussion on how to do this safely using the PVH - * info structure. + * Multiboot (both 1 and 2) and PVH specify the stack pointer as + * undefined. This is unhelpful for relocatable images, where one + * call (i.e. push) is required to calculate the image's load addr= ess. + * + * Durig BIOS boot, there is one area of memory we know about with + * reasonable confidence that it isn't overlapped by Xen, and that= 's + * the Multiboot info structure in %ebx. Use it as a temporary st= ack. + * + * During PVH boot use info structure in %ebx. */ =20 /* Preserve the field we're about to clobber. */ @@ -433,14 +449,7 @@ __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) - - /* Force xen console. Will revert to user choice in init code. */ - movb $-1, sym_esi(opt_console_xen) - - /* Prepare gdt and segments */ + /* Initialize GDTR and basic data segments. */ add %esi, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) =20 @@ -449,62 +458,40 @@ __pvh_start: mov %ecx, %es mov %ecx, %ss =20 - /* Skip bootloader setup and bios setup, go straight to trampoline= */ - movb $1, sym_esi(pvh_boot) - movb $1, sym_esi(skip_realmode) + /* Load null selector to unused segment registers. */ + xor %ecx, %ecx + mov %ecx, %fs + mov %ecx, %gs =20 - /* Set trampoline_phys to use mfn 1 to avoid having a mapping at V= A 0 */ - movw $0x1000, sym_esi(trampoline_phys) - mov (%ebx), %eax /* mov $XEN_HVM_START_MAGIC_VALUE, %eax */ - jmp trampoline_setup - -#endif /* CONFIG_PVH_GUEST */ - -.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 - - /* - * Multiboot (both 1 and 2) specify the stack pointer as undefined - * when entering in BIOS circumstances. This is unhelpful for - * relocatable images, where one call (i.e. push) is required to - * calculate the image's load address. - * - * This early in boot, there is one area of memory we know about w= ith - * reasonable confidence that it isn't overlapped by Xen, and that= 's - * the Multiboot info structure in %ebx. Use it as a temporary st= ack. - */ =20 - /* Preserve the field we're about to clobber. */ - mov (%ebx), %edx - lea 4(%ebx), %esp +#ifdef CONFIG_PVH_GUEST + cmp $XEN_HVM_START_MAGIC_VALUE, %eax + jne 1f =20 - /* Calculate the load base address. */ - call 1f -1: pop %esi - sub $sym_offs(1b), %esi + mov %ebx, sym_esi(pvh_start_info_pa) =20 - /* Restore the clobbered field. */ - mov %edx, (%ebx) + /* Force xen console. Will revert to user choice in init code. */ + movb $-1, sym_esi(opt_console_xen) =20 - /* Set up stack. */ - lea STACK_SIZE - CPUINFO_sizeof + sym_esi(cpu0_stack), %esp + /* Skip bootloader setup and bios setup, go straight to trampoline= */ + movb $1, sym_esi(pvh_boot) + movb $1, sym_esi(skip_realmode) =20 - call .Linitialise_bss + /* Set trampoline_phys to use mfn 1 to avoid having a mapping at V= A 0 */ + movl $PAGE_SIZE, sym_esi(trampoline_phys) + mov (%ebx), %eax /* mov $XEN_HVM_START_MAGIC_VALUE, %eax */ + jmp trampoline_setup +1: +#endif /* CONFIG_PVH_GUEST */ =20 /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value= . */ xor %edx,%edx @@ -563,22 +550,7 @@ __start: trampoline_bios_setup: /* * Called on legacy BIOS platforms only. - * - * Initialize GDTR and basic data segments. */ - add %esi,sym_esi(gdt_boot_base) - lgdt sym_esi(gdt_boot_descr) - - mov $BOOT_DS,%ecx - mov %ecx,%ds - mov %ecx,%es - mov %ecx,%ss - /* %esp is initialized later. */ - - /* Load null descriptor to unused segment registers. */ - xor %ecx,%ecx - mov %ecx,%fs - mov %ecx,%gs =20 /* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ --=20 2.34.1 From nobody Sun Feb 8 09:09:27 2026 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=1727244121; cv=none; d=zohomail.com; s=zohoarc; b=nEWhGhXO/4E119+9yCboZ9Rt+x5OwsOX5DN9DlwRcd2LnBOFOsD/UOLc85vNB3lxjx8W1apSRMOC7CvN++rhrSYW2fLIjXw9MLFcTPsGvAleAA2H/2MeKLz/VieByl/VKG6TKMLwxUfLFqNSH9TurQbtSH4js5LKhYkQOZml0Ak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727244121; 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=2TZg8ToD9JXeRblFEKVdwQiliViyIUTgYI71N5Ruvhc=; b=jOnr5mru+Rtfh7UlTrHXGhnGpDbyLPYBdMXnI/dyTDcGZlEYqh6lJ9ullr/LF6Sfoo9YTigs+MEN8PL/D489yh07X2hBsr2jErrL4hyWOhNzqDkmCHNITnx/zkYHOtmWYodrvn8XPokSpfgdVu4GuaKopQyR5xea2oD8ASKtHyo= 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 1727244120525480.31423022344813; Tue, 24 Sep 2024 23:02:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803449.1214027 (Exim 4.92) (envelope-from ) id 1stL5W-0003EO-O5; Wed, 25 Sep 2024 06:01:22 +0000 Received: by outflank-mailman (output) from mailman id 803449.1214027; Wed, 25 Sep 2024 06:01:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stL5W-0003Cs-JR; Wed, 25 Sep 2024 06:01:22 +0000 Received: by outflank-mailman (input) for mailman id 803449; Wed, 25 Sep 2024 06:01:21 +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 1stL5V-0002f4-Kd for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 06:01:21 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9645e268-7b03-11ef-a0ba-8be0dac302b0; Wed, 25 Sep 2024 08:01:20 +0200 (CEST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5c5b9d2195eso4941428a12.1 for ; Tue, 24 Sep 2024 23:01:20 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 23:01:17 -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: 9645e268-7b03-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1727244079; x=1727848879; 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=2TZg8ToD9JXeRblFEKVdwQiliViyIUTgYI71N5Ruvhc=; b=N8Ry5B8/0N1YlxSFMcQ/XQbHyrcNB4OeCuMbhe8u0YmfrF5iwvKVSg5RMl9miKkgxW y8I3xpIllzet34uTAOPOIlloGO2QsXdEZ1m3Mu9z4PjMnpEqzHpDL4lTfaP7Ya1/zRja wS4bKjmJNbkBKyInnfO/5JcNimfRScoDDu/A0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727244079; x=1727848879; 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=2TZg8ToD9JXeRblFEKVdwQiliViyIUTgYI71N5Ruvhc=; b=kiVSVxaGTgpmd7VC9EYhjB7uugpvDH+pRURzauGNbu4lNIVojQVe+cG2k1CZT5bp0E PaKYFZdmJLHFy8pX7KHZDtTpHP16TZMaqUKNLRoHZCQE7A0g4Yc/PtUseIeSf1zNp5e0 xvt00B7iGbRx7YyJE7F4Zrbukv6G1fLfV6Awk3VyE9XAJ1of49OE1bKAppSiLN84bSQ3 FUTo1pVRZGXvZ8o280uem9dGf2Ab8WSld4ucAzwdvF6UOYAGyqMlWGCc4f1xeiwNG48R aH/1k9/LFwHcIUS843b0mPoKBZdyEvdPvucNwLaM+FhVkkKAmCycQ+DFQLq7XIBzJCFY rzug== X-Gm-Message-State: AOJu0YyGNnpy/Y4++g0GPp71FWfzJd+3gl+qYa1N4TIuhHoFKtR4TL3/ dGlxNg4u9TgD8cfaxkCFW4apt0QBdBXaQnLOGmvtBc39sptAhpuLhhjxuH8Z/BAzPW/kLjlhth8 q X-Google-Smtp-Source: AGHT+IFHOoJTguyvESjJL2g7tRdGHKj4gX3OAdASV6zZN4uwObayuj0bjRgjnNktl7D1pq/Kmad76g== X-Received: by 2002:a05:6402:2113:b0:5c5:b901:5644 with SMTP id 4fb4d7f45d1cf-5c7206226a8mr1242269a12.15.1727244078704; Tue, 24 Sep 2024 23:01:18 -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?= , "Daniel P. Smith" , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [PATCH v4 3/4] x86/boot: Rewrite EFI/MBI2 code partly in C Date: Wed, 25 Sep 2024 07:01:00 +0100 Message-Id: <20240925060101.259244-4-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: 1727244122088116600 Content-Type: text/plain; charset="utf-8" No need to have it coded in assembly. Signed-off-by: Frediano Ziglio --- Changes since v1: - update some comments; - explain why %ebx is saved before calling efi_parse_mbi2; - move lea before test instruction; - removed asmlinkage from efi_multiboot2 and add to efi_parse_mbi2; - fix line length; - update an error message specifying "Multiboot2" instead of "Multiboot"; - use obj-bin-X instead of obj-X in Makefile; - avoid restoring %eax (MBI magic). Changes since v3: - rename new function to efi_multiboot2_prelude; - declare efi_multiboot2 in a separate header. --- xen/arch/x86/boot/head.S | 142 +++++++-------------------------- xen/arch/x86/efi/Makefile | 1 + xen/arch/x86/efi/efi-boot.h | 6 +- xen/arch/x86/efi/parse-mbi2.c | 56 +++++++++++++ xen/arch/x86/efi/stub.c | 3 +- xen/arch/x86/include/asm/efi.h | 18 +++++ 6 files changed, 108 insertions(+), 118 deletions(-) create mode 100644 xen/arch/x86/efi/parse-mbi2.c create mode 100644 xen/arch/x86/include/asm/efi.h diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 2d2f56ad22..859f7055dc 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -121,8 +121,6 @@ multiboot2_header: .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!" .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!" .Lbad_ldr_nbs: .asciz "ERR: Bootloader shutdown EFI x64 boot services!" -.Lbad_ldr_nst: .asciz "ERR: EFI SystemTable is not provided by bootloader!" -.Lbad_ldr_nih: .asciz "ERR: EFI ImageHandle is not provided by bootloader!" .Lbad_efi_msg: .asciz "ERR: EFI IA-32 platforms are not supported!" .Lbag_alg_msg: .asciz "ERR: Xen must be loaded at a 2Mb boundary!" .Lno_nx_msg: .asciz "ERR: Not an NX-capable CPU!" @@ -161,17 +159,6 @@ early_error: /* Here to improve the disassembly. */ mov $sym_offs(.Lno_nx_msg), %ecx jmp .Lget_vtb #endif -.Lmb2_no_st: - /* - * Here we are on EFI platform. vga_text_buffer was zapped earlier - * because there is pretty good chance that VGA is unavailable. - */ - mov $sym_offs(.Lbad_ldr_nst), %ecx - jmp .Lget_vtb -.Lmb2_no_ih: - /* Ditto. */ - mov $sym_offs(.Lbad_ldr_nih), %ecx - jmp .Lget_vtb .Lmb2_no_bs: /* * Ditto. Additionally, here there is a chance that Xen was started @@ -189,6 +176,10 @@ early_error: /* Here to improve the disassembly. */ mov $sym_offs(.Lbad_efi_msg), %ecx xor %edi,%edi # No VGA text buffer jmp .Lprint_err +.Ldirect_error: + mov sym_esi(vga_text_buffer), %edi + mov %eax, %esi + jmp 1f .Lget_vtb: mov sym_esi(vga_text_buffer), %edi .Lprint_err: @@ -235,7 +226,7 @@ __efi64_mb2_start: =20 /* * Align the stack as UEFI spec requires. Keep it aligned - * before efi_multiboot2() call by pushing/popping even + * before efi_multiboot2_prelude() call by pushing/popping even * numbers of items on it. */ and $~15, %rsp @@ -243,7 +234,7 @@ __efi64_mb2_start: /* * Initialize BSS (no nasty surprises!). * It must be done earlier than in BIOS case - * because efi_multiboot2() touches it. + * because efi_multiboot2_prelude() touches it. */ mov %eax, %edx lea __bss_start(%rip), %edi @@ -252,36 +243,30 @@ __efi64_mb2_start: shr $3, %ecx xor %eax, %eax rep stosq - mov %edx, %eax - - /* Check for Multiboot2 bootloader. */ - cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax - je .Lefi_multiboot2_proto - - /* Jump to .Lnot_multiboot after switching CPU to x86_32 mode. */ - lea .Lnot_multiboot(%rip), %r15 - jmp x86_32_switch - -.Lefi_multiboot2_proto: - /* Zero EFI SystemTable, EFI ImageHandle addresses and cmdline. */ - xor %esi,%esi - xor %edi,%edi - xor %edx,%edx =20 - /* Skip Multiboot2 information fixed part. */ - lea (MB2_fixed_sizeof+MULTIBOOT2_TAG_ALIGN-1)(%rbx),%ecx - and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx - -.Lefi_mb2_tsize: - /* Check Multiboot2 information total size. */ - mov %ecx,%r8d - sub %ebx,%r8d - cmp %r8d,MB2_fixed_total_size(%rbx) - jbe .Lrun_bs + /* + * Spill MB2 magic. + * Spill the pointer too, to keep the stack aligned. + */ + push %rdx + push %rbx =20 - /* Are EFI boot services available? */ - cmpl $MULTIBOOT2_TAG_TYPE_EFI_BS,MB2_tag_type(%rcx) - jne .Lefi_mb2_st + /* + * efi_multiboot2_prelude() is called according to System V AMD64 = ABI: + * - IN: %edi - Multiboot2 magic, + * %rsi - Multiboot2 pointer. + * - OUT: %rax - error string. + */ + mov %edx, %edi + mov %rbx, %rsi + call efi_multiboot2_prelude + lea .Ldirect_error(%rip), %r15 + test %rax, %rax + jnz x86_32_switch + + /* Restore Multiboot2 pointer and magic. */ + pop %rbx + pop %rax =20 /* We are on EFI platform and EFI boot services are available. */ incb efi_platform(%rip) @@ -291,77 +276,6 @@ __efi64_mb2_start: * be run on EFI platforms. */ incb skip_realmode(%rip) - jmp .Lefi_mb2_next_tag - -.Lefi_mb2_st: - /* Get EFI SystemTable address from Multiboot2 information. */ - cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx) - cmove MB2_efi64_st(%rcx),%rsi - je .Lefi_mb2_next_tag - - /* Get EFI ImageHandle address from Multiboot2 information. */ - cmpl $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx) - cmove MB2_efi64_ih(%rcx),%rdi - je .Lefi_mb2_next_tag - - /* Get command line from Multiboot2 information. */ - cmpl $MULTIBOOT2_TAG_TYPE_CMDLINE, MB2_tag_type(%rcx) - jne .Lno_cmdline - lea MB2_tag_string(%rcx), %rdx - jmp .Lefi_mb2_next_tag -.Lno_cmdline: - - /* Is it the end of Multiboot2 information? */ - cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx) - je .Lrun_bs - -.Lefi_mb2_next_tag: - /* Go to next Multiboot2 information tag. */ - add MB2_tag_size(%rcx),%ecx - add $(MULTIBOOT2_TAG_ALIGN-1),%ecx - and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx - jmp .Lefi_mb2_tsize - -.Lrun_bs: - /* Are EFI boot services available? */ - cmpb $0,efi_platform(%rip) - - /* Jump to .Lmb2_no_bs after switching CPU to x86_32 mode. */ - lea .Lmb2_no_bs(%rip),%r15 - jz x86_32_switch - - /* Is EFI SystemTable address provided by boot loader? */ - test %rsi,%rsi - - /* Jump to .Lmb2_no_st after switching CPU to x86_32 mode. */ - lea .Lmb2_no_st(%rip),%r15 - jz x86_32_switch - - /* Is EFI ImageHandle address provided by boot loader? */ - test %rdi,%rdi - - /* Jump to .Lmb2_no_ih after switching CPU to x86_32 mode. */ - lea .Lmb2_no_ih(%rip),%r15 - jz x86_32_switch - - /* Save Multiboot2 magic on the stack. */ - push %rax - - /* Save EFI ImageHandle on the stack. */ - push %rdi - - /* - * efi_multiboot2() is called according to System V AMD64 ABI: - * - IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable, - * %rdx - MB2 cmdline - */ - call efi_multiboot2 - - /* Just pop an item from the stack. */ - pop %rax - - /* Restore Multiboot2 magic. */ - pop %rax =20 /* Jump to trampoline_setup after switching CPU to x86_32 mode. */ lea trampoline_setup(%rip),%r15 diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile index 24dfecfad1..51140061fc 100644 --- a/xen/arch/x86/efi/Makefile +++ b/xen/arch/x86/efi/Makefile @@ -14,5 +14,6 @@ $(addprefix $(obj)/,$(EFIOBJ-y)): CFLAGS_stack_boundary := =3D $(cflags-stack-bounda obj-y :=3D common-stub.o stub.o obj-$(XEN_BUILD_EFI) :=3D $(filter-out %.init.o,$(EFIOBJ-y)) obj-bin-$(XEN_BUILD_EFI) :=3D $(filter %.init.o,$(EFIOBJ-y)) +obj-bin-y +=3D parse-mbi2.o extra-$(XEN_BUILD_EFI) +=3D buildid.o relocs-dummy.o nocov-$(XEN_BUILD_EFI) +=3D stub.o diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 7aa55e7aaf..859c01c13f 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -816,9 +816,9 @@ static const char *__init get_option(const char *cmd, c= onst char *opt) return o; } =20 -void asmlinkage __init efi_multiboot2(EFI_HANDLE ImageHandle, - EFI_SYSTEM_TABLE *SystemTable, - const char *cmdline) +void __init efi_multiboot2(EFI_HANDLE ImageHandle, + EFI_SYSTEM_TABLE *SystemTable, + const char *cmdline) { EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; EFI_HANDLE gop_handle; diff --git a/xen/arch/x86/efi/parse-mbi2.c b/xen/arch/x86/efi/parse-mbi2.c new file mode 100644 index 0000000000..89c562cf6a --- /dev/null +++ b/xen/arch/x86/efi/parse-mbi2.c @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include +#include +#include +#include + +const char * asmlinkage __init +efi_multiboot2_prelude(uint32_t magic, const multiboot2_fixed_t *mbi) +{ + const multiboot2_tag_t *tag; + EFI_HANDLE ImageHandle =3D NULL; + EFI_SYSTEM_TABLE *SystemTable =3D NULL; + const char *cmdline =3D NULL; + bool have_bs =3D false; + + if ( magic !=3D MULTIBOOT2_BOOTLOADER_MAGIC ) + return "ERR: Not a Multiboot2 bootloader!"; + + /* Skip Multiboot2 information fixed part. */ + tag =3D _p(ROUNDUP((unsigned long)(mbi + 1), MULTIBOOT2_TAG_ALIGN)); + + for ( ; (const void *)tag - (const void *)mbi < mbi->total_size + && tag->type !=3D MULTIBOOT2_TAG_TYPE_END; + tag =3D _p(ROUNDUP((unsigned long)((const void *)tag + tag->size= ), + MULTIBOOT2_TAG_ALIGN)) ) + { + switch ( tag->type ) + { + case MULTIBOOT2_TAG_TYPE_EFI_BS: + have_bs =3D true; + break; + case MULTIBOOT2_TAG_TYPE_EFI64: + SystemTable =3D _p(((const multiboot2_tag_efi64_t *)tag)->poin= ter); + break; + case MULTIBOOT2_TAG_TYPE_EFI64_IH: + ImageHandle =3D _p(((const multiboot2_tag_efi64_ih_t *)tag)->p= ointer); + break; + case MULTIBOOT2_TAG_TYPE_CMDLINE: + cmdline =3D ((const multiboot2_tag_string_t *)tag)->string; + break; + } + } + + if ( !have_bs ) + return "ERR: Bootloader shutdown EFI x64 boot services!"; + if ( !SystemTable ) + return "ERR: EFI SystemTable is not provided by bootloader!"; + if ( !ImageHandle ) + return "ERR: EFI ImageHandle is not provided by bootloader!"; + + efi_multiboot2(ImageHandle, SystemTable, cmdline); + + return NULL; +} diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c index 2cd5c8d4dc..27d40964d5 100644 --- a/xen/arch/x86/efi/stub.c +++ b/xen/arch/x86/efi/stub.c @@ -17,7 +17,8 @@ */ =20 void __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, - EFI_SYSTEM_TABLE *SystemTable) + EFI_SYSTEM_TABLE *SystemTable, + const char *cmdline) { static const CHAR16 __initconst err[] =3D L"Xen does not have EFI code build in!\r\nSystem halted!\r\n"; diff --git a/xen/arch/x86/include/asm/efi.h b/xen/arch/x86/include/asm/efi.h new file mode 100644 index 0000000000..575a33e302 --- /dev/null +++ b/xen/arch/x86/include/asm/efi.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef X86_ASM_EFI_H +#define X86_ASM_EFI_H + +#include +#include +#include +#include +#include +#include +#include + +void efi_multiboot2(EFI_HANDLE ImageHandle, + EFI_SYSTEM_TABLE *SystemTable, + const char *cmdline); + +#endif /* X86_ASM_EFI_H */ --=20 2.34.1 From nobody Sun Feb 8 09:09:27 2026 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=1727244717; cv=none; d=zohomail.com; s=zohoarc; b=myXH5dzvoj8dZBYWCABCwWW53X+/v7CIpfJPKZsHg5EUEG+feG+1Mvt6SYZ6/6x+wiFjAF9Zp7oRhg8jNltbsMH9yAoLRkFSR9BihXvXsTtaJUdcFQ+x9K4BKoe3v+AEfXG0m6jSRrGstqAP7HqVusLpayud5kxUUVlIl/j7T/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727244717; 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=wVxz4I4vyQGmSKY6Ub9yCNA7tMFmaRorNjlXLxFtjUc=; b=JRK0A7eQYcuW0PGBgaiicW2E5E3iYfRNsUt+bw+vdIpo9k1jQv0tUkPNYI2/HTQEMWuaobi+bp3jpSIv8Mkw71zqnjZT3/qNsx+hHqgpRDP3fVe5WiIsNnG4GoXZYk3XLREyAzSqA7LlOD+VBiljXxXApV64uw6QbHs5vpL70m8= 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 1727244717460681.5196835345332; Tue, 24 Sep 2024 23:11:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803450.1214041 (Exim 4.92) (envelope-from ) id 1stL5a-0003e7-0f; Wed, 25 Sep 2024 06:01:26 +0000 Received: by outflank-mailman (output) from mailman id 803450.1214041; Wed, 25 Sep 2024 06:01:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stL5Z-0003dt-T1; Wed, 25 Sep 2024 06:01:25 +0000 Received: by outflank-mailman (input) for mailman id 803450; Wed, 25 Sep 2024 06:01:24 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stL5Y-0002f5-On for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 06:01:24 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 96c229ce-7b03-11ef-99a2-01e77a169b0f; Wed, 25 Sep 2024 08:01:21 +0200 (CEST) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a8d2b24b7a8so102347766b.1 for ; Tue, 24 Sep 2024 23:01:21 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 23:01:19 -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: 96c229ce-7b03-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1727244080; x=1727848880; 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=wVxz4I4vyQGmSKY6Ub9yCNA7tMFmaRorNjlXLxFtjUc=; b=icRQhwcV9C7fgPmLZok0xPqhq5SFvUEVzCqtzXCwIs0Nuc6zQHmbBubgL3wqOrFZmn XMyMj+R3G93nTQgkvZ3/XnhByMbPl+j14zMWpIsFZRTFC7Hwsl6Tbc5GM859uvfDcJ0u 4+8X7E59LLpn7bc0PTcSOf84CWd3U+yL/10wQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727244080; x=1727848880; 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=wVxz4I4vyQGmSKY6Ub9yCNA7tMFmaRorNjlXLxFtjUc=; b=iNOM75fkBOFkbCchF2A5VsnzYBodMxdiww/ePrb4d08VCRDt4ci5I9iSqaY2EaTtzu 9AvA88qVELfUNlUEj31Oq0FECOYJVT4tI2STHLFa0jqeW8kYMZDyZLzApfaNMs880PnO en07pzV2uCjnf3nksCn7MuxHH6nSmVV8VZixuwXN0d639/MrE3yaP1QYcTJQZoJ5irLR IOrwWefZtfSxxI7ro547DNx+9Fz3XPDSl429D6Y1xQCZqW2sQP8r7F+DZ4x+/82EpGx4 woIydejcZUglH811925pAa+2/+tkI0U11v/LPIHSkyRh6Gh8QMSqWCpuY/DCYK3sjTHo rY6Q== X-Gm-Message-State: AOJu0Yyi9RWiCwZUGZbVY8BWebFHKrGagalBfs/M4s8cElrQdbMOsAra SF4CWSVw1kyzE6N0y7D1KYonQ75XMrafyHMSvLrbULZ5vfjXMtdgevwaiaS5p1GvaYumAu/GQMt + X-Google-Smtp-Source: AGHT+IGKaqBd9awEa1SGJvtToFN9ateo9a6+kddKbdn9a5nrY01jZMuIldAOnRilgdVuoUaZ6Ndk5w== X-Received: by 2002:a17:907:9447:b0:a90:c4a0:9b17 with SMTP id a640c23a62f3a-a92c4810ee5mr641184766b.9.1727244080231; Tue, 24 Sep 2024 23:01:20 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , "Daniel P. Smith" , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v4 4/4] x86/boot: Improve MBI2 structure check Date: Wed, 25 Sep 2024 07:01:01 +0100 Message-Id: <20240925060101.259244-5-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: 1727244734933116600 Content-Type: text/plain; charset="utf-8" Tag structure should contain at least the tag header. Entire tag structure must be contained inside MBI2 data. Signed-off-by: Frediano Ziglio --- xen/arch/x86/efi/parse-mbi2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/efi/parse-mbi2.c b/xen/arch/x86/efi/parse-mbi2.c index 89c562cf6a..0b080dfa92 100644 --- a/xen/arch/x86/efi/parse-mbi2.c +++ b/xen/arch/x86/efi/parse-mbi2.c @@ -13,6 +13,7 @@ efi_multiboot2_prelude(uint32_t magic, const multiboot2_f= ixed_t *mbi) EFI_HANDLE ImageHandle =3D NULL; EFI_SYSTEM_TABLE *SystemTable =3D NULL; const char *cmdline =3D NULL; + const void *const mbi_end =3D (const void *)mbi + mbi->total_size; bool have_bs =3D false; =20 if ( magic !=3D MULTIBOOT2_BOOTLOADER_MAGIC ) @@ -21,7 +22,9 @@ efi_multiboot2_prelude(uint32_t magic, const multiboot2_f= ixed_t *mbi) /* Skip Multiboot2 information fixed part. */ tag =3D _p(ROUNDUP((unsigned long)(mbi + 1), MULTIBOOT2_TAG_ALIGN)); =20 - for ( ; (const void *)tag - (const void *)mbi < mbi->total_size + for ( ; (const void *)(tag + 1) <=3D mbi_end + && tag->size >=3D sizeof(*tag) + && (const void *)tag + tag->size <=3D mbi_end && tag->type !=3D MULTIBOOT2_TAG_TYPE_END; tag =3D _p(ROUNDUP((unsigned long)((const void *)tag + tag->size= ), MULTIBOOT2_TAG_ALIGN)) ) --=20 2.34.1