Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf intel-pt: pkt-decoder: Add CFE and EVD packets

As of Intel SDM (https://www.intel.com/sdm) version 076, there is a new
Intel PT feature called Event Trace which requires 2 new packets CFE and
EVD. Add them to the packet decoder and packet decoder test.

Committer notes:

I got the "Intel® 64 and IA-32 architectures software developer’s manual
combined volumes: 1, 2A, 2B, 2C, 2D, 3A, 3B, 3C, 3D, and 4" PDF at:

https://cdrdv2.intel.com/v1/dl/getContent/671200

And these new packets are described in page 3951:

<quote>
32.2.4

Event Trace is a capability that exposes details about the asynchronous
events, when they are generated, and when their corresponding software
event handler completes execution. These include:

o Interrupts, including NMI and SMI, including the interrupt vector when
defined.

o Faults, exceptions including the fault vector.

— Page faults additionally include the page fault address, when in context.

o Event handler returns, including IRET and RSM.

o VM exits and VM entries.¹

— VM exits include the values written to the “exit reason” and “exit qualification” VMCS fields.
INIT and SIPI events.

o TSX aborts, including the abort status returned for the RTM instructions.

o Shutdown.

Additionally, it provides indication of the status of the Interrupt Flag
(IF), to indicate when interrupts are masked.
</quote>

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20220124084201.2699795-4-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
2750af50 6816c254

+83
+8
tools/perf/arch/x86/tests/intel-pt-pkt-decoder-test.c
··· 166 166 {2, {0x02, 0xb3}, INTEL_PT_BLK_4_CTX, {INTEL_PT_BEP_IP, 0, 0}, 0, 0 }, 167 167 {2, {0x02, 0x33}, INTEL_PT_BLK_8_CTX, {INTEL_PT_BEP, 0, 0}, 0, 0 }, 168 168 {2, {0x02, 0xb3}, INTEL_PT_BLK_8_CTX, {INTEL_PT_BEP_IP, 0, 0}, 0, 0 }, 169 + /* Control Flow Event Packet */ 170 + {4, {0x02, 0x13, 0x01, 0x03}, 0, {INTEL_PT_CFE, 1, 3}, 0, 0 }, 171 + {4, {0x02, 0x13, 0x81, 0x03}, 0, {INTEL_PT_CFE_IP, 1, 3}, 0, 0 }, 172 + {4, {0x02, 0x13, 0x1f, 0x00}, 0, {INTEL_PT_CFE, 0x1f, 0}, 0, 0 }, 173 + {4, {0x02, 0x13, 0x9f, 0xff}, 0, {INTEL_PT_CFE_IP, 0x1f, 0xff}, 0, 0 }, 174 + /* */ 175 + {11, {0x02, 0x53, 0x09, 1, 2, 3, 4, 5, 6, 7}, 0, {INTEL_PT_EVD, 0x09, 0x7060504030201}, 0, 0 }, 176 + {11, {0x02, 0x53, 0x3f, 2, 3, 4, 5, 6, 7, 8}, 0, {INTEL_PT_EVD, 0x3f, 0x8070605040302}, 0, 0 }, 169 177 /* Terminator */ 170 178 {0, {0}, 0, {0, 0, 0}, 0, 0 }, 171 179 };
+32
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
··· 820 820 case INTEL_PT_BIP: 821 821 case INTEL_PT_BEP: 822 822 case INTEL_PT_BEP_IP: 823 + case INTEL_PT_CFE: 824 + case INTEL_PT_CFE_IP: 825 + case INTEL_PT_EVD: 823 826 return 0; 824 827 825 828 case INTEL_PT_MTC: ··· 1876 1873 case INTEL_PT_BIP: 1877 1874 case INTEL_PT_BEP: 1878 1875 case INTEL_PT_BEP_IP: 1876 + case INTEL_PT_CFE: 1877 + case INTEL_PT_CFE_IP: 1878 + case INTEL_PT_EVD: 1879 1879 decoder->have_tma = false; 1880 1880 intel_pt_log("ERROR: Unexpected packet\n"); 1881 1881 err = -EAGAIN; ··· 1981 1975 case INTEL_PT_BIP: 1982 1976 case INTEL_PT_BEP: 1983 1977 case INTEL_PT_BEP_IP: 1978 + case INTEL_PT_CFE: 1979 + case INTEL_PT_CFE_IP: 1980 + case INTEL_PT_EVD: 1984 1981 intel_pt_log("ERROR: Missing TIP after FUP\n"); 1985 1982 decoder->pkt_state = INTEL_PT_STATE_ERR3; 1986 1983 decoder->pkt_step = 0; ··· 2143 2134 case INTEL_PT_TIP: 2144 2135 case INTEL_PT_PSB: 2145 2136 case INTEL_PT_TRACESTOP: 2137 + case INTEL_PT_CFE: 2138 + case INTEL_PT_CFE_IP: 2139 + case INTEL_PT_EVD: 2146 2140 default: 2147 2141 return 1; 2148 2142 } ··· 2665 2653 decoder->blk_type = 0; 2666 2654 break; 2667 2655 2656 + case INTEL_PT_CFE: 2657 + case INTEL_PT_CFE_IP: 2658 + case INTEL_PT_EVD: 2668 2659 case INTEL_PT_MODE_EXEC: 2669 2660 case INTEL_PT_MODE_TSX: 2670 2661 case INTEL_PT_MNT: ··· 2804 2789 case INTEL_PT_BIP: 2805 2790 case INTEL_PT_BEP: 2806 2791 case INTEL_PT_BEP_IP: 2792 + case INTEL_PT_CFE: 2793 + case INTEL_PT_CFE_IP: 2794 + case INTEL_PT_EVD: 2807 2795 default: 2808 2796 return HOP_PROCESS; 2809 2797 } ··· 2875 2857 case INTEL_PT_BIP: 2876 2858 case INTEL_PT_BEP: 2877 2859 case INTEL_PT_BEP_IP: 2860 + case INTEL_PT_CFE: 2861 + case INTEL_PT_CFE_IP: 2862 + case INTEL_PT_EVD: 2878 2863 if (data->after_psbend) { 2879 2864 data->after_psbend -= 1; 2880 2865 if (!data->after_psbend) ··· 3244 3223 } 3245 3224 goto next; 3246 3225 3226 + case INTEL_PT_CFE: 3227 + case INTEL_PT_CFE_IP: 3228 + case INTEL_PT_EVD: 3229 + break; 3230 + 3247 3231 default: 3248 3232 return intel_pt_bug(decoder); 3249 3233 } ··· 3291 3265 case INTEL_PT_BIP: 3292 3266 case INTEL_PT_BEP: 3293 3267 case INTEL_PT_BEP_IP: 3268 + case INTEL_PT_CFE: 3269 + case INTEL_PT_CFE_IP: 3270 + case INTEL_PT_EVD: 3294 3271 intel_pt_log("ERROR: Unexpected packet\n"); 3295 3272 err = -ENOENT; 3296 3273 goto out; ··· 3505 3476 case INTEL_PT_BIP: 3506 3477 case INTEL_PT_BEP: 3507 3478 case INTEL_PT_BEP_IP: 3479 + case INTEL_PT_CFE: 3480 + case INTEL_PT_CFE_IP: 3481 + case INTEL_PT_EVD: 3508 3482 default: 3509 3483 break; 3510 3484 }
+40
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
··· 64 64 [INTEL_PT_BIP] = "BIP", 65 65 [INTEL_PT_BEP] = "BEP", 66 66 [INTEL_PT_BEP_IP] = "BEP", 67 + [INTEL_PT_CFE] = "CFE", 68 + [INTEL_PT_CFE_IP] = "CFE", 69 + [INTEL_PT_EVD] = "EVD", 67 70 }; 68 71 69 72 const char *intel_pt_pkt_name(enum intel_pt_pkt_type type) ··· 331 328 return 2; 332 329 } 333 330 331 + static int intel_pt_get_cfe(const unsigned char *buf, size_t len, 332 + struct intel_pt_pkt *packet) 333 + { 334 + if (len < 4) 335 + return INTEL_PT_NEED_MORE_BYTES; 336 + packet->type = buf[2] & 0x80 ? INTEL_PT_CFE_IP : INTEL_PT_CFE; 337 + packet->count = buf[2] & 0x1f; 338 + packet->payload = buf[3]; 339 + return 4; 340 + } 341 + 342 + static int intel_pt_get_evd(const unsigned char *buf, size_t len, 343 + struct intel_pt_pkt *packet) 344 + { 345 + if (len < 11) 346 + return INTEL_PT_NEED_MORE_BYTES; 347 + packet->type = INTEL_PT_EVD; 348 + packet->count = buf[2] & 0x3f; 349 + packet->payload = buf[3]; 350 + memcpy_le64(&packet->payload, buf + 3, 8); 351 + return 11; 352 + } 353 + 334 354 static int intel_pt_get_ext(const unsigned char *buf, size_t len, 335 355 struct intel_pt_pkt *packet) 336 356 { ··· 400 374 return intel_pt_get_bep(len, packet); 401 375 case 0xb3: /* BEP with IP */ 402 376 return intel_pt_get_bep_ip(len, packet); 377 + case 0x13: /* CFE */ 378 + return intel_pt_get_cfe(buf, len, packet); 379 + case 0x53: /* EVD */ 380 + return intel_pt_get_evd(buf, len, packet); 403 381 default: 404 382 return INTEL_PT_BAD_PACKET; 405 383 } ··· 653 623 case INTEL_PT_MWAIT: 654 624 case INTEL_PT_BEP: 655 625 case INTEL_PT_BEP_IP: 626 + case INTEL_PT_CFE: 627 + case INTEL_PT_CFE_IP: 628 + case INTEL_PT_EVD: 656 629 *ctx = INTEL_PT_NO_CTX; 657 630 break; 658 631 case INTEL_PT_BBP: ··· 782 749 name, packet->count ? "4" : "8", payload); 783 750 case INTEL_PT_BIP: 784 751 return snprintf(buf, buf_len, "%s ID 0x%02x Value 0x%llx", 752 + name, packet->count, payload); 753 + case INTEL_PT_CFE: 754 + case INTEL_PT_CFE_IP: 755 + return snprintf(buf, buf_len, "%s IP:%d Type 0x%02x Vector 0x%llx", 756 + name, packet->type == INTEL_PT_CFE_IP, packet->count, payload); 757 + case INTEL_PT_EVD: 758 + return snprintf(buf, buf_len, "%s Type 0x%02x Payload 0x%llx", 785 759 name, packet->count, payload); 786 760 default: 787 761 break;
+3
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h
··· 56 56 INTEL_PT_BIP, 57 57 INTEL_PT_BEP, 58 58 INTEL_PT_BEP_IP, 59 + INTEL_PT_CFE, 60 + INTEL_PT_CFE_IP, 61 + INTEL_PT_EVD, 59 62 }; 60 63 61 64 struct intel_pt_pkt {