powerpc/watchpoint: 2nd DAWR kvm enablement + selftests
Subsystems (5)
cover powerpc/watchpoint: 2nd DAWR kvm enablement + selftests
Patch #1, #2 and #3 enables p10 2nd DAWR feature for Book3S kvm guest. DAWR is a hypervisor resource and thus H_SET_MODE hcall is used to set/unset it. A new case H_SET_MODE_RESOURCE_SET_DAWR1 is introduced in H_SET_MODE hcall for setting/unsetting 2nd DAWR. Also, new capability KVM_CAP_PPC_DAWR1 has been added to query 2nd DAWR support via kvm ioctl.
This feature also needs to be enabled in Qemu to really use it. I'll reply link to qemu patches once I post them in qemu-devel mailing list.
Patch #4, #5, #6 and #7 adds selftests to test 2nd DAWR.
Dependency:
1: p10 kvm base enablement
https://lore.kernel.org/linuxppc-dev/[email protected]
2: 2nd DAWR powervm/baremetal enablement
https://lore.kernel.org/linuxppc-dev/[email protected]
3: ptrace PPC_DEBUG_FEATURE_DATA_BP_DAWR_ARCH_31 flag
https://lore.kernel.org/linuxppc-dev/[email protected]
Patches in this series applies fine on top of powerpc/next (9a77c4a0a125) plus above dependency patches.
Ravi Bangoria (7):
powerpc/watchpoint/kvm: Rename current DAWR macros and variables powerpc/watchpoint/kvm: Add infrastructure to support 2nd DAWR powerpc/watchpoint/kvm: Introduce new capability for 2nd DAWR powerpc/selftests/ptrace-hwbreak: Add testcases for 2nd DAWR powerpc/selftests/perf-hwbreak: Coalesce event creation code powerpc/selftests/perf-hwbreak: Add testcases for 2nd DAWR powerpc/selftests: Add selftest to test concurrent perf/ptrace events
Documentation/virt/kvm/api.rst | 6 +- arch/powerpc/include/asm/hvcall.h | 2 + arch/powerpc/include/asm/kvm_host.h | 6 +- arch/powerpc/include/uapi/asm/kvm.h | 8 +- arch/powerpc/kernel/asm-offsets.c | 6 +- arch/powerpc/kvm/book3s_hv.c | 73 +- arch/powerpc/kvm/book3s_hv_nested.c | 15 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 43 +- arch/powerpc/kvm/powerpc.c | 3 + include/uapi/linux/kvm.h | 1 + tools/arch/powerpc/include/uapi/asm/kvm.h | 8 +- .../selftests/powerpc/ptrace/.gitignore | 1 + .../testing/selftests/powerpc/ptrace/Makefile | 2 +- .../selftests/powerpc/ptrace/perf-hwbreak.c | 646 +++++++++++++++-- .../selftests/powerpc/ptrace/ptrace-hwbreak.c | 79 +++ .../powerpc/ptrace/ptrace-perf-hwbreak.c | 659 ++++++++++++++++++ 16 files changed, 1476 insertions(+), 82 deletions(-) create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace-perf-hwbreak.c
Signature · 1 line
2.26.2
PATCH 1/7 powerpc/watchpoint/kvm: Rename current DAWR macros and variables
Power10 is introducing second DAWR. Use real register names (with suffix 0) from ISA for current macros and variables used by kvm.
--- Documentation/virt/kvm/api.rst | 4 +-- arch/powerpc/include/asm/kvm_host.h | 4 +-- arch/powerpc/include/uapi/asm/kvm.h | 4 +-- arch/powerpc/kernel/asm-offsets.c | 4 +-- arch/powerpc/kvm/book3s_hv.c | 32 +++++++++++------------ arch/powerpc/kvm/book3s_hv_nested.c | 8 +++--- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 20 +++++++------- tools/arch/powerpc/include/uapi/asm/kvm.h | 4 +-- 8 files changed, 40 insertions(+), 40 deletions(-)
Documentation/virt/kvm/api.rst +2 -2
@@ -2219,8 +2219,8 @@ registers, find a list below: PPC KVM_REG_PPC_BESCR 64 PPC KVM_REG_PPC_TAR 64 PPC KVM_REG_PPC_DPDES 64 - PPC KVM_REG_PPC_DAWR 64 - PPC KVM_REG_PPC_DAWRX 64 + PPC KVM_REG_PPC_DAWR0 64 + PPC KVM_REG_PPC_DAWRX0 64 PPC KVM_REG_PPC_CIABR 64 PPC KVM_REG_PPC_IC 64 PPC KVM_REG_PPC_VTB 64
arch/powerpc/include/asm/kvm_host.h +2 -2
@@ -582,8 +582,8 @@ struct kvm_vcpu_arch {u32 ctrl;u32 dabrx;ulong dabr; -ulong dawr; -ulong dawrx; +ulong dawr0; +ulong dawrx0;ulong ciabr;ulong cfar;ulong ppr;
arch/powerpc/include/uapi/asm/kvm.h +2 -2
@@ -608,8 +608,8 @@ struct kvm_ppc_cpu_char {#define KVM_REG_PPC_BESCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa7)#define KVM_REG_PPC_TAR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa8)#define KVM_REG_PPC_DPDES (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa9) -#define KVM_REG_PPC_DAWR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xaa) -#define KVM_REG_PPC_DAWRX (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xab) +#define KVM_REG_PPC_DAWR0 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xaa) +#define KVM_REG_PPC_DAWRX0 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xab)#define KVM_REG_PPC_CIABR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xac)#define KVM_REG_PPC_IC (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xad)#define KVM_REG_PPC_VTB (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xae)
arch/powerpc/kernel/asm-offsets.c +2 -2
@@ -547,8 +547,8 @@ int main(void)OFFSET (VCPU_CTRL , kvm_vcpu, arch.ctrl);OFFSET (VCPU_DABR , kvm_vcpu, arch.dabr);OFFSET (VCPU_DABRX , kvm_vcpu, arch.dabrx); -OFFSET (VCPU_DAWR , kvm_vcpu, arch.dawr); -OFFSET (VCPU_DAWRX , kvm_vcpu, arch.dawrx); +OFFSET (VCPU_DAWR0 , kvm_vcpu, arch.dawr0); +OFFSET (VCPU_DAWRX0 , kvm_vcpu, arch.dawrx0);OFFSET (VCPU_CIABR , kvm_vcpu, arch.ciabr);OFFSET (VCPU_HFLAGS , kvm_vcpu, arch.hflags);OFFSET (VCPU_DEC , kvm_vcpu, arch.dec);
arch/powerpc/kvm/book3s_hv.c +16 -16
@@ -778,8 +778,8 @@ static int kvmppc_h_set_mode(struct kvm_vcpu *vcpu, unsigned long mflags,return H_UNSUPPORTED_FLAG_START ;if (value2 &DABRX_HYP )return H_P4 ; - vcpu->arch.dawr = value1; - vcpu->arch.dawrx = value2; + vcpu->arch.dawr0 = value1; + vcpu->arch.dawrx0 = value2;return H_SUCCESS ;case H_SET_MODE_RESOURCE_ADDR_TRANS_MODE :/* KVM does not support mflags=2 (AIL=2) */
@@ -1724,11 +1724,11 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,case KVM_REG_PPC_VTB : *val =get_reg_val (id, vcpu->arch.vcore->vtb);break ; -case KVM_REG_PPC_DAWR : - *val =get_reg_val (id, vcpu->arch.dawr); +case KVM_REG_PPC_DAWR0 : + *val =get_reg_val (id, vcpu->arch.dawr0);break ; -case KVM_REG_PPC_DAWRX : - *val =get_reg_val (id, vcpu->arch.dawrx); +case KVM_REG_PPC_DAWRX0 : + *val =get_reg_val (id, vcpu->arch.dawrx0);break ;case KVM_REG_PPC_CIABR : *val =get_reg_val (id, vcpu->arch.ciabr);
@@ -1938,11 +1938,11 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,case KVM_REG_PPC_VTB : vcpu->arch.vcore->vtb =set_reg_val (id, *val);break ; -case KVM_REG_PPC_DAWR : - vcpu->arch.dawr =set_reg_val (id, *val); +case KVM_REG_PPC_DAWR0 : + vcpu->arch.dawr0 =set_reg_val (id, *val);break ; -case KVM_REG_PPC_DAWRX : - vcpu->arch.dawrx =set_reg_val (id, *val) & ~DAWRX_HYP ; +case KVM_REG_PPC_DAWRX0 : + vcpu->arch.dawrx0 =set_reg_val (id, *val) & ~DAWRX_HYP ;break ;case KVM_REG_PPC_CIABR : vcpu->arch.ciabr =set_reg_val (id, *val);
@@ -3397,8 +3397,8 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,int trap;unsigned long host_hfscr =mfspr (SPRN_HFSCR );unsigned long host_ciabr =mfspr (SPRN_CIABR ); -unsigned long host_dawr =mfspr (SPRN_DAWR0 ); -unsigned long host_dawrx =mfspr (SPRN_DAWRX0 ); +unsigned long host_dawr0 =mfspr (SPRN_DAWR0 ); +unsigned long host_dawrx0 =mfspr (SPRN_DAWRX0 );unsigned long host_psscr =mfspr (SPRN_PSSCR );unsigned long host_pidr =mfspr (SPRN_PID );
@@ -3427,8 +3427,8 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,mtspr (SPRN_SPURR , vcpu->arch.spurr);if (dawr_enabled ()) { -mtspr (SPRN_DAWR0 , vcpu->arch.dawr); -mtspr (SPRN_DAWRX0 , vcpu->arch.dawrx); +mtspr (SPRN_DAWR0 , vcpu->arch.dawr0); +mtspr (SPRN_DAWRX0 , vcpu->arch.dawrx0); }mtspr (SPRN_CIABR , vcpu->arch.ciabr);mtspr (SPRN_IC , vcpu->arch.ic);
@@ -3480,8 +3480,8 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit, (local_paca->kvm_hstate.fake_suspend << PSSCR_FAKE_SUSPEND_LG));mtspr (SPRN_HFSCR , host_hfscr);mtspr (SPRN_CIABR , host_ciabr); -mtspr (SPRN_DAWR0 , host_dawr); -mtspr (SPRN_DAWRX0 , host_dawrx); +mtspr (SPRN_DAWR0 , host_dawr0); +mtspr (SPRN_DAWRX0 , host_dawrx0);mtspr (SPRN_PID , host_pidr);/*
arch/powerpc/kvm/book3s_hv_nested.c +4 -4
@@ -33,8 +33,8 @@ void kvmhv_save_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr) hr->dpdes = vc->dpdes; hr->hfscr = vcpu->arch.hfscr; hr->tb_offset = vc->tb_offset; - hr->dawr0 = vcpu->arch.dawr; - hr->dawrx0 = vcpu->arch.dawrx; + hr->dawr0 = vcpu->arch.dawr0; + hr->dawrx0 = vcpu->arch.dawrx0; hr->ciabr = vcpu->arch.ciabr; hr->purr = vcpu->arch.purr; hr->spurr = vcpu->arch.spurr;
@@ -151,8 +151,8 @@ static void restore_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr) vc->pcr = hr->pcr |PCR_MASK ; vc->dpdes = hr->dpdes; vcpu->arch.hfscr = hr->hfscr; - vcpu->arch.dawr = hr->dawr0; - vcpu->arch.dawrx = hr->dawrx0; + vcpu->arch.dawr0 = hr->dawr0; + vcpu->arch.dawrx0 = hr->dawrx0; vcpu->arch.ciabr = hr->ciabr; vcpu->arch.purr = hr->purr; vcpu->arch.spurr = hr->spurr;
arch/powerpc/kvm/book3s_hv_rmhandlers.S +10 -10
@@ -52,8 +52,8 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) #define STACK_SLOT_PID (SFS-32) #define STACK_SLOT_IAMR (SFS-40) #define STACK_SLOT_CIABR (SFS-48) -#define STACK_SLOT_DAWR (SFS-56) -#define STACK_SLOT_DAWRX (SFS-64) +#define STACK_SLOT_DAWR0 (SFS-56) +#define STACK_SLOT_DAWRX0 (SFS-64) #define STACK_SLOT_HFSCR (SFS-72) #define STACK_SLOT_AMR (SFS-80) #define STACK_SLOT_UAMOR (SFS-88)
@@ -711,8 +711,8 @@ BEGIN_FTR_SECTION mfspr r7, SPRN_DAWRX0 mfspr r8, SPRN_IAMR std r5, STACK_SLOT_CIABR(r1) - std r6, STACK_SLOT_DAWR(r1) - std r7, STACK_SLOT_DAWRX(r1) + std r6, STACK_SLOT_DAWR0(r1) + std r7, STACK_SLOT_DAWRX0(r1) std r8, STACK_SLOT_IAMR(r1) END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
@@ -801,8 +801,8 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) lbz r5, 0(r5) cmpdi r5, 0 beq 1f - ld r5, VCPU_DAWR(r4) - ld r6, VCPU_DAWRX(r4) + ld r5, VCPU_DAWR0(r4) + ld r6, VCPU_DAWRX0(r4) mtspr SPRN_DAWR0, r5 mtspr SPRN_DAWRX0, r6 1:
@@ -1759,8 +1759,8 @@ END_FTR_SECTION(CPU_FTR_TM | CPU_FTR_P9_TM_HV_ASSIST, 0) /* Restore host values of some registers */ BEGIN_FTR_SECTION ld r5, STACK_SLOT_CIABR(r1) - ld r6, STACK_SLOT_DAWR(r1) - ld r7, STACK_SLOT_DAWRX(r1) + ld r6, STACK_SLOT_DAWR0(r1) + ld r7, STACK_SLOT_DAWRX0(r1) mtspr SPRN_CIABR, r5 /* * If the DAWR doesn't work, it's ok to write these here as
@@ -2566,8 +2566,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) rlwimi r5, r4, 5, DAWRX_DR | DAWRX_DW rlwimi r5, r4, 2, DAWRX_WT clrrdi r4, r4, 3 - std r4, VCPU_DAWR(r3) - std r5, VCPU_DAWRX(r3) + std r4, VCPU_DAWR0(r3) + std r5, VCPU_DAWRX0(r3) /* * If came in through the real mode hcall handler then it is necessary * to write the registers since the return path won't. Otherwise it is
tools/arch/powerpc/include/uapi/asm/kvm.h +2 -2
@@ -608,8 +608,8 @@ struct kvm_ppc_cpu_char {#define KVM_REG_PPC_BESCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa7)#define KVM_REG_PPC_TAR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa8)#define KVM_REG_PPC_DPDES (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa9) -#define KVM_REG_PPC_DAWR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xaa) -#define KVM_REG_PPC_DAWRX (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xab) +#define KVM_REG_PPC_DAWR0 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xaa) +#define KVM_REG_PPC_DAWRX0 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xab)#define KVM_REG_PPC_CIABR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xac)#define KVM_REG_PPC_IC (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xad)#define KVM_REG_PPC_VTB (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xae)
Signature · 1 line
2.26.2
Re: [PATCH 1/7] powerpc/watchpoint/kvm: Rename current DAWR macros and variables
Quoted 2 lines · Ravi Bangoria
Power10 is introducing second DAWR. Use real register names (with suffix 0) from ISA for current macros and variables used by kvm.
Most of this looks fine, but I think we should not change the existing names in arch/powerpc/include/uapi/asm/kvm.h (and therefore also Documentation/virt/kvm/api.rst).
Quoted 15 lines
Documentation/virt/kvm/api.rst +2
-2@@ -2219,8 +2219,8 @@ registers, find a list below: PPC KVM_REG_PPC_BESCR 64 PPC KVM_REG_PPC_TAR 64 PPC KVM_REG_PPC_DPDES 64 - PPC KVM_REG_PPC_DAWR 64 - PPC KVM_REG_PPC_DAWRX 64 + PPC KVM_REG_PPC_DAWR0 64 + PPC KVM_REG_PPC_DAWRX0 64 PPC KVM_REG_PPC_CIABR 64 PPC KVM_REG_PPC_IC 64 PPC KVM_REG_PPC_VTB 64
...
Quoted 5 lines
arch/powerpc/include/uapi/asm/kvm.h +0
-0
arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 615
Quoted 10 lines
arch/powerpc/include/uapi/asm/kvm.h +2
-2@@ -608,8 +608,8 @@ struct kvm_ppc_cpu_char {#define KVM_REG_PPC_BESCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa7)#define KVM_REG_PPC_TAR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa8)#define KVM_REG_PPC_DPDES (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa9) -#define KVM_REG_PPC_DAWR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xaa) -#define KVM_REG_PPC_DAWRX (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xab) +#define KVM_REG_PPC_DAWR0 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xaa) +#define KVM_REG_PPC_DAWRX0 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xab)#define KVM_REG_PPC_CIABR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xac)#define KVM_REG_PPC_IC (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xad)#define KVM_REG_PPC_VTB (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xae)
The existing names are an API, and if you change them you will break compilation of existing userspace programs. I don't see that adding the '0' on the end is so important that we need to break userspace.
Paul.
Re: [PATCH 1/7] powerpc/watchpoint/kvm: Rename current DAWR macros and variables
Hi Paul,
Quoted 7 lines · Paul Mackerras
Quoted 2 lines · Ravi Bangoria
Power10 is introducing second DAWR. Use real register names (with suffix 0) from ISA for current macros and variables used by kvm.
Most of this looks fine, but I think we should not change the existing names in
arch/powerpc/include/uapi/asm/kvm.h(and therefore alsoDocumentation/virt/kvm/api.rst).
Missed that I'm changing uapi. I'll rename only those macros/variables which are not uapi.
Thanks,
Ravi
PATCH 2/7 powerpc/watchpoint/kvm: Add infrastructure to support 2nd DAWR
In reply to Ravi Bangoriakvm code assumes single DAWR everywhere. Add code to support 2nd DAWR. DAWR is a hypervisor resource and thus H_SET_MODE hcall is used to set/ unset it. Introduce new case H_SET_MODE_RESOURCE_SET_DAWR1 for 2nd DAWR. Also, kvm will support 2nd DAWR only if CPU_FTR_DAWR1 is set.
--- Documentation/virt/kvm/api.rst | 2 ++ arch/powerpc/include/asm/hvcall.h | 2 ++ arch/powerpc/include/asm/kvm_host.h | 2 ++ arch/powerpc/include/uapi/asm/kvm.h | 4 +++ arch/powerpc/kernel/asm-offsets.c | 2 ++ arch/powerpc/kvm/book3s_hv.c | 41 +++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_nested.c | 7 ++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 23 +++++++++++++ tools/arch/powerpc/include/uapi/asm/kvm.h | 4 +++ 9 files changed, 87 insertions(+)
Documentation/virt/kvm/api.rst +2 -0
@@ -2242,6 +2242,8 @@ 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_DAWR1 64 + PPC KVM_REG_PPC_DAWRX1 64 PPC KVM_REG_PPC_TM_GPR0 64 ... PPC KVM_REG_PPC_TM_GPR31 64
arch/powerpc/include/asm/hvcall.h +2 -0
@@ -538,6 +538,8 @@ struct hv_guest_state {s64 tb_offset;u64 dawr0;u64 dawrx0; +u64 dawr1; +u64 dawrx1;u64 ciabr;u64 hdec_expiry;u64 purr;
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -584,6 +584,8 @@ struct kvm_vcpu_arch {ulong dabr;ulong dawr0;ulong dawrx0; +ulong dawr1; +ulong dawrx1;ulong ciabr;ulong cfar;ulong ppr;
arch/powerpc/include/uapi/asm/kvm.h +4 -0
@@ -640,6 +640,10 @@ struct kvm_ppc_cpu_char {#define KVM_REG_PPC_ONLINE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xbf)#define KVM_REG_PPC_PTCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc0) +/* POWER10 registers. */ +#define KVM_REG_PPC_DAWR1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc1) +#define KVM_REG_PPC_DAWRX1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc2) +/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs */
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -549,6 +549,8 @@ int main(void)OFFSET (VCPU_DABRX , kvm_vcpu, arch.dabrx);OFFSET (VCPU_DAWR0 , kvm_vcpu, arch.dawr0);OFFSET (VCPU_DAWRX0 , kvm_vcpu, arch.dawrx0); +OFFSET (VCPU_DAWR1 , kvm_vcpu, arch.dawr1); +OFFSET (VCPU_DAWRX1 , kvm_vcpu, arch.dawrx1);OFFSET (VCPU_CIABR , kvm_vcpu, arch.ciabr);OFFSET (VCPU_HFLAGS , kvm_vcpu, arch.hflags);OFFSET (VCPU_DEC , kvm_vcpu, arch.dec);
arch/powerpc/kvm/book3s_hv.c +41 -0
77 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_nested.c +7 -0
@@ -35,6 +35,8 @@ void kvmhv_save_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr) hr->tb_offset = vc->tb_offset; hr->dawr0 = vcpu->arch.dawr0; hr->dawrx0 = vcpu->arch.dawrx0; + hr->dawr1 = vcpu->arch.dawr1; + hr->dawrx1 = vcpu->arch.dawrx1; hr->ciabr = vcpu->arch.ciabr; hr->purr = vcpu->arch.purr; hr->spurr = vcpu->arch.spurr;
@@ -72,6 +74,8 @@ static void byteswap_hv_regs(struct hv_guest_state *hr) hr->tb_offset =swab64 (hr->tb_offset); hr->dawr0 =swab64 (hr->dawr0); hr->dawrx0 =swab64 (hr->dawrx0); + hr->dawr1 =swab64 (hr->dawr1); + hr->dawrx1 =swab64 (hr->dawrx1); hr->ciabr =swab64 (hr->ciabr); hr->hdec_expiry =swab64 (hr->hdec_expiry); hr->purr =swab64 (hr->purr);
@@ -138,6 +142,7 @@ static void sanitise_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr)/* Don't let data address watchpoint match in hypervisor state */ hr->dawrx0 &= ~DAWRX_HYP ; + hr->dawrx1 &= ~DAWRX_HYP ;/* Don't let completed instruction address breakpt match in HV state */ if ((hr->ciabr &CIABR_PRIV ) ==CIABR_PRIV_HYPER )
@@ -153,6 +158,8 @@ static void restore_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr) vcpu->arch.hfscr = hr->hfscr; vcpu->arch.dawr0 = hr->dawr0; vcpu->arch.dawrx0 = hr->dawrx0; + vcpu->arch.dawr1 = hr->dawr1; + vcpu->arch.dawrx1 = hr->dawrx1; vcpu->arch.ciabr = hr->ciabr; vcpu->arch.purr = hr->purr; vcpu->arch.spurr = hr->spurr;
arch/powerpc/kvm/book3s_hv_rmhandlers.S +23 -0
@@ -57,6 +57,8 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) #define STACK_SLOT_HFSCR (SFS-72) #define STACK_SLOT_AMR (SFS-80) #define STACK_SLOT_UAMOR (SFS-88) +#define STACK_SLOT_DAWR1 (SFS-96) +#define STACK_SLOT_DAWRX1 (SFS-104) /* the following is used by the P9 short path */ #define STACK_SLOT_NVGPRS (SFS-152) /* 18 gprs */
@@ -715,6 +717,12 @@ BEGIN_FTR_SECTION std r7, STACK_SLOT_DAWRX0(r1) std r8, STACK_SLOT_IAMR(r1) END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) +BEGIN_FTR_SECTION + mfspr r6, SPRN_DAWR1 + mfspr r7, SPRN_DAWRX1 + std r6, STACK_SLOT_DAWR1(r1) + std r7, STACK_SLOT_DAWRX1(r1) +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S | CPU_FTR_DAWR1) mfspr r5, SPRN_AMR std r5, STACK_SLOT_AMR(r1)
@@ -805,6 +813,12 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) ld r6, VCPU_DAWRX0(r4) mtspr SPRN_DAWR0, r5 mtspr SPRN_DAWRX0, r6 +BEGIN_FTR_SECTION + ld r5, VCPU_DAWR1(r4) + ld r6, VCPU_DAWRX1(r4) + mtspr SPRN_DAWR1, r5 + mtspr SPRN_DAWRX1, r6 +END_FTR_SECTION_IFSET(CPU_FTR_DAWR1) 1: ld r7, VCPU_CIABR(r4) ld r8, VCPU_TAR(r4)
@@ -1769,6 +1783,12 @@ BEGIN_FTR_SECTION mtspr SPRN_DAWR0, r6 mtspr SPRN_DAWRX0, r7 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) +BEGIN_FTR_SECTION + ld r6, STACK_SLOT_DAWR1(r1) + ld r7, STACK_SLOT_DAWRX1(r1) + mtspr SPRN_DAWR1, r6 + mtspr SPRN_DAWRX1, r7 +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S | CPU_FTR_DAWR1) BEGIN_FTR_SECTION ld r5, STACK_SLOT_TID(r1) ld r6, STACK_SLOT_PSSCR(r1)
@@ -3335,6 +3355,9 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) mtspr SPRN_IAMR, r0 mtspr SPRN_CIABR, r0 mtspr SPRN_DAWRX0, r0 +BEGIN_FTR_SECTION + mtspr SPRN_DAWRX1, r0 +END_FTR_SECTION_IFSET(CPU_FTR_DAWR1) BEGIN_MMU_FTR_SECTION b 4f
tools/arch/powerpc/include/uapi/asm/kvm.h +4 -0
@@ -640,6 +640,10 @@ struct kvm_ppc_cpu_char {#define KVM_REG_PPC_ONLINE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xbf)#define KVM_REG_PPC_PTCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc0) +/* POWER10 registers. */ +#define KVM_REG_PPC_DAWR1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc1) +#define KVM_REG_PPC_DAWRX1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc2) +/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs */
Signature · 1 line
2.26.2
kernel test robot
build botRe: [PATCH 2/7] powerpc/watchpoint/kvm: Add infrastructure to support 2nd DAWR
Thank you for the patch! Yet something to improve:
Hi Ravi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on powerpc/next]
[also build test ERROR on kvm/linux-next v5.8-rc6 next-20200723] [cannot apply to kvm-ppc/kvm-ppc-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Ravi-Bangoria/powerpc-watchpoint-2nd-DAWR-kvm-enablement-selftests/20200723-182601 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next config: powerpc-defconfig (attached as .config) compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
arch/powerpc/kvm/book3s_hv_rmhandlers.S: Assembler messages:
>> arch/powerpc/kvm/book3s_hv_rmhandlers.S:725: Error: invalid operands (*ABS* and *UND* sections) for `|' >> arch/powerpc/kvm/book3s_hv_rmhandlers.S:725: Error: invalid operands (*ABS* and *UND* sections) for `|'
arch/powerpc/kvm/book3s_hv_rmhandlers.S:1791: Error: invalid operands (*ABS* and *UND* sections) for |' arch/powerpc/kvm/book3s_hv_rmhandlers.S:1791: Error: invalid operands (*ABS* and *UND* sections) for |'
--
arch/powerpc/kvm/book3s_hv.c: In function 'kvmppc_h_set_mode':
>> arch/powerpc/kvm/book3s_hv.c:779:7: error: 'H_SET_MODE_RESOURCE_SET_DAWR1' undeclared (first use in this function); did you mean 'H_SET_MODE_RESOURCE_SET_DAWR'?
779 | case H_SET_MODE_RESOURCE_SET_DAWR1:
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| H_SET_MODE_RESOURCE_SET_DAWR
arch/powerpc/kvm/book3s_hv.c:779:7: note: each undeclared identifier is reported only once for each function it appears in
>> arch/powerpc/kvm/book3s_hv.c:784:24: error: 'CPU_FTR_DAWR1' undeclared (first use in this function); did you mean 'CPU_FTR_DAWR'?
784 | if (!cpu_has_feature(CPU_FTR_DAWR1))
| ^~~~~~~~~~~~~
| CPU_FTR_DAWR
arch/powerpc/kvm/book3s_hv.c: In function 'kvmhv_load_hv_regs_and_go':
arch/powerpc/kvm/book3s_hv.c:3428:22: error: 'CPU_FTR_DAWR1' undeclared (first use in this function); did you mean 'CPU_FTR_DAWR'?
3428 | if (cpu_has_feature(CPU_FTR_DAWR1)) {
| ^~~~~~~~~~~~~
| CPU_FTR_DAWR arch/powerpc/kvm/book3s_hv.c: At top level:
arch/powerpc/kvm/book3s_hv.c:3557:5: error: no previous prototype for 'kvmhv_p9_guest_entry' [-Werror=missing-prototypes]
3557 | int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,
| ^~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
vim +725 arch/powerpc/kvm/book3s_hv_rmhandlers.S
664
665 /* Mark the subcore state as inside guest */
666 bl kvmppc_subcore_enter_guest
667 nop
668 ld r5, HSTATE_KVM_VCORE(r13)
669 ld r4, HSTATE_KVM_VCPU(r13)
670 li r0,1
671 stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */
672
673 /* Do we have a guest vcpu to run? */
674 10: cmpdi r4, 0
675 beq kvmppc_primary_no_guest
676 kvmppc_got_guest:
677 /* Increment yield count if they have a VPA */
678 ld r3, VCPU_VPA(r4)
679 cmpdi r3, 0
680 beq 25f
681 li r6, LPPACA_YIELDCOUNT
682 LWZX_BE r5, r3, r6
683 addi r5, r5, 1
684 STWX_BE r5, r3, r6
685 li r6, 1
686 stb r6, VCPU_VPA_DIRTY(r4)
687 25:
688
689 /* Save purr/spurr */
690 mfspr r5,SPRN_PURR
691 mfspr r6,SPRN_SPURR
692 std r5,HSTATE_PURR(r13)
693 std r6,HSTATE_SPURR(r13)
694 ld r7,VCPU_PURR(r4)
695 ld r8,VCPU_SPURR(r4)
696 mtspr SPRN_PURR,r7
697 mtspr SPRN_SPURR,r8
698
699 /* Save host values of some registers */
700 BEGIN_FTR_SECTION
701 mfspr r5, SPRN_TIDR
702 mfspr r6, SPRN_PSSCR
703 mfspr r7, SPRN_PID
704 std r5, STACK_SLOT_TID(r1)
705 std r6, STACK_SLOT_PSSCR(r1)
706 std r7, STACK_SLOT_PID(r1)
707 mfspr r5, SPRN_HFSCR
708 std r5, STACK_SLOT_HFSCR(r1)
709 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
710 BEGIN_FTR_SECTION
711 mfspr r5, SPRN_CIABR
712 mfspr r6, SPRN_DAWR0
713 mfspr r7, SPRN_DAWRX0
714 mfspr r8, SPRN_IAMR
715 std r5, STACK_SLOT_CIABR(r1)
716 std r6, STACK_SLOT_DAWR0(r1)
717 std r7, STACK_SLOT_DAWRX0(r1)
718 std r8, STACK_SLOT_IAMR(r1)
719 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
720 BEGIN_FTR_SECTION
721 mfspr r6, SPRN_DAWR1
722 mfspr r7, SPRN_DAWRX1
723 std r6, STACK_SLOT_DAWR1(r1)
724 std r7, STACK_SLOT_DAWRX1(r1)
> 725 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S | CPU_FTR_DAWR1)
726
727 mfspr r5, SPRN_AMR
728 std r5, STACK_SLOT_AMR(r1)
729 mfspr r6, SPRN_UAMOR
730 std r6, STACK_SLOT_UAMOR(r1)
731
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH 2/7] powerpc/watchpoint/kvm: Add infrastructure to support 2nd DAWR
In reply to Ravi BangoriaQuoted 3 lines · Ravi Bangoria
kvm code assumes single DAWR everywhere. Add code to support 2nd DAWR. DAWR is a hypervisor resource and thus
H_SET_MODEhcall is used to set/ unset it. Introduce new caseH_SET_MODE_RESOURCE_SET_DAWR1for 2nd DAWR.
Is this the same interface as will be defined in PAPR and available under PowerVM, or is it a new/different interface for KVM?
Quoted 1 line
Also, kvm will support 2nd DAWR only if
CPU_FTR_DAWR1is set.
In general QEMU wants to be able to control all aspects of the virtual machine presented to the guest, meaning that just because a host has a particular hardware capability does not mean we should automatically present that capability to the guest.
In this case, QEMU will want a way to control whether the guest sees the availability of the second DAWR/X registers or not, i.e. whether a H_SET_MODE to set DAWR[X]1 will succeed or fail.
Paul.
Re: [PATCH 2/7] powerpc/watchpoint/kvm: Add infrastructure to support 2nd DAWR
Hi Paul,
Quoted 7 lines · Paul Mackerras
Quoted 3 lines · Ravi Bangoria
kvm code assumes single DAWR everywhere. Add code to support 2nd DAWR. DAWR is a hypervisor resource and thus
H_SET_MODEhcall is used to set/ unset it. Introduce new caseH_SET_MODE_RESOURCE_SET_DAWR1for 2nd DAWR.Is this the same interface as will be defined in PAPR and available under PowerVM, or is it a new/different interface for KVM?
Yes, kvm hcall interface for 2nd DAWR is same as PowerVM, as defined in PAPR.
Quoted 11 lines
Quoted 2 lines
Also, kvm will support 2nd DAWR only if
CPU_FTR_DAWR1is set.In general QEMU wants to be able to control all aspects of the virtual machine presented to the guest, meaning that just because a host has a particular hardware capability does not mean we should automatically present that capability to the guest.
In this case, QEMU will want a way to control whether the guest sees the availability of the second DAWR/X registers or not, i.e. whether a
H_SET_MODEto set DAWR[X]1 will succeed or fail.
Patch #3 adds new kvm capability KVM_CAP_PPC_DAWR1 that can be checked by Qemu. Also, as suggested by David in Qemu patch[1], I'm planning to add new machine capability in Qemu:
-machine cap-dawr1=ON/OFF
cap-dawr1 will be default ON when PPC_FEATURE2_ARCH_3_10 is set and OFF otherwise.
Is this correct approach?
[1]: https://lore.kernel.org/kvm/[email protected]
Thanks,
Ravi
Re: [PATCH 2/7] powerpc/watchpoint/kvm: Add infrastructure to support 2nd DAWR
In reply to Ravi BangoriaHi Paul,
arch/powerpc/include/asm/hvcall.h struct hv_guest_state { · line 545
Quoted 13 lines
arch/powerpc/include/asm/hvcall.h +2
-0@@ -538,6 +538,8 @@ struct hv_guest_state {s64 tb_offset;u64 dawr0;u64 dawrx0; +u64 dawr1; +u64 dawrx1;u64 ciabr;u64 hdec_expiry;u64 purr;
After this struct, there is a macro HV_GUEST_STATE_VERSION, I guess that also needs to be incremented because I'm adding new members in the struct?
Thanks,
Ravi
PATCH 3/7 powerpc/watchpoint/kvm: Introduce new capability for 2nd DAWR
In reply to Ravi BangoriaIntroduce KVM_CAP_PPC_DAWR1 which can be used by Qemu to query whether kvm supports 2nd DAWR or not.
--- arch/powerpc/kvm/powerpc.c | 3 +++ include/uapi/linux/kvm.h | 1 + 2 files changed, 4 insertions(+)
arch/powerpc/kvm/powerpc.c +3 -0
@@ -676,6 +676,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) !kvmppc_hv_ops->enable_svm (NULL );break ;#endif +case KVM_CAP_PPC_DAWR1 : + r =cpu_has_feature (CPU_FTR_DAWR1 ); +break ;default : r =0 ;break ;
include/uapi/linux/kvm.h +1 -0
@@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_PPC_SECURE_GUEST 181#define KVM_CAP_HALT_POLL 182#define KVM_CAP_ASYNC_PF_INT 183 +#define KVM_CAP_PPC_DAWR1 184#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.26.2
kernel test robot
build botRe: [PATCH 3/7] powerpc/watchpoint/kvm: Introduce new capability for 2nd DAWR
Thank you for the patch! Yet something to improve:
Hi Ravi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on powerpc/next]
[also build test ERROR on v5.8-rc6]
[cannot apply to kvm/linux-next kvm-ppc/kvm-ppc-next next-20200723] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Ravi-Bangoria/powerpc-watchpoint-2nd-DAWR-kvm-enablement-selftests/20200723-182601 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next config: powerpc-defconfig (attached as .config) compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
arch/powerpc/kvm/powerpc.c: In function 'kvm_vm_ioctl_check_extension':
>> arch/powerpc/kvm/powerpc.c:680:23: error: 'CPU_FTR_DAWR1' undeclared (first use in this function); did you mean 'CPU_FTR_DAWR'?
680 | r = cpu_has_feature(CPU_FTR_DAWR1);
| ^~~~~~~~~~~~~
| CPU_FTR_DAWR arch/powerpc/kvm/powerpc.c:680:23: note: each undeclared identifier is reported only once for each function it appears in arch/powerpc/kvm/powerpc.c: At top level:
arch/powerpc/kvm/powerpc.c:1521:5: error: no previous prototype for 'kvmppc_get_vmx_dword' [-Werror=missing-prototypes]
1521 | int kvmppc_get_vmx_dword(struct kvm_vcpu *vcpu, int index, u64 *val)
| ^~~~~~~~~~~~~~~~~~~~
arch/powerpc/kvm/powerpc.c:1539:5: error: no previous prototype for 'kvmppc_get_vmx_word' [-Werror=missing-prototypes]
1539 | int kvmppc_get_vmx_word(struct kvm_vcpu *vcpu, int index, u64 *val)
| ^~~~~~~~~~~~~~~~~~~
arch/powerpc/kvm/powerpc.c:1557:5: error: no previous prototype for 'kvmppc_get_vmx_hword' [-Werror=missing-prototypes]
1557 | int kvmppc_get_vmx_hword(struct kvm_vcpu *vcpu, int index, u64 *val)
| ^~~~~~~~~~~~~~~~~~~~
arch/powerpc/kvm/powerpc.c:1575:5: error: no previous prototype for 'kvmppc_get_vmx_byte' [-Werror=missing-prototypes]
1575 | int kvmppc_get_vmx_byte(struct kvm_vcpu *vcpu, int index, u64 *val)
| ^~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
vim +680 arch/powerpc/kvm/powerpc.c
571
572 case KVM_CAP_PPC_ALLOC_HTAB:
573 r = hv_enabled;
574 break;
575 #endif /* CONFIG_PPC_BOOK3S_64 */
576 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
577 case KVM_CAP_PPC_SMT:
578 r = 0;
579 if (kvm) {
580 if (kvm->arch.emul_smt_mode > 1)
581 r = kvm->arch.emul_smt_mode;
582 else
583 r = kvm->arch.smt_mode;
584 } else if (hv_enabled) {
585 if (cpu_has_feature(CPU_FTR_ARCH_300))
586 r = 1;
587 else
588 r = threads_per_subcore;
589 }
590 break;
591 case KVM_CAP_PPC_SMT_POSSIBLE:
592 r = 1;
593 if (hv_enabled) {
594 if (!cpu_has_feature(CPU_FTR_ARCH_300))
595 r = ((threads_per_subcore << 1) - 1);
596 else
597 /* P9 can emulate dbells, so allow any mode */
598 r = 8 | 4 | 2 | 1;
599 }
600 break;
601 case KVM_CAP_PPC_RMA:
602 r = 0;
603 break;
604 case KVM_CAP_PPC_HWRNG:
605 r = kvmppc_hwrng_present();
606 break;
607 case KVM_CAP_PPC_MMU_RADIX:
608 r = !!(hv_enabled && radix_enabled());
609 break;
610 case KVM_CAP_PPC_MMU_HASH_V3:
611 r = !!(hv_enabled && cpu_has_feature(CPU_FTR_ARCH_300) &&
612 cpu_has_feature(CPU_FTR_HVMODE));
613 break;
614 case KVM_CAP_PPC_NESTED_HV:
615 r = !!(hv_enabled && kvmppc_hv_ops->enable_nested &&
616 !kvmppc_hv_ops->enable_nested(NULL));
617 break;
618 #endif
619 case KVM_CAP_SYNC_MMU:
620 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
621 r = hv_enabled;
622 #elif defined(KVM_ARCH_WANT_MMU_NOTIFIER)
623 r = 1;
624 #else
625 r = 0;
626 #endif
627 break;
628 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
629 case KVM_CAP_PPC_HTAB_FD:
630 r = hv_enabled;
631 break;
632 #endif
633 case KVM_CAP_NR_VCPUS:
634 /*
635 * Recommending a number of CPUs is somewhat arbitrary; we
636 * return the number of present CPUs for -HV (since a host
637 * will have secondary threads "offline"), and for other KVM
638 * implementations just count online CPUs.
639 */
640 if (hv_enabled)
641 r = num_present_cpus();
642 else
643 r = num_online_cpus();
644 break;
645 case KVM_CAP_MAX_VCPUS:
646 r = KVM_MAX_VCPUS;
647 break;
648 case KVM_CAP_MAX_VCPU_ID:
649 r = KVM_MAX_VCPU_ID;
650 break;
651 #ifdef CONFIG_PPC_BOOK3S_64
652 case KVM_CAP_PPC_GET_SMMU_INFO:
653 r = 1;
654 break;
655 case KVM_CAP_SPAPR_MULTITCE:
656 r = 1;
657 break;
658 case KVM_CAP_SPAPR_RESIZE_HPT:
659 r = !!hv_enabled;
660 break;
661 #endif
662 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
663 case KVM_CAP_PPC_FWNMI:
664 r = hv_enabled;
665 break;
666 #endif
667 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
668 case KVM_CAP_PPC_HTM:
669 r = !!(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_HTM) ||
670 (hv_enabled && cpu_has_feature(CPU_FTR_P9_TM_HV_ASSIST));
671 break;
672 #endif
673 #if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE)
674 case KVM_CAP_PPC_SECURE_GUEST:
675 r = hv_enabled && kvmppc_hv_ops->enable_svm &&
676 !kvmppc_hv_ops->enable_svm(NULL);
677 break;
678 #endif
679 case KVM_CAP_PPC_DAWR1:
> 680 r = cpu_has_feature(CPU_FTR_DAWR1);
681 break;
682 default:
683 r = 0;
684 break;
685 }
686 return r;
687
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 4/7 powerpc/selftests/ptrace-hwbreak: Add testcases for 2nd DAWR
In reply to Ravi BangoriaAdd selftests to test multiple active DAWRs with ptrace interface.
Sample o/p:
$ ./ptrace-hwbreak ... PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED, WO, len: 6: Ok PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED, RO, len: 6: Ok PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, WO, len: 6: Ok PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, RO, len: 6: Ok
--- .../selftests/powerpc/ptrace/ptrace-hwbreak.c | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+)
tools/testing/selftests/powerpc/ptrace/ptrace-hwbreak.c +79 -0
@@ -185,6 +185,18 @@ static void test_workload(void) big_var[rand () %DAWR_MAX_LEN ] ='a' ; else cvar = big_var[rand () %DAWR_MAX_LEN ]; + +/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED, WO test */ + gstruct.a[rand () %A_LEN ] ='a' ; + +/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED, RO test */ + cvar = gstruct.b[rand () %B_LEN ]; + +/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, WO test */ + gstruct.a[rand () %A_LEN ] ='a' ; + +/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, RO test */ + cvar = gstruct.a[rand () %A_LEN ]; } static void check_success(pid_t child_pid, const char *name, const char *type,
@@ -374,6 +386,69 @@ static void test_sethwdebug_range_aligned(pid_t child_pid)ptrace_delhwdebug (child_pid, wh); } +static void test_multi_sethwdebug_range (pid_t child_pid) +{ +struct ppc_hw_breakpoint info1, info2; +unsigned long wp_addr1, wp_addr2; +char *name1 ="PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED" ; +char *name2 ="PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED" ; +int len1, len2; +int wh1, wh2; + + wp_addr1 = (unsigned long )&gstruct.a; + wp_addr2 = (unsigned long )&gstruct.b; + len1 =A_LEN ; + len2 =B_LEN ; +get_ppc_hw_breakpoint (&info1,PPC_BREAKPOINT_TRIGGER_WRITE , wp_addr1, len1); +get_ppc_hw_breakpoint (&info2,PPC_BREAKPOINT_TRIGGER_READ , wp_addr2, len2); + +/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED, WO test */ + wh1 =ptrace_sethwdebug (child_pid, &info1); + +/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED, RO test */ + wh2 =ptrace_sethwdebug (child_pid, &info2); + +ptrace (PTRACE_CONT , child_pid,NULL ,0 ); +check_success (child_pid, name1,"WO" , wp_addr1, len1); + +ptrace (PTRACE_CONT , child_pid,NULL ,0 ); +check_success (child_pid, name2,"RO" , wp_addr2, len2); + +ptrace_delhwdebug (child_pid, wh1); +ptrace_delhwdebug (child_pid, wh2); +} + +static void test_multi_sethwdebug_range_dawr_overlap (pid_t child_pid) +{ +struct ppc_hw_breakpoint info1, info2; +unsigned long wp_addr1, wp_addr2; +char *name ="PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap" ; +int len1, len2; +int wh1, wh2; + + wp_addr1 = (unsigned long )&gstruct.a; + wp_addr2 = (unsigned long )&gstruct.a; + len1 =A_LEN ; + len2 =A_LEN ; +get_ppc_hw_breakpoint (&info1,PPC_BREAKPOINT_TRIGGER_WRITE , wp_addr1, len1); +get_ppc_hw_breakpoint (&info2,PPC_BREAKPOINT_TRIGGER_READ , wp_addr2, len2); + +/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, WO test */ + wh1 =ptrace_sethwdebug (child_pid, &info1); + +/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, RO test */ + wh2 =ptrace_sethwdebug (child_pid, &info2); + +ptrace (PTRACE_CONT , child_pid,NULL ,0 ); +check_success (child_pid, name,"WO" , wp_addr1, len1); + +ptrace (PTRACE_CONT , child_pid,NULL ,0 ); +check_success (child_pid, name,"RO" , wp_addr2, len2); + +ptrace_delhwdebug (child_pid, wh1); +ptrace_delhwdebug (child_pid, wh2); +} +static void test_sethwdebug_range_unaligned (pid_t child_pid) {struct ppc_hw_breakpoint info;
@@ -460,6 +535,10 @@ run_tests(pid_t child_pid, struct ppc_debug_info *dbginfo, bool dawr)test_sethwdebug_range_unaligned (child_pid);test_sethwdebug_range_unaligned_dar (child_pid);test_sethwdebug_dawr_max_range (child_pid); +if (dbginfo->num_data_bps >1 ) { +test_multi_sethwdebug_range (child_pid); +test_multi_sethwdebug_range_dawr_overlap (child_pid); + } } } }
Signature · 1 line
2.26.2
PATCH 5/7 powerpc/selftests/perf-hwbreak: Coalesce event creation code
In reply to Ravi Bangoriaperf-hwbreak selftest opens hw-breakpoint event at multiple places for which it has same code repeated. Coalesce that code into a function.
--- .../selftests/powerpc/ptrace/perf-hwbreak.c | 78 +++++++++---------- 1 file changed, 38 insertions(+), 40 deletions(-)
tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c +38 -40
@@ -34,28 +34,46 @@#define DAWR_LENGTH_MAX ((0x3f + 1) * 8) -static inline int sys_perf_event_open (struct perf_event_attr *attr,pid_t pid, -int cpu,int group_fd, -unsigned long flags) +static void perf_event_attr_set (struct perf_event_attr *attr, +__u32 type,__u64 addr,__u64 len, +bool exclude_user) { - attr->size =sizeof (*attr); -return syscall (__NR_perf_event_open, attr, pid, cpu, group_fd, flags); +memset (attr,0 ,sizeof (struct perf_event_attr )); + attr->type =PERF_TYPE_BREAKPOINT ; + attr->size =sizeof (struct perf_event_attr ); + attr->bp_type = type; + attr->bp_addr = addr; + attr->bp_len = len; + attr->exclude_kernel =1 ; + attr->exclude_hv =1 ; + attr->exclude_guest =1 ; + attr->exclude_user = exclude_user; + attr->disabled =1 ; } -static inline bool breakpoint_test (int len) +static int +perf_process_event_open_exclude_user (__u32 type,__u64 addr,__u64 len,bool exclude_user) {struct perf_event_attr attr; + +perf_event_attr_set (&attr, type, addr, len, exclude_user); +return syscall (__NR_perf_event_open, &attr,getpid (),-1 ,-1 ,0 ); +} + +static int perf_process_event_open (__u32 type,__u64 addr,__u64 len) +{ +struct perf_event_attr attr; + +perf_event_attr_set (&attr, type, addr, len,0 ); +return syscall (__NR_perf_event_open, &attr,getpid (),-1 ,-1 ,0 ); +} + +static inline bool breakpoint_test (int len) +{int fd; -/* setup counters */ -memset (&attr,0 ,sizeof (attr)); - attr.disabled =1 ; - attr.type =PERF_TYPE_BREAKPOINT ; - attr.bp_type =HW_BREAKPOINT_R ;/* bp_addr can point anywhere but needs to be aligned */ - attr.bp_addr = (__u64)(&attr) &0xfffffffffffff800 ; - attr.bp_len = len; - fd =sys_perf_event_open (&attr,0 ,-1 ,-1 ,0 ); + fd =perf_process_event_open (HW_BREAKPOINT_R , (__u64)(&fd) &0xfffffffffffff800 , len);if (fd <0 )return false;close (fd);
@@ -75,7 +93,6 @@ static inline bool dawr_supported(void)static int runtestsingle (int readwriteflag,int exclude_user,int arraytest) {int i,j; -struct perf_event_attr attr;size_t res;unsigned long long breaks, needed;int readint;
@@ -94,19 +111,11 @@ static int runtestsingle(int readwriteflag, int exclude_user, int arraytest)if (arraytest) ptr = &readintalign[0 ]; -/* setup counters */ -memset (&attr,0 ,sizeof (attr)); - attr.disabled =1 ; - attr.type =PERF_TYPE_BREAKPOINT ; - attr.bp_type = readwriteflag; - attr.bp_addr = (__u64 )ptr; - attr.bp_len =sizeof (int ); -if (arraytest) - attr.bp_len =DAWR_LENGTH_MAX ; - attr.exclude_user = exclude_user; - break_fd =sys_perf_event_open (&attr,0 ,-1 ,-1 ,0 ); + break_fd =perf_process_event_open_exclude_user (readwriteflag, (__u64 )ptr, + arraytest ?DAWR_LENGTH_MAX :sizeof (int ), + exclude_user);if (break_fd <0 ) { -perror ("sys_perf_event_open" ); +perror ("perf_process_event_open_exclude_user" );exit (1 ); }
@@ -153,7 +162,6 @@ static int runtest_dar_outside(void)void *target;volatile __u16 temp16;volatile __u64 temp64; -struct perf_event_attr attr;int break_fd;unsigned long long breaks;int fail =0 ;
@@ -165,21 +173,11 @@ static int runtest_dar_outside(void)exit (EXIT_FAILURE ); } -/* setup counters */ -memset (&attr,0 ,sizeof (attr)); - attr.disabled =1 ; - attr.type =PERF_TYPE_BREAKPOINT ; - attr.exclude_kernel =1 ; - attr.exclude_hv =1 ; - attr.exclude_guest =1 ; - attr.bp_type =HW_BREAKPOINT_RW ;/* watch middle half of target array */ - attr.bp_addr = (__u64)(target +2 ); - attr.bp_len =4 ; - break_fd =sys_perf_event_open (&attr,0 ,-1 ,-1 ,0 ); + break_fd =perf_process_event_open (HW_BREAKPOINT_RW , (__u64)(target +2 ),4 );if (break_fd <0 ) {free (target); -perror ("sys_perf_event_open" ); +perror ("perf_process_event_open" );exit (EXIT_FAILURE ); }
Signature · 1 line
2.26.2
PATCH 6/7 powerpc/selftests/perf-hwbreak: Add testcases for 2nd DAWR
In reply to Ravi BangoriaExtend perf-hwbreak.c selftest to test multiple DAWRs. Also add testcase for testing 512 byte boundary removal.
Sample o/p:
# ./perf-hwbreak ... TESTED: Process specific, Two events, diff addr TESTED: Process specific, Two events, same addr TESTED: Process specific, Two events, diff addr, one is RO, other is WO TESTED: Process specific, Two events, same addr, one is RO, other is WO TESTED: Systemwide, Two events, diff addr TESTED: Systemwide, Two events, same addr TESTED: Systemwide, Two events, diff addr, one is RO, other is WO TESTED: Systemwide, Two events, same addr, one is RO, other is WO TESTED: Process specific, 512 bytes, unaligned success: perf_hwbreak
--- .../selftests/powerpc/ptrace/perf-hwbreak.c | 568 +++++++++++++++++- 1 file changed, 567 insertions(+), 1 deletion(-)
tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c +567 -1
@@ -21,8 +21,13 @@#include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <signal.h> #include <string.h> #include <sys/ioctl.h> +#include <sys/wait.h> +#include <sys/ptrace.h> +#include <sys/sysinfo.h> +#include <asm/ptrace.h> #include <elf.h> #include <pthread.h> #include <sys/syscall.h>
@@ -34,6 +39,12 @@#define DAWR_LENGTH_MAX ((0x3f + 1) * 8) +int nprocs; + +static volatile int a =10 ; +static volatile int b =10 ; +static volatile char c[512 + 8] __attribute__((aligned(512))); +static void perf_event_attr_set (struct perf_event_attr *attr,__u32 type,__u64 addr,__u64 len,bool exclude_user)
@@ -68,6 +79,76 @@ static int perf_process_event_open(__u32 type, __u64 addr, __u64 len)return syscall (__NR_perf_event_open, &attr,getpid (),-1 ,-1 ,0 ); } +static int perf_cpu_event_open (long cpu,__u32 type,__u64 addr,__u64 len) +{ +struct perf_event_attr attr; + +perf_event_attr_set (&attr, type, addr, len,0 ); +return syscall (__NR_perf_event_open, &attr,-1 , cpu,-1 ,0 ); +} + +static void close_fds (int *fd,int n) +{ +int i; + +for (i =0 ; i < n; i++) +close (fd[i]); +} + +static unsigned long read_fds (int *fd,int n) +{ +int i; +unsigned long c =0 ; +unsigned long count =0 ; +size_t res; + +for (i =0 ; i < n; i++) { + res =read (fd[i], &c,sizeof (c)); +assert (res ==sizeof (unsigned long long )); + count += c; + } +return count; +} + +static void reset_fds (int *fd,int n) +{ +int i; + +for (i =0 ; i < n; i++) +ioctl (fd[i],PERF_EVENT_IOC_RESET ); +} + +static void enable_fds (int *fd,int n) +{ +int i; + +for (i =0 ; i < n; i++) +ioctl (fd[i],PERF_EVENT_IOC_ENABLE ); +} + +static void disable_fds (int *fd,int n) +{ +int i; + +for (i =0 ; i < n; i++) +ioctl (fd[i],PERF_EVENT_IOC_DISABLE ); +} + +static int perf_systemwide_event_open (int *fd,__u32 type,__u64 addr,__u64 len) +{ +int i =0 ; + +/* Assume online processors are 0 to nprocs for simplisity */ +for (i =0 ; i < nprocs; i++) { + fd[i] =perf_cpu_event_open (i, type, addr, len); +if (fd[i] <0 ) { +close_fds (fd, i); +return fd[i]; + } + } +return 0 ; +} +static inline bool breakpoint_test (int len) {int fd;
@@ -261,11 +342,483 @@ static int runtest_dar_outside(void)return fail; } +static void multi_dawr_workload (void ) +{ + a +=10 ; + b +=10 ; + c[512 +1 ] +='a' ; +} + +static int test_process_multi_diff_addr (void ) +{ +unsigned long long breaks1 =0 , breaks2 =0 ; +int fd1, fd2; +char *desc ="Process specific, Two events, diff addr" ; +size_t res; + + fd1 =perf_process_event_open (HW_BREAKPOINT_RW , (__u64)&a, (__u64 )sizeof (a)); +if (fd1 <0 ) { +perror ("perf_process_event_open" ); +exit (EXIT_FAILURE ); + } + + fd2 =perf_process_event_open (HW_BREAKPOINT_RW , (__u64)&b, (__u64 )sizeof (b)); +if (fd2 <0 ) { +close (fd1); +perror ("perf_process_event_open" ); +exit (EXIT_FAILURE ); + } + +ioctl (fd1,PERF_EVENT_IOC_RESET ); +ioctl (fd2,PERF_EVENT_IOC_RESET ); +ioctl (fd1,PERF_EVENT_IOC_ENABLE ); +ioctl (fd2,PERF_EVENT_IOC_ENABLE ); +multi_dawr_workload (); +ioctl (fd1,PERF_EVENT_IOC_DISABLE ); +ioctl (fd2,PERF_EVENT_IOC_DISABLE ); + + res =read (fd1, &breaks1,sizeof (breaks1)); +assert (res ==sizeof (unsigned long long )); + res =read (fd2, &breaks2,sizeof (breaks2)); +assert (res ==sizeof (unsigned long long )); + +close (fd1); +close (fd2); + +if (breaks1 !=2 || breaks2 !=2 ) { +printf ("FAILED: %s: %lld != 2 || %lld != 2\n" , desc, + breaks1, breaks2); +return 1 ; + } + +printf ("TESTED: %s\n" , desc); +return 0 ; +} + +static int test_process_multi_same_addr (void ) +{ +unsigned long long breaks1 =0 , breaks2 =0 ; +int fd1, fd2; +char *desc ="Process specific, Two events, same addr" ; +size_t res; + + fd1 =perf_process_event_open (HW_BREAKPOINT_RW , (__u64)&a, (__u64 )sizeof (a)); +if (fd1 <0 ) { +perror ("perf_process_event_open" ); +exit (EXIT_FAILURE ); + } + + fd2 =perf_process_event_open (HW_BREAKPOINT_RW , (__u64)&a, (__u64 )sizeof (a)); +if (fd2 <0 ) { +close (fd1); +perror ("perf_process_event_open" ); +exit (EXIT_FAILURE ); + } + +ioctl (fd1,PERF_EVENT_IOC_RESET ); +ioctl (fd2,PERF_EVENT_IOC_RESET ); +ioctl (fd1,PERF_EVENT_IOC_ENABLE ); +ioctl (fd2,PERF_EVENT_IOC_ENABLE ); +multi_dawr_workload (); +ioctl (fd1,PERF_EVENT_IOC_DISABLE ); +ioctl (fd2,PERF_EVENT_IOC_DISABLE ); + + res =read (fd1, &breaks1,sizeof (breaks1)); +assert (res ==sizeof (unsigned long long )); + res =read (fd2, &breaks2,sizeof (breaks2)); +assert (res ==sizeof (unsigned long long )); + +close (fd1); +close (fd2); + +if (breaks1 !=2 || breaks2 !=2 ) { +printf ("FAILED: %s: %lld != 2 || %lld != 2\n" , desc, + breaks1, breaks2); +return 1 ; + } + +printf ("TESTED: %s\n" , desc); +return 0 ; +} + +static int test_process_multi_diff_addr_ro_wo (void ) +{ +unsigned long long breaks1 =0 , breaks2 =0 ; +int fd1, fd2; +char *desc ="Process specific, Two events, diff addr, one is RO, other is WO" ; +size_t res; + + fd1 =perf_process_event_open (HW_BREAKPOINT_W , (__u64)&a, (__u64 )sizeof (a)); +if (fd1 <0 ) { +perror ("perf_process_event_open" ); +exit (EXIT_FAILURE ); + } + + fd2 =perf_process_event_open (HW_BREAKPOINT_R , (__u64)&b, (__u64 )sizeof (b)); +if (fd2 <0 ) { +close (fd1); +perror ("perf_process_event_open" ); +exit (EXIT_FAILURE ); + } + +ioctl (fd1,PERF_EVENT_IOC_RESET ); +ioctl (fd2,PERF_EVENT_IOC_RESET ); +ioctl (fd1,PERF_EVENT_IOC_ENABLE ); +ioctl (fd2,PERF_EVENT_IOC_ENABLE ); +multi_dawr_workload (); +ioctl (fd1,PERF_EVENT_IOC_DISABLE ); +ioctl (fd2,PERF_EVENT_IOC_DISABLE ); + + res =read (fd1, &breaks1,sizeof (breaks1)); +assert (res ==sizeof (unsigned long long )); + res =read (fd2, &breaks2,sizeof (breaks2)); +assert (res ==sizeof (unsigned long long )); + +close (fd1); +close (fd2); + +if (breaks1 !=1 || breaks2 !=1 ) { +printf ("FAILED: %s: %lld != 1 || %lld != 1\n" , desc, + breaks1, breaks2); +return 1 ; + } + +printf ("TESTED: %s\n" , desc); +return 0 ; +} + +static int test_process_multi_same_addr_ro_wo (void ) +{ +unsigned long long breaks1 =0 , breaks2 =0 ; +int fd1, fd2; +char *desc ="Process specific, Two events, same addr, one is RO, other is WO" ; +size_t res; + + fd1 =perf_process_event_open (HW_BREAKPOINT_R , (__u64)&a, (__u64 )sizeof (a)); +if (fd1 <0 ) { +perror ("perf_process_event_open" ); +exit (EXIT_FAILURE ); + } + + fd2 =perf_process_event_open (HW_BREAKPOINT_W , (__u64)&a, (__u64 )sizeof (a)); +if (fd2 <0 ) { +close (fd1); +perror ("perf_process_event_open" ); +exit (EXIT_FAILURE ); + } + +ioctl (fd1,PERF_EVENT_IOC_RESET ); +ioctl (fd2,PERF_EVENT_IOC_RESET ); +ioctl (fd1,PERF_EVENT_IOC_ENABLE ); +ioctl (fd2,PERF_EVENT_IOC_ENABLE ); +multi_dawr_workload (); +ioctl (fd1,PERF_EVENT_IOC_DISABLE ); +ioctl (fd2,PERF_EVENT_IOC_DISABLE ); + + res =read (fd1, &breaks1,sizeof (breaks1)); +assert (res ==sizeof (unsigned long long )); + res =read (fd2, &breaks2,sizeof (breaks2)); +assert (res ==sizeof (unsigned long long )); + +close (fd1); +close (fd2); + +if (breaks1 !=1 || breaks2 !=1 ) { +printf ("FAILED: %s: %lld != 1 || %lld != 1\n" , desc, + breaks1, breaks2); +return 1 ; + } + +printf ("TESTED: %s\n" , desc); +return 0 ; +} + +static int test_syswide_multi_diff_addr (void ) +{ +unsigned long long breaks1 =0 , breaks2 =0 ; +int *fd1 =malloc (nprocs *sizeof (int )); +int *fd2 =malloc (nprocs *sizeof (int )); +char *desc ="Systemwide, Two events, diff addr" ; +int ret; + + ret =perf_systemwide_event_open (fd1,HW_BREAKPOINT_RW , (__u64)&a, + (__u64 )sizeof (a)); +if (ret) { +perror ("perf_systemwide_event_open" ); +exit (EXIT_FAILURE ); + } + + ret =perf_systemwide_event_open (fd2,HW_BREAKPOINT_RW , (__u64)&b, + (__u64 )sizeof (b)); +if (ret) { +close_fds (fd1, nprocs); +perror ("perf_systemwide_event_open" ); +exit (EXIT_FAILURE ); + } + +reset_fds (fd1, nprocs); +reset_fds (fd2, nprocs); +enable_fds (fd1, nprocs); +enable_fds (fd2, nprocs); +multi_dawr_workload (); +disable_fds (fd1, nprocs); +disable_fds (fd2, nprocs); + + breaks1 =read_fds (fd1, nprocs); + breaks2 =read_fds (fd2, nprocs); + +close_fds (fd1, nprocs); +close_fds (fd2, nprocs); + +free (fd1); +free (fd2); + +if (breaks1 !=2 || breaks2 !=2 ) { +printf ("FAILED: %s: %lld != 2 || %lld != 2\n" , desc, + breaks1, breaks2); +return 1 ; + } + +printf ("TESTED: %s\n" , desc); +return 0 ; +} + +static int test_syswide_multi_same_addr (void ) +{ +unsigned long long breaks1 =0 , breaks2 =0 ; +int *fd1 =malloc (nprocs *sizeof (int )); +int *fd2 =malloc (nprocs *sizeof (int )); +char *desc ="Systemwide, Two events, same addr" ; +int ret; + + ret =perf_systemwide_event_open (fd1,HW_BREAKPOINT_RW , (__u64)&a, + (__u64 )sizeof (a)); +if (ret) { +perror ("perf_systemwide_event_open" ); +exit (EXIT_FAILURE ); + } + + ret =perf_systemwide_event_open (fd2,HW_BREAKPOINT_RW , (__u64)&a, + (__u64 )sizeof (a)); +if (ret) { +close_fds (fd1, nprocs); +perror ("perf_systemwide_event_open" ); +exit (EXIT_FAILURE ); + } + +reset_fds (fd1, nprocs); +reset_fds (fd2, nprocs); +enable_fds (fd1, nprocs); +enable_fds (fd2, nprocs); +multi_dawr_workload (); +disable_fds (fd1, nprocs); +disable_fds (fd2, nprocs); + + breaks1 =read_fds (fd1, nprocs); + breaks2 =read_fds (fd2, nprocs); + +close_fds (fd1, nprocs); +close_fds (fd2, nprocs); + +free (fd1); +free (fd2); + +if (breaks1 !=2 || breaks2 !=2 ) { +printf ("FAILED: %s: %lld != 2 || %lld != 2\n" , desc, + breaks1, breaks2); +return 1 ; + } + +printf ("TESTED: %s\n" , desc); +return 0 ; +} + +static int test_syswide_multi_diff_addr_ro_wo (void ) +{ +unsigned long long breaks1 =0 , breaks2 =0 ; +int *fd1 =malloc (nprocs *sizeof (int )); +int *fd2 =malloc (nprocs *sizeof (int )); +char *desc ="Systemwide, Two events, diff addr, one is RO, other is WO" ; +int ret; + + ret =perf_systemwide_event_open (fd1,HW_BREAKPOINT_W , (__u64)&a, + (__u64 )sizeof (a)); +if (ret) { +perror ("perf_systemwide_event_open" ); +exit (EXIT_FAILURE ); + } + + ret =perf_systemwide_event_open (fd2,HW_BREAKPOINT_R , (__u64)&b, + (__u64 )sizeof (b)); +if (ret) { +close_fds (fd1, nprocs); +perror ("perf_systemwide_event_open" ); +exit (EXIT_FAILURE ); + } + +reset_fds (fd1, nprocs); +reset_fds (fd2, nprocs); +enable_fds (fd1, nprocs); +enable_fds (fd2, nprocs); +multi_dawr_workload (); +disable_fds (fd1, nprocs); +disable_fds (fd2, nprocs); + + breaks1 =read_fds (fd1, nprocs); + breaks2 =read_fds (fd2, nprocs); + +close_fds (fd1, nprocs); +close_fds (fd2, nprocs); + +free (fd1); +free (fd2); + +if (breaks1 !=1 || breaks2 !=1 ) { +printf ("FAILED: %s: %lld != 1 || %lld != 1\n" , desc, + breaks1, breaks2); +return 1 ; + } + +printf ("TESTED: %s\n" , desc); +return 0 ; +} + +static int test_syswide_multi_same_addr_ro_wo (void ) +{ +unsigned long long breaks1 =0 , breaks2 =0 ; +int *fd1 =malloc (nprocs *sizeof (int )); +int *fd2 =malloc (nprocs *sizeof (int )); +char *desc ="Systemwide, Two events, same addr, one is RO, other is WO" ; +int ret; + + ret =perf_systemwide_event_open (fd1,HW_BREAKPOINT_W , (__u64)&a, + (__u64 )sizeof (a)); +if (ret) { +perror ("perf_systemwide_event_open" ); +exit (EXIT_FAILURE ); + } + + ret =perf_systemwide_event_open (fd2,HW_BREAKPOINT_R , (__u64)&a, + (__u64 )sizeof (a)); +if (ret) { +close_fds (fd1, nprocs); +perror ("perf_systemwide_event_open" ); +exit (EXIT_FAILURE ); + } + +reset_fds (fd1, nprocs); +reset_fds (fd2, nprocs); +enable_fds (fd1, nprocs); +enable_fds (fd2, nprocs); +multi_dawr_workload (); +disable_fds (fd1, nprocs); +disable_fds (fd2, nprocs); + + breaks1 =read_fds (fd1, nprocs); + breaks2 =read_fds (fd2, nprocs); + +close_fds (fd1, nprocs); +close_fds (fd2, nprocs); + +free (fd1); +free (fd2); + +if (breaks1 !=1 || breaks2 !=1 ) { +printf ("FAILED: %s: %lld != 1 || %lld != 1\n" , desc, + breaks1, breaks2); +return 1 ; + } + +printf ("TESTED: %s\n" , desc); +return 0 ; +} + +static int runtest_multi_dawr (void ) +{ +int ret =0 ; + + ret |=test_process_multi_diff_addr (); + ret |=test_process_multi_same_addr (); + ret |=test_process_multi_diff_addr_ro_wo (); + ret |=test_process_multi_same_addr_ro_wo (); + ret |=test_syswide_multi_diff_addr (); + ret |=test_syswide_multi_same_addr (); + ret |=test_syswide_multi_diff_addr_ro_wo (); + ret |=test_syswide_multi_same_addr_ro_wo (); + +return ret; +} + +static int runtest_unaligned_512bytes (void ) +{ +unsigned long long breaks =0 ; +int fd; +char *desc ="Process specific, 512 bytes, unaligned" ; +__u64 addr = (__u64 )&c +8 ; +size_t res; + + fd =perf_process_event_open (HW_BREAKPOINT_RW , addr,512 ); +if (fd <0 ) { +perror ("perf_process_event_open" ); +exit (EXIT_FAILURE ); + } + +ioctl (fd,PERF_EVENT_IOC_RESET ); +ioctl (fd,PERF_EVENT_IOC_ENABLE ); +multi_dawr_workload (); +ioctl (fd,PERF_EVENT_IOC_DISABLE ); + + res =read (fd, &breaks,sizeof (breaks)); +assert (res ==sizeof (unsigned long long )); + +close (fd); + +if (breaks !=2 ) { +printf ("FAILED: %s: %lld != 2\n" , desc, breaks); +return 1 ; + } + +printf ("TESTED: %s\n" , desc); +return 0 ; +} + +/* There is no perf api to find number of available watchpoints. Use ptrace. */ +static int get_nr_wps (bool *arch_31) +{ +struct ppc_debug_info dbginfo; +int child_pid; + + child_pid =fork (); +if (!child_pid) { +int ret =ptrace (PTRACE_TRACEME ,0 ,NULL ,0 ); +if (ret) { +perror ("PTRACE_TRACEME failed\n" ); +exit (EXIT_FAILURE ); + } +kill (getpid (),SIGUSR1 ); + +sleep (1 ); +exit (EXIT_SUCCESS ); + } + +wait (NULL ); +if (ptrace (PPC_PTRACE_GETHWDBGINFO , child_pid,NULL , &dbginfo)) { +perror ("Can't get breakpoint info" ); +exit (EXIT_FAILURE ); + } + + *arch_31 = !!(dbginfo.features &PPC_DEBUG_FEATURE_DATA_BP_DAWR_ARCH_31 ); +return dbginfo.num_data_bps; +} +static int runtest (void ) {int rwflag;int exclude_user;int ret; +bool dawr =dawr_supported (); +bool arch_31 = false; +int nr_wps =get_nr_wps (&arch_31);/* * perf defines rwflag as two bits read and write and at least
@@ -278,7 +831,7 @@ static int runtest(void)return ret;/* if we have the dawr, we can do an array test */ -if (!dawr_supported ()) +if (!dawr)continue ; ret =runtestsingle (rwflag, exclude_user,1 );if (ret)
@@ -287,6 +840,19 @@ static int runtest(void) } ret =runtest_dar_outside (); +if (ret) +return ret; + +if (dawr && nr_wps >1 ) { + nprocs =get_nprocs (); + ret =runtest_multi_dawr (); +if (ret) +return ret; + } + +if (dawr && arch_31) + ret =runtest_unaligned_512bytes (); +return ret; }
Signature · 1 line
2.26.2
PATCH 7/7 powerpc/selftests: Add selftest to test concurrent perf/ptrace events
In reply to Ravi Bangoriaptrace and perf watchpoints can't co-exists if their address range overlaps. See commit 29da4f91c0c1 ("powerpc/watchpoint: Don't allow concurrent perf and ptrace events") for more detail. Add selftest for the same.
Sample o/p:
# ./ptrace-perf-hwbreak test: ptrace-perf-hwbreak tags: git_version:powerpc-5.8-7-118-g937fa174a15d-dirty perf cpu event -> ptrace thread event (Overlapping): Ok perf cpu event -> ptrace thread event (Non-overlapping): Ok perf thread event -> ptrace same thread event (Overlapping): Ok perf thread event -> ptrace same thread event (Non-overlapping): Ok perf thread event -> ptrace other thread event: Ok ptrace thread event -> perf kernel event: Ok ptrace thread event -> perf same thread event (Overlapping): Ok ptrace thread event -> perf same thread event (Non-overlapping): Ok ptrace thread event -> perf other thread event: Ok ptrace thread event -> perf cpu event (Overlapping): Ok ptrace thread event -> perf cpu event (Non-overlapping): Ok ptrace thread event -> perf same thread & cpu event (Overlapping): Ok ptrace thread event -> perf same thread & cpu event (Non-overlapping): Ok ptrace thread event -> perf other thread & cpu event: Ok success: ptrace-perf-hwbreak
--- .../selftests/powerpc/ptrace/.gitignore | 1 + .../testing/selftests/powerpc/ptrace/Makefile | 2 +- .../powerpc/ptrace/ptrace-perf-hwbreak.c | 659 ++++++++++++++++++ 3 files changed, 661 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace-perf-hwbreak.c
tools/testing/selftests/powerpc/ptrace/.gitignore +1 -0
@@ -14,3 +14,4 @@ perf-hwbreak core-pkey ptrace-pkey ptrace-syscall +ptrace-perf-hwbreak
tools/testing/selftests/powerpc/ptrace/Makefile +1 -1
@@ -2,7 +2,7 @@ TEST_GEN_PROGS := ptrace-gpr ptrace-tm-gpr ptrace-tm-spd-gpr \ ptrace-tar ptrace-tm-tar ptrace-tm-spd-tar ptrace-vsx ptrace-tm-vsx \ ptrace-tm-spd-vsx ptrace-tm-spr ptrace-hwbreak ptrace-pkey core-pkey \ - perf-hwbreak ptrace-syscall + perf-hwbreak ptrace-syscall ptrace-perf-hwbreak top_srcdir = ../../../../.. include ../../lib.mk
tools/testing/selftests/powerpc/ptrace/ptrace-perf-hwbreak.c new file +659 -0
659 lines not on this page · raw message
Signature · 1 line
2.26.2
Quoted 8 lines · Ravi Bangoria
Patch #1, #2 and #3 enables p10 2nd DAWR feature for Book3S kvm guest. DAWR is a hypervisor resource and thus
H_SET_MODEhcall is used to set/unset it. A new caseH_SET_MODE_RESOURCE_SET_DAWR1is introduced inH_SET_MODEhcall for setting/unsetting 2nd DAWR. Also, new capabilityKVM_CAP_PPC_DAWR1has been added to query 2nd DAWR support via kvm ioctl.This feature also needs to be enabled in Qemu to really use it. I'll reply link to qemu patches once I post them in qemu-devel mailing list.
Qemu patches: https://lore.kernel.org/kvm/[email protected]
Quoted 10 lines · Ravi Bangoria
Patch #1, #2 and #3 enables p10 2nd DAWR feature for Book3S kvm guest. DAWR is a hypervisor resource and thus
H_SET_MODEhcall is used to set/unset it. A new caseH_SET_MODE_RESOURCE_SET_DAWR1is introduced inH_SET_MODEhcall for setting/unsetting 2nd DAWR. Also, new capabilityKVM_CAP_PPC_DAWR1has been added to query 2nd DAWR support via kvm ioctl.This feature also needs to be enabled in Qemu to really use it. I'll reply link to qemu patches once I post them in qemu-devel mailing list.
Patch #4, #5, #6 and #7 adds selftests to test 2nd DAWR.
If/when you resubmit these patches, please split the KVM patches into a separate series, since the KVM patches would go via my tree whereas I expect the selftests/powerpc patches would go through Michael Ellerman's tree.
Paul.
Hi Paul,
Quoted 10 lines · Paul Mackerras
Quoted 9 lines · Ravi Bangoria
Patch #1, #2 and #3 enables p10 2nd DAWR feature for Book3S kvm guest. DAWR is a hypervisor resource and thus
H_SET_MODEhcall is used to set/unset it. A new caseH_SET_MODE_RESOURCE_SET_DAWR1is introduced inH_SET_MODEhcall for setting/unsetting 2nd DAWR. Also, new capabilityKVM_CAP_PPC_DAWR1has been added to query 2nd DAWR support via kvm ioctl.This feature also needs to be enabled in Qemu to really use it. I'll reply link to qemu patches once I post them in qemu-devel mailing list.
Quoted 6 lines
Quoted 1 line
Patch #4, #5, #6 and #7 adds selftests to test 2nd DAWR.
If/when you resubmit these patches, please split the KVM patches into a separate series, since the KVM patches would go via my tree whereas I expect the selftests/powerpc patches would go through Michael Ellerman's tree.
Sure. Will split it.
Thanks,
Ravi