From patchwork Thu Feb 20 13:54:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 866788 Delivered-To: patch@linaro.org Received: by 2002:a5d:47cf:0:b0:38f:210b:807b with SMTP id o15csp60117wrc; Thu, 20 Feb 2025 13:01:56 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVvgoLgOItucElM3Kntxq84X+ZIHy7TUowNyA3CVu6sCdUGSmrPwipYjGpw3JtdmxvZOh1XCw==@linaro.org X-Google-Smtp-Source: AGHT+IGPZZB9PTARqG6VfZD74/1aLFTg7C6bAxvK27nb9i5OOMwlkpGAqJtc+zFs7e5NdD1ZVUxW X-Received: by 2002:a5d:5350:0:b0:38f:2a84:7542 with SMTP id ffacd0b85a97d-38f6e97af1emr600007f8f.28.1740085316438; Thu, 20 Feb 2025 13:01:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740085316; cv=none; d=google.com; s=arc-20240605; b=fIXjUAoC2eDCCeB3/g0oyfAGhfmxeXMJq+IbNjY6QrZpqtMgL29Kv72hHVjU3zW61d a5pocn42hoHdFy5KLJz8ahAQ4g1lH1VwJU+/F+fVPQoTU2wTDtGmAT1ALpgNCLfm1oXV H2gTn4BhSHW5LNw9yfWXYHvKE89kK+3x1kUH4/wJEBo3fjYtHZ6i+rCcpxUfVSWD5klN B9duqEz0liYzgLqQhppybnll/7ZxK7ExAOP5XWhKdW+V9NwwnfcDWaHVi006BFJrfEJ6 HwKNE2gB8+srtl5lSgVpVRLe+QE/V9IHvbpmfJADscVOgB6izeB6dRBRphyTqwKGAdKa PKcA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sqOy20sja8WQ+/N6U2BFZ8pmWuEOlVnY5Bc/eM0M/kM=; fh=1uO1DRykpmkjsPiRojAJFElkRVuHmPxKmT+HEHCuZ6E=; b=DyAhz7GIHtpDi2al63dCgdYDa7DHsqGEA/Qgs7K2UjaTHW5luCOVxai+kyH6Cy1O9K TRr2+bmOxDdoMe4GjELGbzADiMP9rFUtDzeNp2VpDdvTbUK3iwyflY8tq+eIr93RN+Si tTS3KjuQbeY/8N0bDtqW0oE2cgVFLFnpU6uy6kxJajRCuwJoxi0XbyujVMSNHOQfZvkG sEJUrFApj3hCxas/OSL8cLiRsVjg2lBUK0kuAK8/caZrn2ZNAM5UGx7xifVfNZmOaCTS VStwR+czYQ3bpjVOtscEHnOm6tTBTUHQdBefpRUJE8RrZWV0YfRFrsx+1mQUQ6a6rt0g vWvg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=coUZ3E6z; 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 ffacd0b85a97d-38f258e1827si15462633f8f.126.2025.02.20.13.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 13:01:56 -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=coUZ3E6z; 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 374B480F5C; Thu, 20 Feb 2025 22:01:47 +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="coUZ3E6z"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6E8B88001F; Thu, 20 Feb 2025 14:55:40 +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-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 618F680F5F for ; Thu, 20 Feb 2025 14:55:38 +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-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-43995b907cfso5898755e9.3 for ; Thu, 20 Feb 2025 05:55:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740059738; x=1740664538; darn=lists.denx.de; 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=sqOy20sja8WQ+/N6U2BFZ8pmWuEOlVnY5Bc/eM0M/kM=; b=coUZ3E6zhbKHKCFLEWdU+Oe+jNaxpQNj3dg3ZRxv2i5poghpHGcZAGh6+itdmd9YZh mrkmZegOfF+pR4zHWOtDM+w4MJdH9SjYS6y8ROFdw3j7IgWVsMQu/24yV6gf3UA881NG v3BeHbh/OUvb0fpgNoCOsAXiSgEmAG1KJzQZsx63wuP/Limon6mzDP0zmjSi3EFgMlB+ ckJPlzF+jF1Yot7K5z5DppreF3ZuJ7BNP8E/t+6MeQosAuxQTANCxxdmV4/w+nJcvKje Ce+6gnS6fV43i4Vgg3QbedEjF8BE8z+Lj/JaSKOB7AnGQlYHsCke072hdM0LkrLSgYRH kDgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740059738; x=1740664538; 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=sqOy20sja8WQ+/N6U2BFZ8pmWuEOlVnY5Bc/eM0M/kM=; b=bA/7NUOQC2dSNcuWyjAuDG9rixQuMZyseMZvhA/N/kBcqGyjnvXHF+fkyf5R/f/VIA BrOSOrUblese/oGQ2ai+O1e17PEDc9Fky9z95nFt3n9oe2BXsA2WiVM1Rhxh1TVXKYej rInJtq42B7Zi8mhnirgX4N9ebTt5r6SQFnwK6SJ8WA566zDwnX72OzplzfY3QEI978hI rWvdOQnj95IJSeY6Q+nn4slUgx8F8B7F8OT+tW2Lt7wihqbUTtz5zpulDcgIWh+/qFea UUVe+qqZ0zGh8uhU4G5x+cWqJPUQgCdf3+VOvHjWaFatn7vh1XNsSoqFh77ORgdalOUh 9NWg== X-Forwarded-Encrypted: i=1; AJvYcCUMKFVKprIaBFKFCzJfdiG5hr1Rv2fQ7txOCphEb4z6O/FVNQ3mkAayl4Az/v+PmjHrRGdWK/s=@lists.denx.de X-Gm-Message-State: AOJu0Yy+VfWedPS5MBkRLqW0KnhUR/oZ0aEWZ3GLXGpYUG/KYmg6jSqr ybxu2FcilNOMnXsL1uh1SsusFyLvu+RU4GH3Cz1G+qzNV8a8BQqrcVChquWucgw= X-Gm-Gg: ASbGnctZPiroPpHjaUY+GzSUnKdiYnF/PpwF6BGP5YyExCiRHHPI8aKNA7GC9X4VaBj /8nDQ6q8K0E6Mflpyxca01yFkynxXaGPcOOtHUuKmZca0Vz+i694DGIy8t+5NRazQreUupSTmQO FzkTkKdJCuWRbcYGWiYYOXVjvKpr4zvcnxN6CbtEBzbR5KlmLhW7hCJpLqXtVXhm9eZBptsJ09n Nf5w1GvoYoFEzA+D9SEk80M/49KpGzDLTPF3nEVmliprIi5Hb4uWn4g4F7N9werbwyOMg554bJC ePOOz3zFO22ybMT/0hwt8e49/z163KN7h3TN8ZYzSxen0KEQIhmToI4MJZ/3GGREm+d+eA== X-Received: by 2002:a05:600c:4750:b0:439:9828:c425 with SMTP id 5b1f17b1804b1-4399828c633mr96694555e9.7.1740059737811; Thu, 20 Feb 2025 05:55:37 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43987088ecbsm111659865e9.31.2025.02.20.05.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 05:55:37 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Jerome Forissier , Caleb Connolly , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Neil Armstrong , Sumit Garg , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Sughosh Ganu , Simon Glass , Sam Protsenko , Peng Fan , Richard Henderson , Sam Edwards , Andre Przywara , Peter Hoyes , Patrick Rudolph , Sam Day , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Alex Shumsky , Jiaxun Yang , Joshua Watt , Jagan Teki , Evgeny Bachinin , Michal Simek , Christian Marangi , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de, u-boot-qcom@groups.io Subject: [PATCH v2 1/6] meminfo: add memory details for armv8 Date: Thu, 20 Feb 2025 15:54:38 +0200 Message-ID: <20250220135506.151894-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250220135506.151894-1-ilias.apalodimas@linaro.org> References: <20250220135506.151894-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 20 Feb 2025 22:01:46 +0100 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 Upcoming patches are mapping memory with RO, RW^X etc permsissions. Fix the meminfo command to display them properly Acked-by: Jerome Forissier Reviewed-by: Caleb Connolly Signed-off-by: Ilias Apalodimas --- arch/arm/cpu/armv8/cache_v8.c | 26 +++++++++++++++++++++++--- arch/arm/include/asm/armv8/mmu.h | 2 ++ cmd/meminfo.c | 6 ++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c index 5d6953ffedd1..c4b3da4a8da7 100644 --- a/arch/arm/cpu/armv8/cache_v8.c +++ b/arch/arm/cpu/armv8/cache_v8.c @@ -421,7 +421,7 @@ static int count_ranges(void) return count; } -#define ALL_ATTRS (3 << 8 | PMD_ATTRINDX_MASK) +#define ALL_ATTRS (3 << 8 | PMD_ATTRMASK) #define PTE_IS_TABLE(pte, level) (pte_type(&(pte)) == PTE_TYPE_TABLE && (level) < 3) enum walker_state { @@ -568,6 +568,20 @@ static void pretty_print_table_attrs(u64 pte) static void pretty_print_block_attrs(u64 pte) { u64 attrs = pte & PMD_ATTRINDX_MASK; + u64 perm_attrs = pte & PMD_ATTRMASK; + char mem_attrs[16] = { 0 }; + int cnt = 0; + + if (perm_attrs & PTE_BLOCK_PXN) + cnt += snprintf(mem_attrs + cnt, sizeof(mem_attrs) - cnt, "PXN "); + if (perm_attrs & PTE_BLOCK_UXN) + cnt += snprintf(mem_attrs + cnt, sizeof(mem_attrs) - cnt, "UXN "); + if (perm_attrs & PTE_BLOCK_RO) + cnt += snprintf(mem_attrs + cnt, sizeof(mem_attrs) - cnt, "RO"); + if (!mem_attrs[0]) + snprintf(mem_attrs, sizeof(mem_attrs), "RWX "); + + printf(" | %-10s", mem_attrs); switch (attrs) { case PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE): @@ -613,6 +627,7 @@ static void print_pte(u64 pte, int level) { if (PTE_IS_TABLE(pte, level)) { printf(" %-5s", "Table"); + printf(" %-12s", "|"); pretty_print_table_attrs(pte); } else { pretty_print_pte_type(pte); @@ -642,9 +657,9 @@ static bool pagetable_print_entry(u64 start_attrs, u64 end, int va_bits, int lev printf("%*s", indent * 2, ""); if (PTE_IS_TABLE(start_attrs, level)) - printf("[%#011llx]%14s", _addr, ""); + printf("[%#016llx]%19s", _addr, ""); else - printf("[%#011llx - %#011llx]", _addr, end); + printf("[%#016llx - %#016llx]", _addr, end); printf("%*s | ", (3 - level) * 2, ""); print_pte(start_attrs, level); @@ -1112,3 +1127,8 @@ void __weak enable_caches(void) icache_enable(); dcache_enable(); } + +void arch_dump_mem_attrs(void) +{ + dump_pagetable(gd->arch.tlb_addr, get_tcr(NULL, NULL)); +} diff --git a/arch/arm/include/asm/armv8/mmu.h b/arch/arm/include/asm/armv8/mmu.h index 0ab681c893d3..6af8cd111a44 100644 --- a/arch/arm/include/asm/armv8/mmu.h +++ b/arch/arm/include/asm/armv8/mmu.h @@ -66,6 +66,7 @@ #define PTE_BLOCK_NG (1 << 11) #define PTE_BLOCK_PXN (UL(1) << 53) #define PTE_BLOCK_UXN (UL(1) << 54) +#define PTE_BLOCK_RO (UL(1) << 7) /* * AttrIndx[2:0] @@ -75,6 +76,7 @@ #define PMD_ATTRMASK (PTE_BLOCK_PXN | \ PTE_BLOCK_UXN | \ PMD_ATTRINDX_MASK | \ + PTE_BLOCK_RO | \ PTE_TYPE_VALID) /* diff --git a/cmd/meminfo.c b/cmd/meminfo.c index 5e83d61c2dd3..acdb38dcba02 100644 --- a/cmd/meminfo.c +++ b/cmd/meminfo.c @@ -15,6 +15,10 @@ DECLARE_GLOBAL_DATA_PTR; +void __weak arch_dump_mem_attrs(void) +{ +} + static void print_region(const char *name, ulong base, ulong size, ulong *uptop) { ulong end = base + size; @@ -58,6 +62,8 @@ static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc, if (!IS_ENABLED(CONFIG_CMD_MEMINFO_MAP)) return 0; + arch_dump_mem_attrs(); + printf("\n%-12s %8s %8s %8s %8s\n", "Region", "Base", "Size", "End", "Gap"); printf("------------------------------------------------\n"); From patchwork Thu Feb 20 13:54:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 866789 Delivered-To: patch@linaro.org Received: by 2002:a5d:47cf:0:b0:38f:210b:807b with SMTP id o15csp60224wrc; Thu, 20 Feb 2025 13:02:06 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWD5Ug0O/0n6I7FeJq4EKFk7Gq9y9JbUw0hjwXyhQ8ZFO3CjS8aWTBSTFTveKu+DNBskyr3jA==@linaro.org X-Google-Smtp-Source: AGHT+IHQB/xG5eEPWYA5lRz265CJ3yDdqrK6/DAbG9eO9pgfgqekH8J7vs4zxvrkx2fgj3+3Ichd X-Received: by 2002:a05:600c:1551:b0:439:9eba:93bb with SMTP id 5b1f17b1804b1-439ae1f19f0mr7419755e9.18.1740085326323; Thu, 20 Feb 2025 13:02:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740085326; cv=none; d=google.com; s=arc-20240605; b=kWwSJNuOSK94hUGgugoqTzuliKSccokfNAxSTUW3IUnmCnMDD06y34kelVXYQQI1eC lRE+KWTV6K20/l4PdsCb2lVrf2gWrP1d51C5iVabe379adk0PMyULMGgbxkiifJC3sQ/ slsrmPfwmo2Cx5b1bh6F24PGQVjIifu0FhfrJAykAR/coUAMKuyMLLpkRxM7C2uxK1PI 3/+chvDDILOj0xDelmOrWZNjFEZBeXqf0lFakj3uvj29m+QBWdoSevPWqoQuZlfg5tWR Ue3UfW/gpBsWZXhSPckUm6FbkM0WU2XdpZJJWVaTF+/sNRCLkc4jecp5tkn9sCZhlVmN ycuQ== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B4GSS1ETVKQO5Boy5/n9bcml4EPCbjNmO/frH+vfBuQ=; fh=N+8ezPxhngi9VWsERn4L7pm4Wc0A/EFabDBfRbm8Xdg=; b=TXZh1vjwUcQP8TiUq0HlPwjBnu3U7s2SsOR5HXVBNCrIjUe43yyBmLx4bGz3mWJEzB X++6yIbpWegaQ42hvdQaz3ergKXx1ci28fTOtAXfMdlFkcYelFDzqmDEcT/pMy4aRguJ yPqEmcWbWECE+BCxR708+1aicPau3VXmYzeWyQMDSYtQ4kZnStE/dG7z63AvKNPqOCCD 5tA0xhC7q3YxMINQowTi93Td+k6eghbq2Ni09CE+DJqJsVC/EFlyVpEJLCPx0dUtfCjY hf6U4+0BYBuC0K3qAhYz+vo++TEpxLRBIvf+xKePsIuiUC4up4a+SPWaUuPkTBXa+RPe k7gA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QXVRmvOm; 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 5b1f17b1804b1-4395a8cc8besi167175785e9.141.2025.02.20.13.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 13:02:06 -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=QXVRmvOm; 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 85D3B80F7B; Thu, 20 Feb 2025 22:01:47 +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="QXVRmvOm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4F2BF80F5F; Thu, 20 Feb 2025 14:55:47 +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-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (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 DD1A88001F for ; Thu, 20 Feb 2025 14:55:44 +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-wm1-x335.google.com with SMTP id 5b1f17b1804b1-439a4fc2d65so6929285e9.3 for ; Thu, 20 Feb 2025 05:55:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740059744; x=1740664544; darn=lists.denx.de; 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=B4GSS1ETVKQO5Boy5/n9bcml4EPCbjNmO/frH+vfBuQ=; b=QXVRmvOmXIxJY0NavCQHtSzljlx93O+UmrKjPX76kaBXhIoC3vS1YfB2hbEqabUpb0 2cInTALQO1vke1e6VvKgHGOAlhIbIcMKOaxNwRPCwjA3794nloYPL2H/60kyx9yvHMjZ PDL2XSrazGcot7YTjPiJbIqwQxJCUkKeV5YJPLDTSvBhzrkVusuywjv3x+0Pwt3/3ZC3 QipVLCVtgrlTyM0B9iRvs8LyveX0dTisPZE7LNuQPpWE3c29C2od7u3D8uXADDWdLpXw bmUqeFsN+4CzGcv9uvxNS9Qvg3rM2Ia7zyJd84LDsh4IpLeVBSKwE2y0Ll1m+enz+rFf JOhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740059744; x=1740664544; 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=B4GSS1ETVKQO5Boy5/n9bcml4EPCbjNmO/frH+vfBuQ=; b=M6bqeFfSLGjSvOPaWX7aLFjvVotxZ0lFKe+cJqAXiFw+nq9qoOXlee//ei5UIXNFyX PFZY6dYeD+ZsWzKw5Cizb6ns+LTRuGZKbJZGimS6xCIJWZWg/cu2gXVohZ6Ix0+IGgZJ MHl5kys0hen5EnYqa32NlHYmS7XtBDKMwCDUs5PdnSc9xWsXvpVQPe78JfN+bO5Vn/hB +TNsZ3FYAEGhpu8swJ5cvWSzC2UwwaGCOru8mapWJRpi7pEaDHkKBcz6cBnlRCpiWSk4 UN0kRlQWCnShKHwKLwaM6ooCMmbWVAFDo5qBSx9LT1p/AjVBSAdUzjxyoyRRfTMslloI IaLw== X-Forwarded-Encrypted: i=1; AJvYcCWDQEF/No+EULa/2f9S5Qc0qKRE75n/6sZwlWBfXhRcjrXIIJJOYi4/06aR+6EVIrRY/SBSZpg=@lists.denx.de X-Gm-Message-State: AOJu0Yw7H3OJbl+GnsWC67wcELPJt/2n/9FZ1FGnBgyIUgmFFZngQbJ4 lG/TSbtlA9MVg3hbiO7BYMCB6vHj67zy/as+MC1ilW1WPhub9kRcxDidYCLlbq0= X-Gm-Gg: ASbGncv+/TFxRFgQUo+4VVPWvEsuHbF+Hb0gzHycBCmvfMsU0ydKYUshPuaxzPnyCxA haI6aJ6m8qb9/UAt+foExgSJlEcRx6fyhn1ejNuyBJHe+n6iIbZs9Dtrrs/W5vXBsV6amtFJfRX ulZ82q3MjCN1pJ9juC2k4I7b/3m7qi1eJGMBcc+QwtxmuUXXcDaMSRwTFLxmKrkDH6V3kKWkbE3 rejFdO0pfGzomjXrVUQ8m6/XM/WzKfOCUTMqc2GDcI1ocBcpZZhFZBAOfp8xTi1vHfswu+bRn4E OaG7pRETgrKJ6/GT2wZiXRKn9Tcd8fKw1kdk6za1ZYlhwxM8+vawt0yOnadfo/Kcek6oOg== X-Received: by 2002:a05:600c:450d:b0:439:9dec:b7a2 with SMTP id 5b1f17b1804b1-4399decb9a6mr63218455e9.2.1740059744214; Thu, 20 Feb 2025 05:55:44 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43987088ecbsm111659865e9.31.2025.02.20.05.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 05:55:43 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Caleb Connolly , Neil Armstrong , Sumit Garg , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Simon Glass , Sughosh Ganu , Marc Zyngier , Sam Protsenko , Peng Fan , Richard Henderson , Sam Edwards , Jerome Forissier , Peter Hoyes , Andre Przywara , Patrick Rudolph , Sam Day , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Jiaxun Yang , Joshua Watt , Alex Shumsky , Jagan Teki , Evgeny Bachinin , Christian Marangi , Michal Simek , Rasmus Villemoes , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de, u-boot-qcom@groups.io Subject: [PATCH v2 2/6] doc: update meminfo with arch specific information Date: Thu, 20 Feb 2025 15:54:39 +0200 Message-ID: <20250220135506.151894-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250220135506.151894-1-ilias.apalodimas@linaro.org> References: <20250220135506.151894-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 20 Feb 2025 22:01:46 +0100 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 Since we added support in meminfo to dump live page tables, describe the only working architecture for now (aarch64) and add links to public documentation for further reading. Signed-off-by: Ilias Apalodimas --- doc/usage/cmd/meminfo.rst | 71 +++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/doc/usage/cmd/meminfo.rst b/doc/usage/cmd/meminfo.rst index 6c94493cccc6..e10bdc6832cf 100644 --- a/doc/usage/cmd/meminfo.rst +++ b/doc/usage/cmd/meminfo.rst @@ -18,7 +18,8 @@ Description The meminfo command shows the amount of memory. If ``CONFIG_CMD_MEMINFO_MAP`` is enabled, then it also shows the layout of memory used by U-Boot and the region -which is free for use by images. +which is free for use by images. In architectures that support it, it also prints +the mapped pages and their permissions. The latter is architecture specific. The layout of memory is set up before relocation, within the init sequence in ``board_init_f()``, specifically the various ``reserve_...()`` functions. This @@ -26,8 +27,9 @@ The layout of memory is set up before relocation, within the init sequence in ending with the stack. This results in the maximum possible amount of memory being left free for image-loading. -The meminfo command writes the DRAM size, then the rest of its outputs in 5 -columns: +The meminfo command writes the DRAM size. If the architecture also supports it, +page table entries will be shown next. Finally the rest of the outputs are +printed in 5 columns: Region Name of the region @@ -99,28 +101,61 @@ free Free memory, which is available for loading images. The base address of this is ``gd->ram_base`` which is generally set by ``CFG_SYS_SDRAM_BASE``. +Aarch64 specific flags +---------------------- + +More information on the output can be found +Chapter D8 - The AArch64 Virtual Memory System Architecture at +https://developer.arm.com/documentation/ddi0487/latest/ + +In short, for a stage 1 translation regime the following apply: + +* RWX: Pages mapped with Read, Write and Execute permissions +* RO: Pages mapped with Read-Only permissions +* PXN: PXN (Privileged Execute Never) applies to execution at EL1 and above +* UXN: UXN (Unprivileged Execute Never) applies to EL0 + Example ------- This example shows output with both ``CONFIG_CMD_MEMINFO`` and -``CONFIG_CMD_MEMINFO_MAP`` enabled:: - - => meminfo - DRAM: 256 MiB +``CONFIG_CMD_MEMINFO_MAP`` enabled for aarch64 qemu:: + + DRAM: 8 GiB + Walking pagetable at 000000023ffe0000, va_bits: 40. Using 4 levels + [0x0000023ffe1000] | Table | | | + [0x0000023ffe2000] | Table | | | + [0x00000000000000 - 0x00000008000000] | Block | RWX | Normal | Inner-shareable + [0x00000008000000 - 0x00000040000000] | Block | PXN UXN | Device-nGnRnE | Non-shareable + [0x00000040000000 - 0x00000200000000] | Block | RWX | Normal | Inner-shareable + [0x0000023ffea000] | Table | | | + [0x00000200000000 - 0x0000023f600000] | Block | RWX | Normal | Inner-shareable + [0x0000023ffeb000] | Table | | | + [0x0000023f600000 - 0x0000023f68c000] | Pages | RWX | Normal | Inner-shareable + [0x0000023f68c000 - 0x0000023f74f000] | Pages | RO | Normal | Inner-shareable + [0x0000023f74f000 - 0x0000023f794000] | Pages | PXN UXN RO | Normal | Inner-shareable + [0x0000023f794000 - 0x0000023f79d000] | Pages | PXN UXN | Normal | Inner-shareable + [0x0000023f79d000 - 0x0000023f800000] | Pages | RWX | Normal | Inner-shareable + [0x0000023f800000 - 0x00000240000000] | Block | RWX | Normal | Inner-shareable + [0x00000240000000 - 0x00004000000000] | Block | RWX | Normal | Inner-shareable + [0x0000023ffe3000] | Table | | | + [0x00004010000000 - 0x00004020000000] | Block | PXN UXN | Device-nGnRnE | Non-shareable + [0x0000023ffe4000] | Table | | | + [0x00008000000000 - 0x00010000000000] | Block | PXN UXN | Device-nGnRnE | Non-shareable Region Base Size End Gap ------------------------------------------------ - video f000000 1000000 10000000 - code ec3a000 3c5d28 efffd28 2d8 - malloc 8c38000 6002000 ec3a000 0 - board_info 8c37f90 68 8c37ff8 8 - global_data 8c37d80 208 8c37f88 8 - devicetree 8c33000 4d7d 8c37d7d 3 - bootstage 8c32c20 3c8 8c32fe8 18 - bloblist 8c32000 400 8c32400 820 - stack 7c31ff0 1000000 8c31ff0 10 - free 0 7c31ff0 7c31ff0 0 - + video 23f7e0000 800000 23ffe0000 + code 23f68a000 156000 23f7e0000 0 + malloc 23e64a000 1040000 23f68a000 0 + board_info 23e649f80 78 23e649ff8 8 + global_data 23e649df0 188 23e649f78 8 + devicetree 23e549df0 100000 23e649df0 0 + bloblist 23e547000 2000 23e549000 df0 + stack 23d546ff0 1000000 23e546ff0 10 + lmb 23d546ff0 0 23d546ff0 0 + lmb 23d543000 3ff0 23d546ff0 0 + free 40000000 23d543000 27d543000 ffffffffc0000000 Return value ------------ From patchwork Thu Feb 20 13:54:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 866790 Delivered-To: patch@linaro.org Received: by 2002:a5d:47cf:0:b0:38f:210b:807b with SMTP id o15csp60314wrc; Thu, 20 Feb 2025 13:02:15 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWfzZckv/g9jklOh9DioMkJHUhWc54RrLD+i7GvZuYFi9vnViS00hkahPsuF5RL1j2A67nwgw==@linaro.org X-Google-Smtp-Source: AGHT+IGMHEWgEicToQ9r09cWsyfKGwBgRp+7nAKMpsfKX0d9ETx46OdUVnJvQsv+1lXf7As30/DH X-Received: by 2002:a5d:64a2:0:b0:38d:e078:43a5 with SMTP id ffacd0b85a97d-38f6e947079mr693964f8f.13.1740085335261; Thu, 20 Feb 2025 13:02:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740085335; cv=none; d=google.com; s=arc-20240605; b=TBLnAluBeY8If87mQMniw6Y/8CM7Z8Oz78qwZLHkDxyy0azys/vrB1DS9jF4i8ub2j 1Arn4AF0QHkj8wYiwj8hnTedMNdTrely3fxImdzl2XJ4rC2g1cT94Nm5JIBbIplhz3u2 rN+UgbKSWdaRxibDO8KxScys2z1tgkuEW71ImkJfhKbjZPHZqXNhyDn6GHIAQNXZiVii RqQPPap298b8xDhLl9nnE85j9K8C+PM4Wb/d9KSqnQSNXBrLsv3joBCVD9wOQXSZlsN5 RWIJQKfDX307U6tS9Ce4k3RR8lQXT8egEUbYDoexzQVdZf3dxQjP7z/uogSAkA6GoGSb vsNA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mFo02FrkhIKmKk+dIhsgUH/KahGMd8Gr637V7DagyXo=; fh=YCtTr0Yk54WSh5rsM76bimNH+jHcGac1NYBodWDIPaI=; b=CwGUvAM6rIX7nXtR6q+flIyWMI8zU2ViALk6M/0PUFOMylQ3KWjSJv26YqNhFv8a6Z UAbuFCo0B4rJg6M5UfK/Pitv//9Rl8ejZGzAw907sw4DN0vcBZDLjW3lhIB1MWE0bLqO yfsumkuUMmtcMX4oeyoC+PLxUQAM233g5dWGiTnGSXcqYGBWdZigwimIqRMT86jGU9Kk kCaxra2Sm2YMVFZj5YSHZvGJyZNo1NDQKnDkiYU37FuBgYq8I5iuIO4DQzisuglaTSeB I878Jyc/bt7cD/UDa1zpt2cV5palMjbSMJEXPGU8hojWp+Xwm9cTv8FqyzJq2b25/3I4 zQKA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NAo6AjJv; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f25a107b2si15071407f8f.612.2025.02.20.13.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 13:02:15 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NAo6AjJv; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 CB06F80F91; Thu, 20 Feb 2025 22:01:47 +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="NAo6AjJv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D580580F5C; Thu, 20 Feb 2025 14:55:53 +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-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (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 7059A8001F for ; Thu, 20 Feb 2025 14:55:51 +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-wr1-x436.google.com with SMTP id ffacd0b85a97d-38dd9b3419cso512398f8f.0 for ; Thu, 20 Feb 2025 05:55:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740059751; x=1740664551; darn=lists.denx.de; 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=mFo02FrkhIKmKk+dIhsgUH/KahGMd8Gr637V7DagyXo=; b=NAo6AjJv2X4mPIphLERqyCjvT0ClKOkZzJsW57B7Fg/lmlWuJiQKBVsAjOMGWg5XZp Cuzdo9jZpVOJDMM5bj9i+rn2036u28i2oYQx8Fv069LBhLZRMV2A9MLXqccB5zkTFZWR D8nAzxgPuQgIVCiFspRBW8sLC03mIoY5nTQGzsdS2UgmzK/l/YS85JBiCSHfOPQDQauX TUJB0Og/4+hj9v185DKF2WXjpM+TW6dQ7NPetD6iAwzuKWekdUkbz4jiw1w9TtDHQZe4 pDg8PrN3o+9BAG3mFvqHQzbwgUn1uViXc+9voxTsrOxborrMr+SDWFHbOSZ5j31lwk+v WY9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740059751; x=1740664551; 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=mFo02FrkhIKmKk+dIhsgUH/KahGMd8Gr637V7DagyXo=; b=GwnSQ7BB4i8bU8xh8Pip4WL7YkydKz+1Z5duxa1vmtzi9HlZyaWqoFY39i2TEK+lhH zePFSOt6a20BWh15PXq9h9uOipF1DJq10koqVTQFuSN/fjsqGew3DGl5m0+SFe+Yxd7C 8yel1SEInoLKpSfc8olA8hUZSxcns8pDKUZL1v+bFsPkLZQhXbUoxMpKEmytrd9FcVEP Nv1F431Qp2aquQlGYGGrBUzfM3IG1PM8xCJe+lKsgtHff/G/jYkKx1H5JznuOkUfrI+B ZAYBhFM2IM/wUucB1ORZYgwjydRxx2lzpaa0Aymsllok1ATDPEhGGnV/ctk1tkJkb68C W1ig== X-Forwarded-Encrypted: i=1; AJvYcCXlM+XDpYegcycOZuOUEAxtCW+U9HPMvdTCmNUUl9T4tgi3tsAh81jKc9RjGt3XPvyNc3Wml4s=@lists.denx.de X-Gm-Message-State: AOJu0YxaewrjFTrt2EedYgp6y//arnrgbp4bLkQz3ICvyJ9txLNkSPhr NQJzpXOBonFwpBWoEnHo49D83fpqtGDfeSDLot+3mgHr+5k/ybT4QQVFsarLtic= X-Gm-Gg: ASbGncv/z3PgTXSkHkwsQUuhwrZeG2cD/b/oj9EYp7bWQeufNbYuak98f8uTYI63lRb 4zIr+xfaTnGzOfOpedQ93YBjYU1jf1rFDVuZwIE7J/lXnYJI39PzZGlfnlSoS8/5PcY0w9uxr5N uTQick4r/jzalFROrKXzuKQfjTv5jilp7u9OeLlfgE/HfK8O2iieQfdXMBk3dNaVwzBd8AJR7n9 8L2F46HhPOxnL/XsKjjfQHjKG89JRTH0bY6uFkoqlZoELDrZV2FxpM7GwjoVpe7KUv9IkMUdOoe iscu5inmSnn2tgIYSgs9SNKlTwMqyd4eqkTO604SKdK1GzHRpKoenQ5UIw0pAwZMX4MCzg== X-Received: by 2002:a05:6000:1885:b0:38f:579f:de15 with SMTP id ffacd0b85a97d-38f650e2555mr2219514f8f.14.1740059750719; Thu, 20 Feb 2025 05:55:50 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43987088ecbsm111659865e9.31.2025.02.20.05.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 05:55:50 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Jerome Forissier , Neil Armstrong , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Caleb Connolly , Sumit Garg , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Sughosh Ganu , Simon Glass , Sam Protsenko , Marc Zyngier , =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= , Peng Fan , Richard Henderson , Sam Edwards , Peter Hoyes , Andre Przywara , Patrick Rudolph , Sam Day , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Jagan Teki , Alex Shumsky , Joshua Watt , Jiaxun Yang , Evgeny Bachinin , Michal Simek , Christian Marangi , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de, u-boot-qcom@groups.io Subject: [PATCH v2 3/6] arm: Prepare linker scripts for memory permissions Date: Thu, 20 Feb 2025 15:54:40 +0200 Message-ID: <20250220135506.151894-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250220135506.151894-1-ilias.apalodimas@linaro.org> References: <20250220135506.151894-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 20 Feb 2025 22:01:46 +0100 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 Upcoming patches are switching the memory mappings to RW, RO, RX after the U-Boot binary and its data are relocated. Add annotations in the linker scripts to and mark text, data, rodata sections and align them to a page boundary. It's worth noting that .efi_runtime memory permissions are left untouched for now. There's two problems with EFI currently. The first problem is that we bundle data, rodata and text in a single .efi_runtime section which also must be close to .text for now. As a result we also dont change the permissions for anything contained in CPUDIR/start.o. In order to fix that we have to decoule .text_rest, .text and .efi_runtime and have the runtime services on their own section with proper memory permission annotations (efi_rodata etc). The efi runtime regions (.efi_runtime_rel) can be relocated by the OS when the latter is calling SetVirtualAddressMap. Which means we have to configure those pages as RX for U-Boot but convert them to RWX just before ExitBootServices. It also needs extra code in efi_tuntime relocation code since R_AARCH64_NONE are emitted as well if we page align the section. Due to the above ignore EFI for now and fix it later once we have the rest in place. Acked-by: Jerome Forissier Tested-by: Neil Armstrong # on AML-S905X-CC Signed-off-by: Ilias Apalodimas Reviewed-by: Richard Henderson --- arch/arm/cpu/armv8/u-boot.lds | 59 +++++++++++++++++++++++----------- include/asm-generic/sections.h | 2 ++ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds index 857f44412e07..f4ce98c82c8d 100644 --- a/arch/arm/cpu/armv8/u-boot.lds +++ b/arch/arm/cpu/armv8/u-boot.lds @@ -36,9 +36,18 @@ SECTIONS __efi_runtime_stop = .; } +#ifdef CONFIG_MMU_PGPROT + .text_rest ALIGN(CONSTANT(COMMONPAGESIZE)) : +#else .text_rest : +#endif { + __text_start = .; *(.text*) +#ifdef CONFIG_MMU_PGPROT + . = ALIGN(CONSTANT(COMMONPAGESIZE)); +#endif + __text_end = .; } #ifdef CONFIG_ARMV8_PSCI @@ -97,35 +106,43 @@ SECTIONS LONG(0x1d1071c); /* Must output something to reset LMA */ } #endif - - . = ALIGN(8); - .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) } - - . = ALIGN(8); - .data : { - *(.data*) + .efi_runtime_rel : { + __efi_runtime_rel_start = .; + *(.rel*.efi_runtime) + *(.rel*.efi_runtime.*) + __efi_runtime_rel_stop = .; } - . = ALIGN(8); - - . = .; +#ifdef CONFIG_MMU_PGPROT + .rodata ALIGN(CONSTANT(COMMONPAGESIZE)): { +#else + .rodata ALIGN(8) : { +#endif + __start_rodata = .; + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) + } - . = ALIGN(8); - __u_boot_list : { + __u_boot_list ALIGN(8) : { KEEP(*(SORT(__u_boot_list*))); +#ifdef CONFIG_MMU_PGPROT + . = ALIGN(CONSTANT(COMMONPAGESIZE)); +#endif + __end_rodata = .; } - .efi_runtime_rel : { - __efi_runtime_rel_start = .; - *(.rel*.efi_runtime) - *(.rel*.efi_runtime.*) - __efi_runtime_rel_stop = .; +#ifdef CONFIG_MMU_PGPROT + .data ALIGN(CONSTANT(COMMONPAGESIZE)) : { +#else + .data ALIGN(8) : { +#endif + __start_data = .; + *(.data*) } . = ALIGN(8); __image_copy_end = .; - .rela.dyn : { + .rela.dyn ALIGN(8) : { __rel_dyn_start = .; *(.rela*) __rel_dyn_end = .; @@ -136,11 +153,15 @@ SECTIONS /* * arch/arm/lib/crt0_64.S assumes __bss_start - __bss_end % 8 == 0 */ - .bss ALIGN(8) : { + .bss ADDR(.rela.dyn) (OVERLAY) : { __bss_start = .; *(.bss*) . = ALIGN(8); __bss_end = .; +#ifdef CONFIG_MMU_PGPROT + . = ALIGN(CONSTANT(COMMONPAGESIZE)); +#endif + __end_data = .; } /DISCARD/ : { *(.dynsym) } diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index 3fd5c772a1af..024b1adde270 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -23,6 +23,7 @@ extern char __kprobes_text_start[], __kprobes_text_end[]; extern char __entry_text_start[], __entry_text_end[]; extern char __initdata_begin[], __initdata_end[]; extern char __start_rodata[], __end_rodata[]; +extern char __start_data[], __end_data[]; extern char __efi_helloworld_begin[]; extern char __efi_helloworld_end[]; extern char __efi_var_file_begin[]; @@ -63,6 +64,7 @@ static inline int arch_is_kernel_data(unsigned long addr) /* Start of U-Boot text region */ extern char __text_start[]; +extern char __text_end[]; /* This marks the text region which must be relocated */ extern char __image_copy_start[], __image_copy_end[]; From patchwork Thu Feb 20 13:54:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 866791 Delivered-To: patch@linaro.org Received: by 2002:a5d:47cf:0:b0:38f:210b:807b with SMTP id o15csp60408wrc; Thu, 20 Feb 2025 13:02:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXmSAwPVBwHYniSmFxItd6Bf1FKJ+SxfBgwLT+4dY2uWWAMMm0NyvJI3eHJqnELEV1+FsGkXw==@linaro.org X-Google-Smtp-Source: AGHT+IGxQJBRgrJTh9aZw0YDVv0/0kwV3DQipPzY2Mig8Y2bY/DluNP6J0RhpbxLlJJWUETohWDO X-Received: by 2002:a05:6000:4712:b0:38f:32d5:3a92 with SMTP id ffacd0b85a97d-38f614b827bmr4102543f8f.12.1740085344219; Thu, 20 Feb 2025 13:02:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740085344; cv=none; d=google.com; s=arc-20240605; b=Pf5Auz4O7Bh0OzviLfE6yr4lZSJB/94/Qy9eKQVhzAvLv+4qfhHQEw+QT10oiDLmj4 yCxG6k9nLUtdXkDMJpOKEFOg0pf5/aaQy2NGfU7/aj57POIqZhIuECsK/8NsqZ+jidKP CuxRBXYcI5YK9XkDtkGkUBgigBXWeP8bwHvoTsF1Cy04Qk6FliQXiHTmlrNOL+LDRxKt OPCsv5Yy0ks9cIJJe1zrJ1kq1XFqlG/hP3y7zZlokAq5dHnM4yZiZ2ME8Tv8dbMtCsK8 DaJzzrvfta+76443wF/64+vPpXLU4h8eYhqIALD2HRH7tIkJCr0jWMDFio44lwC5lDze +Zzg== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kZNDoru6BQKLt0+9h8+H9ivCYVfBH1Oosy/mEW5+620=; fh=5XPrcKMO1Q/zeIh+H28QILgtwIf2iV3AhDiJZ97+oIM=; b=Ojxx+OjhOYfxASbR1dLnqyJSxl5GkJIsYcvldCycPTtqQg/DGrLv/t75MOGgq/dV0b qNFcQnBOi0VkSsUGgXkNRqWMQVa7MNZL2Evtkj4lghX9gCZGJSHdi/wls67OpX8CRv3u jumQ3XfhqhlH/CMzYfbFAnUwTBPRD6wjFiQ8Ii18rTHeD8nkySbEmWMQY8rp0zLyxZ3r utNHRitU8/RS1RfNZN02lyN/DEC4GabshGeU14O1y9KjXLPttrIRUpCZoU7LIg0pY3FM uQnihba9q5Mt91zzEA/Xyb+HviiS7rWCByOpShqZ19RkrFS6Hp3ehZ2XqF08GE8ysstJ mjAw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zTxzBBTh; 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 ffacd0b85a97d-38f258ddbebsi15941427f8f.4.2025.02.20.13.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 13:02:24 -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=zTxzBBTh; 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 4113B80F98; Thu, 20 Feb 2025 22:01:48 +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="zTxzBBTh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4DD7780F5F; Thu, 20 Feb 2025 14:56:00 +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-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 E7DEB8001F for ; Thu, 20 Feb 2025 14:55:57 +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-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43984e9cc90so12398595e9.1 for ; Thu, 20 Feb 2025 05:55:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740059757; x=1740664557; darn=lists.denx.de; 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=kZNDoru6BQKLt0+9h8+H9ivCYVfBH1Oosy/mEW5+620=; b=zTxzBBThpjjQdHarYhJkRYGyiZtBv329wFlOjW0F0arTrmp4e52qLqqxRCe52FBq4U RVkE+24UJGXYhgc5BDeOR1ADizyJ3sKANuCX70LMy8xfI9G4C7H2pyubUlGYizIZ9lA1 8I2E2vWGzg2Nu/3FlV3PENJmL8KAM9fb3WMA1nndA+nm/RLtZkf456oBZrFV044EvEZs auAMIdAC6kDajjXgFXxOrUhSoKVG9gy7PTW7e70U2z/ADftOHqQQ1L3jsIItbuZOdQJM YIYRqk2Id+xp93Hj4MDPyHtwnYBh/xZwpEdanHtnCnPCJPWAWFroNasuMdGUv0rNpSN3 wUiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740059757; x=1740664557; 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=kZNDoru6BQKLt0+9h8+H9ivCYVfBH1Oosy/mEW5+620=; b=cn8M3iAZt10hkZ3dGy4hLSZ1USoe4DK97BxHsglXfJ5lVhECqOfyvdwj45D/hHBjPj 9GN2PmgKopB2a7D/Api89ihu5899PW6R4jxHjlaOxgH6VxfziK87+ibOTcQCzxUyhmn9 pagdtvzfL7DfEAd79T6YTBwX9VuNSUOp57ZxXkvrHPviCf3YglfRAV50TKX+letkVcAQ 7e/fftotgFUoi0wJAdp82vlQ6CskPDTvpkumBtj9BVtqPUhtxl30UpmVdvy+lHQOvoE2 3bzOJULOOebaK7VTktpFTg7ZAndtUFC71wbsPCygD5YZiuv2SmDHLWSzruz3m8SD9KaD hxdA== X-Forwarded-Encrypted: i=1; AJvYcCXqIgXNZ7jBul2r6KzDL/IGrHF1pd1F3j8trwv5BZcd5+/7oRiGrV21QGhRLDhPKYqo0B2dfLM=@lists.denx.de X-Gm-Message-State: AOJu0YxOe3pKT4R4i8tTeNgS0afjEBFWLRily3FlXFt2eL8yfiG2UoxR wrE982yg8yusRIXQCw4/9FA6AhYUmi5p4u0gsM/jGPA5cD8nfhkLJ0t6weyB0Wk= X-Gm-Gg: ASbGncs8mK4I+ZLzR3+qJIAIG/fgIt94pJ7WB7lTv8+qAEsAeSURMPv/OBEsM7mddZq 2OYDKn41cQlLQHvL6yQNX/qlNt2/ElSZJl7/i04C63i/Ratyu74cowvXYxjmelVIxZHcoGhcNZt Jr8kThDVN9GF9rOLQrFixNY0cXRcFOSGv788rOjx1sRhMG2ZPQwHUfzB6nr4ZcE4EdYgShPsZqx LGgany6RkTF90AIk548as5M0/2XsJGHIb/tZ22WQ7DXZuhaVPw77AC02lDVZPAHgsbS+WkXZ1vH oMW4OUiQJ3DCd4EqhVWCQnHAhMgEtkrf+79sZQLIk4CmIqqG2+Fl0iz0oTlVugOIFvURew== X-Received: by 2002:a05:600c:5246:b0:439:98fd:a4b6 with SMTP id 5b1f17b1804b1-439a30e6a0dmr30464965e9.15.1740059757255; Thu, 20 Feb 2025 05:55:57 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43987088ecbsm111659865e9.31.2025.02.20.05.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 05:55:56 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Caleb Connolly , Neil Armstrong , Sumit Garg , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Sughosh Ganu , Simon Glass , Jerome Forissier , Sam Protsenko , =?utf-8?q?Pierre-Cl=C3=A9ment_T?= =?utf-8?q?osi?= , Peng Fan , Richard Henderson , Sam Edwards , Peter Hoyes , Andre Przywara , Patrick Rudolph , Sam Day , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Alex Shumsky , Joshua Watt , Jagan Teki , Jiaxun Yang , Evgeny Bachinin , Michal Simek , Christian Marangi , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de, u-boot-qcom@groups.io Subject: [PATCH v2 4/6] arm64: mmu_change_region_attr() add an option not to break PTEs Date: Thu, 20 Feb 2025 15:54:41 +0200 Message-ID: <20250220135506.151894-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250220135506.151894-1-ilias.apalodimas@linaro.org> References: <20250220135506.151894-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 20 Feb 2025 22:01:46 +0100 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 The ARM ARM on section 8.17.1 describes the cases where break-before-make is required when changing live page tables. Since we can use this function to tweak block and page permssions, where BBM is not required add an extra argument to the function. While at it add a function description. Signed-off-by: Ilias Apalodimas --- arch/arm/cpu/armv8/cache_v8.c | 6 +++++- arch/arm/cpu/armv8/fsl-layerscape/cpu.c | 10 +++++----- arch/arm/include/asm/system.h | 11 ++++++++++- arch/arm/mach-snapdragon/board.c | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c index c4b3da4a8da7..670379e17b7a 100644 --- a/arch/arm/cpu/armv8/cache_v8.c +++ b/arch/arm/cpu/armv8/cache_v8.c @@ -972,11 +972,14 @@ void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size, * The procecess is break-before-make. The target region will be marked as * invalid during the process of changing. */ -void mmu_change_region_attr(phys_addr_t addr, size_t siz, u64 attrs) +void mmu_change_region_attr(phys_addr_t addr, size_t siz, u64 attrs, bool bbm) { int level; u64 r, size, start; + if (!bbm) + goto skip_break; + start = addr; size = siz; /* @@ -1001,6 +1004,7 @@ void mmu_change_region_attr(phys_addr_t addr, size_t siz, u64 attrs) gd->arch.tlb_addr + gd->arch.tlb_size); __asm_invalidate_tlb_all(); +skip_break: /* * Loop through the address range until we find a page granule that fits * our alignment constraints, then set it to the new cache attributes diff --git a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c index d2d3e346a36f..caf1dab05936 100644 --- a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c +++ b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c @@ -1573,7 +1573,7 @@ void update_early_mmu_table(void) PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS | - PTE_TYPE_VALID); + PTE_TYPE_VALID, true); } else { mmu_change_region_attr( CFG_SYS_SDRAM_BASE, @@ -1581,7 +1581,7 @@ void update_early_mmu_table(void) PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS | - PTE_TYPE_VALID); + PTE_TYPE_VALID, true); #ifdef CONFIG_SYS_DDR_BLOCK3_BASE #ifndef CONFIG_SYS_DDR_BLOCK2_SIZE #error "Missing CONFIG_SYS_DDR_BLOCK2_SIZE" @@ -1594,7 +1594,7 @@ void update_early_mmu_table(void) PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS | - PTE_TYPE_VALID); + PTE_TYPE_VALID, true); mmu_change_region_attr( CONFIG_SYS_DDR_BLOCK3_BASE, gd->ram_size - @@ -1603,7 +1603,7 @@ void update_early_mmu_table(void) PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS | - PTE_TYPE_VALID); + PTE_TYPE_VALID, true); } else #endif { @@ -1614,7 +1614,7 @@ void update_early_mmu_table(void) PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS | - PTE_TYPE_VALID); + PTE_TYPE_VALID, true); } } } diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h index 091082281c73..08e6e52cc673 100644 --- a/arch/arm/include/asm/system.h +++ b/arch/arm/include/asm/system.h @@ -303,7 +303,16 @@ void flush_l3_cache(void); * @emerg: Also map the region in the emergency table */ void mmu_map_region(phys_addr_t start, u64 size, bool emerg); -void mmu_change_region_attr(phys_addr_t start, size_t size, u64 attrs); + +/** + * mmu_change_region_attr() - change a mapped region attributes + * + * @start: Start address of the region + * @size: Size of the region + * @aatrs: New attributes + * @bbm: Perform a break-before-make on the page tables entries + */ +void mmu_change_region_attr(phys_addr_t start, size_t size, u64 attrs, bool bbm); /* * smc_call() - issue a secure monitor call diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c index 2ef936aab757..13f4e8e640ef 100644 --- a/arch/arm/mach-snapdragon/board.c +++ b/arch/arm/mach-snapdragon/board.c @@ -577,7 +577,7 @@ static void carve_out_reserved_memory(void) if (i == count || start + size < res[i].start - SZ_2M) { debug(" 0x%016llx - 0x%016llx: reserved\n", start, start + size); - mmu_change_region_attr(start, size, PTE_TYPE_FAULT); + mmu_change_region_attr(start, size, PTE_TYPE_FAULT, true); /* If this is the final region then quit here before we index * out of bounds... */ From patchwork Thu Feb 20 13:54:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 866792 Delivered-To: patch@linaro.org Received: by 2002:a5d:47cf:0:b0:38f:210b:807b with SMTP id o15csp60500wrc; Thu, 20 Feb 2025 13:02:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU17j/sbLxZTIuY07N1J4DwN/DACiEXv+H0dXVFC4cKaf51XjZWzXqtSPpQUwPKuxeXDJ0bHQ==@linaro.org X-Google-Smtp-Source: AGHT+IFNLHGmWqAQqIHf1oKxCTCVn+hpusz3ivNkKT+5TOCmrTbdPZuhoQeV2LjbazEa6oouLQg3 X-Received: by 2002:a5d:59ac:0:b0:38d:d8f7:8f75 with SMTP id ffacd0b85a97d-38f6160f9a0mr4310927f8f.17.1740085352714; Thu, 20 Feb 2025 13:02:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740085352; cv=none; d=google.com; s=arc-20240605; b=Z0S04iEhgxnTWBulC5vR7irt6e4GZ8QuN8Ig/JlHyemkmtGkyv+gvvHQSl9GQwNCME hMUousy+J3M+UVBA2BXvSU+NpcM93/nEcXmO0enlIQzhWhH3P8uqcW9pnQ1WjJzn8AKx sTckEYjkNoGsYjnobqJ4de3szfaqXWVEbq9V5Uz2lRrZuiI8QSHXZSxTCuqNsyLIs2Gn WergM6YAkr2aC6hYvJUGK1MDS/objpBHmqinW9UmLvudOLkqqivNCKi2itH1IUgwO6Xy Bl75ZE8SRNuOzMnLKdJcHsvrWRChNvLamznM4cAJDay2J0uaTDrRBilk/zEW8OP2Oo4h zoZw== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SE7LbKIfrrFvQvUE4Er+NhcZNjIniCA0xj7Zf/eun+Q=; fh=1FWcrBC5qj8ArpjcJznV92g3Y0PW7nRExoKLP3qTKVQ=; b=f4nbRh7h7iSDbcw/EMyregeJenHLqkkC+pPGk6YWg4KD6RYDhhw09+13oNKxWeq/Dz /I1mSR1a/ipQg5OQg66B5CLRNPcD6SArI2I4ck62FCHXmhfKSIgDBb3sXM/xQ8eRkb4u 5d5pBApw0k3OEjL8WLva0H16wLQaaCgN9S9Ugg1trZ21WtKcI6lTtf0W6f4yzdFx4Hwm gn7SgoFdDyfPDF+083nnowGisos46hAcf1mmPZNGAAfcSqtQ+MXQyRImV+CnNteG/kAW 4rjFnevasyKkewiB1f1owjCpcXdTeILnE9zayo/dOPXTtxv39Kk2WpUlmEMSm03i4wbX qr9Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="WP/iUUuh"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 5b1f17b1804b1-439a7ff8490si11719835e9.108.2025.02.20.13.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 13:02:32 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="WP/iUUuh"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 6006980FA4; Thu, 20 Feb 2025 22:01:49 +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="WP/iUUuh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A97BD80F5F; Thu, 20 Feb 2025 14:56:06 +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-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (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 619798001F for ; Thu, 20 Feb 2025 14:56:04 +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-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4398e839cd4so12510525e9.0 for ; Thu, 20 Feb 2025 05:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740059764; x=1740664564; darn=lists.denx.de; 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=SE7LbKIfrrFvQvUE4Er+NhcZNjIniCA0xj7Zf/eun+Q=; b=WP/iUUuhliUmLDrmhpGavvx6XfskQUTPWqLY7iQXT9CIW7L6HjAqLo/Pms+9qPtevO yRHWdsMUDde7rHdd9cd1KIR/kWSWgFM5nmF/BP7iQRoYtKN4I2LA+eRl2/MstsjXpvFv RTGHbQ/YfpX39v3ZVD+H3nM87bIDKC9GQTHR0BUxbIFxKPf0WkR4ibI7n+v3WV2pH6XJ Wea5PtjCgzhBxzVBpzXqiKfxQMqU8TNuN0+mwZxM7Wlbug1Et67jgghM7EkSZWItFnu+ FBn/snZqG8s7BoiuffQu251tQRXHQUKE0P8wHwgfVHIwj6MfwHDZ5YOm8Gpp4srQdQcQ V7HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740059764; x=1740664564; 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=SE7LbKIfrrFvQvUE4Er+NhcZNjIniCA0xj7Zf/eun+Q=; b=lesxXdW3tgZjUqDCC7MHEYC3pifVf7hKWJ5sBTSgsZHcof5Zs6EQozM2U9gHmTl4kK O9GHe0qkUZ5zqUVWGauFDHwizwi2X2YV/4tEP2Z8u6oUksAxbj3Xdnk5Agc7BfUKSelz aZZ4DuEWmgxsnnt2yNu7gc4SWpd/I5FOd6Zv1O6zKSgmGRN2pyRM4O13xnLHVAAoIX5d yy79QKbWDaMTwktfpUd59WqlF1UFvXCj4Gu/EKPI57LBpLzccdsZCLmZusXgruHLjmzn E3GRcvEmDuJ/0ewDLIn9/615u8aPPBtCkLUwcDt0Mo+MEddKbY70PaQcAeQR3AxJW3Nt 5sxQ== X-Forwarded-Encrypted: i=1; AJvYcCWvRP5foT8p2eWPpb2Nx9R2q1f7klttaeKhhfxWQt0fmQ5Qan/B2PkPXMYpYFpAFNn3SqwGpVY=@lists.denx.de X-Gm-Message-State: AOJu0YxYEeVBJz7mwAPneImYTkakKStCpDwLfhMJ9xNxq6Ag4twlN3Ui 0aRxGW/v+Y8eLyD5VyAlaSYXKgSzyzNC9dcQ70tfiwKu/haEzFnIL8U0r+JtQws= X-Gm-Gg: ASbGncucOd9Hcd5yX5NWJG5k3VjtsdRTTFwUfwZPN0zPaogNf6vs5SiXXlFwcTJJQNE tcbs+aat35BLjFqt7wfgZ1fUrpwfMIXiNdd8phDEdIzbDKZ6xO1PrVk0XkurpRG1KJ9d7m99WR4 qMWx9WzJGpewo9qf9byrssw3UqNsZKrGYTLmnvw1BBbJFL2C3z/ZXTx29b4yXzY/eVQqUmN7RRB DMQYNC9zmrHf+jegN82vuclh0qVBNl2/AAM/fIRAueuLGQtpDdGhjYWlbf2RwjyK5AcUeSYg+4+ V+JgcZ+o1fmmkCkZmCYnJMkWh/DIKbrpp5FPU78jWLvhFvsrWSwrdXHpzFkwYgD7xe+9GQ== X-Received: by 2002:a05:600c:6d87:b0:439:8a64:db3c with SMTP id 5b1f17b1804b1-439a2eb0ce6mr28695805e9.1.1740059763772; Thu, 20 Feb 2025 05:56:03 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43987088ecbsm111659865e9.31.2025.02.20.05.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 05:56:03 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Neil Armstrong , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Caleb Connolly , Sumit Garg , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Simon Glass , Sughosh Ganu , Jerome Forissier , Sam Protsenko , Peng Fan , Richard Henderson , Sam Edwards , Andre Przywara , Peter Hoyes , Patrick Rudolph , Sam Day , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Alex Shumsky , Jagan Teki , Jiaxun Yang , Joshua Watt , Evgeny Bachinin , Peter Robinson , Michal Simek , Christian Marangi , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de, u-boot-qcom@groups.io Subject: [PATCH v2 5/6] treewide: Add a function to change page permissions Date: Thu, 20 Feb 2025 15:54:42 +0200 Message-ID: <20250220135506.151894-6-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250220135506.151894-1-ilias.apalodimas@linaro.org> References: <20250220135506.151894-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 20 Feb 2025 22:01:46 +0100 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 For armv8 we are adding proper page permissions for the relocated U-Boot binary. Add a weak function that can be used across architectures to change the page permissions Tested-by: Neil Armstrong # on AML-S905X-CC Signed-off-by: Ilias Apalodimas --- arch/arc/lib/cache.c | 6 ++++++ arch/arm/cpu/arm926ejs/cache.c | 6 ++++++ arch/arm/cpu/armv7/cache_v7.c | 6 ++++++ arch/arm/cpu/armv7m/cache.c | 6 ++++++ arch/arm/cpu/armv8/cache_v8.c | 25 +++++++++++++++++++++++++ arch/arm/lib/cache.c | 6 ++++++ arch/m68k/lib/cache.c | 6 ++++++ arch/nios2/lib/cache.c | 6 ++++++ arch/powerpc/lib/cache.c | 6 ++++++ arch/riscv/lib/cache.c | 6 ++++++ arch/sh/cpu/sh4/cache.c | 6 ++++++ arch/xtensa/lib/cache.c | 6 ++++++ include/cpu_func.h | 17 +++++++++++++++++ 13 files changed, 108 insertions(+) diff --git a/arch/arc/lib/cache.c b/arch/arc/lib/cache.c index 5169fc627fa5..2f8b14f77b55 100644 --- a/arch/arc/lib/cache.c +++ b/arch/arc/lib/cache.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -819,3 +820,8 @@ void sync_n_cleanup_cache_all(void) __ic_entire_invalidate(); } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/arm/cpu/arm926ejs/cache.c b/arch/arm/cpu/arm926ejs/cache.c index 5b87a3af91b2..6051fd47c449 100644 --- a/arch/arm/cpu/arm926ejs/cache.c +++ b/arch/arm/cpu/arm926ejs/cache.c @@ -5,6 +5,7 @@ */ #include #include +#include #include #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) @@ -88,3 +89,8 @@ void enable_caches(void) dcache_enable(); #endif } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/arm/cpu/armv7/cache_v7.c b/arch/arm/cpu/armv7/cache_v7.c index d11420d2fdd0..937b32a7f136 100644 --- a/arch/arm/cpu/armv7/cache_v7.c +++ b/arch/arm/cpu/armv7/cache_v7.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -209,3 +210,8 @@ __weak void v7_outer_cache_flush_all(void) {} __weak void v7_outer_cache_inval_all(void) {} __weak void v7_outer_cache_flush_range(u32 start, u32 end) {} __weak void v7_outer_cache_inval_range(u32 start, u32 end) {} + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/arm/cpu/armv7m/cache.c b/arch/arm/cpu/armv7m/cache.c index b6d08b7aad73..b16a9c8f723b 100644 --- a/arch/arm/cpu/armv7m/cache.c +++ b/arch/arm/cpu/armv7m/cache.c @@ -11,6 +11,7 @@ #include #include #include +#include /* Cache maintenance operation registers */ @@ -370,3 +371,8 @@ void enable_caches(void) dcache_enable(); #endif } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c index 670379e17b7a..b6ea7efc7b75 100644 --- a/arch/arm/cpu/armv8/cache_v8.c +++ b/arch/arm/cpu/armv8/cache_v8.c @@ -14,6 +14,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -1028,6 +1029,30 @@ skip_break: __asm_invalidate_tlb_all(); } +int pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + u64 attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_INNER_SHARE | PTE_TYPE_VALID; + + switch (perm) { + case MMU_ATTR_RO: + attrs |= PTE_BLOCK_PXN | PTE_BLOCK_UXN | PTE_BLOCK_RO; + break; + case MMU_ATTR_RX: + attrs |= PTE_BLOCK_RO; + break; + case MMU_ATTR_RW: + attrs |= PTE_BLOCK_PXN | PTE_BLOCK_UXN; + break; + default: + log_err("Unknown attribute %llx\n", perm); + return -EINVAL; + } + + mmu_change_region_attr(addr, size, attrs, false); + + return 0; +} + #else /* !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ /* diff --git a/arch/arm/lib/cache.c b/arch/arm/lib/cache.c index 516754caeaf9..d4f1528b453d 100644 --- a/arch/arm/lib/cache.c +++ b/arch/arm/lib/cache.c @@ -10,6 +10,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -170,3 +171,8 @@ __weak int arm_reserve_mmu(void) return 0; } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/m68k/lib/cache.c b/arch/m68k/lib/cache.c index 370ad40f1423..fce852db2988 100644 --- a/arch/m68k/lib/cache.c +++ b/arch/m68k/lib/cache.c @@ -8,6 +8,7 @@ #include #include #include +#include volatile int *cf_icache_status = (int *)ICACHE_STATUS; volatile int *cf_dcache_status = (int *)DCACHE_STATUS; @@ -151,3 +152,8 @@ __weak void flush_dcache_range(unsigned long start, unsigned long stop) { /* An empty stub, real implementation should be in platform code */ } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/nios2/lib/cache.c b/arch/nios2/lib/cache.c index 8f543f2a2f26..70f258a1760b 100644 --- a/arch/nios2/lib/cache.c +++ b/arch/nios2/lib/cache.c @@ -8,6 +8,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -127,3 +128,8 @@ void dcache_disable(void) { flush_dcache_all(); } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/powerpc/lib/cache.c b/arch/powerpc/lib/cache.c index a9cd7b8d30ac..b434fbc4b4a5 100644 --- a/arch/powerpc/lib/cache.c +++ b/arch/powerpc/lib/cache.c @@ -8,6 +8,7 @@ #include #include #include +#include static ulong maybe_watchdog_reset(ulong flushed) { @@ -58,3 +59,8 @@ void invalidate_icache_all(void) { puts("No arch specific invalidate_icache_all available!\n"); } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/riscv/lib/cache.c b/arch/riscv/lib/cache.c index 71e4937ab542..d3ec9d460259 100644 --- a/arch/riscv/lib/cache.c +++ b/arch/riscv/lib/cache.c @@ -8,6 +8,7 @@ #include #include #include +#include #define CBO_INVAL(base) \ INSN_I(OPCODE_MISC_MEM, FUNC3(2), __RD(0), \ @@ -151,3 +152,8 @@ __weak void enable_caches(void) if (!zicbom_block_size) log_debug("Zicbom not initialized.\n"); } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/sh/cpu/sh4/cache.c b/arch/sh/cpu/sh4/cache.c index 99acc5999652..4e6751bfd2f5 100644 --- a/arch/sh/cpu/sh4/cache.c +++ b/arch/sh/cpu/sh4/cache.c @@ -11,6 +11,7 @@ #include #include #include +#include #define CACHE_VALID 1 #define CACHE_UPDATED 2 @@ -126,3 +127,8 @@ int dcache_status(void) { return 0; } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/arch/xtensa/lib/cache.c b/arch/xtensa/lib/cache.c index e6a7f6827fc2..17e1e21f28b9 100644 --- a/arch/xtensa/lib/cache.c +++ b/arch/xtensa/lib/cache.c @@ -6,6 +6,7 @@ #include #include +#include /* * We currently run always with caches enabled when running from memory. @@ -57,3 +58,8 @@ void invalidate_icache_all(void) { __invalidate_icache_all(); } + +int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) +{ + return -ENOSYS; +} diff --git a/include/cpu_func.h b/include/cpu_func.h index 7e81c4364a73..ed21bf71293f 100644 --- a/include/cpu_func.h +++ b/include/cpu_func.h @@ -69,6 +69,23 @@ void flush_dcache_range(unsigned long start, unsigned long stop); void invalidate_dcache_range(unsigned long start, unsigned long stop); void invalidate_dcache_all(void); void invalidate_icache_all(void); + +enum pgprot_attrs { + MMU_ATTR_RO, + MMU_ATTR_RX, + MMU_ATTR_RW, +}; + +/** pgprot_set_attrs() - Set page table permissions + * + * @addr: Physical address start + * @size: size of memory to change + * @perm: New permissions + * + * Return: 0 on success, error otherwise. + **/ +int pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm); + /** * noncached_init() - Initialize non-cached memory region * From patchwork Thu Feb 20 13:54:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 866793 Delivered-To: patch@linaro.org Received: by 2002:a5d:47cf:0:b0:38f:210b:807b with SMTP id o15csp60588wrc; Thu, 20 Feb 2025 13:02:42 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVZFKrGhg5MiC9pfsjWZwpzXq7XijkJH327s+ttQQuMVVnFAwDTYLWWEPkGRCw2pYOKu2Vn+w==@linaro.org X-Google-Smtp-Source: AGHT+IHiZRx+7LOb32aniser//3JqEBfUV1Y8Z8SjozcvvSnPXKSmDl6EIQHy2eU6KsoXCS0UI9l X-Received: by 2002:a05:600c:354c:b0:439:91dd:cfaf with SMTP id 5b1f17b1804b1-439ae1f2b3fmr6341025e9.18.1740085362238; Thu, 20 Feb 2025 13:02:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740085362; cv=none; d=google.com; s=arc-20240605; b=O2RFLl9XWyJHShSqggToLWLDTXdSAp66asCHFhutTW8ejkLe7ppCol1eHhnSF3xeO8 aLJFO6F21RJMdqlAIbJpMELFGGTns1wNFN+SzSEFNX5UonLwOHtKff46gMFs03nZ4g7H cuuYc/J2FO/8OZVrimdaV746swFXWt25UiNGcpOMGfVzoOXrzdt7xOGpHXqXSf8IsfxD JwA7DDDRUSi0dDLdy2mg8tyB5GGcuGCGwwD72FYy86fHCL0J82/UIv8kVV2gvavNHxTN i0wxSMDM52kBBqCgFKbIqb7LS1s/6k+617aBYMEV6rBVaX7n/lHn2EK+YIKa86fIDW0S SyJA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gDbbln0j0aifT9JntUADu1O4s2RC+5sjIApqn5zAwL8=; fh=nhab5L8gvDrY8QfesNmKhQp8OPzPPBeYNhyenTzT49Y=; b=gpxACotQt1D7IBNufFAkbvmwo6uCuRVav3aMZZqwDjHSllgYssxxofWtvpPPhSLbSf M6NGtXhRcnZBzQfv5BchIib1mcSdn3BfFuQqt2X6f2Ld1G+M8D7d7KiX31MoKEMuClZL YX4OqJuT0L6XcfHuSyI9oGEY3vemX9AG+0Fw9SzthqsWuhpkl1EzKc3dU/TEtbAwOLC6 zDljzzvd5JKssE7KwLgRVFfzepZWOZauax7drd1sCI36JHEUjB0namjZBn5IUNqY7rQt MuC8WUuXupQ60G7u1uY2Exw7cboEIHjNbQvttdLkUblCjPrTS7eMwhDG4Tl166VBV7pQ fZHA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PxCSpJ9H; 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 ffacd0b85a97d-38f259f7ff2si14918244f8f.538.2025.02.20.13.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 13:02:41 -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=PxCSpJ9H; 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 B16EF80FB1; Thu, 20 Feb 2025 22:01:49 +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="PxCSpJ9H"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 702BD80F5F; Thu, 20 Feb 2025 14:56:15 +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-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (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 191928001F for ; Thu, 20 Feb 2025 14:56:13 +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-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4398738217aso8338335e9.3 for ; Thu, 20 Feb 2025 05:56:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740059772; x=1740664572; darn=lists.denx.de; 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=gDbbln0j0aifT9JntUADu1O4s2RC+5sjIApqn5zAwL8=; b=PxCSpJ9Hd2JPTPEC1Y2k6S/R4Mjd2XS2SqhoyQqfiCoZPaQO3ZlmGB462v/LHD7I/x xtUhrbuoGh6k7IvBZqahVsszTUpQTO3pJ/x5mR/AtRp1F5MaNpeM6QMZMdzAHAl+HQX1 XBAgRG6oTDS919WbOJlEIYEF7bD4LPEUrgR9ptra/DTZjyT1fHqwbudq89K5guLqJlPb zo8gGgdE7qZb1PYqByka0tW09AW44v7L5Wkx+/NPMl73BAVpepWT9I3QyT4leqsEVOGu KJDUqoWJ31zmItFlls6aXOfaWShbZxo9ZNqEFbIsFkI3ckWhwSw6j27arF812zqrWJTG lfVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740059772; x=1740664572; 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=gDbbln0j0aifT9JntUADu1O4s2RC+5sjIApqn5zAwL8=; b=iRCGaqpv8z52tJCgnAbr5TRvuWNIelK1ZrdWoFGVcaXTSJufGbo7dydeJv1hEh9Qq8 9WItFloYU2v3/mRk0Y6mnif2oxo5V2+XgDIvYHcr3Wcr8XfvJG/bwdJGxIYvy3VelUNW t804iN1M3Frq4rukRH2kklONG9XQroeTzx6sJKPGKniSAdZbEfWA2mU0NZnoem8Au1Cd 3md9Ymunsjt0HXo3XtFfz6XmVxzgMLgM0S7/Ts5fyw9tV85nmyoI9DqQHScgNLvNmIRD cGtdr4SeYKqOkKwEkhXt+Nkn9Wj0SI89+6fJmsbqQjN7/wc7YmGUoICcdyhyHU/iVqyS rNLQ== X-Forwarded-Encrypted: i=1; AJvYcCXrF1JC+5+hrIqehVvDY/LhQAo/kAiKWnr130knjOpe5eXZ9KGqQBeB+jSK9+cfXgsv/XGluZU=@lists.denx.de X-Gm-Message-State: AOJu0Yz7Pmm6KypeN9ySJeihH3Hc5vapzBf0cHvSPE7E4K5Bj22OTWbj hy3BLifiJck2BmSZG/QBNB1HFqsVNawx4UhfpoJJN7BAU2NRs2L1l4ELrrGmvc8= X-Gm-Gg: ASbGncsWOZPg64e/3KALUl7Wy10CoDKZdHqAVSw8pONFdEa1vyTgBJtfVY1OEy0WHjM s2pDDoE6/4gSjHM1BJrROuS8JuyVIwsrQznzZgJUa4lqi1YCSR5pxlQp7HR7t+3VnrExtLAJn1F bTR2izuJGFmTNtO27qj9qGbzP93YHXcqGKLLNkO82OGAiIY006V8N8jS7lFmFJTe5GWPB4lEytR Wo0UoTbaAJV9SRfpvuuQBwbOFAzTkikZzNwO+fcU3jsNMhBG+0JPtlrMrF23ddk8vS5zeEbSMsi pCa9djSzOXS5xS6p9cwWzkH5cCzRqU7xCFgvX1l/J6MH2SK9a7o0XyHrI6sDw4cHBVXEVg== X-Received: by 2002:a05:600c:19ce:b0:439:331b:e34f with SMTP id 5b1f17b1804b1-43999da3cffmr70659735e9.17.1740059770856; Thu, 20 Feb 2025 05:56:10 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43987088ecbsm111659865e9.31.2025.02.20.05.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 05:56:10 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Jerome Forissier , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Caleb Connolly , Neil Armstrong , Sumit Garg , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Simon Glass , Sughosh Ganu , =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= , Sam Protsenko , Peng Fan , Richard Henderson , Sam Edwards , Peter Hoyes , Andre Przywara , Patrick Rudolph , Sam Day , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Alex Shumsky , Jagan Teki , Joshua Watt , Jiaxun Yang , Evgeny Bachinin , Peter Robinson , Christian Marangi , Michal Simek , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de, u-boot-qcom@groups.io Subject: [PATCH v2 6/6] arm64: Enable RW, RX and RO mappings for the relocated binary Date: Thu, 20 Feb 2025 15:54:43 +0200 Message-ID: <20250220135506.151894-7-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250220135506.151894-1-ilias.apalodimas@linaro.org> References: <20250220135506.151894-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 20 Feb 2025 22:01:46 +0100 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 Now that we have everything in place switch the page permissions for .rodata, .text and .data just after we relocate everything in top of the RAM. Unfortunately we can't enable this by default, since we have examples of U-Boot crashing due to invalid access. This usually happens because code defines const variables that it later writes. So hide it behind a Kconfig option until we sort it out. It's worth noting that EFI runtime services are not covered by this patch on purpose. Since the OS can call SetVirtualAddressMap which can relocate runtime services, we need to set them to RX initially but remap them as RWX right before ExitBootServices. Link: https://lore.kernel.org/u-boot/20250129-rockchip-pinctrl-const-v1-0-450ccdadfa7e@cherry.de/ Link: https://lore.kernel.org/u-boot/20250130133646.2177194-1-andre.przywara@arm.com/ Reviewed-by: Jerome Forissier Signed-off-by: Ilias Apalodimas Reviewed-by: Richard Henderson --- common/Kconfig | 13 +++++++++++++ common/board_r.c | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/common/Kconfig b/common/Kconfig index 7685914fa6fd..d23e845ee471 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -914,6 +914,19 @@ config STACKPROTECTOR Enable stack smash detection through compiler's stack-protector canary logic +config MMU_PGPROT + bool "Enable RO, RW and RX mappings" + help + U-Boot maps all pages as RWX. If selected pages will + be marked as RO(.rodata), RX(.text), RW(.data) right after + we relocate. Since code sections needs to be page aligned + the final binary size will increase. The mappings can be dumped + using the 'meminfo' command. + + Enabling this feature can expose bugs in U-Boot where we have + code that violates read-only permissions for example. Use this + feature with caution. + config SPL_STACKPROTECTOR bool "Stack Protector buffer overflow detection for SPL" depends on STACKPROTECTOR && SPL diff --git a/common/board_r.c b/common/board_r.c index 179259b00de8..65111e2fc97a 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -170,7 +170,27 @@ static int initr_reloc_global_data(void) efi_save_gd(); efi_runtime_relocate(gd->relocaddr, NULL); + #endif + /* + * We are done with all relocations change the permissions of the binary + * NOTE: __start_rodata etc are defined in arm64 linker scripts and + * sections.h. If you want to add support for your platform you need to + * add the symbols on your linker script, otherwise they will point to + * random addresses. + * + */ + if (IS_ENABLED(CONFIG_MMU_PGPROT)) { + pgprot_set_attrs((phys_addr_t)(uintptr_t)(__start_rodata), + (size_t)(uintptr_t)(__end_rodata - __start_rodata), + MMU_ATTR_RO); + pgprot_set_attrs((phys_addr_t)(uintptr_t)(__start_data), + (size_t)(uintptr_t)(__end_data - __start_data), + MMU_ATTR_RW); + pgprot_set_attrs((phys_addr_t)(uintptr_t)(__text_start), + (size_t)(uintptr_t)(__text_end - __text_start), + MMU_ATTR_RX); + } return 0; }