1
0
Fork 0
alistair23-linux/arch
KarimAllah Ahmed ddd6f0e94d KVM: x86: Update the exit_qualification access bits while walking an address
... to avoid having a stale value when handling an EPT misconfig for MMIO
regions.

MMIO regions that are not passed-through to the guest are handled through
EPT misconfigs. The first time a certain MMIO page is touched it causes an
EPT violation, then KVM marks the EPT entry to cause an EPT misconfig
instead. Any subsequent accesses to the entry will generate an EPT
misconfig.

Things gets slightly complicated with nested guest handling for MMIO
regions that are not passed through from L0 (i.e. emulated by L0
user-space).

An EPT violation for one of these MMIO regions from L2, exits to L0
hypervisor. L0 would then look at the EPT12 mapping for L1 hypervisor and
realize it is not present (or not sufficient to serve the request). Then L0
injects an EPT violation to L1. L1 would then update its EPT mappings. The
EXIT_QUALIFICATION value for L1 would come from exit_qualification variable
in "struct vcpu". The problem is that this variable is only updated on EPT
violation and not on EPT misconfig. So if an EPT violation because of a
read happened first, then an EPT misconfig because of a write happened
afterwards. The L0 hypervisor will still contain exit_qualification value
from the previous read instead of the write and end up injecting an EPT
violation to the L1 hypervisor with an out of date EXIT_QUALIFICATION.

The EPT violation that is injected from L0 to L1 needs to have the correct
EXIT_QUALIFICATION specially for the access bits because the individual
access bits for MMIO EPTs are updated only on actual access of this
specific type. So for the example above, the L1 hypervisor will keep
updating only the read bit in the EPT then resume the L2 guest. The L2
guest would end up causing another exit where the L0 *again* will inject
another EPT violation to L1 hypervisor with *again* an out of date
exit_qualification which indicates a read and not a write. Then this
ping-pong just keeps happening without making any forward progress.

The behavior of mapping MMIO regions changed in:

   commit a340b3e229 ("kvm: Map PFN-type memory regions as writable (if possible)")

... where an EPT violation for a read would also fixup the write bits to
avoid another EPT violation which by acciddent would fix the bug mentioned
above.

This commit fixes this situation and ensures that the access bits for the
exit_qualifcation is up to date. That ensures that even L1 hypervisor
running with a KVM version before the commit mentioned above would still
work.

( The description above assumes EPT to be available and used by L1
  hypervisor + the L1 hypervisor is passing through the MMIO region to the L2
  guest while this MMIO region is emulated by the L0 user-space ).

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: x86@kernel.org
Cc: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
2018-03-16 22:01:30 +01:00
..
alpha locking/xchg/alpha: Fix xchg() and cmpxchg() memory ordering bugs 2018-02-23 08:38:16 +01:00
arc ARC fixes for 4.16-rc4 2018-03-01 14:32:23 -08:00
arm ARM: SoC fixes for 4.16 2018-02-28 16:11:04 -08:00
arm64 ARM: SoC fixes for 4.16 2018-02-28 16:11:04 -08:00
blackfin unify {de,}mangle_poll(), get rid of kernel-side POLL... 2018-02-11 14:37:22 -08:00
c6x The core framework has a handful of patches this time around, mostly due 2018-02-01 16:56:07 -08:00
cris bug.h: work around GCC PR82365 in BUG() 2018-02-21 15:35:43 -08:00
frv unify {de,}mangle_poll(), get rid of kernel-side POLL... 2018-02-11 14:37:22 -08:00
h8300 The core framework has a handful of patches this time around, mostly due 2018-02-01 16:56:07 -08:00
hexagon The core framework has a handful of patches this time around, mostly due 2018-02-01 16:56:07 -08:00
ia64 bug.h: work around GCC PR82365 in BUG() 2018-02-21 15:35:43 -08:00
m32r The core framework has a handful of patches this time around, mostly due 2018-02-01 16:56:07 -08:00
m68k bug.h: work around GCC PR82365 in BUG() 2018-02-21 15:35:43 -08:00
metag The core framework has a handful of patches this time around, mostly due 2018-02-01 16:56:07 -08:00
microblaze Microblaze patches for 4.16-rc1 2018-02-02 09:48:36 -08:00
mips KVM: Introduce paravirtualization hints and KVM_HINTS_DEDICATED 2018-03-06 18:40:44 +01:00
mn10300 The core framework has a handful of patches this time around, mostly due 2018-02-01 16:56:07 -08:00
nios2 nios2 update for v4.16-rc1 2018-02-11 13:52:32 -08:00
openrisc The core framework has a handful of patches this time around, mostly due 2018-02-01 16:56:07 -08:00
parisc Merge branch 'parisc-4.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux 2018-03-02 13:05:20 -08:00
powerpc KVM: Introduce paravirtualization hints and KVM_HINTS_DEDICATED 2018-03-06 18:40:44 +01:00
riscv riscv/barrier: Define __smp_{mb,rmb,wmb} 2018-02-26 08:44:50 -08:00
s390 KVM: Introduce paravirtualization hints and KVM_HINTS_DEDICATED 2018-03-06 18:40:44 +01:00
score arch/score/kernel/setup.c: combine two seq_printf() calls into one call in show_cpuinfo() 2018-02-06 18:32:47 -08:00
sh sh: fix build error for empty CONFIG_BUILTIN_DTB_SOURCE 2018-03-02 09:20:55 +09:00
sparc bug.h: work around GCC PR82365 in BUG() 2018-02-21 15:35:43 -08:00
tile The core framework has a handful of patches this time around, mostly due 2018-02-01 16:56:07 -08:00
um mconsole_proc(): don't mess with file->f_pos 2018-02-09 19:28:01 -08:00
unicore32 lib: optimize cpumask_next_and() 2018-02-06 18:32:44 -08:00
x86 KVM: x86: Update the exit_qualification access bits while walking an address 2018-03-16 22:01:30 +01:00
xtensa xtensa: support DMA buffers in high memory 2018-02-16 19:19:54 -08:00
.gitignore
Kconfig Makefile: introduce CONFIG_CC_STACKPROTECTOR_AUTO 2018-02-06 18:32:44 -08:00