KVM: x86: Rep string I/O WARN removal and test
Sean Christopherson
maintainercover KVM: x86: Rep string I/O WARN removal and test
Remove a WARN that was added as part of the recent I/O overhaul to play nice with SEV-ES string I/O.
For the record, my FIXME in lieu of a WARN was deliberate, as I suspected userspace could trigger a WARN ;-)
Based on kvm/master, commit 95e16b4792b0 ("KVM: SEV-ES: go over the sev_pio_data buffer in multiple passes if needed").
Sean Christopherson (2):
KVM: x86: Don't WARN if userspace mucks with RCX during string I/O
exit
KVM: selftests: Add test to verify KVM doesn't explode on "bad" I/O
arch/x86/kvm/x86.c | 9 +- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/userspace_io_test.c | 114 ++++++++++++++++++ 4 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86_64/userspace_io_test.c
Signature · 1 line
2.33.0.1079.g6e70778dc9-goog
Sean Christopherson
maintainerPATCH 1/2 KVM: x86: Don't WARN if userspace mucks with RCX during string I/O exit
Replace a WARN with a comment to call out that userspace can modify RCX during an exit to userspace to handle string I/O. KVM doesn't actually support changing the rep count during an exit, i.e. the scenario can be ignored, but the WARN needs to go as it's trivial to trigger from userspace.
--- arch/x86/kvm/x86.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +7 -2
@@ -6948,7 +6948,13 @@ static int emulator_pio_in(struct kvm_vcpu *vcpu, int size, unsigned short port, void *val, unsigned int count) { if (vcpu->arch.pio.count) { - /* Complete previous iteration. */ +/* +* Complete a previous iteration that required userspace I/O. +* Note, @count isn't guaranteed to match pio.count as userspace +* can modify ECX before rerunning the vCPU. Ignore any such +* shenanigans as KVM doesn't support modifying the rep count, +* and the emulator ensures @count doesn't overflow the buffer. +*/ } else {int r =__emulator_pio_in (vcpu, size, port, count);if (!r)
@@ -6957,7 +6963,6 @@ static int emulator_pio_in(struct kvm_vcpu *vcpu, int size,/* Results already available, fall through. */ } -WARN_ON (count != vcpu->arch.pio.count);complete_emulator_pio_in (vcpu, val);return 1 ; }
Signature · 1 line
2.33.0.1079.g6e70778dc9-goog
Sean Christopherson
maintainerPATCH 2/2 KVM: selftests: Add test to verify KVM doesn't explode on "bad" I/O
In reply to Sean ChristophersonAdd an x86 selftest to verify that KVM doesn't WARN or otherwise explode if userspace modifies RCX during a userspace exit to handle string I/O. This is a regression test for a user-triggerable WARN introduced by commit 3b27de271839 ("KVM: x86: split the two parts of emulator_pio_in").
--- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/userspace_io_test.c | 114 ++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/userspace_io_test.c
tools/testing/selftests/kvm/.gitignore +1 -0
@@ -27,6 +27,7 @@ /x86_64/svm_int_ctl_test /x86_64/sync_regs_test /x86_64/tsc_msrs_test +/x86_64/userspace_io_test /x86_64/userspace_msr_exit_test /x86_64/vmx_apic_access_test /x86_64/vmx_close_while_nested_test
tools/testing/selftests/kvm/Makefile +1 -0
@@ -58,6 +58,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test TEST_GEN_PROGS_x86_64 += x86_64/svm_int_ctl_test TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test +TEST_GEN_PROGS_x86_64 += x86_64/userspace_io_test TEST_GEN_PROGS_x86_64 += x86_64/userspace_msr_exit_test TEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
tools/testing/selftests/kvm/x86_64/userspace_io_test.c new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
2.33.0.1079.g6e70778dc9-goog
Sean Christopherson
maintainerQuoted 14 lines · Sean Christopherson
Remove a WARN that was added as part of the recent I/O overhaul to play nice with SEV-ES string I/O.
For the record, my FIXME in lieu of a WARN was deliberate, as I suspected userspace could trigger a WARN ;-)
Based on kvm/master, commit
95e16b4792b0("KVM: SEV-ES: go over thesev_pio_databuffer in multiple passes if needed").Sean Christopherson (2):
KVM: x86: Don't WARN if userspace mucks with RCX during string I/O
exit
KVM: selftests: Add test to verify KVM doesn't explode on "bad" I/O
Quoted 6 lines
arch/x86/kvm/x86.c | 9 +- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/userspace_io_test.c | 114 ++++++++++++++++++ 4 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86_64/userspace_io_test.c
Ping. I completely forgot about this too, until I unintentionally ran a userspace_io_test that was lying around.
Quoted 22 lines · Sean Christopherson
Quoted 14 lines · Sean Christopherson
Remove a WARN that was added as part of the recent I/O overhaul to play nice with SEV-ES string I/O.
For the record, my FIXME in lieu of a WARN was deliberate, as I suspected userspace could trigger a WARN ;-)
Based on kvm/master, commit
95e16b4792b0("KVM: SEV-ES: go over thesev_pio_databuffer in multiple passes if needed").Sean Christopherson (2):
KVM: x86: Don't WARN if userspace mucks with RCX during string I/O
exit
KVM: selftests: Add test to verify KVM doesn't explode on "bad" I/OQuoted 6 lines
arch/x86/kvm/x86.c | 9 +- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/userspace_io_test.c | 114 ++++++++++++++++++ 4 files changed, 123 insertions(+), 2 deletions(-)create mode 100644
tools/testing/selftests/kvm/x86_64/userspace_io_test.c
Quoted 3 lines
Ping. I completely forgot about this too, until I unintentionally ran a
userspace_io_testthat was lying around.
Queued now, thanks. I don't know if I want the honor of having KVM singled out again on the -rc release message, but these are bugs nevertheless...
Paolo
Sean Christopherson
maintainerQuoted 23 lines · Paolo Bonzini
Quoted 22 lines · Sean Christopherson
Quoted 20 lines · Sean Christopherson
Remove a WARN that was added as part of the recent I/O overhaul to play nice with SEV-ES string I/O.
For the record, my FIXME in lieu of a WARN was deliberate, as I suspected userspace could trigger a WARN ;-)
Based on kvm/master, commit
95e16b4792b0("KVM: SEV-ES: go over thesev_pio_databuffer in multiple passes if needed").Sean Christopherson (2):
KVM: x86: Don't WARN if userspace mucks with RCX during string I/O
exit
KVM: selftests: Add test to verify KVM doesn't explode on "bad" I/Oarch/x86/kvm/x86.c | 9 +- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/userspace_io_test.c | 114 ++++++++++++++++++ 4 files changed, 123 insertions(+), 2 deletions(-)create mode 100644
tools/testing/selftests/kvm/x86_64/userspace_io_test.c
Quoted 6 lines
Quoted 3 lines
Ping. I completely forgot about this too, until I unintentionally ran a
userspace_io_testthat was lying around.Queued now, thanks. I don't know if I want the honor of having KVM singled out again on the -rc release message, but these are bugs nevertheless...
Heh, you could always wait an -rc to send the fixes and hope Linus has a short memory :-D