1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/arch/parisc/include/asm
John David Anglin 72d95924ee parisc: Try to fix random segmentation faults in package builds
PA-RISC systems with PA8800 and PA8900 processors have had problems
with random segmentation faults for many years.  Systems with earlier
processors are much more stable.

Systems with PA8800 and PA8900 processors have a large L2 cache which
needs per page flushing for decent performance when a large range is
flushed. The combined cache in these systems is also more sensitive to
non-equivalent aliases than the caches in earlier systems.

The majority of random segmentation faults that I have looked at
appear to be memory corruption in memory allocated using mmap and
malloc.

My first attempt at fixing the random faults didn't work. On
reviewing the cache code, I realized that there were two issues
which the existing code didn't handle correctly. Both relate
to cache move-in. Another issue is that the present bit in PTEs
is racy.

1) PA-RISC caches have a mind of their own and they can speculatively
load data and instructions for a page as long as there is a entry in
the TLB for the page which allows move-in. TLBs are local to each
CPU. Thus, the TLB entry for a page must be purged before flushing
the page. This is particularly important on SMP systems.

In some of the flush routines, the flush routine would be called
and then the TLB entry would be purged. This was because the flush
routine needed the TLB entry to do the flush.

2) My initial approach to trying the fix the random faults was to
try and use flush_cache_page_if_present for all flush operations.
This actually made things worse and led to a couple of hardware
lockups. It finally dawned on me that some lines weren't being
flushed because the pte check code was racy. This resulted in
random inequivalent mappings to physical pages.

The __flush_cache_page tmpalias flush sets up its own TLB entry
and it doesn't need the existing TLB entry. As long as we can find
the pte pointer for the vm page, we can get the pfn and physical
address of the page. We can also purge the TLB entry for the page
before doing the flush. Further, __flush_cache_page uses a special
TLB entry that inhibits cache move-in.

When switching page mappings, we need to ensure that lines are
removed from the cache.  It is not sufficient to just flush the
lines to memory as they may come back.

This made it clear that we needed to implement all the required
flush operations using tmpalias routines. This includes flushes
for user and kernel pages.

After modifying the code to use tmpalias flushes, it became clear
that the random segmentation faults were not fully resolved. The
frequency of faults was worse on systems with a 64 MB L2 (PA8900)
and systems with more CPUs (rp4440).

The warning that I added to flush_cache_page_if_present to detect
pages that couldn't be flushed triggered frequently on some systems.

Helge and I looked at the pages that couldn't be flushed and found
that the PTE was either cleared or for a swap page. Ignoring pages
that were swapped out seemed okay but pages with cleared PTEs seemed
problematic.

I looked at routines related to pte_clear and noticed ptep_clear_flush.
The default implementation just flushes the TLB entry. However, it was
obvious that on parisc we need to flush the cache page as well. If
we don't flush the cache page, stale lines will be left in the cache
and cause random corruption. Once a PTE is cleared, there is no way
to find the physical address associated with the PTE and flush the
associated page at a later time.

I implemented an updated change with a parisc specific version of
ptep_clear_flush. It fixed the random data corruption on Helge's rp4440
and rp3440, as well as on my c8000.

At this point, I realized that I could restore the code where we only
flush in flush_cache_page_if_present if the page has been accessed.
However, for this, we also need to flush the cache when the accessed
bit is cleared in ptep_clear_flush_young to keep things synchronized.
The default implementation only flushes the TLB entry.

Other changes in this version are:

1) Implement parisc specific version of ptep_get. It's identical to
default but needed in arch/parisc/include/asm/pgtable.h.
2) Revise parisc implementation of ptep_test_and_clear_young to use
ptep_get (READ_ONCE).
3) Drop parisc implementation of ptep_get_and_clear. We can use default.
4) Revise flush_kernel_vmap_range and invalidate_kernel_vmap_range to
use full data cache flush.
5) Move flush_cache_vmap and flush_cache_vunmap to cache.c. Handle
VM_IOREMAP case in flush_cache_vmap.

At this time, I don't know whether it is better to always flush when
the PTE present bit is set or when both the accessed and present bits
are set. The later saves flushing pages that haven't been accessed,
but we need to flush in ptep_clear_flush_young. It also needs a page
table lookup to find the PTE pointer. The lpa instruction only needs
a page table lookup when the PTE entry isn't in the TLB.

We don't atomically handle setting and clearing the _PAGE_ACCESSED bit.
If we miss an update, we may miss a flush and the cache may get corrupted.
Whether the current code is effectively atomic depends on process control.

When CONFIG_FLUSH_PAGE_ACCESSED is set to zero, the page will eventually
be flushed when the PTE is cleared or in flush_cache_page_if_present. The
_PAGE_ACCESSED bit is not used, so the problem is avoided.

The flush method can be selected using the CONFIG_FLUSH_PAGE_ACCESSED
define in cache.c. The default is 0. I didn't see a large difference
in performance.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
Cc: <stable@vger.kernel.org> # v6.6+
Signed-off-by: Helge Deller <deller@gmx.de>
2024-06-12 01:57:05 +02:00
..
alternative.h parisc: Mark altinstructions read-only and 32-bit aligned 2023-11-25 09:43:17 +01:00
asm-offsets.h kbuild: move asm-offsets.h to include/generated 2009-12-12 13:08:14 +01:00
asmregs.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 153 2019-05-30 11:26:32 -07:00
assembly.h parisc: Avoid clobbering the C/B bits in the PSW with tophys and tovirt macros 2024-02-27 22:51:44 +01:00
atomic.h locking/atomic: parisc: add preprocessor symbols 2023-06-05 09:57:16 +02:00
barrier.h parisc: Add alternative patching to synchronize_caches define 2020-10-15 08:10:38 +02:00
bitops.h Revert "parisc: Show error if wrong 32/64-bit compiler is being used" 2022-08-22 11:09:17 +02:00
bug.h parisc: Fix asm operand number out of range build error in bug table 2023-11-27 11:01:38 +01:00
cache.h parisc: BTLB: Initialize BTLB tables at CPU startup 2023-09-07 09:12:20 +02:00
cacheflush.h parisc: Try to fix random segmentation faults in package builds 2024-06-12 01:57:05 +02:00
cachetype.h Introduce cpu_dcache_is_aliasing() across all architectures 2024-02-22 15:27:19 -08:00
checksum.h parisc: Strip upper 32 bit of sum in csum_ipv6_magic for 64-bit builds 2024-02-27 22:51:45 +01:00
cmpxchg.h parisc: add u16 support to cmpxchg() 2024-04-09 22:06:00 -07:00
compat.h asm-generic: compat: Cleanup duplicate definitions 2022-04-26 13:35:54 -07:00
compat_ucontext.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
current.h parisc: Reduce code size by optimizing get_current() function calls 2022-03-11 19:49:31 +01:00
delay.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
dma-mapping.h dma-mapping: no need to pass a bus_type into get_arch_dma_ops() 2023-02-15 12:35:20 +01:00
dma.h parisc: dma: Add prototype for pcxl_dma_start 2023-08-10 19:12:16 +02:00
dwarf.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
eisa_bus.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
eisa_eeprom.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
elf.h parisc: fix mmap_base calculation when stack grows upwards 2023-11-15 15:30:09 -08:00
extable.h parisc: Fix random data corruption from exception handler 2024-01-30 17:18:58 +01:00
fixmap.h parisc: Don't hardcode assembler bit definitions in tmpalias code 2022-05-23 13:44:24 +02:00
floppy.h arch/*/: remove CONFIG_VIRT_TO_BUS 2022-06-28 13:20:21 +02:00
ftrace.h parisc: ftrace: Add declaration for ftrace_function_trampoline() 2023-08-10 22:51:54 +02:00
futex.h uaccess: remove CONFIG_SET_FS 2022-02-25 09:36:06 +01:00
grfioctl.h parisc: Drop HP-UX constants and structs from grfioctl.h 2023-05-03 17:43:26 +02:00
hardirq.h softirq: Move __ARCH_HAS_DO_SOFTIRQ to Kconfig 2021-02-10 23:34:16 +01:00
hardware.h parisc: Avoid printing the hardware path twice 2022-10-31 15:37:14 +01:00
hash.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hugetlb.h mm: hugetlb: add huge page size param to set_huge_pte_at() 2023-09-29 17:20:47 -07:00
io.h asm/io: remove unnecessary xlate_dev_mem_ptr() and unxlate_dev_mem_ptr() 2023-11-23 10:37:40 +01:00
irq.h parisc: Remove leftover reference to the power_tasklet 2021-01-26 19:57:26 +01:00
irqflags.h parisc: Check if IRQs are disabled when calling arch_local_irq_restore() 2023-06-30 17:14:13 +02:00
jump_label.h work around gcc bugs with 'asm goto' with outputs 2024-02-09 15:57:48 -08:00
kbdleds.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Kbuild char/agp: introduce asm-generic/agp.h 2023-02-13 22:13:29 +01:00
kexec.h parisc: fix compilation when KEXEC=n and KEXEC_FILE=y 2019-12-15 21:05:38 +01:00
kfence.h parisc: Add KFENCE support 2021-10-30 23:11:00 +02:00
kgdb.h parisc: Limit amount of kgdb breakpoints on parisc 2023-05-03 17:41:21 +02:00
kprobes.h parisc/kprobes: always include asm-generic/kprobes.h 2024-02-16 20:18:03 +01:00
ldcw.h parisc: Mark lock_aligned variables 16-byte aligned on SMP 2023-11-25 09:43:17 +01:00
led.h parisc: led: Rewrite LED/LCD driver to utilizize Linux LED subsystem 2023-08-28 17:58:14 +02:00
linkage.h parisc: Fix boot failure of 64-bit kernel 2018-08-21 14:32:44 +02:00
mman.h prctl: generalize PR_SET_MDWE support check to be per-arch 2024-03-26 11:07:22 -07:00
mmu.h parisc: Add vDSO support 2022-03-11 19:49:30 +01:00
mmu_context.h parisc: Use constants to encode the space registers like SR_KERNEL 2022-03-11 19:49:31 +01:00
mmzone.h parisc: Switch from DISCONTIGMEM to SPARSEMEM 2019-05-03 23:47:40 +02:00
module.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
page.h parisc: Define HAVE_ARCH_HUGETLB_UNMAPPED_AREA 2024-05-15 17:14:26 +02:00
parisc-device.h parisc: make parisc_bus_type const 2024-02-27 22:51:44 +01:00
parport.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
patch.h parisc: add support for patching multiple words 2019-06-08 12:56:25 +02:00
pci.h PCI: Remove pci_get_legacy_ide_irq() and asm-generic/pci.h 2022-07-22 17:23:45 -05:00
pdc.h parisc: firmware: Simplify calling non-PA20 functions 2023-09-07 09:12:20 +02:00
pdc_chassis.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
pdcpat.h parisc: Add PDC locking functions for rendezvous code 2022-03-29 21:37:12 +02:00
perf.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
perf_event.h irq_work: Add generic hardirq context callbacks 2010-10-18 19:58:50 +02:00
pgalloc.h parisc: rename PGD_ORDER to PGD_TABLE_ORDER 2022-07-17 17:14:43 -07:00
pgtable.h parisc: Try to fix random segmentation faults in package builds 2024-06-12 01:57:05 +02:00
prefetch.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
processor.h parisc: fix mmap_base calculation when stack grows upwards 2023-11-15 15:30:09 -08:00
psw.h parisc: asm: psw.h: missing header guard 2019-06-25 14:52:26 +02:00
ptrace.h parisc: Use PRIV_USER and PRIV_KERNEL in ptrace.h 2021-11-01 07:36:00 +01:00
ropes.h parisc: sba-iommu: Fix sparse warnigs 2023-08-31 21:42:42 +02:00
rt_sigframe.h parisc: Add vDSO support 2022-03-11 19:49:30 +01:00
runway.h parisc: ccio-dma: Create private runway procfs root entry 2023-08-28 18:00:27 +02:00
seccomp.h parisc: Enable seccomp architecture tracking 2020-11-20 11:16:34 -08:00
sections.h asm-generic: Refactor dereference_[kernel]_function_descriptor() 2022-02-16 23:25:11 +11:00
serial.h parisc: remove empty SERIAL_PORT_DFNS in serial.h 2013-11-30 21:02:18 +01:00
shmparam.h parisc: shmparam.h: Document aliasing requirements of PA-RISC 2023-09-07 08:00:32 +02:00
signal.h parisc: Define sigset_t in parisc uapi header 2024-04-29 13:02:31 +02:00
smp.h parisc: Implement __cpu_die() and __cpu_disable() for CPU hotplugging 2022-03-29 21:37:12 +02:00
socket.h parisc: Define O_NONBLOCK to become 000200000 2020-10-15 08:10:38 +02:00
sparsemem.h parisc: Switch from DISCONTIGMEM to SPARSEMEM 2019-05-03 23:47:40 +02:00
special_insns.h parisc: Fix random data corruption from exception handler 2024-01-30 17:18:58 +01:00
spinlock.h parisc: Fix lightweight spinlock checks to not break futexes 2023-08-10 17:32:09 +02:00
spinlock_types.h parisc: Restore __ldcw_align for PA-RISC 2.0 processors 2023-10-07 20:30:16 +02:00
string.h Revert "parisc: Add assembly implementations for memset, strlen, strcpy, strncpy and strcat" 2021-08-29 10:13:32 -07:00
superio.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
switch_to.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
syscall.h parisc: define syscall_get_error() 2019-07-16 19:23:24 -07:00
thread_info.h parisc: move CPU field back into thread_info 2021-11-04 11:21:47 +01:00
timex.h parisc: define get_cycles macro for arch-override 2022-05-13 23:59:23 +02:00
tlb.h parisc: use pgtable-nopXd instead of 4level-fixup 2019-12-04 19:44:15 -08:00
tlbflush.h parisc: Add vDSO support 2022-03-11 19:49:30 +01:00
topology.h parisc: Switch from GENERIC_CPU_DEVICES to GENERIC_ARCH_TOPOLOGY 2022-03-29 21:37:12 +02:00
traps.h parisc: Fix handling off probe non-access faults 2022-03-11 19:49:30 +01:00
uaccess.h parisc: Fix random data corruption from exception handler 2024-01-30 17:18:58 +01:00
ucontext.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
unaligned.h parisc: Drop ifdef __KERNEL__ from non-uapi kernel headers 2021-11-01 07:36:00 +01:00
unistd.h RISC-V Patches for the 5.19 Merge Window, Part 1 2022-05-31 14:10:54 -07:00
unwind.h parisc: Consolidate unwind initialization calls 2018-08-17 17:00:08 +02:00
vdso.h parisc: Add vDSO support 2022-03-11 19:49:30 +01:00
video.h arch: Rename fbdev header and source files 2024-05-03 17:07:50 +02:00
vmalloc.h mm/vmalloc: Add empty <asm/vmalloc.h> headers and use them from <linux/vmalloc.h> 2019-12-10 10:12:55 +01:00