KVM: PPC: mmio: Reject instructions that access more than mmio.data size
authorFabiano Rosas <farosas@linux.ibm.com>
Tue, 25 Jan 2022 21:56:53 +0000 (18:56 -0300)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 31 Jan 2022 02:43:00 +0000 (13:43 +1100)
commit3f831504482ab0d0d53d1966987959d1485345cc
tree53c27f21502894e16a69b534c0324b64c8442c3c
parentb99234b918c6e36b9aa0a5b2981e86b6bd11f8e2
KVM: PPC: mmio: Reject instructions that access more than mmio.data size

The MMIO interface between the kernel and userspace uses a structure
that supports a maximum of 8-bytes of data. Instructions that access
more than that need to be emulated in parts.

We currently don't have generic support for splitting the emulation in
parts and each set of instructions needs to be explicitly included.

There's already an error message being printed when a load or store
exceeds the mmio.data buffer but we don't fail the emulation until
later at kvmppc_complete_mmio_load and even then we allow userspace to
make a partial copy of the data, which ends up overwriting some fields
of the mmio structure.

This patch makes the emulation fail earlier at kvmppc_handle_load|store,
which will send a Program interrupt to the guest. This is better than
allowing the guest to proceed with partial data.

Note that this was caught in a somewhat artificial scenario using
quadword instructions (lq/stq), there's no account of an actual guest
in the wild running instructions that are not properly emulated.

(While here, remove the "bad MMIO" messages. The caller already has an
error message.)

Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220125215655.1026224-4-farosas@linux.ibm.com
arch/powerpc/kvm/powerpc.c