From patchwork Fri Nov 29 16:35:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 846149 Delivered-To: patch@linaro.org Received: by 2002:adf:f2c4:0:b0:382:43a8:7b94 with SMTP id d4csp999824wrp; Fri, 29 Nov 2024 08:35:26 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW+9IQwesmAIGSoePq18FYXYVzUKZvpn8SK9Oa+F1eTtRJmYHHkBu4J9G1wgDwgFApj+STSRw==@linaro.org X-Google-Smtp-Source: AGHT+IEh2gjboTVmr/CoDdxDEclX72kvZlmHAdrUYo9pu13+s+HbprhfEt3ZQQVvijvxWdi3iceD X-Received: by 2002:a05:6512:3d06:b0:53d:dbe8:e397 with SMTP id 2adb3069b0e04-53df00d109amr6538854e87.14.1732898126344; Fri, 29 Nov 2024 08:35:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732898126; cv=none; d=google.com; s=arc-20240605; b=k8e0sxL1hKxBadwjFOD0mb5J8jKMeco6EQiA9U/1Q0SAT9dfnghcdZ9BPKJGj/G+Dn 0ppeAWNPPCG8aJxglJdV7YaNevOYDpkKjKRZfo3Vdl5+F4+258nQOtnKbxcjft47vY4f hN5z1vmW4tnkTKcxFUTa4Pmk775I3zDR9NlYMie+SC59XPYtC72vaZfzoLF3WofLGkaq Y1uZpDGtqyL5Y4898aZmGfjljlOmNVPylEqVGukqwTGgClwS3V8VQQH8BwufabaIm2Bj HcJ+8gtyZsIk7W23gQ+R9VVRbPNM1r38XFTXRZyhKE3AsgRhimABdC83gjkJ0g7C7wHZ 7lZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=fU90U3F47CumcRAOvrvxLDb55n8icxq6eKeukvJX0Ts=; fh=PJpau1DhnqFYtUa+DbaGFDIIXpSp3KIqyQ6vT1bS8CI=; b=MYlATCUjZqJlRl/fd/ZH9pR62zqIKmIfCCGwxGt5wSaruE04YwxCMbkaPgaL6UwkKA JpLidHTOG5vR/xKMaNr4jisfkOHrDFe9oUZ698rMdB74lP2toKDA3b8uYSQo5pJjKxcE 5xldtDvmKtPKWTUCxIwfz4o/LlQX/OgFg/NYYaf/5Ro3Q/Acd13kOuVs9eKm+8GmRA0w 9gISlsjmXARmITq3BTQXo5yJonojoh9aKzKv9MuYJaEP1VjO3waWFmZvU0cAB7yAaj20 ecuLcqnwUqcUrlFEFe5WD3L83llpQ7iasZFvuvpqrI1mRWP7v3To9crPbVUhsJvHZrbf 4OPg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Obn3FFIJ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-aa599945fa5si277081666b.690.2024.11.29.08.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 08:35:26 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Obn3FFIJ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8BA90891F5; Fri, 29 Nov 2024 17:35:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Obn3FFIJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EFF4E891F5; Fri, 29 Nov 2024 17:35:21 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BCCB7891CF for ; Fri, 29 Nov 2024 17:35:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5cfddb70965so2386397a12.0 for ; Fri, 29 Nov 2024 08:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732898119; x=1733502919; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fU90U3F47CumcRAOvrvxLDb55n8icxq6eKeukvJX0Ts=; b=Obn3FFIJznTRm3qD9e/jU5nEumsU8Zf9K/TFq5HP40ALMqEVcq/3N3V4BUBnAD09pC 2tapxqXAxqpSUr0cSJSAda26NSJVr+cZaop/XZicr9nkT32dUJ91/g3ZM0FubvWs55Qc FgjZH5UWWbDrHl1TVVmWK/gSvFwm0RwerGjwSjTL8npNaBPaFh9tT1ILWKtsUUSeqQTW DIgKJgKxPbD4QFSv1Ddi7nPr467VGudOGzfyi+NIdAC8DwQmpG13u/6QhUZ2AiuvyV3d feHLM0vVNpIHT5xyDxdpRxwyiWwi6htbIJhFBheQlpXDWk4vP/uG/TPd6F6y0Ft9ZL21 XlwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732898119; x=1733502919; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fU90U3F47CumcRAOvrvxLDb55n8icxq6eKeukvJX0Ts=; b=hhnUJzxmOvsDtdjU0URXaEhzK8cIEZyez905c1MRX4qzcUxHr/KIgc1SmBOKc/pMyX n2QsriXKKuU1gZ2W0cRp1WYZhwE7HInSK4ZEypUbB+FnwcLl0y+qKS6Lz38tWXb685B/ jpcZ++tsVas7gzcESbe8ZiIwytKqS/uXJgsY+AtqkgjM6F3fHLnCl0wP/dhV/Wj1cL4W bTRYKeJQ84LgB58Sy2cOn0fGFyQBEUPNLxbnesuyC2P+z8s/g6qpwnPOnIlmUL4gVCes W1dOO4c/xFP6OKjLVibAFasLN1HFDZLEHxQ6K5lF6oRvQ6+jbafiJd3G8B7L3ibu9f+w W/JA== X-Forwarded-Encrypted: i=1; AJvYcCUIPk+fxon8+BuquhWuEjOxtNQLpeeJ/GPTn/bETpaKmzATzq/f/GHdGspytABx0d//kWwxeuE=@lists.denx.de X-Gm-Message-State: AOJu0Yxs1WmXsFcCK857hK3nN3sMYFR9IGp4wF1m8iooYyRfu6apmiDW vSr7KZoGH2e3aiByrae47FTgNVrWXiGJN8rHbDacHEE0yKkTrRAd+2clZkqNbNM= X-Gm-Gg: ASbGncuYhjxl4HE1dbmISIPFjRJAe7OkZ96AsulOAO93jTGpZUzqlbFJz4r6Mt/Bpbc naN79+s3d/jvLVQEFsWQiPw0xOZjMLBJXl6bj9DJVVQ3OLLdT/CRk75lUK+FA3Th93HW1TMX1xp yL8RHGHtamVbyQUWE3dj5CIWog0Px96/1JZHmGWZci1aoEuhwkBXKYab5INFVoYrLHx3UUYm8QA KWuO+poxFJh96o5p+yAfYOPcssQkeUWxOug3WwcVNKd8PFEC4yx61dF574CuECNx5pBqN+LuM6a JFmtnqFIcvw0oRAgOzkPaKPhtA== X-Received: by 2002:a05:6402:5113:b0:5cb:dfd8:464d with SMTP id 4fb4d7f45d1cf-5d080c5ac36mr12098711a12.28.1732898119187; Fri, 29 Nov 2024 08:35:19 -0800 (PST) Received: from localhost.localdomain (ppp089210064034.access.hol.gr. [89.210.64.34]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5996c1945sm188254466b.19.2024.11.29.08.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 08:35:18 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Tom Rini , Sughosh Ganu , Simon Glass , u-boot@lists.denx.de Subject: [PATCH] efi_loader: Add U-Boot memory to the EFI memory map Date: Fri, 29 Nov 2024 18:35:10 +0200 Message-ID: <20241129163511.767015-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This code was removed when the EFI subsystem started using LMB calls for the reservations. In hindsight it unearthed two problems. The e820 code is adding u-boot memory as EfiReservedMemory while it should look at what LMB added and decide instead of blindly overwriting it. Thew reason this worked is that we marked that code properly late, when the EFI came up. But now with the LMB changes, the EFI map gets added first and the e820 code overwrites it. The second problem is that we never mark SetVirtualAddressMap as runtime code, which we should according to the spec. Until we fix this this hack can't go away, at least for architectures that *need* to call SVAM. More specifically x86 which currently requires SVAM, sets the NX bit for pages not marked as *_CODE. So unless we do that late, it will crash trying to execute from non-executable memory. Notably arm64 disables it explicitly if the VA space is > 48bits, so doesn't suffer from any of these problems. This doesn't really deserve a fixes tag, since it brings back a hack to rememdy a sitation that was wrong long before that commit, but in case anyone hits the same bug ... Fixes: commit a68c9ac5d8af ("efi_memory: do not add U-Boot memory to the memory map" Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_memory.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index e493934c7131..edd7da7d8c6e 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -814,7 +814,16 @@ static void add_u_boot_and_runtime(void) { unsigned long runtime_start, runtime_end, runtime_pages; unsigned long runtime_mask = EFI_PAGE_MASK; - + unsigned long uboot_start, uboot_pages; + unsigned long uboot_stack_size = CONFIG_STACK_SIZE; + + /* Add U-Boot */ + uboot_start = ((uintptr_t)map_sysmem(gd->start_addr_sp, 0) - + uboot_stack_size) & ~EFI_PAGE_MASK; + uboot_pages = ((uintptr_t)map_sysmem(gd->ram_top - 1, 0) - + uboot_start + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; + efi_add_memory_map_pg(uboot_start, uboot_pages, EFI_BOOT_SERVICES_CODE, + false); #if defined(__aarch64__) /* * Runtime Services must be 64KiB aligned according to the