s390/pci: Fix s390_mmio_read/write with MIO
authorNiklas Schnelle <schnelle@linux.ibm.com>
Thu, 26 Mar 2020 11:22:50 +0000 (12:22 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Thu, 14 May 2020 21:21:37 +0000 (23:21 +0200)
commitf058599e22d59e594e5aae1dc10560568d8f4a8b
tree37f65457c918fc6774626128eab7b34a77b02ffa
parent2ef96a5bb12be62ef75b5828c0aab838ebb29cb8
s390/pci: Fix s390_mmio_read/write with MIO

The s390_mmio_read/write syscalls are currently broken when running with
MIO.

The new pcistb_mio/pcstg_mio/pcilg_mio instructions are executed
similiarly to normal load/store instructions and do address translation
in the current address space. That means inside the kernel they are
aware of mappings into kernel address space while outside the kernel
they use user space mappings (usually created through mmap'ing a PCI
device file).

Now when existing user space applications use the s390_pci_mmio_write
and s390_pci_mmio_read syscalls, they pass I/O addresses that are mapped
into user space so as to be usable with the new instructions without
needing a syscall. Accessing these addresses with the old instructions
as done currently leads to a kernel panic.

Also, for such a user space mapping there may not exist an equivalent
kernel space mapping which means we can't just use the new instructions
in kernel space.

Instead of replicating user mappings in the kernel which then might
collide with other mappings, we can conceptually execute the new
instructions as if executed by the user space application using the
secondary address space. This even allows us to directly store to the
user pointer without the need for copy_to/from_user().

Cc: stable@vger.kernel.org
Fixes: 71ba41c9b1d9 ("s390/pci: provide support for MIO instructions")
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Reviewed-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/include/asm/pci_io.h
arch/s390/pci/pci_mmio.c