From patchwork Thu Feb 27 12:14:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 868960 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp247034wrz; Thu, 27 Feb 2025 04:57:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUAB8tanbGE7bJvoVFTdcGOiqc3ARmwTErsCYiv3qDlB8X7ZxfFIgka2mUpnhMtUpBBIrfVBw==@linaro.org X-Google-Smtp-Source: AGHT+IGhVhijt2gaazI7Gg0FqxhzwONJf5yyGzJgX3yLBNoLhnYWk7yB4+ljpYN45yB0mEQWmP7/ X-Received: by 2002:a17:906:2191:b0:aa6:8cbc:8d15 with SMTP id a640c23a62f3a-abeeedc8786mr593122366b.14.1740661042256; Thu, 27 Feb 2025 04:57:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740661042; cv=none; d=google.com; s=arc-20240605; b=HCZG78OQBuNGicBuWdluhRxIcUy1KCk4UUqLQgO+EGD4hzWRf6c3u0qMHasT2sx+pZ FI2w2HjLd+I3GAzZ9VlkY3VrioxVIecwhdaUX8qv6EZrUPqq7djpLKPEBLBvl1giyvis uIBbXgxYQKjeGeeMfedVcumPkfonrDXheAq2EAOF7wnDGQTrnw6WIfqenm7gWm3cpBzH 1/gO2hdPkrP3Rw7CxaeVm85/jpthpFj+xzystq980w64Dn4UlsQsEGQPZe71fl4CNT+a jx1K/1VgdXOEDHZv3DHbRVMo8BV4yOtcUyvR9s+ZKioB7koPtRQjs0YwjF7zYwMld3E2 f2TA== 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=eHExA8wiP9H2dxOaeZUpcFRywZHVEwmpX2hHwvdeB/w=; b=aZxLItFDPyDHGj1qYBgjNoMDW4PAWS0Gubl4I/KrpAOwde0fmTZOCyZ4cIJdX0VUXh tIUktRfPPRphckfIZkH71h+hp/9LtexoMzc7m0Czh5VWHqz5ACarliYt0oTctEUJYzZJ 90jSPLM7rC7uJrdH2Vj2gbv7YZsoeu/rWCOMWkhEOVPrrF/XpjVBNhUiCFoP/j2I37BH 2foTIzaKyIEKKxNpISPAJX7m8cVYyVwQmQVXGa208562bNku6Yxb9lp4LyOGZ5oBlffJ PoAWwRYJ9DrIHUiCpti4v+cSPV/7dkfMniT3Q6/qPGsSrV/vwQEoCJzjFfUN+GEZfO7A ortA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="wT39py/t"; 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 a640c23a62f3a-abf0c71378esi154914566b.271.2025.02.27.04.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:57:22 -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="wT39py/t"; 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 4DE4181101; Thu, 27 Feb 2025 13:56: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=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="wT39py/t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 63317801FB; Thu, 27 Feb 2025 13:15:36 +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-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) (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 463A280FF4 for ; Thu, 27 Feb 2025 13:15:34 +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-ej1-x636.google.com with SMTP id a640c23a62f3a-abee54ae370so126055266b.3 for ; Thu, 27 Feb 2025 04:15:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740658534; x=1741263334; 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=wT39py/t+/uNs8VFo59cpc2OHimfNTxSnYR+M8KD3bP89VyBp+qolZLzPPumWlAkxI c0ZFg/gURq0APO3j8O1aXE+qoWtCOxdq5EsAdAvxsKIkJr4mzQ5GpUiqE/ckAILDlbVc 4OIL8WXm3yiZ36/4d2IYo/IoIdbFWwwfznyuvaZxrKWfOlKTkTir8UflYxU9or8G2V7+ ZO3Epyt3oa90fzeSLo/tyz+8pPmxHBqIA6CyeGIiF8xb04IvNtDYaxugcmG4d3BnMYsg SfSmBEP5F3M3X6dLb4kIueq5vwL+MEutuaAHToSVN9QudR09t1svyErXeKiRpYj4Xyrc xSyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740658534; x=1741263334; 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=Cg4USRkIxfWNM5axM8H7wdY1CLBy8kjn3vWjrwDbkhmQmzMBSWKDKRm9a8Asp0nggV FJ8RocK+tiqQy0AqXbboOfQLNNyC5JQnfhUq40Ykik/SxIq0N4lm25+Vvad2X6PLbAcm w7G4Vzo8XzMtQJOfMoUPhLbU4/6yKeL+Yj7CM2r0xsav7r5ncjKBO9pSti02LJXtM24C 1txPcf41XBGBGsQT6ajS2DsWdw81gLPcsEMdB3LOGqnYm+aAXHIOjzKogS73nNt7i+Zl Q1dqlER5XQEj29ffWJBmiNQ7iIoQsgAX+FgHnovqwM8aOLetm3UfvSL3JYXg6rU7v7Tt WKpA== X-Forwarded-Encrypted: i=1; AJvYcCUtpvkZF659wNXv/Rda6GGtwEkg825KvjLotuDrnRDJ9AuixeFb1e+2GnAtMDhWgK/JTaeWtec=@lists.denx.de X-Gm-Message-State: AOJu0Yw8Ac6XJFdsvAVs6tg8p60/2GK6m1QI466Fewk7R51O6dbHQ0Zu UMVjEAobXd1Hn51nff5YjwDzPVFTPzoHFrL33A3lXexFLgCQiT4j1qY6ZK8iGf4= X-Gm-Gg: ASbGncvdl/ymhvLtKjMX6OZIznqigBmC842KXWaYypqUooPLsbdQoYOnD2UPILFtR99 0yaDCicBkDLM3BM0r5J/Bp/i3MRUbioetp+gL+RcN5MT+3hCsMGLjjpecDxdpF+YbjabNy2LNbj 1Iu759N9sRnWlp/koIQnUnSFNyBr+OOJK2N8x0Xo0P2oY91U0xNzveiWQIfxhLQBOumSktpHiRK tN8gYUbaYlUu6VxmM2lX3bJdo9LSwjnabLEHwha3hWyRbSLqMhO69vmvLg/a4Q/8hZ7Kfr4DWIF RpBs+FwChUK4slGlmYyyGO8MwDPEzQYWLISfOzYxfigxnymEZCSEVSjrnAQV0oOoEeI19f4RAuN CTr0+ X-Received: by 2002:a17:906:1daa:b0:abe:ebe2:6748 with SMTP id a640c23a62f3a-abeeef649f8mr830652766b.38.1740658533599; Thu, 27 Feb 2025 04:15:33 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc168sm114736566b.70.2025.02.27.04.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:15:33 -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 , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Sughosh Ganu , Simon Glass , =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= , Neil Armstrong , Sam Protsenko , Richard Henderson , Sam Edwards , Andre Przywara , Peter Hoyes , Patrick Rudolph , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Harrison Mutai , Alex Shumsky , Jagan Teki , Raymond Mao , Jiaxun Yang , Evgeny Bachinin , Rasmus Villemoes , Christian Marangi , Michal Simek , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de Subject: [PATCH v3 1/6] meminfo: add memory details for armv8 Date: Thu, 27 Feb 2025 14:14:51 +0200 Message-ID: <20250227121515.232996-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250227121515.232996-1-ilias.apalodimas@linaro.org> References: <20250227121515.232996-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 27 Feb 2025 13:56:54 +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 27 12:14:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 868961 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp247082wrz; Thu, 27 Feb 2025 04:57:31 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXKulgpLe/UoypaNHlDsx0wm1ch/qAIHuvxXrrZ/P2vl8QP1nZHAoOcETVFTmPNJJJ8C9sj5A==@linaro.org X-Google-Smtp-Source: AGHT+IFra7rgWiD9HENFrKFdJo4l59lvAHMsB75DqvoH6AX5zo4eH+dLTR/ma0jqHLUBRprP1XMH X-Received: by 2002:a05:6000:1a8a:b0:38d:d0ca:fbd5 with SMTP id ffacd0b85a97d-390cc605518mr8443667f8f.22.1740661050911; Thu, 27 Feb 2025 04:57:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740661050; cv=none; d=google.com; s=arc-20240605; b=SL21xbWbK6/jrJowNMcQE/Q10MXuN8baVyfHkui23f0brXXTpOLioiTZmRNhP9uC+7 60jXb0Ujc7UeCFY8XGrh+7X7TDzEwDhBkjnX/tt5WgQEeENuPQgpy6/Z25cIZ5US0l9s 3iLECr5AmNCy3ZGwAJT1zRspWN0fJu6jHCrjQRmcEmIUhD+vFvZZeWklDfFfkLlNtpj2 TDGcLoO1272Vr9GWjU0dDuxL361BZEXW6St4o/PqO6W5WboF0/GWtl41iG5S7HA72zgp prIq/GsjBSYytdw5Eq9tC56JZPZdJoZhVz6r6PC5FgqerS7B+EFbv07sJMXDv7HraWTy biNQ== 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=DvQRhZA03z48s4Knz5v/YKBpV8179HNjVmTN8wpLy3E=; b=VbZbSLujo5IBJxfdsilKvXFFcP2T8NIhFz335l2j71KHwc9MHNLL3QSFICikSceWK1 2HUamreO5oyYisi9+PuO7lYOvWR6De33KgEgSl0M66TewqGqayxBpbzbtrphBVewOB6z VPt9/3c+BW0CW3cKErH6ocThr3e5n+2kf4TQidbmHZcZN142s+0dpCVVmgolsXOsUx74 VN0nJ4p2WADMYp1fhmuWIih7C/4u8Y4JoAKWSLzmdm5ePlzCN8K4QUWxfazN5TswzpOn L70H+8eO5H4+ttO4ljFVebGyEdV7lp2+iNMJS5ZXjGbDbBbFa5acnQBA1vjboDfosgiL 6Wzg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hhevTgc0; 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-390e47ab0acsi960725f8f.198.2025.02.27.04.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:57:30 -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=hhevTgc0; 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 9568D81112; Thu, 27 Feb 2025 13:56: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=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="hhevTgc0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 78C57810EA; Thu, 27 Feb 2025 13:15:42 +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-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) (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 1308C801FB for ; Thu, 27 Feb 2025 13:15:40 +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-ej1-x633.google.com with SMTP id a640c23a62f3a-abbd96bef64so150401466b.3 for ; Thu, 27 Feb 2025 04:15:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740658539; x=1741263339; 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=hhevTgc0U9Fofcod5UW1LIzpmGpC3zOsphO3Vmmd/NgMqGWgFXk8Xz23egpapi/gmh xeZPodP/W8vMA3uLe0NwCKACT4366zOuXwqtIn4op5OWdLY/rzQipvEIaERsMbU3UG5+ EIiokrNtSlE0pgTZHzNCuegtzYR/RZ3LHiBiGKMd8rFW7twcJYaA7uh3wUoUmTg+r80Z ewLJzSIBL69tz0qwTbwg9Wt0oBxuLcHhi1SeBsDqgywFbTNukLXK0+t+yzZOMDulhsDb dLpPKzypc8TERyV5gInpxIap6xAqOY0OCGhQM1HVtz5Fjx4L+oiVGITIEs4FM3NoorER 75kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740658539; x=1741263339; 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=dBN5gC7yPrSA83RqMomZigGF3NHdB0aMA+9JFMlqYr4z/k1UWFTaD6jG1rSwKwnoQ3 nakqgwj2mU/ZCa35Z/YaD2lsmu8leMWCh7+eY1E3huJY0SHuaWbZUJlB1XUMTiJhb6Ba nNuGmF7bbRBTCJgJb9VuKOlp5GQkQlhVcTeleak92Bu3VaHJJmuEh+ZxUd0GhypUCb/B lxfzY4fH2LurKziCmtR5G8BqdPNeczTroe8leZ35g8V7HH9GZDgNoVxCzs7iQNmUD6D6 BJqrajpMELtNOb+kn+XcQ5UwruoQH59bPKMLzrlGrHIVRhypsQNwcWnDB9E0Dr6RfA6z CdhA== X-Forwarded-Encrypted: i=1; AJvYcCU9qC1ghsZvtluc0FO768a2nncUhWhl0VhxMk1i5OgRUgcZf/ivKsGa5iHpNHzpuXBmxh8EXUw=@lists.denx.de X-Gm-Message-State: AOJu0Yz6PxiTzefy2ESiM8QdUlHM7HIMkQPKGfptb3J8tZdp0dx/GwfG Px7tD04xdGEHFUx7NBtPSVcNfW9mY6Nakw7wkMuEZXUp2DbRX19ySA01aHdB+c8= X-Gm-Gg: ASbGnctjyJ+mGHYKF2h8dTWhhISZeYURCrXM2AenbeajxopkCkdEW+qM4840zEPTV+y MqDVYbIhTYD1BRlp4E+3+M4NsxqfPdHuwXg8s66TXZMRsBSi1h8Kx8KpWOGSBNd0wYNsKX1l3zU rsV/bcWKmbVXJQYZvLG1G+945JR8/PW4VYFh1w/leS9YieA2gTcawXMTB/fnhYFic14gzvcRNCM QHKGfNqrh0ract/QJ96zTwtxDjosS/fvt/eMWLKhihSAH3onIwQSKRum2LRoSmiZ8HKSI3ry65O 1jxWo5ksK8SMy4HL8ZRbIHKO1gM/XB/rg8fRGn1kQOLP1hov5LXRQtGb3DwZQ5y58geo5dLga5d G5jdA X-Received: by 2002:a17:907:1ca0:b0:aba:6385:b46d with SMTP id a640c23a62f3a-abed1079d36mr1479598766b.50.1740658539282; Thu, 27 Feb 2025 04:15:39 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc168sm114736566b.70.2025.02.27.04.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:15:38 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Simon Glass , Sughosh Ganu , Caleb Connolly , Marc Zyngier , Neil Armstrong , =?utf-8?q?Pierre-Cl=C3=A9ment_T?= =?utf-8?q?osi?= , Sam Protsenko , Richard Henderson , Sam Edwards , Jerome Forissier , Peter Hoyes , Andre Przywara , Patrick Rudolph , Mayuresh Chitale , Mattijs Korpershoek , Harrison Mutai , Joshua Watt , Raymond Mao , Jiaxun Yang , Evgeny Bachinin , Christian Marangi , Michal Simek , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de Subject: [PATCH v3 2/6] doc: update meminfo with arch specific information Date: Thu, 27 Feb 2025 14:14:52 +0200 Message-ID: <20250227121515.232996-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250227121515.232996-1-ilias.apalodimas@linaro.org> References: <20250227121515.232996-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 27 Feb 2025 13:56:54 +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 27 12:14:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 868962 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp247150wrz; Thu, 27 Feb 2025 04:57:40 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWu0//I0SFLsu/endT8JjHiiU5UR4n9rOK0X0ai5tb2uuNWrgAEU6mzy9UPQ5a8/jRFNMq0DA==@linaro.org X-Google-Smtp-Source: AGHT+IFzbujc6exkVWbTexJbj8SjlQ+f8zQWKOU+YysyrNij/0Xt3/rX+4+FHF1kC3k6PJ6K/jyr X-Received: by 2002:a5d:6d07:0:b0:38f:3f65:2ea3 with SMTP id ffacd0b85a97d-390cc602127mr8265878f8f.17.1740661060084; Thu, 27 Feb 2025 04:57:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740661060; cv=none; d=google.com; s=arc-20240605; b=aQpYJqU14jkMGDFLuwJGM3SMcgpYNf/ltjw2nj6XlGLz/dZkhfiLnytLkuNpjO5KW/ nF3Agf7e4764YC1MW6F02MsYs0CkDxAZtyHir/cHbpVvN9R/NZ0wHF+f729kfbgUahst uqZk//ghy2Wj+jDiRmU7OlEsaUO+ZFHUOl7pAETe2N2GmOK472/or3ml3XFi+MsBvoNC pITx/zkI4QWpfBTODvngITPshRZyVH9y/otEx5ZxoTtK4jY2IUV99hoXkPl+In+5MF7w PJt+rBcF7WvhsfHocz0MUnf+ChztxHMdxmZZoVc+jZpsk+FvBFN/ndi6bc73ioMBQKG5 HVbw== 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=5qSeBQm8rIiofeh7plKeu/pk/Zyacx6XzEy5fwctVGo=; fh=kkXx8zhK7uZMdTX03n+IWXECBgmzC7X3Q5ZcQhxoAPE=; b=COb6FJQmLnDn/XktZIYIGzcq5/edWGjMAFOp7pRBDf3JzSqZv+lwMkl2bFs6HTo7an eOdBPdfiC1dodxDM5hukpk7rZckbtncAVQ1J3kbrdnlNJGgpi1eD9k4AFv3a/Nsw6zFN ksim0LBG9hTEEzYb/7YDIHGO7TNZk6IweM1VOlSReVzCYl16piRT+a1FOoqjWEimPPg1 5XZk8G9doR+ukO/3TuW3T2SPLKSmyTthJdsHzcH8AUoMNYq6E8R1X2gOmGFucslzh8yx r0eUHq6pIAbcmxAzy6IfXTf8gmLlrgDk7K4pVHzVHCwAIh2R9J/Ii3YEozExdm7nWpQa AWvg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vz3RmQBY; 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-43b7a267f9bsi10593375e9.126.2025.02.27.04.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:57:40 -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=Vz3RmQBY; 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 DFBA881120; Thu, 27 Feb 2025 13:56: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=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="Vz3RmQBY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E51F7810EA; Thu, 27 Feb 2025 13:15: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-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (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 C6EC1801FB for ; Thu, 27 Feb 2025 13:15:45 +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-ej1-x62f.google.com with SMTP id a640c23a62f3a-abb7f539c35so158230066b.1 for ; Thu, 27 Feb 2025 04:15:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740658545; x=1741263345; 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=5qSeBQm8rIiofeh7plKeu/pk/Zyacx6XzEy5fwctVGo=; b=Vz3RmQBYTILp8QCodnkZCARKpp2BzjCMAridH7xaWiO4X9fZ2sTJuxtfzvgsEXYN+H ic8pYB8SYmx34x3oin9kufKuRNybxcXbbgfdom+Q4iSgcrSjALyKASydqRxIi99HG16X jJa3u93gczFfmJ1jZNr4j1gfamztcAiMQ9bU9wecXQVomnVwqa4ZZd2bDzJh6pydZaUb h4MPQFTFvrOxEyxKeaFMKFbZziPq3p/7V/nCq9GEWNrL3lFQwqIKmNmAGrjeptadim/Y EkTbCbYBB41CQvjETdBk6OfmEkz3/R73PLQQzw3648IwUjstM6lCgz1fPhGLsHS/tZSA kBEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740658545; x=1741263345; 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=5qSeBQm8rIiofeh7plKeu/pk/Zyacx6XzEy5fwctVGo=; b=lSPmGaAJJuR/gGXhcYVR+/Z2FHch3oxui5pQOEKT3Did4F2+PVzHazYchFLmt0e113 /R/0r9iRetbIy6khmy315HymH6xHn4Z1ZJPzoxZU4QEPzXNAglPTvsz7y/JLFt+LXFHD 1T6CqWjIzWCh7i3aoQYDv6YeZ2hPT1iEiOPXITxkwITSYCFMUa5FSLcrc8il4tLo231X JGZG4zohgPmIZaJYfruWlA51fd3Lt3B9+7zYS3GKyi7OzVgWkTDWe4kwaT/VJxAb5Ivh yvlR33cSLqFxbV1MtFpUv+vgBw4Vz83hScW+ySoWUFtit+SfokZHuZRelREAUhW71/Pu PhmA== X-Forwarded-Encrypted: i=1; AJvYcCWhydjJpMJ8bycYz4u81e9/xyi637ah2OtvVdX0tviIhTC5cG9p5Nih9Jyi2ayqaFCyQJmuxuM=@lists.denx.de X-Gm-Message-State: AOJu0Yx0iW8NHx1oYEw8cKut9JLtaChxeMNB2bB9r1K+4PX8LDJOr4qa sl5bwhm75a8HW22dq+UsS2fB/nlIuSx5H4kkr6VBrcKJwhrCn0cJDQjGFomJc78= X-Gm-Gg: ASbGncteL6yHanPBzMOkx1YRXHfiP3oaowf01qRd6tlqLgbe3w6Af4tyburJ8XRitMB jlKRcULDe9zIw1BX14/2ZpGM39i+JxKRXD6ng8y2F3QJqw9rzfpuBbnrzO5aDfQU2lQNREqwRFC c9dSokKV5R2OKwBL35Tro5TsLdz7d5/3a4IwO4IxQ8/brjc4E0riUs4NZJ31kiNbtCna6hZl86r YNbl3kP0UoqiAPqkjYhmQ7aE5XnNQL3mXfgqutOT54Dx77PslftQipd5t3D53KRLKteiZWTRDdg wr+zXw9oUhuj63eoF3Rv/KIaa6N+mFXqzCtd5/+WhDKnZdiEOToeh0mjkYqeLgbtEwZB2EbmnHR yOga/ X-Received: by 2002:a17:906:31c6:b0:aba:7a3a:e267 with SMTP id a640c23a62f3a-abed101d92fmr1207034366b.45.1740658545038; Thu, 27 Feb 2025 04:15:45 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc168sm114736566b.70.2025.02.27.04.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:15:44 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Jerome Forissier , Neil Armstrong , Richard Henderson , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Simon Glass , Sughosh Ganu , Caleb Connolly , Marc Zyngier , Sam Protsenko , =?utf-8?q?Pierre-Cl=C3=A9ment_T?= =?utf-8?q?osi?= , Sam Edwards , Peter Hoyes , Andre Przywara , Patrick Rudolph , Mayuresh Chitale , Mattijs Korpershoek , Harrison Mutai , Alex Shumsky , Joshua Watt , Raymond Mao , Jagan Teki , Evgeny Bachinin , Peter Robinson , Christian Marangi , Michal Simek , Rasmus Villemoes , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de Subject: [PATCH v3 3/6] arm: Prepare linker scripts for memory permissions Date: Thu, 27 Feb 2025 14:14:53 +0200 Message-ID: <20250227121515.232996-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250227121515.232996-1-ilias.apalodimas@linaro.org> References: <20250227121515.232996-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 27 Feb 2025 13:56:54 +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 Reviewed-by: Richard Henderson Signed-off-by: Ilias Apalodimas --- 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 27 12:14:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 868963 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp247204wrz; Thu, 27 Feb 2025 04:57:49 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVjmFJS7bpIZC5TQncMNi176aZD7oYp7jdrjhGzUT3g0OTkzeCuQc1U7V80lPSvtrKusbEJaQ==@linaro.org X-Google-Smtp-Source: AGHT+IFEFeLQmsrC4TBGDn1/66LidVgWxxq7+Rjr/Sll19/EsASs7Ngv5cGM5NS30FHyWGlCLHLl X-Received: by 2002:a17:907:3f8f:b0:abe:ee4f:f635 with SMTP id a640c23a62f3a-abeee50aae2mr911976666b.39.1740661069441; Thu, 27 Feb 2025 04:57:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740661069; cv=none; d=google.com; s=arc-20240605; b=HXy66GC/kV4Ku7Rl/g+J9qUxzh9X6nY/3529CHlIOkWT26o0wgA/rys7iJ+V8BmTf7 eHoYRZI0EiJq+azj5wH7xUZ/2jrDNbZ4CsxT4QU6rkOSZ9UlM4TEi/aMUrGuiKdUAdmp 0sO83Rq1BQQ4DBVtn/yogCMSM+CDsVqG0mm5Gi+SOnNWYebrVZn3GtcHxGHdMPk4Lvp/ CQKRhueRxpZ+Mt+YeiKSCAb8Cg8RSjXr1xHrfxFYbSx2BWwTK81ItR3kRyw1ECC8pDP3 XGc/1OGVOkfjORGPYeBxIU5cyRfUvcQmEjXxMHWVOe2XvguLKtNA06tevVZ3Fyo6yGU6 EXOA== 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=6JyPI1S6xBDKgWp6CFwNc+WJrzcMVyQFEDE89E/GLJY=; fh=jKiCqOgxKydo4P2vfQOluUivWuk/oTThzwfiCbmn6gs=; b=ZRRmXL9J9AgX4Ku5UJ7EbA0DiuxNyxrEockN/VZQD1NC5+LNPKY9jfP1ZNbqMRTKCI let5zDC3db2FpbTh2haUndRDxCYUhEaSVupEC5MmIMO9iH0Xbd9g3BdfVE7XGVoJR/Of z1ouSBb2eODfD4usRXpW4D6Ip9/zyxhiL0RmZ8xMFpHFetAJSDIvzFe8U8ng0nSFTEFN VUJEohOwrAKFkCoV6fXqxIxU7hI2y0Oo5oSPgKhD8WGUgXbrVT4logsUwu8GtLO6jwJs JXBZvRnDgjanwAqe+oiB3BtRvYEgzd7EcWCYbcxRvYGq6o4r8WHldmgXaqQxDoiLO4U6 w2cw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DAPIlLj8; 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 a640c23a62f3a-abf0c8605fcsi151589366b.806.2025.02.27.04.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:57:49 -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=DAPIlLj8; 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 30F43811A7; Thu, 27 Feb 2025 13:56:58 +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="DAPIlLj8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 33ECF801FB; Thu, 27 Feb 2025 13:15: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-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (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 29D86810EA for ; Thu, 27 Feb 2025 13:15: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-ej1-x62a.google.com with SMTP id a640c23a62f3a-aaeec07b705so122818966b.2 for ; Thu, 27 Feb 2025 04:15:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740658550; x=1741263350; 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=6JyPI1S6xBDKgWp6CFwNc+WJrzcMVyQFEDE89E/GLJY=; b=DAPIlLj8bPRVvNUDT2XH+7hSncIQzsEB5+i0QLBZWgOnVpSNaVfsO3cOI6LajlDB0X YW56UbLVWyTgWodlx9WuGQgwGVXq2n4FmoPsMqPpO2rVhXYf4+reZc9Qkj5ytkTGgwil T4uanojCEPIgmvTedIA/iNIck+i+x+kQoVoNyvWBbuuhe9H2Kz9LHmudQNvMeEnEXwuw Wx7PB3Fjxgrd+pNZA8DQbkbU+df7vJMVKXeNW5e8Sz2tntP7BeKm9EiUFOPOH9fKBBUx y1DNODGqsydrh3qoczTyFimHNebu5J14vFQhP/oLBhYD5ClMwyoFRtAkn8E5swpXffrG GMvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740658550; x=1741263350; 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=6JyPI1S6xBDKgWp6CFwNc+WJrzcMVyQFEDE89E/GLJY=; b=e4+zA708ee1K0fjRn+t/0Am5iA4m5luxuE55nvrjp2To7e5//Tf3oJowHy6QCyhhm/ q/W8vhZc7BXLmCFWMRT137nUqMsxuN3qxnPl3+W26wSn0zikU8DiP7Te2NtWDmMSGJkh CL3vrYaqcuPUnuRfdUu1ND7sny4gkZm2WWB21vqnClno8AeCGK78ZqOmEpO/MU91ZRk4 UGE1yIIcBeHINg7AHpX2lWDNmtqMM6US8Xdx8yCCEflyTIgLlG3w3BpRVxELZF/0YbCE t+5lchRRUkzmEGpmjZpsB8lX5reKNhOJjhM8wBjrnjR4g8l6grx3Dxbx6Qz5EKyUtkf7 FyOw== X-Forwarded-Encrypted: i=1; AJvYcCXU1fQJkbwyq1yG2/S6OnEaOVbDP3TrOeS6Phx2xN5NVvUk9StJqDA6f7PjHH1AXXyY+sx57tM=@lists.denx.de X-Gm-Message-State: AOJu0YxXkrwLpEKou1kGm4Hlr4EsQDDXEXPt5OIrWRP4bLBIdJT/KcBZ yo+87cnlVMM69UD5Oat/BiLkMDOipJH3Iuhe4YAgE89jUbgChIe7c6NePNUTN9o= X-Gm-Gg: ASbGncvR2DNnR99gLc2LLGI9HBXddQyTsu0IUCIn/cKFEDETb0numRUsFh1bdbYHPNN pkoZJpUmS7KoGK2XqkWcMmWGy8svbA5Q7pexcbvoqR1jIvvrEImYOJKHQJx0Oiuou9Q8l9IXjOh Kx46wf7wIOa1cJ+WT+lkwJYN8HREhPkbP6HDLFzuwfrjjZZGVgPaZzMuLeHYIECsKmlCqx11i52 A638nuvuY4mitDpOzk/2do7fXzXQ2Z+irqS8mfZIUWaPEfZiINJF2z8vgmh4PPbtE1AZcQfbOwR gkEwNBwUUubp69Jj/1JIe6xFH8vxvzv3N0ewe7S377pXggrh9smtzAv6JZQJvx9/s0cnExDvUtB RBoS/ X-Received: by 2002:a17:907:1b22:b0:abf:b2f:fef7 with SMTP id a640c23a62f3a-abf0b300382mr334268866b.29.1740658550536; Thu, 27 Feb 2025 04:15:50 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc168sm114736566b.70.2025.02.27.04.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:15:50 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Simon Glass , Sughosh Ganu , Caleb Connolly , Sam Protsenko , Jerome Forissier , =?utf-8?q?Pierre-Cl=C3=A9me?= =?utf-8?q?nt_Tosi?= , Richard Henderson , Sam Edwards , Andre Przywara , Peter Hoyes , Patrick Rudolph , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Harrison Mutai , Joshua Watt , Raymond Mao , Jagan Teki , Evgeny Bachinin , Christian Marangi , Michal Simek , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de Subject: [PATCH v3 4/6] arm64: mmu_change_region_attr() add an option not to break PTEs Date: Thu, 27 Feb 2025 14:14:54 +0200 Message-ID: <20250227121515.232996-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250227121515.232996-1-ilias.apalodimas@linaro.org> References: <20250227121515.232996-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 27 Feb 2025 13:56:54 +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 | 28 ++++++++++++++++++++++++++++ arch/arm/include/asm/system.h | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c index c4b3da4a8da7..504fef34bf0f 100644 --- a/arch/arm/cpu/armv8/cache_v8.c +++ b/arch/arm/cpu/armv8/cache_v8.c @@ -1024,6 +1024,34 @@ void mmu_change_region_attr(phys_addr_t addr, size_t siz, u64 attrs) __asm_invalidate_tlb_all(); } +void mmu_change_region_attr_nobreak(phys_addr_t addr, size_t siz, u64 attrs) +{ + int level; + u64 r, size, start; + + /* + * Loop through the address range until we find a page granule that fits + * our alignment constraints, then set it to the new cache attributes + */ + start = addr; + size = siz; + while (size > 0) { + for (level = 1; level < 4; level++) { + /* Set PTE to new attributes */ + r = set_one_region(start, size, attrs, true, level); + if (r) { + /* PTE successfully updated */ + size -= r; + start += r; + break; + } + } + } + flush_dcache_range(gd->arch.tlb_addr, + gd->arch.tlb_addr + gd->arch.tlb_size); + __asm_invalidate_tlb_all(); +} + #else /* !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ /* diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h index dbf9ab43e280..802640de3b64 100644 --- a/arch/arm/include/asm/system.h +++ b/arch/arm/include/asm/system.h @@ -287,8 +287,26 @@ 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); + +/** + * mmu_change_region_attr() - change a mapped region attributes + * + * @start: Start address of the region + * @size: Size of the region + * @aatrs: New attributes + */ void mmu_change_region_attr(phys_addr_t start, size_t size, u64 attrs); +/** + * mmu_change_region_attr_nobreak() - change a mapped region attributes without doing + * break-before-make + * + * @start: Start address of the region + * @size: Size of the region + * @aatrs: New attributes + */ +void mmu_change_region_attr_nobreak(phys_addr_t addr, size_t size, u64 attrs); + /* * smc_call() - issue a secure monitor call * From patchwork Thu Feb 27 12:14:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 868964 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp247248wrz; Thu, 27 Feb 2025 04:57:58 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVDUk+dQmYR6OjIYWNPOlk3Jaa7l9K0a21RlBu1mDe41HQyG+v/0gi18+hWHATeBys+rC3Lhw==@linaro.org X-Google-Smtp-Source: AGHT+IELUmdL0jsoqW492eVXmz8MfcOGy9spnT6QXqKsnQK1mh3FZUeJNgoS611vA90bzrH+UN/n X-Received: by 2002:a17:906:3145:b0:aae:fb7c:50df with SMTP id a640c23a62f3a-abeeef41690mr830449866b.36.1740661078526; Thu, 27 Feb 2025 04:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740661078; cv=none; d=google.com; s=arc-20240605; b=XLj/diTbINiUJa9z9ftDpk3xqv9sDFpuDyxL012klwLvAolLmZPTU1Y88OlKUiKMsL tv2Iz5N4kr7vK1PV/4oYzHScc5mhLxekznCCp8qZPv6dv9QSbSgfhZZ7hVrc+9U+D3S9 TDDC1LDCxz0VrkDAE6g97nRwgNaPesPHTOeSg5U7To+bQNpHC7jbBtK5Kwc4ekOxQaOD IobKB1cGwsJczEoO0bTwj5x03kBN4dtyg6UiKOrCmOv/noyG90VmucGj86fbZDNhFqmZ VtS7YEkspANYsYt5ZGsp5Jz551Zk7Brv87b6EU09JMeKApf/l+q1GgXwf2TRgeiwmlTD dq6Q== 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=p4ZffA+aQTK/U7KqY248PKjkrsmddQQHuzNPXdM4GZQ=; fh=0ontBIK2unMOsOLxteuckOBL33r3iE/68qRA3dPfZcM=; b=TGc2SxH4tUkeCT1ebYcMPCBMcQl9WLd5SJUmXrHadZanehRjDKNOioV3G2oeqxaKfy QBDO3VYG/3VmXx52XgLaVpb5UvEswKrF+i6jGH5t245+HTEPwnmOTS10sTX8oA9ZHYcv W1CrBTJj3ep++H8eBFKhPghgHKE4yKWpoDAs5QOTcyHYq6o3ojTqWa8kWH0RQc2YnVL4 lGfUHXG2s6LYUI+9uecQiAn3CKFLZEeqwaPFXcKsn/FGdRuSskLTZF3Jum5OQPA9bU+M 8K/DSXSJ6PMvhWJyHxo5E2BMZskfIVl6BcKOaz46rLsn9DIoBMsJK5SIVjDTqn5cbyvJ iozA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LDSC09QS; 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 a640c23a62f3a-abf0c0b8c1csi159742066b.43.2025.02.27.04.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:57:58 -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=LDSC09QS; 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 7FD96811C5; Thu, 27 Feb 2025 13:56:58 +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="LDSC09QS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 34DAB801FB; Thu, 27 Feb 2025 13:15:59 +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-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) (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 DE23D810EA for ; Thu, 27 Feb 2025 13:15:56 +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-ej1-x636.google.com with SMTP id a640c23a62f3a-abec925a135so123510466b.0 for ; Thu, 27 Feb 2025 04:15:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740658556; x=1741263356; 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=p4ZffA+aQTK/U7KqY248PKjkrsmddQQHuzNPXdM4GZQ=; b=LDSC09QSRGghLkpzujzU2y9bsqGzvXEFjjF7grjzW3RY6Pge1Ykmzlat+yXLg+r90V eCk0mK67081BXY2gfSWYqK++qygAq9qvxKK0NydDPblwvCJ6M0GvkSJKyJxKLfRHM0db S0B+sFfRMQX1hhDWEgVm9ZBpWb0G8V3eO/eIBDSHrn8JkUOIupt4owch7hpvSX3Dz9bB iNeU2pI4ZHqVWNrcUujC7sHQN0/ZDYGJREb4ege3wsPHEt+pJsErV/+wc8zs4t7DttAE 3sH2Df7YUTG5MQUsFAccYy/tLvW7fChhxjK99FQJRjmivdMPVzmZlOsWqzszo6ZZKmVc zUEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740658556; x=1741263356; 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=p4ZffA+aQTK/U7KqY248PKjkrsmddQQHuzNPXdM4GZQ=; b=V3Au7Ef0VNsFP7hhcY4GxIPdUb/NhSBqKmDLnozAvxurCsFP22MB3PMKhtinKsbGJ6 uX25AvETV72ATn079ProFQadlNoZM8aBLRm3BqohlYGYvwMi2zYk5ZKMU9tAGkcFdfLs 3uqcM+iIk++DXD8JkglNC7np+g8tU97plJXmMG2b1HtGtUkIAREzI5YzkXh9yhBRZ/9B PP0H2czshJ8FH8iT+Z27f840Bwu7TFZlETCLnwb/rrcusfnSqsCCKQ+HoPBNxBKH5JGS Q0Wk+0UDXcPndvnrO76CWVLQuUTHaZXo2lbiydrqQx3JAm0ZwHDFaZ0lKLOGpTGHTFMQ YS7Q== X-Forwarded-Encrypted: i=1; AJvYcCUuk/tm7I2cMTZMtjLncAdSB9RPXER6tSSbIc/6FwICs8L+yBYAEycjxxlWpDXtJV2i0xVbJ1I=@lists.denx.de X-Gm-Message-State: AOJu0Yw8yU9//PQpHuyooSnTIg6LkMWL7Q+V11DwN5RS7wlhG6Zth1Ik VWVRNmSBrTIGb3vtRYhJ5F+rEteI+xSD7WbxM0Jz5vHzFi5+qVxkswjM157CWyA= X-Gm-Gg: ASbGncvrKQyVbeg1aAbDjbX1RwW5eCnjBeoYNFR/5n18vl62PgJj41wmH3x3+xrRJCr IN/AL136bwq/h8S+36Pn5fEO4Nxy7QrW0+AFGH2IcHuXxqLQJ/Q98hbM4FSSsQr1XLkm+QGYvEh jMhCd0tmVV5QH5BAehaD54LtKmGeruGyzwWCsx/a9K7n4NRE85lFXqW1nxaVLQ9cMCdQx1nCKJR Zd7HFG6W+zAPZMry0FL0K56HaMIU7TWnwR4lrNSmA/CuZfiEffKR+Gy0otHjLwotZ7FgRoaHXda FV5pV7BG05uxvSYZMy4p884x6LAvHXwaqGoqpqTDgUkr6a0UAXeZuo86aY5a29y4LWQ0fGwfJ8Q iUUQH X-Received: by 2002:a17:907:7f92:b0:abe:d0c8:851c with SMTP id a640c23a62f3a-abeeef75224mr1001145966b.50.1740658556236; Thu, 27 Feb 2025 04:15:56 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc168sm114736566b.70.2025.02.27.04.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:15:55 -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 , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Simon Glass , Sughosh Ganu , Caleb Connolly , Sam Protsenko , Jerome Forissier , =?utf-8?q?Pierre-Cl=C3=A9me?= =?utf-8?q?nt_Tosi?= , Richard Henderson , Sam Edwards , Andre Przywara , Peter Hoyes , Patrick Rudolph , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Harrison Mutai , Jiaxun Yang , Raymond Mao , Joshua Watt , Jagan Teki , Evgeny Bachinin , Christian Marangi , Michal Simek , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de Subject: [PATCH v3 5/6] treewide: Add a function to change page permissions Date: Thu, 27 Feb 2025 14:14:55 +0200 Message-ID: <20250227121515.232996-6-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250227121515.232996-1-ilias.apalodimas@linaro.org> References: <20250227121515.232996-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 27 Feb 2025 13:56:54 +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..08f9e7dceac0 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/arm/cpu/arm926ejs/cache.c b/arch/arm/cpu/arm926ejs/cache.c index 5b87a3af91b2..71b8ad0f71d8 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/arm/cpu/armv7/cache_v7.c b/arch/arm/cpu/armv7/cache_v7.c index d11420d2fdd0..371dc92cd46c 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/arm/cpu/armv7m/cache.c b/arch/arm/cpu/armv7m/cache.c index b6d08b7aad73..8e7db7340557 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c index 504fef34bf0f..81cf7f9bd661 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; @@ -1052,6 +1053,30 @@ void mmu_change_region_attr_nobreak(phys_addr_t addr, size_t siz, u64 attrs) __asm_invalidate_tlb_all(); } +int pgprot_set_attrs(phys_addr_t addr, size_t size, enum pgprot_attrs 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 %d\n", perm); + return -EINVAL; + } + + mmu_change_region_attr_nobreak(addr, size, attrs); + + 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..dd19bd3e4fb3 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/m68k/lib/cache.c b/arch/m68k/lib/cache.c index 370ad40f1423..a21fe3279440 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/nios2/lib/cache.c b/arch/nios2/lib/cache.c index 8f543f2a2f26..d7fd9ca8bd4a 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/powerpc/lib/cache.c b/arch/powerpc/lib/cache.c index a9cd7b8d30ac..e4d9546039d8 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/riscv/lib/cache.c b/arch/riscv/lib/cache.c index 71e4937ab542..31aa30bc7d72 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/sh/cpu/sh4/cache.c b/arch/sh/cpu/sh4/cache.c index 99acc5999652..56161ee72e4b 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/arch/xtensa/lib/cache.c b/arch/xtensa/lib/cache.c index e6a7f6827fc2..1229b4077835 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, enum pgprot_attrs perm) +{ + return -ENOSYS; +} diff --git a/include/cpu_func.h b/include/cpu_func.h index 7e81c4364a73..70a41ead3f73 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, enum pgprot_attrs perm); + /** * noncached_init() - Initialize non-cached memory region * From patchwork Thu Feb 27 12:14:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 868965 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp247281wrz; Thu, 27 Feb 2025 04:58:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWi8ctABzKa05Yde5hWa/E0tTXttRapFbUo2rGcEL+J3K4g09RPysCp5NYY3GWk5Innj0eykw==@linaro.org X-Google-Smtp-Source: AGHT+IES/smYk9mBtzXDBsXgUtlptqsDTEqNW7GlWaczGX9gGTNUdWZ3pNpZA0BWNbQ/fSxM93Rg X-Received: by 2002:a17:906:30cf:b0:ab7:b2a7:9cb8 with SMTP id a640c23a62f3a-abeeed7a3camr805349966b.15.1740661087824; Thu, 27 Feb 2025 04:58:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740661087; cv=none; d=google.com; s=arc-20240605; b=H8q4jLvyRZXI2g/YsLcEmKpthuHxVriaAbZqvBv8u0mM+pwqpXbtkSk2SUzIXCO+pV hhDBZIHxLRgNvdtrWTLE+3Oueyht6Z2hIn2Mm27PcfSet109TFuI0wQaU+cI+zoEbVxM TZxHiFIJ1oh7Sfoe4JtRXxEg6IgSzc5jhUlrmkkjK8LQvfatDlcI5FTIBjtN4NPd2V5+ EA2g2wcnl7eBOj5K9b0VeIlnx1NBZdP6XNnZyA+jr6cpELKWJZ0tHeHASL/HITgBsji/ 9XdTvaQA4M6mi1LbGZQlNAas61xEAkU5Sz3eI9kWTnKPX7gpoMTMoFI3V/Nv7WxjKJeM VWkQ== 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=PVfIOgHxpE9oah2uVOuIo9KhwUxCA9wrkpQ/cElJizo=; fh=TMmu+XQAvQG6D0fNdhrxxVZvGjL2K/F8JArN86yCTcY=; b=DD4GJ455MyAscpeS7t8lXOZfh+MqeiWZBMPvDcNciymFj5v5khk/flidd/sQ8HM74e Xr4sR+3vFFcQtofJIm9Jutr1xJ3CPb2VRNKrDuzFi/DO4SKtZ5pe2l+jVR3UhfzVy/gq BIo4megdq2DEfu/aLKivkOVEdlC8MN5towUZKnkFW9yGiDpy4t1Sl1dGHwnRF1CM0I7s miOx4vnDhAanKxo04o/Oo9DD7EpdhW735CiFBJZK6MBuBylGn7AaZIBUe4EvVS5yeDFW P61DJTGkhHPUS9jIontMh+821OKajumOZNiXXsJVl+8LfISoZSuvAWnKEKh0TaAmkqP/ cdIQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yuT8Yl3n; 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 a640c23a62f3a-abf0c78118fsi150980166b.478.2025.02.27.04.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:58:07 -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=yuT8Yl3n; 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 CA164811E0; Thu, 27 Feb 2025 13:56:58 +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="yuT8Yl3n"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1083D810EA; Thu, 27 Feb 2025 13:16:05 +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-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) (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 A7E00801FB for ; Thu, 27 Feb 2025 13:16:02 +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-ej1-x632.google.com with SMTP id a640c23a62f3a-abb86beea8cso158627166b.1 for ; Thu, 27 Feb 2025 04:16:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740658562; x=1741263362; 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=PVfIOgHxpE9oah2uVOuIo9KhwUxCA9wrkpQ/cElJizo=; b=yuT8Yl3nz0C656ejHziEFOe8g3O+LwGUXAHFjV7PaxcBHql3saKsdmC1jC6zhnFZ/l EWXQcmDWjdp5ytv9KAcUyF9QbZoSzG9iCRyRVduZ8O5kzA58UsJ8Cz/FCRPKAFOdPrnB Sfx7NqsmRD2gjsZXG6XR3ULyUey9BmOlZlnyip4iOaJGR3ua9xXq54QWVtRxOkzLn14y lGfLFQTHaJBZw/sJ10/wBUzKM7k1xRVgKooWP8lZJ9EzmOrKal2hfqE4KyIYQEQ+ShRU b71qmtaQ2cbe52ugoDOUyq+FT9INnrrASXs6kmtWrsrXo2zGBjRkdUv8iAttB3/xybsK Z3ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740658562; x=1741263362; 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=PVfIOgHxpE9oah2uVOuIo9KhwUxCA9wrkpQ/cElJizo=; b=HP8Flx/AxON743/myKHTtVoBf5yyyoy2dSUKpX47SJ/08vOLlXKIG+hdbQIr+ze4E0 ZPPGQS8bMB0NjXJWZyoIK8tR81Pqyc6Uh7oi52RJQy8sqbVrtCGkStdC+N0vTL0YHjmb 8TTFNi4ttdLViDT5ZK2dZuUeRwNQXQxskAD6kbSXaoYY5H3RvoOMd+z9s4nAY3j1UFYj gAzPDb92B0yk5sRQhIxxQoKOh7wCiCC/9PR6jUwNzhND06eG4fte4dqGPGb8AuZDw6UO 2p73KXES6TFp6qXpO74cS1B5X4qZzccBPO/Ac0iZP2ns7zKi8PTNVu8xHreEGDgo91wa u04g== X-Forwarded-Encrypted: i=1; AJvYcCXLZTnHe+cMKk5MDDUimtHxce0ZyAIdHo8gVX8XP3Gw6jMZPNZbgF8bxXAOWX5SFH7PMS+Ln7U=@lists.denx.de X-Gm-Message-State: AOJu0YxMQZxpmNXIjx2sjQKBykXTfeUFQrDQFqr+EEBvoCtaBDn1gogQ 4IxF3P2IBQugIJW3Bg2iNkJEAOpsAkbF6zA4yB/lQMwIUN6zWNJldwwwZGzYZGg= X-Gm-Gg: ASbGncvF2pkDJAmBUCz/i1Fm/zNmxCYlng0y1yuTX7oO1xmDua9sw5Tx+RT47nY0xpW 3oLed0/XSyqnEe+zNXN5C5LWRGm4EgCEYIsgRwCOmWST0ldxe/e8eGSJ9Pr0jiNiDA0LQiXXT/x jpDNu64pvcfzq+PftCU9NmcT33hyvFm7MEhPkbWG/u6bBnJdHD32qKs2YIUKLLRrPoaYTMSYFuo X3TlfUvAUVrNJAHCPX846ZdpdsUsaa4NI/5bmThWgau3G2SgoZndtK5ecLUV9jo1rxLEw/7teaN +0LNB4xNn8ADSvpuUbqxJbi0jxtxSt162dAcKJLRUfFRoa3WEqWk9JBl/cv/OUuSiNY/FpPwKPX vCgBA X-Received: by 2002:a17:906:4c2:b0:abc:a1b:2781 with SMTP id a640c23a62f3a-abeeed0d62fmr882122066b.4.1740658562029; Thu, 27 Feb 2025 04:16:02 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc168sm114736566b.70.2025.02.27.04.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:16:01 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Jerome Forissier , Richard Henderson , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Sughosh Ganu , Simon Glass , Caleb Connolly , =?utf-8?q?Pierre-Cl=C3=A9ment_T?= =?utf-8?q?osi?= , Neil Armstrong , Sam Protsenko , Sam Edwards , Peter Hoyes , Andre Przywara , Patrick Rudolph , Mayuresh Chitale , Mattijs Korpershoek , Harrison Mutai , Stefan Roese , Jagan Teki , Joshua Watt , Raymond Mao , Jiaxun Yang , Evgeny Bachinin , Peter Robinson , Christian Marangi , Michal Simek , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de Subject: [PATCH v3 6/6] arm64: Enable RW, RX and RO mappings for the relocated binary Date: Thu, 27 Feb 2025 14:14:56 +0200 Message-ID: <20250227121515.232996-7-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250227121515.232996-1-ilias.apalodimas@linaro.org> References: <20250227121515.232996-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 27 Feb 2025 13:56:54 +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 Reviewed-by: Richard Henderson Signed-off-by: Ilias Apalodimas --- common/Kconfig | 13 +++++++++++++ common/board_r.c | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/common/Kconfig b/common/Kconfig index 1d6de8badf75..edb857e4de7f 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; }