From nobody Sun Nov 24 03:03:25 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=1723624514; cv=none; d=zohomail.com; s=zohoarc; b=ftTQDQmH2Os3cvqDQgNuSuO+v0N/yTJu9BuU1knfjHmtcEWnEKkxAAWxl19DGxEvPMUXemaAaq5CIrl6DXNycHXm4pXFBz5udOa+QUlMSArLtvfHWnwg8NCtLuKgoJfxYu/8QVKDHbtXTo9kRg2p8zNf2vDFAimyuiHrt6VuOE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723624514; 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=gz57YRc5BprGPTvdYo9SU35adCn77Ws3eV4wwb5cJIk=; b=O0mIt69JGgaW+jkpnoI/zTV+lIo0C8Mu6Y5PVXIq0P0WOS0NYUWc+gW6fIivCgFDM8uHx0ai8wRlWmTC0/eqAu1mXoGPEl2Lh0i5KNJQguXfGVJtFH7iJKV7h6z1LZBF10n5xEoTwHUYW7drNMcgSgA1WCcXYD+1dmgibv8pFEs= 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 1723624514124455.06567235010823; Wed, 14 Aug 2024 01:35:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.776848.1187036 (Exim 4.92) (envelope-from ) id 1se9TA-00044j-FH; Wed, 14 Aug 2024 08:35:00 +0000 Received: by outflank-mailman (output) from mailman id 776848.1187036; Wed, 14 Aug 2024 08:35:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1se9TA-00044a-C1; Wed, 14 Aug 2024 08:35:00 +0000 Received: by outflank-mailman (input) for mailman id 776848; Wed, 14 Aug 2024 08:34:58 +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 1se9T8-0002t1-MZ for xen-devel@lists.xenproject.org; Wed, 14 Aug 2024 08:34:58 +0000 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [2607:f8b0:4864:20::730]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 160e20d9-5a18-11ef-a505-bb4a2ccca743; Wed, 14 Aug 2024 10:34:57 +0200 (CEST) Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-7a1d067d5bbso416764485a.3 for ; Wed, 14 Aug 2024 01:34:57 -0700 (PDT) Received: from fziglio-xenia-fedora.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4c7e05595sm407786785a.122.2024.08.14.01.34.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:34:55 -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: 160e20d9-5a18-11ef-a505-bb4a2ccca743 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723624496; x=1724229296; 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=gz57YRc5BprGPTvdYo9SU35adCn77Ws3eV4wwb5cJIk=; b=M7LwU/cRPzolVj+d1NoK/05YuxazJIyRsktCHWXfG8FMeuG9e7NjtKipy7UpEnG0Ob lidRiThI9unKGfYG0pvcE7AUTRWPqSLlVGxc0mLcPSSbpVJNuBLyGF2Xo8HQHOX3Q9cz 8DboQc8GJ2k5faSB5h9+G6FzoHp8lFufSATlg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723624496; x=1724229296; 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=gz57YRc5BprGPTvdYo9SU35adCn77Ws3eV4wwb5cJIk=; b=gjbaQBWYTl35dDsJ4l+PhrJNQaLpRjaN+G5HX8vovGbOd9Xb1EiM1+562MSaY39R5r yNBtDE3s0AxxWGPCVhqHxv/MMUbTn7FXg2/7cgu3cVDCNYkjdZMHjrQX2TcBtySm+A2I CJ74GqHnroBbUp8QTAswvM9OMR+W8Dcb77dWmlYbS64cpWVULSohjsxX12zQfRlZG0KC nobQWCiAh9GZtVxU+CpHJAf88XIGH063yx2WrQE01oA+ZBZ3fS60g7+Gv11mptUYaFUw /KlK2mghN0ph5+MVsO7V1Y3c+9w91UgA8Z6FmlHROXLzxS0aKBnk196Yr6KkhfH11YAG y25g== X-Gm-Message-State: AOJu0YwoYpn84edwH4UT0T+o7D1ZW5obwDcm4et1oaMlYQPvsvO5eM4a 5QorccwcgDz0ji9HL480hn5Z2YBXPA3MhuZNdjmxgVUIYeYMXNvfQeGgZyOobaQI2l5uh9q4+jT y X-Google-Smtp-Source: AGHT+IEVCJQeVFkZOhco5FcI3nGMRX2zjGWj3Gwlx3oxDXdB2Rk7Mq7EaVpIZTamEuWTOGgtNoJUVQ== X-Received: by 2002:a05:620a:24d4:b0:79e:fbef:d23e with SMTP id af79cd13be357-7a4ee335132mr231733185a.17.1723624495972; Wed, 14 Aug 2024 01:34:55 -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 v2 1/5] x86: Put trampoline in .init.data section Date: Wed, 14 Aug 2024 09:34:10 +0100 Message-ID: <20240814083428.3012-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814083428.3012-1-frediano.ziglio@cloud.com> References: <20240814083428.3012-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723624516122116600 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..16830f636f 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 + ENTRY(trampoline_start) #include "trampoline.S" ENTRY(trampoline_end) --=20 2.45.2 From nobody Sun Nov 24 03:03:25 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=1723624519; cv=none; d=zohomail.com; s=zohoarc; b=Hz0xTxBNZcsS5mZFpCjuRg5FlyH/nBUSTnc/+Iam7OTNqLzmYyXhGj+OJ4oCtBfMsvHaF70l/LnLwG4AneQsi3WtFvaZvlevA/9wUEsuejoA/XHq9OJkSWy5ghD57sGrq5r98Zd03xj54mIuAlwM3MCY6Tj8geSQ7Zbxdcqs0ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723624519; 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=9liPXw8F8uWc1T2M5e5K9juxcl/gQEIllOyVhjRgClo=; b=iPEh+jh9Qa7yChpu+ATltnNqr5Hl8X7YtwqKtmy4wfnlKxqibCAfEurR4sDuSzS4ot57LBpCJLS0Tr0uUetO6GIpY+N0D41DrSkEYDaH50v7Vo13lSvtgkSiXWqqLfo0NoHA7MaPEhliVsEBO8yOTP849XB2sDTzXi9MBeG3xSI= 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 1723624519131944.8005676457736; Wed, 14 Aug 2024 01:35:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.776849.1187043 (Exim 4.92) (envelope-from ) id 1se9TB-0004D0-1L; Wed, 14 Aug 2024 08:35:01 +0000 Received: by outflank-mailman (output) from mailman id 776849.1187043; Wed, 14 Aug 2024 08:35:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1se9TA-0004CO-S7; Wed, 14 Aug 2024 08:35:00 +0000 Received: by outflank-mailman (input) for mailman id 776849; Wed, 14 Aug 2024 08:35:00 +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 1se9TA-0003IY-2G for xen-devel@lists.xenproject.org; Wed, 14 Aug 2024 08:35:00 +0000 Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [2607:f8b0:4864:20::1130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 16bf59dd-5a18-11ef-8776-851b0ebba9a2; Wed, 14 Aug 2024 10:34:58 +0200 (CEST) Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-690af536546so63569377b3.3 for ; Wed, 14 Aug 2024 01:34:58 -0700 (PDT) Received: from fziglio-xenia-fedora.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4c7e05595sm407786785a.122.2024.08.14.01.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:34:56 -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: 16bf59dd-5a18-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723624497; x=1724229297; 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=9liPXw8F8uWc1T2M5e5K9juxcl/gQEIllOyVhjRgClo=; b=YZuTbeCi/FYg66M3taI8SEwHanJvd8Hx+Kqafh0DrF6FR5XeQi0iHXZguxdTN4wYtg ilT1QxuJDth8LjAMJJkbjElrTpq3T5r9ilp2ZEqsZT3HbczaHj4jzqI42yrxRZX/QAqZ jYJq5ByXGFQlPdz0+uuRMFr3LGqd6W4eodr10= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723624497; x=1724229297; 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=9liPXw8F8uWc1T2M5e5K9juxcl/gQEIllOyVhjRgClo=; b=cT1p6z05tWzlCXlHvUrWfgcKHAfFEk1DS9gMy0pHEE929Fqbfy4njXt8hkSJ3WZvje WjKJauE2+BVnPopvdXPbMbV5H3KcgMhQkZr6Wt9vh25Kav2xXkxH19J4x0z45dFbJOVq 7tn/Uw+2HbgH8Xf8IzeBu+G1lpk2rfq5+iaSMT5YNdCJHDOypJzT6uzz6b6afM2xOnlI I9pNBL+CkoI1M+A6ARUF8lCiOOhO3T3z8PZ2VASdwIOgguqS3IG3VuHla2Eq65OQqUcn Bg4wxcCtWUOuE3Dd2nG5zQBbfK8DD4CpT6ZmD3ZdiIjLCDjOTopeBZpalt+NLV8uYgLR vZJw== X-Gm-Message-State: AOJu0Yz/uNKJO0RnpqZnmyiPqq8uZt9NmAmy4cHrZkKdVCimaSBuf/oz sjKOSDLo3i+MW7VjCF8fjHLA3EagGrFuQzIVRM2xdP55sypNnwOo5dgB+XQeqRoPs2KCKE0Cm5q W X-Google-Smtp-Source: AGHT+IGMUyQiPtuxz+T1VQxDgT44hXZVi7vkaynauzor/OZHJNJzRTZJWR2TZztIUfw3xi2fMzeBPA== X-Received: by 2002:a05:690c:2512:b0:648:3fb2:753b with SMTP id 00721157ae682-6ac976454c9mr21427057b3.24.1723624497101; Wed, 14 Aug 2024 01:34:57 -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 v2 2/5] x86: Set xen_phys_start and trampoline_xen_phys_start earlier Date: Wed, 14 Aug 2024 09:34:11 +0100 Message-ID: <20240814083428.3012-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814083428.3012-1-frediano.ziglio@cloud.com> References: <20240814083428.3012-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723624520125116600 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 EFI code paths more similar and allows the usage of these variables if needed. Signed-off-by: Frediano Ziglio --- xen/arch/x86/boot/head.S | 5 +++++ 1 file changed, 5 insertions(+) --- Changes since v1: - Do not remove other hunk, used for BIOS; - Slightly improved commit message. diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 16830f636f..af598a60bf 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -240,6 +240,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), %esi + mov %rsi, xen_phys_start(%rip) + mov %esi, trampoline_xen_phys_start(%rip) + /* Zero EFI SystemTable, EFI ImageHandle addresses and cmdline. */ xor %esi,%esi xor %edi,%edi --=20 2.45.2 From nobody Sun Nov 24 03:03:25 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=1723624516; cv=none; d=zohomail.com; s=zohoarc; b=UNSR4ihPp7a6Mihch30pP06P/PhhJdUHbffFIhA2i47UzwAhwhlok7L4L1d3xLhUKBjtu1PnzWTMhpwb3yCgNXBY7F7tEOjzUjP+TY0ooCaVGfcJW3BhNpaXDxCqNaFJsvceQsdmEVeJ/ApUwNXHlTD0p9pyjlV998P7EX4TGgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723624516; 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=hx6AIwlEbMHavC5DjEjakTrNbCVEjBb0SKVNkWMFXTc=; b=jKyP/Gozg08y2WBJAsjvFpn4j39ZKgl8bLVAcckkOFnuUUpnQLcP4ySSTmV4Abltvw53RGGtL1kKLqt6Qtqm4Ntwe6mwRokCvCg1tnG9H1lPyY44BbsVrEODNko2eRZ0WDW60SQjVhKuYOrzrl3Y//cSvObQpqzxDchSEFPFP/0= 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 1723624516341311.9810651879584; Wed, 14 Aug 2024 01:35:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.776850.1187049 (Exim 4.92) (envelope-from ) id 1se9TB-0004H2-DA; Wed, 14 Aug 2024 08:35:01 +0000 Received: by outflank-mailman (output) from mailman id 776850.1187049; Wed, 14 Aug 2024 08:35:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1se9TB-0004G8-4t; Wed, 14 Aug 2024 08:35:01 +0000 Received: by outflank-mailman (input) for mailman id 776850; Wed, 14 Aug 2024 08:35:00 +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 1se9TA-0002t1-3f for xen-devel@lists.xenproject.org; Wed, 14 Aug 2024 08:35:00 +0000 Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [2607:f8b0:4864:20::e2e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 175b8caa-5a18-11ef-a505-bb4a2ccca743; Wed, 14 Aug 2024 10:34:59 +0200 (CEST) Received: by mail-vs1-xe2e.google.com with SMTP id ada2fe7eead31-492a01bce97so2246922137.2 for ; Wed, 14 Aug 2024 01:34:59 -0700 (PDT) Received: from fziglio-xenia-fedora.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4c7e05595sm407786785a.122.2024.08.14.01.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:34:58 -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: 175b8caa-5a18-11ef-a505-bb4a2ccca743 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723624498; x=1724229298; 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=hx6AIwlEbMHavC5DjEjakTrNbCVEjBb0SKVNkWMFXTc=; b=hN5Oh2eW3WaDyDtMkMUKMYqhlwsaIHHRbPiZFw1qmF8JftzGcJ30bax86QiFXOG4sW x2pJkGIlTsv5lfb/NDrJgUhMx5SqswPWpEfUiNE+9LlkID12mXA350jl59UbgKy+ytWD xkXSqfCUeczJYMi+2B1HME+acSCyJovlXJn/o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723624498; x=1724229298; 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=hx6AIwlEbMHavC5DjEjakTrNbCVEjBb0SKVNkWMFXTc=; b=j6IktMvRA45hviFyWD9sPur/l+oA/6BMKCHA8OIM8+3YMsD8MK+BG9Zw/21HoqF0oF 30YAA3eL3e0oP92EF7bUb6HHrufGvb5JlRKGyfYUb59g99Dt6wEi8m/A0ch47njjdUYv 2kayIYQuSvLq9IK0xo9xRFtIqQjnTIFjNfvuCnDrdQFrgSf3BS76LiYiAeD7NeM4/1UK /PHqyY+TvFcpxPjbavorYzmeeAtz5wLTtM+nuKmrgQ/ZSlB5Gw+1l4jzkK0yIVPNTx+f NuZH7AZ2hUTp9qVpT46eqIP5ffWYxhZO3Y5jyTAcOzWu2a3cnLAWLScE6JNojrJdRFs8 FqCQ== X-Gm-Message-State: AOJu0YyqjeHFMYwAtJTHMcTepqFN5Qj2R8nwI2Po8rXPvvGyyOKNQgXC sBhEKC1GkuT0cqonOI0Idu0rjFErLoX93okUynAIbpekd34uwQycSBofuzoLfdfykMx57wrmwYp K X-Google-Smtp-Source: AGHT+IFL70GY1qUxURIAZQ+mo6txlE+c+ln237y0PC4cC3hmxTtF9rJyDjIROcbYWReJ7g4d9xoUaQ== X-Received: by 2002:a05:6102:3593:b0:48f:89cc:dd2b with SMTP id ada2fe7eead31-4975992d5efmr2467012137.11.1723624498219; Wed, 14 Aug 2024 01:34:58 -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 v2 3/5] x86: Force proper gdt_boot_base setting Date: Wed, 14 Aug 2024 09:34:12 +0100 Message-ID: <20240814083428.3012-4-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814083428.3012-1-frediano.ziglio@cloud.com> References: <20240814083428.3012-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723624518129116600 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 af598a60bf..666e341bc5 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 @@ -373,15 +372,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 + mov %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 @@ -439,7 +439,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 + mov %ecx, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) =20 mov $BOOT_DS, %ecx @@ -543,7 +544,8 @@ trampoline_bios_setup: * * Initialize GDTR and basic data segments. */ - add %esi,sym_esi(gdt_boot_base) + lea sym_esi(trampoline_gdt), %ecx + mov %ecx, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) =20 mov $BOOT_DS,%ecx --=20 2.45.2 From nobody Sun Nov 24 03:03:25 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=1723624521; cv=none; d=zohomail.com; s=zohoarc; b=NC68VKFiSESY3AbOMsRjFajdag1PJQAb+iFDW6m/EJGVbmdWPDjZaARyMy+iJdSVcB3EflrMWaC7ChjU+8KMJIZI5evBHoQlqVneWx7Ri2eJyoNy/WRQEWPb1Y60yVH6o8nV7Tj4NHOiKBvsfW94ArQddNJYgQ/LlgsIO9H7/ww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723624521; 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=8cx+yFVCJfgxWpnsCCMINuRQ/ctq1Ga1ijOLJ+Mk9mo=; b=Tlin/lKjn/mDAz04Nv5IhCQZensw3Ucx1/Zn5eggVRs14wTKg2U/zLFjvoZ+MSCqq+yHlGDe72VODWBL9ZlbiqLXUn/XkKgmpBzmJdnTSIzjttrdJKTaAbumNmH/hwTe4sFT0cMyMRLpxjr4Ck3DOQEh26Y6tRshQ/OstSgWrY4= 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 1723624521901205.54415518259657; Wed, 14 Aug 2024 01:35:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.776851.1187066 (Exim 4.92) (envelope-from ) id 1se9TD-0004qh-LH; Wed, 14 Aug 2024 08:35:03 +0000 Received: by outflank-mailman (output) from mailman id 776851.1187066; Wed, 14 Aug 2024 08:35:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1se9TD-0004qW-HB; Wed, 14 Aug 2024 08:35:03 +0000 Received: by outflank-mailman (input) for mailman id 776851; Wed, 14 Aug 2024 08:35:02 +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 1se9TC-0002t1-1Q for xen-devel@lists.xenproject.org; Wed, 14 Aug 2024 08:35:02 +0000 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [2607:f8b0:4864:20::72c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 18748825-5a18-11ef-a505-bb4a2ccca743; Wed, 14 Aug 2024 10:35:01 +0200 (CEST) Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7a1dac7f0b7so433371885a.0 for ; Wed, 14 Aug 2024 01:35:01 -0700 (PDT) Received: from fziglio-xenia-fedora.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4c7e05595sm407786785a.122.2024.08.14.01.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:34:59 -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: 18748825-5a18-11ef-a505-bb4a2ccca743 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723624500; x=1724229300; 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=8cx+yFVCJfgxWpnsCCMINuRQ/ctq1Ga1ijOLJ+Mk9mo=; b=az8blai454zBbhhrTHV6Kk0zNQXleVGKjhEpAfDMNQ4gOaR3TyIDLIewHInPiL+MMz sIv5m1zqwWNfq4AxeRGinH8Ji7zv5kbhX1oDtsKpdxUNNWXyVUpfVmFNp8etNIBX7U0E /aoUBk4aRC69/GiPlCb7/ubwAuZ7n3Rt8awDY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723624500; x=1724229300; 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=8cx+yFVCJfgxWpnsCCMINuRQ/ctq1Ga1ijOLJ+Mk9mo=; b=sC0NKDKJq+QC1mbucCmP6D1yLegdb28k8Ot9aWRpjyz2ErKCTkTqxJtU8aQ06ELg9z cOqxqMpEWWdH4iGIjDpx2XNSuygyjj80k4g8KJ91NK1BqgAOXw+1r0dJrD8UyXZsxNBh 0K3/Qr2KhxoDZBBeChsImpHMVT17t/hezRBGhck4jqE7SyosYOVLvlh6UThV2lZmHntN DmIhr16Knnjkmj3xSrJwnlAAQR9klVwpxsOnBLtT7BIOENtEdkvGEZhNPe31152ZXItd tEzQkmlnbqD2VKtO2zKxOr2giXUGEkdfQSN9ZrdWcpFttbQzRlFHvIlhSwyn7Asjn0jR z+MQ== X-Gm-Message-State: AOJu0YxAFTt81phoaOMmR8fKfxsS23Hfb4PgT9zaMjVz/JNHwkqD2pya fipAP3OwEaL86HMQWwh+iLDN/NLj/INacItRBHbRtAZbX36gWXvBWoKuf4lOUzqB9fx0AwdwAjQ / X-Google-Smtp-Source: AGHT+IH9FUz7tjCeqZVLYlglNRnjlEx+UsjubjRMdy3lW/lyF98I7fqJhsyulPcCyllSixJ04vyVjA== X-Received: by 2002:a05:620a:28c1:b0:79f:9b5:ff78 with SMTP id af79cd13be357-7a4ee33c969mr246582985a.34.1723624500146; Wed, 14 Aug 2024 01:35:00 -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 v2 4/5] x86: Compensate relocation in case of EFI Date: Wed, 14 Aug 2024 09:34:13 +0100 Message-ID: <20240814083428.3012-5-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814083428.3012-1-frediano.ziglio@cloud.com> References: <20240814083428.3012-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723624522147116600 Content-Type: text/plain; charset="utf-8" If code is loaded by EFI the loader will relocate the image under 4GB. This causes 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 wanted address when using sym_offs an sym_esi compensate the difference in %esi. Signed-off-by: Frediano Ziglio --- xen/arch/x86/boot/head.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- Changes since v1: - Completely different way to cope with the issue, much more easier. diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 666e341bc5..86805389f9 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -380,7 +380,8 @@ x86_32_switch: 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 + lea __image_base__(%rip), %esi + sub $sym_offs(__image_base__), %esi =20 /* Reload code selector. */ pushq $BOOT_CS32 --=20 2.45.2 From nobody Sun Nov 24 03:03:25 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=1723624527; cv=none; d=zohomail.com; s=zohoarc; b=eo3ExUMLSTmIBV8rfytjhTqUyIFJRFIoaSbJ1jax/gtKPbaV1Kh9AwQp2bBkmtwm/0o0tu+AUqqwTd9Z6/ZW2w9cM2jaPVuSbaw41Vn3tRDd9fbiV+a5XH16gzIUkgIbIjI5uQSCpGu8EIKUhflmqM3y1zGat+g0ZIVwusJfSfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723624527; 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=C3RLkkdEw+WvOJ6h0uz0D93wDr/BTPYuQooWwQucVfo=; b=ObsOLJRlaj3GnsyY4ES8XGHZTess++eMkJvcWzysv87aWGzpphCexDS1kCYxTtzfsT4GENuxXyq09NHVKntT9n4i6ZnrbO+aLCyFZpgMi7DUBE9GAsPyq5by/LVPyjI/v88XTfW7uCyhLTlD6Fm2Wuxwrebcvkk/SGspPSMB6t4= 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 172362452760970.18857432798893; Wed, 14 Aug 2024 01:35:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.776852.1187076 (Exim 4.92) (envelope-from ) id 1se9TE-00057u-Up; Wed, 14 Aug 2024 08:35:04 +0000 Received: by outflank-mailman (output) from mailman id 776852.1187076; Wed, 14 Aug 2024 08:35:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1se9TE-00057f-QW; Wed, 14 Aug 2024 08:35:04 +0000 Received: by outflank-mailman (input) for mailman id 776852; Wed, 14 Aug 2024 08:35:03 +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 1se9TD-0002t1-KE for xen-devel@lists.xenproject.org; Wed, 14 Aug 2024 08:35:03 +0000 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [2607:f8b0:4864:20::b31]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 194a8861-5a18-11ef-a505-bb4a2ccca743; Wed, 14 Aug 2024 10:35:02 +0200 (CEST) Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-e0e88873825so6295835276.2 for ; Wed, 14 Aug 2024 01:35:02 -0700 (PDT) Received: from fziglio-xenia-fedora.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4c7e05595sm407786785a.122.2024.08.14.01.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:35:01 -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: 194a8861-5a18-11ef-a505-bb4a2ccca743 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723624501; x=1724229301; 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=C3RLkkdEw+WvOJ6h0uz0D93wDr/BTPYuQooWwQucVfo=; b=Jm05QScSbdxb7nUlMX+0piRorKZwHiGH3zsUozIEigTxKg24CVYfX9puy2e+rfBfgr vxQHrpzNz3fhGzbt7r2oMCI40eH1iXC08B2f8Yq1G1KHjaViIBel3/t7YPqu5BooxjTR gSSDH7foo7nir5C99Lg9LiefxW3ZAg9oDcCWM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723624501; x=1724229301; 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=C3RLkkdEw+WvOJ6h0uz0D93wDr/BTPYuQooWwQucVfo=; b=B49CzAUgQhsZ4GZfU8c0lKYkIIihKQseP1kI41McEm5vbLirq9h9QngYvZGmdwGOMW SNqiaA47XqHRii+xFEe1W7SspVaH/8NJ+FcPhanCxihX0UAUn6wSsv42JL/fp1y93CDZ FSBk9dREmVkyhJ+//YYoRTASVjL70jXo+gF35P/dAIq0ou+7wYDRONhaE/uJtqW8/zyP E1xUoiQwCDHhR+K/f66the3JsN3Q++NKppAY1aOhBmpGhZdmH2S4s9EDCH8oPbfqFFxd 1AlB/o0pSB9rj7PvXW9yDSqX06iQ5D7lMAOuSqBCBYVOZdsFwWl4UBqHzs+l3fkTy4gy vutg== X-Gm-Message-State: AOJu0YyipzgSXuD2WcTJuRzMm8aGFhuipESf5ye8D/oA8HvAr0XyNiko 7Frq8Ke0FefR22k8NhKQd2phED2u/6wFltpKzeJRZ1ldmyhr7xkc3zpEFyyU0QQWOJHV505viXh v X-Google-Smtp-Source: AGHT+IGKNHJUKcuFo4EaeLXlmE5TDLQ5CU7BIa/3jgXJownF0st8Fk8SKovg0rOsFbAmrWJAlwJQ0A== X-Received: by 2002:a05:690c:3405:b0:62f:945a:7bb1 with SMTP id 00721157ae682-6ac9a478546mr20841897b3.42.1723624501462; Wed, 14 Aug 2024 01:35:01 -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 v2 5/5] x86: Rollback relocation in case of EFI multiboot Date: Wed, 14 Aug 2024 09:34:14 +0100 Message-ID: <20240814083428.3012-6-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814083428.3012-1-frediano.ziglio@cloud.com> References: <20240814083428.3012-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723624528227116600 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/Makefile | 2 +- xen/arch/x86/boot/efi-reloc-image.c | 40 ++++++++++++++ xen/arch/x86/boot/efi-reloc-image.h | 85 +++++++++++++++++++++++++++++ xen/arch/x86/boot/head.S | 44 ++++++++++++--- xen/arch/x86/efi/efi-boot.h | 64 ++-------------------- 5 files changed, 168 insertions(+), 67 deletions(-) create mode 100644 xen/arch/x86/boot/efi-reloc-image.c create mode 100644 xen/arch/x86/boot/efi-reloc-image.h --- Changes since v1: - many style updates; - split file for 32 bit relocation; - reuse code from header avoiding duplication; - add some more comment to assembly code; diff --git a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile index 03d8ce3a9e..49792e0acf 100644 --- a/xen/arch/x86/boot/Makefile +++ b/xen/arch/x86/boot/Makefile @@ -1,6 +1,6 @@ obj-bin-y +=3D head.o =20 -head-bin-objs :=3D cmdline.o reloc.o +head-bin-objs :=3D cmdline.o reloc.o efi-reloc-image.o =20 nocov-y +=3D $(head-bin-objs) noubsan-y +=3D $(head-bin-objs) diff --git a/xen/arch/x86/boot/efi-reloc-image.c b/xen/arch/x86/boot/efi-re= loc-image.c new file mode 100644 index 0000000000..b103e37cd7 --- /dev/null +++ b/xen/arch/x86/boot/efi-reloc-image.c @@ -0,0 +1,40 @@ +/* + * efi-reloc-image.c + * + * 32-bit flat memory-map routines for relocating back PE executable. + * This is done with paging disabled to avoid permission issues. + * + * Copyright (c) 2024, Citrix Systems, Inc. + */ + +/* + * This entry point is entered from xen/arch/x86/boot/head.S with: + * - 0x04(%esp) =3D __XEN_VIRT_START - xen_phys_start + * - 0x0c(%esp) =3D xen_phys_start + * - 0x10(%esp) =3D __base_relocs_start + * - 0x14(%esp) =3D __base_relocs_end + */ +asm ( + " .text \n" + " .globl _start \n" + "_start: \n" + " jmp reloc_pe_back \n" + ); + +#include "defs.h" + +/* Do not patch page tables. */ +#define in_page_tables(v) false + +#define EFI_RELOC_IMAGE_EARLY 1 +#include "efi-reloc-image.h" + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/boot/efi-reloc-image.h b/xen/arch/x86/boot/efi-re= loc-image.h new file mode 100644 index 0000000000..999dd2d2c8 --- /dev/null +++ b/xen/arch/x86/boot/efi-reloc-image.h @@ -0,0 +1,85 @@ +/* + * efi-reloc-image.h + * + * Code for relocating back PE executable. + * This code is common between 64 bit and 32 bit. + * + * Copyright (c) 2024, Citrix Systems, Inc. + */ + +#if EFI_RELOC_IMAGE_EARLY !=3D 0 && EFI_RELOC_IMAGE_EARLY !=3D 1 +#error EFI_RELOC_IMAGE_EARLY must be defined either 0 or 1 +#endif + +typedef struct pe_base_relocs { + uint32_t rva; + uint32_t size; + uint16_t entries[]; +} pe_base_relocs; + +#define PE_BASE_RELOC_ABS 0 +#define PE_BASE_RELOC_HIGHLOW 3 +#define PE_BASE_RELOC_DIR64 10 + +#if EFI_RELOC_IMAGE_EARLY +bool __stdcall +#else +static bool +#endif +reloc_pe_back(long long delta, + unsigned long xen_phys_start, + const pe_base_relocs *__base_relocs_start, + const pe_base_relocs *__base_relocs_end) +{ + 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); + + 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 ) + { + *(uint32_t *)addr +=3D delta; + if ( in_page_tables(addr) ) + *(uint32_t *)addr +=3D xen_phys_start; + } + break; + case PE_BASE_RELOC_DIR64: + if ( delta ) + { + *(uint64_t *)addr +=3D delta; + if ( in_page_tables(addr) ) + *(uint64_t *)addr +=3D xen_phys_start; + } + break; + default: + return false; + } + } + base_relocs =3D (const void *)(base_relocs->entries + i + (i & 1)); + } + return true; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 86805389f9..dd3600c14b 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -332,7 +332,8 @@ __efi64_mb2_start: */ and $~15,%rsp =20 - /* Save Multiboot2 magic on the stack. */ + /* Save Multiboot2 magic on the stack for a later 32bit call */ + shl $32, %rax push %rax =20 /* Save EFI ImageHandle on the stack. */ @@ -363,11 +364,25 @@ __efi64_mb2_start: /* Just pop an item from the stack. */ pop %rax =20 - /* Restore Multiboot2 magic. */ - pop %rax + /* + * Prepare stack for relocation call. + * Note that we are in 64bit mode but we are going to call a + * function in 32bit mode so the stack is not written with + * push instructions. + */ + sub $16, %rsp + lea __base_relocs_end(%rip), %ecx + mov %ecx, 16(%rsp) + lea __base_relocs_start(%rip), %ecx + mov %ecx, 12(%rsp) + lea __image_base__(%rip), %esi + mov %esi, 8(%rsp) + movabs $__XEN_VIRT_START, %rcx + sub %rsi, %rcx + mov %rcx, (%rsp) =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 @@ -539,6 +554,17 @@ __start: and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx jmp .Lmb2_tsize =20 +trampoline_efi_setup: + call reloc_pe_back + pop %eax + + /* Calculate the load base address again, adjusting to sym_esi nee= ds */ + call 1f +1: pop %esi + sub $sym_offs(1b), %esi + + jmp trampoline_setup + trampoline_bios_setup: /* * Called on legacy BIOS platforms only. @@ -867,8 +893,8 @@ trampoline_setup: lret =20 /* - * cmdline and reloc are written in C, and linked to be 32bit PIC = with - * entrypoints at 0 and using the stdcall convention. + * cmdline, reloc and reloc_pe_back are written in C, and linked t= o be + * 32bit PIC with entrypoints at 0 and using the stdcall conventio= n. */ ALIGN cmdline_parse_early: @@ -878,6 +904,10 @@ cmdline_parse_early: reloc: .incbin "reloc.bin" =20 + ALIGN +reloc_pe_back: + .incbin "efi-reloc-image.bin" + .section .init.data, "aw", @progbits =20 ENTRY(trampoline_start) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index f282358435..4f473a287e 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -36,69 +36,15 @@ extern const intpte_t __page_tables_start[], __page_tab= les_end[]; #define in_page_tables(v) ((intpte_t *)(v) >=3D __page_tables_start && \ (intpte_t *)(v) < __page_tables_end) =20 -#define PE_BASE_RELOC_ABS 0 -#define PE_BASE_RELOC_HIGHLOW 3 -#define PE_BASE_RELOC_DIR64 10 +#define EFI_RELOC_IMAGE_EARLY 0 +#include "../boot/efi-reloc-image.h" =20 -extern const struct pe_base_relocs { - u32 rva; - u32 size; - u16 entries[]; -} __base_relocs_start[], __base_relocs_end[]; +extern pe_base_relocs __base_relocs_start[], __base_relocs_end[]; =20 static void __init efi_arch_relocate_image(unsigned long delta) { - 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; - if ( in_page_tables(addr) ) - *(u32 *)addr +=3D xen_phys_start; - } - break; - case PE_BASE_RELOC_DIR64: - if ( delta ) - { - *(u64 *)addr +=3D delta; - if ( in_page_tables(addr) ) - *(u64 *)addr +=3D xen_phys_start; - } - break; - default: - blexit(L"Unsupported relocation type"); - } - } - base_relocs =3D (const void *)(base_relocs->entries + i + (i & 1)); - } + if (!reloc_pe_back(delta, xen_phys_start, __base_relocs_start, __base_= relocs_end)) + blexit(L"Unsupported relocation type"); } =20 extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[]; --=20 2.45.2