From nobody Sun Dec 22 06:09:10 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=1727342501; cv=none; d=zohomail.com; s=zohoarc; b=O8Sq+SRDe091WvMGTpbfAa8PUF+QzkCdG2y/km5xEOKPfjk+6DuJO2XZiRI5pmhGRuuGv20CIdttHAiA87DK8PVWCLogai2DO8sF0slhbkcTEiB/TGzwWv3IsQ5qrY4KULWCQW+fl2D1Xq167PCqVEX2ONdcO4MAcgapZYzYw9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727342501; 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=S70211ALl89jb/A0SZTofQwu7xG6yOycti6baccoONo=; b=NiLJg/hlA4q5KtVLHy4UTuKNa1xj2HMv2MeQiBjHp1RJKqMN2niNT2MvLJoS0ktEHUsDk10nKFqu398Y6Zk9oKflGKPaMm/vyLAZbOwhItHnRgd7UFV0iPmurkEt1cA51duSEyHWNh747fAB9+ciybVJOz0XF8W45OiEqP7KqZY= 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 1727342501347838.8880434690715; Thu, 26 Sep 2024 02:21:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.805089.1216115 (Exim 4.92) (envelope-from ) id 1stkgb-0001z9-G5; Thu, 26 Sep 2024 09:21:21 +0000 Received: by outflank-mailman (output) from mailman id 805089.1216115; Thu, 26 Sep 2024 09:21:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stkgb-0001yD-Be; Thu, 26 Sep 2024 09:21:21 +0000 Received: by outflank-mailman (input) for mailman id 805089; Thu, 26 Sep 2024 09:21: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 1stkga-0001w1-BP for xen-devel@lists.xenproject.org; Thu, 26 Sep 2024 09:21:20 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b09094a4-7be8-11ef-a0ba-8be0dac302b0; Thu, 26 Sep 2024 11:21:19 +0200 (CEST) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a8d2b24b7a8so351875266b.1 for ; Thu, 26 Sep 2024 02:21:19 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9392f5485asm325846666b.88.2024.09.26.02.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 02:21:18 -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: b09094a4-7be8-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1727342479; x=1727947279; 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=S70211ALl89jb/A0SZTofQwu7xG6yOycti6baccoONo=; b=daBAYndEcrveyMX8AhioSCe4VfZa0Tlh3xKSdUska8n4F+Grt/AG9OFoKtBSq5vNVM r/YejshtuU30wZHjEFehv/gZB9sYSnrCWiVJcY7Phl6JIttslDX/GhN9gD74ZPbmr/IG Gm3T71e4BaqHghmCOEK5A0ZZHTjOSK+83QywI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727342479; x=1727947279; 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=S70211ALl89jb/A0SZTofQwu7xG6yOycti6baccoONo=; b=EdPfmRldHn2kA8WkAK1Hd2jQcxiVBuw5y6qw1ysdf5TgbWzNECRyz84zJRxYDgcOpH rGcprAbFmeSadUakywkjXncGOEaE70MyKM/m0BWjJh5hIJQe6Shi7zMH/81qspHJqrlu J/bvlrbebWfMTwXzY1qOxAPlYuoo2GQeGHQSmXS/lukVqYM7oeGLX2oKxR+y4vECfgAi MMzgzc/pOSBqDinR/dpgxkBmiyevpRxcQ4prx85DxHgJ8NiEVutyejUwndlYxDMuCKUN Klk9bgr1P+bDp4JlSLke24z5uHzID3Sf3AXZI2Mfpe2H8A7O0BDaC1I/QJnNDy6B3mtG SXtg== X-Gm-Message-State: AOJu0YwZ7DMuTghbxpmzoQ6PE4M/W/H/Ly72RbGlAJ0DIPPytCK4umL7 G+DrnlrNOUII1qTDKpVTO2i49KoxdUeUg2y7VQus+uownpggiFivD1r5f9/R2cB8j9+rKkWkbyZ J X-Google-Smtp-Source: AGHT+IEcf4/lScaVZLzpXZT3ERQ12hSbh7r2/s33qXGej6Pc+j/Dl2WVNUdpBrtZnBvLJhojXZrpww== X-Received: by 2002:a17:907:9728:b0:a90:34e8:6761 with SMTP id a640c23a62f3a-a93b157ccfbmr291353666b.6.1727342478808; Thu, 26 Sep 2024 02:21: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?= Subject: [PATCH v6 1/3] x86/boot: Refactor BIOS/PVH start Date: Thu, 26 Sep 2024 10:21:07 +0100 Message-Id: <20240926092109.475271-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240926092109.475271-1-frediano.ziglio@cloud.com> References: <20240926092109.475271-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1727342501754116600 Content-Type: text/plain; charset="utf-8" The 2 code paths were sharing quite some common code, reuse it instead of having duplications. 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. Changes since v4: - remove old sentence from commit message; - fixed a typo; - load XEN_HVM_START_MAGIC_VALUE constant directly; - set %fs and %gs as other segment registers; - remove some spurious line changes. Changes since v5: - fixed a typo. --- xen/arch/x86/boot/head.S | 104 ++++++++++++++------------------------- 1 file changed, 37 insertions(+), 67 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 267207e5a2..e0901ee400 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 $XEN_HVM_START_MAGIC_VALUE, %eax + /* + * Fall through into BIOS code. + * We will use %eax to distinguish we came from PVH 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. + * + * During 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 @@ -448,19 +457,9 @@ __pvh_start: mov %ecx, %ds mov %ecx, %es mov %ecx, %ss + mov %ecx, %fs + mov %ecx, %gs =20 - /* Skip bootloader setup and bios setup, go straight to trampoline= */ - movb $1, sym_esi(pvh_boot) - movb $1, sym_esi(skip_realmode) - - /* 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 =20 @@ -472,39 +471,25 @@ __pvh_start: rep stosl =20 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) + 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 +548,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 Dec 22 06:09:10 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=1727342504; cv=none; d=zohomail.com; s=zohoarc; b=knrgx3n3KUNVVG6baMn6EbzPuFWeGBr6pNDmJEFkIUuLVxdRDqJIP++EPZbXDypeZ7o7hz77Ft6t1gMpISbdfOz7/Nq19EEbHNjKioLrRPbgqYDQfxpvtfFZvhBhcAuHyOJZNBZAJvtzOizbNbrlckZ+h8fWVR7in7ghiqsCoMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727342504; 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=RE9zPGw7uXdaStphlidPBgHBY1QIBKq37/9PhyIL3ZI=; b=FLYpltE8Yt01KysZfjWK35/aM6ZWiqyDHaxLwZ3/swFya+/EdUaEGzp4KKzqyuzPHubUzdYrt5ONd+eIx2Qc4tRd/VtP76vOy8ox52viNRt5EwcUQDv5TiBK0naiNDQcFnXWxSgdoV2lOsDtPEEznbY08sTifgzKkJ7n7eMvnBQ= 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 1727342504432813.9103018567495; Thu, 26 Sep 2024 02:21:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.805091.1216140 (Exim 4.92) (envelope-from ) id 1stkgf-0002g4-2a; Thu, 26 Sep 2024 09:21:25 +0000 Received: by outflank-mailman (output) from mailman id 805091.1216140; Thu, 26 Sep 2024 09:21: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 1stkge-0002fv-Vg; Thu, 26 Sep 2024 09:21:24 +0000 Received: by outflank-mailman (input) for mailman id 805091; Thu, 26 Sep 2024 09:21:23 +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 1stkgd-0002PZ-79 for xen-devel@lists.xenproject.org; Thu, 26 Sep 2024 09:21:23 +0000 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [2a00:1450:4864:20::62d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b1474486-7be8-11ef-99a2-01e77a169b0f; Thu, 26 Sep 2024 11:21:21 +0200 (CEST) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a7aa086b077so100973966b.0 for ; Thu, 26 Sep 2024 02:21:21 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9392f5485asm325846666b.88.2024.09.26.02.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 02:21: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: b1474486-7be8-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1727342480; x=1727947280; 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=RE9zPGw7uXdaStphlidPBgHBY1QIBKq37/9PhyIL3ZI=; b=fBtfzHfVf5rmKM7MW8IpwtebkxAHajLldhrriT2w7cEPXxmW7MSWmLRi3fhs8WiGD8 Kjo7sTUFAhc7XpgIEILH4WV82A+AMQL5v3Va+sYlmcNTXOCgt6Zq73SbsuIewAXWdiyA DI0m+UJGP4Dr2thSf0W0Sag1k4p/La33qciJ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727342480; x=1727947280; 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=RE9zPGw7uXdaStphlidPBgHBY1QIBKq37/9PhyIL3ZI=; b=KBSrgXqR0fjNqbuiLOtaL2G7FL9ALwZeHvF/xLPcw2DCJktfGBLZXYWyW94TQi6b0z ZK1+Pa8q5PsRKPdRHYBGbb0W3HTMmiCw4ZfUDekzWIN+qJpesE62LaClWswS03IWGB7L vTmjyLakLYPnstGgp3821KU8hihsWcw0WslKjEZHM8Io4XQqGnRBNJNS1/XlNqJFJTP9 1Ma3W6IVaf1GSgcxKhQ9/cXcNCFk8kr6MqU4sGrD6+sn3p8A2GMbdCu0YgAY9z+1DNlB cKTB6RvDOd7phyY9zJ813LymyOrw7D9UcJKNCI9h8YOyzoknuduHFmcz1Mh/xG8cBDGf dz5Q== X-Gm-Message-State: AOJu0YwtF8dbISkLC9GqXF4Xn93k6hRxRFxwKmexpapooLVV6HNUG+bW GplM7iw6oHYPUbLQVreFJna35QJmwACjiknqgqIM7HRm8h4j0ExZ7lGxsh2J8IGzA8xUbLadYyn p X-Google-Smtp-Source: AGHT+IHFRVspOhDtMBFEaXV9v9KX/s1hg6/MJiDsMDUeP1OVuCIzeO1tGRO0LmngKLBpGva0Xnpr8w== X-Received: by 2002:a17:907:3daa:b0:a86:6d39:cbfd with SMTP id a640c23a62f3a-a93a0682bd7mr583743166b.57.1727342480132; Thu, 26 Sep 2024 02:21:20 -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 v6 2/3] x86/boot: Rewrite EFI/MBI2 code partly in C Date: Thu, 26 Sep 2024 10:21:08 +0100 Message-Id: <20240926092109.475271-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240926092109.475271-1-frediano.ziglio@cloud.com> References: <20240926092109.475271-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1727342505872116600 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. Changes since v4: - fix some style and space; - fix MISRA requirement. --- 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 | 63 +++++++++++++++ xen/arch/x86/efi/stub.c | 3 +- xen/arch/x86/include/asm/efi.h | 18 +++++ 6 files changed, 115 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 e0901ee400..89b5e2af88 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..55a1777483 --- /dev/null +++ b/xen/arch/x86/efi/parse-mbi2.c @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#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)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; + + default: + /* Satisfy MISRA requirement. */ + 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 Dec 22 06:09:10 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=1727342505; cv=none; d=zohomail.com; s=zohoarc; b=BsOlJnsRpN3fKlzLDySYo7giVMuWC1OLyNpH77mM9BCK7o9HCtpepbsFIuNB4QuMAWNNHXUvBdBz0WDc9UBhwoEpYHsLLlAXHrFKUZMysny4VQZuguuMijGXZK2zZXTbnHVOzQHlb/se3/HnEAs6x0lNaxbqShh4xNG3DqQrwM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727342505; 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=zv+yM3lvTRJQIA1+ZYdW3e6DFoAUNOBXydVMy3hCsps=; b=T95S2hGx4x+YLtTyY7ZnLF82moQxUJyipTBQqXSbJwOXv2c/BvqyIj3fX6olzy8nvbCszBMJb2ek3rUOZOgUaiBtw+cEifH0hMo6K2Rrsg+GDJjRcAVPFDc4vHyDtHVdQQNGjHRnOhdlTko5pWGMIGEdUxyZRViOiUp4jkQaNw0= 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 172734250576863.38982947001102; Thu, 26 Sep 2024 02:21:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.805090.1216131 (Exim 4.92) (envelope-from ) id 1stkgd-0002QC-ME; Thu, 26 Sep 2024 09:21:23 +0000 Received: by outflank-mailman (output) from mailman id 805090.1216131; Thu, 26 Sep 2024 09:21:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stkgd-0002Px-JO; Thu, 26 Sep 2024 09:21:23 +0000 Received: by outflank-mailman (input) for mailman id 805090; Thu, 26 Sep 2024 09:21:22 +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 1stkgc-0001w1-9I for xen-devel@lists.xenproject.org; Thu, 26 Sep 2024 09:21:22 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b1c98281-7be8-11ef-a0ba-8be0dac302b0; Thu, 26 Sep 2024 11:21:21 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a8a789c4fc5so317897166b.0 for ; Thu, 26 Sep 2024 02:21:21 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9392f5485asm325846666b.88.2024.09.26.02.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 02:21:20 -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: b1c98281-7be8-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1727342481; x=1727947281; 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=zv+yM3lvTRJQIA1+ZYdW3e6DFoAUNOBXydVMy3hCsps=; b=WJE9Lm6vf3DfZDNo3BuHquUd0Y+swMlK4cNVkk9QM8YOw7k+0cGZoWmMgKVFAwJU7k hBCq0hmwC2ntUJBXBXcDaN7qBPWxbxXMPQ6MEI5/DBcdEvVj8/OIB2VbMf8IBTIxsY2F 9HNvAQOY4bAVoOIFW8R5c5NEkEUwUqLkT119s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727342481; x=1727947281; 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=zv+yM3lvTRJQIA1+ZYdW3e6DFoAUNOBXydVMy3hCsps=; b=JPpx7Pr0CPPk2ptydDpvmwwBtcKjFzoJM8ehw6aGX3gBYLn2PvrMer8aHBZCZLusbB +heWVMgFb3prUemkgOdThDxELfvxYk4p2Q5ht3cgFglMG3eXoDL57VBnqlTXkJ3YDCWL 5jmzffkcrUFwe95ljJ7LxPvHOAIugfEJh/ZERyGCKZp6CxxZNh2vdk5hU8icEkVBDBDd XJZoQiH4mtwtAwGqCSLc9zaPexCthKkb3tiqXqID4/UyjO3u8tKotGf90C4TiYpqW5X9 sDtVgGCDR5vwxzpKzUZ72Y0ncoYZDjpW3IrpawCev3sF3Wr1/xyMgRg18LXyI3WIRGaW 5L2g== X-Gm-Message-State: AOJu0YxucaNBXhv4gPFSsG8w5g+viACyZPI5NWO4wBuLuN6wfXOtqwf8 Ppzeoh13U6/T9de3Z4gUIyU9PK5Qu1KxJ42c4DU09J2R5GZy+8cfy3w4mBPikaQA0JNTX2h0ra9 8 X-Google-Smtp-Source: AGHT+IH8pM7sNRHOHPY0mSu77Jrh0ij1F71jjKeCo0sGy21bnOxVElQnJcwDqoWNpL3dlLEi4l8lrg== X-Received: by 2002:a17:907:36c6:b0:a8a:7884:c491 with SMTP id a640c23a62f3a-a93b15f9342mr247811666b.17.1727342481006; Thu, 26 Sep 2024 02:21:21 -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 v6 3/3] x86/boot: Improve MBI2 structure check Date: Thu, 26 Sep 2024 10:21:09 +0100 Message-Id: <20240926092109.475271-4-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240926092109.475271-1-frediano.ziglio@cloud.com> References: <20240926092109.475271-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1727342507682116600 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 55a1777483..cae26d5e10 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)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) ) --=20 2.34.1