linux/arch/parisc/include/asm
John David Anglin 01ab605704 parisc: Fix some PTE/TLB race conditions and optimize __flush_tlb_range based on timing results
The increased use of pdtlb/pitlb instructions seemed to increase the
frequency of random segmentation faults building packages. Further, we
had a number of cases where TLB inserts would repeatedly fail and all
forward progress would stop. The Haskell ghc package caused a lot of
trouble in this area. The final indication of a race in pte handling was
this syslog entry on sibaris (C8000):

 swap_free: Unused swap offset entry 00000004
 BUG: Bad page map in process mysqld  pte:00000100 pmd:019bbec5
 addr:00000000ec464000 vm_flags:00100073 anon_vma:0000000221023828 mapping: (null) index:ec464
 CPU: 1 PID: 9176 Comm: mysqld Not tainted 4.0.0-2-parisc64-smp #1 Debian 4.0.5-1
 Backtrace:
  [<0000000040173eb0>] show_stack+0x20/0x38
  [<0000000040444424>] dump_stack+0x9c/0x110
  [<00000000402a0d38>] print_bad_pte+0x1a8/0x278
  [<00000000402a28b8>] unmap_single_vma+0x3d8/0x770
  [<00000000402a4090>] zap_page_range+0xf0/0x198
  [<00000000402ba2a4>] SyS_madvise+0x404/0x8c0

Note that the pte value is 0 except for the accessed bit 0x100. This bit
shouldn't be set without the present bit.

It should be noted that the madvise system call is probably a trigger for many
of the random segmentation faults.

In looking at the kernel code, I found the following problems:

1) The pte_clear define didn't take TLB lock when clearing a pte.
2) We didn't test pte present bit inside lock in exception support.
3) The pte and tlb locks needed to merged in order to ensure consistency
between page table and TLB. This also has the effect of serializing TLB
broadcasts on SMP systems.

The attached change implements the above and a few other tweaks to try
to improve performance. Based on the timing code, TLB purges are very
slow (e.g., ~ 209 cycles per page on rp3440). Thus, I think it
beneficial to test the split_tlb variable to avoid duplicate purges.
Probably, all PA 2.0 machines have combined TLBs.

I dropped using __flush_tlb_range in flush_tlb_mm as I realized all
applications and most threads have a stack size that is too large to
make this useful. I added some comments to this effect.

Since implementing 1 through 3, I haven't had any random segmentation
faults on mx3210 (rp3440) in about one week of building code and running
as a Debian buildd.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
Cc: stable@vger.kernel.org # v3.18+
Signed-off-by: Helge Deller <deller@gmx.de>
2015-07-10 21:47:47 +02:00
..
agp.h
asm-offsets.h
asmregs.h
assembly.h parisc: provide macro to create exception table entries 2013-11-07 22:25:33 +01:00
atomic.h locking,arch: Use ACCESS_ONCE() instead of cast to volatile in atomic_read() 2014-10-03 06:06:23 +02:00
bitops.h arch,parisc: Convert smp_mb__*() 2014-04-18 14:20:41 +02:00
bug.h [PARISC] fix missing TAINT_WARN problem 2012-06-05 14:10:17 +09:00
bugs.h
cache.h
cacheflush.h sched/preempt, mm/kmap: Explicitly disable/enable preemption in kmap_atomic_* 2015-05-19 08:39:14 +02:00
checksum.h
cmpxchg.h arch: Remove __ARCH_HAVE_CMPXCHG 2015-05-13 10:55:42 +02:00
compat.h parisc: convert msgrcv and msgsnd syscalls to use compat layer 2013-02-20 22:56:50 +01:00
compat_ucontext.h
current.h
delay.h parisc: make udelay() SMP-safe 2013-11-07 22:28:26 +01:00
dma-mapping.h remove <asm/scatterlist.h> 2015-05-05 13:35:39 -06:00
dma.h
eisa_bus.h
eisa_eeprom.h
elf.h parisc,metag: Fix crashes due to stack randomization on stack-grows-upwards architectures 2015-05-12 22:03:44 +02:00
fb.h
fixmap.h
floppy.h parisc: remove IRQF_DISABLED 2013-02-20 22:50:26 +01:00
ftrace.h ftrace: Make CALLER_ADDRx macros more generic 2014-05-21 03:10:32 -04:00
futex.h
grfioctl.h
hardirq.h parisc: do not count IPI calls twice 2013-11-07 22:28:54 +01:00
hardware.h
ide.h
io.h parisc: io: implement dummy relaxed accessor macros for writes 2014-10-20 18:49:18 +01:00
irq.h
irqflags.h
kbdleds.h
Kbuild remove scatterlist.h generation from arch Kbuild files 2015-05-19 09:14:34 -06:00
kmap_types.h
ldcw.h parisc: fix out-of-register compiler error in ldcw inline assembler function 2014-12-26 17:47:01 +01:00
led.h
linkage.h
machdep.h
mc146818rtc.h
mckinley.h
mm-arch-hooks.h mm: new mm hook framework 2015-06-24 17:49:41 -07:00
mmu.h
mmu_context.h
mmzone.h parisc: fix kernel BUG at arch/parisc/include/asm/mmzone.h:50 (part 2) 2013-06-18 20:20:21 +02:00
module.h Make most arch asm/module.h files use asm-generic/module.h 2012-09-28 14:31:03 +09:30
page.h parisc: Remove unused CONFIG_PARISC_TMPALIAS code 2014-03-23 16:46:30 +01:00
parisc-device.h parisc: Fix interrupt routing for C8000 serial ports 2013-07-31 23:42:32 +02:00
parport.h ARCH: drivers remove __dev* attributes. 2013-01-03 15:57:13 -08:00
pci.h Merge branch 'for-4.2/sg' of git://git.kernel.dk/linux-block 2015-06-25 15:22:36 -07:00
pdc.h UAPI: (Scripted) Disintegrate arch/parisc/include/asm 2012-10-16 21:28:05 +01:00
pdc_chassis.h
pdcpat.h
perf.h
perf_event.h
pgalloc.h parisc: Replace PT_NLEVELS with CONFIG_PGTABLE_LEVELS 2015-04-21 22:04:03 +02:00
pgtable.h parisc: Fix some PTE/TLB race conditions and optimize __flush_tlb_range based on timing results 2015-07-10 21:47:47 +02:00
prefetch.h
processor.h parisc: hpux - Remove hpux gateway page 2015-02-16 22:35:06 +01:00
psw.h
ptrace.h parisc: add kernel audit feature 2013-11-07 22:27:20 +01:00
ropes.h
rt_sigframe.h
rtc.h
runway.h
sections.h
serial.h parisc: remove empty SERIAL_PORT_DFNS in serial.h 2013-11-30 21:02:18 +01:00
shmparam.h parisc: change value of SHMLBA from 0x00400000 to PAGE_SIZE 2014-04-13 15:00:53 +02:00
signal.h Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal 2013-02-23 18:50:11 -08:00
smp.h
socket.h parisc: break out SOCK_NONBLOCK define to own asm header file 2013-11-19 23:36:17 +01:00
special_insns.h parisc: optimize mtsp(0,sr) inline assembly 2013-07-09 22:09:21 +02:00
spinlock.h parisc: locks: remove redundant arch_*_relax operations 2014-03-23 17:01:23 +01:00
spinlock_types.h
string.h
superio.h
switch_to.h
syscall.h ARCH: AUDIT: implement syscall_get_arch for all arches 2014-09-23 16:20:10 -04:00
termios.h UAPI: (Scripted) Disintegrate arch/parisc/include/asm 2012-10-16 21:28:05 +01:00
thread_info.h arch: Remove exec_domain from remaining archs 2015-04-12 21:03:30 +02:00
timex.h
tlb.h
tlbflush.h parisc: Fix some PTE/TLB race conditions and optimize __flush_tlb_range based on timing results 2015-07-10 21:47:47 +02:00
traps.h parisc: mark parisc_terminate() noreturn and cold. 2013-10-13 17:44:49 +02:00
uaccess.h parisc: macro whitespace fixes 2015-02-17 10:39:14 +01:00
ucontext.h
unaligned.h
unistd.h sys_sgetmask/sys_ssetmask: add CONFIG_SGETMASK_SYSCALL 2014-06-04 16:54:14 -07:00
unwind.h