powerpc/perf: Use regs->nip when SIAR is zero
authorMadhavan Srinivasan <maddy@linux.ibm.com>
Wed, 21 Oct 2020 08:53:29 +0000 (14:23 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 19 Nov 2020 05:56:56 +0000 (16:56 +1100)
In power10 DD1, there is an issue where the SIAR (Sampled Instruction
Address Register) is not latching to the sampled address during random
sampling. This results in value of 0s in the SIAR. Add a check to use
regs->nip when SIAR is zero.

Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201021085329.384535-5-maddy@linux.ibm.com
arch/powerpc/perf/core-book3s.c

index 6be0349e01ad3e49cdd9445ff955f574b367c63a..3c8c6ce634c56a4bc8e8e5bef4dd0d4a6afa2637 100644 (file)
@@ -263,9 +263,16 @@ static inline u32 perf_get_misc_flags(struct pt_regs *regs)
         * DD1.
         */
        if (marked && (ppmu->flags & PPMU_P10_DD1)) {
-               if (is_kernel_addr(mfspr(SPRN_SIAR)))
-                       return PERF_RECORD_MISC_KERNEL;
-               return PERF_RECORD_MISC_USER;
+               unsigned long siar = mfspr(SPRN_SIAR);
+               if (siar) {
+                       if (is_kernel_addr(siar))
+                               return PERF_RECORD_MISC_KERNEL;
+                       return PERF_RECORD_MISC_USER;
+               } else {
+                       if (is_kernel_addr(regs->nip))
+                               return PERF_RECORD_MISC_KERNEL;
+                       return PERF_RECORD_MISC_USER;
+               }
        }
 
        /*
@@ -2199,8 +2206,14 @@ unsigned long perf_misc_flags(struct pt_regs *regs)
 unsigned long perf_instruction_pointer(struct pt_regs *regs)
 {
        bool use_siar = regs_use_siar(regs);
+       unsigned long siar = mfspr(SPRN_SIAR);
 
-       if (use_siar && siar_valid(regs))
+       if (ppmu->flags & PPMU_P10_DD1) {
+               if (siar)
+                       return siar;
+               else
+                       return regs->nip;
+       } else if (use_siar && siar_valid(regs))
                return mfspr(SPRN_SIAR) + perf_ip_adjust(regs);
        else if (use_siar)
                return 0;               // no valid instruction pointer