All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/18] KVM/arm64: Refactoring the vcpu flags
@ 2022-05-28 11:38 ` Marc Zyngier
  0 siblings, 0 replies; 141+ messages in thread
From: Marc Zyngier @ 2022-05-28 11:38 UTC (permalink / raw)
  To: kvmarm, kvm, linux-arm-kernel
  Cc: James Morse, Suzuki K Poulose, Alexandru Elisei, Oliver Upton,
	Will Deacon, Fuad Tabba, Quentin Perret, Mark Brown, kernel-team

While working on pKVM, it slowly became apparent that dealing with the
flags was a pain, as they serve multiple purposes:

- some flags are purely a configuration artefact,

- some are an input from the host kernel to the world switch,

- a bunch of them are bookkeeping information for the kernel itself,

- and finally some form a state machine between the host and the world
  switch.

Given that, it became pretty hard to clearly delineate what needed to
be conveyed between the host view of a vcpu and the shadow copy the
world switch deals with, both on entry and exit. This has led to a
flurry of bad bugs when developing the feature, and it is time to put
some order in this mess.

This series is roughly split in four parts:

- patch 1 addresses an embarrassing bug that would leave SVE enabled
  for host EL0 once the vcpu had the flag set (it was never cleared),
  and patch 2 fix the same bug for SME, as it copied the bad
  behaviour (both patches are fix candidates for -rc1, and the first
  one carries a Cc stable).

- patches 3 and 4 rid us of the FP flags altogether, as they really
  form a state machine that is better represented with an enum instead
  of dubious bit fiddling in both directions.

- patch 5 through to 14 split all the flags into three distinct
  categories: configuration, input to the world switch, and host
  state, using some ugly^Wbeautiful^Wquestionable cpp tricks.

- finally, the last patches add some cheap hardening and size
  optimisation to the new flags.

With that in place, it should be much easier to reason about which
flags need to be synchronised at runtime, and in which direction (for
pKVM, this is only a subset of the input flags, and nothing else).

This has been lightly tested on both VHE and nVHE systems, but not
with pKVM itself (there is a bit of work to rebase it on top of this
infrastructure). Patches on top of kvmarm-4.19 (there is a minor
conflict with Linus' current tree).

Marc Zyngier (18):
  KVM: arm64: Always start with clearing SVE flag on load
  KVM: arm64: Always start with clearing SME flag on load
  KVM: arm64: Drop FP_FOREIGN_STATE from the hypervisor code
  KVM: arm64: Move FP state ownership from flag to a tristate
  KVM: arm64: Add helpers to manipulate vcpu flags among a set
  KVM: arm64: Add three sets of flags to the vcpu state
  KVM: arm64: Move vcpu configuration flags into their own set
  KVM: arm64: Move vcpu PC/Exception flags to the input flag set
  KVM: arm64: Move vcpu debug/SPE/TRBE flags to the input flag set
  KVM: arm64: Move vcpu SVE/SME flags to the state flag set
  KVM: arm64: Move vcpu ON_UNSUPPORTED_CPU flag to the state flag set
  KVM: arm64: Move vcpu WFIT flag to the state flag set
  KVM: arm64: Kill unused vcpu flags field
  KVM: arm64: Convert vcpu sysregs_loaded_on_cpu to a state flag
  KVM: arm64: Warn when PENDING_EXCEPTION and INCREMENT_PC are set
    together
  KVM: arm64: Add build-time sanity checks for flags
  KVM: arm64: Reduce the size of the vcpu flag members
  KVM: arm64: Document why pause cannot be turned into a flag

 arch/arm64/include/asm/kvm_emulate.h       |   3 +-
 arch/arm64/include/asm/kvm_host.h          | 192 +++++++++++++++------
 arch/arm64/kvm/arch_timer.c                |   2 +-
 arch/arm64/kvm/arm.c                       |   6 +-
 arch/arm64/kvm/debug.c                     |  22 +--
 arch/arm64/kvm/fpsimd.c                    |  36 ++--
 arch/arm64/kvm/handle_exit.c               |   2 +-
 arch/arm64/kvm/hyp/exception.c             |  23 ++-
 arch/arm64/kvm/hyp/include/hyp/debug-sr.h  |   6 +-
 arch/arm64/kvm/hyp/include/hyp/switch.h    |  24 +--
 arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h |   4 +-
 arch/arm64/kvm/hyp/nvhe/debug-sr.c         |   8 +-
 arch/arm64/kvm/hyp/nvhe/switch.c           |   6 +-
 arch/arm64/kvm/hyp/nvhe/sys_regs.c         |   7 +-
 arch/arm64/kvm/hyp/vhe/switch.c            |   4 +-
 arch/arm64/kvm/hyp/vhe/sysreg-sr.c         |   4 +-
 arch/arm64/kvm/inject_fault.c              |  30 ++--
 arch/arm64/kvm/reset.c                     |   6 +-
 arch/arm64/kvm/sys_regs.c                  |  12 +-
 19 files changed, 238 insertions(+), 159 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 141+ messages in thread

end of thread, other threads:[~2022-06-10  7:49 UTC | newest]

Thread overview: 141+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-28 11:38 [PATCH 00/18] KVM/arm64: Refactoring the vcpu flags Marc Zyngier
2022-05-28 11:38 ` Marc Zyngier
2022-05-28 11:38 ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 01/18] KVM: arm64: Always start with clearing SVE flag on load Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-30 14:41   ` Mark Brown
2022-05-30 14:41     ` Mark Brown
2022-05-30 14:41     ` Mark Brown
2022-06-06 11:28     ` Marc Zyngier
2022-06-06 11:28       ` Marc Zyngier
2022-06-06 11:28       ` Marc Zyngier
2022-06-06 12:16       ` Mark Brown
2022-06-06 12:16         ` Mark Brown
2022-06-06 12:16         ` Mark Brown
2022-05-28 11:38 ` [PATCH 02/18] KVM: arm64: Always start with clearing SME " Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-30 14:51   ` Mark Brown
2022-05-30 14:51     ` Mark Brown
2022-05-30 14:51     ` Mark Brown
2022-05-28 11:38 ` [PATCH 03/18] KVM: arm64: Drop FP_FOREIGN_STATE from the hypervisor code Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-06-03  5:23   ` Reiji Watanabe
2022-06-03  5:23     ` Reiji Watanabe
2022-06-03  5:23     ` Reiji Watanabe
2022-06-04  8:10     ` Marc Zyngier
2022-06-04  8:10       ` Marc Zyngier
2022-06-04  8:10       ` Marc Zyngier
2022-06-07  4:47       ` Reiji Watanabe
2022-06-07  4:47         ` Reiji Watanabe
2022-06-07  4:47         ` Reiji Watanabe
2022-06-03  9:09   ` Mark Brown
2022-06-03  9:09     ` Mark Brown
2022-06-03  9:09     ` Mark Brown
2022-05-28 11:38 ` [PATCH 04/18] KVM: arm64: Move FP state ownership from flag to a tristate Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-06-03  9:14   ` Mark Brown
2022-06-03  9:14     ` Mark Brown
2022-06-03  9:14     ` Mark Brown
2022-06-06  8:41     ` Marc Zyngier
2022-06-06  8:41       ` Marc Zyngier
2022-06-06  8:41       ` Marc Zyngier
2022-06-06 10:31       ` Mark Brown
2022-06-06 10:31         ` Mark Brown
2022-06-06 10:31         ` Mark Brown
2022-06-04  8:16   ` Reiji Watanabe
2022-06-04  8:16     ` Reiji Watanabe
2022-06-04  8:16     ` Reiji Watanabe
2022-05-28 11:38 ` [PATCH 05/18] KVM: arm64: Add helpers to manipulate vcpu flags among a set Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-06-08  5:26   ` Reiji Watanabe
2022-06-08  5:26     ` Reiji Watanabe
2022-06-08  5:26     ` Reiji Watanabe
2022-06-08  6:51     ` Marc Zyngier
2022-06-08  6:51       ` Marc Zyngier
2022-06-08  6:51       ` Marc Zyngier
2022-06-09  2:25       ` Reiji Watanabe
2022-06-09  2:25         ` Reiji Watanabe
2022-06-09  2:25         ` Reiji Watanabe
2022-05-28 11:38 ` [PATCH 06/18] KVM: arm64: Add three sets of flags to the vcpu state Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-06-08 15:23   ` Fuad Tabba
2022-06-08 15:23     ` Fuad Tabba
2022-06-08 15:23     ` Fuad Tabba
2022-06-09  6:10   ` Reiji Watanabe
2022-06-09  6:10     ` Reiji Watanabe
2022-06-09  6:10     ` Reiji Watanabe
2022-06-09  7:46     ` Marc Zyngier
2022-06-09  7:46       ` Marc Zyngier
2022-06-09  7:46       ` Marc Zyngier
2022-06-09 17:24       ` Reiji Watanabe
2022-06-09 17:24         ` Reiji Watanabe
2022-06-09 17:24         ` Reiji Watanabe
2022-06-10  7:48         ` Marc Zyngier
2022-06-10  7:48           ` Marc Zyngier
2022-06-10  7:48           ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 07/18] KVM: arm64: Move vcpu configuration flags into their own set Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-06-09  6:15   ` Reiji Watanabe
2022-06-09  6:15     ` Reiji Watanabe
2022-06-09  6:15     ` Reiji Watanabe
2022-05-28 11:38 ` [PATCH 08/18] KVM: arm64: Move vcpu PC/Exception flags to the input flag set Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-06-10  6:13   ` Reiji Watanabe
2022-06-10  6:13     ` Reiji Watanabe
2022-06-10  6:13     ` Reiji Watanabe
2022-05-28 11:38 ` [PATCH 09/18] KVM: arm64: Move vcpu debug/SPE/TRBE " Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-06-08 15:16   ` Fuad Tabba
2022-06-08 15:16     ` Fuad Tabba
2022-06-08 15:16     ` Fuad Tabba
2022-06-08 16:01     ` Marc Zyngier
2022-06-08 16:01       ` Marc Zyngier
2022-06-08 16:01       ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 10/18] KVM: arm64: Move vcpu SVE/SME flags to the state " Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 11/18] KVM: arm64: Move vcpu ON_UNSUPPORTED_CPU flag " Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 12/18] KVM: arm64: Move vcpu WFIT " Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 13/18] KVM: arm64: Kill unused vcpu flags field Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 14/18] KVM: arm64: Convert vcpu sysregs_loaded_on_cpu to a state flag Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 15/18] KVM: arm64: Warn when PENDING_EXCEPTION and INCREMENT_PC are set together Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-06-08 15:16   ` Fuad Tabba
2022-06-08 15:16     ` Fuad Tabba
2022-06-08 15:16     ` Fuad Tabba
2022-06-08 16:42     ` Marc Zyngier
2022-06-08 16:42       ` Marc Zyngier
2022-06-08 16:42       ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 16/18] KVM: arm64: Add build-time sanity checks for flags Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 17/18] KVM: arm64: Reduce the size of the vcpu flag members Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38 ` [PATCH 18/18] KVM: arm64: Document why pause cannot be turned into a flag Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-28 11:38   ` Marc Zyngier
2022-05-30  8:28 ` [PATCH 00/18] KVM/arm64: Refactoring the vcpu flags Marc Zyngier
2022-05-30  8:28   ` Marc Zyngier
2022-05-30  8:28   ` Marc Zyngier
2022-06-07 13:43 ` Marc Zyngier
2022-06-07 13:43   ` Marc Zyngier
2022-06-07 13:43   ` Marc Zyngier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.