From d3d6c6e3e9860024cda8766dbcf62f8022a68002 Mon Sep 17 00:00:00 2001 From: Antonio Nino Diaz Date: Thu, 8 Dec 2016 16:03:46 +0000 Subject: Assert correct granularity when mapping a PA Each translation table level entry can only map a given virtual address onto physical addresses of the same granularity. For example, with the current configuration, a level 2 entry maps blocks of 2 MB, so the physical address must be aligned to 2 MB. If the address is not aligned, the MMU will just ignore the lower bits. This patch adds an assertion to make sure that physical addresses are always aligned to the correct boundary. Change-Id: I0ab43df71829d45cdbe323301b3053e08ca99c2c Signed-off-by: Antonio Nino Diaz --- lib/xlat_tables/xlat_tables_common.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/xlat_tables') diff --git a/lib/xlat_tables/xlat_tables_common.c b/lib/xlat_tables/xlat_tables_common.c index ebbc9161..808aa33a 100644 --- a/lib/xlat_tables/xlat_tables_common.c +++ b/lib/xlat_tables/xlat_tables_common.c @@ -198,6 +198,9 @@ static uint64_t mmap_desc(unsigned attr, unsigned long long addr_pa, uint64_t desc; int mem_type; + /* Make sure that the granularity is fine enough to map this address. */ + assert((addr_pa & XLAT_BLOCK_MASK(level)) == 0); + desc = addr_pa; /* * There are different translation table descriptors for level 3 and the -- cgit v1.2.3