Skip to contentSkip to conversation

KVM: PPC: Save/restore complete Book3S HV guest register state

PATCH Superseded Paul Mackerras 3 participants 8 messages Sep 18, 2012 – Sep 19, 2012

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover KVM: PPC: Save/restore complete Book3S HV guest register state

This series of 2 patches makes it possible for userspace to save and restore the complete register state of a Book3S HV guest. Currently it is not possible to save/restore several SPRs or any of the floating-point state (including VMX/Altivec and VSX state). This series extends the [GS]ET_ONE_REG ioctl to handle the missing SPRs, and implements kvm_arch_vcpu_ioctl_[gs]et_fpu() and extends struct kvm_fpu to handle the floating-point state.

These patches are against the kvm-ppc-next branch of Alex Graf's linux-2.6.git repository on github.

Paul.

#1 lore raw

PATCH v2 1/2 KVM: PPC: Book3S HV: Get/set guest SPRs using the GET/SET_ONE_REG interface

This enables userspace to get and set various SPRs (special-purpose registers) using the KVM_[GS]ET_ONE_REG ioctls. With this, userspace can get and set all the SPRs that are part of the guest state, either through the KVM_[GS]ET_REGS ioctls, the KVM_[GS]ET_SREGS ioctls, or the KVM_[GS]ET_ONE_REG ioctls.

The SPRs that are added here are:

- DABR:  Data address breakpoint register
- DSCR:  Data stream control register
- PURR:  Processor utilization of resources register

- SPURR: Scaled PURR
- DAR: Data address register
- DSISR: Data storage interrupt status register
- AMR: Authority mask register
- UAMOR: User authority mask override register
- MMCR0, MMCR1, MMCRA: Performance monitor unit control registers
- PMC1..PMC8: Performance monitor unit counter registers

---
v2: use case a...b: notation for MMCR0/1/A and PMCs

 Documentation/virtual/kvm/api.txt |   19 ++++++++
 arch/powerpc/include/asm/kvm.h    |   21 +++++++++
 arch/powerpc/kvm/book3s_hv.c      |   88 +++++++++++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+)
Documentation/virtual/kvm/api.txt +19 -0
index a12f4e4..407556f 100644
@@ -1740,6 +1740,25 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_IAC4      | 64
   PPC   | KVM_REG_PPC_DAC1      | 64
   PPC   | KVM_REG_PPC_DAC2      | 64
+  PPC   | KVM_REG_PPC_DABR      | 64
+  PPC   | KVM_REG_PPC_DSCR      | 64
+  PPC   | KVM_REG_PPC_PURR      | 64
+  PPC   | KVM_REG_PPC_SPURR     | 64
+  PPC   | KVM_REG_PPC_DAR       | 64
+  PPC   | KVM_REG_PPC_DSISR	| 32
+  PPC   | KVM_REG_PPC_AMR       | 64
+  PPC   | KVM_REG_PPC_UAMOR     | 64
+  PPC   | KVM_REG_PPC_MMCR0     | 64
+  PPC   | KVM_REG_PPC_MMCR1     | 64
+  PPC   | KVM_REG_PPC_MMCRA     | 64
+  PPC   | KVM_REG_PPC_PMC1      | 32
+  PPC   | KVM_REG_PPC_PMC2      | 32
+  PPC   | KVM_REG_PPC_PMC3      | 32
+  PPC   | KVM_REG_PPC_PMC4      | 32
+  PPC   | KVM_REG_PPC_PMC5      | 32
+  PPC   | KVM_REG_PPC_PMC6      | 32
+  PPC   | KVM_REG_PPC_PMC7      | 32
+  PPC   | KVM_REG_PPC_PMC8      | 32
 
 4.69 KVM_GET_ONE_REG
 
arch/powerpc/include/asm/kvm.h +21 -0
index 3c14202..9557576 100644
@@ -338,5 +338,26 @@ struct kvm_book3e_206_tlb_params {
 #define KVM_REG_PPC_IAC4	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x5)
 #define KVM_REG_PPC_DAC1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x6)
 #define KVM_REG_PPC_DAC2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x7)
+#define KVM_REG_PPC_DABR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8)
+#define KVM_REG_PPC_DSCR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x9)
+#define KVM_REG_PPC_PURR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa)
+#define KVM_REG_PPC_SPURR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb)
+#define KVM_REG_PPC_DAR		(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc)
+#define KVM_REG_PPC_DSISR	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xd)
+#define KVM_REG_PPC_AMR		(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xe)
+#define KVM_REG_PPC_UAMOR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xf)
+
+#define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
+#define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+
+#define KVM_REG_PPC_PMC1	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x18)
+#define KVM_REG_PPC_PMC2	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x19)
+#define KVM_REG_PPC_PMC3	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1a)
+#define KVM_REG_PPC_PMC4	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1b)
+#define KVM_REG_PPC_PMC5	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1c)
+#define KVM_REG_PPC_PMC6	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1d)
+#define KVM_REG_PPC_PMC7	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1e)
+#define KVM_REG_PPC_PMC8	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1f)
 
 #endif /* __LINUX_KVM_POWERPC_H */
arch/powerpc/kvm/book3s_hv.c +88 -0

111 lines not on this page · raw message

Signature · 1 line
1.7.10.rc3.219.g53414
#7 lore raw

PATCH v2 2/2 KVM: PPC: Book3S HV: Get/set guest FP regs using the GET/SET_ONE_REG interface

In reply to Paul Mackerras

This enables userspace to get and set all the guest floating-point state using the KVM_[GS]ET_ONE_REG ioctls. The floating-point state includes all of the traditional floating-point registers and the FPSCR (floating point status/control register), all the VMX/Altivec vector registers and the VSCR (vector status/control register), and on POWER7, the vector-scalar registers (note that each FP register is the high-order half of the corresponding VSR).

---
 Documentation/virtual/kvm/api.txt |   11 ++++
 arch/powerpc/include/asm/kvm.h    |   20 +++++++
 arch/powerpc/kvm/book3s_hv.c      |  112 +++++++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)
Documentation/virtual/kvm/api.txt +11 -0
index 407556f..a02f0de 100644
@@ -1759,6 +1759,17 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_PMC6      | 32
   PPC   | KVM_REG_PPC_PMC7      | 32
   PPC   | KVM_REG_PPC_PMC8      | 32
+  PPC   | KVM_REG_PPC_FPR0	| 64
+          ...
+  PPC   | KVM_REG_PPC_FPR31     | 64
+  PPC   | KVM_REG_PPC_VR0	| 128
+          ...
+  PPC   | KVM_REG_PPC_VR31      | 128
+  PPC   | KVM_REG_PPC_VSR0	| 128
+          ...
+  PPC   | KVM_REG_PPC_VSR31     | 128
+  PPC   | KVM_REG_PPC_FPSCR     | 64
+  PPC   | KVM_REG_PPC_VSCR      | 32
 
 4.69 KVM_GET_ONE_REG
 
arch/powerpc/include/asm/kvm.h +20 -0
index 9557576..1466975 100644
@@ -360,4 +360,24 @@ struct kvm_book3e_206_tlb_params {
 #define KVM_REG_PPC_PMC7	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1e)
 #define KVM_REG_PPC_PMC8	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1f)
 
+/* 32 floating-point registers */
+#define KVM_REG_PPC_FPR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x20)
+#define KVM_REG_PPC_FPR(n)	(KVM_REG_PPC_FPR0 + (n))
+#define KVM_REG_PPC_FPR31	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x3f)
+
+/* 32 VMX/Altivec vector registers */
+#define KVM_REG_PPC_VR0		(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x40)
+#define KVM_REG_PPC_VR(n)	(KVM_REG_PPC_VR0 + (n))
+#define KVM_REG_PPC_VR31	(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x5f)
+
+/* 32 double-width FP registers for VSX */
+/* High-order halves overlap with FP regs */
+#define KVM_REG_PPC_VSR0	(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x60)
+#define KVM_REG_PPC_VSR(n)	(KVM_REG_PPC_VSR0 + (n))
+#define KVM_REG_PPC_VSR31	(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x7f)
+
+/* FP and vector status/control registers */
+#define KVM_REG_PPC_FPSCR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x80)
+#define KVM_REG_PPC_VSCR	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x81)
+
 #endif /* __LINUX_KVM_POWERPC_H */
arch/powerpc/kvm/book3s_hv.c +112 -0

124 lines not on this page · raw message

Signature · 1 line
1.7.10.rc3.219.g53414
#2 lore raw

Re: [PATCH v2 1/2] KVM: PPC: Book3S HV: Get/set guest SPRs using the GET/SET_ONE_REG interface

In reply to Paul Mackerras
Quoted 105 lines · Paul Mackerras

This enables userspace to get and set various SPRs (special-purpose registers) using the KVM_[GS]ET_ONE_REG ioctls. With this, userspace can get and set all the SPRs that are part of the guest state, either through the KVM_[GS]ET_REGS ioctls, the KVM_[GS]ET_SREGS ioctls, or the KVM_[GS]ET_ONE_REG ioctls.

The SPRs that are added here are:

- DABR:  Data address breakpoint register
- DSCR:  Data stream control register
- PURR:  Processor utilization of resources register

- SPURR: Scaled PURR
- DAR: Data address register
- DSISR: Data storage interrupt status register
- AMR: Authority mask register
- UAMOR: User authority mask override register
- MMCR0, MMCR1, MMCRA: Performance monitor unit control registers
- PMC1..PMC8: Performance monitor unit counter registers

---
v2: use case a...b: notation for MMCR0/1/A and PMCs

  Documentation/virtual/kvm/api.txt |   19 ++++++++
  arch/powerpc/include/asm/kvm.h    |   21 +++++++++
  arch/powerpc/kvm/book3s_hv.c      |   88 +++++++++++++++++++++++++++++++++++++
  3 files changed, 128 insertions(+)
Documentation/virtual/kvm/api.txt +19 -0
index a12f4e4..407556f 100644
@@ -1740,6 +1740,25 @@ registers, find a list below:
    PPC   | KVM_REG_PPC_IAC4      | 64
    PPC   | KVM_REG_PPC_DAC1      | 64
    PPC   | KVM_REG_PPC_DAC2      | 64
+  PPC   | KVM_REG_PPC_DABR      | 64
+  PPC   | KVM_REG_PPC_DSCR      | 64
+  PPC   | KVM_REG_PPC_PURR      | 64
+  PPC   | KVM_REG_PPC_SPURR     | 64
+  PPC   | KVM_REG_PPC_DAR       | 64
+  PPC   | KVM_REG_PPC_DSISR	| 32
+  PPC   | KVM_REG_PPC_AMR       | 64
+  PPC   | KVM_REG_PPC_UAMOR     | 64
+  PPC   | KVM_REG_PPC_MMCR0     | 64
+  PPC   | KVM_REG_PPC_MMCR1     | 64
+  PPC   | KVM_REG_PPC_MMCRA     | 64
+  PPC   | KVM_REG_PPC_PMC1      | 32
+  PPC   | KVM_REG_PPC_PMC2      | 32
+  PPC   | KVM_REG_PPC_PMC3      | 32
+  PPC   | KVM_REG_PPC_PMC4      | 32
+  PPC   | KVM_REG_PPC_PMC5      | 32
+  PPC   | KVM_REG_PPC_PMC6      | 32
+  PPC   | KVM_REG_PPC_PMC7      | 32
+  PPC   | KVM_REG_PPC_PMC8      | 32
 
  4.69 KVM_GET_ONE_REG
 
arch/powerpc/include/asm/kvm.h +21 -0
index 3c14202..9557576 100644
@@ -338,5 +338,26 @@ struct kvm_book3e_206_tlb_params {
  #define KVM_REG_PPC_IAC4	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x5)
  #define KVM_REG_PPC_DAC1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x6)
  #define KVM_REG_PPC_DAC2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x7)
+#define KVM_REG_PPC_DABR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8)
+#define KVM_REG_PPC_DSCR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x9)
+#define KVM_REG_PPC_PURR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa)
+#define KVM_REG_PPC_SPURR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb)
+#define KVM_REG_PPC_DAR		(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc)
+#define KVM_REG_PPC_DSISR	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xd)
+#define KVM_REG_PPC_AMR		(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xe)
+#define KVM_REG_PPC_UAMOR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xf)
+
+#define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
+#define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+
+#define KVM_REG_PPC_PMC1	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x18)
+#define KVM_REG_PPC_PMC2	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x19)
+#define KVM_REG_PPC_PMC3	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1a)
+#define KVM_REG_PPC_PMC4	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1b)
+#define KVM_REG_PPC_PMC5	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1c)
+#define KVM_REG_PPC_PMC6	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1d)
+#define KVM_REG_PPC_PMC7	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1e)
+#define KVM_REG_PPC_PMC8	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1f)
 
  #endif /* __LINUX_KVM_POWERPC_H */
arch/powerpc/kvm/book3s_hv.c +3 -0
index 38c7f1b..c4b5636 100644
@@ -547,11 +547,44 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
  int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
  {
  	int r = -EINVAL;
+	long int i;
 
  	switch (reg->id) {
  	case KVM_REG_PPC_HIOR:
  		r = put_user(0, (u64 __user *)reg->addr);
  		break;
+	case KVM_REG_PPC_DABR:
+		r = put_user(vcpu->arch.dabr, (u64 __user *)reg->addr);

arch/powerpc/kvm/book3s_hv.c int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, · line 567

Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +10 -0
+		break;
+	case KVM_REG_PPC_DSCR:
+		r = put_user(vcpu->arch.dscr, (u64 __user *)reg->addr);
+		break;
+	case KVM_REG_PPC_PURR:
+		r = put_user(vcpu->arch.purr, (u64 __user *)reg->addr);
+		break;
+	case KVM_REG_PPC_SPURR:
+		r = put_user(vcpu->arch.spurr, (u64 __user *)reg->addr);
+		break;

Could you please merge the registers that you share with book3s pr into shared code?

Alex

#3 lore raw

Re: [PATCH v2 1/2] KVM: PPC: Book3S HV: Get/set guest SPRs using the GET/SET_ONE_REG interface

Quoted 2 lines · Alexander Graf

Could you please merge the registers that you share with book3s pr into shared code?

OK - that's just DAR and DSISR for this patch, isn't it? And basically all of the FP/VMX/VSX regs in the second patch? (Does VSX work in PR KVM?)

Paul.

#4 lore raw

Re: [PATCH v2 1/2] KVM: PPC: Book3S HV: Get/set guest SPRs using the GET/SET_ONE_REG interface

Quoted 5 lines · Paul Mackerras
Quoted 2 lines · Alexander Graf

Could you please merge the registers that you share with book3s pr into shared code?

OK - that's just DAR and DSISR for this patch, isn't it?

Unfortunately yes. Basically all of the registers should be accessible from the PR side as well. But that's nothing you need to worry about now.

Quoted 2 lines

And basically all of the FP/VMX/VSX regs in the second patch? (Does VSX work in PR KVM?)

VSX should work in PR KVM, yes.

Alex

#5 lore raw

Re: [PATCH v2 1/2] KVM: PPC: Book3S HV: Get/set guest SPRs using the GET/SET_ONE_REG interface

In reply to Paul Mackerras
Quoted 7 lines · Paul Mackerras
Quoted 2 lines · Alexander Graf

Could you please merge the registers that you share with book3s pr into shared code?

OK - that's just DAR and DSISR for this patch, isn't it? And basically all of the FP/VMX/VSX regs in the second patch? (Does VSX work in PR KVM?)

Can the FP reg code be shared with booke as well?

-Scott

#6 lore raw

Re: [PATCH v2 1/2] KVM: PPC: Book3S HV: Get/set guest SPRs using the GET/SET_ONE_REG interface

Quoted 9 lines · Scott Wood
Quoted 6 lines · Paul Mackerras
Quoted 2 lines · Alexander Graf

Could you please merge the registers that you share with book3s pr into shared code?

OK - that's just DAR and DSISR for this patch, isn't it? And basically all of the FP/VMX/VSX regs in the second patch? (Does VSX work in PR KVM?)

Can the FP reg code be shared with booke as well?

For real FP they should, yes. And if the register representations in vcpu->arch don't look the same today, we better make them look identical :).

Alex

Quoted 2 lines

-Scott