Since v7.1 a nested hypervisor can run its guests in ESA mode (the
ESA/390-compatibility mode of the machine) when user space enables
KVM_CAP_S390_VSIE_ESAMODE. One piece of vsie still treats the PSW of such a
guest as a z/Architecture PSW: the rewind that vsie uses to have an
instruction repeated. For a state description in ESA/390 format the
instruction is skipped instead, and a stray value is left in the half of
the PSW field that such a state description does not use.
What a nested guest sees: the first STORE FACILITY LIST EXTENDED after
every entry into SIE does nothing (operand and condition code untouched),
because vsie intercepts it to shadow the facility list. A program that
tests facility bits gets zeros.
Patch 1 is the fix, patch 2 a selftest that reproduces the problem with a
small guest 2 that issues SIE itself (modelled on the vsie selftest that is
queued in kvm-s390 next). The series is based on v7.4-rc4-260-g4dce97c6c265.
Why it matters beyond one instruction: backward compatibility is a
defining property of this platform, and the ESA/390-compatibility mode is
the architecture's mechanism for running older programs on machines that
only start in z/Architecture mode. Any hypervisor that runs as a KVM guest
and gives its own guests that mode depends on vsie handling such state
descriptions exactly like the machine.
Testing (z14)
- On an LPAR running v7.3.6 with patch 1 (the host owns SIE) the selftest
of patch 2 passes all three checks: the unused doubleword stays 0, the
PSW ends behind the last instruction, and the first STFLE stores the
designated list.
- Without patch 1 (v7.3.6, test kernel running as a KVM guest above a level
that passed ESA mode state descriptions on): the unused PSW doubleword
comes back as 0x7ffffff8 and neither STFLE stores anything. In such a
nested setup above a host without the fix, checks 1 and 3 still fail
with patch 1 in the test kernel, because the defect acts once per level.
- On a host whose lower level refuses ESA mode state descriptions the test
skips (validity 0x0001 seen by guest 2).
- KVM selftests (12 s390 tests and 5 generic ones) and the s390x
kvm-unit-tests (37 pass, 4 fail, 21 skip) give the same result for every
test with and without the series (v7.3.6, nested setup); the 4 failures
(sclp-1g, sclp-3g, css, edat) are the same with the unmodified module.
- Built with W=1 and sparse without warnings; checkpatch --strict is clean
apart from the MAINTAINERS note for the new file.
- Not tested: MOVE PAGE partial execution and the addressing-exception
path for a guest in ESA mode. MOVE PAGE is not available in the mode
without the ESA/XC facilities, so the first should not occur.
Assistance: the series was prepared with an AI coding assistant (see the
Assisted-by tags); the defect was found while tracing why a facility test
failed in a nested guest, the analysis, fix and test were written with the
assistant and reviewed by the submitter.
Yvan Janssens (2):
KVM: s390: vsie: Rewind the PSW of ESA mode guests in the right format
KVM: s390: selftests: Add a test for nested guests in ESA mode
arch/s390/kvm/s390/vsie.c | 23 ++-
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/s390/vsie_esa_test.c | 180 ++++++++++++++++++
3 files changed, 202 insertions(+), 2 deletions(-)
create mode 100644 tools/testing/selftests/kvm/s390/vsie_esa_test.c
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
--
2.47.3