Skip to contentSkip to conversation

pte_fsl_booke: fix instruction TLB error permission check

PATCH Applied Li Yang 4 participants 11 messages May 7, 2010 – May 14, 2010 PowerPC

lore
Share & tools
lore

Li Yang

author
#0 lore raw

PATCH 1/1 pte_fsl_booke: fix instruction TLB error permission check

Check the user/supervisor execution permission base on the code address. This fixes the following oops on module loading or removing.

Unable to handle kernel paging request for instruction fetch
Faulting instruction address: 0xf938d040
Oops: Kernel access of bad area, sig: 11 [#1]
---
 arch/powerpc/kernel/head_fsl_booke.S |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
arch/powerpc/kernel/head_fsl_booke.S +10 -3
index 78aac7b..61b6687 100644
@@ -684,6 +684,13 @@ interrupt_base:
 	rlwinm	r12,r12,0,16,1
 	mtspr	SPRN_MAS1,r12
 
+	/* Make up the required permissions for kernel code */
+#ifdef CONFIG_PTE_64BIT
+	li	r13,_PAGE_PRESENT | _PAGE_BAP_SX
+	oris	r13,r13,_PAGE_ACCESSED@h
+#else
+	li	r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
+#endif
 	b	4f
 
 	/* Get the PGD for the current thread */
@@ -691,15 +698,15 @@ interrupt_base:
 	mfspr	r11,SPRN_SPRG_THREAD
 	lwz	r11,PGDIR(r11)
 
-4:
-	/* Make up the required permissions */
+	/* Make up the required permissions for user code */
 #ifdef CONFIG_PTE_64BIT
-	li	r13,_PAGE_PRESENT | _PAGE_EXEC
+	li	r13,_PAGE_PRESENT | _PAGE_BAP_UX
 	oris	r13,r13,_PAGE_ACCESSED@h
 #else
 	li	r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
 #endif
 
+4:
 	FIND_PTE
 	andc.	r13,r13,r11		/* Check permission */
 
Signature · 1 line
1.6.6-rc1.GIT
Applied
#1 lore raw
Quoted 1 line · Li Yang

Check the user/supervisor execution permission base on the code =

address.

Quoted 11 lines

This fixes the following oops on module loading or removing. =20

Unable to handle kernel paging request for instruction fetch
Faulting instruction address: 0xf938d040
Oops: Kernel access of bad area, sig: 11 [#1]

=20

---
arch/powerpc/kernel/head_fsl_booke.S | 13 ++++++++++---

1 files changed, 10 insertions(+), 3 deletions(-)

applied to merge.

I've updated the commit message to be a bit more clear on why we need to = do this.

Thanks for figuring this out.

- k=

#2 lore raw
Quoted 15 lines · Kumar Gala
Quoted 7 lines · Li Yang

Check the user/supervisor execution permission base on the code address. This fixes the following oops on module loading or removing.

Unable to handle kernel paging request for instruction fetch
Faulting instruction address: 0xf938d040
Oops: Kernel access of bad area, sig: 11 [#1]
Quoted 5 lines

---
arch/powerpc/kernel/head_fsl_booke.S | 13 ++++++++++---

1 files changed, 10 insertions(+), 3 deletions(-)
Quoted 3 lines

applied to merge.

I've updated the commit message to be a bit more clear on why we need to do this.

Not looking at the code right now ... but do we have the same issue on 64e ?

Cheers,
Ben.

#5 lore raw
Quoted 7 lines
Quoted 2 lines

Aaron pointed the issue on FSL BookE.
=20

http://lists.ozlabs.org/pipermail/linuxppc-dev/2010-January/079738.htm

Quoted 1 line

l

=20
Right, but I think 64-bit BookE has the same issue. We can=20 fix that later tho.

Ben,

We also find the _PAGE_USER is different between pte-book3e and old fsl-booke
It is UR in old fsl-booke, and is _PAGE_BAP_UR | _PAGE_BAP_SR in pte-book3e,
which will cause the ioremap_flags issue.

Did you have a test your commit
[ea3cc330ac0cd521ff07c7cd432a1848c19a7e92]?

Thanks, Dave

#6 lore raw
Quoted 10 lines · On Fri, 2010-05-14 at 17:14 +0800, Liu Dave-R63238 wrote:
Quoted 7 lines
Quoted 2 lines

Aaron pointed the issue on FSL BookE.

http://lists.ozlabs.org/pipermail/linuxppc-dev/2010-January/079738.htm

Quoted 1 line

l

Right, but I think 64-bit BookE has the same issue. We can fix that later tho.

Ben,

Quoted 8 lines

We also find the _PAGE_USER is different between pte-book3e and old fsl-booke
It is UR in old fsl-booke, and is _PAGE_BAP_UR | _PAGE_BAP_SR in pte-book3e,
which will cause the ioremap_flags issue.

Did you have a test your commit
[ea3cc330ac0cd521ff07c7cd432a1848c19a7e92]?

I tested on some things :-) I keep asking Kumar to send me some e500 gear so I can actually test on it :-)

Cheers,
Ben.

#7 lore raw
In reply to Kumar Gala
Quoted 2 lines

I've updated the commit message to be a bit more clear on why=20 we need to do this.

I'm curious why the _PAGE_EXEC have different definition in pte-book3e.h and pte-fsl-booke.h?

It is UX permission in pte-book3e, but is SX permission in pte-fsl-booke.h.

Thanks, Dave

#8 lore raw
Quoted 8 lines · On Fri, 2010-05-14 at 08:53 +0800, Liu Dave-R63238 wrote:
Quoted 2 lines

I've updated the commit message to be a bit more clear on why we need to do this.

I'm curious why the _PAGE_EXEC have different definition in pte-book3e.h and pte-fsl-booke.h?

It is UX permission in pte-book3e, but is SX permission in pte-fsl-booke.h.

Oh well, there's a whole history here :-)

I'm not 100% sure of the "old" fsl-booke, but pte-book3e uses UX since that's what _PAGE_EXEC really represents from a kernel standpoint, user-execute.

On book3e, we need to account for the HW tablewalk, which means that the PTE can be loaded as-is by the HW. We thus don't get a chance to test whether we are user or supervisor or change the bits accordingly. We thus need _PAGE_EXEC to fall right into UX since that's really what the kernel manipulates it for.

It also means that user pages will not get execute permission in supervisor mode which is a good thing :-)

For kernel-execute, we have a specific permission, which should be obtained via PAGE_KERNEL_EXEC in vmalloc_exec().

Cheers,
Ben.

#9 lore raw
In reply to Kumar Gala
Quoted 15 lines · Kumar Gala
Quoted 7 lines · Li Yang

Check the user/supervisor execution permission base on the code address. This fixes the following oops on module loading or removing.

Unable to handle kernel paging request for instruction fetch
Faulting instruction address: 0xf938d040
Oops: Kernel access of bad area, sig: 11 [#1]
Quoted 5 lines

---
arch/powerpc/kernel/head_fsl_booke.S | 13 ++++++++++---

1 files changed, 10 insertions(+), 3 deletions(-)
Quoted 5 lines

applied to merge.

I've updated the commit message to be a bit more clear on why we need to do this.

Thanks for figuring this out.

Should I pull & send to Linus ?

Cheers,
Ben.

#10 lore raw
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Kumar Gala

On May 7, 2010, at 3:38 AM, Li Yang wrote:
=20

Quoted 1 line

Check the user/supervisor execution permission base on the code =

address.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

This fixes the following oops on module loading or removing. =20

Unable to handle kernel paging request for instruction fetch
Faulting instruction address: 0xf938d040
Oops: Kernel access of bad area, sig: 11 [#1]

=20

---
arch/powerpc/kernel/head_fsl_booke.S | 13 ++++++++++---

1 files changed, 10 insertions(+), 3 deletions(-)
Quoted 4 lines
Quoted 4 lines

=20
applied to merge.
=20
I've updated the commit message to be a bit more clear on why we need =

to do this.

Quoted 4 lines
Quoted 2 lines

=20
Thanks for figuring this out.

=20
Should I pull & send to Linus ?

No, I've got another patch to fix a FTRACE issue with SMP CPU bringup. = Will post a tree for you here shortly.

- k=