perf intel-pt: pkt-decoder: Add CFE and EVD packets
authorAdrian Hunter <adrian.hunter@intel.com>
Mon, 24 Jan 2022 08:41:39 +0000 (10:41 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Mar 2023 08:40:14 +0000 (09:40 +0100)
commit 2750af50a360b52c6df1f5652ae728878bececc0 upstream.

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>
Cc: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/perf/arch/x86/tests/intel-pt-pkt-decoder-test.c
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h

index c933e3dcd0a82ec61bf777d0541d225376d2110b..9589314d60b724c28bc7210caf7b07fad5e4b51c 100644 (file)
@@ -166,6 +166,14 @@ struct test_data {
        {2, {0x02, 0xb3}, INTEL_PT_BLK_4_CTX, {INTEL_PT_BEP_IP, 0, 0}, 0, 0 },
        {2, {0x02, 0x33}, INTEL_PT_BLK_8_CTX, {INTEL_PT_BEP, 0, 0}, 0, 0 },
        {2, {0x02, 0xb3}, INTEL_PT_BLK_8_CTX, {INTEL_PT_BEP_IP, 0, 0}, 0, 0 },
+       /* Control Flow Event Packet */
+       {4, {0x02, 0x13, 0x01, 0x03}, 0, {INTEL_PT_CFE, 1, 3}, 0, 0 },
+       {4, {0x02, 0x13, 0x81, 0x03}, 0, {INTEL_PT_CFE_IP, 1, 3}, 0, 0 },
+       {4, {0x02, 0x13, 0x1f, 0x00}, 0, {INTEL_PT_CFE, 0x1f, 0}, 0, 0 },
+       {4, {0x02, 0x13, 0x9f, 0xff}, 0, {INTEL_PT_CFE_IP, 0x1f, 0xff}, 0, 0 },
+       /*  */
+       {11, {0x02, 0x53, 0x09, 1, 2, 3, 4, 5, 6, 7}, 0, {INTEL_PT_EVD, 0x09, 0x7060504030201}, 0, 0 },
+       {11, {0x02, 0x53, 0x3f, 2, 3, 4, 5, 6, 7, 8}, 0, {INTEL_PT_EVD, 0x3f, 0x8070605040302}, 0, 0 },
        /* Terminator */
        {0, {0}, 0, {0, 0, 0}, 0, 0 },
 };
index a7daec6cdc7b26b56e773c7ed2b03d92dba1de4c..372ffec96c2df9a05c65acae076d645b880faf80 100644 (file)
@@ -823,6 +823,9 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
        case INTEL_PT_BIP:
        case INTEL_PT_BEP:
        case INTEL_PT_BEP_IP:
+       case INTEL_PT_CFE:
+       case INTEL_PT_CFE_IP:
+       case INTEL_PT_EVD:
                return 0;
 
        case INTEL_PT_MTC:
@@ -1967,6 +1970,9 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)
                case INTEL_PT_BIP:
                case INTEL_PT_BEP:
                case INTEL_PT_BEP_IP:
+               case INTEL_PT_CFE:
+               case INTEL_PT_CFE_IP:
+               case INTEL_PT_EVD:
                        decoder->have_tma = false;
                        intel_pt_log("ERROR: Unexpected packet\n");
                        err = -EAGAIN;
@@ -2069,6 +2075,9 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
                case INTEL_PT_BIP:
                case INTEL_PT_BEP:
                case INTEL_PT_BEP_IP:
+               case INTEL_PT_CFE:
+               case INTEL_PT_CFE_IP:
+               case INTEL_PT_EVD:
                        intel_pt_log("ERROR: Missing TIP after FUP\n");
                        decoder->pkt_state = INTEL_PT_STATE_ERR3;
                        decoder->pkt_step = 0;
@@ -2228,6 +2237,9 @@ static int intel_pt_vm_psb_lookahead_cb(struct intel_pt_pkt_info *pkt_info)
        case INTEL_PT_TIP:
        case INTEL_PT_PSB:
        case INTEL_PT_TRACESTOP:
+       case INTEL_PT_CFE:
+       case INTEL_PT_CFE_IP:
+       case INTEL_PT_EVD:
        default:
                return 1;
        }
@@ -2747,6 +2759,9 @@ static int intel_pt_vm_time_correlation(struct intel_pt_decoder *decoder)
                        decoder->blk_type = 0;
                        break;
 
+               case INTEL_PT_CFE:
+               case INTEL_PT_CFE_IP:
+               case INTEL_PT_EVD:
                case INTEL_PT_MODE_EXEC:
                case INTEL_PT_MODE_TSX:
                case INTEL_PT_MNT:
@@ -2883,6 +2898,9 @@ static int intel_pt_hop_trace(struct intel_pt_decoder *decoder, bool *no_tip, in
        case INTEL_PT_BIP:
        case INTEL_PT_BEP:
        case INTEL_PT_BEP_IP:
+       case INTEL_PT_CFE:
+       case INTEL_PT_CFE_IP:
+       case INTEL_PT_EVD:
        default:
                return HOP_PROCESS;
        }
@@ -2951,6 +2969,9 @@ static int intel_pt_psb_lookahead_cb(struct intel_pt_pkt_info *pkt_info)
        case INTEL_PT_BIP:
        case INTEL_PT_BEP:
        case INTEL_PT_BEP_IP:
+       case INTEL_PT_CFE:
+       case INTEL_PT_CFE_IP:
+       case INTEL_PT_EVD:
                if (data->after_psbend) {
                        data->after_psbend -= 1;
                        if (!data->after_psbend)
@@ -3317,6 +3338,11 @@ next:
                        }
                        goto next;
 
+               case INTEL_PT_CFE:
+               case INTEL_PT_CFE_IP:
+               case INTEL_PT_EVD:
+                       break;
+
                default:
                        return intel_pt_bug(decoder);
                }
@@ -3359,6 +3385,9 @@ static int intel_pt_walk_psb(struct intel_pt_decoder *decoder)
                case INTEL_PT_BIP:
                case INTEL_PT_BEP:
                case INTEL_PT_BEP_IP:
+               case INTEL_PT_CFE:
+               case INTEL_PT_CFE_IP:
+               case INTEL_PT_EVD:
                        intel_pt_log("ERROR: Unexpected packet\n");
                        err = -ENOENT;
                        goto out;
@@ -3570,6 +3599,9 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
                case INTEL_PT_BIP:
                case INTEL_PT_BEP:
                case INTEL_PT_BEP_IP:
+               case INTEL_PT_CFE:
+               case INTEL_PT_CFE_IP:
+               case INTEL_PT_EVD:
                default:
                        break;
                }
index 02a3395d6ce3a43882de1378a157789e23fb8b62..6ff97b6107b72a88ee3a480155206bfd8bca48ec 100644 (file)
@@ -64,6 +64,9 @@ static const char * const packet_name[] = {
        [INTEL_PT_BIP]          = "BIP",
        [INTEL_PT_BEP]          = "BEP",
        [INTEL_PT_BEP_IP]       = "BEP",
+       [INTEL_PT_CFE]          = "CFE",
+       [INTEL_PT_CFE_IP]       = "CFE",
+       [INTEL_PT_EVD]          = "EVD",
 };
 
 const char *intel_pt_pkt_name(enum intel_pt_pkt_type type)
@@ -329,6 +332,29 @@ static int intel_pt_get_bep_ip(size_t len, struct intel_pt_pkt *packet)
        return 2;
 }
 
+static int intel_pt_get_cfe(const unsigned char *buf, size_t len,
+                           struct intel_pt_pkt *packet)
+{
+       if (len < 4)
+               return INTEL_PT_NEED_MORE_BYTES;
+       packet->type = buf[2] & 0x80 ? INTEL_PT_CFE_IP : INTEL_PT_CFE;
+       packet->count = buf[2] & 0x1f;
+       packet->payload = buf[3];
+       return 4;
+}
+
+static int intel_pt_get_evd(const unsigned char *buf, size_t len,
+                           struct intel_pt_pkt *packet)
+{
+       if (len < 11)
+               return INTEL_PT_NEED_MORE_BYTES;
+       packet->type = INTEL_PT_EVD;
+       packet->count = buf[2] & 0x3f;
+       packet->payload = buf[3];
+       memcpy_le64(&packet->payload, buf + 3, 8);
+       return 11;
+}
+
 static int intel_pt_get_ext(const unsigned char *buf, size_t len,
                            struct intel_pt_pkt *packet)
 {
@@ -375,6 +401,10 @@ static int intel_pt_get_ext(const unsigned char *buf, size_t len,
                return intel_pt_get_bep(len, packet);
        case 0xb3: /* BEP with IP */
                return intel_pt_get_bep_ip(len, packet);
+       case 0x13: /* CFE */
+               return intel_pt_get_cfe(buf, len, packet);
+       case 0x53: /* EVD */
+               return intel_pt_get_evd(buf, len, packet);
        default:
                return INTEL_PT_BAD_PACKET;
        }
@@ -624,6 +654,9 @@ void intel_pt_upd_pkt_ctx(const struct intel_pt_pkt *packet,
        case INTEL_PT_MWAIT:
        case INTEL_PT_BEP:
        case INTEL_PT_BEP_IP:
+       case INTEL_PT_CFE:
+       case INTEL_PT_CFE_IP:
+       case INTEL_PT_EVD:
                *ctx = INTEL_PT_NO_CTX;
                break;
        case INTEL_PT_BBP:
@@ -751,6 +784,13 @@ int intel_pt_pkt_desc(const struct intel_pt_pkt *packet, char *buf,
        case INTEL_PT_BIP:
                return snprintf(buf, buf_len, "%s ID 0x%02x Value 0x%llx",
                                name, packet->count, payload);
+       case INTEL_PT_CFE:
+       case INTEL_PT_CFE_IP:
+               return snprintf(buf, buf_len, "%s IP:%d Type 0x%02x Vector 0x%llx",
+                               name, packet->type == INTEL_PT_CFE_IP, packet->count, payload);
+       case INTEL_PT_EVD:
+               return snprintf(buf, buf_len, "%s Type 0x%02x Payload 0x%llx",
+                               name, packet->count, payload);
        default:
                break;
        }
index 996090cb84f666079075a9c7f8f5f4d3c656a7f9..496ba4be875ca780d218eb477671bc01bcdd4c82 100644 (file)
@@ -56,6 +56,9 @@ enum intel_pt_pkt_type {
        INTEL_PT_BIP,
        INTEL_PT_BEP,
        INTEL_PT_BEP_IP,
+       INTEL_PT_CFE,
+       INTEL_PT_CFE_IP,
+       INTEL_PT_EVD,
 };
 
 struct intel_pt_pkt {