From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/8] ARM mmu: use high vectors if possible
Date: Mon, 8 Aug 2011 08:46:38 +0200 [thread overview]
Message-ID: <1312786003-14734-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1312786003-14734-1-git-send-email-s.hauer@pengutronix.de>
Using high vectors allows us to map a faulting zero page to
catch NULL pointer dereferences.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/cpu/mmu.c | 37 +++++++++++++++++++++++++++++++------
1 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 2f754c8..b669349 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -4,6 +4,7 @@
#include <errno.h>
#include <sizes.h>
#include <asm/memory.h>
+#include <asm/system.h>
static unsigned long *ttb;
@@ -161,22 +162,46 @@ static int arm_mmu_remap_sdram(struct arm_memory *mem)
#define ARM_VECTORS_SIZE (sizeof(u32) * 8 * 2)
/*
- * Allocate a page, map it to the zero page and copy our exception
- * vectors there.
+ * Map vectors and zero page
*/
static void vectors_init(void)
{
- u32 *exc;
+ u32 *exc, *zero = NULL;
void *vectors;
extern unsigned long exception_vectors;
-
- exc = arm_create_pte(0x0);
+ u32 cr;
+
+ cr = get_cr();
+ cr |= CR_V;
+ set_cr(cr);
+ cr = get_cr();
+
+ if (cr & CR_V) {
+ /*
+ * If we can use high vectors, create the second level
+ * page table for the high vectors and zero page
+ */
+ exc = arm_create_pte(0xfff00000);
+ zero = arm_create_pte(0x0);
+
+ /* Set the zero page to faulting */
+ zero[0] = 0;
+ } else {
+ /*
+ * Otherwise map the vectors to the zero page. We have to
+ * live without being able to catch NULL pointer dereferences
+ */
+ exc = arm_create_pte(0x0);
+ }
vectors = xmemalign(PAGE_SIZE, PAGE_SIZE);
memset(vectors, 0, PAGE_SIZE);
memcpy(vectors, &exception_vectors, ARM_VECTORS_SIZE);
- exc[0] = (u32)vectors | PTE_TYPE_SMALL | PTE_FLAGS_CACHED;
+ if (cr & CR_V)
+ exc[256 - 16] = (u32)vectors | PTE_TYPE_SMALL | PTE_FLAGS_CACHED;
+ else
+ exc[0] = (u32)vectors | PTE_TYPE_SMALL | PTE_FLAGS_CACHED;
}
/*
--
1.7.5.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2011-08-08 6:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-08 6:46 ARM: " Sascha Hauer
2011-08-08 6:46 ` [PATCH 1/8] ARM: add missing volatile in get_cr() Sascha Hauer
2011-08-08 6:46 ` [PATCH 2/8] ARM mmu: fix arm_create_pte Sascha Hauer
2011-08-08 6:46 ` Sascha Hauer [this message]
2011-08-08 6:46 ` [PATCH 4/8] ARM: remove unused exception Sascha Hauer
2011-08-08 6:46 ` [PATCH 5/8] ARM: exceptions: remove unnecessary function declarations Sascha Hauer
2011-08-08 6:46 ` [PATCH 6/8] ARM: remove unused irq enable/disable functions Sascha Hauer
2011-08-08 6:46 ` [PATCH 7/8] ARM: fix comments in interrupts.c Sascha Hauer
2011-08-08 6:46 ` [PATCH 8/8] ARM: some cleanup " Sascha Hauer
2011-08-08 7:06 ` ARM: use high vectors if possible Jean-Christophe PLAGNIOL-VILLARD
2011-08-08 7:32 ` Sascha Hauer
2011-08-09 7:36 ` Jean-Christophe PLAGNIOL-VILLARD
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=1312786003-14734-4-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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