KVM: fix bad user ABI for KVM_EXIT_SYSTEM_EVENT
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 22 Apr 2022 10:30:13 +0000 (12:30 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 29 Apr 2022 16:38:22 +0000 (12:38 -0400)
commitd495f942f40aa412f8d4d65951152648cfa09903
tree81a4c05ce5fb66d9bdcc613d35f235b5b93e951b
parent86931ff7207bc045fa5439ef97b31859613dc303
KVM: fix bad user ABI for KVM_EXIT_SYSTEM_EVENT

When KVM_EXIT_SYSTEM_EVENT was introduced, it included a flags
member that at the time was unused.  Unfortunately this extensibility
mechanism has several issues:

- x86 is not writing the member, so it would not be possible to use it
  on x86 except for new events

- the member is not aligned to 64 bits, so the definition of the
  uAPI struct is incorrect for 32- on 64-bit userspace.  This is a
  problem for RISC-V, which supports CONFIG_KVM_COMPAT, but fortunately
  usage of flags was only introduced in 5.18.

Since padding has to be introduced, place a new field in there
that tells if the flags field is valid.  To allow further extensibility,
in fact, change flags to an array of 16 values, and store how many
of the values are valid.  The availability of the new ndata field
is tied to a system capability; all architectures are changed to
fill in the field.

To avoid breaking compilation of userspace that was using the flags
field, provide a userspace-only union to overlap flags with data[0].
The new field is placed at the same offset for both 32- and 64-bit
userspace.

Cc: Will Deacon <will@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Peter Gonda <pgonda@google.com>
Cc: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reported-by: kernel test robot <lkp@intel.com>
Message-Id: <20220422103013.34832-1-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Documentation/virt/kvm/api.rst
arch/arm64/kvm/psci.c
arch/riscv/kvm/vcpu_sbi.c
arch/x86/kvm/x86.c
include/uapi/linux/kvm.h
virt/kvm/kvm_main.c