powerpc/kvm: Move pmu code in kvm folder to separate file for power9 and later platforms
Subsystems (2)
PATCH 1/2 powerpc/kvm: Move pmu code in kvm folder to separate file for power9 and later platforms
File book3s_hv_p9_entry.c in powerpc/kvm folder consists of functions like freeze_pmu, switch_pmu_to_guest and switch_pmu_to_host which are specific to Performance Monitoring Unit(PMU) for power9 and later platforms.
For better maintenance, moving pmu related code from book3s_hv_p9_entry.c to a new file called book3s_hv_p9_perf.c, without any logic change.
Also make corresponding changes in the Makefile to include book3s_hv_p9_perf.c during compilation.
--- arch/powerpc/kvm/Makefile | 1 + arch/powerpc/kvm/book3s_hv_p9_entry.c | 221 ------------------------- arch/powerpc/kvm/book3s_hv_p9_perf.c | 225 ++++++++++++++++++++++++++ 3 files changed, 226 insertions(+), 221 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_hv_p9_perf.c
arch/powerpc/kvm/Makefile +1 -0
@@ -86,6 +86,7 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_hv_rm_mmu.o \ book3s_hv_ras.o \ book3s_hv_builtin.o \ + book3s_hv_p9_perf.o \ $(kvm-book3s_64-builtin-tm-objs-y) \ $(kvm-book3s_64-builtin-xics-objs-y) endif
arch/powerpc/kvm/book3s_hv_p9_entry.c +0 -221
231 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_p9_perf.c new file +225 -0
225 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH 2/2 powerpc/kvm: Remove comment related to moving PMU code to perf subsystem
Commit aabcaf6ae2a0 ("KVM: PPC: Book3S HV P9: Move host OS save/restore functions to built-in") added a comment in switch_pmu_to_guest function, indicating possibility of moving PMU handling code to perf subsystem. But perf subsystem code compilation depends upon the enablement of CONFIG_PERF_EVENTS whereas, kvm code don't have any dependency on this config.
Patch remove this comment as switch_pmu_to_guest functionality is needed even if perf subsystem is disabled.
--- arch/powerpc/kvm/book3s_hv_p9_perf.c | 6 ------ 1 file changed, 6 deletions(-)
arch/powerpc/kvm/book3s_hv_p9_perf.c +0 -6
@@ -44,12 +44,6 @@ void switch_pmu_to_guest(struct kvm_vcpu *vcpu,/* Save host */ if (ppc_get_pmu_inuse ()) { -/* -* It might be better to put PMU handling (at least for the -* host) in the perf subsystem because it knows more about what -* is being used. -*/ -/* POWER9, POWER10 do not implement HPMC or SPMC */ host_os_sprs->mmcr0 =mfspr (SPRN_MMCR0 );
Signature · 1 line
2.27.0
Nicholas Piggin
reviewerRe: [PATCH 2/2] powerpc/kvm: Remove comment related to moving PMU code to perf subsystem
Excerpts from Kajol Jain's message of July 11, 2022 1:49 pm:
Quoted 10 lines
Commit
aabcaf6ae2a0("KVM: PPC: Book3S HV P9: Move host OS save/restore functions to built-in") added a comment inswitch_pmu_to_guestfunction, indicating possibility of moving PMU handling code to perf subsystem. But perf subsystem code compilation depends upon the enablement ofCONFIG_PERF_EVENTSwhereas, kvm code don't have any dependency on this config.
Patch remove this comment asswitch_pmu_to_guestfunctionality is needed even if perf subsystem is disabled.Signed-off-by Kajol Jain <[email protected]>
Does the host PMU state need to be saved/restored if we don't have PERF_EVENTS enabled? Guest yes, but host maybe could become a no-op?
Thanks,
Nick
Quoted 25 lines
--- arch/powerpc/kvm/book3s_hv_p9_perf.c | 6 ------ 1 file changed, 6 deletions(-)arch/powerpc/kvm/book3s_hv_p9_perf.c +0
-6@@ -44,12 +44,6 @@ void switch_pmu_to_guest(struct kvm_vcpu *vcpu,/* Save host */ if (ppc_get_pmu_inuse ()) { -/* -* It might be better to put PMU handling (at least for the -* host) in the perf subsystem because it knows more about what -* is being used. -*/ -/* POWER9, POWER10 do not implement HPMC or SPMC */ host_os_sprs->mmcr0 =mfspr (SPRN_MMCR0 );Signature · 1 line
2.27.0
Excerpts from Kajol Jain's message of July 11, 2022 1:49 pm:
Quoted 30 lines
File
book3s_hv_p9_entry.cin powerpc/kvm folder consists of functions likefreeze_pmu,switch_pmu_to_guestandswitch_pmu_to_hostwhich are specific to Performance Monitoring Unit(PMU) for power9 and later platforms.For better maintenance, moving pmu related code from
book3s_hv_p9_entry.cto a new file calledbook3s_hv_p9_perf.c, without any logic change.
Also make corresponding changes in theMakefileto includebook3s_hv_p9_perf.cduring compilation.arch/powerpc/kvm/book3s_hv_p9_perf.c new file +17
-0+ +if (ppc_get_pmu_inuse ()) { +mtspr (SPRN_PMC1 , host_os_sprs->pmc1); +mtspr (SPRN_PMC2 , host_os_sprs->pmc2); +mtspr (SPRN_PMC3 , host_os_sprs->pmc3); +mtspr (SPRN_PMC4 , host_os_sprs->pmc4); +mtspr (SPRN_PMC5 , host_os_sprs->pmc5); +mtspr (SPRN_PMC6 , host_os_sprs->pmc6); +mtspr (SPRN_MMCR1 , host_os_sprs->mmcr1); +mtspr (SPRN_MMCR2 , host_os_sprs->mmcr2); +mtspr (SPRN_SDAR , host_os_sprs->sdar); +mtspr (SPRN_SIAR , host_os_sprs->siar); +mtspr (SPRN_SIER , host_os_sprs->sier1); + +if (cpu_has_feature (CPU_FTR_ARCH_31 )) { +mtspr (SPRN_MMCR3 , host_os_sprs->mmcr3); +mtspr (SPRN_SIER2 , host_os_sprs->sier2);
arch/powerpc/kvm/book3s_hv_p9_perf.c line 225
Quoted 10 lines
arch/powerpc/kvm/book3s_hv_p9_perf.c new file +10
-0+mtspr (SPRN_SIER3 , host_os_sprs->sier3); + } + +/* Set MMCRA then MMCR0 last */ +mtspr (SPRN_MMCRA , host_os_sprs->mmcra); +mtspr (SPRN_MMCR0 , host_os_sprs->mmcr0); +isync (); + } +} +EXPORT_SYMBOL_GPL (switch_pmu_to_host);
I'm still thinking these parts of the code in particular that do the host PMU save/restore could be handled by calls into perf subsystem. In some cases it doesn't need to save SPRs because it can recreate them or is not using them. Maybe it's not so simple.
Either way, I'm fine with this move to stat with.
Madhavan Srinivasan
maintainerQuoted 36 lines · Nicholas Piggin
Excerpts from Kajol Jain's message of July 11, 2022 1:49 pm:
Quoted 35 lines
File
book3s_hv_p9_entry.cin powerpc/kvm folder consists of functions likefreeze_pmu,switch_pmu_to_guestandswitch_pmu_to_hostwhich are specific to Performance Monitoring Unit(PMU) for power9 and later platforms.For better maintenance, moving pmu related code from
book3s_hv_p9_entry.cto a new file calledbook3s_hv_p9_perf.c, without any logic change.
Also make corresponding changes in theMakefileto includebook3s_hv_p9_perf.cduring compilation.arch/powerpc/kvm/book3s_hv_p9_perf.c new file +24
-0+ +if (ppc_get_pmu_inuse ()) { +mtspr (SPRN_PMC1 , host_os_sprs->pmc1); +mtspr (SPRN_PMC2 , host_os_sprs->pmc2); +mtspr (SPRN_PMC3 , host_os_sprs->pmc3); +mtspr (SPRN_PMC4 , host_os_sprs->pmc4); +mtspr (SPRN_PMC5 , host_os_sprs->pmc5); +mtspr (SPRN_PMC6 , host_os_sprs->pmc6); +mtspr (SPRN_MMCR1 , host_os_sprs->mmcr1); +mtspr (SPRN_MMCR2 , host_os_sprs->mmcr2); +mtspr (SPRN_SDAR , host_os_sprs->sdar); +mtspr (SPRN_SIAR , host_os_sprs->siar); +mtspr (SPRN_SIER , host_os_sprs->sier1); + +if (cpu_has_feature (CPU_FTR_ARCH_31 )) { +mtspr (SPRN_MMCR3 , host_os_sprs->mmcr3); +mtspr (SPRN_SIER2 , host_os_sprs->sier2); +mtspr (SPRN_SIER3 , host_os_sprs->sier3); + } + +/* Set MMCRA then MMCR0 last */ +mtspr (SPRN_MMCRA , host_os_sprs->mmcra); +mtspr (SPRN_MMCR0 , host_os_sprs->mmcr0); +isync ();
Quoted 8 lines
arch/powerpc/kvm/book3s_hv_p9_perf.c line 225
Quoted 4 lines
arch/powerpc/kvm/book3s_hv_p9_perf.c new file +3
-0+ } +} +EXPORT_SYMBOL_GPL (switch_pmu_to_host);I'm still thinking these parts of the code in particular that do the host PMU save/restore could be handled by calls into perf subsystem. In some cases it doesn't need to save SPRs because it can recreate them or is not using them. Maybe it's not so simple.
Yes, we looked at this. Concern for me is counter data leak.
Host application will still have read access to these SPRs
in power9 and before.So I would recommend to save/restore host values as part of it.
Maddy
Quoted 4 lines
Either way, I'm fine with this move to stat with.
Reviewed-by Nicholas Piggin <[email protected]>
Michael Ellerman
AppliedQuoted 5 lines · Kajol Jain
File
book3s_hv_p9_entry.cin powerpc/kvm folder consists of functions likefreeze_pmu,switch_pmu_to_guestandswitch_pmu_to_hostwhich are specific to Performance Monitoring Unit(PMU) for power9 and later platforms.
Quoted 7 lines
For better maintenance, moving pmu related code from
book3s_hv_p9_entry.cto a new file calledbook3s_hv_p9_perf.c, without any logic change.
Also make corresponding changes in theMakefileto includebook3s_hv_p9_perf.cduring compilation.[...]
Applied to powerpc/topic/ppc-kvm.
[1/2] powerpc/kvm: Move pmu code in kvm folder to separate file for power9 and later platforms
https://git.kernel.org/powerpc/c/db5360840f09eded71009a981084ab10a93a08d8 [2/2] powerpc/kvm: Remove comment related to moving PMU code to perf subsystem https://git.kernel.org/powerpc/c/4008d54e29531813e800580f8309133b9b14a921
cheers