KVM: PPC: Nested APIv2 : Performance improvements
Subsystems (3)
cover KVM: PPC: Nested APIv2 : Performance improvements
From: vaibhav <[email protected]>
This patch series introduces series of performance improvements to recently added support for Nested APIv2 PPC64 Guests via [1]. Details for Nested APIv2 for PPC64 Guests is available in Documentation/powerpc/kvm-nested.rst.
This patch series introduces various optimizations for a Nested APIv2 guests namely:
* Reduce the number times L1 hypervisor requests for L2 state from L0.
* Register the L2 VPA with L1
* Optimizing interrupt delivery of some interrupt types.
* Optimize emulation of mmio loads/stores for L2 in L1.
The hcalls needed for testing these patches have been implemented in the spapr qemu model and is available at [2].
There are scripts available to assist in setting up an environment for testing nested guests at [3].
These patches are consequence of insights from on going performance engineering effort for improving performance of Nested APIv2 Guests. Special thanks goes to:
* Gautam Menghani
* Jordan Niethe
* Nicholas Piggin
* Vaidyanathan Srinivasan
Refs:
[1] https://lore.kernel.org/all/[email protected]
[2] https://github.com/planetharsh/qemu/tree/upstream-0714-kop
[3] https://github.com/iamjpn/kvm-powervm-test
Jordan Niethe (11):
KVM: PPC: Book3S HV nestedv2: Invalidate RPT before deleting a guest
KVM: PPC: Book3S HV nestedv2: Avoid reloading the tb offset
KVM: PPC: Book3S HV nestedv2: Do not check msr on hcalls
KVM: PPC: Book3S HV nestedv2: Get the PID only if needed to copy
tofrom a guest
KVM: PPC: Book3S HV nestedv2: Ensure LPCR_MER bit is passed to the L0
KVM: PPC: Book3S HV nestedv2: Do not inject certain interrupts
KVM: PPC: Book3S HV nestedv2: Avoid msr check in
kvmppc_handle_exit_hv()
KVM: PPC: Book3S HV nestedv2: Do not call H_COPY_TOFROM_GUEST
KVM: PPC: Book3S HV nestedv2: Register the VPA with the L0
KVM: PPC: Reduce reliance on analyse_instr() in mmio emulation
KVM: PPC: Book3S HV nestedv2: Do not cancel pending decrementer
exception
Nicholas Piggin (1):
KVM: PPC: Book3S HV: Handle pending exceptions on guest entry with
MSR_EE
arch/powerpc/include/asm/kvm_book3s.h | 10 +++- arch/powerpc/include/asm/kvm_book3s_64.h | 1 + arch/powerpc/kvm/book3s.c | 4 +- arch/powerpc/kvm/book3s_64_mmu_radix.c | 7 ++- arch/powerpc/kvm/book3s_hv.c | 72 +++++++++++++++++------- arch/powerpc/kvm/book3s_hv_nested.c | 2 +- arch/powerpc/kvm/book3s_hv_nestedv2.c | 29 ++++++++++ arch/powerpc/kvm/emulate_loadstore.c | 21 ++++--- 8 files changed, 107 insertions(+), 39 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/12 KVM: PPC: Book3S HV nestedv2: Invalidate RPT before deleting a guest
From: Jordan Niethe <[email protected]>
An L0 must invalidate the L2's RPT during H_GUEST_DELETE if this has not already been done. This is a slow operation that means H_GUEST_DELETE must return H_BUSY multiple times before completing. Invalidating the tables before deleting the guest so there is less work for the L0 to do.
--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/kvm/book3s_hv.c | 6 ++++-- arch/powerpc/kvm/book3s_hv_nested.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -0
@@ -302,6 +302,7 @@ void kvmhv_nested_exit(void);void kvmhv_vm_nested_init (struct kvm *kvm);long kvmhv_set_partition_table (struct kvm_vcpu *vcpu);long kvmhv_copy_tofrom_guest_nested (struct kvm_vcpu *vcpu); +void kvmhv_flush_lpid (u64 lpid);void kvmhv_set_ptbl_entry (u64 lpid,u64 dw0,u64 dw1);void kvmhv_release_all_nested (struct kvm *kvm);long kvmhv_enter_nested_guest (struct kvm_vcpu *vcpu);
arch/powerpc/kvm/book3s_hv.c +4 -2
@@ -5691,10 +5691,12 @@ static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)kvmhv_set_ptbl_entry (kvm->arch.lpid,0 ,0 ); } -if (kvmhv_is_nestedv2 ()) +if (kvmhv_is_nestedv2 ()) { +kvmhv_flush_lpid (kvm->arch.lpid);plpar_guest_delete (0 , kvm->arch.lpid); -else + }else {kvmppc_free_lpid (kvm->arch.lpid); + }kvmppc_free_pimap (kvm); }
arch/powerpc/kvm/book3s_hv_nested.c +1 -1
@@ -503,7 +503,7 @@ void kvmhv_nested_exit(void) } } -static void kvmhv_flush_lpid (u64 lpid) +void kvmhv_flush_lpid (u64 lpid) {long rc;
Signature · 1 line
2.42.0
Re: [PATCH 01/12] KVM: PPC: Book3S HV nestedv2: Invalidate RPT before deleting a guest
Quoted 31 lines · Vaibhav Jain
From: Jordan Niethe <[email protected]>
An L0 must invalidate the L2's RPT during
H_GUEST_DELETEif this has not already been done. This is a slow operation that meansH_GUEST_DELETEmust returnH_BUSYmultiple times before completing. Invalidating the tables before deleting the guest so there is less work for the L0 to do.Signed-off-by Jordan Niethe <[email protected]>--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/kvm/book3s_hv.c | 6 ++++-- arch/powerpc/kvm/book3s_hv_nested.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)arch/powerpc/include/asm/kvm_book3s.h +1
-0@@ -302,6 +302,7 @@ void kvmhv_nested_exit(void);void kvmhv_vm_nested_init (struct kvm *kvm);long kvmhv_set_partition_table (struct kvm_vcpu *vcpu);long kvmhv_copy_tofrom_guest_nested (struct kvm_vcpu *vcpu); +void kvmhv_flush_lpid (u64 lpid);void kvmhv_set_ptbl_entry (u64 lpid,u64 dw0,u64 dw1);void kvmhv_release_all_nested (struct kvm *kvm);long kvmhv_enter_nested_guest (struct kvm_vcpu *vcpu);arch/powerpc/kvm/book3s_hv.c +0
-0
arch/powerpc/kvm/book3s_hv.c static void kvmppc_core_destroy_vm_hv(struct kvm *kvm) · line 5697
Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c +2
-1@@ -5691,10 +5691,12 @@ static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)kvmhv_set_ptbl_entry (kvm->arch.lpid,0 ,0 ); } -if (kvmhv_is_nestedv2 ()) +if (kvmhv_is_nestedv2 ()) { +kvmhv_flush_lpid (kvm->arch.lpid);plpar_guest_delete (0 , kvm->arch.lpid);
I am not sure I follow the optimization here. I would expect the hypervisor to kill all the translation caches as part of guest_delete. What is the benefit of doing a lpid flush outside the guest delete?
Quoted 22 lines
arch/powerpc/kvm/book3s_hv.c +2
-1-else + }else {kvmppc_free_lpid (kvm->arch.lpid); + }kvmppc_free_pimap (kvm);}
arch/powerpc/kvm/book3s_hv_nested.c +1
-1@@ -503,7 +503,7 @@ void kvmhv_nested_exit(void) } } -static void kvmhv_flush_lpid (u64 lpid) +void kvmhv_flush_lpid (u64 lpid) {long rc;Signature · 1 line
2.42.0
Re: [PATCH 01/12] KVM: PPC: Book3S HV nestedv2: Invalidate RPT before deleting a guest
Hi Aneesh,
Thanks for looking into this patch. My responses inline below:
Quoted 36 lines · Aneesh Kumar K.V (IBM)
Quoted 34 lines · Vaibhav Jain
From: Jordan Niethe <[email protected]>
An L0 must invalidate the L2's RPT during
H_GUEST_DELETEif this has not already been done. This is a slow operation that meansH_GUEST_DELETEmust returnH_BUSYmultiple times before completing. Invalidating the tables before deleting the guest so there is less work for the L0 to do.Signed-off-by Jordan Niethe <[email protected]>--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/kvm/book3s_hv.c | 6 ++++-- arch/powerpc/kvm/book3s_hv_nested.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)arch/powerpc/include/asm/kvm_book3s.h +1
-0@@ -302,6 +302,7 @@ void kvmhv_nested_exit(void);void kvmhv_vm_nested_init (struct kvm *kvm);long kvmhv_set_partition_table (struct kvm_vcpu *vcpu);long kvmhv_copy_tofrom_guest_nested (struct kvm_vcpu *vcpu); +void kvmhv_flush_lpid (u64 lpid);void kvmhv_set_ptbl_entry (u64 lpid,u64 dw0,u64 dw1);void kvmhv_release_all_nested (struct kvm *kvm);long kvmhv_enter_nested_guest (struct kvm_vcpu *vcpu);arch/powerpc/kvm/book3s_hv.c +0
-0@@ -5691,10 +5691,12 @@ static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)kvmhv_set_ptbl_entry (kvm->arch.lpid,0 ,0 ); }
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c static void kvmppc_core_destroy_vm_hv(struct kvm *kvm) · line 5700
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +2
-1-if (kvmhv_is_nestedv2 ()) +if (kvmhv_is_nestedv2 ()) { +kvmhv_flush_lpid (kvm->arch.lpid);plpar_guest_delete (0 , kvm->arch.lpid);I am not sure I follow the optimization here. I would expect the hypervisor to kill all the translation caches as part of
guest_delete. What is the benefit of doing a lpid flush outside the guest delete?
Thats right. However without this optimization the H_GUEST_DELETE hcall in plpar_guest_delete() returns H_BUSY multiple times resulting in multiple hcalls to the hypervisor until it finishes. Flushing the guest translation cache upfront reduces the number of HCALLs L1 guests has to make to delete a L2 guest via H_GUEST_DELETE.
Quoted 22 lines
Quoted 22 lines
arch/powerpc/kvm/book3s_hv.c +2
-1-else + }else {kvmppc_free_lpid (kvm->arch.lpid); + }kvmppc_free_pimap (kvm);}
arch/powerpc/kvm/book3s_hv_nested.c +1
-1@@ -503,7 +503,7 @@ void kvmhv_nested_exit(void) } } -static void kvmhv_flush_lpid (u64 lpid) +void kvmhv_flush_lpid (u64 lpid) {long rc;Signature · 1 line
2.42.0
Signature · 2 lines
Cheers ~ Vaibhav
Re: [PATCH 01/12] KVM: PPC: Book3S HV nestedv2: Invalidate RPT before deleting a guest
Quoted 52 lines · Vaibhav Jain
Hi Aneesh,
Thanks for looking into this patch. My responses inline below:
Quoted 36 lines · Aneesh Kumar K.V (IBM)
Quoted 34 lines · Vaibhav Jain
From: Jordan Niethe <[email protected]>
An L0 must invalidate the L2's RPT during
H_GUEST_DELETEif this has not already been done. This is a slow operation that meansH_GUEST_DELETEmust returnH_BUSYmultiple times before completing. Invalidating the tables before deleting the guest so there is less work for the L0 to do.Signed-off-by Jordan Niethe <[email protected]>--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/kvm/book3s_hv.c | 6 ++++-- arch/powerpc/kvm/book3s_hv_nested.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)arch/powerpc/include/asm/kvm_book3s.h +1
-0@@ -302,6 +302,7 @@ void kvmhv_nested_exit(void);void kvmhv_vm_nested_init (struct kvm *kvm);long kvmhv_set_partition_table (struct kvm_vcpu *vcpu);long kvmhv_copy_tofrom_guest_nested (struct kvm_vcpu *vcpu); +void kvmhv_flush_lpid (u64 lpid);void kvmhv_set_ptbl_entry (u64 lpid,u64 dw0,u64 dw1);void kvmhv_release_all_nested (struct kvm *kvm);long kvmhv_enter_nested_guest (struct kvm_vcpu *vcpu);arch/powerpc/kvm/book3s_hv.c +0
-0@@ -5691,10 +5691,12 @@ static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)kvmhv_set_ptbl_entry (kvm->arch.lpid,0 ,0 ); }Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c static void kvmppc_core_destroy_vm_hv(struct kvm *kvm) · line 5700
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +2
-1-if (kvmhv_is_nestedv2 ()) +if (kvmhv_is_nestedv2 ()) { +kvmhv_flush_lpid (kvm->arch.lpid);plpar_guest_delete (0 , kvm->arch.lpid);I am not sure I follow the optimization here. I would expect the hypervisor to kill all the translation caches as part of
guest_delete. What is the benefit of doing a lpid flush outside the guest delete?
Quoted 6 lines
Thats right. However without this optimization the
H_GUEST_DELETEhcall inplpar_guest_delete()returnsH_BUSYmultiple times resulting in multiple hcalls to the hypervisor until it finishes. Flushing the guest translation cache upfront reduces the number of HCALLs L1 guests has to make to delete a L2 guest viaH_GUEST_DELETE.
can we add that as a comment above that kvmhv_flush_lpid()?
-aneesh
Re: [PATCH 01/12] KVM: PPC: Book3S HV nestedv2: Invalidate RPT before deleting a guest
Quoted 54 lines · Aneesh Kumar K.V
Quoted 52 lines · Vaibhav Jain
Hi Aneesh,
Thanks for looking into this patch. My responses inline below:
Quoted 46 lines · Aneesh Kumar K.V (IBM)
Quoted 31 lines · Vaibhav Jain
From: Jordan Niethe <[email protected]>
An L0 must invalidate the L2's RPT during
H_GUEST_DELETEif this has not already been done. This is a slow operation that meansH_GUEST_DELETEmust returnH_BUSYmultiple times before completing. Invalidating the tables before deleting the guest so there is less work for the L0 to do.Signed-off-by Jordan Niethe <[email protected]>--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/kvm/book3s_hv.c | 6 ++++-- arch/powerpc/kvm/book3s_hv_nested.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)arch/powerpc/include/asm/kvm_book3s.h +1
-0@@ -302,6 +302,7 @@ void kvmhv_nested_exit(void);void kvmhv_vm_nested_init (struct kvm *kvm);long kvmhv_set_partition_table (struct kvm_vcpu *vcpu);long kvmhv_copy_tofrom_guest_nested (struct kvm_vcpu *vcpu); +void kvmhv_flush_lpid (u64 lpid);void kvmhv_set_ptbl_entry (u64 lpid,u64 dw0,u64 dw1);void kvmhv_release_all_nested (struct kvm *kvm);long kvmhv_enter_nested_guest (struct kvm_vcpu *vcpu);arch/powerpc/kvm/book3s_hv.c +0
-0arch/powerpc/kvm/book3s_hv.c static void kvmppc_core_destroy_vm_hv(struct kvm *kvm) · line 5697
Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c +2
-1@@ -5691,10 +5691,12 @@ static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)kvmhv_set_ptbl_entry (kvm->arch.lpid,0 ,0 ); } -if (kvmhv_is_nestedv2 ()) +if (kvmhv_is_nestedv2 ()) { +kvmhv_flush_lpid (kvm->arch.lpid);plpar_guest_delete (0 , kvm->arch.lpid);I am not sure I follow the optimization here. I would expect the hypervisor to kill all the translation caches as part of
guest_delete. What is the benefit of doing a lpid flush outside the guest delete?
Quoted 8 lines
Quoted 6 lines
Thats right. However without this optimization the
H_GUEST_DELETEhcall inplpar_guest_delete()returnsH_BUSYmultiple times resulting in multiple hcalls to the hypervisor until it finishes. Flushing the guest translation cache upfront reduces the number of HCALLs L1 guests has to make to delete a L2 guest viaH_GUEST_DELETE.can we add that as a comment above that
kvmhv_flush_lpid()?
Sure, I will put up a comment with that detail in v2 of the patch series.
Quoted 2 lines
-aneesh
Signature · 2 lines
Cheers ~ Vaibhav
PATCH 2/12 KVM: PPC: Book3S HV nestedv2: Avoid reloading the tb offset
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
The kvmppc_get_tb_offset() getter reloads KVMPPC_GSID_TB_OFFSET from the L0 for nestedv2 host. This is unnecessary as the value does not change. KVMPPC_GSID_TB_OFFSET also need not be reloaded in kvmppc_{s,g}et_dec_expires().
--- arch/powerpc/include/asm/kvm_book3s.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +6 -3
@@ -594,13 +594,17 @@ static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ KVMPPC_BOOK3S_VCORE_ACCESSOR(vtb, 64, KVMPPC_GSID_VTB) -KVMPPC_BOOK3S_VCORE_ACCESSOR(tb_offset, 64, KVMPPC_GSID_TB_OFFSET) KVMPPC_BOOK3S_VCORE_ACCESSOR_GET(arch_compat, 32, KVMPPC_GSID_LOGICAL_PVR) KVMPPC_BOOK3S_VCORE_ACCESSOR_GET(lpcr, 64, KVMPPC_GSID_LPCR) +KVMPPC_BOOK3S_VCORE_ACCESSOR_SET(tb_offset, 64, KVMPPC_GSID_TB_OFFSET) + +static inline u64 kvmppc_get_tb_offset (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.vcore->tb_offset; +}static inline u64 kvmppc_get_dec_expires (struct kvm_vcpu *vcpu) { -WARN_ON (kvmhv_nestedv2_cached_reload (vcpu,KVMPPC_GSID_TB_OFFSET ) <0 );WARN_ON (kvmhv_nestedv2_cached_reload (vcpu,KVMPPC_GSID_DEC_EXPIRY_TB ) <0 );return vcpu->arch.dec_expires; }
@@ -608,7 +612,6 @@ static inline u64 kvmppc_get_dec_expires(struct kvm_vcpu *vcpu)static inline void kvmppc_set_dec_expires (struct kvm_vcpu *vcpu,u64 val) { vcpu->arch.dec_expires = val; -WARN_ON (kvmhv_nestedv2_cached_reload (vcpu,KVMPPC_GSID_TB_OFFSET ) <0 );kvmhv_nestedv2_mark_dirty (vcpu,KVMPPC_GSID_DEC_EXPIRY_TB ); }
Signature · 1 line
2.42.0
PATCH 3/12 KVM: PPC: Book3S HV nestedv2: Do not check msr on hcalls
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
The check for a hcall coming from userspace is done for KVM-PR. This is not supported for nestedv2 and the L0 will directly inject the necessary exception to the L2 if userspace performs a hcall. Avoid checking the MSR and thus avoid a H_GUEST_GET_STATE hcall in the L1.
--- arch/powerpc/kvm/book3s_hv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_hv.c +2 -2
@@ -1688,7 +1688,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu, {int i; -if (unlikely (__kvmppc_get_msr_hv (vcpu) &MSR_PR )) { +if (!kvmhv_is_nestedv2 () &&unlikely (__kvmppc_get_msr_hv (vcpu) &MSR_PR )) {/* * Guest userspace executed sc 1. This can only be * reached by the P9 path because the old path
@@ -4949,7 +4949,7 @@ static int kvmppc_vcpu_run_hv(struct kvm_vcpu *vcpu)if (run->exit_reason ==KVM_EXIT_PAPR_HCALL ) {accumulate_time (vcpu, &vcpu->arch.hcall); -if (WARN_ON_ONCE (__kvmppc_get_msr_hv (vcpu) &MSR_PR )) { +if (!kvmhv_is_nestedv2 () &&WARN_ON_ONCE (__kvmppc_get_msr_hv (vcpu) &MSR_PR )) {/* * These should have been caught reflected * into the guest by now. Final sanity check:
Signature · 1 line
2.42.0
PATCH 4/12 KVM: PPC: Book3S HV nestedv2: Get the PID only if needed to copy tofrom a guest
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
kvmhv_copy_tofrom_guest_radix() gets the PID at the start of the function. If pid is not used, then this is a wasteful H_GUEST_GET_STATE hcall for nestedv2 hosts. Move the assignment to where pid will be used.
--- arch/powerpc/kvm/book3s_64_mmu_radix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_64_mmu_radix.c +3 -1
@@ -97,7 +97,7 @@ static long kvmhv_copy_tofrom_guest_radix(struct kvm_vcpu *vcpu, gva_t eaddr, void *to, void *from, unsigned long n) { int lpid = vcpu->kvm->arch.lpid; -int pid =kvmppc_get_pid (vcpu); +int pid;/* This would cause a data segment intr so don't allow the access */ if (eaddr & (0x3FFUL <<52 ))
@@ -110,6 +110,8 @@ static long kvmhv_copy_tofrom_guest_radix(struct kvm_vcpu *vcpu, gva_t eaddr,/* If accessing quadrant 3 then pid is expected to be 0 */ if (((eaddr >>62 ) &0x3 ) ==0x3 ) pid =0 ; +else + pid =kvmppc_get_pid (vcpu); eaddr &= ~(0xFFFUL <<52 );
Signature · 1 line
2.42.0
PATCH 5/12 KVM: PPC: Book3S HV nestedv2: Ensure LPCR_MER bit is passed to the L0
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
LPCR_MER is conditionally set during entry to a guest if there is a pending external interrupt. In the nestedv2 case, this change is not being communicated to the L0, which means it is not being set in the L2. Ensure the updated LPCR value is passed to the L0.
--- arch/powerpc/kvm/book3s_hv.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/kvm/book3s_hv.c +2 -0
@@ -4084,6 +4084,8 @@ static int kvmhv_vcpu_entry_nestedv2(struct kvm_vcpu *vcpu, u64 time_limit,if (rc <0 )return -EINVAL ; +kvmppc_gse_put_u64 (io->vcpu_run_input,KVMPPC_GSID_LPCR , lpcr); +accumulate_time (vcpu, &vcpu->arch.in_guest); rc =plpar_guest_run_vcpu (0 , vcpu->kvm->arch.lpid, vcpu->vcpu_id, &trap, &i);
Signature · 1 line
2.42.0
PATCH 6/12 KVM: PPC: Book3S HV: Handle pending exceptions on guest entry with MSR_EE
In reply to Vaibhav JainFrom: Nicholas Piggin <[email protected]>
Commit 026728dc5d41 ("KVM: PPC: Book3S HV P9: Inject pending xive interrupts at guest entry") changed guest entry so that if external interrupts are enabled, BOOK3S_IRQPRIO_EXTERNAL is not tested for. Test for this regardless of MSR_EE.
For an L1 host, do not inject an interrupt, but always use LPCR_MER. If the L0 desires it can inject an interrupt.
--- arch/powerpc/kvm/book3s_hv.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
arch/powerpc/kvm/book3s_hv.c +12 -6
@@ -4738,13 +4738,19 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,if (!nested) {kvmppc_core_prepare_to_enter (vcpu); -if (__kvmppc_get_msr_hv (vcpu) &MSR_EE ) { -if (xive_interrupt_pending (vcpu)) +if (test_bit (BOOK3S_IRQPRIO_EXTERNAL , + &vcpu->arch.pending_exceptions) || +xive_interrupt_pending (vcpu)) { +/* +* For nested HV, don't synthesize but always pass MER, +* the L0 will be able to optimise that more +* effectively than manipulating registers directly. +*/ +if (!kvmhv_on_pseries () && (__kvmppc_get_msr_hv (vcpu) &MSR_EE ))kvmppc_inject_interrupt_hv (vcpu, -BOOK3S_INTERRUPT_EXTERNAL ,0 ); - }else if (test_bit (BOOK3S_IRQPRIO_EXTERNAL , - &vcpu->arch.pending_exceptions)) { - lpcr |=LPCR_MER ; +BOOK3S_INTERRUPT_EXTERNAL ,0 ); +else + lpcr |=LPCR_MER ; } } else if (vcpu->arch.pending_exceptions || vcpu->arch.doorbell_request ||
Signature · 1 line
2.42.0
PATCH 7/12 KVM: PPC: Book3S HV nestedv2: Do not inject certain interrupts
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
There is no need to inject an external interrupt in kvmppc_book3s_irqprio_deliver() as the test for BOOK3S_IRQPRIO_EXTERNAL in kvmhv_run_single_vcpu() before guest entry will raise LPCR_MER if needed. There is also no need to inject the decrementer interrupt as this will be raised within the L2 if needed. Avoiding these injections reduces H_GUEST_GET_STATE hcalls by the L1.
--- arch/powerpc/kvm/book3s.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s.c +2 -2
@@ -302,11 +302,11 @@ static int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu,switch (priority) {case BOOK3S_IRQPRIO_DECREMENTER : - deliver = (kvmppc_get_msr (vcpu) &MSR_EE ) && !crit; + deliver = !kvmhv_is_nestedv2 () && (kvmppc_get_msr (vcpu) &MSR_EE ) && !crit; vec =BOOK3S_INTERRUPT_DECREMENTER ;break ;case BOOK3S_IRQPRIO_EXTERNAL : - deliver = (kvmppc_get_msr (vcpu) &MSR_EE ) && !crit; + deliver = !kvmhv_is_nestedv2 () && (kvmppc_get_msr (vcpu) &MSR_EE ) && !crit; vec =BOOK3S_INTERRUPT_EXTERNAL ;break ;case BOOK3S_IRQPRIO_SYSTEM_RESET :
Signature · 1 line
2.42.0
PATCH 8/12 KVM: PPC: Book3S HV nestedv2: Avoid msr check in kvmppc_handle_exit_hv()
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
The msr check in kvmppc_handle_exit_hv() is not needed for nestedv2 hosts, skip the check to avoid a H_GUEST_GET_STATE hcall.
--- arch/powerpc/kvm/book3s_hv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +1 -1
@@ -1597,7 +1597,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,* That can happen due to a bug, or due to a machine check * occurring at just the wrong time. */ -if (__kvmppc_get_msr_hv (vcpu) &MSR_HV ) { +if (!kvmhv_is_nestedv2 () && (__kvmppc_get_msr_hv (vcpu) &MSR_HV )) {printk (KERN_EMERG "KVM trap in HV mode!\n" ); printk(KERN_EMERG "trap=0x%x | pc=0x%lx | msr=0x%llx\n", vcpu->arch.trap, kvmppc_get_pc(vcpu),
Signature · 1 line
2.42.0
PATCH 9/12 KVM: PPC: Book3S HV nestedv2: Do not call H_COPY_TOFROM_GUEST
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
H_COPY_TOFROM_GUEST is part of the nestedv1 API and so should not be called by a nestedv2 host. Do not attempt to call it.
--- arch/powerpc/kvm/book3s_64_mmu_radix.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/kvm/book3s_64_mmu_radix.c +3 -0
@@ -40,6 +40,9 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid,unsigned long quadrant, ret = n;bool is_load = !!to; +if (kvmhv_is_nestedv2 ()) +return H_UNSUPPORTED ; +/* Can't access quadrants 1 or 2 in non-HV mode, call the HV to do it */ if (kvmhv_on_pseries ()) return plpar_hcall_norets(H_COPY_TOFROM_GUEST, lpid, pid, eaddr,
Signature · 1 line
2.42.0
Re: [PATCH 09/12] KVM: PPC: Book3S HV nestedv2: Do not call H_COPY_TOFROM_GUEST
Quoted 5 lines · Vaibhav Jain
From: Jordan Niethe <[email protected]>
H_COPY_TOFROM_GUESTis part of the nestedv1 API and so should not be called by a nestedv2 host. Do not attempt to call it.
May be we should use firmware_has_feature(FW_FEATURE_H_COPY_TOFROM_GUEST))?
the nestedv2 can end up using the above hcall if it is supported by the hypervisor right? In its absence we will have to translate the guest ea using xlate and then use kvm_guest_read to read location using the guest real address right? That xlate will also involves multiple kvm_guest_read.
Quoted 21 lines
Signed-off-by Jordan Niethe <[email protected]>--- arch/powerpc/kvm/book3s_64_mmu_radix.c | 3 +++ 1 file changed, 3 insertions(+)arch/powerpc/kvm/book3s_64_mmu_radix.c +3
-0@@ -40,6 +40,9 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid,unsigned long quadrant, ret = n;bool is_load = !!to; +if (kvmhv_is_nestedv2 ()) +return H_UNSUPPORTED ; +/* Can't access quadrants 1 or 2 in non-HV mode, call the HV to do it */ if (kvmhv_on_pseries ()) return plpar_hcall_norets(H_COPY_TOFROM_GUEST, lpid, pid, eaddr,Signature · 1 line
2.42.0
Re: [PATCH 09/12] KVM: PPC: Book3S HV nestedv2: Do not call H_COPY_TOFROM_GUEST
Hi Aneesh,
Thanks for looking into this patch. My responses inline:
"Aneesh Kumar K.V (IBM)" <[email protected]> writes:
<snip>
Quoted 9 lines
May be we should use
firmware_has_feature(FW_FEATURE_H_COPY_TOFROM_GUEST))?the nestedv2 can end up using the above hcall if it is supported by the hypervisor right? In its absence we will have to translate the guest ea using xlate and then use
kvm_guest_readto read location using the guest real address right? That xlate will also involves multiplekvm_guest_read.
Yes, Agreed and thats a nice suggestion. However ATM the hypervisor supporting Nestedv2 doesnt have support for this hcall. In future once we have support for this hcall for nestedv2 from the hypervisor we can replace this branch with a firmware_has_feature() test.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Jordan Niethe <[email protected]>--- arch/powerpc/kvm/book3s_64_mmu_radix.c | 3 +++ 1 file changed, 3 insertions(+)arch/powerpc/kvm/book3s_64_mmu_radix.c +3
-0@@ -40,6 +40,9 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid,unsigned long quadrant, ret = n;bool is_load = !!to; +if (kvmhv_is_nestedv2 ()) +return H_UNSUPPORTED ; +/* Can't access quadrants 1 or 2 in non-HV mode, call the HV to do it */ if (kvmhv_on_pseries ()) return plpar_hcall_norets(H_COPY_TOFROM_GUEST, lpid, pid, eaddr,Signature · 1 line
2.42.0
Signature · 2 lines
Cheers ~ Vaibhav
Re: [PATCH 09/12] KVM: PPC: Book3S HV nestedv2: Do not call H_COPY_TOFROM_GUEST
Quoted 17 lines · Vaibhav Jain
Hi Aneesh,
Thanks for looking into this patch. My responses inline:
"Aneesh Kumar K.V (IBM)" <[email protected]> writes:
<snip>
Quoted 10 lines
May be we should use
firmware_has_feature(FW_FEATURE_H_COPY_TOFROM_GUEST))?the nestedv2 can end up using the above hcall if it is supported by the hypervisor right? In its absence we will have to translate the guest ea using xlate and then use
kvm_guest_readto read location using the guest real address right? That xlate will also involves multiplekvm_guest_read.
Quoted 5 lines
Yes, Agreed and thats a nice suggestion. However ATM the hypervisor supporting Nestedv2 doesnt have support for this hcall. In future once we have support for this hcall for nestedv2 from the hypervisor we can replace this branch with a
firmware_has_feature()test.
What I am suggesting is we convert that conditional to firmware_has_feature so that later when hypervisor supports this hcall all older kernel can make use of the copy_tofrom_guest without any code change.
Quoted 18 lines
Quoted 17 lines
Quoted 17 lines
Signed-off-by Jordan Niethe <[email protected]> ---
arch/powerpc/kvm/book3s_64_mmu_radix.c| 3 +++ 1 file changed, 3 insertions(+)(quoted diff) +0
-0
b/arch/powerpc/kvm/book3s_64_mmu_radix.cindex916af6c153a5..4a1abb9f7c05100644 ---a/arch/powerpc/kvm/book3s_64_mmu_radix.c+++b/arch/powerpc/kvm/book3s_64_mmu_radix.c@@ -40,6 +40,9 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid, unsigned long quadrant, ret = n; boolis_load= !!to;(quoted diff) +1
-0+ if (kvmhv_is_nestedv2()) + return H_UNSUPPORTED; + /* Can'taccess quadrants 1 or 2 in non-HV mode, call the HV to do it */ if (
kvmhv_on_pseries()) return plpar_hcall_norets(H_COPY_TOFROM_GUEST, lpid, pid, eaddr, -- 2.42.0
Re: [PATCH 09/12] KVM: PPC: Book3S HV nestedv2: Do not call H_COPY_TOFROM_GUEST
Hi Aneesh,
"Aneesh Kumar K.V" <[email protected]> writes:
<snip>
Quoted 9 lines
Quoted 5 lines
Yes, Agreed and thats a nice suggestion. However ATM the hypervisor supporting Nestedv2 doesnt have support for this hcall. In future once we have support for this hcall for nestedv2 from the hypervisor we can replace this branch with a
firmware_has_feature()test.What I am suggesting is we convert that conditional to
firmware_has_featureso that later when hypervisor supports this hcall all older kernel can make use of thecopy_tofrom_guestwithout any code change.
AFAIK for firmware_has_feature to work we either need:
- A way to call this hcall with some invalid args. However lpid/pid for guest arent allocated during boot.
- A way for hypervisor to advertise support for this hcall before the L1 kernel boots.
ATM L0 dosent support for any of these two ways. I can do a follow up patch later when we have a clarity on how we want to advertise support for this hcall. For now current kernel supporting nestedv2 wont be using this hcall assuming its not supported. Future kernels can use one of the two ways above to set the firmware_has_feature flag to take advantage of this hcall.
Signature · 2 lines
Cheers ~ Vaibhav
Re: [PATCH 09/12] KVM: PPC: Book3S HV nestedv2: Do not call H_COPY_TOFROM_GUEST
Quoted 22 lines · Vaibhav Jain
Hi Aneesh,
"Aneesh Kumar K.V" <[email protected]> writes:
<snip>
Quoted 9 lines
Quoted 5 lines
Yes, Agreed and thats a nice suggestion. However ATM the hypervisor supporting Nestedv2 doesnt have support for this hcall. In future once we have support for this hcall for nestedv2 from the hypervisor we can replace this branch with a
firmware_has_feature()test.What I am suggesting is we convert that conditional to
firmware_has_featureso that later when hypervisor supports this hcall all older kernel can make use of thecopy_tofrom_guestwithout any code change.AFAIK for
firmware_has_featureto work we either need:
- A way to call this hcall with some invalid args. However lpid/pid for guest arent allocated during boot.- A way for hypervisor to advertise support for this hcall before the L1 kernel boots.
Quoted 7 lines
ATM L0 dosent support for any of these two ways. I can do a follow up patch later when we have a clarity on how we want to advertise support for this hcall. For now current kernel supporting nestedv2 wont be using this hcall assuming its not supported. Future kernels can use one of the two ways above to set the
firmware_has_featureflag to take advantage of this hcall.
We can use the second option and have L0 publish the firmware feature when it adds the new hcall. The good part about this is that all existing L1 kernels will automatically use the new hcall. Something like.
arch/powerpc/include/asm/firmware.h +1 -0
@@ -57,6 +57,7 @@#define FW_FEATURE_ENERGY_SCALE_INFO ASM_CONST(0x0000040000000000)#define FW_FEATURE_WATCHDOG ASM_CONST(0x0000080000000000)#define FW_FEATURE_PLPKS ASM_CONST(0x0000100000000000) +#define FW_FEATURE_H_COPY_TOFROM_GUEST ASM_CONST(0x0000200000000000)#ifndef __ASSEMBLY__
arch/powerpc/kvm/book3s_64_mmu_radix.c +3 -0
@@ -39,6 +39,9 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid,unsigned long quadrant, ret = n;bool is_load = !!to; +if (!firmware_has_feature (FW_FEATURE_H_COPY_TOFROM_GUEST )) +return H_UNSUPPORTED ; +/* Can't access quadrants 1 or 2 in non-HV mode, call the HV to do it */ if (kvmhv_on_pseries ()) return plpar_hcall_norets(H_COPY_TOFROM_GUEST, lpid, pid, eaddr,
arch/powerpc/platforms/pseries/firmware.c +2 -0
@@ -69,6 +69,8 @@ hypertas_fw_features_table[] = { {FW_FEATURE_ENERGY_SCALE_INFO, "hcall-energy-scale-info"}, {FW_FEATURE_WATCHDOG, "hcall-watchdog"}, {FW_FEATURE_PLPKS, "hcall-pks"}, + {FW_FEATURE_H_COPY_TOFROM_GUEST, + "hcall-h-copy_tofrom-guest"}, };/* Build up the firmware features bitmask using the contents of
PATCH 10/12 KVM: PPC: Book3S HV nestedv2: Register the VPA with the L0
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
In the nestedv2 case, the L1 may register the L2's VPA with the L0. This allows the L0 to manage the L2's dispatch count, as well as enable possible performance optimisations by seeing if certain resources are not being used by the L2 (such as the PMCs).
Use the H_GUEST_SET_STATE call to inform the L0 of the L2's VPA address. This can not be done in the H_GUEST_VCPU_RUN input buffer.
--- arch/powerpc/include/asm/kvm_book3s_64.h | 1 + arch/powerpc/kvm/book3s_hv.c | 38 ++++++++++++++++++------ arch/powerpc/kvm/book3s_hv_nestedv2.c | 29 ++++++++++++++++++ 3 files changed, 59 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/kvm_book3s_64.h +1 -0
@@ -682,6 +682,7 @@ void kvmhv_nestedv2_vcpu_free(struct kvm_vcpu *vcpu, struct kvmhv_nestedv2_io *iint kvmhv_nestedv2_flush_vcpu (struct kvm_vcpu *vcpu,u64 time_limit);int kvmhv_nestedv2_set_ptbl_entry (unsigned long lpid,u64 dw0,u64 dw1);int kvmhv_nestedv2_parse_output (struct kvm_vcpu *vcpu); +int kvmhv_nestedv2_set_vpa (struct kvm_vcpu *vcpu,unsigned long vpa);#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
arch/powerpc/kvm/book3s_hv.c +29 -9
@@ -650,7 +650,8 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu,return err; } -static void kvmppc_update_vpa (struct kvm_vcpu *vcpu,struct kvmppc_vpa *vpap) +static void kvmppc_update_vpa (struct kvm_vcpu *vcpu,struct kvmppc_vpa *vpap, +struct kvmppc_vpa *old_vpap) {struct kvm *kvm = vcpu->kvm;void *va;
@@ -690,9 +691,8 @@ static void kvmppc_update_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *vpap)kvmppc_unpin_guest_page (kvm, va, gpa, false); va =NULL ; } -if (vpap->pinned_addr) -kvmppc_unpin_guest_page (kvm, vpap->pinned_addr, vpap->gpa, - vpap->dirty); + *old_vpap = *vpap; + vpap->gpa = gpa; vpap->pinned_addr = va; vpap->dirty = false;
@@ -702,6 +702,9 @@ static void kvmppc_update_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *vpap)static void kvmppc_update_vpas (struct kvm_vcpu *vcpu) { +struct kvm *kvm = vcpu->kvm; +struct kvmppc_vpa old_vpa = {0 }; +if (!(vcpu->arch.vpa.update_pending || vcpu->arch.slb_shadow.update_pending || vcpu->arch.dtl.update_pending))
@@ -709,17 +712,34 @@ static void kvmppc_update_vpas(struct kvm_vcpu *vcpu)spin_lock (&vcpu->arch.vpa_update_lock);if (vcpu->arch.vpa.update_pending) { -kvmppc_update_vpa (vcpu, &vcpu->arch.vpa); -if (vcpu->arch.vpa.pinned_addr) +kvmppc_update_vpa (vcpu, &vcpu->arch.vpa, &old_vpa); +if (old_vpa.pinned_addr) { +if (kvmhv_is_nestedv2 ()) +kvmhv_nestedv2_set_vpa (vcpu, ~0ull ); +kvmppc_unpin_guest_page (kvm, old_vpa.pinned_addr, old_vpa.gpa, + old_vpa.dirty); + } +if (vcpu->arch.vpa.pinned_addr) {init_vpa (vcpu, vcpu->arch.vpa.pinned_addr); +if (kvmhv_is_nestedv2 ()) +kvmhv_nestedv2_set_vpa (vcpu,__pa (vcpu->arch.vpa.pinned_addr)); + } }if (vcpu->arch.dtl.update_pending) { -kvmppc_update_vpa (vcpu, &vcpu->arch.dtl); +kvmppc_update_vpa (vcpu, &vcpu->arch.dtl, &old_vpa); +if (old_vpa.pinned_addr) +kvmppc_unpin_guest_page (kvm, old_vpa.pinned_addr, old_vpa.gpa, + old_vpa.dirty); vcpu->arch.dtl_ptr = vcpu->arch.dtl.pinned_addr; vcpu->arch.dtl_index =0 ; } -if (vcpu->arch.slb_shadow.update_pending) -kvmppc_update_vpa (vcpu, &vcpu->arch.slb_shadow); +if (vcpu->arch.slb_shadow.update_pending) { +kvmppc_update_vpa (vcpu, &vcpu->arch.slb_shadow, &old_vpa); +if (old_vpa.pinned_addr) +kvmppc_unpin_guest_page (kvm, old_vpa.pinned_addr, old_vpa.gpa, + old_vpa.dirty); + } +spin_unlock (&vcpu->arch.vpa_update_lock); }
arch/powerpc/kvm/book3s_hv_nestedv2.c +29 -0
@@ -855,6 +855,35 @@ int kvmhv_nestedv2_set_ptbl_entry(unsigned long lpid, u64 dw0, u64 dw1) }EXPORT_SYMBOL_GPL (kvmhv_nestedv2_set_ptbl_entry); +/** +* kvmhv_nestedv2_set_vpa() - register L2 VPA with L0 +* @vcpu: vcpu +* @vpa: L1 logical real address +*/ +int kvmhv_nestedv2_set_vpa (struct kvm_vcpu *vcpu,unsigned long vpa) +{ +struct kvmhv_nestedv2_io *io; +struct kvmppc_gs_buff *gsb; +int rc =0 ; + + io = &vcpu->arch.nestedv2_io; + gsb = io->vcpu_run_input; + +kvmppc_gsb_reset (gsb); + rc =kvmppc_gse_put_u64 (gsb,KVMPPC_GSID_VPA , vpa); +if (rc <0 ) + goto out; + + rc =kvmppc_gsb_send (gsb,0 ); +if (rc <0 ) +pr_err ("KVM-NESTEDv2: couldn't register the L2 VPA (rc=%d)\n" , rc); + +out: +kvmppc_gsb_reset (gsb); +return rc; +} +EXPORT_SYMBOL_GPL (kvmhv_nestedv2_set_vpa); +/** * kvmhv_nestedv2_parse_output() - receive values from H_GUEST_RUN_VCPU output * @vcpu: vcpu
Signature · 1 line
2.42.0
PATCH 11/12 KVM: PPC: Reduce reliance on analyse_instr() in mmio emulation
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
Commit 709236039964 ("KVM: PPC: Reimplement non-SIMD LOAD/STORE instruction mmio emulation with analyse_instr() input") and commit 2b33cb585f94 ("KVM: PPC: Reimplement LOAD_FP/STORE_FP instruction mmio emulation with analyse_instr() input") made kvmppc_emulate_loadstore() use the results from analyse_instr() for instruction emulation. In particular the effective address from analyse_instr() is used for UPDATE type instructions and fact that op.val is all ready endian corrected is used in the STORE case.
However, these changes now have some negative implications for the nestedv2 case. For analyse_instr() to determine the correct effective address, the GPRs must be loaded from the L0. This is not needed as vcpu->arch.vaddr_accessed is already set. Change back to using vcpu->arch.vaddr_accessed.
In the STORE case, use kvmppc_get_gpr() value instead of the op.val. kvmppc_get_gpr() will reload from the L0 if needed in the nestedv2 case. This means if a byte reversal is needed must now be passed to kvmppc_handle_store() like in the kvmppc_handle_load() case.
This means the call to kvmhv_nestedv2_reload_ptregs() can be avoided as there is no concern about op.val being stale. Drop the call to kvmhv_nestedv2_mark_dirty_ptregs() as without the call to kvmhv_nestedv2_reload_ptregs(), stale state could be marked as valid.
This is fine as the required marking things dirty is already handled for the UPDATE case by the call to kvmppc_set_gpr(). For LOADs, it is handled in kvmppc_complete_mmio_load(). This is called either directly in __kvmppc_handle_load() if the load can be handled in KVM, or on the next kvm_arch_vcpu_ioctl_run() if an exit was required.
--- arch/powerpc/kvm/emulate_loadstore.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
arch/powerpc/kvm/emulate_loadstore.c +10 -11
@@ -93,7 +93,6 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) emulated =EMULATE_FAIL ; vcpu->arch.regs.msr =kvmppc_get_msr (vcpu); -kvmhv_nestedv2_reload_ptregs (vcpu, &vcpu->arch.regs);if (analyse_instr (&op, &vcpu->arch.regs, inst) ==0 ) {int type = op.type &INSTR_TYPE_MASK ;int size =GETSIZE (op.type);
@@ -112,7 +111,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) op.reg, size, !instr_byte_swap);if ((op.type &UPDATE ) && (emulated !=EMULATE_FAIL )) -kvmppc_set_gpr (vcpu, op.update_reg, op.ea); +kvmppc_set_gpr (vcpu, op.update_reg, vcpu->arch.vaddr_accessed);break ; }
@@ -132,7 +131,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) KVM_MMIO_REG_FPR|op.reg, size, 1);if ((op.type &UPDATE ) && (emulated !=EMULATE_FAIL )) -kvmppc_set_gpr (vcpu, op.update_reg, op.ea); +kvmppc_set_gpr (vcpu, op.update_reg, vcpu->arch.vaddr_accessed);break ;#endif
@@ -224,16 +223,17 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) break; }#endif -case STORE : -/* if need byte reverse, op.val has been reversed by -* analyse_instr(). -*/ - emulated =kvmppc_handle_store (vcpu, op.val, size,1 ); +case STORE : { +int instr_byte_swap = op.type &BYTEREV ; + + emulated =kvmppc_handle_store (vcpu,kvmppc_get_gpr (vcpu, op.reg), + size, !instr_byte_swap);if ((op.type &UPDATE ) && (emulated !=EMULATE_FAIL )) -kvmppc_set_gpr (vcpu, op.update_reg, op.ea); +kvmppc_set_gpr (vcpu, op.update_reg, vcpu->arch.vaddr_accessed);break ; + }#ifdef CONFIG_PPC_FPU case STORE_FP :if (kvmppc_check_fp_disabled (vcpu))
@@ -254,7 +254,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) kvmppc_get_fpr(vcpu, op.reg), size, 1);if ((op.type &UPDATE ) && (emulated !=EMULATE_FAIL )) -kvmppc_set_gpr (vcpu, op.update_reg, op.ea); +kvmppc_set_gpr (vcpu, op.update_reg, vcpu->arch.vaddr_accessed);break ;#endif
@@ -358,7 +358,6 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) }trace_kvm_ppc_instr (ppc_inst_val (inst),kvmppc_get_pc (vcpu), emulated); -kvmhv_nestedv2_mark_dirty_ptregs (vcpu, &vcpu->arch.regs);/* Advance past emulated instruction. */ if (emulated !=EMULATE_FAIL )
Signature · 1 line
2.42.0
PATCH 12/12 KVM: PPC: Book3S HV nestedv2: Do not cancel pending decrementer exception
In reply to Vaibhav JainFrom: Jordan Niethe <[email protected]>
In the nestedv2 case, if there is a pending decrementer exception, the L1 must get the L2's timebase from the L0 to see if the exception should be cancelled. This adds the overhead of a H_GUEST_GET_STATE call to the likely case in which the decrementer should not be cancelled.
Avoid this logic for the nestedv2 case.
--- arch/powerpc/kvm/book3s_hv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +1 -1
@@ -4834,7 +4834,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,* entering a nested guest in which case the decrementer is now owned * by L2 and the L1 decrementer is provided in hdec_expires */ -if (kvmppc_core_pending_dec (vcpu) && +if (!kvmhv_is_nestedv2 () &&kvmppc_core_pending_dec (vcpu) && ((tb <kvmppc_dec_expires_host_tb (vcpu)) || (trap ==BOOK3S_INTERRUPT_SYSCALL &&kvmppc_get_gpr (vcpu,3 ) ==H_ENTER_NESTED )))
Signature · 1 line
2.42.0
Michael Ellerman
AppliedQuoted 8 lines · Vaibhav Jain
This patch series introduces series of performance improvements to recently added support for Nested APIv2 PPC64 Guests via [1]. Details for Nested APIv2 for PPC64 Guests is available in
Documentation/powerpc/kvm-nested.rst.This patch series introduces various optimizations for a Nested APIv2 guests namely:
[...]
Applied to powerpc/topic/ppc-kvm.
[01/12] KVM: PPC: Book3S HV nestedv2: Invalidate RPT before deleting a guest
https://git.kernel.org/powerpc/c/7d370e1812b9a5f5cc68aaa5991bf7d31d8ff52c [02/12] KVM: PPC: Book3S HV nestedv2: Avoid reloading the tb offset https://git.kernel.org/powerpc/c/e0d4acbcba3f2d63dc15bc5432c8e26fc9e19675 [03/12] KVM: PPC: Book3S HV nestedv2: Do not check msr on hcalls https://git.kernel.org/powerpc/c/63ccae78cd88b52fb1d598ae33fa8408ce067b30 [04/12] KVM: PPC: Book3S HV nestedv2: Get the PID only if needed to copy tofrom a guest https://git.kernel.org/powerpc/c/e678748a8dca5b57041a84a66577f6168587b3f7 [05/12] KVM: PPC: Book3S HV nestedv2: Ensure LPCR_MER bit is passed to the L0 https://git.kernel.org/powerpc/c/ec0f6639fa8853cf6bfdfc3588aada7eeb7e5e37 [06/12] KVM: PPC: Book3S HV: Handle pending exceptions on guest entry with MSR_EE https://git.kernel.org/powerpc/c/ecd10702baae5c16a91d139bde7eff84ce55daee [07/12] KVM: PPC: Book3S HV nestedv2: Do not inject certain interrupts https://git.kernel.org/powerpc/c/df938a5576f3f3b08e1f217c660385c0d58a0b91 [08/12] KVM: PPC: Book3S HV nestedv2: Avoid msr check in kvmppc_handle_exit_hv() https://git.kernel.org/powerpc/c/a9a3de530d7531bf6cd3f6ccda769cd94c1105a0 [09/12] KVM: PPC: Book3S HV nestedv2: Do not call H_COPY_TOFROM_GUEST https://git.kernel.org/powerpc/c/4bc8ff6f170c78f64446c5d5f9ef6771eefd3416 [10/12] KVM: PPC: Book3S HV nestedv2: Register the VPA with the L0 https://git.kernel.org/powerpc/c/db1dcfae1dae3c042f348175ac0394e2fc14b1b3 [11/12] KVM: PPC: Reduce reliance on analyse_instr() in mmio emulation https://git.kernel.org/powerpc/c/797a5af8fc7297b19e5c6b1713956ebf1e6c1cde [12/12] KVM: PPC: Book3S HV nestedv2: Do not cancel pending decrementer exception https://git.kernel.org/powerpc/c/180c6b072bf360b686e53d893d8dcf7dbbaec6bb
cheers