linux/arch/nios2/mm
Simon Schuster 83ab598362 nios2: do not introduce conflicting mappings when flushing tlb entries
The NIOS2 hardware does not support conflicting mappings for the same
virtual address (see Nios II Processor Reference Guide from 2023.08.28):

 "The operating system software is responsible for guaranteeing that
  multiple TLB entries do not map the same virtual address. The hardware
  behavior is undefined when multiple entries map the same virtual
  address."

When flushing tlb-entries, the kernel may violate this invariant for
virtual addresses related to PID 0 as flushing is currently implemented
by assigning physical address, pid and flags to 0.

A small example:

Before flushing TLB mappings for pid:0x42:
  dump tlb-entries for line=0xd (addr 000d0000):
  -- way:09 vpn:0x0006d000 phys:0x01145000 pid:0x00 flags:rw--c
  ...
  -- way:0d vpn:0x0006d000 phys:0x02020000 pid:0x42 flags:rw--c

After flushing TLB mappings for pid:0x42:
  dump tlb-entries for line=0xd (addr 000d0000):
  -- way:09 vpn:0x0006d000 phys:0x01145000 pid:0x00 flags:rw--c
  ...
  -- way:0d vpn:0x0006d000 phys:0x00000000 pid:0x00 flags:-----

As functions such as replace_tlb_one_pid operate on the assumption of
unique mappings, this can cause repeated pagefaults for a single
address that are not covered by the existing spurious pagefault handling.

This commit fixes this issue by keeping the pid field of the entries
when flushing. That way, no conflicting mappings are introduced as the
pair of <address,pid> is now kept unique:

Fixed example after flushing TLB mappings for pid:0x42:
  dump tlb-entries for line=0xd (addr 000d0000):
  -- way:09 vpn:0x0006d000 phys:0x01145000 pid:0x00 flags:rw--c
  ...
  -- way:0d vpn:0x0006d000 phys:0x00000000 pid:0x42 flags:-----

When flushing the complete tlb/initialising all entries, the way is
used as a substitute mmu pid value for the "invalid" entries.

Signed-off-by: Simon Schuster <schuster.simon@siemens-energy.com>
Signed-off-by: Andreas Oetken <andreas.oetken@siemens-energy.com>
Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>
2025-04-24 17:19:02 -05:00
..
cacheflush.c nios2: fix flush_dcache_page() for usage from irq context 2023-08-24 16:20:31 -07:00
dma-mapping.c dma-direct: make uncached_kernel_address more general 2020-03-16 10:48:09 +01:00
extable.c
fault.c mm/fault: convert remaining simple cases to lock_mm_and_find_vma() 2023-06-24 14:12:58 -07:00
init.c arch, mm: make releasing of memory to page allocator more explicit 2025-03-17 22:06:53 -07:00
ioremap.c nios2: add support for folded p4d page tables 2020-06-04 19:06:21 -07:00
Makefile
mmu_context.c
pgtable.c asm-generic: pgalloc: provide generic __pgd_{alloc,free} 2025-01-25 20:22:24 -08:00
tlb.c nios2: do not introduce conflicting mappings when flushing tlb entries 2025-04-24 17:19:02 -05:00
uaccess.c