mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <sha@pengutronix.de>
Cc: Rouven Czerwinski <r.czerwinski@pengutronix.de>,
	barebox@lists.infradead.org
Subject: Re: [PATCH v2 3/8] ARM: mmu: use reserve mem entries to modify maps
Date: Tue, 24 Aug 2021 09:09:37 +0200	[thread overview]
Message-ID: <501906d6-58ff-7399-9ba4-012dc0a27537@pengutronix.de> (raw)
In-Reply-To: <20210809183042.GF11515@pengutronix.de>

On 09.08.21 20:30, Sascha Hauer wrote:
> On Thu, Aug 05, 2021 at 04:06:42PM +0200, Ahmad Fatoum wrote:
>> On 03.08.21 11:44, Rouven Czerwinski wrote:
>>> Use the information from the reserved memory entries to modify the
>>> mapping of memory regions to mark them as uncachable and not-executable.
>>> This also prevents the processor from speculating into these regions,
>>> preventing hard to debug scenarios where boots fail for unknown reasons.
>>>
>>> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
>>> ---
>>>  arch/arm/cpu/mmu.c | 34 ++++++++++++++++++++++++++++++++--
>>>  1 file changed, 32 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
>>> index 6388e1bf14..73f4cf5b36 100644
>>> --- a/arch/arm/cpu/mmu.c
>>> +++ b/arch/arm/cpu/mmu.c
>>> @@ -17,6 +17,7 @@
>>>  #include <memory.h>
>>>  #include <asm/system_info.h>
>>>  #include <asm/sections.h>
>>> +#include <of.h>
>>>  
>>>  #include "mmu.h"
>>>  
>>> @@ -407,6 +408,36 @@ static void vectors_init(void)
>>>  	create_vector_table(ARM_LOW_VECTORS);
>>>  }
>>>  
>>> +static void create_sections_with_intersect(struct memory_bank *bank)
>>> +{
>>> +	struct of_reserve_map *res_map;
>>> +	unsigned long j_end;
>>> +	unsigned long end;
>>> +	unsigned long j;
>>> +	u32 pmd_flags;
>>> +	int i;
>>> +
>>> +	res_map = of_get_reserve_map();
>>> +	if (!res_map)
>>> +		return;
>>
>> If there is no reserve map, you should still map the banks cached.
>> So this early exit is wrong.
>>
>>> +
>>> +	end = bank->start + bank->size - 1;
>>> +
>>> +	for (j = bank->start; j < end; j += PGDIR_SIZE) {
>>> +		pmd_flags = PMD_SECT_DEF_CACHED;
>>> +		j_end = j + PGDIR_SIZE - 1;
>>> +
>>> +		for (i = 0; i < res_map->num_entries; i++) {
>>> +			if ((BIT(i) & res_map->xn) &&
>>> +			    j_end >= res_map->start[i] &&
>>> +			    j_end <= res_map->end[i])
>>> +				pmd_flags = PMD_SECT_DEF_UNCACHED | PMD_SECT_XN;
>>> +		}
>>> +
>>> +		create_sections(ttb, j, j_end, pmd_flags);
>>> +	}
>>
>> Do we need the nested loop? Can't we create sections cached first
>> and then iterate once over the reserved map, deduce the sections containing
>> start and end and map those uncached?
> 
> Wouldn't that open a window to speculate into the areas we want to avoid
> speculating into in the first place?

Right. Forgot that MMU is enabled here.

> 
> Sascha
> 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-08-24  7:11 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03  9:44 [PATCH v2 0/8] XN Support for reserved-memory areas Rouven Czerwinski
2021-08-03  9:44 ` [PATCH v2 1/8] of: reserve: add xn flag mem entries Rouven Czerwinski
2021-08-05 13:54   ` Ahmad Fatoum
2021-08-09 18:26   ` Sascha Hauer
2021-08-03  9:44 ` [PATCH v2 2/8] of: add of_get_reserve_map stub for !CONFIG_OFTREE Rouven Czerwinski
2021-08-05 13:55   ` Ahmad Fatoum
2021-08-03  9:44 ` [PATCH v2 3/8] ARM: mmu: use reserve mem entries to modify maps Rouven Czerwinski
2021-08-05 14:06   ` Ahmad Fatoum
2021-08-09 18:30     ` Sascha Hauer
2021-08-24  7:09       ` Ahmad Fatoum [this message]
2021-08-03  9:44 ` [PATCH v2 4/8] of: add flag to not create resmem DT entries Rouven Czerwinski
2021-08-05 14:09   ` Ahmad Fatoum
2021-08-03  9:44 ` [PATCH v2 5/8] of: add reserved_mem_read initcall Rouven Czerwinski
2021-08-05 14:14   ` Ahmad Fatoum
2021-08-03  9:44 ` [PATCH v2 6/8] pbl: fdt: add support to parse reserved mem Rouven Czerwinski
2021-08-05 14:20   ` Ahmad Fatoum
2021-08-03  9:44 ` [PATCH v2 7/8] ARM: mmu-early: map no-map entries XN & uncached Rouven Czerwinski
2021-08-05 14:24   ` Ahmad Fatoum
2021-08-03  9:44 ` [PATCH v2 8/8] PBL: enable LIBFDT for OP-TEE early loading Rouven Czerwinski
2021-08-05 13:53   ` Ahmad Fatoum
2021-08-24  6:47     ` Rouven Czerwinski

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=501906d6-58ff-7399-9ba4-012dc0a27537@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=r.czerwinski@pengutronix.de \
    --cc=sha@pengutronix.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