From nobody Thu Nov 21 19:54:42 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=1723038544; cv=none; d=zohomail.com; s=zohoarc; b=bbGuaGOK81Ud86H7I9eBvMmh42bor4h4AoHQJ86Th7FRWCYeIlGJBIuPAu5kVlGL0h/M9t6MVMtkPOACXbPA01oasN1s4+EGbflD5xpVBurAT2wJAUNwBnBTzi0vbMc1PtcUyBVtFWHWUqv5a32gZJIvYM+56URyzJmzsdy3fS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723038544; 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=o7eodO/9HzqH08fbvCI7vy2Uyw8SnwXrkAc77uD4d2A=; b=IMqFtJYpUyVJRMoel+uyWzE10JRSsG5x64xj8erAk09arwHD0iJcAuUVbB2OweKetVtHOMMoxwJB+k1W1wtkYNXBupddUODCgcs7ToTEqhZzDFd82sug1sOWuEcjWKr0k7Vnp02tLSc+8y4fr89X/JATKTKOgZCcMmh3UgXXtcY= 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 1723038544645771.8818650332588; Wed, 7 Aug 2024 06:49:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.773500.1183943 (Exim 4.92) (envelope-from ) id 1sbh1x-0005JH-EY; Wed, 07 Aug 2024 13:48:45 +0000 Received: by outflank-mailman (output) from mailman id 773500.1183943; Wed, 07 Aug 2024 13:48:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sbh1x-0005HQ-7G; Wed, 07 Aug 2024 13:48:45 +0000 Received: by outflank-mailman (input) for mailman id 773500; Wed, 07 Aug 2024 13:48:43 +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 1sbh1v-0005AD-It for xen-devel@lists.xenproject.org; Wed, 07 Aug 2024 13:48:43 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c193147c-54c3-11ef-8776-851b0ebba9a2; Wed, 07 Aug 2024 15:48:41 +0200 (CEST) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5a10835487fso2854813a12.1 for ; Wed, 07 Aug 2024 06:48:41 -0700 (PDT) Received: from EMEAENGAAD19049.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83960f353sm7017710a12.15.2024.08.07.06.48.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 06:48:40 -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: c193147c-54c3-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723038521; x=1723643321; 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=o7eodO/9HzqH08fbvCI7vy2Uyw8SnwXrkAc77uD4d2A=; b=eBmFeBDkNd87aJhO+ZE7x/ImfPfj+wxGn0b6RqJRAry5eqGWjMu2VUkh3mniOF1LUY 8kJfDYYZkcDYt+MEkFIgHLYwdSVQlsQga4mP3d/xyAiQMoAPUJysjYgxXKw96el3Wxy/ GEmzKfZkfRwpLxhevcFbs85MkQwB77S3BpB7o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723038521; x=1723643321; 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=o7eodO/9HzqH08fbvCI7vy2Uyw8SnwXrkAc77uD4d2A=; b=Z/JNdUw//WdfpfZ1FMEzStTe2l3w2u/IHPrhWSFpk00EdoS/c5qQHpcsmvR7dR5+D/ C4dSPxIyitib2C8Bn07m9I4L924HopFlXXPXzRkyUuQ9FDd/HyOKLjTDBUx6t8URqPGD omodKRDHbPyX183YMItTs3E2JR63diKKgu2f1OY2fGA+kcU5PCIsf3fIRMMO+3T1ZHzZ ahVx73ytZ76Sq4kbMQsSCupIrklq08P7MnxHN0mYM6XJ/qAxx7+ZguPmr8afRGtWHCjy 5XJ4hESuJfK//08o2ltT6/TkqVzz9cPLxy/Z4xuCSycAPuRPPRaLaY57YuGQWL+ghNTN QSnw== X-Gm-Message-State: AOJu0Ywkf6nM/fM8uHMTgUZwJzAKD1RYO2D0dprDUcwSk5Mz1qeX7jLk dr+NwXnhu8lcWM53IJtongKm/79S0hkU7OWu38JCLXTiSxa+++hYLBP0qvmHi0X7g/Vmu6XMXOl 4 X-Google-Smtp-Source: AGHT+IHfPjkr6YvB77y4L8XA3v+BcfW12X55BGLdGL+x8IdxKIMhcYOiZjiZPba6g4zjb1J6DD+tUA== X-Received: by 2002:a05:6402:2032:b0:5a3:a4d7:caf5 with SMTP id 4fb4d7f45d1cf-5b7f5dc13cemr11942212a12.36.1723038520673; Wed, 07 Aug 2024 06:48:40 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 1/5] x86: Put trampoline in .init.data section Date: Wed, 7 Aug 2024 14:48:15 +0100 Message-ID: <20240807134819.8987-2-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240807134819.8987-1-alejandro.vallejo@cloud.com> References: <20240807134819.8987-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723038545726116600 Content-Type: text/plain; charset="utf-8" This change allows to put the trampoline in a separate, not executable section. The trampoline contains a mix of code and data (data which is modified from C code during early start so must be writable). This is in preparation for W^X patch in order to satisfy UEFI CA memory mitigation requirements. At the moment .init.text and .init.data in EFI mode are put together so they will be in the same final section as before this patch. Signed-off-by: Frediano Ziglio --- xen/arch/x86/boot/head.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index d8ac0f0494..f027ff45fd 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -870,6 +870,8 @@ cmdline_parse_early: reloc: .incbin "reloc.bin" =20 + .section .init.data, "aw", @progbits + .align 4 ENTRY(trampoline_start) #include "trampoline.S" ENTRY(trampoline_end) --=20 2.45.2 From nobody Thu Nov 21 19:54:42 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=1723038548; cv=none; d=zohomail.com; s=zohoarc; b=lRbtDP8DGVKWZ77Q6RdbZ38x2iSGCMK/DT4kNSSy8ZOIZh8JkRt0KloHxyiPHmBecD9QnxY2ht7GCLa9dmxdBEuHE6FIGlVVRTY4bu57ON+4xdzcTYqaXPGqGlUTrEgsF/3bYl/lMv8jpq++n1VKU1zcCyloWu2qLn7GGc9NBUw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723038548; 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=wGRtbIN13o/ciUAaf4wEJGcURp+ZlWP4onOzPdvMd2A=; b=XcUBR2roxIrPZgVPR7xi6jQauRF/Q9L6BQwgr7ElONEyb+weHYmTHVGKOQsKrys3wg/nLVuUDh+s7kljY0EjY9IrZrP0vs2+9bouVMkhvaQ6WJDIzb7c9OVVofssuQZrM/RIet2UzmnuKJYiPceTv3QJB1O/oT3DU1CfOV/tt1g= 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 1723038548211798.9445358879021; Wed, 7 Aug 2024 06:49:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.773499.1183937 (Exim 4.92) (envelope-from ) id 1sbh1x-0005Do-5T; Wed, 07 Aug 2024 13:48:45 +0000 Received: by outflank-mailman (output) from mailman id 773499.1183937; Wed, 07 Aug 2024 13:48:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sbh1w-0005Cw-VF; Wed, 07 Aug 2024 13:48:44 +0000 Received: by outflank-mailman (input) for mailman id 773499; Wed, 07 Aug 2024 13:48:43 +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 1sbh1v-0005AI-E9 for xen-devel@lists.xenproject.org; Wed, 07 Aug 2024 13:48:43 +0000 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [2a00:1450:4864:20::22d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c22c20e7-54c3-11ef-bc04-fd08da9f4363; Wed, 07 Aug 2024 15:48:42 +0200 (CEST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2f040733086so21372121fa.1 for ; Wed, 07 Aug 2024 06:48:42 -0700 (PDT) Received: from EMEAENGAAD19049.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83960f353sm7017710a12.15.2024.08.07.06.48.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 06:48:41 -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: c22c20e7-54c3-11ef-bc04-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723038522; x=1723643322; 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=wGRtbIN13o/ciUAaf4wEJGcURp+ZlWP4onOzPdvMd2A=; b=SAn7ebwph8UNrja7FvAiOECzqlzt6tqo+Kb27CoM7xC2pLtT7vd1pglkORw2k9WBIo xiBMu1+Vp9I0vVTkS4Bjl7ApzaYErat9ef6BdvdlPjQwVLeI9K9Q1uzOYxQAxoJVG/Dv sBt1gLWOZx/GGFszfi0Wx0wKpnnrKn4OnP7qY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723038522; x=1723643322; 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=wGRtbIN13o/ciUAaf4wEJGcURp+ZlWP4onOzPdvMd2A=; b=A7yfaBTUO4ApVZIL5hspa9zqwggSJ/EPLhTkX3F4fXtSOlWkuy17WhMIjjkgVwP6PK LaszW4E42LY/NfpJz+/OqYbbpQ7rMS4IdMGQk98Hbq6JUqDsF7MWf7DrdXIyU4tqGjtv Splzsd6dM7EoOQEpclxb6D8aMjPx5SSbU7eKcpfbpyk7uD/OzioI82qg5g7KEnpBu/We /QNnDURLtSIwaUvP2pdS0fJJSjALZfInox4dGGl5KdwtOeYOxKQ0eLc9n426b2+DBSSs 56g1a/r4vO6WAsE4Zdyv7eFLpwOUTH5cGMU/dpsHQAMkN9+ee04DVnrEKX153R637US+ 9CiQ== X-Gm-Message-State: AOJu0YxBhMM4QwmXuQxEZ0JSgneienu/S2xTBhRR/LLGmagsBEfGFnVR zp5rUhe0EU807tNczkNZlOvfg41d2KQE2Pcbs8pHLPexWReX2nf7riSDY/clvzjP+BkHwltb4SS d X-Google-Smtp-Source: AGHT+IG1l8Rjqon1YH1RNx/xfW2NajRmcQ+83qN/XAymq6z2D6oNRyKPWQ/aF56UUdD0Gabg4msoyA== X-Received: by 2002:a2e:9bc5:0:b0:2f0:1fd5:2f29 with SMTP id 38308e7fff4ca-2f15aaa6099mr129936081fa.19.1723038521707; Wed, 07 Aug 2024 06:48:41 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 2/5] x86: Fix early output messages in case of EFI Date: Wed, 7 Aug 2024 14:48:16 +0100 Message-ID: <20240807134819.8987-3-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240807134819.8987-1-alejandro.vallejo@cloud.com> References: <20240807134819.8987-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723038549454116600 Content-Type: text/plain; charset="utf-8" If code is loaded by EFI the loader will relocate the image under 4GB. This cause offsets in x86 code generated by sym_offs(SYMBOL) to be relocated too (basically they won't be offsets from image base). In order to get real offset the formulae "sym_offs(SYMBOL) - sym_offs(__image_base__)" is used instead. Also, in some case %esi register (that should point to __image_base__ addresss) is not set so compute in all cases. Code tested forcing failures in the code. Signed-off-by: Frediano Ziglio --- xen/arch/x86/boot/head.S | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index f027ff45fd..296f76146a 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -188,8 +188,27 @@ early_error: /* Here to improve the disassembly. */ xor %edi,%edi # No VGA text buffer jmp .Lprint_err .Lget_vtb: - mov sym_esi(vga_text_buffer), %edi + mov $sym_offs(vga_text_buffer), %edi .Lprint_err: + mov $sym_offs(__image_base__), %ebx + + /* compute base, relocation or not */ + call 1f +1: + pop %esi + subl $sym_offs(1b), %esi + addl %ebx, %esi + + /* adjust offset and load */ + test %edi, %edi + jz 1f + subl %ebx, %edi + movl (%edi,%esi,1), %edi +1: + + /* adjust message offset */ + subl %ebx, %ecx + add %ecx, %esi # Add string offset to relocation base. # NOTE: No further use of sym_esi() till the end of the "function"! 1: --=20 2.45.2 From nobody Thu Nov 21 19:54:42 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=1723038547; cv=none; d=zohomail.com; s=zohoarc; b=TeJ2yEplIrLiCKUrjh0T0FuRDj0p9oxB+frelg6sD+z74DMzBy1jAQ/NhW94/0FeM3J0ebtPmUZO7AxwhMK8qMSUIvOX/FFDoSlJY2mT1g/NxXUzr+E4aqfyp0R8lhAgeicHNHY1ctfL8QatuqIegu7xBMe0sEqCqc0NUNCvljY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723038547; 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=6ss20XkPoOS/17MJ2dIfZqErwnJ4zQ6MM+H++oOIE0s=; b=hVEdXFdSVMApUEjcBsLDG22RrWMF3F0QqWZHKrqAjCnwvVROCdp8O/wzitpDmHHrgPg6SFkEgTHCnqY0dWo0L9RVQwTlJ7cMNI4WNKjelrIcXeZPeIXDa7nuoX5zm38W/mqo7ArY2Kan1gaeu8lc6xVlzmKnx7ybTBbUxg/bpCk= 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 1723038547564477.3495543276715; Wed, 7 Aug 2024 06:49:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.773501.1183960 (Exim 4.92) (envelope-from ) id 1sbh1y-0005qC-Ij; Wed, 07 Aug 2024 13:48:46 +0000 Received: by outflank-mailman (output) from mailman id 773501.1183960; Wed, 07 Aug 2024 13:48:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sbh1y-0005pG-FR; Wed, 07 Aug 2024 13:48:46 +0000 Received: by outflank-mailman (input) for mailman id 773501; Wed, 07 Aug 2024 13:48:45 +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 1sbh1x-0005AD-7r for xen-devel@lists.xenproject.org; Wed, 07 Aug 2024 13:48:45 +0000 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [2a00:1450:4864:20::536]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c2d5edc2-54c3-11ef-8776-851b0ebba9a2; Wed, 07 Aug 2024 15:48:43 +0200 (CEST) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5af51684d52so2139034a12.1 for ; Wed, 07 Aug 2024 06:48:43 -0700 (PDT) Received: from EMEAENGAAD19049.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83960f353sm7017710a12.15.2024.08.07.06.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 06:48:42 -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: c2d5edc2-54c3-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723038523; x=1723643323; 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=6ss20XkPoOS/17MJ2dIfZqErwnJ4zQ6MM+H++oOIE0s=; b=RsJ/oxCBXDZjOo6aTCy7P52KXLoHF0bMgk3jQCQuPmRxpDzo1dSkDk5Nmi4d/zrf4x Py37kFqTczOaBcS7dZLcM141TeAQKkoB4JlrxDUvbIKtjIC7h2sGVcLFMedSpdymynXY kolwpFcbCjui/g6sPOkSlKgWYNOJRsxNZWc6M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723038523; x=1723643323; 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=6ss20XkPoOS/17MJ2dIfZqErwnJ4zQ6MM+H++oOIE0s=; b=JVHKYraNbwEtI8D+cLoRtnWPBZj+wJPCA7AXrASwjL+JhzEd3ydOMjwRD+TC/42Nrc ZEUsFMHMvXO/giEBO30xEkcVtkd7BrDtLYC8wzE+oijXrh0qB7ghdKPUZdRyEfFaKqtf JSQvNGp7XnfWy+pCXNH4dWBqxeqslmd4m/u5Cx6NaeU9jtSKuUAjxeXeBsZjDfvCDVqX j/l7ZMLTYGEEkrRK0ofxXxaI5GHtRob/URrMGxPPx99s5/axwntEzIo2JhZUN/M/mjfr usla7QhOYRgeQXDBIlufE/PlzUJ/qlI46BLtXRUpckDIllVPLEaxfv68hcbeLzLAUhCl A5mg== X-Gm-Message-State: AOJu0Yw0NRT+kziN9Ip7ahNDKXo9DlnNiAFATbWPjr1WKza70fUfW5k2 qcaLtPhpN4MJcCi9wvUdrc+uFkm8U62ibfedmOTs7yEUNdHzRwW6pUSaRKLo51mnLuB/TOyiKcR C X-Google-Smtp-Source: AGHT+IHCXTM5fGaE9/iFzHECw4HaTuzn5M6eXxe17YBVWA7pFfxIaCBP3tiSHOseOczCK8WOgg8Oog== X-Received: by 2002:a50:ff0b:0:b0:5a0:f8a2:9cf4 with SMTP id 4fb4d7f45d1cf-5b7f5129b4bmr12290625a12.25.1723038522669; Wed, 07 Aug 2024 06:48:42 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 3/5] x86: Set xen_phys_start and trampoline_xen_phys_start earlier Date: Wed, 7 Aug 2024 14:48:17 +0100 Message-ID: <20240807134819.8987-4-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240807134819.8987-1-alejandro.vallejo@cloud.com> References: <20240807134819.8987-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723038549459116600 Content-Type: text/plain; charset="utf-8" No reason to wait, if Xen image is loaded by EFI (not multiboot EFI path) these are set in efi_arch_load_addr_check, but not in the multiboot EFI code path. This change makes the 2 code paths more similar and allows the usage of these variables if needed. Signed-off-by: Frediano Ziglio --- xen/arch/x86/boot/head.S | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 296f76146a..5b82221038 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -259,6 +259,11 @@ __efi64_mb2_start: jmp x86_32_switch =20 .Lefi_multiboot2_proto: + /* Save Xen image load base address for later use. */ + lea __image_base__(%rip),%rsi + movq %rsi, xen_phys_start(%rip) + movl %esi, trampoline_xen_phys_start(%rip) + /* Zero EFI SystemTable, EFI ImageHandle addresses and cmdline. */ xor %esi,%esi xor %edi,%edi @@ -605,10 +610,6 @@ trampoline_setup: * Called on legacy BIOS and EFI platforms. */ =20 - /* Save Xen image load base address for later use. */ - mov %esi, sym_esi(xen_phys_start) - mov %esi, sym_esi(trampoline_xen_phys_start) - /* Get bottom-most low-memory stack address. */ mov sym_esi(trampoline_phys), %ecx add $TRAMPOLINE_SPACE,%ecx --=20 2.45.2 From nobody Thu Nov 21 19:54:42 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=1723038547; cv=none; d=zohomail.com; s=zohoarc; b=JLT4rKcnVP15OP8Yt+lv+CGHbUsw5cIS82WL9ZY/YPq44WYxCbDdklTjMIjwTOh2thg1z2j8y4J0Zw3EuS5JFuuMjV4g+N1Y0lNb7v6YScydGynAMVbQopYaYdtmSpPPU01uvJijkFK5JJK3WhP4y/YuphpbJIMA/EMSQgZKrPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723038547; 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=PtnPxebiV0FOs9Be6cyaf3Vp45b5Mwz7UfucVn6WbxI=; b=MwBsnm/sLaDr7uu9DASLsQvc6edx4r4hvpXRmD2mnUE++B8osLq8JbAeI9sYUg15LB2qNheG9QF2BXMvF8/aAXo1HHSTbs/2VZNpBBuWuf6w3bsup/Mu652ZZFZnuDaV8kZUbsmByh/BF2U8YOQAxh1VvRSjnFRXeATIcn7GJDQ= 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 1723038547551543.2097619901359; Wed, 7 Aug 2024 06:49:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.773503.1183976 (Exim 4.92) (envelope-from ) id 1sbh20-00069z-Dh; Wed, 07 Aug 2024 13:48:48 +0000 Received: by outflank-mailman (output) from mailman id 773503.1183976; Wed, 07 Aug 2024 13:48:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sbh20-00068s-5M; Wed, 07 Aug 2024 13:48:48 +0000 Received: by outflank-mailman (input) for mailman id 773503; Wed, 07 Aug 2024 13:48:46 +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 1sbh1x-0005AD-UC for xen-devel@lists.xenproject.org; Wed, 07 Aug 2024 13:48:45 +0000 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [2a00:1450:4864:20::530]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c333feae-54c3-11ef-8776-851b0ebba9a2; Wed, 07 Aug 2024 15:48:44 +0200 (CEST) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5b01af9b0c9so2004978a12.3 for ; Wed, 07 Aug 2024 06:48:44 -0700 (PDT) Received: from EMEAENGAAD19049.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83960f353sm7017710a12.15.2024.08.07.06.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 06:48:43 -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: c333feae-54c3-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723038523; x=1723643323; 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=PtnPxebiV0FOs9Be6cyaf3Vp45b5Mwz7UfucVn6WbxI=; b=CqtN8RIhDHwMHJhKxxyFN4vudwuoTeLauX9/MSOXiLxERpzpwPer2QdK+72gXEo8w6 XVRDtou9y0sEJYXW7bp5D+Ij60WXGsM+SBcjHlbubaHRCSidITyvn9HIs4B/NJ8MuxWF i93HU5eF7le5GT0Diecat8RDQeUHAQH9sPbRM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723038523; x=1723643323; 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=PtnPxebiV0FOs9Be6cyaf3Vp45b5Mwz7UfucVn6WbxI=; b=Qh3AcLAo46LZEfNYbgqgNHyBDrL5Gg4qlnbOgvzZ4GI4DCr4/fs9rR4SPNuDw3vbjU McnfEAIcmclCLIC9fV9sqUyb9TUfZb4NRvlceqR9L6blW9QMOsIYl8yAJYNB0vytVxpi IJ50NCmYrUqLrqv8FERWz5y5rpiinuzbABrwhN4Nm8KzQwH3wSypBMYAGIIy6mTXw8WO OlYqQ1xu0BVzKTNbw/PoaLeuzA6amosZ3k8VljoAcfoFwmMQE8geRSJrm8rmC8GKasiQ TNRX6jKSCa97C5QxDGXvXUcY+4sWFJ56FTrOLyeNta4rvXGBO5f1zsYujcooByXWbv8B 0yXg== X-Gm-Message-State: AOJu0Yy7aEzMgxx9eTWaLGf2gKzK7qdNI7gFyerFoJ/hkB/y9TxqhU6r /4QkOSjifTx+u+F7gWTnA+eUhfG5v3XR1aMzwqJQ7jK/rHErfaxt62nTuTIpCkyNK3StYj9U+Vr y X-Google-Smtp-Source: AGHT+IG4FXzaPjOkx4vTqxbBk8DdOUhH9rRyVIw44LocTNgv3PCN99jLkRnGQYbczuJH1gfp0oL8Xw== X-Received: by 2002:aa7:d501:0:b0:584:8feb:c3a1 with SMTP id 4fb4d7f45d1cf-5b7f36f8e9fmr13738466a12.1.1723038523464; Wed, 07 Aug 2024 06:48:43 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 4/5] x86: Force proper gdt_boot_base setting Date: Wed, 7 Aug 2024 14:48:18 +0100 Message-ID: <20240807134819.8987-5-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240807134819.8987-1-alejandro.vallejo@cloud.com> References: <20240807134819.8987-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723038549461116600 Content-Type: text/plain; charset="utf-8" Instead of relocate the value at that position compute it entirely and write it. During EFI boots sym_offs(SYMBOL) are potentially relocated causing the values to be corrupted. For PVH and BIOS the change won't be necessary but keep the code consistent. Signed-off-by: Frediano Ziglio --- xen/arch/x86/boot/head.S | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 5b82221038..abfa3d82f7 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -132,8 +132,7 @@ multiboot2_header: gdt_boot_descr: .word .Ltrampoline_gdt_end - trampoline_gdt - 1 gdt_boot_base: - .long sym_offs(trampoline_gdt) - .long 0 /* Needed for 64-bit lgdt */ + .quad 0 /* Needed for 64-bit lgdt */ =20 vga_text_buffer: .long 0xb8000 @@ -392,15 +391,16 @@ __efi64_mb2_start: x86_32_switch: mov %r15,%rdi =20 - /* Store Xen image load base address in place accessible for 32-bi= t code. */ - lea __image_base__(%rip),%esi - cli =20 /* Initialize GDTR. */ - add %esi,gdt_boot_base(%rip) + lea trampoline_gdt(%rip),%esi + movl %esi,gdt_boot_base(%rip) lgdt gdt_boot_descr(%rip) =20 + /* Store Xen image load base address in place accessible for 32-bi= t code. */ + lea __image_base__(%rip),%esi + /* Reload code selector. */ pushq $BOOT_CS32 lea cs32_switch(%rip),%edx @@ -458,7 +458,8 @@ __pvh_start: movb $-1, sym_esi(opt_console_xen) =20 /* Prepare gdt and segments */ - add %esi, sym_esi(gdt_boot_base) + lea sym_esi(trampoline_gdt), %ecx + movl %ecx, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) =20 mov $BOOT_DS, %ecx @@ -562,7 +563,8 @@ trampoline_bios_setup: * * Initialize GDTR and basic data segments. */ - add %esi,sym_esi(gdt_boot_base) + lea sym_esi(trampoline_gdt), %ecx + movl %ecx, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) =20 mov $BOOT_DS,%ecx --=20 2.45.2 From nobody Thu Nov 21 19:54:42 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=1723038545; cv=none; d=zohomail.com; s=zohoarc; b=UMvzsVLTMUwFfXdBiAWlHdR0PuUPLlemquwexCrixVFkfZeWt3PYE0obWEt4bk9Em6dSLL8di9QqMNdr9eE2FoAJnZ0OI1uH7LL+uQ3dTqkLKIOY/pDU1ShFTzyiNhteyDDi/IXTzzVbirlMrTMOW+so0fJGc2TnhuKH/t5jMCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723038545; 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=j0P2O0so3M3+faOWsBdEY2/POlgK4yVIXKMk2Q6OuFU=; b=PcF4W/6iNXnITgK2bgOAolHmxVUQyo1Wc3iKMRmyzOG7yWWZJdZv0bkYAAmHp8WXP1wOiTJtA6SNz3zXchdofg45+zC4gEV5SiEG+h5hW7xkdAUMf+dLVXAE9uvAvYQlF1R1RpE8yi5c/5cyFZE0gH6lHSoxGbJisziOjgNhfYE= 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 172303854586632.22212495285146; Wed, 7 Aug 2024 06:49:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.773502.1183971 (Exim 4.92) (envelope-from ) id 1sbh20-00067w-1u; Wed, 07 Aug 2024 13:48:48 +0000 Received: by outflank-mailman (output) from mailman id 773502.1183971; Wed, 07 Aug 2024 13:48:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sbh1z-00067o-Ud; Wed, 07 Aug 2024 13:48:47 +0000 Received: by outflank-mailman (input) for mailman id 773502; Wed, 07 Aug 2024 13:48:46 +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 1sbh1x-0005AI-Tx for xen-devel@lists.xenproject.org; Wed, 07 Aug 2024 13:48:45 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c3d58bc4-54c3-11ef-bc04-fd08da9f4363; Wed, 07 Aug 2024 15:48:45 +0200 (CEST) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5bb8e62570fso2684663a12.1 for ; Wed, 07 Aug 2024 06:48:45 -0700 (PDT) Received: from EMEAENGAAD19049.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83960f353sm7017710a12.15.2024.08.07.06.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 06:48:43 -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: c3d58bc4-54c3-11ef-bc04-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723038524; x=1723643324; 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=j0P2O0so3M3+faOWsBdEY2/POlgK4yVIXKMk2Q6OuFU=; b=iAoiPvx3eMS3A+aZnAIzNn02TKhWoTZGBKy4BjNlv1A0OApXKCZzVuHnzS1hxN54ad exjUozp6ApvCoRNNLG3ue40u4U00SIUCpUXvtq6xZ/sAaeMKj3BLB8X5t9n7TWGpkHd0 vlX5Uzm5z24KUryTXGQBoCBLbFOJgmCFiwyPo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723038524; x=1723643324; 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=j0P2O0so3M3+faOWsBdEY2/POlgK4yVIXKMk2Q6OuFU=; b=Vo895biDKg1Ejz9G/nKeGRzdJF1jFMY8BoouipR5nqg5BC+oj6Gt16iF0GYblCE5dp 2lpn0zw80ArKrrGHa94OyAcUVkp4Hu567291Qbj+Sq9nC08MMrbSWplcCCMSXaQZMwp6 z/8iIsGPbYRl7VZ67gEpS3UkQDs8RKEXlwmrBPDkSiCdXgNCl35JrZ8qQktd80cYNlg9 oBb4oMSGisZe45sPJ3HdGM3KBAWrPks7k/DybJ8/AKm8SJ71nnLNgJKYafo8P5kXYfQG zwAd5QPqj4ZVoytIvbO7mFmQpOHL7LnnVj0QqpdSwMA5iTnMvcxO/+kPtcwVKMA8XW46 iRsw== X-Gm-Message-State: AOJu0YwKvGetLtxhO2K4BXnYfr9uH0PR5ch2rvHZGZq1Xl9GaDrF7u6z 5ciP+E99vVoOvOtZJPEGdcNh9F/wYhwldBb/Mr0Vd+9QaVrrtXrs2R4shdp4RrMfu/hg1fUfzux K X-Google-Smtp-Source: AGHT+IFxiUbA4aqh8QoSftI9J0K9AalqflVdBk2c6Kh9BR0drMFevjsJzg2bcxaav/UmEHj0VqlgvA== X-Received: by 2002:aa7:c3cc:0:b0:5a0:e62c:61bd with SMTP id 4fb4d7f45d1cf-5b7f5413b5cmr12727946a12.29.1723038524429; Wed, 07 Aug 2024 06:48:44 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 5/5] x86: Rollback relocation in case of EFI multiboot Date: Wed, 7 Aug 2024 14:48:19 +0100 Message-ID: <20240807134819.8987-6-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240807134819.8987-1-alejandro.vallejo@cloud.com> References: <20240807134819.8987-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723038547430116600 Content-Type: text/plain; charset="utf-8" In case EFI not multiboot rolling back relocation is done in efi_arch_post_exit_boot, called by efi_start however this is not done in multiboot code path. Do it also for this path to make it work correctly. Signed-off-by: Frediano Ziglio --- xen/arch/x86/boot/head.S | 29 +++++++++++++++--- xen/arch/x86/boot/reloc.c | 63 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index abfa3d82f7..75ac74a589 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -352,6 +352,7 @@ __efi64_mb2_start: and $~15,%rsp =20 /* Save Multiboot2 magic on the stack. */ + shlq $32, %rax push %rax =20 /* Save EFI ImageHandle on the stack. */ @@ -382,11 +383,24 @@ __efi64_mb2_start: /* Just pop an item from the stack. */ pop %rax =20 - /* Restore Multiboot2 magic. */ - pop %rax + /* Prepare stack for relocation call */ + subq $16, %rsp + lea l2_bootmap(%rip), %ecx + movl %ecx, 16(%rsp) + lea l3_bootmap(%rip), %ecx + movl %ecx, 12(%rsp) + lea __base_relocs_end(%rip), %ecx + movl %ecx, 8(%rsp) + lea __base_relocs_start(%rip), %ecx + movl %ecx, 4(%rsp) + lea __image_base__(%rip),%rsi + movl %esi, (%rsp) + movabsq $__XEN_VIRT_START, %rcx + subq %rsi, %rcx + push %rcx =20 - /* Jump to trampoline_setup after switching CPU to x86_32 mode. */ - lea trampoline_setup(%rip),%r15 + /* Jump to trampoline_efi_setup after switching CPU to x86_32 mode= . */ + lea trampoline_efi_setup(%rip),%r15 =20 x86_32_switch: mov %r15,%rdi @@ -557,6 +571,12 @@ __start: and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx jmp .Lmb2_tsize =20 +trampoline_efi_setup: + movb $1, %al + call reloc + pop %eax + jmp trampoline_setup + trampoline_bios_setup: /* * Called on legacy BIOS platforms only. @@ -627,6 +647,7 @@ trampoline_setup: push %ecx /* Bottom-most low-memory stack addres= s. */ push %ebx /* Multiboot / PVH information address= . */ push %eax /* Magic number. */ + movb $0, %al call reloc #ifdef CONFIG_PVH_GUEST cmpb $0, sym_esi(pvh_boot) diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index 4033557481..3aa97a99d0 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -23,7 +23,9 @@ asm ( " .text \n" " .globl _start \n" "_start: \n" - " jmp reloc \n" + " cmpb $0, %al \n" + " je reloc \n" + " jmp reloc_pe_back \n" ); =20 #include "defs.h" @@ -375,6 +377,65 @@ void *__stdcall reloc(uint32_t magic, uint32_t in, uin= t32_t trampoline, } } =20 +struct pe_base_relocs { + u32 rva; + u32 size; + u16 entries[]; +}; + +#define PE_BASE_RELOC_ABS 0 +#define PE_BASE_RELOC_HIGHLOW 3 +#define PE_BASE_RELOC_DIR64 10 + +void __stdcall reloc_pe_back(long long delta, + uint32_t xen_phys_start, + const struct pe_base_relocs *__base_relocs_st= art, + const struct pe_base_relocs *__base_relocs_en= d, + char *l3_bootmap, char *l2_bootmap) +{ + const struct pe_base_relocs *base_relocs; + + for ( base_relocs =3D __base_relocs_start; base_relocs < __base_relocs= _end; ) + { + unsigned int i =3D 0, n; + + n =3D (base_relocs->size - sizeof(*base_relocs)) / + sizeof(*base_relocs->entries); + + /* + * Relevant l{2,3}_bootmap entries get initialized explicitly in + * efi_arch_memory_setup(), so we must not apply relocations there. + * l2_directmap's first slot, otoh, should be handled normally, as + * efi_arch_memory_setup() won't touch it (xen_phys_start should + * never be zero). + */ + if ( xen_phys_start + base_relocs->rva =3D=3D (unsigned long)l3_bo= otmap || + xen_phys_start + base_relocs->rva =3D=3D (unsigned long)l2_bo= otmap ) + i =3D n; + + for ( ; i < n; ++i ) + { + unsigned long addr =3D xen_phys_start + base_relocs->rva + + (base_relocs->entries[i] & 0xfff); + + switch ( base_relocs->entries[i] >> 12 ) + { + case PE_BASE_RELOC_ABS: + break; + case PE_BASE_RELOC_HIGHLOW: + if ( delta ) + *(u32 *)addr +=3D delta; + break; + case PE_BASE_RELOC_DIR64: + if ( delta ) + *(u64 *)addr +=3D delta; + break; + } + } + base_relocs =3D (const void *)(base_relocs->entries + i + (i & 1)); + } +} + /* * Local variables: * mode: C --=20 2.45.2