Skip to contentSkip to conversation

Extend SEV-SNP SVSM support with a kvm_vcpu per VMPL

RFC PATCH In review Roy Hopkins 4 participants 10 messages Sep 16, 2024 – Oct 23, 2024

Subsystems (22)
Documentation x86 KVM PowerPC +18 more subsystems
lore
Share & tools
lore
#0 lore raw

cover Extend SEV-SNP SVSM support with a kvm_vcpu per VMPL

I've prepared this series as an extension to the RFC patch series: 'SEV-SNP support for running an SVSM' posted by Tom Lendacky [1]. This extends the support for transitioning a vCPU between VM Privilege Levels (VMPLs) by storing the vCPU state for each VMPL in its own struct kvm_vcpu. This additionally allows for separate APICs for each VMPL.

In treating each VMPL as a struct kvm_vcpu it makes it very simple to perform a VMPL transition. In most cases it is a simple as just switching the context from one kvm_vcpu pointer to another. This results in very low overhead VMPL switches. This can can also support the case where a VMPL switch occurs during guest execution - something that we will need to support for Intel TDX and perhaps other isolation technologies.

Obviously, there is much to consider when splitting a single vCPU into being managed by multiple struct kvm_vcpus. First and foremost is the fact that much of the state should be shared between all kvm_vcpu's that relate to a single vCPU, such as the vCPU ID, requests, mutexes, etc. This series introduces a solution where the common fields are accessed via a pointer in each kvm_vcpu. Unfortunately this means that any code that refers to these fields needs to be updated, resulting in the first patch in the series that touches many areas of the code.

This is very much proof-of-concept code and, like Tom's series, is introduced to trigger discussions around implementing VMPL support and not intended for merging at this stage. The code currently has some instabilities during guest startup which I need to locate.

This series is based off the same tip tree as [1], and the patches from that series need to be applied before this series:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git master

b0c57a7002b0 ("Merge branch into tip/master: 'x86/cpu'")

[1] Provide SEV-SNP support for running under an SVSM
https://lore.kernel.org/lkml/[email protected]/

Roy Hopkins (5):
kvm: Move kvm_vcpu fields into common structure x86/kvm: Create a child struct kvm_vcpu for each VMPL kvm/sev: Update SEV VMPL handling to use multiple struct kvm_vcpus x86/kvm: Add x86 field to find the default VMPL that IRQs should
target
x86/kvm: Add target VMPL to IRQs and send to APIC for VMPL

 Documentation/virt/kvm/api.rst                |   2 +-
 Documentation/virt/kvm/locking.rst            |   6 +-
 Documentation/virt/kvm/vcpu-requests.rst      |  20 +-
 arch/arm64/kvm/arch_timer.c                   |   4 +-
 arch/arm64/kvm/arm.c                          |  34 +-
 arch/arm64/kvm/debug.c                        |  22 +-
 arch/arm64/kvm/guest.c                        |   6 +-
 arch/arm64/kvm/handle_exit.c                  |  12 +-
 arch/arm64/kvm/hyp/include/hyp/switch.h       |   2 +-
 arch/arm64/kvm/hypercalls.c                   |   2 +-
 arch/arm64/kvm/mmio.c                         |  14 +-
 arch/arm64/kvm/pmu-emul.c                     |   4 +-
 arch/arm64/kvm/psci.c                         |  14 +-
 arch/arm64/kvm/vgic/vgic.c                    |   2 +-
 arch/loongarch/kvm/exit.c                     |  52 +--
 arch/loongarch/kvm/timer.c                    |   2 +-
 arch/loongarch/kvm/vcpu.c                     |  22 +-
 arch/mips/kvm/emulate.c                       |  94 ++--
 arch/mips/kvm/mips.c                          |  52 +--
 arch/mips/kvm/vz.c                            |  30 +-
 arch/powerpc/kvm/book3s.c                     |   4 +-
 arch/powerpc/kvm/book3s_emulate.c             |   6 +-
 arch/powerpc/kvm/book3s_hv.c                  |  38 +-
 arch/powerpc/kvm/book3s_hv_nested.c           |   4 +-
 arch/powerpc/kvm/book3s_hv_rm_xics.c          |   8 +-
 arch/powerpc/kvm/book3s_pr.c                  |  38 +-
 arch/powerpc/kvm/book3s_pr_papr.c             |   2 +-
 arch/powerpc/kvm/book3s_xics.c                |   8 +-
 arch/powerpc/kvm/book3s_xive.c                |  12 +-
 arch/powerpc/kvm/book3s_xive_native.c         |   8 +-
 arch/powerpc/kvm/booke.c                      |  38 +-
 arch/powerpc/kvm/booke_emulate.c              |  22 +-
 arch/powerpc/kvm/e500_emulate.c               |   6 +-
 arch/powerpc/kvm/emulate.c                    |   6 +-
 arch/powerpc/kvm/emulate_loadstore.c          |   2 +-
 arch/powerpc/kvm/powerpc.c                    |  62 +--
 arch/powerpc/kvm/timing.h                     |  28 +-
 arch/powerpc/kvm/trace.h                      |   2 +-
 arch/powerpc/kvm/trace_hv.h                   |   2 +-
 arch/riscv/kvm/aia_device.c                   |   8 +-
 arch/riscv/kvm/aia_imsic.c                    |   2 +-
 arch/riscv/kvm/vcpu.c                         |  24 +-
 arch/riscv/kvm/vcpu_insn.c                    |  14 +-
 arch/riscv/kvm/vcpu_sbi.c                     |   2 +-
 arch/riscv/kvm/vcpu_sbi_hsm.c                 |   2 +-
 arch/s390/include/asm/kvm_host.h              |   8 +-
 arch/s390/kvm/diag.c                          |  72 ++--
 arch/s390/kvm/gaccess.c                       |   4 +-
 arch/s390/kvm/guestdbg.c                      |  14 +-
 arch/s390/kvm/intercept.c                     |  30 +-
 arch/s390/kvm/interrupt.c                     |  82 ++--
 arch/s390/kvm/kvm-s390.c                      | 160 +++----
 arch/s390/kvm/kvm-s390.h                      |  12 +-
 arch/s390/kvm/priv.c                          | 186 ++++----
 arch/s390/kvm/pv.c                            |   2 +-
 arch/s390/kvm/sigp.c                          |  62 +--
 arch/s390/kvm/vsie.c                          |   6 +-
 arch/x86/include/asm/kvm_host.h               |   8 +
 arch/x86/kvm/cpuid.c                          |  78 ++--
 arch/x86/kvm/debugfs.c                        |   2 +-
 arch/x86/kvm/hyperv.c                         |  20 +-
 arch/x86/kvm/ioapic.c                         |   3 +
 arch/x86/kvm/irq_comm.c                       |   1 +
 arch/x86/kvm/kvm_cache_regs.h                 |   4 +-
 arch/x86/kvm/lapic.c                          |  10 +-
 arch/x86/kvm/mmu/mmu.c                        |  28 +-
 arch/x86/kvm/mmu/tdp_mmu.c                    |   2 +-
 arch/x86/kvm/pmu.c                            |   2 +-
 arch/x86/kvm/svm/nested.c                     |   6 +-
 arch/x86/kvm/svm/sev.c                        | 231 +++++-----
 arch/x86/kvm/svm/svm.c                        | 122 +++---
 arch/x86/kvm/svm/svm.h                        |  36 +-
 arch/x86/kvm/trace.h                          |  12 +-
 arch/x86/kvm/vmx/nested.c                     |  18 +-
 arch/x86/kvm/vmx/posted_intr.c                |   2 +-
 arch/x86/kvm/vmx/sgx.c                        |   4 +-
 arch/x86/kvm/vmx/vmx.c                        | 128 +++---
 arch/x86/kvm/x86.c                            | 406 ++++++++++--------
 arch/x86/kvm/xen.c                            |  24 +-
 arch/x86/kvm/xen.h                            |   2 +-
 drivers/s390/crypto/vfio_ap_ops.c             |  10 +-
 include/linux/kvm_host.h                      | 180 ++++----
 include/trace/events/kvm.h                    |  48 +++
 .../selftests/kvm/aarch64/debug-exceptions.c  |   2 +-
 .../selftests/kvm/aarch64/page_fault_test.c   |   2 +-
 .../selftests/kvm/aarch64/smccc_filter.c      |   2 +-
 .../selftests/kvm/demand_paging_test.c        |   2 +-
 .../selftests/kvm/dirty_log_perf_test.c       |   2 +-
 tools/testing/selftests/kvm/dirty_log_test.c  |   4 +-
 .../testing/selftests/kvm/guest_print_test.c  |   4 +-
 .../selftests/kvm/hardware_disable_test.c     |   2 +-
 .../selftests/kvm/kvm_page_table_test.c       |   2 +-
 .../testing/selftests/kvm/lib/aarch64/ucall.c |   2 +-
 tools/testing/selftests/kvm/lib/kvm_util.c    |  14 +-
 tools/testing/selftests/kvm/lib/riscv/ucall.c |   2 +-
 .../kvm/lib/s390x/diag318_test_handler.c      |   2 +-
 .../selftests/kvm/lib/s390x/processor.c       |   6 +-
 tools/testing/selftests/kvm/lib/s390x/ucall.c |   2 +-
 .../testing/selftests/kvm/lib/x86_64/ucall.c  |   2 +-
 .../kvm/memslot_modification_stress_test.c    |   2 +-
 .../testing/selftests/kvm/memslot_perf_test.c |   2 +-
 .../selftests/kvm/pre_fault_memory_test.c     |   2 +-
 tools/testing/selftests/kvm/s390x/cmma_test.c |  20 +-
 .../testing/selftests/kvm/s390x/debug_test.c  |  12 +-
 tools/testing/selftests/kvm/s390x/memop.c     |   2 +-
 tools/testing/selftests/kvm/s390x/resets.c    |  14 +-
 .../selftests/kvm/s390x/sync_regs_test.c      |  10 +-
 tools/testing/selftests/kvm/s390x/tprot.c     |   2 +-
 .../selftests/kvm/set_memory_region_test.c    |   4 +-
 tools/testing/selftests/kvm/steal_time.c      |   2 +-
 .../testing/selftests/kvm/x86_64/cpuid_test.c |   2 +-
 .../testing/selftests/kvm/x86_64/debug_regs.c |   2 +-
 .../selftests/kvm/x86_64/fix_hypercall_test.c |   2 +-
 .../selftests/kvm/x86_64/flds_emulation.h     |   2 +-
 .../kvm/x86_64/hyperv_extended_hypercalls.c   |   2 +-
 .../kvm/x86_64/nested_exceptions_test.c       |   4 +-
 .../kvm/x86_64/private_mem_conversions_test.c |   4 +-
 .../kvm/x86_64/private_mem_kvm_exits_test.c   |  16 +-
 .../selftests/kvm/x86_64/set_boot_cpu_id.c    |   2 +-
 .../selftests/kvm/x86_64/sev_smoke_test.c     |  22 +-
 .../selftests/kvm/x86_64/sync_regs_test.c     |  16 +-
 .../kvm/x86_64/triple_fault_event_test.c      |   2 +-
 .../selftests/kvm/x86_64/tsc_msrs_test.c      |   2 +-
 .../selftests/kvm/x86_64/userspace_io_test.c  |   2 +-
 .../kvm/x86_64/userspace_msr_exit_test.c      |   8 +-
 .../kvm/x86_64/vmx_apic_access_test.c         |   2 +-
 .../kvm/x86_64/vmx_close_while_nested_test.c  |   2 +-
 .../vmx_exception_with_invalid_guest_state.c  |   2 +-
 .../x86_64/vmx_invalid_nested_guest_state.c   |   2 +-
 .../selftests/kvm/x86_64/xcr0_cpuid_test.c    |   2 +-
 .../selftests/kvm/x86_64/xen_vmcall_test.c    |   2 +-
 virt/kvm/async_pf.c                           |  60 +--
 virt/kvm/dirty_ring.c                         |   6 +-
 virt/kvm/kvm_main.c                           | 274 +++++++-----
 134 files changed, 1746 insertions(+), 1587 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/5 kvm: Move kvm_vcpu fields into common structure

This commit is in preparation for supporting multiple VM privilege levels (VMPLs) within KVM by creating an instance of struct kvm_vcpu for each VMPL. Support for multiple VMPLs will be introduced in a later commit. This commit prepares struct kvm_vcpu by allowing the fields that are common to all VMPLs to be accessed from the struct kvm_vcpu for any VMPL.

To add support for common fields across multiple struct kvm_vcpus, this commit creates a sub-structure within struct kvm_vcpu for storing the common fields. Any fields that have been identified as common across VMPLs for SEV-SNP (for now) have been moved into this sub-structure.

When the struct kvm_vcpu is initialised, a pointer to the common structure is stored within struct kvm_vcpu allowing access to the common fields.

This means that any reference to these common fields needs to be updated to access them via the structure pointer, e.g. vcpu->common->[common_field]. This has resulted in this patch generating many small changes to many files which is an unfortunate side-effect of this implementation.

---
 Documentation/virt/kvm/api.rst                |   2 +-
 Documentation/virt/kvm/locking.rst            |   6 +-
 Documentation/virt/kvm/vcpu-requests.rst      |  20 +-
 arch/arm64/kvm/arch_timer.c                   |   4 +-
 arch/arm64/kvm/arm.c                          |  34 +-
 arch/arm64/kvm/debug.c                        |  22 +-
 arch/arm64/kvm/guest.c                        |   6 +-
 arch/arm64/kvm/handle_exit.c                  |  12 +-
 arch/arm64/kvm/hyp/include/hyp/switch.h       |   2 +-
 arch/arm64/kvm/hypercalls.c                   |   2 +-
 arch/arm64/kvm/mmio.c                         |  14 +-
 arch/arm64/kvm/pmu-emul.c                     |   4 +-
 arch/arm64/kvm/psci.c                         |  14 +-
 arch/arm64/kvm/vgic/vgic.c                    |   2 +-
 arch/loongarch/kvm/exit.c                     |  52 +--
 arch/loongarch/kvm/timer.c                    |   2 +-
 arch/loongarch/kvm/vcpu.c                     |  22 +-
 arch/mips/kvm/emulate.c                       |  94 ++---
 arch/mips/kvm/mips.c                          |  52 +--
 arch/mips/kvm/vz.c                            |  30 +-
 arch/powerpc/kvm/book3s.c                     |   4 +-
 arch/powerpc/kvm/book3s_emulate.c             |   6 +-
 arch/powerpc/kvm/book3s_hv.c                  |  38 +-
 arch/powerpc/kvm/book3s_hv_nested.c           |   4 +-
 arch/powerpc/kvm/book3s_hv_rm_xics.c          |   8 +-
 arch/powerpc/kvm/book3s_pr.c                  |  38 +-
 arch/powerpc/kvm/book3s_pr_papr.c             |   2 +-
 arch/powerpc/kvm/book3s_xics.c                |   8 +-
 arch/powerpc/kvm/book3s_xive.c                |  12 +-
 arch/powerpc/kvm/book3s_xive_native.c         |   8 +-
 arch/powerpc/kvm/booke.c                      |  38 +-
 arch/powerpc/kvm/booke_emulate.c              |  22 +-
 arch/powerpc/kvm/e500_emulate.c               |   6 +-
 arch/powerpc/kvm/emulate.c                    |   6 +-
 arch/powerpc/kvm/emulate_loadstore.c          |   2 +-
 arch/powerpc/kvm/powerpc.c                    |  62 ++--
 arch/powerpc/kvm/timing.h                     |  28 +-
 arch/powerpc/kvm/trace.h                      |   2 +-
 arch/powerpc/kvm/trace_hv.h                   |   2 +-
 arch/riscv/kvm/aia_device.c                   |   8 +-
 arch/riscv/kvm/aia_imsic.c                    |   2 +-
 arch/riscv/kvm/vcpu.c                         |  24 +-
 arch/riscv/kvm/vcpu_insn.c                    |  14 +-
 arch/riscv/kvm/vcpu_sbi.c                     |   2 +-
 arch/riscv/kvm/vcpu_sbi_hsm.c                 |   2 +-
 arch/s390/include/asm/kvm_host.h              |   8 +-
 arch/s390/kvm/diag.c                          |  72 ++--
 arch/s390/kvm/gaccess.c                       |   4 +-
 arch/s390/kvm/guestdbg.c                      |  14 +-
 arch/s390/kvm/intercept.c                     |  30 +-
 arch/s390/kvm/interrupt.c                     |  82 ++---
 arch/s390/kvm/kvm-s390.c                      | 160 ++++----
 arch/s390/kvm/kvm-s390.h                      |  12 +-
 arch/s390/kvm/priv.c                          | 186 +++++-----
 arch/s390/kvm/pv.c                            |   2 +-
 arch/s390/kvm/sigp.c                          |  62 ++--
 arch/s390/kvm/vsie.c                          |   6 +-
 arch/x86/kvm/debugfs.c                        |   2 +-
 arch/x86/kvm/hyperv.c                         |  20 +-
 arch/x86/kvm/kvm_cache_regs.h                 |   4 +-
 arch/x86/kvm/lapic.c                          |   4 +-
 arch/x86/kvm/mmu/mmu.c                        |  28 +-
 arch/x86/kvm/mmu/tdp_mmu.c                    |   2 +-
 arch/x86/kvm/pmu.c                            |   2 +-
 arch/x86/kvm/svm/nested.c                     |   6 +-
 arch/x86/kvm/svm/sev.c                        |  66 ++--
 arch/x86/kvm/svm/svm.c                        |  56 +--
 arch/x86/kvm/vmx/nested.c                     |  18 +-
 arch/x86/kvm/vmx/posted_intr.c                |   2 +-
 arch/x86/kvm/vmx/sgx.c                        |   4 +-
 arch/x86/kvm/vmx/vmx.c                        | 128 +++----
 arch/x86/kvm/x86.c                            | 348 +++++++++---------
 arch/x86/kvm/xen.c                            |  24 +-
 arch/x86/kvm/xen.h                            |   2 +-
 drivers/s390/crypto/vfio_ap_ops.c             |  10 +-
 include/linux/kvm_host.h                      | 167 +++++----
 .../selftests/kvm/aarch64/debug-exceptions.c  |   2 +-
 .../selftests/kvm/aarch64/page_fault_test.c   |   2 +-
 .../selftests/kvm/aarch64/smccc_filter.c      |   2 +-
 .../selftests/kvm/demand_paging_test.c        |   2 +-
 .../selftests/kvm/dirty_log_perf_test.c       |   2 +-
 tools/testing/selftests/kvm/dirty_log_test.c  |   4 +-
 .../testing/selftests/kvm/guest_print_test.c  |   4 +-
 .../selftests/kvm/hardware_disable_test.c     |   2 +-
 .../selftests/kvm/kvm_page_table_test.c       |   2 +-
 .../testing/selftests/kvm/lib/aarch64/ucall.c |   2 +-
 tools/testing/selftests/kvm/lib/kvm_util.c    |  14 +-
 tools/testing/selftests/kvm/lib/riscv/ucall.c |   2 +-
 .../kvm/lib/s390x/diag318_test_handler.c      |   2 +-
 .../selftests/kvm/lib/s390x/processor.c       |   6 +-
 tools/testing/selftests/kvm/lib/s390x/ucall.c |   2 +-
 .../testing/selftests/kvm/lib/x86_64/ucall.c  |   2 +-
 .../kvm/memslot_modification_stress_test.c    |   2 +-
 .../testing/selftests/kvm/memslot_perf_test.c |   2 +-
 .../selftests/kvm/pre_fault_memory_test.c     |   2 +-
 tools/testing/selftests/kvm/s390x/cmma_test.c |  20 +-
 .../testing/selftests/kvm/s390x/debug_test.c  |  12 +-
 tools/testing/selftests/kvm/s390x/memop.c     |   2 +-
 tools/testing/selftests/kvm/s390x/resets.c    |  14 +-
 .../selftests/kvm/s390x/sync_regs_test.c      |  10 +-
 tools/testing/selftests/kvm/s390x/tprot.c     |   2 +-
 .../selftests/kvm/set_memory_region_test.c    |   4 +-
 tools/testing/selftests/kvm/steal_time.c      |   2 +-
 .../testing/selftests/kvm/x86_64/cpuid_test.c |   2 +-
 .../testing/selftests/kvm/x86_64/debug_regs.c |   2 +-
 .../selftests/kvm/x86_64/fix_hypercall_test.c |   2 +-
 .../selftests/kvm/x86_64/flds_emulation.h     |   2 +-
 .../kvm/x86_64/hyperv_extended_hypercalls.c   |   2 +-
 .../kvm/x86_64/nested_exceptions_test.c       |   4 +-
 .../kvm/x86_64/private_mem_conversions_test.c |   4 +-
 .../kvm/x86_64/private_mem_kvm_exits_test.c   |  16 +-
 .../selftests/kvm/x86_64/set_boot_cpu_id.c    |   2 +-
 .../selftests/kvm/x86_64/sev_smoke_test.c     |  22 +-
 .../selftests/kvm/x86_64/sync_regs_test.c     |  16 +-
 .../kvm/x86_64/triple_fault_event_test.c      |   2 +-
 .../selftests/kvm/x86_64/tsc_msrs_test.c      |   2 +-
 .../selftests/kvm/x86_64/userspace_io_test.c  |   2 +-
 .../kvm/x86_64/userspace_msr_exit_test.c      |   8 +-
 .../kvm/x86_64/vmx_apic_access_test.c         |   2 +-
 .../kvm/x86_64/vmx_close_while_nested_test.c  |   2 +-
 .../vmx_exception_with_invalid_guest_state.c  |   2 +-
 .../x86_64/vmx_invalid_nested_guest_state.c   |   2 +-
 .../selftests/kvm/x86_64/xcr0_cpuid_test.c    |   2 +-
 .../selftests/kvm/x86_64/xen_vmcall_test.c    |   2 +-
 virt/kvm/async_pf.c                           |  60 +--
 virt/kvm/dirty_ring.c                         |   6 +-
 virt/kvm/kvm_main.c                           | 176 ++++-----
 127 files changed, 1375 insertions(+), 1366 deletions(-)
Documentation/virt/kvm/api.rst +1 -1
index 33938468d62d..5f4df9a90907 100644
@@ -7494,7 +7494,7 @@ initial handling in the kernel, KVM exits to user space with
 KVM_EXIT_S390_STSI to allow user space to insert further data.
 
 Before exiting to userspace, kvm handlers should fill in s390_stsi field of
-vcpu->run::
+vcpu->common->run::
 
   struct {
 	__u64 addr;
Documentation/virt/kvm/locking.rst +3 -3
index 02880d5552d5..a571cfa9a8be 100644
@@ -11,7 +11,7 @@ The acquisition orders for mutexes are as follows:
 
 - cpus_read_lock() is taken outside kvm_lock
 
-- kvm->lock is taken outside vcpu->mutex
+- kvm->lock is taken outside vcpu->common->mutex
 
 - kvm->lock is taken outside kvm->slots_lock and kvm->irq_lock
 
@@ -27,7 +27,7 @@ The acquisition orders for mutexes are as follows:
 For SRCU:
 
 - ``synchronize_srcu(&kvm->srcu)`` is called inside critical sections
-  for kvm->lock, vcpu->mutex and kvm->slots_lock.  These locks _cannot_
+  for kvm->lock, vcpu->common->mutex and kvm->slots_lock.  These locks _cannot_
   be taken inside a kvm->srcu read-side critical section; that is, the
   following is broken::
 
@@ -41,7 +41,7 @@ For SRCU:
 
 On x86:
 
-- vcpu->mutex is taken outside kvm->arch.hyperv.hv_lock and kvm->arch.xen.xen_lock
+- vcpu->common->mutex is taken outside kvm->arch.hyperv.hv_lock and kvm->arch.xen.xen_lock
 
 - kvm->arch.mmu_lock is an rwlock; critical sections for
   kvm->arch.tdp_mmu_pages_lock and kvm->arch.mmu_unsync_pages_lock must
Documentation/virt/kvm/vcpu-requests.rst +10 -10
index 06718b9bc959..2a54cdc908e3 100644
@@ -63,9 +63,9 @@ are listed below:
 VCPU Mode
 ---------
 
-VCPUs have a mode state, ``vcpu->mode``, that is used to track whether the
+VCPUs have a mode state, ``vcpu->common->mode``, that is used to track whether the
 guest is running in guest mode or not, as well as some specific
-outside guest mode states.  The architecture may use ``vcpu->mode`` to
+outside guest mode states.  The architecture may use ``vcpu->common->mode`` to
 ensure VCPU requests are seen by VCPUs (see "Ensuring Requests Are Seen"),
 as well as to avoid sending unnecessary IPIs (see "IPI Reduction"), and
 even to ensure IPI acknowledgements are waited upon (see "Waiting for
@@ -198,7 +198,7 @@ enter guest mode.  This means that an optimized implementation (see "IPI
 Reduction") must be certain when it's safe to not send the IPI.  One
 solution, which all architectures except s390 apply, is to:
 
-- set ``vcpu->mode`` to IN_GUEST_MODE between disabling the interrupts and
+- set ``vcpu->common->mode`` to IN_GUEST_MODE between disabling the interrupts and
   the last kvm_request_pending() check;
 - enable interrupts atomically when entering the guest.
 
@@ -209,15 +209,15 @@ can exclude the possibility of a VCPU thread observing
 the next request made of it, even if the request is made immediately after
 the check.  This is done by way of the Dekker memory barrier pattern
 (scenario 10 of [lwn-mb]_).  As the Dekker pattern requires two variables,
-this solution pairs ``vcpu->mode`` with ``vcpu->requests``.  Substituting
+this solution pairs ``vcpu->common->mode`` with ``vcpu->requests``.  Substituting
 them into the pattern gives::
 
   CPU1                                    CPU2
   =================                       =================
   local_irq_disable();
-  WRITE_ONCE(vcpu->mode, IN_GUEST_MODE);  kvm_make_request(REQ, vcpu);
+  WRITE_ONCE(vcpu->common->mode, IN_GUEST_MODE);  kvm_make_request(REQ, vcpu);
   smp_mb();                               smp_mb();
-  if (kvm_request_pending(vcpu)) {        if (READ_ONCE(vcpu->mode) ==
+  if (kvm_request_pending(vcpu)) {        if (READ_ONCE(vcpu->common->mode) ==
                                               IN_GUEST_MODE) {
       ...abort guest entry...                 ...send IPI...
   }                                       }
@@ -225,9 +225,9 @@ them into the pattern gives::
 As stated above, the IPI is only useful for VCPU threads in guest mode or
 that have already disabled interrupts.  This is why this specific case of
 the Dekker pattern has been extended to disable interrupts before setting
-``vcpu->mode`` to IN_GUEST_MODE.  WRITE_ONCE() and READ_ONCE() are used to
+``vcpu->common->mode`` to IN_GUEST_MODE.  WRITE_ONCE() and READ_ONCE() are used to
 pedantically implement the memory barrier pattern, guaranteeing the
-compiler doesn't interfere with ``vcpu->mode``'s carefully planned
+compiler doesn't interfere with ``vcpu->common->mode``'s carefully planned
 accesses.
 
 IPI Reduction
@@ -269,8 +269,8 @@ even the request-less VCPU kick is coupled with the same
 local_irq_disable() + smp_mb() pattern described above; the ON bit
 (Outstanding Notification) in the posted interrupt descriptor takes the
 role of ``vcpu->requests``.  When sending a posted interrupt, PIR.ON is
-set before reading ``vcpu->mode``; dually, in the VCPU thread,
-vmx_sync_pir_to_irr() reads PIR after setting ``vcpu->mode`` to
+set before reading ``vcpu->common->mode``; dually, in the VCPU thread,
+vmx_sync_pir_to_irr() reads PIR after setting ``vcpu->common->mode`` to
 IN_GUEST_MODE.
 
 Additional Considerations
arch/arm64/kvm/arch_timer.c +2 -2
index 879982b1cc73..d488bff63fcc 100644
@@ -431,7 +431,7 @@ void kvm_timer_update_run(struct kvm_vcpu *vcpu)
 {
 	struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
 	struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
-	struct kvm_sync_regs *regs = &vcpu->run->s.regs;
+	struct kvm_sync_regs *regs = &vcpu->common->run->s.regs;
 
 	/* Populate the device bitmap with the timer states */
 	regs->device_irq_level &= ~(KVM_ARM_DEV_EL1_VTIMER |
@@ -861,7 +861,7 @@ bool kvm_timer_should_notify_user(struct kvm_vcpu *vcpu)
 {
 	struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
 	struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
-	struct kvm_sync_regs *sregs = &vcpu->run->s.regs;
+	struct kvm_sync_regs *sregs = &vcpu->common->run->s.regs;
 	bool vlevel, plevel;
 
 	if (likely(irqchip_in_kernel(vcpu->kvm)))
arch/arm64/kvm/arm.c +17 -17
index a7ca776b51ec..1a2de4007d08 100644
@@ -456,11 +456,11 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 	spin_lock_init(&vcpu->arch.mp_state_lock);
 
 #ifdef CONFIG_LOCKDEP
-	/* Inform lockdep that the config_lock is acquired after vcpu->mutex */
-	mutex_lock(&vcpu->mutex);
+	/* Inform lockdep that the config_lock is acquired after vcpu->common->mutex */
+	mutex_lock(&vcpu->common->mutex);
 	mutex_lock(&vcpu->kvm->arch.config_lock);
 	mutex_unlock(&vcpu->kvm->arch.config_lock);
-	mutex_unlock(&vcpu->mutex);
+	mutex_unlock(&vcpu->common->mutex);
 #endif
 
 	/* Force users to call KVM_ARM_VCPU_INIT */
@@ -975,9 +975,9 @@ static int kvm_vcpu_suspend(struct kvm_vcpu *vcpu)
 	 * userspace informing it of the wakeup condition.
 	 */
 	if (kvm_arch_vcpu_runnable(vcpu)) {
-		memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event));
-		vcpu->run->system_event.type = KVM_SYSTEM_EVENT_WAKEUP;
-		vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
+		memset(&vcpu->common->run->system_event, 0, sizeof(vcpu->common->run->system_event));
+		vcpu->common->run->system_event.type = KVM_SYSTEM_EVENT_WAKEUP;
+		vcpu->common->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
 		return 0;
 	}
 
@@ -1067,7 +1067,7 @@ static bool vcpu_mode_is_bad_32bit(struct kvm_vcpu *vcpu)
  */
 static bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu, int *ret)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 
 	/*
 	 * If we're using a userspace irqchip, then check if we need
@@ -1127,7 +1127,7 @@ static int noinstr kvm_arm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
  */
 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	int ret;
 
 	if (run->exit_reason == KVM_EXIT_MMIO) {
@@ -1138,7 +1138,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 
 	vcpu_load(vcpu);
 
-	if (!vcpu->wants_to_run) {
+	if (!vcpu->common->wants_to_run) {
 		ret = -EINTR;
 		goto out;
 	}
@@ -1192,10 +1192,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		 * See the comment in kvm_vcpu_exiting_guest_mode() and
 		 * Documentation/virt/kvm/vcpu-requests.rst
 		 */
-		smp_store_mb(vcpu->mode, IN_GUEST_MODE);
+		smp_store_mb(vcpu->common->mode, IN_GUEST_MODE);
 
 		if (ret <= 0 || kvm_vcpu_exit_request(vcpu, &ret)) {
-			vcpu->mode = OUTSIDE_GUEST_MODE;
+			vcpu->common->mode = OUTSIDE_GUEST_MODE;
 			isb(); /* Ensure work in x_flush_hwstate is committed */
 			kvm_pmu_sync_hwstate(vcpu);
 			if (static_branch_unlikely(&userspace_irqchip_in_use))
@@ -1217,8 +1217,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 
 		ret = kvm_arm_vcpu_enter_exit(vcpu);
 
-		vcpu->mode = OUTSIDE_GUEST_MODE;
-		vcpu->stat.exits++;
+		vcpu->common->mode = OUTSIDE_GUEST_MODE;
+		vcpu->common->stat.exits++;
 		/*
 		 * Back from guest
 		 *************************************************************/
@@ -1920,7 +1920,7 @@ static void unlock_vcpus(struct kvm *kvm, int vcpu_lock_idx)
 
 	for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) {
 		tmp_vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
-		mutex_unlock(&tmp_vcpu->mutex);
+		mutex_unlock(&tmp_vcpu->common->mutex);
 	}
 }
 
@@ -1941,13 +1941,13 @@ bool lock_all_vcpus(struct kvm *kvm)
 
 	/*
 	 * Any time a vcpu is in an ioctl (including running), the
-	 * core KVM code tries to grab the vcpu->mutex.
+	 * core KVM code tries to grab the vcpu->common->mutex.
 	 *
-	 * By grabbing the vcpu->mutex of all VCPUs we ensure that no
+	 * By grabbing the vcpu->common->mutex of all VCPUs we ensure that no
 	 * other VCPUs can fiddle with the state while we access it.
 	 */
 	kvm_for_each_vcpu(c, tmp_vcpu, kvm) {
-		if (!mutex_trylock(&tmp_vcpu->mutex)) {
+		if (!mutex_trylock(&tmp_vcpu->common->mutex)) {
 			unlock_vcpus(kvm, c - 1);
 			return false;
 		}
arch/arm64/kvm/debug.c +11 -11
index ce8886122ed3..8a0984778cfa 100644
@@ -108,7 +108,7 @@ static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu)
 				MDCR_EL2_TDOSA);
 
 	/* Is the VM being debugged by userspace? */
-	if (vcpu->guest_debug)
+	if (vcpu->common->guest_debug)
 		/* Route all software debug exceptions to EL2 */
 		vcpu->arch.mdcr_el2 |= MDCR_EL2_TDE;
 
@@ -119,7 +119,7 @@ static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu)
 	 *  - The guest is not using debug (DEBUG_DIRTY clear).
 	 *  - The guest has enabled the OS Lock (debug exceptions are blocked).
 	 */
-	if ((vcpu->guest_debug & KVM_GUESTDBG_USE_HW) ||
+	if ((vcpu->common->guest_debug & KVM_GUESTDBG_USE_HW) ||
 	    !vcpu_get_flag(vcpu, DEBUG_DIRTY) ||
 	    kvm_vcpu_os_lock_enabled(vcpu))
 		vcpu->arch.mdcr_el2 |= MDCR_EL2_TDA;
@@ -171,12 +171,12 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
 {
 	unsigned long mdscr, orig_mdcr_el2 = vcpu->arch.mdcr_el2;
 
-	trace_kvm_arm_setup_debug(vcpu, vcpu->guest_debug);
+	trace_kvm_arm_setup_debug(vcpu, vcpu->common->guest_debug);
 
 	kvm_arm_setup_mdcr_el2(vcpu);
 
 	/* Check if we need to use the debug registers. */
-	if (vcpu->guest_debug || kvm_vcpu_os_lock_enabled(vcpu)) {
+	if (vcpu->common->guest_debug || kvm_vcpu_os_lock_enabled(vcpu)) {
 		/* Save guest debug state */
 		save_guest_debug_regs(vcpu);
 
@@ -200,7 +200,7 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
 		 * returns to normal once the host is no longer
 		 * debugging the system.
 		 */
-		if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
+		if (vcpu->common->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
 			/*
 			 * If the software step state at the last guest exit
 			 * was Active-pending, we don't set DBG_SPSR_SS so
@@ -232,7 +232,7 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
 		 * debug ioctl. The existing DEBUG_DIRTY mechanism ensures
 		 * the registers are updated on the world switch.
 		 */
-		if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW) {
+		if (vcpu->common->guest_debug & KVM_GUESTDBG_USE_HW) {
 			/* Enable breakpoints/watchpoints */
 			mdscr = vcpu_read_sys_reg(vcpu, MDSCR_EL1);
 			mdscr |= DBG_MDSCR_MDE;
@@ -264,7 +264,7 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
 		}
 	}
 
-	BUG_ON(!vcpu->guest_debug &&
+	BUG_ON(!vcpu->common->guest_debug &&
 		vcpu->arch.debug_ptr != &vcpu->arch.vcpu_debug_state);
 
 	/* If KDE or MDE are set, perform a full save/restore cycle. */
@@ -280,13 +280,13 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
 
 void kvm_arm_clear_debug(struct kvm_vcpu *vcpu)
 {
-	trace_kvm_arm_clear_debug(vcpu->guest_debug);
+	trace_kvm_arm_clear_debug(vcpu->common->guest_debug);
 
 	/*
 	 * Restore the guest's debug registers if we were using them.
 	 */
-	if (vcpu->guest_debug || kvm_vcpu_os_lock_enabled(vcpu)) {
-		if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
+	if (vcpu->common->guest_debug || kvm_vcpu_os_lock_enabled(vcpu)) {
+		if (vcpu->common->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
 			if (!(*vcpu_cpsr(vcpu) & DBG_SPSR_SS))
 				/*
 				 * Mark the vcpu as ACTIVE_PENDING
@@ -301,7 +301,7 @@ void kvm_arm_clear_debug(struct kvm_vcpu *vcpu)
 		 * If we were using HW debug we need to restore the
 		 * debug_ptr to the guest debug state.
 		 */
-		if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW) {
+		if (vcpu->common->guest_debug & KVM_GUESTDBG_USE_HW) {
 			kvm_arm_reset_debug_ptr(vcpu);
 
 			trace_kvm_arm_set_regset("BKPTS", get_num_brps(),
arch/arm64/kvm/guest.c +3 -3
index 11098eb7eb44..891b6cc27c7c 100644
@@ -927,16 +927,16 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 	}
 
 	if (dbg->control & KVM_GUESTDBG_ENABLE) {
-		vcpu->guest_debug = dbg->control;
+		vcpu->common->guest_debug = dbg->control;
 
 		/* Hardware assisted Break and Watch points */
-		if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW) {
+		if (vcpu->common->guest_debug & KVM_GUESTDBG_USE_HW) {
 			vcpu->arch.external_debug_state = dbg->arch;
 		}
 
 	} else {
 		/* If not enabled clear all flags */
-		vcpu->guest_debug = 0;
+		vcpu->common->guest_debug = 0;
 		vcpu_clear_flag(vcpu, DBG_SS_ACTIVE_PENDING);
 	}
 
arch/arm64/kvm/handle_exit.c +6 -6
index d7c2990e7c9e..de749c8e3009 100644
@@ -38,7 +38,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu)
 {
 	trace_kvm_hvc_arm64(*vcpu_pc(vcpu), vcpu_get_reg(vcpu, 0),
 			    kvm_vcpu_hvc_get_imm(vcpu));
-	vcpu->stat.hvc_exit_stat++;
+	vcpu->common->stat.hvc_exit_stat++;
 
 	/* Forward hvc instructions to the virtual EL2 if the guest has EL2. */
 	if (vcpu_has_nv(vcpu)) {
@@ -132,10 +132,10 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu)
 
 	if (esr & ESR_ELx_WFx_ISS_WFE) {
 		trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true);
-		vcpu->stat.wfe_exit_stat++;
+		vcpu->common->stat.wfe_exit_stat++;
 	} else {
 		trace_kvm_wfx_arm64(*vcpu_pc(vcpu), false);
-		vcpu->stat.wfi_exit_stat++;
+		vcpu->common->stat.wfi_exit_stat++;
 	}
 
 	if (esr & ESR_ELx_WFx_ISS_WFxT) {
@@ -176,11 +176,11 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu)
  * guest and host are using the same debug facilities it will be up to
  * userspace to re-inject the correct exception for guest delivery.
  *
- * @return: 0 (while setting vcpu->run->exit_reason)
+ * @return: 0 (while setting vcpu->common->run->exit_reason)
  */
 static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	u64 esr = kvm_vcpu_get_esr(vcpu);
 
 	run->exit_reason = KVM_EXIT_DEBUG;
@@ -360,7 +360,7 @@ static int handle_trap_exceptions(struct kvm_vcpu *vcpu)
  */
 int handle_exit(struct kvm_vcpu *vcpu, int exception_index)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 
 	if (ARM_SERROR_PENDING(exception_index)) {
 		/*
arch/arm64/kvm/hyp/include/hyp/switch.h +1 -1
index f59ccfe11ab9..6e846b14542f 100644
@@ -645,7 +645,7 @@ static inline void synchronize_vcpu_pstate(struct kvm_vcpu *vcpu, u64 *exit_code
 	 * active-not-pending state?
 	 */
 	if (cpus_have_final_cap(ARM64_WORKAROUND_2077057)		&&
-	    vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP			&&
+	    vcpu->common->guest_debug & KVM_GUESTDBG_SINGLESTEP			&&
 	    *vcpu_cpsr(vcpu) & DBG_SPSR_SS				&&
 	    ESR_ELx_EC(read_sysreg_el2(SYS_ESR)) == ESR_ELx_EC_PAC)
 		write_sysreg_el2(*vcpu_cpsr(vcpu), SYS_SPSR);
arch/arm64/kvm/hypercalls.c +1 -1
index 5763d979d8ca..1b4e11414125 100644
@@ -244,7 +244,7 @@ static u8 kvm_smccc_get_action(struct kvm_vcpu *vcpu, u32 func_id)
 static void kvm_prepare_hypercall_exit(struct kvm_vcpu *vcpu, u32 func_id)
 {
 	u8 ec = ESR_ELx_EC(kvm_vcpu_get_esr(vcpu));
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	u64 flags = 0;
 
 	if (ec == ESR_ELx_EC_SMC32 || ec == ESR_ELx_EC_SMC64)
arch/arm64/kvm/mmio.c +7 -7
index cd6b7b83e2c3..4524f590e170 100644
@@ -85,13 +85,13 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu)
 	int mask;
 
 	/* Detect an already handled MMIO return */
-	if (unlikely(!vcpu->mmio_needed))
+	if (unlikely(!vcpu->common->mmio_needed))
 		return 1;
 
-	vcpu->mmio_needed = 0;
+	vcpu->common->mmio_needed = 0;
 
 	if (!kvm_vcpu_dabt_iswrite(vcpu)) {
-		struct kvm_run *run = vcpu->run;
+		struct kvm_run *run = vcpu->common->run;
 
 		len = kvm_vcpu_dabt_get_as(vcpu);
 		data = kvm_mmio_read_buf(run->mmio.data, len);
@@ -122,7 +122,7 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu)
 
 int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	unsigned long data;
 	unsigned long rt;
 	int ret;
@@ -187,20 +187,20 @@ int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa)
 	run->mmio.is_write	= is_write;
 	run->mmio.phys_addr	= fault_ipa;
 	run->mmio.len		= len;
-	vcpu->mmio_needed	= 1;
+	vcpu->common->mmio_needed	= 1;
 
 	if (!ret) {
 		/* We handled the access successfully in the kernel. */
 		if (!is_write)
 			memcpy(run->mmio.data, data_buf, len);
-		vcpu->stat.mmio_exit_kernel++;
+		vcpu->common->stat.mmio_exit_kernel++;
 		kvm_handle_mmio_return(vcpu);
 		return 1;
 	}
 
 	if (is_write)
 		memcpy(run->mmio.data, data_buf, len);
-	vcpu->stat.mmio_exit_user++;
+	vcpu->common->stat.mmio_exit_user++;
 	run->exit_reason	= KVM_EXIT_MMIO;
 	return 0;
 }
arch/arm64/kvm/pmu-emul.c +2 -2
index 82a2a003259c..daa6f4a16612 100644
@@ -373,7 +373,7 @@ static void kvm_pmu_update_state(struct kvm_vcpu *vcpu)
 bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
 {
 	struct kvm_pmu *pmu = &vcpu->arch.pmu;
-	struct kvm_sync_regs *sregs = &vcpu->run->s.regs;
+	struct kvm_sync_regs *sregs = &vcpu->common->run->s.regs;
 	bool run_level = sregs->device_irq_level & KVM_ARM_DEV_PMU;
 
 	if (likely(irqchip_in_kernel(vcpu->kvm)))
@@ -387,7 +387,7 @@ bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
  */
 void kvm_pmu_update_run(struct kvm_vcpu *vcpu)
 {
-	struct kvm_sync_regs *regs = &vcpu->run->s.regs;
+	struct kvm_sync_regs *regs = &vcpu->common->run->s.regs;
 
 	/* Populate the timer bitmap for user space */
 	regs->device_irq_level &= ~KVM_ARM_DEV_PMU;
arch/arm64/kvm/psci.c +7 -7
index 1f69b667332b..5eb741514196 100644
@@ -182,11 +182,11 @@ static void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type, u64 flags)
 	}
 	kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP);
 
-	memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event));
-	vcpu->run->system_event.type = type;
-	vcpu->run->system_event.ndata = 1;
-	vcpu->run->system_event.data[0] = flags;
-	vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
+	memset(&vcpu->common->run->system_event, 0, sizeof(vcpu->common->run->system_event));
+	vcpu->common->run->system_event.type = type;
+	vcpu->common->run->system_event.ndata = 1;
+	vcpu->common->run->system_event.data[0] = flags;
+	vcpu->common->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
 }
 
 static void kvm_psci_system_off(struct kvm_vcpu *vcpu)
@@ -207,9 +207,9 @@ static void kvm_psci_system_reset2(struct kvm_vcpu *vcpu)
 
 static void kvm_psci_system_suspend(struct kvm_vcpu *vcpu)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 
-	memset(&run->system_event, 0, sizeof(vcpu->run->system_event));
+	memset(&run->system_event, 0, sizeof(vcpu->common->run->system_event));
 	run->system_event.type = KVM_SYSTEM_EVENT_SUSPEND;
 	run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
 }
arch/arm64/kvm/vgic/vgic.c +1 -1
index f07b3ddff7d4..4685bc985779 100644
@@ -24,7 +24,7 @@ struct vgic_global kvm_vgic_global_state __ro_after_init = {
 /*
  * Locking order is always:
  * kvm->lock (mutex)
- *   vcpu->mutex (mutex)
+ *   vcpu->common->mutex (mutex)
  *     kvm->arch.config_lock (mutex)
  *       its->cmd_lock (mutex)
  *         its->its_lock (mutex)
arch/loongarch/kvm/exit.c +26 -26

184 lines not on this page · raw message

arch/loongarch/kvm/timer.c +1 -1
index bcc6b6d063d9..195984339769 100644
@@ -30,7 +30,7 @@ enum hrtimer_restart kvm_swtimer_wakeup(struct hrtimer *timer)
 
 	vcpu = container_of(timer, struct kvm_vcpu, arch.swtimer);
 	kvm_queue_irq(vcpu, INT_TI);
-	rcuwait_wake_up(&vcpu->wait);
+	rcuwait_wake_up(&vcpu->common->wait);
 
 	return HRTIMER_NORESTART;
 }
arch/loongarch/kvm/vcpu.c +11 -11
index 16756ffb55e8..cf63b36d92e8 100644
@@ -156,7 +156,7 @@ static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
 		kvm_deliver_intr(vcpu);
 		kvm_deliver_exception(vcpu);
 		/* Make sure the vcpu mode has been written */
-		smp_store_mb(vcpu->mode, IN_GUEST_MODE);
+		smp_store_mb(vcpu->common->mode, IN_GUEST_MODE);
 		kvm_check_vpid(vcpu);
 
 		/*
@@ -171,7 +171,7 @@ static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
 
 		if (kvm_request_pending(vcpu) || xfer_to_guest_mode_work_pending()) {
 			/* make sure the vcpu mode has been written */
-			smp_store_mb(vcpu->mode, OUTSIDE_GUEST_MODE);
+			smp_store_mb(vcpu->common->mode, OUTSIDE_GUEST_MODE);
 			local_irq_enable();
 			ret = -EAGAIN;
 		}
@@ -190,7 +190,7 @@ static int kvm_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 	u32 intr = estat & 0x1fff; /* Ignore NMI */
 	u32 ecode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
 
-	vcpu->mode = OUTSIDE_GUEST_MODE;
+	vcpu->common->mode = OUTSIDE_GUEST_MODE;
 
 	/* Set a default exit reason */
 	run->exit_reason = KVM_EXIT_UNKNOWN;
@@ -204,7 +204,7 @@ static int kvm_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 		ret = kvm_handle_fault(vcpu, ecode);
 	} else {
 		WARN(!intr, "vm exiting with suspicious irq\n");
-		++vcpu->stat.int_exits;
+		++vcpu->common->stat.int_exits;
 	}
 
 	if (ret == RESUME_GUEST)
@@ -316,9 +316,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 		return -EINVAL;
 
 	if (dbg->control & KVM_GUESTDBG_ENABLE)
-		vcpu->guest_debug = dbg->control;
+		vcpu->common->guest_debug = dbg->control;
 	else
-		vcpu->guest_debug = 0;
+		vcpu->common->guest_debug = 0;
 
 	return 0;
 }
@@ -1403,12 +1403,12 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 {
 	int r = -EINTR;
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 
-	if (vcpu->mmio_needed) {
-		if (!vcpu->mmio_is_write)
+	if (vcpu->common->mmio_needed) {
+		if (!vcpu->common->mmio_is_write)
 			kvm_complete_mmio_read(vcpu, run);
-		vcpu->mmio_needed = 0;
+		vcpu->common->mmio_needed = 0;
 	}
 
 	if (run->exit_reason == KVM_EXIT_LOONGARCH_IOCSR) {
@@ -1416,7 +1416,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 			kvm_complete_iocsr_read(vcpu, run);
 	}
 
-	if (!vcpu->wants_to_run)
+	if (!vcpu->common->wants_to_run)
 		return r;
 
 	/* Clear exit_reason */
arch/mips/kvm/emulate.c +47 -47

279 lines not on this page · raw message

arch/mips/kvm/mips.c +26 -26

169 lines not on this page · raw message

arch/mips/kvm/vz.c +15 -15
index 99d5a71e4300..7f720410f2fd 100644
@@ -833,7 +833,7 @@ static int kvm_trap_vz_no_handler(struct kvm_vcpu *vcpu)
 		exccode, opc, inst, badvaddr,
 		read_gc0_status());
 	kvm_arch_vcpu_dump_regs(vcpu);
-	vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+	vcpu->common->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
 	return RESUME_HOST;
 }
 
@@ -1162,7 +1162,7 @@ static enum emulation_result kvm_vz_gpsi_lwc2(union mips_instruction inst,
 	rd = inst.loongson3_lscsr_format.rd;
 	switch (inst.loongson3_lscsr_format.fr) {
 	case 0x8:  /* Read CPUCFG */
-		++vcpu->stat.vz_cpucfg_exits;
+		++vcpu->common->stat.vz_cpucfg_exits;
 		hostcfg = read_cpucfg(vcpu->arch.gprs[rs]);
 
 		switch (vcpu->arch.gprs[rs]) {
@@ -1491,38 +1491,38 @@ static int kvm_trap_vz_handle_guest_exit(struct kvm_vcpu *vcpu)
 	trace_kvm_exit(vcpu, KVM_TRACE_EXIT_GEXCCODE_BASE + gexccode);
 	switch (gexccode) {
 	case MIPS_GCTL0_GEXC_GPSI:
-		++vcpu->stat.vz_gpsi_exits;
+		++vcpu->common->stat.vz_gpsi_exits;
 		er = kvm_trap_vz_handle_gpsi(cause, opc, vcpu);
 		break;
 	case MIPS_GCTL0_GEXC_GSFC:
-		++vcpu->stat.vz_gsfc_exits;
+		++vcpu->common->stat.vz_gsfc_exits;
 		er = kvm_trap_vz_handle_gsfc(cause, opc, vcpu);
 		break;
 	case MIPS_GCTL0_GEXC_HC:
-		++vcpu->stat.vz_hc_exits;
+		++vcpu->common->stat.vz_hc_exits;
 		er = kvm_trap_vz_handle_hc(cause, opc, vcpu);
 		break;
 	case MIPS_GCTL0_GEXC_GRR:
-		++vcpu->stat.vz_grr_exits;
+		++vcpu->common->stat.vz_grr_exits;
 		er = kvm_trap_vz_no_handler_guest_exit(gexccode, cause, opc,
 						       vcpu);
 		break;
 	case MIPS_GCTL0_GEXC_GVA:
-		++vcpu->stat.vz_gva_exits;
+		++vcpu->common->stat.vz_gva_exits;
 		er = kvm_trap_vz_no_handler_guest_exit(gexccode, cause, opc,
 						       vcpu);
 		break;
 	case MIPS_GCTL0_GEXC_GHFC:
-		++vcpu->stat.vz_ghfc_exits;
+		++vcpu->common->stat.vz_ghfc_exits;
 		er = kvm_trap_vz_handle_ghfc(cause, opc, vcpu);
 		break;
 	case MIPS_GCTL0_GEXC_GPA:
-		++vcpu->stat.vz_gpa_exits;
+		++vcpu->common->stat.vz_gpa_exits;
 		er = kvm_trap_vz_no_handler_guest_exit(gexccode, cause, opc,
 						       vcpu);
 		break;
 	default:
-		++vcpu->stat.vz_resvd_exits;
+		++vcpu->common->stat.vz_resvd_exits;
 		er = kvm_trap_vz_no_handler_guest_exit(gexccode, cause, opc,
 						       vcpu);
 		break;
@@ -1534,7 +1534,7 @@ static int kvm_trap_vz_handle_guest_exit(struct kvm_vcpu *vcpu)
 	} else if (er == EMULATE_HYPERCALL) {
 		ret = kvm_mips_handle_hypcall(vcpu);
 	} else {
-		vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+		vcpu->common->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
 		ret = RESUME_HOST;
 	}
 	return ret;
@@ -1579,7 +1579,7 @@ static int kvm_trap_vz_handle_cop_unusable(struct kvm_vcpu *vcpu)
 		break;
 
 	case EMULATE_FAIL:
-		vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+		vcpu->common->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
 		ret = RESUME_HOST;
 		break;
 
@@ -1611,7 +1611,7 @@ static int kvm_trap_vz_handle_msa_disabled(struct kvm_vcpu *vcpu)
 	    (read_gc0_status() & (ST0_CU1 | ST0_FR)) == ST0_CU1 ||
 	    !(read_gc0_config5() & MIPS_CONF5_MSAEN) ||
 	    vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA) {
-		vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+		vcpu->common->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
 		return RESUME_HOST;
 	}
 
@@ -1622,7 +1622,7 @@ static int kvm_trap_vz_handle_msa_disabled(struct kvm_vcpu *vcpu)
 
 static int kvm_trap_vz_handle_tlb_ld_miss(struct kvm_vcpu *vcpu)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	u32 *opc = (u32 *) vcpu->arch.pc;
 	u32 cause = vcpu->arch.host_cp0_cause;
 	ulong badvaddr = vcpu->arch.host_cp0_badvaddr;
@@ -1669,7 +1669,7 @@ static int kvm_trap_vz_handle_tlb_ld_miss(struct kvm_vcpu *vcpu)
 
 static int kvm_trap_vz_handle_tlb_st_miss(struct kvm_vcpu *vcpu)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	u32 *opc = (u32 *) vcpu->arch.pc;
 	u32 cause = vcpu->arch.host_cp0_cause;
 	ulong badvaddr = vcpu->arch.host_cp0_badvaddr;
arch/powerpc/kvm/book3s.c +2 -2
index ff6c38373957..75665a8ae276 100644
@@ -178,7 +178,7 @@ void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu,
 
 void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)
 {
-	vcpu->stat.queue_intr++;
+	vcpu->common->stat.queue_intr++;
 
 	set_bit(kvmppc_book3s_vec2irqprio(vec),
 		&vcpu->arch.pending_exceptions);
@@ -818,7 +818,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 					struct kvm_guest_debug *dbg)
 {
 	vcpu_load(vcpu);
-	vcpu->guest_debug = dbg->control;
+	vcpu->common->guest_debug = dbg->control;
 	vcpu_put(vcpu);
 	return 0;
 }
arch/powerpc/kvm/book3s_emulate.c +3 -3
index de126d153328..7078db40fb17 100644
@@ -367,13 +367,13 @@ int kvmppc_core_emulate_op_pr(struct kvm_vcpu *vcpu,
 			if (kvmppc_h_pr(vcpu, cmd) == EMULATE_DONE)
 				break;
 
-			vcpu->run->papr_hcall.nr = cmd;
+			vcpu->common->run->papr_hcall.nr = cmd;
 			for (i = 0; i < 9; ++i) {
 				ulong gpr = kvmppc_get_gpr(vcpu, 4 + i);
-				vcpu->run->papr_hcall.args[i] = gpr;
+				vcpu->common->run->papr_hcall.args[i] = gpr;
 			}
 
-			vcpu->run->exit_reason = KVM_EXIT_PAPR_HCALL;
+			vcpu->common->run->exit_reason = KVM_EXIT_PAPR_HCALL;
 			vcpu->arch.hcall_needed = 1;
 			emulated = EMULATE_EXIT_USER;
 			break;
arch/powerpc/kvm/book3s_hv.c +19 -19
index 8f7d7e37bc8c..b71735d10d85 100644
@@ -238,7 +238,7 @@ static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
 
 	waitp = kvm_arch_vcpu_get_wait(vcpu);
 	if (rcuwait_wake_up(waitp))
-		++vcpu->stat.generic.halt_wakeup;
+		++vcpu->common->stat.generic.halt_wakeup;
 
 	cpu = READ_ONCE(vcpu->arch.thread_cpu);
 	if (cpu >= 0 && kvmppc_ipi_thread(cpu))
@@ -1482,8 +1482,8 @@ static int kvmppc_emulate_debug_inst(struct kvm_vcpu *vcpu)
 	}
 
 	if (ppc_inst_val(last_inst) == KVMPPC_INST_SW_BREAKPOINT) {
-		vcpu->run->exit_reason = KVM_EXIT_DEBUG;
-		vcpu->run->debug.arch.address = kvmppc_get_pc(vcpu);
+		vcpu->common->run->exit_reason = KVM_EXIT_DEBUG;
+		vcpu->common->run->debug.arch.address = kvmppc_get_pc(vcpu);
 		return RESUME_HOST;
 	} else {
 		kvmppc_core_queue_program(vcpu, SRR1_PROGILL |
@@ -1627,10 +1627,10 @@ static int kvmppc_tm_unavailable(struct kvm_vcpu *vcpu)
 static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,
 				 struct task_struct *tsk)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	int r = RESUME_HOST;
 
-	vcpu->stat.sum_exits++;
+	vcpu->common->stat.sum_exits++;
 
 	/*
 	 * This can happen if an interrupt occurs in the last stages
@@ -1659,13 +1659,13 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,
 		vcpu->arch.trap = BOOK3S_INTERRUPT_HV_DECREMENTER;
 		fallthrough;
 	case BOOK3S_INTERRUPT_HV_DECREMENTER:
-		vcpu->stat.dec_exits++;
+		vcpu->common->stat.dec_exits++;
 		r = RESUME_GUEST;
 		break;
 	case BOOK3S_INTERRUPT_EXTERNAL:
 	case BOOK3S_INTERRUPT_H_DOORBELL:
 	case BOOK3S_INTERRUPT_H_VIRT:
-		vcpu->stat.ext_intr_exits++;
+		vcpu->common->stat.ext_intr_exits++;
 		r = RESUME_GUEST;
 		break;
 	/* SR/HMI/PMI are HV interrupts that host has handled. Resume guest.*/
@@ -1887,7 +1887,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,
 			vcpu->arch.last_inst = kvmppc_need_byteswap(vcpu) ?
 				swab32(vcpu->arch.emul_inst) :
 				vcpu->arch.emul_inst;
-		if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) {
+		if (vcpu->common->guest_debug & KVM_GUESTDBG_USE_SW_BP) {
 			r = kvmppc_emulate_debug_inst(vcpu);
 		} else {
 			kvmppc_core_queue_program(vcpu, SRR1_PROGILL |
@@ -1960,7 +1960,7 @@ static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu)
 	int r;
 	int srcu_idx;
 
-	vcpu->stat.sum_exits++;
+	vcpu->common->stat.sum_exits++;
 
 	/*
 	 * This can happen if an interrupt occurs in the last stages
@@ -1981,22 +1981,22 @@ static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu)
 	switch (vcpu->arch.trap) {
 	/* We're good on these - the host merely wanted to get our attention */
 	case BOOK3S_INTERRUPT_HV_DECREMENTER:
-		vcpu->stat.dec_exits++;
+		vcpu->common->stat.dec_exits++;
 		r = RESUME_GUEST;
 		break;
 	case BOOK3S_INTERRUPT_EXTERNAL:
-		vcpu->stat.ext_intr_exits++;
+		vcpu->common->stat.ext_intr_exits++;
 		r = RESUME_HOST;
 		break;
 	case BOOK3S_INTERRUPT_H_DOORBELL:
 	case BOOK3S_INTERRUPT_H_VIRT:
-		vcpu->stat.ext_intr_exits++;
+		vcpu->common->stat.ext_intr_exits++;
 		r = RESUME_GUEST;
 		break;
 	/* These need to go to the nested HV */
 	case BOOK3S_INTERRUPT_NESTED_HV_DECREMENTER:
 		vcpu->arch.trap = BOOK3S_INTERRUPT_HV_DECREMENTER;
-		vcpu->stat.dec_exits++;
+		vcpu->common->stat.dec_exits++;
 		r = RESUME_HOST;
 		break;
 	/* SR/HMI/PMI are HV interrupts that host has handled. Resume guest.*/
@@ -4679,7 +4679,7 @@ static int kvmhv_setup_mmu(struct kvm_vcpu *vcpu)
 
 static int kvmppc_run_vcpu(struct kvm_vcpu *vcpu)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	int n_ceded, i, r;
 	struct kvmppc_vcore *vc;
 	struct kvm_vcpu *v;
@@ -4790,7 +4790,7 @@ static int kvmppc_run_vcpu(struct kvm_vcpu *vcpu)
 
 	if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) {
 		kvmppc_remove_runnable(vc, vcpu, mftb());
-		vcpu->stat.signal_exits++;
+		vcpu->common->stat.signal_exits++;
 		run->exit_reason = KVM_EXIT_INTR;
 		vcpu->arch.ret = -EINTR;
 	}
@@ -4811,7 +4811,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,
 			  unsigned long lpcr)
 {
 	struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu);
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	int trap, r, pcpu;
 	int srcu_idx;
 	struct kvmppc_vcore *vc;
@@ -4978,7 +4978,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,
 		for (;;) {
 			set_current_state(TASK_INTERRUPTIBLE);
 			if (signal_pending(current)) {
-				vcpu->stat.signal_exits++;
+				vcpu->common->stat.signal_exits++;
 				run->exit_reason = KVM_EXIT_INTR;
 				vcpu->arch.ret = -EINTR;
 				break;
@@ -5001,7 +5001,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,
 	return vcpu->arch.ret;
 
  sigpend:
-	vcpu->stat.signal_exits++;
+	vcpu->common->stat.signal_exits++;
 	run->exit_reason = KVM_EXIT_INTR;
 	vcpu->arch.ret = -EINTR;
  out:
@@ -5015,7 +5015,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,
 
 static int kvmppc_vcpu_run_hv(struct kvm_vcpu *vcpu)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	int r;
 	int srcu_idx;
 	struct kvm *kvm;
arch/powerpc/kvm/book3s_hv_nested.c +2 -2
index 05f5220960c6..0a8383cca6f7 100644
@@ -203,7 +203,7 @@ static void kvmhv_nested_mmio_needed(struct kvm_vcpu *vcpu, u64 regs_ptr)
 	 * written there in kvmppc_complete_mmio_load()
 	 */
 	if (((vcpu->arch.io_gpr & KVM_MMIO_REG_EXT_MASK) == KVM_MMIO_REG_GPR)
-	    && (vcpu->mmio_is_write == 0)) {
+	    && (vcpu->common->mmio_is_write == 0)) {
 		vcpu->arch.nested_io_gpr = (gpa_t) regs_ptr +
 					   offsetof(struct pt_regs,
 						    gpr[vcpu->arch.io_gpr]);
@@ -420,7 +420,7 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
 	if (r == -EINTR)
 		return H_INTERRUPT;
 
-	if (vcpu->mmio_needed) {
+	if (vcpu->common->mmio_needed) {
 		kvmhv_nested_mmio_needed(vcpu, regs_ptr);
 		return H_TOO_HARD;
 	}
arch/powerpc/kvm/book3s_hv_rm_xics.c +4 -4
index f2636414d82a..abc5b2b7afc5 100644
@@ -132,7 +132,7 @@ static void icp_rm_set_vcpu_irq(struct kvm_vcpu *vcpu,
 	int hcore;
 
 	/* Mark the target VCPU as having an interrupt pending */
-	vcpu->stat.queue_intr++;
+	vcpu->common->stat.queue_intr++;
 	set_bit(BOOK3S_IRQPRIO_EXTERNAL, &vcpu->arch.pending_exceptions);
 
 	/* Kick self ? Just set MER and return */
@@ -713,14 +713,14 @@ static int ics_rm_eoi(struct kvm_vcpu *vcpu, u32 irq)
 
 	/* Handle passthrough interrupts */
 	if (state->host_irq) {
-		++vcpu->stat.pthru_all;
+		++vcpu->common->stat.pthru_all;
 		if (state->intr_cpu != -1) {
 			int pcpu = raw_smp_processor_id();
 
 			pcpu = cpu_first_thread_sibling(pcpu);
-			++vcpu->stat.pthru_host;
+			++vcpu->common->stat.pthru_host;
 			if (state->intr_cpu != pcpu) {
-				++vcpu->stat.pthru_bad_aff;
+				++vcpu->common->stat.pthru_bad_aff;
 				xics_opal_set_server(state->host_irq, pcpu);
 			}
 			state->intr_cpu = -1;
arch/powerpc/kvm/book3s_pr.c +19 -19
index 7b8ae509328f..a9ba0b6334d0 100644
@@ -493,7 +493,7 @@ static void kvmppc_set_msr_pr(struct kvm_vcpu *vcpu, u64 msr)
 	if (msr & MSR_POW) {
 		if (!vcpu->arch.pending_exceptions) {
 			kvm_vcpu_halt(vcpu);
-			vcpu->stat.generic.halt_wakeup++;
+			vcpu->common->stat.generic.halt_wakeup++;
 
 			/* Unset POW bit after we woke up */
 			msr &= ~MSR_POW;
@@ -774,17 +774,17 @@ static int kvmppc_handle_pagefault(struct kvm_vcpu *vcpu,
 		/* The guest's PTE is not mapped yet. Map on the host */
 		if (kvmppc_mmu_map_page(vcpu, &pte, iswrite) == -EIO) {
 			/* Exit KVM if mapping failed */
-			vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+			vcpu->common->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
 			return RESUME_HOST;
 		}
 		if (data)
-			vcpu->stat.sp_storage++;
+			vcpu->common->stat.sp_storage++;
 		else if (vcpu->arch.mmu.is_dcbz32(vcpu) &&
 			 (!(vcpu->arch.hflags & BOOK3S_HFLAG_DCBZ32)))
 			kvmppc_patch_dcbz(vcpu, &pte);
 	} else {
 		/* MMIO */
-		vcpu->stat.mmio_exits++;
+		vcpu->common->stat.mmio_exits++;
 		vcpu->arch.paddr_accessed = pte.raddr;
 		vcpu->arch.vaddr_accessed = pte.eaddr;
 		r = kvmppc_emulate_mmio(vcpu);
@@ -1056,7 +1056,7 @@ void kvmppc_set_fscr(struct kvm_vcpu *vcpu, u64 fscr)
 
 static void kvmppc_setup_debug(struct kvm_vcpu *vcpu)
 {
-	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
+	if (vcpu->common->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
 		u64 msr = kvmppc_get_msr(vcpu);
 
 		kvmppc_set_msr(vcpu, msr | MSR_SE);
@@ -1065,7 +1065,7 @@ static void kvmppc_setup_debug(struct kvm_vcpu *vcpu)
 
 static void kvmppc_clear_debug(struct kvm_vcpu *vcpu)
 {
-	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
+	if (vcpu->common->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
 		u64 msr = kvmppc_get_msr(vcpu);
 
 		kvmppc_set_msr(vcpu, msr & ~MSR_SE);
@@ -1105,7 +1105,7 @@ static int kvmppc_exit_pr_progint(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 		}
 	}
 
-	vcpu->stat.emulated_inst_exits++;
+	vcpu->common->stat.emulated_inst_exits++;
 	er = kvmppc_emulate_instruction(vcpu);
 	switch (er) {
 	case EMULATE_DONE:
@@ -1121,7 +1121,7 @@ static int kvmppc_exit_pr_progint(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 		r = RESUME_GUEST;
 		break;
 	case EMULATE_DO_MMIO:
-		vcpu->run->exit_reason = KVM_EXIT_MMIO;
+		vcpu->common->run->exit_reason = KVM_EXIT_MMIO;
 		r = RESUME_HOST_NV;
 		break;
 	case EMULATE_EXIT_USER:
@@ -1136,11 +1136,11 @@ static int kvmppc_exit_pr_progint(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 
 int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	int r = RESUME_HOST;
 	int s;
 
-	vcpu->stat.sum_exits++;
+	vcpu->common->stat.sum_exits++;
 
 	run->exit_reason = KVM_EXIT_UNKNOWN;
 	run->ready_for_interrupt_injection = 1;
@@ -1154,7 +1154,7 @@ int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 	case BOOK3S_INTERRUPT_INST_STORAGE:
 	{
 		ulong shadow_srr1 = vcpu->arch.shadow_srr1;
-		vcpu->stat.pf_instruc++;
+		vcpu->common->stat.pf_instruc++;
 
 		if (kvmppc_is_split_real(vcpu))
 			kvmppc_fixup_split_real(vcpu);
@@ -1182,7 +1182,7 @@ int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 			int idx = srcu_read_lock(&vcpu->kvm->srcu);
 			r = kvmppc_handle_pagefault(vcpu, kvmppc_get_pc(vcpu), exit_nr);
 			srcu_read_unlock(&vcpu->kvm->srcu, idx);
-			vcpu->stat.sp_instruc++;
+			vcpu->common->stat.sp_instruc++;
 		} else if (vcpu->arch.mmu.is_dcbz32(vcpu) &&
 			  (!(vcpu->arch.hflags & BOOK3S_HFLAG_DCBZ32))) {
 			/*
@@ -1203,7 +1203,7 @@ int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 	{
 		ulong dar = kvmppc_get_fault_dar(vcpu);
 		u32 fault_dsisr = vcpu->arch.fault_dsisr;
-		vcpu->stat.pf_storage++;
+		vcpu->common->stat.pf_storage++;
 
 #ifdef CONFIG_PPC_BOOK3S_32
 		/* We set segments as unused segments when invalidating them. So
@@ -1258,13 +1258,13 @@ int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 	case BOOK3S_INTERRUPT_HV_DECREMENTER:
 	case BOOK3S_INTERRUPT_DOORBELL:
 	case BOOK3S_INTERRUPT_H_DOORBELL:
-		vcpu->stat.dec_exits++;
+		vcpu->common->stat.dec_exits++;
 		r = RESUME_GUEST;
 		break;
 	case BOOK3S_INTERRUPT_EXTERNAL:
 	case BOOK3S_INTERRUPT_EXTERNAL_HV:
 	case BOOK3S_INTERRUPT_H_VIRT:
-		vcpu->stat.ext_intr_exits++;
+		vcpu->common->stat.ext_intr_exits++;
 		r = RESUME_GUEST;
 		break;
 	case BOOK3S_INTERRUPT_HMI:
@@ -1333,7 +1333,7 @@ int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 			r = RESUME_GUEST;
 		} else {
 			/* Guest syscalls */
-			vcpu->stat.syscall_exits++;
+			vcpu->common->stat.syscall_exits++;
 			kvmppc_book3s_queue_irqprio(vcpu, exit_nr);
 			r = RESUME_GUEST;
 		}
@@ -1407,7 +1407,7 @@ int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 		r = RESUME_GUEST;
 		break;
 	case BOOK3S_INTERRUPT_TRACE:
-		if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
+		if (vcpu->common->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
 			run->exit_reason = KVM_EXIT_DEBUG;
 			r = RESUME_HOST;
 		} else {
@@ -1813,7 +1813,7 @@ static int kvmppc_vcpu_run_pr(struct kvm_vcpu *vcpu)
 
 	/* Check if we can run the vcpu at all */
 	if (!vcpu->arch.sane) {
-		vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+		vcpu->common->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
 		ret = -EINVAL;
 		goto out;
 	}
@@ -1855,7 +1855,7 @@ static int kvmppc_vcpu_run_pr(struct kvm_vcpu *vcpu)
 
 	srr_regs_clobbered();
 out:
-	vcpu->mode = OUTSIDE_GUEST_MODE;
+	vcpu->common->mode = OUTSIDE_GUEST_MODE;
 	return ret;
 }
 
arch/powerpc/kvm/book3s_pr_papr.c +1 -1
index b2c89e850d7a..bde9c79c339b 100644
@@ -393,7 +393,7 @@ int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd)
 	case H_CEDE:
 		kvmppc_set_msr_fast(vcpu, kvmppc_get_msr(vcpu) | MSR_EE);
 		kvm_vcpu_halt(vcpu);
-		vcpu->stat.generic.halt_wakeup++;
+		vcpu->common->stat.generic.halt_wakeup++;
 		return EMULATE_DONE;
 	case H_LOGICAL_CI_LOAD:
 		return kvmppc_h_pr_logical_ci_load(vcpu);
arch/powerpc/kvm/book3s_xics.c +4 -4
index 589a8f257120..94bd793a760d 100644
@@ -1353,17 +1353,17 @@ static void kvmppc_xics_release(struct kvm_device *dev)
 	 */
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		/*
-		 * Take vcpu->mutex to ensure that no one_reg get/set ioctl
+		 * Take vcpu->common->mutex to ensure that no one_reg get/set ioctl
 		 * (i.e. kvmppc_xics_[gs]et_icp) can be done concurrently.
-		 * Holding the vcpu->mutex also means that execution is
+		 * Holding the vcpu->common->mutex also means that execution is
 		 * excluded for the vcpu until the ICP was freed. When the vcpu
 		 * can execute again, vcpu->arch.icp and vcpu->arch.irq_type
 		 * have been cleared and the vcpu will not be going into the
 		 * XICS code anymore.
 		 */
-		mutex_lock(&vcpu->mutex);
+		mutex_lock(&vcpu->common->mutex);
 		kvmppc_xics_free_icp(vcpu);
-		mutex_unlock(&vcpu->mutex);
+		mutex_unlock(&vcpu->common->mutex);
 	}
 
 	if (kvm)
arch/powerpc/kvm/book3s_xive.c +6 -6
index 1362c672387e..ae7ec36e5fbd 100644
@@ -1510,7 +1510,7 @@ int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval)
 
 	/*
 	 * We can't update the state of a "pushed" VCPU, but that
-	 * shouldn't happen because the vcpu->mutex makes running a
+	 * shouldn't happen because the vcpu->common->mutex makes running a
 	 * vcpu mutually exclusive with doing one_reg get/set on it.
 	 */
 	if (WARN_ON(vcpu->arch.xive_pushed))
@@ -1770,7 +1770,7 @@ void kvmppc_xive_disable_vcpu_interrupts(struct kvm_vcpu *vcpu)
 
 	/*
 	 * Clear pointers to escalation interrupt ESB.
-	 * This is safe because the vcpu->mutex is held, preventing
+	 * This is safe because the vcpu->common->mutex is held, preventing
 	 * any other CPU from concurrently executing a KVM_RUN ioctl.
 	 */
 	vcpu->arch.xive_esc_vaddr = 0;
@@ -2663,16 +2663,16 @@ static void kvmppc_xive_release(struct kvm_device *dev)
 	 */
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		/*
-		 * Take vcpu->mutex to ensure that no one_reg get/set ioctl
+		 * Take vcpu->common->mutex to ensure that no one_reg get/set ioctl
 		 * (i.e. kvmppc_xive_[gs]et_icp) can be done concurrently.
-		 * Holding the vcpu->mutex also means that the vcpu cannot
+		 * Holding the vcpu->common->mutex also means that the vcpu cannot
 		 * be executing the KVM_RUN ioctl, and therefore it cannot
 		 * be executing the XIVE push or pull code or accessing
 		 * the XIVE MMIO regions.
 		 */
-		mutex_lock(&vcpu->mutex);
+		mutex_lock(&vcpu->common->mutex);
 		kvmppc_xive_cleanup_vcpu(vcpu);
-		mutex_unlock(&vcpu->mutex);
+		mutex_unlock(&vcpu->common->mutex);
 	}
 
 	/*
arch/powerpc/kvm/book3s_xive_native.c +4 -4
index 6e2ebbd8aaac..8cf6489f0d76 100644
@@ -1045,16 +1045,16 @@ static void kvmppc_xive_native_release(struct kvm_device *dev)
 	 */
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		/*
-		 * Take vcpu->mutex to ensure that no one_reg get/set ioctl
+		 * Take vcpu->common->mutex to ensure that no one_reg get/set ioctl
 		 * (i.e. kvmppc_xive_native_[gs]et_vp) can be being done.
-		 * Holding the vcpu->mutex also means that the vcpu cannot
+		 * Holding the vcpu->common->mutex also means that the vcpu cannot
 		 * be executing the KVM_RUN ioctl, and therefore it cannot
 		 * be executing the XIVE push or pull code or accessing
 		 * the XIVE MMIO regions.
 		 */
-		mutex_lock(&vcpu->mutex);
+		mutex_lock(&vcpu->common->mutex);
 		kvmppc_xive_native_cleanup_vcpu(vcpu);
-		mutex_unlock(&vcpu->mutex);
+		mutex_unlock(&vcpu->common->mutex);
 	}
 
 	/*
arch/powerpc/kvm/booke.c +19 -19
index 6a5be025a8af..10e4fbf8b8cd 100644
@@ -234,7 +234,7 @@ static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu)
 #endif
 
 	/* Force enable debug interrupts when user space wants to debug */
-	if (vcpu->guest_debug) {
+	if (vcpu->common->guest_debug) {
 #ifdef CONFIG_KVM_BOOKE_HV
 		/*
 		 * Since there is no shadow MSR, sync MSR_DE into the guest
@@ -743,14 +743,14 @@ int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
 #endif
 
 	if (kvm_check_request(KVM_REQ_WATCHDOG, vcpu)) {
-		vcpu->run->exit_reason = KVM_EXIT_WATCHDOG;
+		vcpu->common->run->exit_reason = KVM_EXIT_WATCHDOG;
 		r = 0;
 	}
 
 	if (kvm_check_request(KVM_REQ_EPR_EXIT, vcpu)) {
-		vcpu->run->epr.epr = 0;
+		vcpu->common->run->epr.epr = 0;
 		vcpu->arch.epr_needed = true;
-		vcpu->run->exit_reason = KVM_EXIT_EPR;
+		vcpu->common->run->exit_reason = KVM_EXIT_EPR;
 		r = 0;
 	}
 
@@ -763,7 +763,7 @@ int kvmppc_vcpu_run(struct kvm_vcpu *vcpu)
 	struct debug_reg debug;
 
 	if (!vcpu->arch.sane) {
-		vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+		vcpu->common->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
 		return -EINVAL;
 	}
 
@@ -823,7 +823,7 @@ int kvmppc_vcpu_run(struct kvm_vcpu *vcpu)
 #endif
 
 out:
-	vcpu->mode = OUTSIDE_GUEST_MODE;
+	vcpu->common->mode = OUTSIDE_GUEST_MODE;
 	return ret;
 }
 
@@ -848,8 +848,8 @@ static int emulation_exit(struct kvm_vcpu *vcpu)
 		       __func__, vcpu->arch.regs.nip, vcpu->arch.last_inst);
 		/* For debugging, encode the failing instruction and
 		 * report it to userspace. */
-		vcpu->run->hw.hardware_exit_reason = ~0ULL << 32;
-		vcpu->run->hw.hardware_exit_reason |= vcpu->arch.last_inst;
+		vcpu->common->run->hw.hardware_exit_reason = ~0ULL << 32;
+		vcpu->common->run->hw.hardware_exit_reason |= vcpu->arch.last_inst;
 		kvmppc_core_queue_program(vcpu, ESR_PIL);
 		return RESUME_HOST;
 
@@ -863,11 +863,11 @@ static int emulation_exit(struct kvm_vcpu *vcpu)
 
 static int kvmppc_handle_debug(struct kvm_vcpu *vcpu)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	struct debug_reg *dbg_reg = &(vcpu->arch.dbg_reg);
 	u32 dbsr = vcpu->arch.dbsr;
 
-	if (vcpu->guest_debug == 0) {
+	if (vcpu->common->guest_debug == 0) {
 		/*
 		 * Debug resources belong to Guest.
 		 * Imprecise debug event is not injected
@@ -993,8 +993,8 @@ static int kvmppc_resume_inst_load(struct kvm_vcpu *vcpu,
 		       __func__, vcpu->arch.regs.nip);
 		/* For debugging, encode the failing instruction and
 		 * report it to userspace. */
-		vcpu->run->hw.hardware_exit_reason = ~0ULL << 32;
-		vcpu->run->hw.hardware_exit_reason |= last_inst;
+		vcpu->common->run->hw.hardware_exit_reason = ~0ULL << 32;
+		vcpu->common->run->hw.hardware_exit_reason |= last_inst;
 		kvmppc_core_queue_program(vcpu, ESR_PIL);
 		return RESUME_HOST;
 
@@ -1010,7 +1010,7 @@ static int kvmppc_resume_inst_load(struct kvm_vcpu *vcpu,
  */
 int kvmppc_handle_exit(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 {
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	int r = RESUME_HOST;
 	int s;
 	int idx;
@@ -1040,7 +1040,7 @@ int kvmppc_handle_exit(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 		break;
 	case BOOKE_INTERRUPT_PROGRAM:
 		/* SW breakpoints arrive as illegal instructions on HV */
-		if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) {
+		if (vcpu->common->guest_debug & KVM_GUESTDBG_USE_SW_BP) {
 			emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, &pinst);
 			last_inst = ppc_inst_val(pinst);
 		}
@@ -1136,7 +1136,7 @@ int kvmppc_handle_exit(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 		break;
 
 	case BOOKE_INTERRUPT_PROGRAM:
-		if ((vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) &&
+		if ((vcpu->common->guest_debug & KVM_GUESTDBG_USE_SW_BP) &&
 			(last_inst == KVMPPC_INST_SW_BREAKPOINT)) {
 			/*
 			 * We are here because of an SW breakpoint instr,
@@ -2039,16 +2039,16 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 
 	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
 		vcpu->arch.dbg_reg.dbcr0 = 0;
-		vcpu->guest_debug = 0;
+		vcpu->common->guest_debug = 0;
 		kvm_guest_protect_msr(vcpu, MSR_DE, false);
 		goto out;
 	}
 
 	kvm_guest_protect_msr(vcpu, MSR_DE, true);
-	vcpu->guest_debug = dbg->control;
+	vcpu->common->guest_debug = dbg->control;
 	vcpu->arch.dbg_reg.dbcr0 = 0;
 
-	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
+	if (vcpu->common->guest_debug & KVM_GUESTDBG_SINGLESTEP)
 		vcpu->arch.dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
 
 	/* Code below handles only HW breakpoints */
@@ -2072,7 +2072,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 	dbg_reg->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
 #endif
 
-	if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP))
+	if (!(vcpu->common->guest_debug & KVM_GUESTDBG_USE_HW_BP))
 		goto out;
 
 	ret = -EINVAL;
arch/powerpc/kvm/booke_emulate.c +11 -11
index d8d38aca71bd..77d0f0f40db8 100644
@@ -146,7 +146,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		debug_inst = true;
@@ -157,7 +157,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		debug_inst = true;
@@ -169,7 +169,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		debug_inst = true;
@@ -180,7 +180,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		debug_inst = true;
@@ -192,7 +192,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		debug_inst = true;
@@ -203,7 +203,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		debug_inst = true;
@@ -214,7 +214,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		debug_inst = true;
@@ -229,7 +229,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		debug_inst = true;
@@ -240,7 +240,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		debug_inst = true;
@@ -251,7 +251,7 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		 * If userspace is debugging guest then guest
 		 * can not access debug registers.
 		 */
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			break;
 
 		vcpu->arch.dbsr &= ~spr_val;
@@ -427,7 +427,7 @@ int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
 		break;
 	case SPRN_DBCR0:
 		*spr_val = vcpu->arch.dbg_reg.dbcr0;
-		if (vcpu->guest_debug)
+		if (vcpu->common->guest_debug)
 			*spr_val = *spr_val | DBCR0_EDM;
 		break;
 	case SPRN_DBCR1:
arch/powerpc/kvm/e500_emulate.c +3 -3
index 051102d50c31..ded7c572157e 100644
@@ -90,9 +90,9 @@ static int kvmppc_e500_emul_ehpriv(struct kvm_vcpu *vcpu,
 
 	switch (get_oc(inst)) {
 	case EHPRIV_OC_DEBUG:
-		vcpu->run->exit_reason = KVM_EXIT_DEBUG;
-		vcpu->run->debug.arch.address = vcpu->arch.regs.nip;
-		vcpu->run->debug.arch.status = 0;
+		vcpu->common->run->exit_reason = KVM_EXIT_DEBUG;
+		vcpu->common->run->debug.arch.address = vcpu->arch.regs.nip;
+		vcpu->common->run->debug.arch.status = 0;
 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
 		emulated = EMULATE_EXIT_USER;
 		*advance = 0;
arch/powerpc/kvm/emulate.c +3 -3
index 355d5206e8aa..e66c5a637a4b 100644
@@ -272,9 +272,9 @@ int kvmppc_emulate_instruction(struct kvm_vcpu *vcpu)
 		 * these are illegal instructions.
 		 */
 		if (inst == KVMPPC_INST_SW_BREAKPOINT) {
-			vcpu->run->exit_reason = KVM_EXIT_DEBUG;
-			vcpu->run->debug.arch.status = 0;
-			vcpu->run->debug.arch.address = kvmppc_get_pc(vcpu);
+			vcpu->common->run->exit_reason = KVM_EXIT_DEBUG;
+			vcpu->common->run->debug.arch.status = 0;
+			vcpu->common->run->debug.arch.address = kvmppc_get_pc(vcpu);
 			emulated = EMULATE_EXIT_USER;
 			advance = 0;
 		} else
arch/powerpc/kvm/emulate_loadstore.c +1 -1
index ec60c7979718..9869f2f65cee 100644
@@ -97,7 +97,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
 		int type = op.type & INSTR_TYPE_MASK;
 		int size = GETSIZE(op.type);
 
-		vcpu->mmio_is_write = OP_IS_STORE(type);
+		vcpu->common->mmio_is_write = OP_IS_STORE(type);
 
 		switch (type) {
 		case LOAD:  {
arch/powerpc/kvm/powerpc.c +31 -31

214 lines not on this page · raw message

arch/powerpc/kvm/timing.h +14 -14
index 45817ab82bb4..78b8872e5995 100644
@@ -45,46 +45,46 @@ static inline void kvmppc_account_exit_stat(struct kvm_vcpu *vcpu, int type)
 	*/
 	switch (type) {
 	case EXT_INTR_EXITS:
-		vcpu->stat.ext_intr_exits++;
+		vcpu->common->stat.ext_intr_exits++;
 		break;
 	case DEC_EXITS:
-		vcpu->stat.dec_exits++;
+		vcpu->common->stat.dec_exits++;
 		break;
 	case EMULATED_INST_EXITS:
-		vcpu->stat.emulated_inst_exits++;
+		vcpu->common->stat.emulated_inst_exits++;
 		break;
 	case DSI_EXITS:
-		vcpu->stat.dsi_exits++;
+		vcpu->common->stat.dsi_exits++;
 		break;
 	case ISI_EXITS:
-		vcpu->stat.isi_exits++;
+		vcpu->common->stat.isi_exits++;
 		break;
 	case SYSCALL_EXITS:
-		vcpu->stat.syscall_exits++;
+		vcpu->common->stat.syscall_exits++;
 		break;
 	case DTLB_REAL_MISS_EXITS:
-		vcpu->stat.dtlb_real_miss_exits++;
+		vcpu->common->stat.dtlb_real_miss_exits++;
 		break;
 	case DTLB_VIRT_MISS_EXITS:
-		vcpu->stat.dtlb_virt_miss_exits++;
+		vcpu->common->stat.dtlb_virt_miss_exits++;
 		break;
 	case MMIO_EXITS:
-		vcpu->stat.mmio_exits++;
+		vcpu->common->stat.mmio_exits++;
 		break;
 	case ITLB_REAL_MISS_EXITS:
-		vcpu->stat.itlb_real_miss_exits++;
+		vcpu->common->stat.itlb_real_miss_exits++;
 		break;
 	case ITLB_VIRT_MISS_EXITS:
-		vcpu->stat.itlb_virt_miss_exits++;
+		vcpu->common->stat.itlb_virt_miss_exits++;
 		break;
 	case SIGNAL_EXITS:
-		vcpu->stat.signal_exits++;
+		vcpu->common->stat.signal_exits++;
 		break;
 	case DBELL_EXITS:
-		vcpu->stat.dbell_exits++;
+		vcpu->common->stat.dbell_exits++;
 		break;
 	case GDBELL_EXITS:
-		vcpu->stat.gdbell_exits++;
+		vcpu->common->stat.gdbell_exits++;
 		break;
 	}
 }
arch/powerpc/kvm/trace.h +1 -1
index ea1d7c808319..35c000d918bb 100644
@@ -108,7 +108,7 @@ TRACE_EVENT(kvm_check_requests,
 
 	TP_fast_assign(
 		__entry->cpu_nr		= vcpu->vcpu_id;
-		__entry->requests	= vcpu->requests;
+		__entry->requests	= vcpu->common->requests;
 	),
 
 	TP_printk("vcpu=%x requests=%x",
arch/powerpc/kvm/trace_hv.h +1 -1
index 77ebc724e6cd..6395698cfe05 100644
@@ -504,7 +504,7 @@ TRACE_EVENT(kvmppc_run_vcpu_exit,
 
 	TP_fast_assign(
 		__entry->vcpu_id  = vcpu->vcpu_id;
-		__entry->exit     = vcpu->run->exit_reason;
+		__entry->exit     = vcpu->common->run->exit_reason;
 		__entry->ret      = vcpu->arch.ret;
 	),
 
arch/riscv/kvm/aia_device.c +4 -4
index 39cd26af5a69..17cf59ccfae3 100644
@@ -18,7 +18,7 @@ static void unlock_vcpus(struct kvm *kvm, int vcpu_lock_idx)
 
 	for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) {
 		tmp_vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
-		mutex_unlock(&tmp_vcpu->mutex);
+		mutex_unlock(&tmp_vcpu->common->mutex);
 	}
 }
 
@@ -33,7 +33,7 @@ static bool lock_all_vcpus(struct kvm *kvm)
 	unsigned long c;
 
 	kvm_for_each_vcpu(c, tmp_vcpu, kvm) {
-		if (!mutex_trylock(&tmp_vcpu->mutex)) {
+		if (!mutex_trylock(&tmp_vcpu->common->mutex)) {
 			unlock_vcpus(kvm, c - 1);
 			return false;
 		}
@@ -207,12 +207,12 @@ static int aia_imsic_addr(struct kvm *kvm, u64 *addr,
 			return -EINVAL;
 	}
 
-	mutex_lock(&vcpu->mutex);
+	mutex_lock(&vcpu->common->mutex);
 	if (write)
 		vcpu_aia->imsic_addr = *addr;
 	else
 		*addr = vcpu_aia->imsic_addr;
-	mutex_unlock(&vcpu->mutex);
+	mutex_unlock(&vcpu->common->mutex);
 
 	return 0;
 }
arch/riscv/kvm/aia_imsic.c +1 -1
index 0a1e859323b4..cceae3dc9102 100644
@@ -734,7 +734,7 @@ int kvm_riscv_vcpu_aia_imsic_update(struct kvm_vcpu *vcpu)
 	struct imsic_mrif tmrif;
 	void __iomem *new_vsfile_va;
 	struct kvm *kvm = vcpu->kvm;
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 	struct kvm_vcpu_aia *vaia = &vcpu->arch.aia_context;
 	struct imsic *imsic = vaia->imsic_state;
 	int ret = 0, new_vsfile_hgei = -1, old_vsfile_hgei, old_vsfile_cpu;
arch/riscv/kvm/vcpu.c +12 -12
index 8d7d381737ee..c2c8bc303394 100644
@@ -517,10 +517,10 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 					struct kvm_guest_debug *dbg)
 {
 	if (dbg->control & KVM_GUESTDBG_ENABLE) {
-		vcpu->guest_debug = dbg->control;
+		vcpu->common->guest_debug = dbg->control;
 		vcpu->arch.cfg.hedeleg &= ~BIT(EXC_BREAKPOINT);
 	} else {
-		vcpu->guest_debug = 0;
+		vcpu->common->guest_debug = 0;
 		vcpu->arch.cfg.hedeleg |= BIT(EXC_BREAKPOINT);
 	}
 
@@ -555,7 +555,7 @@ static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu)
 	}
 
 	cfg->hedeleg = KVM_HEDELEG_DEFAULT;
-	if (vcpu->guest_debug)
+	if (vcpu->common->guest_debug)
 		cfg->hedeleg &= ~BIT(EXC_BREAKPOINT);
 }
 
@@ -732,7 +732,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 {
 	int ret;
 	struct kvm_cpu_trap trap;
-	struct kvm_run *run = vcpu->run;
+	struct kvm_run *run = vcpu->common->run;
 
 	if (!vcpu->arch.ran_atleast_once)
 		kvm_riscv_vcpu_setup_config(vcpu);
@@ -745,15 +745,15 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 	switch (run->exit_reason) {
 	case KVM_EXIT_MMIO:
 		/* Process MMIO value returned from user-space */
-		ret = kvm_riscv_vcpu_mmio_return(vcpu, vcpu->run);
+		ret = kvm_riscv_vcpu_mmio_return(vcpu, vcpu->common->run);
 		break;
 	case KVM_EXIT_RISCV_SBI:
 		/* Process SBI value returned from user-space */
-		ret = kvm_riscv_vcpu_sbi_return(vcpu, vcpu->run);
+		ret = kvm_riscv_vcpu_sbi_return(vcpu, vcpu->common->run);
 		break;
 	case KVM_EXIT_RISCV_CSR:
 		/* Process CSR value returned from user-space */
-		ret = kvm_riscv_vcpu_csr_return(vcpu, vcpu->run);
+		ret = kvm_riscv_vcpu_csr_return(vcpu, vcpu->common->run);
 		break;
 	default:
 		ret = 0;
@@ -764,7 +764,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		return ret;
 	}
 
-	if (!vcpu->wants_to_run) {
+	if (!vcpu->common->wants_to_run) {
 		kvm_vcpu_srcu_read_unlock(vcpu);
 		return -EINTR;
 	}
@@ -803,7 +803,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		 * See the comment in kvm_vcpu_exiting_guest_mode() and
 		 * Documentation/virt/kvm/vcpu-requests.rst
 		 */
-		vcpu->mode = IN_GUEST_MODE;
+		vcpu->common->mode = IN_GUEST_MODE;
 
 		kvm_vcpu_srcu_read_unlock(vcpu);
 		smp_mb__after_srcu_read_unlock();
@@ -820,7 +820,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		if (kvm_riscv_gstage_vmid_ver_changed(&vcpu->kvm->arch.vmid) ||
 		    kvm_request_pending(vcpu) ||
 		    xfer_to_guest_mode_work_pending()) {
-			vcpu->mode = OUTSIDE_GUEST_MODE;
+			vcpu->common->mode = OUTSIDE_GUEST_MODE;
 			local_irq_enable();
 			preempt_enable();
 			kvm_vcpu_srcu_read_lock(vcpu);
@@ -841,8 +841,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 
 		kvm_riscv_vcpu_enter_exit(vcpu);
 
-		vcpu->mode = OUTSIDE_GUEST_MODE;
-		vcpu->stat.exits++;
+		vcpu->common->mode = OUTSIDE_GUEST_MODE;
+		vcpu->common->stat.exits++;
 
 		/*
 		 * Save SCAUSE, STVAL, HTVAL, and HTINST because we might
arch/riscv/kvm/vcpu_insn.c +7 -7
index 97dec18e6989..c5e4f869cc33 100644
@@ -201,7 +201,7 @@ void kvm_riscv_vcpu_wfi(struct kvm_vcpu *vcpu)
 
 static int wfi_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, ulong insn)
 {
-	vcpu->stat.wfi_exit_stat++;
+	vcpu->common->stat.wfi_exit_stat++;
 	kvm_riscv_vcpu_wfi(vcpu);
 	return KVM_INSN_CONTINUE_NEXT_SEPC;
 }
@@ -335,7 +335,7 @@ static int csr_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, ulong insn)
 		if (rc > KVM_INSN_EXIT_TO_USER_SPACE) {
 			if (rc == KVM_INSN_CONTINUE_NEXT_SEPC) {
 				run->riscv_csr.ret_value = val;
-				vcpu->stat.csr_exit_kernel++;
+				vcpu->common->stat.csr_exit_kernel++;
 				kvm_riscv_vcpu_csr_return(vcpu, run);
 				rc = KVM_INSN_CONTINUE_SAME_SEPC;
 			}
@@ -345,7 +345,7 @@ static int csr_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, ulong insn)
 
 	/* Exit to user-space for CSR emulation */
 	if (rc <= KVM_INSN_EXIT_TO_USER_SPACE) {
-		vcpu->stat.csr_exit_user++;
+		vcpu->common->stat.csr_exit_user++;
 		run->exit_reason = KVM_EXIT_RISCV_CSR;
 	}
 
@@ -576,13 +576,13 @@ int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run,
 	if (!kvm_io_bus_read(vcpu, KVM_MMIO_BUS, fault_addr, len, data_buf)) {
 		/* Successfully handled MMIO access in the kernel so resume */
 		memcpy(run->mmio.data, data_buf, len);
-		vcpu->stat.mmio_exit_kernel++;
+		vcpu->common->stat.mmio_exit_kernel++;
 		kvm_riscv_vcpu_mmio_return(vcpu, run);
 		return 1;
 	}
 
 	/* Exit to userspace for MMIO emulation */
-	vcpu->stat.mmio_exit_user++;
+	vcpu->common->stat.mmio_exit_user++;
 	run->exit_reason = KVM_EXIT_MMIO;
 
 	return 0;
@@ -709,13 +709,13 @@ int kvm_riscv_vcpu_mmio_store(struct kvm_vcpu *vcpu, struct kvm_run *run,
 	if (!kvm_io_bus_write(vcpu, KVM_MMIO_BUS,
 			      fault_addr, len, run->mmio.data)) {
 		/* Successfully handled MMIO access in the kernel so resume */
-		vcpu->stat.mmio_exit_kernel++;
+		vcpu->common->stat.mmio_exit_kernel++;
 		kvm_riscv_vcpu_mmio_return(vcpu, run);
 		return 1;
 	}
 
 	/* Exit to userspace for MMIO emulation */
-	vcpu->stat.mmio_exit_user++;
+	vcpu->common->stat.mmio_exit_user++;
 	run->exit_reason = KVM_EXIT_MMIO;
 
 	return 0;
arch/riscv/kvm/vcpu_sbi.c +1 -1
index 62f409d4176e..3e450efc8a87 100644
@@ -117,7 +117,7 @@ void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run)
 	struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
 
 	vcpu->arch.sbi_context.return_handled = 0;
-	vcpu->stat.ecall_exit_stat++;
+	vcpu->common->stat.ecall_exit_stat++;
 	run->exit_reason = KVM_EXIT_RISCV_SBI;
 	run->riscv_sbi.extension_id = cp->a7;
 	run->riscv_sbi.function_id = cp->a6;
arch/riscv/kvm/vcpu_sbi_hsm.c +1 -1
index dce667f4b6ab..a759f1b80b8a 100644
@@ -81,7 +81,7 @@ static int kvm_sbi_hsm_vcpu_get_status(struct kvm_vcpu *vcpu)
 		return SBI_ERR_INVALID_PARAM;
 	if (!kvm_riscv_vcpu_stopped(target_vcpu))
 		return SBI_HSM_STATE_STARTED;
-	else if (vcpu->stat.generic.blocking)
+	else if (vcpu->common->stat.generic.blocking)
 		return SBI_HSM_STATE_SUSPENDED;
 	else
 		return SBI_HSM_STATE_STOPPED;
arch/s390/include/asm/kvm_host.h +4 -4
index 8e77afbed58e..337bb899c7ac 100644
@@ -708,13 +708,13 @@ struct kvm_hw_bp_info_arch {
 #define KVM_GUESTDBG_EXIT_PENDING 0x10000000
 
 #define guestdbg_enabled(vcpu) \
-		(vcpu->guest_debug & KVM_GUESTDBG_ENABLE)
+		(vcpu->common->guest_debug & KVM_GUESTDBG_ENABLE)
 #define guestdbg_sstep_enabled(vcpu) \
-		(vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
+		(vcpu->common->guest_debug & KVM_GUESTDBG_SINGLESTEP)
 #define guestdbg_hw_bp_enabled(vcpu) \
-		(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
+		(vcpu->common->guest_debug & KVM_GUESTDBG_USE_HW_BP)
 #define guestdbg_exit_pending(vcpu) (guestdbg_enabled(vcpu) && \
-		(vcpu->guest_debug & KVM_GUESTDBG_EXIT_PENDING))
+		(vcpu->common->guest_debug & KVM_GUESTDBG_EXIT_PENDING))
 
 #define KVM_GUESTDBG_VALID_MASK \
 		(KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP |\
arch/s390/kvm/diag.c +36 -36

180 lines not on this page · raw message

arch/s390/kvm/gaccess.c +2 -2
index e65f597e3044..3431bc47371c 100644
@@ -235,8 +235,8 @@ static int ar_translation(struct kvm_vcpu *vcpu, union asce *asce, u8 ar,
 		return -EINVAL;
 
 	if (vcpu->arch.acrs_loaded)
-		save_access_regs(vcpu->run->s.regs.acrs);
-	alet.val = vcpu->run->s.regs.acrs[ar];
+		save_access_regs(vcpu->common->run->s.regs.acrs);
+	alet.val = vcpu->common->run->s.regs.acrs[ar];
 
 	if (ar == 0 || alet.val == 0) {
 		asce->val = vcpu->arch.sie_block->gcr[1];
arch/s390/kvm/guestdbg.c +7 -7
index 80879fc73c90..82c4a2dd066c 100644
@@ -370,8 +370,8 @@ static struct kvm_hw_wp_info_arch *any_wp_changed(struct kvm_vcpu *vcpu)
 
 void kvm_s390_prepare_debug_exit(struct kvm_vcpu *vcpu)
 {
-	vcpu->run->exit_reason = KVM_EXIT_DEBUG;
-	vcpu->guest_debug &= ~KVM_GUESTDBG_EXIT_PENDING;
+	vcpu->common->run->exit_reason = KVM_EXIT_DEBUG;
+	vcpu->common->guest_debug &= ~KVM_GUESTDBG_EXIT_PENDING;
 }
 
 #define PER_CODE_MASK		(PER_EVENT_MASK >> 24)
@@ -388,7 +388,7 @@ void kvm_s390_prepare_debug_exit(struct kvm_vcpu *vcpu)
 static int debug_exit_required(struct kvm_vcpu *vcpu, u8 perc,
 			       unsigned long peraddr)
 {
-	struct kvm_debug_exit_arch *debug_exit = &vcpu->run->debug.arch;
+	struct kvm_debug_exit_arch *debug_exit = &vcpu->common->run->debug.arch;
 	struct kvm_hw_wp_info_arch *wp_info = NULL;
 	struct kvm_hw_bp_info_arch *bp_info = NULL;
 	unsigned long addr = vcpu->arch.sie_block->gpsw.addr;
@@ -482,8 +482,8 @@ static int per_fetched_addr(struct kvm_vcpu *vcpu, unsigned long *addr)
 			u32 disp = opcode[1] & 0x0fff;
 			u32 index = opcode[0] & 0x000f;
 
-			*addr = base ? vcpu->run->s.regs.gprs[base] : 0;
-			*addr += index ? vcpu->run->s.regs.gprs[index] : 0;
+			*addr = base ? vcpu->common->run->s.regs.gprs[base] : 0;
+			*addr += index ? vcpu->common->run->s.regs.gprs[index] : 0;
 			*addr += disp;
 		}
 		*addr = kvm_s390_logical_to_effective(vcpu, *addr);
@@ -516,7 +516,7 @@ int kvm_s390_handle_per_ifetch_icpt(struct kvm_vcpu *vcpu)
 		return kvm_s390_inject_prog_irq(vcpu, &pgm_info);
 
 	if (debug_exit_required(vcpu, pgm_info.per_code, pgm_info.per_address))
-		vcpu->guest_debug |= KVM_GUESTDBG_EXIT_PENDING;
+		vcpu->common->guest_debug |= KVM_GUESTDBG_EXIT_PENDING;
 
 	if (!guest_per_enabled(vcpu) ||
 	    !(vcpu->arch.sie_block->gcr[9] & PER_EVENT_IFETCH))
@@ -589,7 +589,7 @@ int kvm_s390_handle_per_event(struct kvm_vcpu *vcpu)
 
 	if (debug_exit_required(vcpu, vcpu->arch.sie_block->perc,
 				vcpu->arch.sie_block->peraddr))
-		vcpu->guest_debug |= KVM_GUESTDBG_EXIT_PENDING;
+		vcpu->common->guest_debug |= KVM_GUESTDBG_EXIT_PENDING;
 
 	rc = filter_guest_per_event(vcpu);
 	if (rc)
arch/s390/kvm/intercept.c +15 -15
index b16352083ff9..8c8569b506b6 100644
@@ -56,7 +56,7 @@ static int handle_stop(struct kvm_vcpu *vcpu)
 	int rc = 0;
 	uint8_t flags, stop_pending;
 
-	vcpu->stat.exit_stop_request++;
+	vcpu->common->stat.exit_stop_request++;
 
 	/* delay the stop if any non-stop irq is pending */
 	if (kvm_s390_vcpu_has_irq(vcpu, 1))
@@ -92,7 +92,7 @@ static int handle_validity(struct kvm_vcpu *vcpu)
 {
 	int viwhy = vcpu->arch.sie_block->ipb >> 16;
 
-	vcpu->stat.exit_validity++;
+	vcpu->common->stat.exit_validity++;
 	trace_kvm_s390_intercept_validity(vcpu, viwhy);
 	KVM_EVENT(3, "validity intercept 0x%x for pid %u (kvm 0x%pK)", viwhy,
 		  current->pid, vcpu->kvm);
@@ -105,7 +105,7 @@ static int handle_validity(struct kvm_vcpu *vcpu)
 
 static int handle_instruction(struct kvm_vcpu *vcpu)
 {
-	vcpu->stat.exit_instruction++;
+	vcpu->common->stat.exit_instruction++;
 	trace_kvm_s390_intercept_instruction(vcpu,
 					     vcpu->arch.sie_block->ipa,
 					     vcpu->arch.sie_block->ipb);
@@ -248,7 +248,7 @@ static int handle_prog(struct kvm_vcpu *vcpu)
 	psw_t psw;
 	int rc;
 
-	vcpu->stat.exit_program_interruption++;
+	vcpu->common->stat.exit_program_interruption++;
 
 	/*
 	 * Intercept 8 indicates a loop of specification exceptions
@@ -306,7 +306,7 @@ static int handle_external_interrupt(struct kvm_vcpu *vcpu)
 	psw_t newpsw;
 	int rc;
 
-	vcpu->stat.exit_external_interrupt++;
+	vcpu->common->stat.exit_external_interrupt++;
 
 	if (kvm_s390_pv_cpu_is_protected(vcpu)) {
 		newpsw = vcpu->arch.sie_block->gpsw;
@@ -363,7 +363,7 @@ static int handle_mvpg_pei(struct kvm_vcpu *vcpu)
 	kvm_s390_get_regs_rre(vcpu, &reg1, &reg2);
 
 	/* Ensure that the source is paged-in, no actual access -> no key checking */
-	rc = guest_translate_address_with_key(vcpu, vcpu->run->s.regs.gprs[reg2],
+	rc = guest_translate_address_with_key(vcpu, vcpu->common->run->s.regs.gprs[reg2],
 					      reg2, &srcaddr, GACC_FETCH, 0);
 	if (rc)
 		return kvm_s390_inject_prog_cond(vcpu, rc);
@@ -372,7 +372,7 @@ static int handle_mvpg_pei(struct kvm_vcpu *vcpu)
 		return rc;
 
 	/* Ensure that the source is paged-in, no actual access -> no key checking */
-	rc = guest_translate_address_with_key(vcpu, vcpu->run->s.regs.gprs[reg1],
+	rc = guest_translate_address_with_key(vcpu, vcpu->common->run->s.regs.gprs[reg1],
 					      reg1, &dstaddr, GACC_STORE, 0);
 	if (rc)
 		return kvm_s390_inject_prog_cond(vcpu, rc);
@@ -387,7 +387,7 @@ static int handle_mvpg_pei(struct kvm_vcpu *vcpu)
 
 static int handle_partial_execution(struct kvm_vcpu *vcpu)
 {
-	vcpu->stat.exit_pei++;
+	vcpu->common->stat.exit_pei++;
 
 	if (vcpu->arch.sie_block->ipa == 0xb254)	/* MVPG */
 		return handle_mvpg_pei(vcpu);
@@ -412,10 +412,10 @@ int handle_sthyi(struct kvm_vcpu *vcpu)
 		return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
 
 	kvm_s390_get_regs_rre(vcpu, &reg1, &reg2);
-	code = vcpu->run->s.regs.gprs[reg1];
-	addr = vcpu->run->s.regs.gprs[reg2];
+	code = vcpu->common->run->s.regs.gprs[reg1];
+	addr = vcpu->common->run->s.regs.gprs[reg2];
 
-	vcpu->stat.instruction_sthyi++;
+	vcpu->common->stat.instruction_sthyi++;
 	VCPU_EVENT(vcpu, 3, "STHYI: fc: %llu addr: 0x%016llx", code, addr);
 	trace_kvm_s390_handle_sthyi(vcpu, code, addr);
 
@@ -454,7 +454,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu)
 	}
 
 	free_page((unsigned long)sctns);
-	vcpu->run->s.regs.gprs[reg2 + 1] = rc;
+	vcpu->common->run->s.regs.gprs[reg2 + 1] = rc;
 	kvm_s390_set_psw_cc(vcpu, cc);
 	return r;
 }
@@ -464,7 +464,7 @@ static int handle_operexc(struct kvm_vcpu *vcpu)
 	psw_t oldpsw, newpsw;
 	int rc;
 
-	vcpu->stat.exit_operation_exception++;
+	vcpu->common->stat.exit_operation_exception++;
 	trace_kvm_s390_handle_operexc(vcpu, vcpu->arch.sie_block->ipa,
 				      vcpu->arch.sie_block->ipb);
 
@@ -608,10 +608,10 @@ int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
 
 	switch (vcpu->arch.sie_block->icptcode) {
 	case ICPT_EXTREQ:
-		vcpu->stat.exit_external_request++;
+		vcpu->common->stat.exit_external_request++;
 		return 0;
 	case ICPT_IOREQ:
-		vcpu->stat.exit_io_request++;
+		vcpu->common->stat.exit_io_request++;
 		return 0;
 	case ICPT_INST:
 		rc = handle_instruction(vcpu);
arch/s390/kvm/interrupt.c +41 -41

221 lines not on this page · raw message

arch/s390/kvm/kvm-s390.c +80 -80

160 lines not on this page · raw message

arch/s390/kvm/kvm-s390.h +6 -6
index bf8534218af3..992d78d7b408 100644

Lines of this file are not shown. View the raw message.

arch/s390/kvm/priv.c +93 -93

186 lines not on this page · raw message

arch/s390/kvm/pv.c +1 -1
index 75e81ba26d04..9c36d0c2a8ef 100644

Lines of this file are not shown. View the raw message.

arch/s390/kvm/sigp.c +31 -31

62 lines not on this page · raw message

arch/s390/kvm/vsie.c +3 -3
index 89cafea4c41f..6a9a0fbfc41d 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/debugfs.c +1 -1
index 999227fc7c66..2c71b422238a 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/hyperv.c +10 -10
index 4f0a94346d00..d95beecd818d 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/kvm_cache_regs.h +2 -2
index b1eb46e26b2e..6d99076e570f 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/lapic.c +2 -2
index 4915acdbfcd8..e2dd573e4f2d 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/mmu/mmu.c +14 -14
index 928cf84778b0..a61e68249620 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/mmu/tdp_mmu.c +1 -1
index c7dc49ee7388..edc6d0594d1c 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/pmu.c +1 -1
index 47a46283c866..599827b14fcd 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/svm/nested.c +3 -3
index 6f704c1037e5..521b3e9ce60a 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/svm/sev.c +33 -33

66 lines not on this page · raw message

arch/x86/kvm/svm/svm.c +28 -28

56 lines not on this page · raw message

arch/x86/kvm/vmx/nested.c +9 -9
index 2392a7ef254d..9e02425a9c4e 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/vmx/posted_intr.c +1 -1
index ec08fa3caf43..64fff7e2d487 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/vmx/sgx.c +2 -2
index 6fef01e0536e..5487a4abfe0f 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/vmx/vmx.c +64 -64

128 lines not on this page · raw message

arch/x86/kvm/x86.c +174 -174

348 lines not on this page · raw message

arch/x86/kvm/xen.c +12 -12
index 622fe24da910..57a699db05f2 100644

Lines of this file are not shown. View the raw message.

arch/x86/kvm/xen.h +1 -1
index f5841d9000ae..ce0d90767df8 100644

Lines of this file are not shown. View the raw message.

drivers/s390/crypto/vfio_ap_ops.c +5 -5
index 9f76f2d7b66e..b851c7650bbb 100644

Lines of this file are not shown. View the raw message.

include/linux/kvm_host.h +87 -80

167 lines not on this page · raw message

tools/testing/selftests/kvm/aarch64/debug-exceptions.c +1 -1
index 2582c49e525a..b162545286b0 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/aarch64/page_fault_test.c +1 -1
index d29b08198b42..357e842a3328 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/aarch64/smccc_filter.c +1 -1
index 2d189f3da228..bbcc1a1a9c1a 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/demand_paging_test.c +1 -1
index 0202b78f8680..be98b5c3d629 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/dirty_log_perf_test.c +1 -1
index 9f24303acb8c..1e194fbc87b5 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/dirty_log_test.c +2 -2
index aacf80f57439..35890dcd8d6f 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/guest_print_test.c +2 -2
index 8092c2d0f5d6..bbb910363120 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/hardware_disable_test.c +1 -1
index bce73bcb973c..805363b9e706 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/kvm_page_table_test.c +1 -1
index dd8b12f626d3..12ae35b635ca 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/lib/aarch64/ucall.c +1 -1
index ddab0ce89d4d..7146625553ce 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/lib/kvm_util.c +7 -7
index 56b170b725b3..520e820d7683 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/lib/riscv/ucall.c +1 -1
index b5035c63d516..2f9c327eace1 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/lib/s390x/diag318_test_handler.c +1 -1
index 2c432fa164f1..f9207a502eab 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/lib/s390x/processor.c +3 -3
index 4ad4492eea1d..f717e8bcd03c 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/lib/s390x/ucall.c +1 -1
index cca98734653d..bd6822a78ab7 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/lib/x86_64/ucall.c +1 -1
index 1265cecc7dd1..b40e55525897 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/memslot_modification_stress_test.c +1 -1
index 49f162573126..7d8957ddb8a1 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/memslot_perf_test.c +1 -1
index 579a64f97333..ab419ad6bb41 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/pre_fault_memory_test.c +1 -1
index 0350a8896a2f..a2f956821d1e 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/s390x/cmma_test.c +10 -10
index b39033844756..dad56f823d8e 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/s390x/debug_test.c +6 -6
index 84313fb27529..bc9acb6fb068 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/s390x/memop.c +1 -1
index f2df7416be84..77cd0549d9d6 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/s390x/resets.c +7 -7
index 357943f2bea8..ecb8526339f5 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/s390x/sync_regs_test.c +5 -5
index 53def355ccba..cd843306788c 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/s390x/tprot.c +1 -1
index 7a742a673b7c..d181e999c74c 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/set_memory_region_test.c +2 -2
index bb8002084f52..458e6072c263 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/steal_time.c +1 -1
index a8d3afa0b86b..0e49c153c5c1 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/cpuid_test.c +1 -1
index 8c579ce714e9..89ae4537f160 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/debug_regs.c +1 -1
index f6b295e0b2d2..ee391b07ada3 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c +1 -1
index 762628f7d4ba..b76a020b740b 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/flds_emulation.h +1 -1
index 37b1a9f52864..ebc81c02e719 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/hyperv_extended_hypercalls.c +1 -1
index 949e08e98f31..5562f19a6b60 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c +2 -2
index 3eb0313ffa39..342a71434586 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +2 -2
index 82a8d88b5338..fe887798811d 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/private_mem_kvm_exits_test.c +8 -8
index 13e72fcec8dd..ad1d63aeca97 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c +1 -1
index 49913784bc82..581b98df7cdd 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/sev_smoke_test.c +11 -11
index 7c70c0da4fb7..d807e758ad7c 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/sync_regs_test.c +8 -8
index 8fa3948b0170..a2089abfd29a 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c +1 -1
index 56306a19144a..bbd8344046e3 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/tsc_msrs_test.c +1 -1
index 12b0964f4f13..9356a4da7cec 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/userspace_io_test.c +1 -1
index 9481cbcf284f..d2165b76c93a 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c +4 -4
index 32b2794b78fe..dc2ab9a7fc3d 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c +1 -1
index a81a24761aac..e36ea3afd548 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c +1 -1
index dad988351493..e2b5ac2af396 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c +1 -1
index 3fd6eceab46f..f7cb3eec4a17 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/vmx_invalid_nested_guest_state.c +1 -1
index a100ee5f0009..8006d6d11ccd 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c +1 -1
index 95ce192d0753..b1427e8835de 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c +1 -1
index e149d0574961..30f2aee1f1e9 100644

Lines of this file are not shown. View the raw message.

virt/kvm/async_pf.c +30 -30

60 lines not on this page · raw message

virt/kvm/dirty_ring.c +3 -3
index 7bc74969a819..370e64680548 100644

Lines of this file are not shown. View the raw message.

virt/kvm/kvm_main.c +89 -87

176 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.43.0

Part of the diff is not shown here. View the raw message.

#2 lore raw

RFC PATCH 2/5 x86/kvm: Create a child struct kvm_vcpu for each VMPL

In reply to Roy Hopkins

Isolation technologies such as SEV-SNP introduce the concept of virtual machine privilege levels (VMPLs), separate to the processor CPL. A guest runs in the context of one of these VMPLs which allows for a different register context, memory privileges, etc.

KVM must maintain state for each supported VMPL and switch between these states before entering the guest based on guest requests or other factors.

This patch introduces the ability to create multiple
struct kvm_cpus: one for each VMPL related to a single vCPU. This is achieved by introducing a new structure, struct kvm_vcpu_vmpl_state that is included in struct kvm_vcpu to track the state of each VMPL for supported platforms (currently only SEV-SNP). The state for each VMPL is then stored in its own struct kvm_vcpu. State that is common to all VMPL kvm_vcpus is managed by vcpu->common, allowing a pointer to the common fields to be shared amongst all VMPL kvm_vcpu's for a single vCPU id.

The patch supports switching VMPLs by changing the target_vmpl in the state structure. However, no code to generate a VMPL switch invokes this at present.

---
 arch/x86/kvm/cpuid.c       |  78 +++++++++++++------------
 arch/x86/kvm/trace.h       |  12 +++-
 arch/x86/kvm/x86.c         |  58 +++++++++++++++++--
 include/linux/kvm_host.h   |  17 ++++++
 include/trace/events/kvm.h |  48 +++++++++++++++
 virt/kvm/kvm_main.c        | 116 +++++++++++++++++++++++++------------
 6 files changed, 249 insertions(+), 80 deletions(-)
arch/x86/kvm/cpuid.c +41 -37
index 2617be544480..4dc5ac431e97 100644
@@ -437,51 +437,55 @@ static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2,
                         int nent)
 {
 	int r;
+	int vtl;
+	struct kvm_vcpu_vmpl_state *vcpu_parent = vcpu->vcpu_parent;
 
-	__kvm_update_cpuid_runtime(vcpu, e2, nent);
+	for (vtl = 0; vtl <= vcpu_parent->max_vmpl; ++vtl) {
+		vcpu = vcpu_parent->vcpu_vmpl[vtl];
+		__kvm_update_cpuid_runtime(vcpu, e2, nent);
 
-	/*
-	 * KVM does not correctly handle changing guest CPUID after KVM_RUN, as
-	 * MAXPHYADDR, GBPAGES support, AMD reserved bit behavior, etc.. aren't
-	 * tracked in kvm_mmu_page_role.  As a result, KVM may miss guest page
-	 * faults due to reusing SPs/SPTEs. In practice no sane VMM mucks with
-	 * the core vCPU model on the fly. It would've been better to forbid any
-	 * KVM_SET_CPUID{,2} calls after KVM_RUN altogether but unfortunately
-	 * some VMMs (e.g. QEMU) reuse vCPU fds for CPU hotplug/unplug and do
-	 * KVM_SET_CPUID{,2} again. To support this legacy behavior, check
-	 * whether the supplied CPUID data is equal to what's already set.
-	 */
-	if (kvm_vcpu_has_run(vcpu)) {
-		r = kvm_cpuid_check_equal(vcpu, e2, nent);
-		if (r)
-			return r;
-
-		kvfree(e2);
-		return 0;
-	}
+		/*
+		* KVM does not correctly handle changing guest CPUID after KVM_RUN, as
+		* MAXPHYADDR, GBPAGES support, AMD reserved bit behavior, etc.. aren't
+		* tracked in kvm_mmu_page_role.  As a result, KVM may miss guest page
+		* faults due to reusing SPs/SPTEs. In practice no sane VMM mucks with
+		* the core vCPU model on the fly. It would've been better to forbid any
+		* KVM_SET_CPUID{,2} calls after KVM_RUN altogether but unfortunately
+		* some VMMs (e.g. QEMU) reuse vCPU fds for CPU hotplug/unplug and do
+		* KVM_SET_CPUID{,2} again. To support this legacy behavior, check
+		* whether the supplied CPUID data is equal to what's already set.
+		*/
+		if (kvm_vcpu_has_run(vcpu)) {
+			r = kvm_cpuid_check_equal(vcpu, e2, nent);
+			if (r)
+				return r;
+
+			kvfree(e2);
+			return 0;
+		}
 
 #ifdef CONFIG_KVM_HYPERV
-	if (kvm_cpuid_has_hyperv(e2, nent)) {
-		r = kvm_hv_vcpu_init(vcpu);
-		if (r)
-			return r;
-	}
+		if (kvm_cpuid_has_hyperv(e2, nent)) {
+			r = kvm_hv_vcpu_init(vcpu);
+			if (r)
+				return r;
+		}
 #endif
 
-	r = kvm_check_cpuid(vcpu, e2, nent);
-	if (r)
-		return r;
-
-	kvfree(vcpu->arch.cpuid_entries);
-	vcpu->arch.cpuid_entries = e2;
-	vcpu->arch.cpuid_nent = nent;
+		r = kvm_check_cpuid(vcpu, e2, nent);
+		if (r)
+			return r;
 
-	vcpu->arch.kvm_cpuid = kvm_get_hypervisor_cpuid(vcpu, KVM_SIGNATURE);
-#ifdef CONFIG_KVM_XEN
-	vcpu->arch.xen.cpuid = kvm_get_hypervisor_cpuid(vcpu, XEN_SIGNATURE);
-#endif
-	kvm_vcpu_after_set_cpuid(vcpu);
+		kvfree(vcpu->arch.cpuid_entries);
+		vcpu->arch.cpuid_entries = e2;
+		vcpu->arch.cpuid_nent = nent;
 
+		vcpu->arch.kvm_cpuid = kvm_get_hypervisor_cpuid(vcpu, KVM_SIGNATURE);
+	#ifdef CONFIG_KVM_XEN
+		vcpu->arch.xen.cpuid = kvm_get_hypervisor_cpuid(vcpu, XEN_SIGNATURE);
+	#endif
+		kvm_vcpu_after_set_cpuid(vcpu);
+	}
 	return 0;
 }
 
arch/x86/kvm/trace.h +10 -2
index d3aeffd6ae75..882b8d2356c6 100644
@@ -20,18 +20,26 @@ TRACE_EVENT(kvm_entry,
 
 	TP_STRUCT__entry(
 		__field(	unsigned int,	vcpu_id		)
+		__field(	unsigned int,	vcpu_vmpl	)
+		__field(	unsigned int,	current_vmpl	)
+		__field(	unsigned int,	target_vmpl	)
 		__field(	unsigned long,	rip		)
 		__field(	bool,		immediate_exit	)
 	),
 
 	TP_fast_assign(
 		__entry->vcpu_id        = vcpu->vcpu_id;
+		__entry->vcpu_vmpl	= vcpu->vmpl;
+		__entry->current_vmpl	= vcpu->vcpu_parent->current_vmpl;
+		__entry->target_vmpl	= vcpu->vcpu_parent->target_vmpl;
 		__entry->rip		= kvm_rip_read(vcpu);
 		__entry->immediate_exit	= force_immediate_exit;
 	),
 
-	TP_printk("vcpu %u, rip 0x%lx%s", __entry->vcpu_id, __entry->rip,
-		  __entry->immediate_exit ? "[immediate exit]" : "")
+	TP_printk("vcpu %u, rip 0x%lx%s, vcpu_vmpl %d, current_vmpl %d, target_vmpl %d",
+		  __entry->vcpu_id, __entry->rip, __entry->immediate_exit ? "[immediate exit]" : "",
+		  __entry->vcpu_vmpl, __entry->current_vmpl, __entry->target_vmpl
+		  )
 );
 
 /*
arch/x86/kvm/x86.c +53 -5

100 lines not on this page · raw message

include/linux/kvm_host.h +17 -0
index fb5c58c90975..806b7ba869cb 100644
@@ -320,6 +320,8 @@ struct kvm_mmio_fragment {
 	unsigned len;
 };
 
+struct kvm_vcpu_vmpl_state;
+
 struct kvm_vcpu {
 	struct kvm *kvm;
 #ifdef CONFIG_PREEMPT_NOTIFIERS
@@ -402,6 +404,21 @@ struct kvm_vcpu {
 	} _common;
 
 	struct kvm_vcpu_common *common;
+
+	struct kvm_vcpu_vmpl_state *vcpu_parent;
+	int vmpl;
+};
+
+struct kvm_vcpu_vmpl_state {
+	/*
+	 * TODO: This array needs to be dynamically allocated to store the
+	 * required number of VMPLs based on the architecture. This has been
+	 * hardcoded to 4 for this RFC for SEV-SNP.
+	 */
+	struct kvm_vcpu *vcpu_vmpl[4];
+	int max_vmpl;
+	int current_vmpl;
+	int target_vmpl;
 };
 
 /*
include/trace/events/kvm.h +48 -0

60 lines not on this page · raw message

virt/kvm/kvm_main.c +80 -36

189 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH 3/5 kvm/sev: Update SEV VMPL handling to use multiple struct kvm_vcpus

In reply to Roy Hopkins

This commit builds on Tom Lendacky's SEV-SNP support RFC patch series and reworks the handling of VMPL switching to use multiple struct kvm_vcpus to store VMPL context.

---
 arch/x86/kvm/svm/sev.c | 159 +++++++++++++++--------------------------
 arch/x86/kvm/svm/svm.c |  66 ++++++++++-------
 arch/x86/kvm/svm/svm.h |  36 +++-------
 3 files changed, 109 insertions(+), 152 deletions(-)
arch/x86/kvm/svm/sev.c +59 -100
index 2ad1b9b497e0..3fbb1ce5195d 100644
@@ -147,7 +147,7 @@ static bool sev_vcpu_has_debug_swap(struct vcpu_svm *svm)
 	struct kvm_vcpu *vcpu = &svm->vcpu;
 	struct kvm_sev_info *sev = &to_kvm_svm(vcpu->kvm)->sev_info;
 
-	return sev->vmsa_features[cur_vmpl(svm)] & SVM_SEV_FEAT_DEBUG_SWAP;
+	return sev->vmsa_features[vcpu->vmpl] & SVM_SEV_FEAT_DEBUG_SWAP;
 }
 
 /* Must be called with the sev_bitmap_lock held */
@@ -818,7 +818,7 @@ static int sev_es_sync_vmsa(struct vcpu_svm *svm)
 {
 	struct kvm_vcpu *vcpu = &svm->vcpu;
 	struct kvm_sev_info *sev = &to_kvm_svm(vcpu->kvm)->sev_info;
-	struct sev_es_save_area *save = vmpl_vmsa(svm, SVM_SEV_VMPL0);
+	struct sev_es_save_area *save = vmpl_vmsa(svm);
 	struct xregs_state *xsave;
 	const u8 *s;
 	u8 *d;
@@ -931,11 +931,11 @@ static int __sev_launch_update_vmsa(struct kvm *kvm, struct kvm_vcpu *vcpu,
 	 * the VMSA memory content (i.e it will write the same memory region
 	 * with the guest's key), so invalidate it first.
 	 */
-	clflush_cache_range(vmpl_vmsa(svm, SVM_SEV_VMPL0), PAGE_SIZE);
+	clflush_cache_range(vmpl_vmsa(svm), PAGE_SIZE);
 
 	vmsa.reserved = 0;
 	vmsa.handle = to_kvm_sev_info(kvm)->handle;
-	vmsa.address = __sme_pa(vmpl_vmsa(svm, SVM_SEV_VMPL0));
+	vmsa.address = __sme_pa(vmpl_vmsa(svm));
 	vmsa.len = PAGE_SIZE;
 	ret = sev_issue_cmd(kvm, SEV_CMD_LAUNCH_UPDATE_VMSA, &vmsa, error);
 	if (ret)
@@ -2504,7 +2504,7 @@ static int snp_launch_update_vmsa(struct kvm *kvm, struct kvm_sev_cmd *argp)
 
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		struct vcpu_svm *svm = to_svm(vcpu);
-		u64 pfn = __pa(vmpl_vmsa(svm, SVM_SEV_VMPL0)) >> PAGE_SHIFT;
+		u64 pfn = __pa(vmpl_vmsa(svm)) >> PAGE_SHIFT;
 
 		/* If SVSM support is requested, only measure the boot vCPU */
 		if ((sev->snp_init_flags & KVM_SEV_SNP_SVSM) && vcpu->vcpu_id != 0)
@@ -2520,7 +2520,7 @@ static int snp_launch_update_vmsa(struct kvm *kvm, struct kvm_sev_cmd *argp)
 			return ret;
 
 		/* Issue the SNP command to encrypt the VMSA */
-		data.address = __sme_pa(vmpl_vmsa(svm, SVM_SEV_VMPL0));
+		data.address = __sme_pa(vmpl_vmsa(svm));
 		ret = __sev_issue_cmd(argp->sev_fd, SEV_CMD_SNP_LAUNCH_UPDATE,
 				      &data, &argp->error);
 		if (ret) {
@@ -3242,16 +3242,16 @@ void sev_free_vcpu(struct kvm_vcpu *vcpu)
 	 * releasing it back to the system.
 	 */
 	if (sev_snp_guest(vcpu->kvm)) {
-		u64 pfn = __pa(vmpl_vmsa(svm, SVM_SEV_VMPL0)) >> PAGE_SHIFT;
+		u64 pfn = __pa(vmpl_vmsa(svm)) >> PAGE_SHIFT;
 
 		if (kvm_rmp_make_shared(vcpu->kvm, pfn, PG_LEVEL_4K))
 			goto skip_vmsa_free;
 	}
 
 	if (vcpu->arch.guest_state_protected)
-		sev_flush_encrypted_page(vcpu, vmpl_vmsa(svm, SVM_SEV_VMPL0));
+		sev_flush_encrypted_page(vcpu, vmpl_vmsa(svm));
 
-	__free_page(virt_to_page(vmpl_vmsa(svm, SVM_SEV_VMPL0)));
+	__free_page(virt_to_page(vmpl_vmsa(svm)));
 
 skip_vmsa_free:
 	if (svm->sev_es.ghcb_sa_free)
@@ -3924,13 +3924,18 @@ static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu)
 
 	/* Clear use of the VMSA */
 	svm->vmcb->control.vmsa_pa = INVALID_PAGE;
-	tgt_vmpl_vmsa_hpa(svm) = INVALID_PAGE;
+	vmpl_vmsa_hpa(svm) = INVALID_PAGE;
 
-	if (VALID_PAGE(tgt_vmpl_vmsa_gpa(svm))) {
-		gfn_t gfn = gpa_to_gfn(tgt_vmpl_vmsa_gpa(svm));
+	if (VALID_PAGE(vmpl_vmsa_gpa(svm))) {
+		gfn_t gfn = gpa_to_gfn(vmpl_vmsa_gpa(svm));
 		struct kvm_memory_slot *slot;
 		kvm_pfn_t pfn;
 
+		if (vcpu->vmpl != 0) {
+			svm->vmcb->control.asid = to_svm(vcpu->vcpu_parent->vcpu_vmpl[0])->vmcb->control.asid;
+			svm->vmcb->control.nested_cr3 = to_svm(vcpu->vcpu_parent->vcpu_vmpl[0])->vmcb->control.nested_cr3;
+		}
+
 		slot = gfn_to_memslot(vcpu->kvm, gfn);
 		if (!slot)
 			return -EINVAL;
@@ -3952,11 +3957,11 @@ static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu)
 		 * guest boot. Deferring that also allows the existing logic for
 		 * SEV-ES VMSAs to be re-used with minimal SNP-specific changes.
 		 */
-		tgt_vmpl_has_guest_vmsa(svm) = true;
+		vmpl_has_guest_vmsa(svm) = true;
 
 		/* Use the new VMSA */
 		svm->vmcb->control.vmsa_pa = pfn_to_hpa(pfn);
-		tgt_vmpl_vmsa_hpa(svm) = pfn_to_hpa(pfn);
+		vmpl_vmsa_hpa(svm) = pfn_to_hpa(pfn);
 
 		/*
 		 * Since the vCPU may not have gone through the LAUNCH_UPDATE_VMSA path,
@@ -3969,7 +3974,7 @@ static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu)
 		vcpu->arch.pv.pv_unhalted = false;
 		vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
 
-		tgt_vmpl_vmsa_gpa(svm) = INVALID_PAGE;
+		vmpl_vmsa_gpa(svm) = INVALID_PAGE;
 
 		/*
 		 * gmem pages aren't currently migratable, but if this ever
@@ -3980,25 +3985,6 @@ static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu)
 		kvm_release_pfn_clean(pfn);
 	}
 
-	if (cur_vmpl(svm) != tgt_vmpl(svm)) {
-		/* Unmap the current GHCB */
-		sev_es_unmap_ghcb(svm);
-
-		/* Save the GHCB GPA of the current VMPL */
-		svm->sev_es.ghcb_gpa[cur_vmpl(svm)] = svm->vmcb->control.ghcb_gpa;
-
-		/* Set the GHCB_GPA for the target VMPL and make it the current VMPL */
-		svm->vmcb->control.ghcb_gpa = svm->sev_es.ghcb_gpa[tgt_vmpl(svm)];
-
-		cur_vmpl(svm) = tgt_vmpl(svm);
-	}
-
-	/*
-	 * When replacing the VMSA during SEV-SNP AP creation,
-	 * mark the VMCB dirty so that full state is always reloaded.
-	 */
-	vmcb_mark_all_dirty(svm->vmcb);
-
 	return 0;
 }
 
@@ -4017,12 +4003,12 @@ bool sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)
 
 	mutex_lock(&svm->sev_es.snp_vmsa_mutex);
 
-	if (!tgt_vmpl_ap_waiting_for_reset(svm))
+	if (!vmpl_ap_waiting_for_reset(svm))
 		goto unlock;
 
 	init = true;
 
-	tgt_vmpl_ap_waiting_for_reset(svm) = false;
+	vmpl_ap_waiting_for_reset(svm) = false;
 
 	ret = __sev_snp_update_protected_guest_state(vcpu);
 	if (ret)
@@ -4067,6 +4053,8 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
 			    apic_id);
 		return -EINVAL;
 	}
+	/* Ensure we have the target CPU for the correct VMPL */
+	target_vcpu = target_vcpu->vcpu_parent->vcpu_vmpl[vmpl];
 
 	ret = 0;
 
@@ -4081,13 +4069,13 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
 
 	mutex_lock(&target_svm->sev_es.snp_vmsa_mutex);
 
-	vmpl_vmsa_gpa(target_svm, vmpl) = INVALID_PAGE;
-	vmpl_ap_waiting_for_reset(target_svm, vmpl) = true;
+	vmpl_vmsa_gpa(target_svm) = INVALID_PAGE;
+	vmpl_ap_waiting_for_reset(target_svm) = true;
 
 	/* VMPL0 can only be replaced by another vCPU running VMPL0 */
 	if (vmpl == SVM_SEV_VMPL0 &&
 	    (vcpu == target_vcpu ||
-	     vmpl_vmsa_hpa(svm, SVM_SEV_VMPL0) != svm->vmcb->control.vmsa_pa)) {
+	     vmpl_vmsa_hpa(svm) != svm->vmcb->control.vmsa_pa)) {
 		ret = -EINVAL;
 		goto out;
 	}
@@ -4145,9 +4133,7 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
 		kick = false;
 		fallthrough;
 	case SVM_VMGEXIT_AP_CREATE:
-		/* Switch to new VMSA on the next VMRUN */
-		target_svm->sev_es.snp_target_vmpl = vmpl;
-		vmpl_vmsa_gpa(target_svm, vmpl) = svm->vmcb->control.exit_info_2 & PAGE_MASK;
+		vmpl_vmsa_gpa(target_svm) = svm->vmcb->control.exit_info_2 & PAGE_MASK;
 		break;
 	case SVM_VMGEXIT_AP_DESTROY:
 		break;
@@ -4161,6 +4147,17 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
 out:
 	if (kick) {
 		kvm_make_request(KVM_REQ_UPDATE_PROTECTED_GUEST_STATE, target_vcpu);
+
+		/*
+		 * SNP APs can be initially started using the APIC INIT/SIPI sequence or
+		 * via a GHCB call. In the case of the GHCB call the sequence is not moved
+		 * from KVM_MP_STATE_UNINITIALIZED to KVM_MP_STATE_RUNNABLE, so we need
+    	 * to unblock the VCPU.
+		 */
+		if (target_vcpu->vcpu_parent->vcpu_vmpl[0]->arch.mp_state == KVM_MP_STATE_UNINITIALIZED) {
+			target_vcpu->vcpu_parent->vcpu_vmpl[0]->arch.mp_state = KVM_MP_STATE_RUNNABLE;
+		}
+
 		kvm_vcpu_kick(target_vcpu);
 	}
 
@@ -4339,59 +4336,33 @@ static void sev_get_apic_ids(struct vcpu_svm *svm)
 
 static int __sev_run_vmpl_vmsa(struct vcpu_svm *svm, unsigned int new_vmpl)
 {
-	struct kvm_vcpu *vcpu = &svm->vcpu;
-	struct vmpl_switch_sa *old_vmpl_sa;
-	struct vmpl_switch_sa *new_vmpl_sa;
-	unsigned int old_vmpl;
+	struct kvm_vcpu_vmpl_state *vcpu_parent = svm->vcpu.vcpu_parent;
+	struct kvm_vcpu *vcpu_current = &svm->vcpu;
+	struct kvm_vcpu *vcpu_target = vcpu_parent->vcpu_vmpl[new_vmpl];
+	struct vcpu_svm *svm_current = svm;
+	struct vcpu_svm *svm_target = to_svm(vcpu_target);
 
 	if (new_vmpl >= SVM_SEV_VMPL_MAX)
 		return -EINVAL;
 	new_vmpl = array_index_nospec(new_vmpl, SVM_SEV_VMPL_MAX);
+	vcpu_current->vcpu_parent->target_vmpl = new_vmpl;
 
-	old_vmpl = svm->sev_es.snp_current_vmpl;
-	svm->sev_es.snp_target_vmpl = new_vmpl;
+	if (new_vmpl == vcpu_parent->current_vmpl) {
+		return 0;
+	}
 
-	if (svm->sev_es.snp_target_vmpl == svm->sev_es.snp_current_vmpl ||
-	    sev_snp_init_protected_guest_state(vcpu))
+	if (sev_snp_init_protected_guest_state(vcpu_target)) {
 		return 0;
+	}
 
 	/* If the VMSA is not valid, return an error */
-	if (!VALID_PAGE(vmpl_vmsa_hpa(svm, new_vmpl)))
+	if (!VALID_PAGE(vmpl_vmsa_hpa(svm_target)))
 		return -EINVAL;
 
 	/* Unmap the current GHCB */
-	sev_es_unmap_ghcb(svm);
-
-	/* Save some current VMCB values */
-	svm->sev_es.ghcb_gpa[old_vmpl]		= svm->vmcb->control.ghcb_gpa;
-
-	old_vmpl_sa = &svm->sev_es.vssa[old_vmpl];
-	old_vmpl_sa->int_state			= svm->vmcb->control.int_state;
-	old_vmpl_sa->exit_int_info		= svm->vmcb->control.exit_int_info;
-	old_vmpl_sa->exit_int_info_err		= svm->vmcb->control.exit_int_info_err;
-	old_vmpl_sa->cr0			= vcpu->arch.cr0;
-	old_vmpl_sa->cr2			= vcpu->arch.cr2;
-	old_vmpl_sa->cr4			= vcpu->arch.cr4;
-	old_vmpl_sa->cr8			= vcpu->arch.cr8;
-	old_vmpl_sa->efer			= vcpu->arch.efer;
-
-	/* Restore some previous VMCB values */
-	svm->vmcb->control.vmsa_pa		= vmpl_vmsa_hpa(svm, new_vmpl);
-	svm->vmcb->control.ghcb_gpa		= svm->sev_es.ghcb_gpa[new_vmpl];
-
-	new_vmpl_sa = &svm->sev_es.vssa[new_vmpl];
-	svm->vmcb->control.int_state		= new_vmpl_sa->int_state;
-	svm->vmcb->control.exit_int_info	= new_vmpl_sa->exit_int_info;
-	svm->vmcb->control.exit_int_info_err	= new_vmpl_sa->exit_int_info_err;
-	vcpu->arch.cr0				= new_vmpl_sa->cr0;
-	vcpu->arch.cr2				= new_vmpl_sa->cr2;
-	vcpu->arch.cr4				= new_vmpl_sa->cr4;
-	vcpu->arch.cr8				= new_vmpl_sa->cr8;
-	vcpu->arch.efer				= new_vmpl_sa->efer;
-
-	svm->sev_es.snp_current_vmpl = new_vmpl;
-
-	vmcb_mark_all_dirty(svm->vmcb);
+	sev_es_unmap_ghcb(svm_current);
+
+	vcpu_parent->target_vmpl = new_vmpl;
 
 	return 0;
 }
@@ -4520,7 +4491,7 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
 		gfn = get_ghcb_msr_bits(svm, GHCB_MSR_GPA_VALUE_MASK,
 					GHCB_MSR_GPA_VALUE_POS);
 
-		svm->sev_es.ghcb_registered_gpa[cur_vmpl(svm)] = gfn_to_gpa(gfn);
+		svm->sev_es.ghcb_registered_gpa = gfn_to_gpa(gfn);
 
 		set_ghcb_msr_bits(svm, gfn, GHCB_MSR_GPA_VALUE_MASK,
 				  GHCB_MSR_GPA_VALUE_POS);
@@ -4825,8 +4796,8 @@ static void sev_es_init_vmcb(struct vcpu_svm *svm)
 	 * the VMSA will be NULL if this vCPU is the destination for intrahost
 	 * migration, and will be copied later.
 	 */
-	if (cur_vmpl_vmsa(svm) && !cur_vmpl_has_guest_vmsa(svm))
-		svm->vmcb->control.vmsa_pa = __pa(cur_vmpl_vmsa(svm));
+	if (vmpl_vmsa(svm) && !vmpl_has_guest_vmsa(svm))
+		svm->vmcb->control.vmsa_pa = __pa(vmpl_vmsa(svm));
 
 	/* Can't intercept CR register access, HV can't modify CR registers */
 	svm_clr_intercept(svm, INTERCEPT_CR0_READ);
@@ -4889,7 +4860,6 @@ void sev_es_vcpu_reset(struct vcpu_svm *svm)
 {
 	struct kvm_vcpu *vcpu = &svm->vcpu;
 	struct kvm_sev_info *sev = &to_kvm_svm(vcpu->kvm)->sev_info;
-	unsigned int i;
 	u64 sev_info;
 
 	/*
@@ -4899,20 +4869,9 @@ void sev_es_vcpu_reset(struct vcpu_svm *svm)
 	sev_info = GHCB_MSR_SEV_INFO((__u64)sev->ghcb_version, GHCB_VERSION_MIN,
 				     sev_enc_bit);
 	set_ghcb_msr(svm, sev_info);
-	svm->sev_es.ghcb_gpa[SVM_SEV_VMPL0] = sev_info;
+	svm->sev_es.ghcb_gpa = sev_info;
 
 	mutex_init(&svm->sev_es.snp_vmsa_mutex);
-
-	/*
-	 * When not running under SNP, the "current VMPL" tracking for a guest
-	 * is always 0 and the base tracking of GPAs and SPAs will be as before
-	 * multiple VMPL support. However, under SNP, multiple VMPL levels can
-	 * be run, so initialize these values appropriately.
-	 */
-	for (i = 1; i < SVM_SEV_VMPL_MAX; i++) {
-		svm->sev_es.vmsa_info[i].hpa = INVALID_PAGE;
-		svm->sev_es.ghcb_gpa[i] = sev_info;
-	}
 }
 
 void sev_es_prepare_switch_to_guest(struct vcpu_svm *svm, struct sev_es_save_area *hostsa)
@@ -5301,7 +5260,7 @@ bool sev_snp_is_rinj_active(struct kvm_vcpu *vcpu)
 		return false;
 
 	sev = &to_kvm_svm(vcpu->kvm)->sev_info;
-	vmpl = to_svm(vcpu)->sev_es.snp_current_vmpl;
+	vmpl = vcpu->vcpu_parent->current_vmpl;
 
 	return sev->vmsa_features[vmpl] & SVM_SEV_FEAT_RESTRICTED_INJECTION;
 }
arch/x86/kvm/svm/svm.c +40 -26

88 lines not on this page · raw message

arch/x86/kvm/svm/svm.h +10 -26
index 97a1b1b4cb5f..de7f92ba55c3 100644
@@ -211,25 +211,11 @@ struct vmpl_switch_sa {
 	u64 efer;
 };
 
-#define vmpl_vmsa(s, v)				((s)->sev_es.vmsa_info[(v)].vmsa)
-#define vmpl_vmsa_gpa(s, v)			((s)->sev_es.vmsa_info[(v)].gpa)
-#define vmpl_vmsa_hpa(s, v)			((s)->sev_es.vmsa_info[(v)].hpa)
-#define vmpl_ap_waiting_for_reset(s, v)		((s)->sev_es.vmsa_info[(v)].ap_waiting_for_reset)
-#define vmpl_has_guest_vmsa(s, v)		((s)->sev_es.vmsa_info[(v)].has_guest_vmsa)
-
-#define cur_vmpl(s)				((s)->sev_es.snp_current_vmpl)
-#define cur_vmpl_vmsa(s)			vmpl_vmsa((s), cur_vmpl(s))
-#define cur_vmpl_vmsa_gpa(s)			vmpl_vmsa_gpa((s), cur_vmpl(s))
-#define cur_vmpl_vmsa_hpa(s)			vmpl_vmsa_hpa((s), cur_vmpl(s))
-#define cur_vmpl_ap_waiting_for_reset(s)	vmpl_ap_waiting_for_reset((s), cur_vmpl(s))
-#define cur_vmpl_has_guest_vmsa(s)		vmpl_has_guest_vmsa((s), cur_vmpl(s))
-
-#define tgt_vmpl(s)				((s)->sev_es.snp_target_vmpl)
-#define tgt_vmpl_vmsa(s)			vmpl_vmsa((s), tgt_vmpl(s))
-#define tgt_vmpl_vmsa_gpa(s)			vmpl_vmsa_gpa((s), tgt_vmpl(s))
-#define tgt_vmpl_vmsa_hpa(s)			vmpl_vmsa_hpa((s), tgt_vmpl(s))
-#define tgt_vmpl_ap_waiting_for_reset(s)	vmpl_ap_waiting_for_reset((s), tgt_vmpl(s))
-#define tgt_vmpl_has_guest_vmsa(s)		vmpl_has_guest_vmsa((s), tgt_vmpl(s))
+#define vmpl_vmsa(s)				((s)->sev_es.vmsa_info.vmsa)
+#define vmpl_vmsa_gpa(s)			((s)->sev_es.vmsa_info.gpa)
+#define vmpl_vmsa_hpa(s)			((s)->sev_es.vmsa_info.hpa)
+#define vmpl_ap_waiting_for_reset(s)	((s)->sev_es.vmsa_info.ap_waiting_for_reset)
+#define vmpl_has_guest_vmsa(s)		((s)->sev_es.vmsa_info.has_guest_vmsa)
 
 struct sev_vmsa_info {
 	/* SEV-ES and SEV-SNP */
@@ -262,15 +248,13 @@ struct vcpu_sev_es_state {
 	u16 psc_inflight;
 	bool psc_2m;
 
-	gpa_t ghcb_gpa[SVM_SEV_VMPL_MAX];
-	u64 ghcb_registered_gpa[SVM_SEV_VMPL_MAX];
-	struct sev_vmsa_info vmsa_info[SVM_SEV_VMPL_MAX];
+	gpa_t ghcb_gpa;
+	u64 ghcb_registered_gpa;
+	struct sev_vmsa_info vmsa_info;
 
 	struct mutex snp_vmsa_mutex; /* Used to handle concurrent updates of VMSA. */
-	unsigned int snp_current_vmpl;
-	unsigned int snp_target_vmpl;
 
-	struct vmpl_switch_sa vssa[SVM_SEV_VMPL_MAX];
+	struct vmpl_switch_sa vssa;
 };
 
 struct vcpu_svm {
@@ -426,7 +410,7 @@ static __always_inline bool sev_snp_guest(struct kvm *kvm)
 
 static inline bool ghcb_gpa_is_registered(struct vcpu_svm *svm, u64 val)
 {
-	return svm->sev_es.ghcb_registered_gpa[cur_vmpl(svm)] == val;
+	return svm->sev_es.ghcb_registered_gpa == val;
 }
 
 static inline void vmcb_mark_all_dirty(struct vmcb *vmcb)
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH 4/5 x86/kvm: Add x86 field to find the default VMPL that IRQs should target

In reply to Roy Hopkins

When a CPU supports multiple VMPLs, injected interrupts need to be sent to the correct context. This commit adds an operation that determines the VMPL number that IRQs should be sent to in the absence of an explicit target VMPL.

---
 arch/x86/include/asm/kvm_host.h | 7 +++++++
 arch/x86/kvm/svm/sev.c          | 8 ++++++++
 2 files changed, 15 insertions(+)
arch/x86/include/asm/kvm_host.h +7 -0
index 94e7b5a4fafe..3dd3a5ff0cec 100644
@@ -1537,6 +1537,13 @@ struct kvm_arch {
 	 */
 #define SPLIT_DESC_CACHE_MIN_NR_OBJECTS (SPTE_ENT_PER_PAGE + 1)
 	struct kvm_mmu_memory_cache split_desc_cache;
+
+	/*
+	 * When a system supports multiple VMPLs, injected interrupts need to be
+	 * sent to the correct context. The default VMPL that IRQs should be sent
+	 * to is indicated in this variable.
+	 */
+	unsigned int default_irq_vmpl;
 };
 
 struct kvm_vm_stat {
arch/x86/kvm/svm/sev.c +8 -0
index 3fbb1ce5195d..ed91aa93da6e 100644
@@ -3983,6 +3983,14 @@ static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu)
 		 * means.
 		 */
 		kvm_release_pfn_clean(pfn);
+
+		/*
+		 * TEMP: If the newly created VMSA is for a lower VMPL then
+		 * set this VMPL to be the default for sending IRQs to.
+		 */
+		if (vcpu->vmpl > vcpu->kvm->arch.default_irq_vmpl) {
+			vcpu->kvm->arch.default_irq_vmpl = vcpu->vmpl;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.43.0
#5 lore raw

RFC PATCH 5/5 x86/kvm: Add target VMPL to IRQs and send to APIC for VMPL

In reply to Roy Hopkins

Systems that support VMPLs need to decide which VMPL each IRQ is destined for; each VMPL can support its own set of hardware devices that generate interrupts.

This commit extends kvm_lapic_irq to include a target_vmpl field the sends the IRQ to the APIC instance at the target VMPL.

---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/ioapic.c           | 3 +++
 arch/x86/kvm/irq_comm.c         | 1 +
 arch/x86/kvm/lapic.c            | 6 +++++-
 4 files changed, 10 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +1 -0
index 3dd3a5ff0cec..d0febb67dabf 100644
@@ -1624,6 +1624,7 @@ struct kvm_lapic_irq {
 	u32 shorthand;
 	u32 dest_id;
 	bool msi_redir_hint;
+	unsigned int target_vmpl;
 };
 
 static inline u16 kvm_lapic_irq_dest_mode(bool dest_mode_logical)
arch/x86/kvm/ioapic.c +3 -0
index 995eb5054360..7b835a192561 100644
@@ -413,6 +413,8 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
 			irq.shorthand = APIC_DEST_NOSHORT;
 			irq.dest_id = e->fields.dest_id;
 			irq.msi_redir_hint = false;
+			irq.target_vmpl = ioapic->kvm->arch.default_irq_vmpl;
+
 			bitmap_zero(vcpu_bitmap, KVM_MAX_VCPUS);
 			kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq,
 						 vcpu_bitmap);
@@ -458,6 +460,7 @@ static int ioapic_service(struct kvm_ioapic *ioapic, int irq, bool line_status)
 	irqe.level = 1;
 	irqe.shorthand = APIC_DEST_NOSHORT;
 	irqe.msi_redir_hint = false;
+	irqe.target_vmpl = ioapic->kvm->arch.default_irq_vmpl;
 
 	if (irqe.trig_mode == IOAPIC_EDGE_TRIG)
 		ioapic->irr_delivered |= 1 << irq;
arch/x86/kvm/irq_comm.c +1 -0
index 8136695f7b96..6bd4a78dddba 100644
@@ -119,6 +119,7 @@ void kvm_set_msi_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e,
 	irq->msi_redir_hint = msg.arch_addr_lo.redirect_hint;
 	irq->level = 1;
 	irq->shorthand = APIC_DEST_NOSHORT;
+	irq->target_vmpl = kvm->arch.default_irq_vmpl;
 }
 EXPORT_SYMBOL_GPL(kvm_set_msi_irq);
 
arch/x86/kvm/lapic.c +5 -1
index e2dd573e4f2d..20b433a78457 100644
@@ -836,7 +836,9 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
 int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq,
 		     struct dest_map *dest_map)
 {
-	struct kvm_lapic *apic = vcpu->arch.apic;
+	struct kvm_lapic *apic = vcpu->vcpu_parent->vcpu_vmpl[irq->target_vmpl]->arch.apic;
+	if (!apic)
+		return -EINVAL;
 
 	return __apic_accept_irq(apic, irq->delivery_mode, irq->vector,
 			irq->level, irq->trig_mode, dest_map);
@@ -1528,6 +1530,8 @@ void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high)
 	irq.trig_mode = icr_low & APIC_INT_LEVELTRIG;
 	irq.shorthand = icr_low & APIC_SHORT_MASK;
 	irq.msi_redir_hint = false;
+	/* IPIs always target the same VMPL as the source */
+	irq.target_vmpl = apic->vcpu->vmpl;
 	if (apic_x2apic_mode(apic))
 		irq.dest_id = icr_high;
 	else
Signature · 1 line
2.43.0
#6 lore raw
In reply to Roy Hopkins
Quoted 6 lines

I've prepared this series as an extension to the RFC patch series:
'SEV-SNP support for running an SVSM' posted by Tom Lendacky [1]. This extends the support for transitioning a vCPU between VM Privilege Levels (VMPLs) by storing the vCPU state for each VMPL in its own struct kvm_vcpu. This additionally allows for separate APICs for each VMPL.

I couldn't attend KVM forum, but I understand based on feedback at a session there, Paolo took the lead to provide an architecture document for this feature, is that correct? Just asking because I haven't noticed anything about this on the list.

Regards,

James

#7 lore raw
Quoted 10 lines · James Bottomley
Quoted 6 lines

I've prepared this series as an extension to the RFC patch series:
'SEV-SNP support for running an SVSM' posted by Tom Lendacky [1]. This extends the support for transitioning a vCPU between VM Privilege Levels (VMPLs) by storing the vCPU state for each VMPL in its own struct kvm_vcpu. This additionally allows for separate APICs for each VMPL.

I couldn't attend KVM forum, but I understand based on feedback at a session there, Paolo took the lead to provide an architecture document for this feature, is that correct?

Yep.

Quoted 1 line

Just asking because I haven't noticed anything about this on the list.

Heh, there's quite a queue of blocked readers (and writers!) at this point ;-)

maintainer
#8 lore raw
Quoted 12 lines · Sean Christopherson
Quoted 10 lines · James Bottomley
Quoted 6 lines

I've prepared this series as an extension to the RFC patch series:
'SEV-SNP support for running an SVSM' posted by Tom Lendacky [1]. This extends the support for transitioning a vCPU between VM Privilege Levels (VMPLs) by storing the vCPU state for each VMPL in its own struct kvm_vcpu. This additionally allows for separate APICs for each VMPL.

I couldn't attend KVM forum, but I understand based on feedback at a session there, Paolo took the lead to provide an architecture document for this feature, is that correct?

Quoted 5 lines

Yep.

Quoted 1 line

Just asking because I haven't noticed anything about this on the list.

Heh, there's quite a queue of blocked readers (and writers!) at this point ;-)

Well, at least one person had a writer's block instead.

I had it almost ready but then noticed a few hiccups in the design we came up with, and have been seating on it for a while. I'm sending it now, finishing the commit messages.

Paolo

#9 lore raw
Quoted 18 lines · Paolo Bonzini
Quoted 17 lines · Sean Christopherson
Quoted 10 lines · James Bottomley
Quoted 6 lines

I've prepared this series as an extension to the RFC patch
series: 'SEV-SNP support for running an SVSM' posted by Tom Lendacky [1]. This extends the support for transitioning a vCPU between VM Privilege Levels (VMPLs) by storing the vCPU state for each VMPL in its own struct kvm_vcpu. This additionally allows for separate APICs for each VMPL.

I couldn't attend KVM forum, but I understand based on feedback at a session there, Paolo took the lead to provide an architecture document for this feature, is that correct?

Yep.

Quoted 2 lines

Just asking because I haven't noticed anything about this on the list.

Quoted 8 lines
Quoted 2 lines

Heh, there's quite a queue of blocked readers (and writers!) at this point ;-)

Well, at least one person had a writer's block instead.

I had it almost ready but then noticed a few hiccups in the design we came up with, and have been seating on it for a while.  I'm sending it now, finishing the commit messages.

Thanks for doing that. For those on linux-coco who don't follow the KVM list, the document is here:

https://lore.kernel.org/kvm/[email protected]/

Regards,

James