Commit e7177c7
KVM: x86: Don't (re)check L1 intercepts when completing userspace I/O
commit e750f85 upstream.
When completing emulation of instruction that generated a userspace exit
for I/O, don't recheck L1 intercepts as KVM has already finished that
phase of instruction execution, i.e. has already committed to allowing L2
to perform I/O. If L1 (or host userspace) modifies the I/O permission
bitmaps during the exit to userspace, KVM will treat the access as being
intercepted despite already having emulated the I/O access.
Pivot on EMULTYPE_NO_DECODE to detect that KVM is completing emulation.
Of the three users of EMULTYPE_NO_DECODE, only complete_emulated_io() (the
intended "recipient") can reach the code in question. gp_interception()'s
use is mutually exclusive with is_guest_mode(), and
complete_emulated_insn_gp() unconditionally pairs EMULTYPE_NO_DECODE with
EMULTYPE_SKIP.
The bad behavior was detected by a syzkaller program that toggles port I/O
interception during the userspace I/O exit, ultimately resulting in a WARN
on vcpu->arch.pio.count being non-zero due to KVM no completing emulation
of the I/O instruction.
WARNING: CPU: 23 PID: 1083 at arch/x86/kvm/x86.c:8039 emulator_pio_in_out+0x154/0x170 [kvm]
Modules linked in: kvm_intel kvm irqbypass
CPU: 23 UID: 1000 PID: 1083 Comm: repro Not tainted 6.16.0-rc5-c1610d2d66b1-next-vm #74 NONE
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
RIP: 0010:emulator_pio_in_out+0x154/0x170 [kvm]
PKRU: 55555554
Call Trace:
<TASK>
kvm_fast_pio+0xd6/0x1d0 [kvm]
vmx_handle_exit+0x149/0x610 [kvm_intel]
kvm_arch_vcpu_ioctl_run+0xda8/0x1ac0 [kvm]
kvm_vcpu_ioctl+0x244/0x8c0 [kvm]
__x64_sys_ioctl+0x8a/0xd0
do_syscall_64+0x5d/0xc60
entry_SYSCALL_64_after_hwframe+0x4b/0x53
</TASK>
Reported-by: [email protected]
Closes: https://lore.kernel.org/all/[email protected]
Fixes: 8a76d7f ("KVM: x86: Add x86 callback for intercept check")
Cc: [email protected]
Cc: Jim Mattson <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Sean Christopherson <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>1 parent 716dceb commit e7177c7
3 files changed
+13
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5104 | 5104 | | |
5105 | 5105 | | |
5106 | 5106 | | |
5107 | | - | |
| 5107 | + | |
5108 | 5108 | | |
5109 | 5109 | | |
5110 | 5110 | | |
5111 | 5111 | | |
5112 | | - | |
5113 | 5112 | | |
5114 | 5113 | | |
5115 | 5114 | | |
| |||
5157 | 5156 | | |
5158 | 5157 | | |
5159 | 5158 | | |
5160 | | - | |
| 5159 | + | |
5161 | 5160 | | |
5162 | 5161 | | |
5163 | 5162 | | |
| |||
5186 | 5185 | | |
5187 | 5186 | | |
5188 | 5187 | | |
5189 | | - | |
| 5188 | + | |
5190 | 5189 | | |
5191 | 5190 | | |
5192 | 5191 | | |
| |||
5240 | 5239 | | |
5241 | 5240 | | |
5242 | 5241 | | |
5243 | | - | |
| 5242 | + | |
5244 | 5243 | | |
5245 | 5244 | | |
5246 | 5245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
234 | 233 | | |
235 | 234 | | |
236 | 235 | | |
| |||
514 | 513 | | |
515 | 514 | | |
516 | 515 | | |
517 | | - | |
| 516 | + | |
518 | 517 | | |
519 | 518 | | |
520 | 519 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8567 | 8567 | | |
8568 | 8568 | | |
8569 | 8569 | | |
8570 | | - | |
8571 | | - | |
8572 | | - | |
8573 | | - | |
8574 | | - | |
8575 | 8570 | | |
8576 | 8571 | | |
8577 | 8572 | | |
| |||
8655 | 8650 | | |
8656 | 8651 | | |
8657 | 8652 | | |
8658 | | - | |
8659 | 8653 | | |
8660 | 8654 | | |
8661 | 8655 | | |
| |||
9209 | 9203 | | |
9210 | 9204 | | |
9211 | 9205 | | |
9212 | | - | |
| 9206 | + | |
| 9207 | + | |
| 9208 | + | |
| 9209 | + | |
| 9210 | + | |
| 9211 | + | |
| 9212 | + | |
| 9213 | + | |
9213 | 9214 | | |
9214 | 9215 | | |
9215 | 9216 | | |
| |||
0 commit comments