linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes
@ 2024-06-05 13:06 Shivaprasad G Bhat
  2024-06-05 13:06 ` [PATCH v2 1/8] KVM: PPC: Book3S HV: Fix the set_one_reg for MMCR3 Shivaprasad G Bhat
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Shivaprasad G Bhat @ 2024-06-05 13:06 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, sbhat, corbet, linux-kernel, npiggin, namhyung,
	naveen.n.rao, pbonzini, jniethe5

The series fixes the issues exposed by the kvm-unit-tests[1]
sprs-migration test.

The SDAR, MMCR3 were seen to have some typo/refactoring bugs.
The first two patches fix them.

The remaining patches take care of save-restoring the guest
state elements for DEXCR, HASHKEYR and HASHPKEYR SPRs with PHYP
during entry-exit. The KVM_PPC_REG too for them are missing which
are added for use by the QEMU.

References:
[1]: https://github.com/kvm-unit-tests/kvm-unit-tests

---

Changelog:
v1: https://lore.kernel.org/kvm/171741555734.11675.17428208097186191736.stgit@c0c876608f2d/
 - Reordered the patches in a way to introduce the SPRs first as
   suggested.
 - Added Reviewed-bys to the reviewed ones.
 - Added 2 more patches to handle the hashpkeyr state

Shivaprasad G Bhat (8):
      KVM: PPC: Book3S HV: Fix the set_one_reg for MMCR3
      KVM: PPC: Book3S HV: Fix the get_one_reg of SDAR
      KVM: PPC: Book3S HV: Add one-reg interface for DEXCR register
      KVM: PPC: Book3S HV nestedv2: Keep nested guest DEXCR in sync
      KVM: PPC: Book3S HV: Add one-reg interface for HASHKEYR register
      KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHKEYR in sync
      KVM: PPC: Book3S HV: Add one-reg interface for HASHPKEYR register
      KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHPKEYR in sync


 Documentation/virt/kvm/api.rst        |  3 +++
 arch/powerpc/include/asm/kvm_host.h   |  3 +++
 arch/powerpc/include/uapi/asm/kvm.h   |  3 +++
 arch/powerpc/kvm/book3s_hv.c          | 22 ++++++++++++++++++++--
 arch/powerpc/kvm/book3s_hv.h          |  3 +++
 arch/powerpc/kvm/book3s_hv_nestedv2.c | 18 ++++++++++++++++++
 6 files changed, 50 insertions(+), 2 deletions(-)

--
Signature


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

* [PATCH v2 1/8] KVM: PPC: Book3S HV: Fix the set_one_reg for MMCR3
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
@ 2024-06-05 13:06 ` Shivaprasad G Bhat
  2024-06-05 13:06 ` [PATCH v2 2/8] KVM: PPC: Book3S HV: Fix the get_one_reg of SDAR Shivaprasad G Bhat
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Shivaprasad G Bhat @ 2024-06-05 13:06 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, sbhat, corbet, linux-kernel, npiggin, namhyung,
	naveen.n.rao, pbonzini, jniethe5

The kvmppc_set_one_reg_hv() wrongly get() the value
instead of set() for MMCR3. Fix the same.

Fixes: 5752fe0b811b ("KVM: PPC: Book3S HV: Save/restore new PMU registers")
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kvm/book3s_hv.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index daaf7faf21a5..a4f34f94c86f 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2540,7 +2540,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 		vcpu->arch.mmcrs = set_reg_val(id, *val);
 		break;
 	case KVM_REG_PPC_MMCR3:
-		*val = get_reg_val(id, vcpu->arch.mmcr[3]);
+		kvmppc_set_mmcr_hv(vcpu, 3, set_reg_val(id, *val));
 		break;
 	case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8:
 		i = id - KVM_REG_PPC_PMC1;



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

* [PATCH v2 2/8] KVM: PPC: Book3S HV: Fix the get_one_reg of SDAR
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
  2024-06-05 13:06 ` [PATCH v2 1/8] KVM: PPC: Book3S HV: Fix the set_one_reg for MMCR3 Shivaprasad G Bhat
@ 2024-06-05 13:06 ` Shivaprasad G Bhat
  2024-06-05 13:06 ` [PATCH v2 3/8] KVM: PPC: Book3S HV: Add one-reg interface for DEXCR register Shivaprasad G Bhat
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Shivaprasad G Bhat @ 2024-06-05 13:06 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, sbhat, corbet, linux-kernel, npiggin, namhyung,
	naveen.n.rao, pbonzini, jniethe5

The kvmppc_get_one_reg_hv() for SDAR is wrongly getting the SIAR
instead of SDAR, possibly a paste error emanating from the previous
refactoring.

Patch fixes the wrong get_one_reg() for the same.

Fixes: ebc88ea7a6ad ("KVM: PPC: Book3S HV: Use accessors for VCPU registers")
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kvm/book3s_hv.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index a4f34f94c86f..b576781d58d5 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2305,7 +2305,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 		*val = get_reg_val(id, kvmppc_get_siar_hv(vcpu));
 		break;
 	case KVM_REG_PPC_SDAR:
-		*val = get_reg_val(id, kvmppc_get_siar_hv(vcpu));
+		*val = get_reg_val(id, kvmppc_get_sdar_hv(vcpu));
 		break;
 	case KVM_REG_PPC_SIER:
 		*val = get_reg_val(id, kvmppc_get_sier_hv(vcpu, 0));



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

* [PATCH v2 3/8] KVM: PPC: Book3S HV: Add one-reg interface for DEXCR register
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
  2024-06-05 13:06 ` [PATCH v2 1/8] KVM: PPC: Book3S HV: Fix the set_one_reg for MMCR3 Shivaprasad G Bhat
  2024-06-05 13:06 ` [PATCH v2 2/8] KVM: PPC: Book3S HV: Fix the get_one_reg of SDAR Shivaprasad G Bhat
@ 2024-06-05 13:06 ` Shivaprasad G Bhat
  2024-06-05 13:07 ` [PATCH v2 4/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest DEXCR in sync Shivaprasad G Bhat
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Shivaprasad G Bhat @ 2024-06-05 13:06 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, sbhat, corbet, linux-kernel, npiggin, namhyung,
	naveen.n.rao, pbonzini, jniethe5

The patch adds a one-reg register identifier which can be used to
read and set the DEXCR for the guest during enter/exit with
KVM_REG_PPC_DEXCR. The specific SPR KVM API documentation
too updated.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
 Documentation/virt/kvm/api.rst      |    1 +
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/powerpc/include/uapi/asm/kvm.h |    1 +
 arch/powerpc/kvm/book3s_hv.c        |    6 ++++++
 arch/powerpc/kvm/book3s_hv.h        |    1 +
 5 files changed, 10 insertions(+)

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index a71d91978d9e..81077c654281 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -2441,6 +2441,7 @@ registers, find a list below:
   PPC     KVM_REG_PPC_PTCR                64
   PPC     KVM_REG_PPC_DAWR1               64
   PPC     KVM_REG_PPC_DAWRX1              64
+  PPC     KVM_REG_PPC_DEXCR               64
   PPC     KVM_REG_PPC_TM_GPR0             64
   ...
   PPC     KVM_REG_PPC_TM_GPR31            64
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 8abac532146e..1e2fdcbecffd 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -599,6 +599,7 @@ struct kvm_vcpu_arch {
 	ulong dawrx0;
 	ulong dawr1;
 	ulong dawrx1;
+	ulong dexcr;
 	ulong ciabr;
 	ulong cfar;
 	ulong ppr;
diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h
index 1691297a766a..fcb947f65667 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -645,6 +645,7 @@ struct kvm_ppc_cpu_char {
 #define KVM_REG_PPC_SIER3	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc3)
 #define KVM_REG_PPC_DAWR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc4)
 #define KVM_REG_PPC_DAWRX1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc5)
+#define KVM_REG_PPC_DEXCR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc6)
 
 /* Transactional Memory checkpointed state:
  * This is all GPRs, all VSX regs and a subset of SPRs
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index b576781d58d5..1294c6839d37 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2349,6 +2349,9 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_DAWRX1:
 		*val = get_reg_val(id, kvmppc_get_dawrx1_hv(vcpu));
 		break;
+	case KVM_REG_PPC_DEXCR:
+		*val = get_reg_val(id, kvmppc_get_dexcr_hv(vcpu));
+		break;
 	case KVM_REG_PPC_CIABR:
 		*val = get_reg_val(id, kvmppc_get_ciabr_hv(vcpu));
 		break;
@@ -2592,6 +2595,9 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_DAWRX1:
 		kvmppc_set_dawrx1_hv(vcpu, set_reg_val(id, *val) & ~DAWRX_HYP);
 		break;
+	case KVM_REG_PPC_DEXCR:
+		kvmppc_set_dexcr_hv(vcpu, set_reg_val(id, *val));
+		break;
 	case KVM_REG_PPC_CIABR:
 		kvmppc_set_ciabr_hv(vcpu, set_reg_val(id, *val));
 		/* Don't allow setting breakpoints in hypervisor code */
diff --git a/arch/powerpc/kvm/book3s_hv.h b/arch/powerpc/kvm/book3s_hv.h
index 47b2c815641e..7b0fd282fe95 100644
--- a/arch/powerpc/kvm/book3s_hv.h
+++ b/arch/powerpc/kvm/book3s_hv.h
@@ -116,6 +116,7 @@ KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawr0, 64, KVMPPC_GSID_DAWR0)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawr1, 64, KVMPPC_GSID_DAWR1)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx0, 64, KVMPPC_GSID_DAWRX0)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx1, 64, KVMPPC_GSID_DAWRX1)
+KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dexcr, 64, KVMPPC_GSID_DEXCR)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ciabr, 64, KVMPPC_GSID_CIABR)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(wort, 64, KVMPPC_GSID_WORT)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ppr, 64, KVMPPC_GSID_PPR)



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

* [PATCH v2 4/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest DEXCR in sync
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
                   ` (2 preceding siblings ...)
  2024-06-05 13:06 ` [PATCH v2 3/8] KVM: PPC: Book3S HV: Add one-reg interface for DEXCR register Shivaprasad G Bhat
@ 2024-06-05 13:07 ` Shivaprasad G Bhat
  2024-06-05 13:07 ` [PATCH v2 5/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHKEYR register Shivaprasad G Bhat
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Shivaprasad G Bhat @ 2024-06-05 13:07 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, sbhat, corbet, linux-kernel, npiggin, namhyung,
	naveen.n.rao, pbonzini, jniethe5

The nestedv2 APIs has the guest state element defined for DEXCR
for the save-restore with L0. However, its ignored in the code.

The patch takes care of this for the DEXCR GSID.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kvm/book3s_hv_nestedv2.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/kvm/book3s_hv_nestedv2.c b/arch/powerpc/kvm/book3s_hv_nestedv2.c
index 1091f7a83b25..d207a6d936ff 100644
--- a/arch/powerpc/kvm/book3s_hv_nestedv2.c
+++ b/arch/powerpc/kvm/book3s_hv_nestedv2.c
@@ -193,6 +193,9 @@ static int gs_msg_ops_vcpu_fill_info(struct kvmppc_gs_buff *gsb,
 		case KVMPPC_GSID_DAWRX1:
 			rc = kvmppc_gse_put_u32(gsb, iden, vcpu->arch.dawrx1);
 			break;
+		case KVMPPC_GSID_DEXCR:
+			rc = kvmppc_gse_put_u64(gsb, iden, vcpu->arch.dexcr);
+			break;
 		case KVMPPC_GSID_CIABR:
 			rc = kvmppc_gse_put_u64(gsb, iden, vcpu->arch.ciabr);
 			break;
@@ -441,6 +444,9 @@ static int gs_msg_ops_vcpu_refresh_info(struct kvmppc_gs_msg *gsm,
 		case KVMPPC_GSID_DAWRX1:
 			vcpu->arch.dawrx1 = kvmppc_gse_get_u32(gse);
 			break;
+		case KVMPPC_GSID_DEXCR:
+			vcpu->arch.dexcr = kvmppc_gse_get_u64(gse);
+			break;
 		case KVMPPC_GSID_CIABR:
 			vcpu->arch.ciabr = kvmppc_gse_get_u64(gse);
 			break;



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

* [PATCH v2 5/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHKEYR register
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
                   ` (3 preceding siblings ...)
  2024-06-05 13:07 ` [PATCH v2 4/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest DEXCR in sync Shivaprasad G Bhat
@ 2024-06-05 13:07 ` Shivaprasad G Bhat
  2024-06-05 13:07 ` [PATCH v2 6/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHKEYR in sync Shivaprasad G Bhat
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Shivaprasad G Bhat @ 2024-06-05 13:07 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, sbhat, corbet, linux-kernel, npiggin, namhyung,
	naveen.n.rao, pbonzini, jniethe5

The patch adds a one-reg register identifier which can be used to
read and set the virtual HASHKEYR for the guest during enter/exit
with KVM_REG_PPC_HASHKEYR. The specific SPR KVM API documentation
too updated.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
 Documentation/virt/kvm/api.rst      |    1 +
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/powerpc/include/uapi/asm/kvm.h |    1 +
 arch/powerpc/kvm/book3s_hv.c        |    6 ++++++
 arch/powerpc/kvm/book3s_hv.h        |    1 +
 5 files changed, 10 insertions(+)

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 81077c654281..0c22cb4196d8 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -2439,6 +2439,7 @@ registers, find a list below:
   PPC     KVM_REG_PPC_PSSCR               64
   PPC     KVM_REG_PPC_DEC_EXPIRY          64
   PPC     KVM_REG_PPC_PTCR                64
+  PPC     KVM_REG_PPC_HASHKEYR            64
   PPC     KVM_REG_PPC_DAWR1               64
   PPC     KVM_REG_PPC_DAWRX1              64
   PPC     KVM_REG_PPC_DEXCR               64
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 1e2fdcbecffd..a0cd9dbf534f 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -600,6 +600,7 @@ struct kvm_vcpu_arch {
 	ulong dawr1;
 	ulong dawrx1;
 	ulong dexcr;
+	ulong hashkeyr;
 	ulong ciabr;
 	ulong cfar;
 	ulong ppr;
diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h
index fcb947f65667..23a0af739c78 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -646,6 +646,7 @@ struct kvm_ppc_cpu_char {
 #define KVM_REG_PPC_DAWR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc4)
 #define KVM_REG_PPC_DAWRX1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc5)
 #define KVM_REG_PPC_DEXCR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc6)
+#define KVM_REG_PPC_HASHKEYR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc7)
 
 /* Transactional Memory checkpointed state:
  * This is all GPRs, all VSX regs and a subset of SPRs
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 1294c6839d37..ccc9564c5a31 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2352,6 +2352,9 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_DEXCR:
 		*val = get_reg_val(id, kvmppc_get_dexcr_hv(vcpu));
 		break;
+	case KVM_REG_PPC_HASHKEYR:
+		*val = get_reg_val(id, kvmppc_get_hashkeyr_hv(vcpu));
+		break;
 	case KVM_REG_PPC_CIABR:
 		*val = get_reg_val(id, kvmppc_get_ciabr_hv(vcpu));
 		break;
@@ -2598,6 +2601,9 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_DEXCR:
 		kvmppc_set_dexcr_hv(vcpu, set_reg_val(id, *val));
 		break;
+	case KVM_REG_PPC_HASHKEYR:
+		kvmppc_set_hashkeyr_hv(vcpu, set_reg_val(id, *val));
+		break;
 	case KVM_REG_PPC_CIABR:
 		kvmppc_set_ciabr_hv(vcpu, set_reg_val(id, *val));
 		/* Don't allow setting breakpoints in hypervisor code */
diff --git a/arch/powerpc/kvm/book3s_hv.h b/arch/powerpc/kvm/book3s_hv.h
index 7b0fd282fe95..c073fdfa7dc4 100644
--- a/arch/powerpc/kvm/book3s_hv.h
+++ b/arch/powerpc/kvm/book3s_hv.h
@@ -117,6 +117,7 @@ KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawr1, 64, KVMPPC_GSID_DAWR1)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx0, 64, KVMPPC_GSID_DAWRX0)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx1, 64, KVMPPC_GSID_DAWRX1)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dexcr, 64, KVMPPC_GSID_DEXCR)
+KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(hashkeyr, 64, KVMPPC_GSID_HASHKEYR)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ciabr, 64, KVMPPC_GSID_CIABR)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(wort, 64, KVMPPC_GSID_WORT)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ppr, 64, KVMPPC_GSID_PPR)



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

* [PATCH v2 6/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHKEYR in sync
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
                   ` (4 preceding siblings ...)
  2024-06-05 13:07 ` [PATCH v2 5/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHKEYR register Shivaprasad G Bhat
@ 2024-06-05 13:07 ` Shivaprasad G Bhat
  2024-06-05 13:07 ` [PATCH v2 7/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHPKEYR register Shivaprasad G Bhat
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Shivaprasad G Bhat @ 2024-06-05 13:07 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, sbhat, corbet, linux-kernel, npiggin, namhyung,
	naveen.n.rao, pbonzini, jniethe5

The nestedv2 APIs has the guest state element defined for HASHKEYR for
the save-restore with L0. However, its ignored in the code.

The patch takes care of this for the HASHKEYR GSID.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kvm/book3s_hv_nestedv2.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/kvm/book3s_hv_nestedv2.c b/arch/powerpc/kvm/book3s_hv_nestedv2.c
index d207a6d936ff..bbff933f2ccc 100644
--- a/arch/powerpc/kvm/book3s_hv_nestedv2.c
+++ b/arch/powerpc/kvm/book3s_hv_nestedv2.c
@@ -196,6 +196,9 @@ static int gs_msg_ops_vcpu_fill_info(struct kvmppc_gs_buff *gsb,
 		case KVMPPC_GSID_DEXCR:
 			rc = kvmppc_gse_put_u64(gsb, iden, vcpu->arch.dexcr);
 			break;
+		case KVMPPC_GSID_HASHKEYR:
+			rc = kvmppc_gse_put_u64(gsb, iden, vcpu->arch.hashkeyr);
+			break;
 		case KVMPPC_GSID_CIABR:
 			rc = kvmppc_gse_put_u64(gsb, iden, vcpu->arch.ciabr);
 			break;
@@ -447,6 +450,9 @@ static int gs_msg_ops_vcpu_refresh_info(struct kvmppc_gs_msg *gsm,
 		case KVMPPC_GSID_DEXCR:
 			vcpu->arch.dexcr = kvmppc_gse_get_u64(gse);
 			break;
+		case KVMPPC_GSID_HASHKEYR:
+			vcpu->arch.hashkeyr = kvmppc_gse_get_u64(gse);
+			break;
 		case KVMPPC_GSID_CIABR:
 			vcpu->arch.ciabr = kvmppc_gse_get_u64(gse);
 			break;



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

* [PATCH v2 7/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHPKEYR register
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
                   ` (5 preceding siblings ...)
  2024-06-05 13:07 ` [PATCH v2 6/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHKEYR in sync Shivaprasad G Bhat
@ 2024-06-05 13:07 ` Shivaprasad G Bhat
  2024-06-05 13:07 ` [PATCH v2 8/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHPKEYR in sync Shivaprasad G Bhat
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Shivaprasad G Bhat @ 2024-06-05 13:07 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, sbhat, corbet, linux-kernel, npiggin, namhyung,
	naveen.n.rao, pbonzini, jniethe5

The patch adds a one-reg register identifier which can be used to
read and set the virtual HASHPKEYR for the guest during enter/exit
with KVM_REG_PPC_HASHPKEYR. The specific SPR KVM API documentation
too updated.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
---
 Documentation/virt/kvm/api.rst      |    1 +
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/powerpc/include/uapi/asm/kvm.h |    1 +
 arch/powerpc/kvm/book3s_hv.c        |    6 ++++++
 arch/powerpc/kvm/book3s_hv.h        |    1 +
 5 files changed, 10 insertions(+)

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 0c22cb4196d8..899480d4acaf 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -2440,6 +2440,7 @@ registers, find a list below:
   PPC     KVM_REG_PPC_DEC_EXPIRY          64
   PPC     KVM_REG_PPC_PTCR                64
   PPC     KVM_REG_PPC_HASHKEYR            64
+  PPC     KVM_REG_PPC_HASHPKEYR           64
   PPC     KVM_REG_PPC_DAWR1               64
   PPC     KVM_REG_PPC_DAWRX1              64
   PPC     KVM_REG_PPC_DEXCR               64
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index a0cd9dbf534f..6a0c771d3ce8 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -601,6 +601,7 @@ struct kvm_vcpu_arch {
 	ulong dawrx1;
 	ulong dexcr;
 	ulong hashkeyr;
+	ulong hashpkeyr;
 	ulong ciabr;
 	ulong cfar;
 	ulong ppr;
diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h
index 23a0af739c78..eaeda001784e 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -647,6 +647,7 @@ struct kvm_ppc_cpu_char {
 #define KVM_REG_PPC_DAWRX1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc5)
 #define KVM_REG_PPC_DEXCR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc6)
 #define KVM_REG_PPC_HASHKEYR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc7)
+#define KVM_REG_PPC_HASHPKEYR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc8)
 
 /* Transactional Memory checkpointed state:
  * This is all GPRs, all VSX regs and a subset of SPRs
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index ccc9564c5a31..bf05b63b0e20 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2355,6 +2355,9 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_HASHKEYR:
 		*val = get_reg_val(id, kvmppc_get_hashkeyr_hv(vcpu));
 		break;
+	case KVM_REG_PPC_HASHPKEYR:
+		*val = get_reg_val(id, kvmppc_get_hashpkeyr_hv(vcpu));
+		break;
 	case KVM_REG_PPC_CIABR:
 		*val = get_reg_val(id, kvmppc_get_ciabr_hv(vcpu));
 		break;
@@ -2604,6 +2607,9 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_HASHKEYR:
 		kvmppc_set_hashkeyr_hv(vcpu, set_reg_val(id, *val));
 		break;
+	case KVM_REG_PPC_HASHPKEYR:
+		kvmppc_set_hashpkeyr_hv(vcpu, set_reg_val(id, *val));
+		break;
 	case KVM_REG_PPC_CIABR:
 		kvmppc_set_ciabr_hv(vcpu, set_reg_val(id, *val));
 		/* Don't allow setting breakpoints in hypervisor code */
diff --git a/arch/powerpc/kvm/book3s_hv.h b/arch/powerpc/kvm/book3s_hv.h
index c073fdfa7dc4..a404c9b221c1 100644
--- a/arch/powerpc/kvm/book3s_hv.h
+++ b/arch/powerpc/kvm/book3s_hv.h
@@ -118,6 +118,7 @@ KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx0, 64, KVMPPC_GSID_DAWRX0)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx1, 64, KVMPPC_GSID_DAWRX1)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dexcr, 64, KVMPPC_GSID_DEXCR)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(hashkeyr, 64, KVMPPC_GSID_HASHKEYR)
+KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(hashpkeyr, 64, KVMPPC_GSID_HASHPKEYR)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ciabr, 64, KVMPPC_GSID_CIABR)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(wort, 64, KVMPPC_GSID_WORT)
 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ppr, 64, KVMPPC_GSID_PPR)



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

* [PATCH v2 8/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHPKEYR in sync
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
                   ` (6 preceding siblings ...)
  2024-06-05 13:07 ` [PATCH v2 7/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHPKEYR register Shivaprasad G Bhat
@ 2024-06-05 13:07 ` Shivaprasad G Bhat
  2024-06-06  3:06 ` [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Nicholas Piggin
  2024-06-20 14:29 ` Michael Ellerman
  9 siblings, 0 replies; 11+ messages in thread
From: Shivaprasad G Bhat @ 2024-06-05 13:07 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, sbhat, corbet, linux-kernel, npiggin, namhyung,
	naveen.n.rao, pbonzini, jniethe5

The nestedv2 APIs has the guest state element defined for HASHPKEYR
for the save-restore with L0. However, its ignored in the code.

The patch takes care of this for the HASHPKEYR GSID.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
---
 arch/powerpc/kvm/book3s_hv_nestedv2.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/kvm/book3s_hv_nestedv2.c b/arch/powerpc/kvm/book3s_hv_nestedv2.c
index bbff933f2ccc..ce61cb6fc9b9 100644
--- a/arch/powerpc/kvm/book3s_hv_nestedv2.c
+++ b/arch/powerpc/kvm/book3s_hv_nestedv2.c
@@ -199,6 +199,9 @@ static int gs_msg_ops_vcpu_fill_info(struct kvmppc_gs_buff *gsb,
 		case KVMPPC_GSID_HASHKEYR:
 			rc = kvmppc_gse_put_u64(gsb, iden, vcpu->arch.hashkeyr);
 			break;
+		case KVMPPC_GSID_HASHPKEYR:
+			rc = kvmppc_gse_put_u64(gsb, iden, vcpu->arch.hashpkeyr);
+			break;
 		case KVMPPC_GSID_CIABR:
 			rc = kvmppc_gse_put_u64(gsb, iden, vcpu->arch.ciabr);
 			break;
@@ -453,6 +456,9 @@ static int gs_msg_ops_vcpu_refresh_info(struct kvmppc_gs_msg *gsm,
 		case KVMPPC_GSID_HASHKEYR:
 			vcpu->arch.hashkeyr = kvmppc_gse_get_u64(gse);
 			break;
+		case KVMPPC_GSID_HASHPKEYR:
+			vcpu->arch.hashpkeyr = kvmppc_gse_get_u64(gse);
+			break;
 		case KVMPPC_GSID_CIABR:
 			vcpu->arch.ciabr = kvmppc_gse_get_u64(gse);
 			break;



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

* Re: [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
                   ` (7 preceding siblings ...)
  2024-06-05 13:07 ` [PATCH v2 8/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHPKEYR in sync Shivaprasad G Bhat
@ 2024-06-06  3:06 ` Nicholas Piggin
  2024-06-20 14:29 ` Michael Ellerman
  9 siblings, 0 replies; 11+ messages in thread
From: Nicholas Piggin @ 2024-06-06  3:06 UTC (permalink / raw)
  To: Shivaprasad G Bhat, kvm, linux-doc, linuxppc-dev
  Cc: atrajeev, corbet, linux-kernel, namhyung, naveen.n.rao, pbonzini,
	jniethe5

On Wed Jun 5, 2024 at 11:06 PM AEST, Shivaprasad G Bhat wrote:
> The series fixes the issues exposed by the kvm-unit-tests[1]
> sprs-migration test.
>
> The SDAR, MMCR3 were seen to have some typo/refactoring bugs.
> The first two patches fix them.
>
> The remaining patches take care of save-restoring the guest
> state elements for DEXCR, HASHKEYR and HASHPKEYR SPRs with PHYP
> during entry-exit. The KVM_PPC_REG too for them are missing which
> are added for use by the QEMU.

These and the qemu patches all look good now. I'll give them
some testing and send R-B in the next day or two. I'm trying
to write a k-u-t for the hashpkey migration case...

Thanks,
Nick

>
> References:
> [1]: https://github.com/kvm-unit-tests/kvm-unit-tests
>
> ---
>
> Changelog:
> v1: https://lore.kernel.org/kvm/171741555734.11675.17428208097186191736.stgit@c0c876608f2d/
>  - Reordered the patches in a way to introduce the SPRs first as
>    suggested.
>  - Added Reviewed-bys to the reviewed ones.
>  - Added 2 more patches to handle the hashpkeyr state
>
> Shivaprasad G Bhat (8):
>       KVM: PPC: Book3S HV: Fix the set_one_reg for MMCR3
>       KVM: PPC: Book3S HV: Fix the get_one_reg of SDAR
>       KVM: PPC: Book3S HV: Add one-reg interface for DEXCR register
>       KVM: PPC: Book3S HV nestedv2: Keep nested guest DEXCR in sync
>       KVM: PPC: Book3S HV: Add one-reg interface for HASHKEYR register
>       KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHKEYR in sync
>       KVM: PPC: Book3S HV: Add one-reg interface for HASHPKEYR register
>       KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHPKEYR in sync
>
>
>  Documentation/virt/kvm/api.rst        |  3 +++
>  arch/powerpc/include/asm/kvm_host.h   |  3 +++
>  arch/powerpc/include/uapi/asm/kvm.h   |  3 +++
>  arch/powerpc/kvm/book3s_hv.c          | 22 ++++++++++++++++++++--
>  arch/powerpc/kvm/book3s_hv.h          |  3 +++
>  arch/powerpc/kvm/book3s_hv_nestedv2.c | 18 ++++++++++++++++++
>  6 files changed, 50 insertions(+), 2 deletions(-)
>
> --
> Signature


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

* Re: [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes
  2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
                   ` (8 preceding siblings ...)
  2024-06-06  3:06 ` [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Nicholas Piggin
@ 2024-06-20 14:29 ` Michael Ellerman
  9 siblings, 0 replies; 11+ messages in thread
From: Michael Ellerman @ 2024-06-20 14:29 UTC (permalink / raw)
  To: kvm, linux-doc, linuxppc-dev, Shivaprasad G Bhat
  Cc: corbet, atrajeev, linux-kernel, christophe.leroy, npiggin,
	namhyung, naveen.n.rao, pbonzini, jniethe5

On Wed, 05 Jun 2024 13:06:00 +0000, Shivaprasad G Bhat wrote:
> The series fixes the issues exposed by the kvm-unit-tests[1]
> sprs-migration test.
> 
> The SDAR, MMCR3 were seen to have some typo/refactoring bugs.
> The first two patches fix them.
> 
> The remaining patches take care of save-restoring the guest
> state elements for DEXCR, HASHKEYR and HASHPKEYR SPRs with PHYP
> during entry-exit. The KVM_PPC_REG too for them are missing which
> are added for use by the QEMU.
> 
> [...]

Applied to powerpc/topic/ppc-kvm.

[1/8] KVM: PPC: Book3S HV: Fix the set_one_reg for MMCR3
      https://git.kernel.org/powerpc/c/f9ca6a10be20479d526f27316cc32cfd1785ed39
[2/8] KVM: PPC: Book3S HV: Fix the get_one_reg of SDAR
      https://git.kernel.org/powerpc/c/009f6f42c67e9de737d6d3d199f92b21a8cb9622
[3/8] KVM: PPC: Book3S HV: Add one-reg interface for DEXCR register
      https://git.kernel.org/powerpc/c/1a1e6865f516696adcf6e94f286c7a0f84d78df3
[4/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest DEXCR in sync
      https://git.kernel.org/powerpc/c/2d6be3ca3276ab30fb14f285d400461a718d45e7
[5/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHKEYR register
      https://git.kernel.org/powerpc/c/e9eb790b25577a15d3f450ed585c59048e4e6c44
[6/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHKEYR in sync
      https://git.kernel.org/powerpc/c/1e97c1eb785fe2dc863c2bd570030d6fcf4b5e5b
[7/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHPKEYR register
      https://git.kernel.org/powerpc/c/9a0d2f4995ddde3022c54e43f9ece4f71f76f6e8
[8/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHPKEYR in sync
      https://git.kernel.org/powerpc/c/0b65365f3fa95c2c5e2094739151a05cabb3c48a

cheers

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

end of thread, other threads:[~2024-06-20 14:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-05 13:06 [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Shivaprasad G Bhat
2024-06-05 13:06 ` [PATCH v2 1/8] KVM: PPC: Book3S HV: Fix the set_one_reg for MMCR3 Shivaprasad G Bhat
2024-06-05 13:06 ` [PATCH v2 2/8] KVM: PPC: Book3S HV: Fix the get_one_reg of SDAR Shivaprasad G Bhat
2024-06-05 13:06 ` [PATCH v2 3/8] KVM: PPC: Book3S HV: Add one-reg interface for DEXCR register Shivaprasad G Bhat
2024-06-05 13:07 ` [PATCH v2 4/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest DEXCR in sync Shivaprasad G Bhat
2024-06-05 13:07 ` [PATCH v2 5/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHKEYR register Shivaprasad G Bhat
2024-06-05 13:07 ` [PATCH v2 6/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHKEYR in sync Shivaprasad G Bhat
2024-06-05 13:07 ` [PATCH v2 7/8] KVM: PPC: Book3S HV: Add one-reg interface for HASHPKEYR register Shivaprasad G Bhat
2024-06-05 13:07 ` [PATCH v2 8/8] KVM: PPC: Book3S HV nestedv2: Keep nested guest HASHPKEYR in sync Shivaprasad G Bhat
2024-06-06  3:06 ` [PATCH v2 0/8] KVM: PPC: Book3S HV: Nested guest migration fixes Nicholas Piggin
2024-06-20 14:29 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).