From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jJDtE-0003OX-RE for barebox@lists.infradead.org; Tue, 31 Mar 2020 10:13:02 +0000 From: Sascha Hauer Date: Tue, 31 Mar 2020 12:12:58 +0200 Message-Id: <20200331101258.7756-1-s.hauer@pengutronix.de> In-Reply-To: <20200331080109.24402-3-s.hauer@pengutronix.de> References: <20200331080109.24402-3-s.hauer@pengutronix.de> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH v2] arm64: Set PXN/UXN attributes for uncached mem To: Barebox List The attributes should be set to avoid speculative access to memory-mapped peripherals. The patch has been tested with: noinline unsigned long nox(void) { return get_pc(); } static void xn_test(void) { void *adr = (void *)SOME_SRAM_ADDRESS; unsigned long ret; unsigned long (*fn)(void) = adr; memcpy(adr, nox, 0x1000); sync_caches_for_execution(); ret = fn(); printf("pc: 0x%08lx\n", ret); } Without this patch nox() gets executed in SRAM, with it runs into a abort as expected. Signed-off-by: Sascha Hauer --- Changes since v1: - Select correct PXN/UXN bits based on current exception level arch/arm/cpu/mmu_64.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm/cpu/mmu_64.h b/arch/arm/cpu/mmu_64.h index a2a5477569..f5b7624037 100644 --- a/arch/arm/cpu/mmu_64.h +++ b/arch/arm/cpu/mmu_64.h @@ -6,7 +6,8 @@ PTE_BLOCK_AF) #define UNCACHED_MEM (PTE_BLOCK_MEMTYPE(MT_DEVICE_nGnRnE) | \ PTE_BLOCK_OUTER_SHARE | \ - PTE_BLOCK_AF) + PTE_BLOCK_AF | \ + PTE_BLOCK_UXN) /* * Do it the simple way for now and invalidate the entire tlb -- 2.26.0.rc2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox