Skip to content

Commit

Permalink
libipt: add new IP compression variants
Browse files Browse the repository at this point in the history
There are two new IP compression variants:

    - a full 64bit IP
    - a 48bit IP compressed against last-IP

Support them.

Change-Id: I4722a45bc8fa5090ee402c311844a9da423b24b0
Signed-off-by: Markus Metzger <[email protected]>
  • Loading branch information
markus-metzger committed Jul 2, 2015
1 parent 8613a41 commit 4d6aab5
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 22 deletions.
22 changes: 21 additions & 1 deletion libipt/include/intel-pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,15 @@ enum pt_payload {
/* The size of an IP packet's payload with update-32 compression. */
pt_pl_ip_upd32_size = 4,

/* The size of an IP packet's payload with update-48 compression. */
pt_pl_ip_upd48_size = 6,

/* The size of an IP packet's payload with sext-48 compression. */
pt_pl_ip_sext48_size = 6,

/* The size of an IP packet's payload with full-ip compression. */
pt_pl_ip_full_size = 8,

/* Byte locations, sizes, and masks for processing TMA packets. */
pt_pl_tma_size = 5,
pt_pl_tma_ctc_size = 2,
Expand Down Expand Up @@ -336,7 +342,13 @@ enum pt_ip_compression {
pt_ipc_update_32 = 0x02,

/* Payload: 48 bits. Sign extend to full address. */
pt_ipc_sext_48 = 0x03
pt_ipc_sext_48 = 0x03,

/* Payload: 48 bits. Update last IP. */
pt_ipc_update_48 = 0x04,

/* Payload: 64 bits. Full address. */
pt_ipc_full = 0x06
};

/** The size of the various packets in bytes. */
Expand All @@ -355,19 +367,27 @@ enum pt_packet_size {
ptps_tip_supp = pt_opcs_tip,
ptps_tip_upd16 = pt_opcs_tip + pt_pl_ip_upd16_size,
ptps_tip_upd32 = pt_opcs_tip + pt_pl_ip_upd32_size,
ptps_tip_upd48 = pt_opcs_tip + pt_pl_ip_upd48_size,
ptps_tip_sext48 = pt_opcs_tip + pt_pl_ip_sext48_size,
ptps_tip_full = pt_opcs_tip + pt_pl_ip_full_size,
ptps_tip_pge_supp = pt_opcs_tip_pge,
ptps_tip_pge_upd16 = pt_opcs_tip_pge + pt_pl_ip_upd16_size,
ptps_tip_pge_upd32 = pt_opcs_tip_pge + pt_pl_ip_upd32_size,
ptps_tip_pge_upd48 = pt_opcs_tip_pge + pt_pl_ip_upd48_size,
ptps_tip_pge_sext48 = pt_opcs_tip_pge + pt_pl_ip_sext48_size,
ptps_tip_pge_full = pt_opcs_tip_pge + pt_pl_ip_full_size,
ptps_tip_pgd_supp = pt_opcs_tip_pgd,
ptps_tip_pgd_upd16 = pt_opcs_tip_pgd + pt_pl_ip_upd16_size,
ptps_tip_pgd_upd32 = pt_opcs_tip_pgd + pt_pl_ip_upd32_size,
ptps_tip_pgd_upd48 = pt_opcs_tip_pgd + pt_pl_ip_upd48_size,
ptps_tip_pgd_sext48 = pt_opcs_tip_pgd + pt_pl_ip_sext48_size,
ptps_tip_pgd_full = pt_opcs_tip_pgd + pt_pl_ip_full_size,
ptps_fup_supp = pt_opcs_fup,
ptps_fup_upd16 = pt_opcs_fup + pt_pl_ip_upd16_size,
ptps_fup_upd32 = pt_opcs_fup + pt_pl_ip_upd32_size,
ptps_fup_upd48 = pt_opcs_fup + pt_pl_ip_upd48_size,
ptps_fup_sext48 = pt_opcs_fup + pt_pl_ip_sext48_size,
ptps_fup_full = pt_opcs_fup + pt_pl_ip_full_size,
ptps_tma = pt_opcs_tma + pt_pl_tma_size,
ptps_stop = pt_opcs_stop,
ptps_vmcs = pt_opcs_vmcs + pt_pl_vmcs_size,
Expand Down
11 changes: 8 additions & 3 deletions libipt/src/pt_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ static int pt_reserve(const struct pt_encoder *encoder, unsigned int size)
static int pt_ipc_size(enum pt_ip_compression ipc)
{
switch (ipc) {
default:
return -pte_invalid;

case pt_ipc_suppressed:
return 0;

Expand All @@ -175,9 +172,17 @@ static int pt_ipc_size(enum pt_ip_compression ipc)
case pt_ipc_update_32:
return pt_pl_ip_upd32_size;

case pt_ipc_update_48:
return pt_pl_ip_upd48_size;

case pt_ipc_sext_48:
return pt_pl_ip_sext48_size;

case pt_ipc_full:
return pt_pl_ip_full_size;
}

return -pte_invalid;
}

/* Encode an integer value.
Expand Down
13 changes: 13 additions & 0 deletions libipt/src/pt_last_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ int pt_last_ip_update_ip(struct pt_last_ip *last_ip,
last_ip->have_ip = 1;
last_ip->suppressed = 0;
return 0;

case pt_ipc_update_48:
last_ip->ip = (last_ip->ip & ~0xffffffffffffull)
| (packet->ip & 0xffffffffffffull);
last_ip->have_ip = 1;
last_ip->suppressed = 0;
return 0;

case pt_ipc_full:
last_ip->ip = packet->ip;
last_ip->have_ip = 1;
last_ip->suppressed = 0;
return 0;
}

return -pte_bad_packet;
Expand Down
44 changes: 26 additions & 18 deletions libipt/src/pt_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ int pt_pkt_read_psb(const uint8_t *pos, const struct pt_config *config)
return ptps_psb;
}

static int pt_pkt_ip_size(enum pt_ip_compression ipc)
{
switch (ipc) {
case pt_ipc_suppressed:
return 0;

case pt_ipc_update_16:
return 2;

case pt_ipc_update_32:
return 4;

case pt_ipc_update_48:
case pt_ipc_sext_48:
return 6;

case pt_ipc_full:
return 8;
}

return -pte_internal;
}

int pt_pkt_read_ip(struct pt_packet_ip *packet, const uint8_t *pos,
const struct pt_config *config)
{
Expand All @@ -121,24 +144,9 @@ int pt_pkt_read_ip(struct pt_packet_ip *packet, const uint8_t *pos,
ipc = (*pos++ >> pt_opm_ipc_shr) & pt_opm_ipc_shr_mask;

ip = 0ull;
ipsize = 0;
switch (ipc) {
case pt_ipc_suppressed:
ipsize = 0;
break;

case pt_ipc_update_16:
ipsize = 2;
break;

case pt_ipc_update_32:
ipsize = 4;
break;

case pt_ipc_sext_48:
ipsize = 6;
break;
}
ipsize = pt_pkt_ip_size((enum pt_ip_compression) ipc);
if (ipsize < 0)
return ipsize;

if (config->end < pos + ipsize)
return -pte_eos;
Expand Down
Loading

0 comments on commit 4d6aab5

Please sign in to comment.