From: Patrick Delaunay <patrick.delaunay@st.com>
To: u-boot@lists.denx.de
Subject: [PATCH 7/7] arm: cache: cp15: don't map the reserved region with no-map property
Date: Tue, 6 Oct 2020 18:36:02 +0200 [thread overview]
Message-ID: <20201006163602.21687-2-patrick.delaunay@st.com> (raw)
In-Reply-To: <20201006163602.21687-1-patrick.delaunay@st.com>
No more map the reserved region with "no-map" property by marking
the corresponding TLB entries with invalid entry (=0) to avoid
speculative access.
This patch fixes an issue on STM32MP15x where predictive read access
on secure DDR area are caught by OP-TEE.
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---
arch/arm/include/asm/system.h | 3 +++
arch/arm/lib/cache-cp15.c | 19 +++++++++++++++++--
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
index ce552944b7..932f12af1c 100644
--- a/arch/arm/include/asm/system.h
+++ b/arch/arm/include/asm/system.h
@@ -458,6 +458,7 @@ static inline void set_dacr(unsigned int val)
/* options available for data cache on each page */
enum dcache_option {
+ INVALID_ENTRY = 0,
DCACHE_OFF = TTB_SECT | TTB_SECT_MAIR(0) | TTB_SECT_XN_MASK,
DCACHE_WRITETHROUGH = TTB_SECT | TTB_SECT_MAIR(1),
DCACHE_WRITEBACK = TTB_SECT | TTB_SECT_MAIR(2),
@@ -488,6 +489,7 @@ enum dcache_option {
* 1 1 1 Outer/Inner Write-Back, Read-Allocate Write-Allocate
*/
enum dcache_option {
+ INVALID_ENTRY = 0,
DCACHE_OFF = TTB_SECT_DOMAIN(0) | TTB_SECT_XN_MASK | TTB_SECT,
DCACHE_WRITETHROUGH = DCACHE_OFF | TTB_SECT_C_MASK,
DCACHE_WRITEBACK = DCACHE_WRITETHROUGH | TTB_SECT_B_MASK,
@@ -497,6 +499,7 @@ enum dcache_option {
#define TTB_SECT_AP (3 << 10)
/* options available for data cache on each page */
enum dcache_option {
+ INVALID_ENTRY = 0,
DCACHE_OFF = 0x12,
DCACHE_WRITETHROUGH = 0x1a,
DCACHE_WRITEBACK = 0x1e,
diff --git a/arch/arm/lib/cache-cp15.c b/arch/arm/lib/cache-cp15.c
index abd81d21c7..9e778dfd06 100644
--- a/arch/arm/lib/cache-cp15.c
+++ b/arch/arm/lib/cache-cp15.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <cpu_func.h>
+#include <lmb.h>
#include <log.h>
#include <asm/system.h>
#include <asm/cache.h>
@@ -105,18 +106,32 @@ void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
__weak void dram_bank_mmu_setup(int bank)
{
struct bd_info *bd = gd->bd;
+ struct lmb lmb;
int i;
/* bd->bi_dram is available only after relocation */
if ((gd->flags & GD_FLG_RELOC) == 0)
return;
+ /*
+ * don't allow cache on reserved memory tagged 'no-map' in DT
+ * => avoid speculative access to "secure" data
+ */
+ if (IS_ENABLED(CONFIG_LMB))
+ lmb_init_and_reserve(&lmb, bd, (void *)gd->fdt_blob);
+
debug("%s: bank: %d\n", __func__, bank);
for (i = bd->bi_dram[bank].start >> MMU_SECTION_SHIFT;
i < (bd->bi_dram[bank].start >> MMU_SECTION_SHIFT) +
(bd->bi_dram[bank].size >> MMU_SECTION_SHIFT);
- i++)
- set_section_dcache(i, DCACHE_DEFAULT_OPTION);
+ i++) {
+ if (IS_ENABLED(CONFIG_LMB) &&
+ lmb_is_reserved_flags(&lmb, i << MMU_SECTION_SHIFT,
+ LMB_NOMAP))
+ set_section_dcache(i, INVALID_ENTRY);
+ else
+ set_section_dcache(i, DCACHE_DEFAULT_OPTION);
+ }
}
/* to activate the MMU we need to set up virtual memory: use 1M areas */
--
2.17.1
next prev parent reply other threads:[~2020-10-06 16:36 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-06 16:35 [PATCH 0/7] arm: cache: cp15: don't map reserved region with no-map property Patrick Delaunay
2020-10-06 16:35 ` [PATCH 1/7] lmb: Add support of flags for no-map properties Patrick Delaunay
2020-10-06 16:35 ` [PATCH 2/7] lmb: add lmb_is_reserved_flags Patrick Delaunay
2020-10-06 16:35 ` [PATCH 3/7] lmb: remove lmb_region.size Patrick Delaunay
2020-10-06 16:35 ` [PATCH 4/7] lmb: add lmb_dump_region() function Patrick Delaunay
2020-10-06 16:36 ` [PATCH 5/7] test: lmb: add test for lmb_reserve_flags Patrick Delaunay
2020-10-06 16:36 ` [PATCH 6/7] image-fdt: save no-map parameter of reserve-memory Patrick Delaunay
2020-10-06 16:36 ` Patrick Delaunay [this message]
2020-10-07 10:26 ` [PATCH 0/7] arm: cache: cp15: don't map reserved region with no-map property Ard Biesheuvel
2020-10-07 11:23 ` [Uboot-stm32] " Ahmad Fatoum
2020-10-07 11:52 ` Ahmad Fatoum
2020-10-07 13:15 ` Ard Biesheuvel
2020-10-07 14:55 ` Etienne Carriere
2020-10-07 15:07 ` Ard Biesheuvel
2020-10-07 15:13 ` Etienne Carriere
2020-10-09 17:00 ` Patrick DELAUNAY
2020-10-27 17:25 ` Tom Rini
2020-10-27 21:04 ` Ard Biesheuvel
2020-10-28 10:33 ` Patrick DELAUNAY
2020-10-29 10:40 ` Etienne Carriere
2020-10-29 11:26 ` Ard Biesheuvel
2020-10-29 16:06 ` Etienne Carriere
2020-10-29 16:31 ` Ard Biesheuvel
2020-10-29 16:35 ` Jerome Forissier
2020-10-29 17:11 ` Etienne Carriere
2020-10-09 15:52 ` Patrick DELAUNAY
2020-10-09 17:12 ` Ahmad Fatoum
2020-10-09 17:15 ` Ahmad Fatoum
2020-10-09 18:35 ` Ard Biesheuvel
2020-10-12 9:09 ` Etienne Carriere
2020-10-12 9:20 ` Ard Biesheuvel
2020-10-12 9:51 ` Etienne Carriere
2020-10-12 10:27 ` Ard Biesheuvel
2020-10-09 11:18 ` Patrick DELAUNAY
2020-10-09 12:26 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201006163602.21687-2-patrick.delaunay@st.com \
--to=patrick.delaunay@st.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox