sparc64: Fix top-level fault handling bugs.
David Miller
maintainerPATCH 7/10 sparc64: Fix top-level fault handling bugs.
Make get_user_insn() able to cope with huge PMDs.
Next, make do_fault_siginfo() more robust when get_user_insn() can't actually fetch the instruction. In particular, use the MMU announced fault address when that happens, instead of calling compute_effective_address() and computing garbage.
--- arch/sparc/mm/fault_64.c | 75 ++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 28 deletions(-)
arch/sparc/mm/fault_64.c +47 -28
@@ -96,38 +96,48 @@ static unsigned int get_user_insn(unsigned long tpc)pte_t *ptep, pte;unsigned long pa;u32 insn =0 ; -unsigned long pstate;if (pgd_none (*pgdp)) - goto outret; + goto out; pudp =pud_offset (pgdp, tpc);if (pud_none (*pudp)) - goto outret; - pmdp =pmd_offset (pudp, tpc); -if (pmd_none (*pmdp)) - goto outret; + goto out;/* This disables preemption for us as well. */ - __asm__ __volatile__("rdpr %%pstate, %0" :"=r" (pstate)); - __asm__ __volatile__("wrpr %0, %1, %%pstate" - : :"r" (pstate),"i" (PSTATE_IE )); - ptep =pte_offset_map (pmdp, tpc); - pte = *ptep; -if (!pte_present (pte)) - goto out; +local_irq_disable (); + + pmdp =pmd_offset (pudp, tpc); +if (pmd_none (*pmdp)) + goto out_irq_enable; - pa = (pte_pfn (pte) <<PAGE_SHIFT ); - pa += (tpc & ~PAGE_MASK ); +if (pmd_trans_huge (*pmdp)) { +if (pmd_trans_splitting (*pmdp)) + goto out_irq_enable; -/* Use phys bypass so we don't pollute dtlb/dcache. */ - __asm__ __volatile__("lduwa [%1] %2, %0" - :"=r" (insn) - :"r" (pa),"i" (ASI_PHYS_USE_EC )); + pa =pmd_pfn (*pmdp) <<PAGE_SHIFT ; + pa += tpc & ~HPAGE_MASK ; +/* Use phys bypass so we don't pollute dtlb/dcache. */ + __asm__ __volatile__("lduwa [%1] %2, %0" + :"=r" (insn) + :"r" (pa),"i" (ASI_PHYS_USE_EC )); + }else { + ptep =pte_offset_map (pmdp, tpc); + pte = *ptep; +if (pte_present (pte)) { + pa = (pte_pfn (pte) <<PAGE_SHIFT ); + pa += (tpc & ~PAGE_MASK ); + +/* Use phys bypass so we don't pollute dtlb/dcache. */ + __asm__ __volatile__("lduwa [%1] %2, %0" + :"=r" (insn) + :"r" (pa),"i" (ASI_PHYS_USE_EC )); + } +pte_unmap (ptep); + } +out_irq_enable: +local_irq_enable (); out: -pte_unmap (ptep); - __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : :"r" (pstate)); -outret:return insn; }
@@ -153,7 +163,8 @@ show_signal_msg(struct pt_regs *regs, int sig, int code, }static void do_fault_siginfo (int code,int sig,struct pt_regs *regs, -unsigned int insn,int fault_code) +unsigned long fault_addr,unsigned int insn, +int fault_code) {unsigned long addr;siginfo_t info;
@@ -161,10 +172,18 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs, info.si_code = code; info.si_signo = sig; info.si_errno =0 ; -if (fault_code &FAULT_CODE_ITLB ) +if (fault_code &FAULT_CODE_ITLB ) { addr = regs->tpc; -else - addr =compute_effective_address (regs, insn,0 ); + }else { +/* If we were able to probe the faulting instruction, use it +* to compute a precise fault address. Otherwise use the fault +* time provided address which may only have page granularity. +*/ +if (insn) + addr =compute_effective_address (regs, insn,0 ); +else + addr = fault_addr; + } info.si_addr = (void __user *) addr; info.si_trapno =0 ;
@@ -239,7 +258,7 @@ static void __kprobes do_kernel_fault(struct pt_regs *regs, int si_code,/* The si_code was set to make clear whether * this was a SEGV_MAPERR or SEGV_ACCERR fault. */ -do_fault_siginfo (si_code,SIGSEGV , regs, insn, fault_code); +do_fault_siginfo (si_code,SIGSEGV , regs, address, insn, fault_code);return ; }
@@ -525,7 +544,7 @@ do_sigbus:* Send a sigbus, regardless of whether we were in kernel * or user mode. */ -do_fault_siginfo (BUS_ADRERR ,SIGBUS , regs, insn, fault_code); +do_fault_siginfo (BUS_ADRERR ,SIGBUS , regs, address, insn, fault_code);/* Kernel mode? Handle exceptions or die */ if (regs->tstate &TSTATE_PRIV )
Signature · 1 line
1.8.1.2
Quoted 8 lines
Make
get_user_insn()able to cope with huge PMDs.Next, make
do_fault_siginfo()more robust whenget_user_insn()can't actually fetch the instruction. In particular, use the MMU announced fault address when that happens, instead of callingcompute_effective_address()and computing garbage.Signed-off-by David S. Miller <[email protected]>
This patch happens to introduce a compile failure on a computer that has THP diabled:
CC arch/sparc/mm/fault_64.oarch/sparc/mm/fault_64.c: In function ¡get_user_insn¢:arch/sparc/mm/fault_64.c:117:3: error: implicit declaration of function ¡pmd_pfn¢ [-Werror=implicit-function-declaration]
arch/sparc/include/asm/pgtable_64.h has pmd_pfn declared only for THP.
Quoted 130 lines
--- arch/sparc/mm/fault_64.c | 75 ++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 28 deletions(-)arch/sparc/mm/fault_64.c +47
-28@@ -96,38 +96,48 @@ static unsigned int get_user_insn(unsigned long tpc)pte_t *ptep, pte;unsigned long pa;u32 insn =0 ; -unsigned long pstate;if (pgd_none (*pgdp)) - goto outret; + goto out; pudp =pud_offset (pgdp, tpc);if (pud_none (*pudp)) - goto outret; - pmdp =pmd_offset (pudp, tpc); -if (pmd_none (*pmdp)) - goto outret; + goto out;/* This disables preemption for us as well. */ - __asm__ __volatile__("rdpr %%pstate, %0" :"=r" (pstate)); - __asm__ __volatile__("wrpr %0, %1, %%pstate" - : :"r" (pstate),"i" (PSTATE_IE )); - ptep =pte_offset_map (pmdp, tpc); - pte = *ptep; -if (!pte_present (pte)) - goto out; +local_irq_disable (); + + pmdp =pmd_offset (pudp, tpc); +if (pmd_none (*pmdp)) + goto out_irq_enable; - pa = (pte_pfn (pte) <<PAGE_SHIFT ); - pa += (tpc & ~PAGE_MASK ); +if (pmd_trans_huge (*pmdp)) { +if (pmd_trans_splitting (*pmdp)) + goto out_irq_enable; -/* Use phys bypass so we don't pollute dtlb/dcache. */ - __asm__ __volatile__("lduwa [%1] %2, %0" - :"=r" (insn) - :"r" (pa),"i" (ASI_PHYS_USE_EC )); + pa =pmd_pfn (*pmdp) <<PAGE_SHIFT ; + pa += tpc & ~HPAGE_MASK ; +/* Use phys bypass so we don't pollute dtlb/dcache. */ + __asm__ __volatile__("lduwa [%1] %2, %0" + :"=r" (insn) + :"r" (pa),"i" (ASI_PHYS_USE_EC )); + }else { + ptep =pte_offset_map (pmdp, tpc); + pte = *ptep; +if (pte_present (pte)) { + pa = (pte_pfn (pte) <<PAGE_SHIFT ); + pa += (tpc & ~PAGE_MASK ); + +/* Use phys bypass so we don't pollute dtlb/dcache. */ + __asm__ __volatile__("lduwa [%1] %2, %0" + :"=r" (insn) + :"r" (pa),"i" (ASI_PHYS_USE_EC )); + } +pte_unmap (ptep); + } +out_irq_enable: +local_irq_enable (); out: -pte_unmap (ptep); - __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : :"r" (pstate)); -outret:return insn; }@@ -153,7 +163,8 @@ show_signal_msg(struct pt_regs *regs, int sig, int code, }static void do_fault_siginfo (int code,int sig,struct pt_regs *regs, -unsigned int insn,int fault_code) +unsigned long fault_addr,unsigned int insn, +int fault_code) {unsigned long addr;siginfo_t info;@@ -161,10 +172,18 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs, info.si_code = code; info.si_signo = sig; info.si_errno =0 ; -if (fault_code &FAULT_CODE_ITLB ) +if (fault_code &FAULT_CODE_ITLB ) { addr = regs->tpc; -else - addr =compute_effective_address (regs, insn,0 ); + }else { +/* If we were able to probe the faulting instruction, use it +* to compute a precise fault address. Otherwise use the fault +* time provided address which may only have page granularity. +*/ +if (insn) + addr =compute_effective_address (regs, insn,0 ); +else + addr = fault_addr; + } info.si_addr = (void __user *) addr; info.si_trapno =0 ;@@ -239,7 +258,7 @@ static void __kprobes do_kernel_fault(struct pt_regs *regs, int si_code,/* The si_code was set to make clear whether * this was a SEGV_MAPERR or SEGV_ACCERR fault. */ -do_fault_siginfo (si_code,SIGSEGV , regs, insn, fault_code); +do_fault_siginfo (si_code,SIGSEGV , regs, address, insn, fault_code);return ; }@@ -525,7 +544,7 @@ do_sigbus:* Send a sigbus, regardless of whether we were in kernel * or user mode. */ -do_fault_siginfo (BUS_ADRERR ,SIGBUS , regs, insn, fault_code); +do_fault_siginfo (BUS_ADRERR ,SIGBUS , regs, address, insn, fault_code);/* Kernel mode? Handle exceptions or die */ if (regs->tstate &TSTATE_PRIV )
Signature · 1 line
Meelis Roos ([email protected]) http://www.cs.ut.ee/~mroos/
David Miller
maintainerRnJvbTogTWVlbGlzIFJvb3MgPG1yb29zQHV0LmVlPg0KRGF0ZTogRnJpLCAyIE1heSAyMDE0IDA3 OjUxOjEzICswMzAwIChFRVNUKQ0KDQo+PiBNYWtlIGdldF91c2VyX2luc24oKSBhYmxlIHRvIGNv cGUgd2l0aCBodWdlIFBNRHMuDQo+PiANCj4+IE5leHQsIG1ha2UgZG9fZmF1bHRfc2lnaW5mbygp IG1vcmUgcm9idXN0IHdoZW4gZ2V0X3VzZXJfaW5zbigpIGNhbid0DQo+PiBhY3R1YWxseSBmZXRj aCB0aGUgaW5zdHJ1Y3Rpb24uICBJbiBwYXJ0aWN1bGFyLCB1c2UgdGhlIE1NVSBhbm5vdW5jZWQN Cj4+IGZhdWx0IGFkZHJlc3Mgd2hlbiB0aGF0IGhhcHBlbnMsIGluc3RlYWQgb2YgY2FsbGluZw0K Pj4gY29tcHV0ZV9lZmZlY3RpdmVfYWRkcmVzcygpIGFuZCBjb21wdXRpbmcgZ2FyYmFnZS4NCj4+ IA0KPj4gU2lnbmVkLW9mZi1ieTogRGF2aWQgUy4gTWlsbGVyIDxkYXZlbUBkYXZlbWxvZnQubmV0 Pg0KPiANCj4gVGhpcyBwYXRjaCBoYXBwZW5zIHRvIGludHJvZHVjZSBhIGNvbXBpbGUgZmFpbHVy ZSBvbiBhIGNvbXB1dGVyIHRoYXQgaGFzIA0KPiBUSFAgZGlhYmxlZDoNCj4gDQo+ICAgQ0MgICAg ICBhcmNoL3NwYXJjL21tL2ZhdWx0XzY0Lm8NCj4gYXJjaC9zcGFyYy9tbS9mYXVsdF82NC5jOiBJ biBmdW5jdGlvbiChZ2V0X3VzZXJfaW5zbqI6DQo+IGFyY2gvc3BhcmMvbW0vZmF1bHRfNjQuYzox MTc6MzogZXJyb3I6IGltcGxpY2l0IGRlY2xhcmF0aW9uIG9mIGZ1bmN0aW9uIKFwbWRfcGZuoiBb LVdlcnJvcj1pbXBsaWNpdC1mdW5jdGlvbi1kZWNsYXJhdGlvbl0NCj4gDQo+IGFyY2gvc3BhcmMv aW5jbHVkZS9hc20vcGd0YWJsZV82NC5oIGhhcyBwbWRfcGZuIGRlY2xhcmVkIG9ubHkgZm9yIFRI UC4NCg0KVGhhbmtzIGEgbG90LCBJJ2xsIGZpeCB0aGlzIGJ5IGFkZGluZyB0aGUgYXBwcm9wcmlh dGUgaWZkZWYgYXJvdW5kDQp0aGF0IGNvZGUuDQo