Skip to content

Commit e00b0a2

Browse files
danglin44hdeller
authored andcommitted
parisc: Fix handling off probe non-access faults
Currently, the parisc kernel does not fully support non-access TLB fault handling for probe instructions. In the fast path, we set the target register to zero if it is not a shadowed register. The slow path is not implemented, so we call do_page_fault. The architecture indicates that non-access faults should not cause a page fault from disk. This change adds to code to provide non-access fault support for probe instructions. It also modifies the handling of faults on userspace so that if the address lies in a valid VMA and the access type matches that for the VMA, the probe target register is set to one. Otherwise, the target register is set to zero. This was done to make probe instructions more useful for userspace. Probe instructions are not very useful if they set the target register to zero whenever a page is not present in memory. Nominally, the purpose of the probe instruction is determine whether read or write access to a given address is allowed. This fixes a problem in function pointer comparison noticed in the glibc testsuite (stdio-common/tst-vfprintf-user-type). The same problem is likely in glibc (_dl_lookup_address). V2 adds flush and lpa instruction support to handle_nadtlb_fault. Signed-off-by: John David Anglin <dave.anglin@bell.net> Signed-off-by: Helge Deller <deller@gmx.de>
1 parent f839e5f commit e00b0a2

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

arch/parisc/include/asm/traps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ unsigned long parisc_acctyp(unsigned long code, unsigned int inst);
1818
const char *trap_name(unsigned long code);
1919
void do_page_fault(struct pt_regs *regs, unsigned long code,
2020
unsigned long address);
21+
int handle_nadtlb_fault(struct pt_regs *regs);
2122
#endif
2223

2324
#endif

arch/parisc/kernel/traps.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
662662
by hand. Technically we need to emulate:
663663
fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw
664664
*/
665+
if (code == 17 && handle_nadtlb_fault(regs))
666+
return;
665667
fault_address = regs->ior;
666668
fault_space = regs->isr;
667669
break;

arch/parisc/mm/fault.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,92 @@ void do_page_fault(struct pt_regs *regs, unsigned long code,
425425
}
426426
pagefault_out_of_memory();
427427
}
428+
429+
/* Handle non-access data TLB miss faults.
430+
*
431+
* For probe instructions, accesses to userspace are considered allowed
432+
* if they lie in a valid VMA and the access type matches. We are not
433+
* allowed to handle MM faults here so there may be situations where an
434+
* actual access would fail even though a probe was successful.
435+
*/
436+
int
437+
handle_nadtlb_fault(struct pt_regs *regs)
438+
{
439+
unsigned long insn = regs->iir;
440+
int breg, treg, xreg, val = 0;
441+
struct vm_area_struct *vma, *prev_vma;
442+
struct task_struct *tsk;
443+
struct mm_struct *mm;
444+
unsigned long address;
445+
unsigned long acc_type;
446+
447+
switch (insn & 0x380) {
448+
case 0x280:
449+
/* FDC instruction */
450+
fallthrough;
451+
case 0x380:
452+
/* PDC and FIC instructions */
453+
if (printk_ratelimit()) {
454+
pr_warn("BUG: nullifying cache flush/purge instruction\n");
455+
show_regs(regs);
456+
}
457+
if (insn & 0x20) {
458+
/* Base modification */
459+
breg = (insn >> 21) & 0x1f;
460+
xreg = (insn >> 16) & 0x1f;
461+
if (breg && xreg)
462+
regs->gr[breg] += regs->gr[xreg];
463+
}
464+
regs->gr[0] |= PSW_N;
465+
return 1;
466+
467+
case 0x180:
468+
/* PROBE instruction */
469+
treg = insn & 0x1f;
470+
if (regs->isr) {
471+
tsk = current;
472+
mm = tsk->mm;
473+
if (mm) {
474+
/* Search for VMA */
475+
address = regs->ior;
476+
mmap_read_lock(mm);
477+
vma = find_vma_prev(mm, address, &prev_vma);
478+
mmap_read_unlock(mm);
479+
480+
/*
481+
* Check if access to the VMA is okay.
482+
* We don't allow for stack expansion.
483+
*/
484+
acc_type = (insn & 0x40) ? VM_WRITE : VM_READ;
485+
if (vma
486+
&& address >= vma->vm_start
487+
&& (vma->vm_flags & acc_type) == acc_type)
488+
val = 1;
489+
}
490+
}
491+
if (treg)
492+
regs->gr[treg] = val;
493+
regs->gr[0] |= PSW_N;
494+
return 1;
495+
496+
case 0x300:
497+
/* LPA instruction */
498+
if (insn & 0x20) {
499+
/* Base modification */
500+
breg = (insn >> 21) & 0x1f;
501+
xreg = (insn >> 16) & 0x1f;
502+
if (breg && xreg)
503+
regs->gr[breg] += regs->gr[xreg];
504+
}
505+
treg = insn & 0x1f;
506+
if (treg)
507+
regs->gr[treg] = 0;
508+
regs->gr[0] |= PSW_N;
509+
return 1;
510+
511+
default:
512+
break;
513+
}
514+
515+
return 0;
516+
}

0 commit comments

Comments
 (0)