From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 17 Aug 2022 13:44:50 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oOHTe-001pZS-Sc for lore@lore.pengutronix.de; Wed, 17 Aug 2022 13:44:50 +0200 Received: from bombadil.infradead.org ([2607:7c80:54:3::133]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oOHTb-0001vb-6C for lore@pengutronix.de; Wed, 17 Aug 2022 13:44:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IvbFxbhZMJjXdXfLq/fXIdrIV5wtiL7rxUheCF0D/QE=; b=3LxEFM2ZG9qs8+il21Er6le/d6 5TcM1Dax8XO7ALBerz07t6lKAW4tmV5wJgzpGvfFg6D2R3qhcZnppjkXg9ddYBKfQVEFss7nnTF+Q zHJMEbBTuoj9WABvnUf5nWjhA0pQuSgjOMuPfDHHjhXRkMFO4iY2M5qhzl07plmQfi114RnrsL02p rX4Sf/xI8MNDlo5AQWYx4++7F1hkddJza5kYnybF8+f3PNzDeErKT9yhbI3kOWNy19kQS2xAX1APT 6qIVS09Ua0eF4NE778Z+vEnIhc1OAIkmca2rwiHK/AeHB5HyO9dE8NUC4691zVuw/k0K5yKXwtOD+ hIQKiHvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oOHRv-001ZGK-Kv; Wed, 17 Aug 2022 11:43:03 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oOHRp-001ZAK-N5 for barebox@lists.infradead.org; Wed, 17 Aug 2022 11:42:59 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oOHRg-0001OD-LL; Wed, 17 Aug 2022 13:42:48 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1oOHRf-000IqT-UU; Wed, 17 Aug 2022 13:42:47 +0200 Received: from afa by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1oOHRd-007dCv-Lm; Wed, 17 Aug 2022 13:42:45 +0200 From: Ahmad Fatoum To: barebox@lists.infradead.org Cc: uol@pengutronix.de, Ahmad Fatoum Date: Wed, 17 Aug 2022 13:42:40 +0200 Message-Id: <20220817114244.1810531-7-a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220817114244.1810531-1-a.fatoum@pengutronix.de> References: <20220817114244.1810531-1-a.fatoum@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220817_044257_788780_16FBB7C3 X-CRM114-Status: GOOD ( 12.84 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:3::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.ext.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-3.7 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Subject: [PATCH v2 06/10] ARM: mmu64: map reserved regions uncached X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.ext.pengutronix.de) Now that we have reserved memory regions specially marked in the SDRAM bank requests, we can use this information to map these regions uncached and eXecute Never to avoid speculative access into these regions from causing hard-to-debug data aborts. The sequence used here is safe because __mmu_init turns off the MMU if enabled, so even if we overwrite early MMU uncached entries they are without effect until the MMU is turned on again, by which time the for_each_reserved_region should have disabled caching for them again (e.g. because they were listed in DT as /reserve-memory). Signed-off-by: Ahmad Fatoum --- arch/arm/cpu/mmu-common.h | 15 +++++++++++++++ arch/arm/cpu/mmu_64.c | 10 +++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/arm/cpu/mmu-common.h b/arch/arm/cpu/mmu-common.h index ed7d5bc3168f..c9ea2c122857 100644 --- a/arch/arm/cpu/mmu-common.h +++ b/arch/arm/cpu/mmu-common.h @@ -3,6 +3,11 @@ #ifndef __ARM_MMU_COMMON_H #define __ARM_MMU_COMMON_H +#include +#include +#include +#include + void dma_inv_range(void *ptr, size_t size); void dma_flush_range(void *ptr, size_t size); void *dma_alloc_map(size_t size, dma_addr_t *dma_handle, unsigned flags); @@ -19,4 +24,14 @@ static inline void arm_mmu_not_initialized_error(void) panic("MMU not initialized\n"); } +static inline size_t resource_first_page(const struct resource *res) +{ + return ALIGN_DOWN(res->start, SZ_4K); +} + +static inline size_t resource_count_pages(const struct resource *res) +{ + return ALIGN(resource_size(res), SZ_4K); +} + #endif diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c index 06049e000375..f43ac9a12186 100644 --- a/arch/arm/cpu/mmu_64.c +++ b/arch/arm/cpu/mmu_64.c @@ -201,9 +201,17 @@ void __mmu_init(bool mmu_on) create_sections(0, 0, 1UL << (BITS_PER_VA - 1), attrs_uncached_mem()); /* Map sdram cached. */ - for_each_memory_bank(bank) + for_each_memory_bank(bank) { + struct resource *rsv; + create_sections(bank->start, bank->start, bank->size, CACHED_MEM); + for_each_reserved_region(bank, rsv) { + create_sections(resource_first_page(rsv), resource_first_page(rsv), + resource_count_pages(rsv), attrs_uncached_mem()); + } + } + /* Make zero page faulting to catch NULL pointer derefs */ zero_page_faulting(); -- 2.30.2