From 85f87cf491bec6f90948a85b10f5523ea24db9e3 Mon Sep 17 00:00:00 2001 From: Ruslan Bukin Date: Thu, 10 Oct 2019 12:46:34 +0000 Subject: [PATCH] Update Intel Processor Trace decoder library. Its latest version merged from: ^/vendor/processor-trace/892e12c5a27bda5806d1e63269986bb4171b5a8b Sponsored by: DARPA, AFRL --- .../processor-trace/include/posix/threads.h | 2 +- contrib/processor-trace/include/pt_compiler.h | 2 +- .../windows/init.c => include/pt_version.h} | 73 +++- .../include/windows/inttypes.h | 2 +- .../processor-trace/include/windows/threads.h | 2 +- contrib/processor-trace/libipt/CMakeLists.txt | 36 +- .../processor-trace/libipt/include/intel-pt.h | 29 +- .../libipt/include/intel-pt.h.in | 29 +- .../internal/include/posix/pt_section_posix.h | 2 +- .../libipt/internal/include/pt_asid.h | 2 +- .../libipt/internal/include/pt_block_cache.h | 2 +- .../internal/include/pt_block_decoder.h | 2 +- .../libipt/internal/include/pt_config.h | 2 +- .../libipt/internal/include/pt_cpu.h | 2 +- .../libipt/internal/include/pt_cpuid.h | 2 +- .../internal/include/pt_decoder_function.h | 2 +- .../libipt/internal/include/pt_encoder.h | 2 +- .../libipt/internal/include/pt_event_queue.h | 2 +- .../libipt/internal/include/pt_ild.h | 7 +- .../libipt/internal/include/pt_image.h | 2 +- .../internal/include/pt_image_section_cache.h | 2 +- .../libipt/internal/include/pt_insn.h | 2 +- .../libipt/internal/include/pt_insn_decoder.h | 2 +- .../libipt/internal/include/pt_last_ip.h | 2 +- .../internal/include/pt_mapped_section.h | 2 +- .../libipt/internal/include/pt_msec_cache.h | 2 +- .../libipt/internal/include/pt_opcodes.h | 2 +- .../libipt/internal/include/pt_packet.h | 2 +- .../internal/include/pt_packet_decoder.h | 2 +- .../internal/include/pt_query_decoder.h | 2 +- .../libipt/internal/include/pt_retstack.h | 2 +- .../libipt/internal/include/pt_section.h | 13 +- .../libipt/internal/include/pt_section_file.h | 2 +- .../libipt/internal/include/pt_sync.h | 2 +- .../libipt/internal/include/pt_time.h | 9 +- .../libipt/internal/include/pt_tnt_cache.h | 2 +- .../libipt/internal/include/pti-disp-defs.h | 2 +- .../libipt/internal/include/pti-disp.h | 2 +- .../internal/include/pti-disp_default.h | 209 +++++++++ .../libipt/internal/include/pti-imm-defs.h | 2 +- .../libipt/internal/include/pti-imm.h | 2 +- .../libipt/internal/include/pti-modrm-defs.h | 2 +- .../libipt/internal/include/pti-modrm.h | 2 +- .../libipt/internal/include/pti-sib.h | 209 +++++++++ .../include/windows/pt_section_windows.h | 2 +- .../processor-trace/libipt/src/posix/init.c | 36 -- .../libipt/src/posix/pt_cpuid.c | 2 +- .../libipt/src/posix/pt_section_posix.c | 21 +- contrib/processor-trace/libipt/src/pt_asid.c | 2 +- .../libipt/src/pt_block_cache.c | 2 +- .../libipt/src/pt_block_decoder.c | 18 +- .../processor-trace/libipt/src/pt_config.c | 28 +- contrib/processor-trace/libipt/src/pt_cpu.c | 2 +- .../libipt/src/pt_decoder_function.c | 2 +- .../processor-trace/libipt/src/pt_encoder.c | 10 +- contrib/processor-trace/libipt/src/pt_error.c | 2 +- .../libipt/src/pt_event_queue.c | 2 +- contrib/processor-trace/libipt/src/pt_ild.c | 406 +++++++++++++----- contrib/processor-trace/libipt/src/pt_image.c | 17 +- .../libipt/src/pt_image_section_cache.c | 17 +- contrib/processor-trace/libipt/src/pt_insn.c | 5 +- .../libipt/src/pt_insn_decoder.c | 12 +- .../processor-trace/libipt/src/pt_last_ip.c | 2 +- .../libipt/src/pt_msec_cache.c | 2 +- .../processor-trace/libipt/src/pt_packet.c | 2 +- .../libipt/src/pt_packet_decoder.c | 25 +- .../libipt/src/pt_query_decoder.c | 39 +- .../processor-trace/libipt/src/pt_retstack.c | 2 +- .../processor-trace/libipt/src/pt_section.c | 67 +-- .../libipt/src/pt_section_file.c | 2 +- contrib/processor-trace/libipt/src/pt_sync.c | 11 +- contrib/processor-trace/libipt/src/pt_time.c | 104 ++++- .../processor-trace/libipt/src/pt_tnt_cache.c | 2 +- .../processor-trace/libipt/src/pt_version.c | 6 +- .../libipt/src/windows/pt_cpuid.c | 2 +- .../libipt/src/windows/pt_section_windows.c | 27 +- .../libipt/test/src/ptunit-asid.c | 2 +- .../libipt/test/src/ptunit-block_cache.c | 2 +- .../libipt/test/src/ptunit-block_decoder.c | 351 +++++++++++++++ .../libipt/test/src/ptunit-config.c | 68 ++- .../libipt/test/src/ptunit-cpp.cpp | 2 +- .../libipt/test/src/ptunit-cpu.c | 2 +- .../libipt/test/src/ptunit-encoder.c | 237 ++++++++++ .../libipt/test/src/ptunit-event_queue.c | 2 +- .../libipt/test/src/ptunit-fetch.c | 2 +- .../libipt/test/src/ptunit-ild.c | 4 +- .../libipt/test/src/ptunit-image.c | 11 +- .../test/src/ptunit-image_section_cache.c | 68 +-- .../libipt/test/src/ptunit-insn_decoder.c | 351 +++++++++++++++ .../libipt/test/src/ptunit-last_ip.c | 2 +- .../libipt/test/src/ptunit-mapped_section.c | 2 +- .../libipt/test/src/ptunit-msec_cache.c | 2 +- .../libipt/test/src/ptunit-packet.c | 2 +- .../libipt/test/src/ptunit-packet_decoder.c | 274 ++++++++++++ .../libipt/test/src/ptunit-query.c | 8 +- .../libipt/test/src/ptunit-retstack.c | 2 +- .../libipt/test/src/ptunit-section-file.c | 2 +- .../libipt/test/src/ptunit-section.c | 171 +++++--- .../libipt/test/src/ptunit-sync.c | 2 +- .../libipt/test/src/ptunit-time.c | 33 +- .../libipt/test/src/ptunit-tnt_cache.c | 2 +- lib/libipt/Makefile | 5 +- 102 files changed, 2716 insertions(+), 456 deletions(-) rename contrib/processor-trace/{libipt/src/windows/init.c => include/pt_version.h} (50%) create mode 100644 contrib/processor-trace/libipt/internal/include/pti-disp_default.h create mode 100644 contrib/processor-trace/libipt/internal/include/pti-sib.h delete mode 100644 contrib/processor-trace/libipt/src/posix/init.c create mode 100644 contrib/processor-trace/libipt/test/src/ptunit-block_decoder.c create mode 100644 contrib/processor-trace/libipt/test/src/ptunit-encoder.c create mode 100644 contrib/processor-trace/libipt/test/src/ptunit-insn_decoder.c create mode 100644 contrib/processor-trace/libipt/test/src/ptunit-packet_decoder.c diff --git a/contrib/processor-trace/include/posix/threads.h b/contrib/processor-trace/include/posix/threads.h index a9dcf05f757a..758865c5815c 100644 --- a/contrib/processor-trace/include/posix/threads.h +++ b/contrib/processor-trace/include/posix/threads.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/include/pt_compiler.h b/contrib/processor-trace/include/pt_compiler.h index 611703f25928..67cf40c51724 100644 --- a/contrib/processor-trace/include/pt_compiler.h +++ b/contrib/processor-trace/include/pt_compiler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, Intel Corporation + * Copyright (c) 2017-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/windows/init.c b/contrib/processor-trace/include/pt_version.h similarity index 50% rename from contrib/processor-trace/libipt/src/windows/init.c rename to contrib/processor-trace/include/pt_version.h index f679be2746f8..be6beb751177 100644 --- a/contrib/processor-trace/libipt/src/windows/init.c +++ b/contrib/processor-trace/include/pt_version.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2018-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -26,26 +26,63 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "pt_ild.h" +#ifndef PT_VERSION_H +#define PT_VERSION_H -#include +#include "intel-pt.h" + +#include +#include -BOOLEAN WINAPI DllMain(HINSTANCE handle, DWORD reason, LPVOID reserved) +static inline int pt_fprint_version(FILE *file, struct pt_version version) { - (void) handle; - (void) reserved; - - switch (reason) { - case DLL_PROCESS_ATTACH: - /* Initialize the Intel(R) Processor Trace instruction - decoder. */ - pt_ild_init(); - break; - - default: - break; + if (version.build) { + if (version.ext && version.ext[0]) + return fprintf(file, "%" PRIu8 ".%" PRIu8 ".%" PRIu16 + "-%" PRIu32 "-%s", version.major, + version.minor, version.patch, + version.build, version.ext); + else + return fprintf(file, "%" PRIu8 ".%" PRIu8 ".%" PRIu16 + "-%" PRIu32 "", version.major, + version.minor, version.patch, + version.build); + } else { + if (version.ext && version.ext[0]) + return fprintf(file, "%" PRIu8 ".%" PRIu8 ".%" PRIu16 + "-%s", version.major, version.minor, + version.patch, version.ext); + else + return fprintf(file, "%" PRIu8 ".%" PRIu8 ".%" PRIu16, + version.major, version.minor, + version.patch); } - - return TRUE; } + +static inline int pt_print_version(struct pt_version version) +{ + return pt_fprint_version(stdout, version); +} + +static inline void pt_print_tool_version(const char *name) +{ + struct pt_version v = { + /* .major = */ PT_VERSION_MAJOR, + /* .minor = */ PT_VERSION_MINOR, + /* .patch = */ PT_VERSION_PATCH, + /* .build = */ PT_VERSION_BUILD, + /* .ext = */ PT_VERSION_EXT + }; + + if (!name) + name = ""; + + printf("%s-", name); + pt_print_version(v); + printf(" / libipt-"); + pt_print_version(pt_library_version()); + printf("\n"); +} + +#endif /* PT_VERSION_H */ diff --git a/contrib/processor-trace/include/windows/inttypes.h b/contrib/processor-trace/include/windows/inttypes.h index 3659f361f1b4..20777ae21702 100644 --- a/contrib/processor-trace/include/windows/inttypes.h +++ b/contrib/processor-trace/include/windows/inttypes.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/include/windows/threads.h b/contrib/processor-trace/include/windows/threads.h index 9e57b81d4ca7..9d74ca714b31 100644 --- a/contrib/processor-trace/include/windows/threads.h +++ b/contrib/processor-trace/include/windows/threads.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/CMakeLists.txt b/contrib/processor-trace/libipt/CMakeLists.txt index 726bdfe0c869..9f1820d9375f 100644 --- a/contrib/processor-trace/libipt/CMakeLists.txt +++ b/contrib/processor-trace/libipt/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2018, Intel Corporation +# Copyright (c) 2013-2019, Intel Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -64,28 +64,28 @@ if (CMAKE_HOST_UNIX) internal/include/posix ) - set(LIBIPT_FILES ${LIBIPT_FILES} src/posix/init.c) set(LIBIPT_SECTION_FILES ${LIBIPT_SECTION_FILES} src/posix/pt_section_posix.c) endif (CMAKE_HOST_UNIX) if (CMAKE_HOST_WIN32) - add_definitions( - # export libipt symbols - # - /Dpt_export=__declspec\(dllexport\) - ) + if (BUILD_SHARED_LIBS) + add_definitions( + # export libipt symbols + # + /Dpt_export=__declspec\(dllexport\) + ) + endif (BUILD_SHARED_LIBS) include_directories( internal/include/windows ) - set(LIBIPT_FILES ${LIBIPT_FILES} src/windows/init.c) set(LIBIPT_SECTION_FILES ${LIBIPT_SECTION_FILES} src/windows/pt_section_windows.c) endif (CMAKE_HOST_WIN32) set(LIBIPT_FILES ${LIBIPT_FILES} ${LIBIPT_SECTION_FILES}) -add_library(libipt SHARED +add_library(libipt ${LIBIPT_FILES} ) @@ -167,6 +167,24 @@ add_ptunit_c_test(fetch src/pt_encoder.c src/pt_config.c ) +add_ptunit_c_test(encoder + src/pt_encoder.c + src/pt_config.c +) +add_ptunit_c_test(packet_decoder + src/pt_packet_decoder.c + src/pt_packet.c + src/pt_config.c + src/pt_sync.c + src/pt_decoder_function.c + src/pt_query_decoder.c + src/pt_event_queue.c + src/pt_last_ip.c + src/pt_tnt_cache.c + src/pt_time.c +) +add_ptunit_c_test(insn_decoder ${LIBIPT_FILES}) +add_ptunit_c_test(block_decoder ${LIBIPT_FILES}) add_ptunit_cpp_test(cpp) add_ptunit_libraries(cpp libipt) diff --git a/contrib/processor-trace/libipt/include/intel-pt.h b/contrib/processor-trace/libipt/include/intel-pt.h index de1c6275c806..bdfeb83a918e 100755 --- a/contrib/processor-trace/libipt/include/intel-pt.h +++ b/contrib/processor-trace/libipt/include/intel-pt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -80,6 +80,7 @@ struct pt_block_decoder; /** The header version. */ #define LIBIPT_VERSION_MAJOR ${PT_VERSION_MAJOR} #define LIBIPT_VERSION_MINOR ${PT_VERSION_MINOR} +#define LIBIPT_VERSION_PATCH ${PT_VERSION_PATCH} #define LIBIPT_VERSION ((LIBIPT_VERSION_MAJOR << 8) + LIBIPT_VERSION_MINOR) @@ -92,8 +93,8 @@ struct pt_version { /** Minor version number. */ uint8_t minor; - /** Reserved bits. */ - uint16_t reserved; + /** Patch level. */ + uint16_t patch; /** Build number. */ uint32_t build; @@ -330,6 +331,16 @@ struct pt_errata { */ uint32_t apl11:1; + /** SKL168: Intel(R) PT CYC Packets Can be Dropped When Immediately + * Preceding PSB + * + * Due to a rare microarchitectural condition, generation of an Intel + * PT (Processor Trace) PSB (Packet Stream Boundary) packet can cause a + * single CYC (Cycle Count) packet, possibly along with an associated + * MTC (Mini Time Counter) packet, to be dropped. + */ + uint32_t skl168:1; + /* Reserve a few bytes for the future. */ uint32_t reserved[15]; }; @@ -348,14 +359,26 @@ struct pt_conf_flags { /** End a block after a jump instruction. */ uint32_t end_on_jump:1; + + /** Preserve timing calibration on overflow. */ + uint32_t keep_tcal_on_ovf:1; } block; /** Flags for the instruction flow decoder. */ struct { /** Enable tick events for timing updates. */ uint32_t enable_tick_events:1; + + /** Preserve timing calibration on overflow. */ + uint32_t keep_tcal_on_ovf:1; } insn; + /** Flags for the query decoder. */ + struct { + /** Preserve timing calibration on overflow. */ + uint32_t keep_tcal_on_ovf:1; + } query; + /* Reserve a few bytes for future extensions. */ uint32_t reserved[4]; } variant; diff --git a/contrib/processor-trace/libipt/include/intel-pt.h.in b/contrib/processor-trace/libipt/include/intel-pt.h.in index de1c6275c806..bdfeb83a918e 100755 --- a/contrib/processor-trace/libipt/include/intel-pt.h.in +++ b/contrib/processor-trace/libipt/include/intel-pt.h.in @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -80,6 +80,7 @@ struct pt_block_decoder; /** The header version. */ #define LIBIPT_VERSION_MAJOR ${PT_VERSION_MAJOR} #define LIBIPT_VERSION_MINOR ${PT_VERSION_MINOR} +#define LIBIPT_VERSION_PATCH ${PT_VERSION_PATCH} #define LIBIPT_VERSION ((LIBIPT_VERSION_MAJOR << 8) + LIBIPT_VERSION_MINOR) @@ -92,8 +93,8 @@ struct pt_version { /** Minor version number. */ uint8_t minor; - /** Reserved bits. */ - uint16_t reserved; + /** Patch level. */ + uint16_t patch; /** Build number. */ uint32_t build; @@ -330,6 +331,16 @@ struct pt_errata { */ uint32_t apl11:1; + /** SKL168: Intel(R) PT CYC Packets Can be Dropped When Immediately + * Preceding PSB + * + * Due to a rare microarchitectural condition, generation of an Intel + * PT (Processor Trace) PSB (Packet Stream Boundary) packet can cause a + * single CYC (Cycle Count) packet, possibly along with an associated + * MTC (Mini Time Counter) packet, to be dropped. + */ + uint32_t skl168:1; + /* Reserve a few bytes for the future. */ uint32_t reserved[15]; }; @@ -348,14 +359,26 @@ struct pt_conf_flags { /** End a block after a jump instruction. */ uint32_t end_on_jump:1; + + /** Preserve timing calibration on overflow. */ + uint32_t keep_tcal_on_ovf:1; } block; /** Flags for the instruction flow decoder. */ struct { /** Enable tick events for timing updates. */ uint32_t enable_tick_events:1; + + /** Preserve timing calibration on overflow. */ + uint32_t keep_tcal_on_ovf:1; } insn; + /** Flags for the query decoder. */ + struct { + /** Preserve timing calibration on overflow. */ + uint32_t keep_tcal_on_ovf:1; + } query; + /* Reserve a few bytes for future extensions. */ uint32_t reserved[4]; } variant; diff --git a/contrib/processor-trace/libipt/internal/include/posix/pt_section_posix.h b/contrib/processor-trace/libipt/internal/include/posix/pt_section_posix.h index 99e85a834a3b..b1ed5b1236eb 100644 --- a/contrib/processor-trace/libipt/internal/include/posix/pt_section_posix.h +++ b/contrib/processor-trace/libipt/internal/include/posix/pt_section_posix.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2018, Intel Corporation + * Copyright (c) 2015-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_asid.h b/contrib/processor-trace/libipt/internal/include/pt_asid.h index cded0c1092d3..a97a4814ba7c 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_asid.h +++ b/contrib/processor-trace/libipt/internal/include/pt_asid.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_block_cache.h b/contrib/processor-trace/libipt/internal/include/pt_block_cache.h index 552fd93a7bb6..8745e787350b 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_block_cache.h +++ b/contrib/processor-trace/libipt/internal/include/pt_block_cache.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_block_decoder.h b/contrib/processor-trace/libipt/internal/include/pt_block_decoder.h index b965be1fc5fd..e84259ca4f08 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_block_decoder.h +++ b/contrib/processor-trace/libipt/internal/include/pt_block_decoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_config.h b/contrib/processor-trace/libipt/internal/include/pt_config.h index 406130efb5d7..5d18ca42485a 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_config.h +++ b/contrib/processor-trace/libipt/internal/include/pt_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2018, Intel Corporation + * Copyright (c) 2015-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_cpu.h b/contrib/processor-trace/libipt/internal/include/pt_cpu.h index 3ab40446083f..3a1da3a4dba7 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_cpu.h +++ b/contrib/processor-trace/libipt/internal/include/pt_cpu.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_cpuid.h b/contrib/processor-trace/libipt/internal/include/pt_cpuid.h index e5afabf9079b..995ad80abbe0 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_cpuid.h +++ b/contrib/processor-trace/libipt/internal/include/pt_cpuid.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_decoder_function.h b/contrib/processor-trace/libipt/internal/include/pt_decoder_function.h index 9bed3f29f720..0b59dc695fa7 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_decoder_function.h +++ b/contrib/processor-trace/libipt/internal/include/pt_decoder_function.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_encoder.h b/contrib/processor-trace/libipt/internal/include/pt_encoder.h index 9d48a34a863d..f1b338e80848 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_encoder.h +++ b/contrib/processor-trace/libipt/internal/include/pt_encoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_event_queue.h b/contrib/processor-trace/libipt/internal/include/pt_event_queue.h index c606dfa39752..a6df4ca32468 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_event_queue.h +++ b/contrib/processor-trace/libipt/internal/include/pt_event_queue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_ild.h b/contrib/processor-trace/libipt/internal/include/pt_ild.h index d0d0e915fb07..ebc41f575299 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_ild.h +++ b/contrib/processor-trace/libipt/internal/include/pt_ild.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -97,11 +97,6 @@ static inline uint8_t pti_get_modrm_rm(const struct pt_ild *ild) return ild->modrm_byte & 7; } -/* MAIN ENTRANCE POINTS */ - -/* one time call. not thread safe init. call when single threaded. */ -extern void pt_ild_init(void); - /* all decoding is multithread safe. */ /* Decode one instruction. diff --git a/contrib/processor-trace/libipt/internal/include/pt_image.h b/contrib/processor-trace/libipt/internal/include/pt_image.h index dbc2186bea18..8b05b480ce2b 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_image.h +++ b/contrib/processor-trace/libipt/internal/include/pt_image.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_image_section_cache.h b/contrib/processor-trace/libipt/internal/include/pt_image_section_cache.h index 1e7f0d358af2..9e70c13de1c6 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_image_section_cache.h +++ b/contrib/processor-trace/libipt/internal/include/pt_image_section_cache.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_insn.h b/contrib/processor-trace/libipt/internal/include/pt_insn.h index 22039827daaf..56e1c9b65b7d 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_insn.h +++ b/contrib/processor-trace/libipt/internal/include/pt_insn.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_insn_decoder.h b/contrib/processor-trace/libipt/internal/include/pt_insn_decoder.h index 70b47f33e491..eef1dc8bb5cd 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_insn_decoder.h +++ b/contrib/processor-trace/libipt/internal/include/pt_insn_decoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_last_ip.h b/contrib/processor-trace/libipt/internal/include/pt_last_ip.h index 0f4490db2b60..aaf068f2fd1f 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_last_ip.h +++ b/contrib/processor-trace/libipt/internal/include/pt_last_ip.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_mapped_section.h b/contrib/processor-trace/libipt/internal/include/pt_mapped_section.h index 7e1016111f88..322f928d1ae3 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_mapped_section.h +++ b/contrib/processor-trace/libipt/internal/include/pt_mapped_section.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_msec_cache.h b/contrib/processor-trace/libipt/internal/include/pt_msec_cache.h index 43f3813bfbd7..6a52d09267d2 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_msec_cache.h +++ b/contrib/processor-trace/libipt/internal/include/pt_msec_cache.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, Intel Corporation + * Copyright (c) 2017-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_opcodes.h b/contrib/processor-trace/libipt/internal/include/pt_opcodes.h index 93eab79a80ec..945445ea735e 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_opcodes.h +++ b/contrib/processor-trace/libipt/internal/include/pt_opcodes.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_packet.h b/contrib/processor-trace/libipt/internal/include/pt_packet.h index ed4fc63c4600..ae1357ff29cb 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_packet.h +++ b/contrib/processor-trace/libipt/internal/include/pt_packet.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_packet_decoder.h b/contrib/processor-trace/libipt/internal/include/pt_packet_decoder.h index 2c114310c84b..0ea30db13386 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_packet_decoder.h +++ b/contrib/processor-trace/libipt/internal/include/pt_packet_decoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_query_decoder.h b/contrib/processor-trace/libipt/internal/include/pt_query_decoder.h index 355338feab1c..40194ec766dc 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_query_decoder.h +++ b/contrib/processor-trace/libipt/internal/include/pt_query_decoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_retstack.h b/contrib/processor-trace/libipt/internal/include/pt_retstack.h index c68a782a7dbe..e619ee602b2c 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_retstack.h +++ b/contrib/processor-trace/libipt/internal/include/pt_retstack.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_section.h b/contrib/processor-trace/libipt/internal/include/pt_section.h index df9200e19770..f0a80c5e5b0a 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_section.h +++ b/contrib/processor-trace/libipt/internal/include/pt_section.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -162,10 +162,15 @@ struct pt_section { * The returned section is not mapped and starts with a user count of one and * instruction caching enabled. * - * Returns a new section on success, NULL otherwise. + * Returns zero on success, a negative pt_error_code otherwise. + * Returns -pte_internal if @psection is NULL. + * Returns -pte_nomem when running out of memory. + * Returns -pte_bad_file if @filename cannot be opened. + * Returns -pte_invalid if @offset lies beyond @file. + * Returns -pte_invalid if @filename is too long. */ -extern struct pt_section *pt_mk_section(const char *file, uint64_t offset, - uint64_t size); +extern int pt_mk_section(struct pt_section **psection, const char *filename, + uint64_t offset, uint64_t size); /* Lock a section. * diff --git a/contrib/processor-trace/libipt/internal/include/pt_section_file.h b/contrib/processor-trace/libipt/internal/include/pt_section_file.h index 9b266dbba0f3..1f3c6cb2a72a 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_section_file.h +++ b/contrib/processor-trace/libipt/internal/include/pt_section_file.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_sync.h b/contrib/processor-trace/libipt/internal/include/pt_sync.h index 8e0c5d527aa1..24d654cef979 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_sync.h +++ b/contrib/processor-trace/libipt/internal/include/pt_sync.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pt_time.h b/contrib/processor-trace/libipt/internal/include/pt_time.h index 1f3816ae163a..61079c372141 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_time.h +++ b/contrib/processor-trace/libipt/internal/include/pt_time.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -166,6 +166,9 @@ struct pt_time_cal { /* A flag saying whether we have seen a MTC packet. */ uint32_t have_mtc:1; + + /* A flag saying whether we need to check for erratum SKL168. */ + uint32_t check_skl168:1; }; enum { @@ -228,5 +231,9 @@ extern int pt_tcal_update_mtc(struct pt_time_cal *, extern int pt_tcal_update_cyc(struct pt_time_cal *, const struct pt_packet_cyc *, const struct pt_config *); +extern int pt_tcal_update_psb(struct pt_time_cal *, + const struct pt_config *); +extern int pt_tcal_update_ovf(struct pt_time_cal *, + const struct pt_config *); #endif /* PT_TIME_H */ diff --git a/contrib/processor-trace/libipt/internal/include/pt_tnt_cache.h b/contrib/processor-trace/libipt/internal/include/pt_tnt_cache.h index 67d2b3798de1..1d0d0da4bd53 100644 --- a/contrib/processor-trace/libipt/internal/include/pt_tnt_cache.h +++ b/contrib/processor-trace/libipt/internal/include/pt_tnt_cache.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pti-disp-defs.h b/contrib/processor-trace/libipt/internal/include/pti-disp-defs.h index 82a6d04245b7..0f1077cacc8e 100644 --- a/contrib/processor-trace/libipt/internal/include/pti-disp-defs.h +++ b/contrib/processor-trace/libipt/internal/include/pti-disp-defs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pti-disp.h b/contrib/processor-trace/libipt/internal/include/pti-disp.h index 99e97a334230..a82f381d4e24 100644 --- a/contrib/processor-trace/libipt/internal/include/pti-disp.h +++ b/contrib/processor-trace/libipt/internal/include/pti-disp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pti-disp_default.h b/contrib/processor-trace/libipt/internal/include/pti-disp_default.h new file mode 100644 index 000000000000..7b454baefd1e --- /dev/null +++ b/contrib/processor-trace/libipt/internal/include/pti-disp_default.h @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2017-2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef PTI_DISP_DEFAULT_H +#define PTI_DISP_DEFAULT_H + +#include + + +static const uint8_t disp_default[4][4][8] = { + /* Effective Addressing Mode: ptem_unknown. */ { + /* MOD: 0 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 1 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 2 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 3 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + } + }, + + /* Effective Addressing Mode: ptem_16bit. */ { + /* MOD: 0 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 2, + /* RM: 7 */ 0 + }, + /* MOD: 1 */ { + /* RM: 0 */ 1, + /* RM: 1 */ 1, + /* RM: 2 */ 1, + /* RM: 3 */ 1, + /* RM: 4 */ 1, + /* RM: 5 */ 1, + /* RM: 6 */ 1, + /* RM: 7 */ 1 + }, + /* MOD: 2 */ { + /* RM: 0 */ 2, + /* RM: 1 */ 2, + /* RM: 2 */ 2, + /* RM: 3 */ 2, + /* RM: 4 */ 2, + /* RM: 5 */ 2, + /* RM: 6 */ 2, + /* RM: 7 */ 2 + }, + /* MOD: 3 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + } + }, + + /* Effective Addressing Mode: ptem_32bit. */ { + /* MOD: 0 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 4, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 1 */ { + /* RM: 0 */ 1, + /* RM: 1 */ 1, + /* RM: 2 */ 1, + /* RM: 3 */ 1, + /* RM: 4 */ 1, + /* RM: 5 */ 1, + /* RM: 6 */ 1, + /* RM: 7 */ 1 + }, + /* MOD: 2 */ { + /* RM: 0 */ 4, + /* RM: 1 */ 4, + /* RM: 2 */ 4, + /* RM: 3 */ 4, + /* RM: 4 */ 4, + /* RM: 5 */ 4, + /* RM: 6 */ 4, + /* RM: 7 */ 4 + }, + /* MOD: 3 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + } + }, + + /* Effective Addressing Mode: ptem_64bit. */ { + /* MOD: 0 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 4, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 1 */ { + /* RM: 0 */ 1, + /* RM: 1 */ 1, + /* RM: 2 */ 1, + /* RM: 3 */ 1, + /* RM: 4 */ 1, + /* RM: 5 */ 1, + /* RM: 6 */ 1, + /* RM: 7 */ 1 + }, + /* MOD: 2 */ { + /* RM: 0 */ 4, + /* RM: 1 */ 4, + /* RM: 2 */ 4, + /* RM: 3 */ 4, + /* RM: 4 */ 4, + /* RM: 5 */ 4, + /* RM: 6 */ 4, + /* RM: 7 */ 4 + }, + /* MOD: 3 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + } + } +}; + +#endif /* PTI_DISP_DEFAULT_H */ diff --git a/contrib/processor-trace/libipt/internal/include/pti-imm-defs.h b/contrib/processor-trace/libipt/internal/include/pti-imm-defs.h index 598c335638b8..c26ea4e02e87 100644 --- a/contrib/processor-trace/libipt/internal/include/pti-imm-defs.h +++ b/contrib/processor-trace/libipt/internal/include/pti-imm-defs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pti-imm.h b/contrib/processor-trace/libipt/internal/include/pti-imm.h index 7f3ceab2b307..fbbfbbb5c693 100644 --- a/contrib/processor-trace/libipt/internal/include/pti-imm.h +++ b/contrib/processor-trace/libipt/internal/include/pti-imm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pti-modrm-defs.h b/contrib/processor-trace/libipt/internal/include/pti-modrm-defs.h index fd75618ce172..cb67c4be49ec 100644 --- a/contrib/processor-trace/libipt/internal/include/pti-modrm-defs.h +++ b/contrib/processor-trace/libipt/internal/include/pti-modrm-defs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pti-modrm.h b/contrib/processor-trace/libipt/internal/include/pti-modrm.h index ddddf63d29db..72bdec8a37b5 100644 --- a/contrib/processor-trace/libipt/internal/include/pti-modrm.h +++ b/contrib/processor-trace/libipt/internal/include/pti-modrm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/internal/include/pti-sib.h b/contrib/processor-trace/libipt/internal/include/pti-sib.h new file mode 100644 index 000000000000..d57670f47571 --- /dev/null +++ b/contrib/processor-trace/libipt/internal/include/pti-sib.h @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2017-2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef PTI_SIB_H +#define PTI_SIB_H + +#include + + +static const uint8_t has_sib[4][4][8] = { + /* Effective Addressing Mode: ptem_unknown. */ { + /* MOD: 0 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 1 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 2 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 3 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + } + }, + + /* Effective Addressing Mode: ptem_16bit. */ { + /* MOD: 0 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 1 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 2 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 3 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + } + }, + + /* Effective Addressing Mode: ptem_32bit. */ { + /* MOD: 0 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 1, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 1 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 1, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 2 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 1, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 3 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + } + }, + + /* Effective Addressing Mode: ptem_64bit. */ { + /* MOD: 0 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 1, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 1 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 1, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 2 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 1, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + }, + /* MOD: 3 */ { + /* RM: 0 */ 0, + /* RM: 1 */ 0, + /* RM: 2 */ 0, + /* RM: 3 */ 0, + /* RM: 4 */ 0, + /* RM: 5 */ 0, + /* RM: 6 */ 0, + /* RM: 7 */ 0 + } + } +}; + +#endif /* PTI_SIB_H */ diff --git a/contrib/processor-trace/libipt/internal/include/windows/pt_section_windows.h b/contrib/processor-trace/libipt/internal/include/windows/pt_section_windows.h index 96b101532a9b..0fcce2dffefe 100644 --- a/contrib/processor-trace/libipt/internal/include/windows/pt_section_windows.h +++ b/contrib/processor-trace/libipt/internal/include/windows/pt_section_windows.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2018, Intel Corporation + * Copyright (c) 2015-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/posix/init.c b/contrib/processor-trace/libipt/src/posix/init.c deleted file mode 100644 index dc20a432b02a..000000000000 --- a/contrib/processor-trace/libipt/src/posix/init.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2013-2018, Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "pt_ild.h" - - -static void __attribute__((constructor)) init(void) -{ - /* Initialize the Intel(R) Processor Trace instruction decoder. */ - pt_ild_init(); -} diff --git a/contrib/processor-trace/libipt/src/posix/pt_cpuid.c b/contrib/processor-trace/libipt/src/posix/pt_cpuid.c index 0ca755dd3fe9..9334e0d4fac2 100644 --- a/contrib/processor-trace/libipt/src/posix/pt_cpuid.c +++ b/contrib/processor-trace/libipt/src/posix/pt_cpuid.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/posix/pt_section_posix.c b/contrib/processor-trace/libipt/src/posix/pt_section_posix.c index 392ce4ecc6bb..651f2546837c 100644 --- a/contrib/processor-trace/libipt/src/posix/pt_section_posix.c +++ b/contrib/processor-trace/libipt/src/posix/pt_section_posix.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -53,7 +53,7 @@ int pt_section_mk_status(void **pstatus, uint64_t *psize, const char *filename) errcode = stat(filename, &buffer); if (errcode < 0) - return errcode; + return -pte_bad_file; if (buffer.st_size < 0) return -pte_bad_image; @@ -65,7 +65,7 @@ int pt_section_mk_status(void **pstatus, uint64_t *psize, const char *filename) status->stat = buffer; *pstatus = status; - *psize = buffer.st_size; + *psize = (uint64_t) buffer.st_size; return 0; } @@ -81,7 +81,7 @@ static int check_file_status(struct pt_section *section, int fd) errcode = fstat(fd, &stat); if (errcode) - return -pte_bad_image; + return -pte_bad_file; status = section->status; if (!status) @@ -101,6 +101,7 @@ int pt_sec_posix_map(struct pt_section *section, int fd) struct pt_sec_posix_mapping *mapping; uint64_t offset, size, adjustment; uint8_t *base; + long page_size; int errcode; if (!section) @@ -109,7 +110,11 @@ int pt_sec_posix_map(struct pt_section *section, int fd) offset = section->offset; size = section->size; - adjustment = offset % sysconf(_SC_PAGESIZE); + page_size = sysconf(_SC_PAGESIZE); + if (page_size < 0) + return -pte_bad_config; + + adjustment = offset % (uint64_t) page_size; offset -= adjustment; size += adjustment; @@ -213,7 +218,7 @@ int pt_section_map(struct pt_section *section) if (!filename) goto out_unlock; - errcode = -pte_bad_image; + errcode = -pte_bad_file; fd = open(filename, O_RDONLY); if (fd == -1) goto out_unlock; @@ -234,8 +239,10 @@ int pt_section_map(struct pt_section *section) * if we fail to convert the file descriptor. */ file = fdopen(fd, "rb"); - if (!file) + if (!file) { + errcode = -pte_bad_file; goto out_fd; + } /* We need to keep the file open on success. It will be closed when * the section is unmapped. diff --git a/contrib/processor-trace/libipt/src/pt_asid.c b/contrib/processor-trace/libipt/src/pt_asid.c index f492e0f7fd67..5cb4dd61b69e 100644 --- a/contrib/processor-trace/libipt/src/pt_asid.c +++ b/contrib/processor-trace/libipt/src/pt_asid.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_block_cache.c b/contrib/processor-trace/libipt/src/pt_block_cache.c index abe6ea1f3ca2..9c12a8ffb69d 100644 --- a/contrib/processor-trace/libipt/src/pt_block_cache.c +++ b/contrib/processor-trace/libipt/src/pt_block_cache.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_block_decoder.c b/contrib/processor-trace/libipt/src/pt_block_decoder.c index d6c816db65cc..e6890f5bed27 100644 --- a/contrib/processor-trace/libipt/src/pt_block_decoder.c +++ b/contrib/processor-trace/libipt/src/pt_block_decoder.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -102,6 +102,8 @@ static int pt_blk_init_qry_flags(struct pt_conf_flags *qflags, return -pte_internal; memset(qflags, 0, sizeof(*qflags)); + qflags->variant.query.keep_tcal_on_ovf = + flags->variant.block.keep_tcal_on_ovf; return 0; } @@ -568,7 +570,8 @@ static int pt_blk_next_ip(uint64_t *pip, struct pt_block_decoder *decoder, ip = insn->ip + insn->size; if (taken) - ip += iext->variant.branch.displacement; + ip += (uint64_t) (int64_t) + iext->variant.branch.displacement; *pip = ip; return status; @@ -1778,8 +1781,8 @@ pt_blk_proceed_no_event_fill_cache(struct pt_block_decoder *decoder, struct pt_bcache_entry bce; struct pt_insn_ext iext; struct pt_insn insn; - uint64_t nip, dip; - int64_t disp, ioff, noff; + uint64_t nip, dip, ioff, noff; + int64_t disp; int status; if (!decoder || !steps) @@ -2002,7 +2005,7 @@ pt_blk_proceed_no_event_fill_cache(struct pt_block_decoder *decoder, return -pte_internal; /* The decision point IP and the displacement from @insn.ip. */ - dip = nip + bce.displacement; + dip = nip + (uint64_t) (int64_t) bce.displacement; disp = (int64_t) (dip - insn.ip); /* We may have switched sections if the section was split. See @@ -2166,7 +2169,7 @@ static int pt_blk_proceed_no_event_cached(struct pt_block_decoder *decoder, * * Switch to the slow path until we reach the end of this section. */ - nip = decoder->ip + bce.displacement; + nip = decoder->ip + (uint64_t) (int64_t) bce.displacement; if (!pt_blk_is_in_section(msec, nip)) return pt_blk_proceed_no_event_uncached(decoder, block); @@ -2262,7 +2265,8 @@ static int pt_blk_proceed_no_event_cached(struct pt_block_decoder *decoder, if (status < 0) return status; - ip += iext.variant.branch.displacement; + ip += (uint64_t) (int64_t) + iext.variant.branch.displacement; } decoder->ip = ip + bce.isize; diff --git a/contrib/processor-trace/libipt/src/pt_config.c b/contrib/processor-trace/libipt/src/pt_config.c index 1479daebd556..7c14c5eb181f 100644 --- a/contrib/processor-trace/libipt/src/pt_config.c +++ b/contrib/processor-trace/libipt/src/pt_config.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -59,20 +59,23 @@ int pt_cpu_errata(struct pt_errata *errata, const struct pt_cpu *cpu) case 0x4e: case 0x5e: - errata->bdm70 = 1; - errata->skd007 = 1; - errata->skd022 = 1; - errata->skd010 = 1; - errata->skl014 = 1; - return 0; - case 0x8e: case 0x9e: errata->bdm70 = 1; - errata->skl014 = 1; + errata->skd007 = 1; errata->skd022 = 1; errata->skd010 = 1; - errata->skd007 = 1; + errata->skl014 = 1; + errata->skl168 = 1; + return 0; + + case 0x55: + case 0x66: + case 0x7d: + case 0x7e: + errata->bdm70 = 1; + errata->skl014 = 1; + errata->skd022 = 1; return 0; case 0x5c: @@ -80,6 +83,11 @@ int pt_cpu_errata(struct pt_errata *errata, const struct pt_cpu *cpu) errata->apl12 = 1; errata->apl11 = 1; return 0; + + case 0x7a: + case 0x86: + errata->apl11 = 1; + return 0; } break; } diff --git a/contrib/processor-trace/libipt/src/pt_cpu.c b/contrib/processor-trace/libipt/src/pt_cpu.c index c47e54d40cf6..adcb1ca5cb83 100644 --- a/contrib/processor-trace/libipt/src/pt_cpu.c +++ b/contrib/processor-trace/libipt/src/pt_cpu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_decoder_function.c b/contrib/processor-trace/libipt/src/pt_decoder_function.c index 4c7d48e1c68c..96734cac6920 100644 --- a/contrib/processor-trace/libipt/src/pt_decoder_function.c +++ b/contrib/processor-trace/libipt/src/pt_decoder_function.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_encoder.c b/contrib/processor-trace/libipt/src/pt_encoder.c index 946b88cbff7a..a34ef12466cf 100644 --- a/contrib/processor-trace/libipt/src/pt_encoder.c +++ b/contrib/processor-trace/libipt/src/pt_encoder.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -117,7 +117,7 @@ int pt_enc_get_offset(const struct pt_encoder *encoder, uint64_t *offset) if (!begin) return -pte_internal; - *offset = raw - begin; + *offset = (uint64_t) (int64_t) (raw - begin); return 0; } @@ -230,7 +230,8 @@ static int pt_encode_ip(struct pt_encoder *encoder, enum pt_opcode op, if (size < 0) return size; - errcode = pt_reserve(encoder, /* opc size = */ 1 + size); + errcode = pt_reserve(encoder, + /* opc size = */ 1u + (unsigned int) size); if (errcode < 0) return errcode; @@ -661,7 +662,8 @@ int pt_enc_next(struct pt_encoder *encoder, const struct pt_packet *packet) if (size < 0) return size; - errcode = pt_reserve(encoder, pt_opcs_ptw + size); + errcode = pt_reserve(encoder, + (unsigned int) (pt_opcs_ptw + size)); if (errcode < 0) return errcode; diff --git a/contrib/processor-trace/libipt/src/pt_error.c b/contrib/processor-trace/libipt/src/pt_error.c index c3ee81cfdba1..5208d1f09ba8 100644 --- a/contrib/processor-trace/libipt/src/pt_error.c +++ b/contrib/processor-trace/libipt/src/pt_error.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_event_queue.c b/contrib/processor-trace/libipt/src/pt_event_queue.c index 89518ea3e041..e0d449016a97 100644 --- a/contrib/processor-trace/libipt/src/pt_event_queue.c +++ b/contrib/processor-trace/libipt/src/pt_event_queue.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_ild.c b/contrib/processor-trace/libipt/src/pt_ild.c index a8d78d4102e4..748c1ae38153 100644 --- a/contrib/processor-trace/libipt/src/pt_ild.c +++ b/contrib/processor-trace/libipt/src/pt_ild.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -33,66 +33,27 @@ #include "pti-modrm.h" #include "pti-disp-defs.h" #include "pti-disp.h" +#include "pti-disp_default.h" +#include "pti-sib.h" #include -/* SET UP 3 TABLES */ -static uint8_t has_disp_regular[4][4][8]; +static const uint8_t eamode_table[2][4] = { + /* Default: */ { + /* ptem_unknown = */ ptem_unknown, + /* ptem_16bit = */ ptem_16bit, + /* ptem_32bit = */ ptem_32bit, + /* ptem_64bit = */ ptem_64bit + }, -static void init_has_disp_regular_table(void) -{ - uint8_t mod, rm; - - memset(has_disp_regular, 0, sizeof(has_disp_regular)); - - /*fill eamode16 */ - has_disp_regular[ptem_16bit][0][6] = 2; - for (rm = 0; rm < 8; rm++) - for (mod = 1; mod <= 2; mod++) - has_disp_regular[ptem_16bit][mod][rm] = mod; - - /*fill eamode32/64 */ - has_disp_regular[ptem_32bit][0][5] = 4; - has_disp_regular[ptem_64bit][0][5] = 4; - for (rm = 0; rm < 8; rm++) { - has_disp_regular[ptem_32bit][1][rm] = 1; - has_disp_regular[ptem_32bit][2][rm] = 4; - - has_disp_regular[ptem_64bit][1][rm] = 1; - has_disp_regular[ptem_64bit][2][rm] = 4; + /* With Address-size prefix (0x67): */ { + /* ptem_unknown = */ ptem_unknown, + /* ptem_16bit = */ ptem_32bit, + /* ptem_32bit = */ ptem_16bit, + /* ptem_64bit = */ ptem_32bit } -} - -static uint8_t eamode_table[2][4]; - -static void init_eamode_table(void) -{ - eamode_table[0][ptem_unknown] = ptem_unknown; - eamode_table[0][ptem_16bit] = ptem_16bit; - eamode_table[0][ptem_32bit] = ptem_32bit; - eamode_table[0][ptem_64bit] = ptem_64bit; - - eamode_table[1][ptem_unknown] = ptem_unknown; - eamode_table[1][ptem_16bit] = ptem_32bit; - eamode_table[1][ptem_32bit] = ptem_16bit; - eamode_table[1][ptem_64bit] = ptem_32bit; -} - -static uint8_t has_sib_table[4][4][8]; - -static void init_has_sib_table(void) -{ - uint8_t mod; - - memset(has_sib_table, 0, sizeof(has_sib_table)); - - /*for eamode32/64 there is sib byte for mod!=3 and rm==4 */ - for (mod = 0; mod <= 2; mod++) { - has_sib_table[ptem_32bit][mod][4] = 1; - has_sib_table[ptem_64bit][mod][4] = 1; - } -} +}; /* SOME ACCESSORS */ @@ -479,12 +440,12 @@ static int modrm_dec(struct pt_ild *ild, uint8_t length) uint8_t eamode = eamode_table[ild->u.s.asz][ild->mode]; uint8_t mod = (uint8_t) pti_get_modrm_mod(ild); uint8_t rm = (uint8_t) pti_get_modrm_rm(ild); - uint8_t has_sib; + uint8_t sib; - ild->disp_bytes = has_disp_regular[eamode][mod][rm]; + ild->disp_bytes = disp_default[eamode][mod][rm]; - has_sib = has_sib_table[eamode][mod][rm]; - if (has_sib) + sib = has_sib[eamode][mod][rm]; + if (sib) return sib_dec(ild, length + 1); } @@ -557,7 +518,292 @@ static int opcode_dec(struct pt_ild *ild, uint8_t length) } typedef int (*prefix_decoder)(struct pt_ild *ild, uint8_t length, uint8_t rex); -static prefix_decoder prefix_table[256]; + +static int prefix_osz(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_asz(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_lock(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_f2(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_f3(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_rex(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_vex_c4(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_vex_c5(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_evex(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_ignore(struct pt_ild *ild, uint8_t length, uint8_t rex); +static int prefix_done(struct pt_ild *ild, uint8_t length, uint8_t rex); + +static const prefix_decoder prefix_table[256] = { + /* 00 = */ prefix_done, + /* 01 = */ prefix_done, + /* 02 = */ prefix_done, + /* 03 = */ prefix_done, + /* 04 = */ prefix_done, + /* 05 = */ prefix_done, + /* 06 = */ prefix_done, + /* 07 = */ prefix_done, + /* 08 = */ prefix_done, + /* 09 = */ prefix_done, + /* 0a = */ prefix_done, + /* 0b = */ prefix_done, + /* 0c = */ prefix_done, + /* 0d = */ prefix_done, + /* 0e = */ prefix_done, + /* 0f = */ prefix_done, + + /* 10 = */ prefix_done, + /* 11 = */ prefix_done, + /* 12 = */ prefix_done, + /* 13 = */ prefix_done, + /* 14 = */ prefix_done, + /* 15 = */ prefix_done, + /* 16 = */ prefix_done, + /* 17 = */ prefix_done, + /* 18 = */ prefix_done, + /* 19 = */ prefix_done, + /* 1a = */ prefix_done, + /* 1b = */ prefix_done, + /* 1c = */ prefix_done, + /* 1d = */ prefix_done, + /* 1e = */ prefix_done, + /* 1f = */ prefix_done, + + /* 20 = */ prefix_done, + /* 21 = */ prefix_done, + /* 22 = */ prefix_done, + /* 23 = */ prefix_done, + /* 24 = */ prefix_done, + /* 25 = */ prefix_done, + /* 26 = */ prefix_ignore, + /* 27 = */ prefix_done, + /* 28 = */ prefix_done, + /* 29 = */ prefix_done, + /* 2a = */ prefix_done, + /* 2b = */ prefix_done, + /* 2c = */ prefix_done, + /* 2d = */ prefix_done, + /* 2e = */ prefix_ignore, + /* 2f = */ prefix_done, + + /* 30 = */ prefix_done, + /* 31 = */ prefix_done, + /* 32 = */ prefix_done, + /* 33 = */ prefix_done, + /* 34 = */ prefix_done, + /* 35 = */ prefix_done, + /* 36 = */ prefix_ignore, + /* 37 = */ prefix_done, + /* 38 = */ prefix_done, + /* 39 = */ prefix_done, + /* 3a = */ prefix_done, + /* 3b = */ prefix_done, + /* 3c = */ prefix_done, + /* 3d = */ prefix_done, + /* 3e = */ prefix_ignore, + /* 3f = */ prefix_done, + + /* 40 = */ prefix_rex, + /* 41 = */ prefix_rex, + /* 42 = */ prefix_rex, + /* 43 = */ prefix_rex, + /* 44 = */ prefix_rex, + /* 45 = */ prefix_rex, + /* 46 = */ prefix_rex, + /* 47 = */ prefix_rex, + /* 48 = */ prefix_rex, + /* 49 = */ prefix_rex, + /* 4a = */ prefix_rex, + /* 4b = */ prefix_rex, + /* 4c = */ prefix_rex, + /* 4d = */ prefix_rex, + /* 4e = */ prefix_rex, + /* 4f = */ prefix_rex, + + /* 50 = */ prefix_done, + /* 51 = */ prefix_done, + /* 52 = */ prefix_done, + /* 53 = */ prefix_done, + /* 54 = */ prefix_done, + /* 55 = */ prefix_done, + /* 56 = */ prefix_done, + /* 57 = */ prefix_done, + /* 58 = */ prefix_done, + /* 59 = */ prefix_done, + /* 5a = */ prefix_done, + /* 5b = */ prefix_done, + /* 5c = */ prefix_done, + /* 5d = */ prefix_done, + /* 5e = */ prefix_done, + /* 5f = */ prefix_done, + + /* 60 = */ prefix_done, + /* 61 = */ prefix_done, + /* 62 = */ prefix_evex, + /* 63 = */ prefix_done, + /* 64 = */ prefix_ignore, + /* 65 = */ prefix_ignore, + /* 66 = */ prefix_osz, + /* 67 = */ prefix_asz, + /* 68 = */ prefix_done, + /* 69 = */ prefix_done, + /* 6a = */ prefix_done, + /* 6b = */ prefix_done, + /* 6c = */ prefix_done, + /* 6d = */ prefix_done, + /* 6e = */ prefix_done, + /* 6f = */ prefix_done, + + /* 70 = */ prefix_done, + /* 71 = */ prefix_done, + /* 72 = */ prefix_done, + /* 73 = */ prefix_done, + /* 74 = */ prefix_done, + /* 75 = */ prefix_done, + /* 76 = */ prefix_done, + /* 77 = */ prefix_done, + /* 78 = */ prefix_done, + /* 79 = */ prefix_done, + /* 7a = */ prefix_done, + /* 7b = */ prefix_done, + /* 7c = */ prefix_done, + /* 7d = */ prefix_done, + /* 7e = */ prefix_done, + /* 7f = */ prefix_done, + + /* 80 = */ prefix_done, + /* 81 = */ prefix_done, + /* 82 = */ prefix_done, + /* 83 = */ prefix_done, + /* 84 = */ prefix_done, + /* 85 = */ prefix_done, + /* 86 = */ prefix_done, + /* 87 = */ prefix_done, + /* 88 = */ prefix_done, + /* 89 = */ prefix_done, + /* 8a = */ prefix_done, + /* 8b = */ prefix_done, + /* 8c = */ prefix_done, + /* 8d = */ prefix_done, + /* 8e = */ prefix_done, + /* 8f = */ prefix_done, + + /* 90 = */ prefix_done, + /* 91 = */ prefix_done, + /* 92 = */ prefix_done, + /* 93 = */ prefix_done, + /* 94 = */ prefix_done, + /* 95 = */ prefix_done, + /* 96 = */ prefix_done, + /* 97 = */ prefix_done, + /* 98 = */ prefix_done, + /* 99 = */ prefix_done, + /* 9a = */ prefix_done, + /* 9b = */ prefix_done, + /* 9c = */ prefix_done, + /* 9d = */ prefix_done, + /* 9e = */ prefix_done, + /* 9f = */ prefix_done, + + /* a0 = */ prefix_done, + /* a1 = */ prefix_done, + /* a2 = */ prefix_done, + /* a3 = */ prefix_done, + /* a4 = */ prefix_done, + /* a5 = */ prefix_done, + /* a6 = */ prefix_done, + /* a7 = */ prefix_done, + /* a8 = */ prefix_done, + /* a9 = */ prefix_done, + /* aa = */ prefix_done, + /* ab = */ prefix_done, + /* ac = */ prefix_done, + /* ad = */ prefix_done, + /* ae = */ prefix_done, + /* af = */ prefix_done, + + /* b0 = */ prefix_done, + /* b1 = */ prefix_done, + /* b2 = */ prefix_done, + /* b3 = */ prefix_done, + /* b4 = */ prefix_done, + /* b5 = */ prefix_done, + /* b6 = */ prefix_done, + /* b7 = */ prefix_done, + /* b8 = */ prefix_done, + /* b9 = */ prefix_done, + /* ba = */ prefix_done, + /* bb = */ prefix_done, + /* bc = */ prefix_done, + /* bd = */ prefix_done, + /* be = */ prefix_done, + /* bf = */ prefix_done, + + /* c0 = */ prefix_done, + /* c1 = */ prefix_done, + /* c2 = */ prefix_done, + /* c3 = */ prefix_done, + /* c4 = */ prefix_vex_c4, + /* c5 = */ prefix_vex_c5, + /* c6 = */ prefix_done, + /* c7 = */ prefix_done, + /* c8 = */ prefix_done, + /* c9 = */ prefix_done, + /* ca = */ prefix_done, + /* cb = */ prefix_done, + /* cc = */ prefix_done, + /* cd = */ prefix_done, + /* ce = */ prefix_done, + /* cf = */ prefix_done, + + /* d0 = */ prefix_done, + /* d1 = */ prefix_done, + /* d2 = */ prefix_done, + /* d3 = */ prefix_done, + /* d4 = */ prefix_done, + /* d5 = */ prefix_done, + /* d6 = */ prefix_done, + /* d7 = */ prefix_done, + /* d8 = */ prefix_done, + /* d9 = */ prefix_done, + /* da = */ prefix_done, + /* db = */ prefix_done, + /* dc = */ prefix_done, + /* dd = */ prefix_done, + /* de = */ prefix_done, + /* df = */ prefix_done, + + /* e0 = */ prefix_done, + /* e1 = */ prefix_done, + /* e2 = */ prefix_done, + /* e3 = */ prefix_done, + /* e4 = */ prefix_done, + /* e5 = */ prefix_done, + /* e6 = */ prefix_done, + /* e7 = */ prefix_done, + /* e8 = */ prefix_done, + /* e9 = */ prefix_done, + /* ea = */ prefix_done, + /* eb = */ prefix_done, + /* ec = */ prefix_done, + /* ed = */ prefix_done, + /* ee = */ prefix_done, + /* ef = */ prefix_done, + + /* f0 = */ prefix_lock, + /* f1 = */ prefix_done, + /* f2 = */ prefix_f2, + /* f3 = */ prefix_f3, + /* f4 = */ prefix_done, + /* f5 = */ prefix_done, + /* f6 = */ prefix_done, + /* f7 = */ prefix_done, + /* f8 = */ prefix_done, + /* f9 = */ prefix_done, + /* fa = */ prefix_done, + /* fb = */ prefix_done, + /* fc = */ prefix_done, + /* fd = */ prefix_done, + /* fe = */ prefix_done, + /* ff = */ prefix_done +}; static inline int prefix_decode(struct pt_ild *ild, uint8_t length, uint8_t rex) { @@ -822,36 +1068,6 @@ static int prefix_evex(struct pt_ild *ild, uint8_t length, uint8_t rex) return prefix_vex_done(ild, length); } -static void init_prefix_table(void) -{ - unsigned int byte; - - for (byte = 0; byte <= 0xff; ++byte) - prefix_table[byte] = prefix_done; - - prefix_table[0x66] = prefix_osz; - prefix_table[0x67] = prefix_asz; - - /* Segment prefixes. */ - prefix_table[0x2e] = prefix_ignore; - prefix_table[0x3e] = prefix_ignore; - prefix_table[0x26] = prefix_ignore; - prefix_table[0x36] = prefix_ignore; - prefix_table[0x64] = prefix_ignore; - prefix_table[0x65] = prefix_ignore; - - prefix_table[0xf0] = prefix_lock; - prefix_table[0xf2] = prefix_f2; - prefix_table[0xf3] = prefix_f3; - - for (byte = 0x40; byte <= 0x4f; ++byte) - prefix_table[byte] = prefix_rex; - - prefix_table[0xc4] = prefix_vex_c4; - prefix_table[0xc5] = prefix_vex_c5; - prefix_table[0x62] = prefix_evex; -} - static int decode(struct pt_ild *ild) { return prefix_decode(ild, 0, 0); @@ -885,16 +1101,6 @@ static int set_branch_target(struct pt_insn_ext *iext, const struct pt_ild *ild) return 0; } -/* MAIN ENTRY POINTS */ - -void pt_ild_init(void) -{ /* initialization */ - init_has_disp_regular_table(); - init_has_sib_table(); - init_eamode_table(); - init_prefix_table(); -} - static int pt_instruction_length_decode(struct pt_ild *ild) { if (!ild) diff --git a/contrib/processor-trace/libipt/src/pt_image.c b/contrib/processor-trace/libipt/src/pt_image.c index b22c62601a56..5ec82c6e1a4e 100644 --- a/contrib/processor-trace/libipt/src/pt_image.c +++ b/contrib/processor-trace/libipt/src/pt_image.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -43,12 +43,16 @@ static char *dupstr(const char *str) if (!str) return NULL; - len = strlen(str); + /* Silently truncate the name if it gets too big. */ + len = strnlen(str, 4096ul); + dup = malloc(len + 1); if (!dup) return NULL; - return strcpy(dup, str); + dup[len] = 0; + + return memcpy(dup, str, len); } static struct pt_section_list *pt_mk_section_list(struct pt_section *section, @@ -315,9 +319,10 @@ int pt_image_add_file(struct pt_image *image, const char *filename, if (errcode < 0) return errcode; - section = pt_mk_section(filename, offset, size); - if (!section) - return -pte_invalid; + section = NULL; + errcode = pt_mk_section(§ion, filename, offset, size); + if (errcode < 0) + return errcode; errcode = pt_image_add(image, section, &asid, vaddr, 0); if (errcode < 0) { diff --git a/contrib/processor-trace/libipt/src/pt_image_section_cache.c b/contrib/processor-trace/libipt/src/pt_image_section_cache.c index f380890ee0b4..c2fe64bf3ce7 100644 --- a/contrib/processor-trace/libipt/src/pt_image_section_cache.c +++ b/contrib/processor-trace/libipt/src/pt_image_section_cache.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -42,12 +42,16 @@ static char *dupstr(const char *str) if (!str) return NULL; - len = strlen(str); + /* Silently truncate the name if it gets too big. */ + len = strnlen(str, 4096ul); + dup = malloc(len + 1); if (!dup) return NULL; - return strcpy(dup, str); + dup[len] = 0; + + return memcpy(dup, str, len); } int pt_iscache_init(struct pt_image_section_cache *iscache, const char *name) @@ -975,9 +979,10 @@ int pt_iscache_add_file(struct pt_image_section_cache *iscache, if (errcode < 0) return errcode; - section = pt_mk_section(filename, offset, size); - if (!section) - return -pte_invalid; + section = NULL; + errcode = pt_mk_section(§ion, filename, offset, size); + if (errcode < 0) + return errcode; } /* We unlocked @iscache and hold a reference to @section. */ diff --git a/contrib/processor-trace/libipt/src/pt_insn.c b/contrib/processor-trace/libipt/src/pt_insn.c index 0a41c4bf391e..0e8979159536 100644 --- a/contrib/processor-trace/libipt/src/pt_insn.c +++ b/contrib/processor-trace/libipt/src/pt_insn.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -187,7 +187,8 @@ int pt_insn_next_ip(uint64_t *pip, const struct pt_insn *insn, case ptic_call: case ptic_jump: if (iext->variant.branch.is_direct) { - ip += iext->variant.branch.displacement; + ip += (uint64_t) (int64_t) + iext->variant.branch.displacement; break; } diff --git a/contrib/processor-trace/libipt/src/pt_insn_decoder.c b/contrib/processor-trace/libipt/src/pt_insn_decoder.c index 0cf8740ee8dc..c6088d4a4731 100644 --- a/contrib/processor-trace/libipt/src/pt_insn_decoder.c +++ b/contrib/processor-trace/libipt/src/pt_insn_decoder.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -99,6 +99,8 @@ static int pt_insn_init_qry_flags(struct pt_conf_flags *qflags, return -pte_internal; memset(qflags, 0, sizeof(*qflags)); + qflags->variant.query.keep_tcal_on_ovf = + flags->variant.insn.keep_tcal_on_ovf; return 0; } @@ -598,7 +600,8 @@ static int pt_insn_proceed(struct pt_insn_decoder *decoder, * and all flavors of far transfers. */ if (iext->variant.branch.is_direct) - decoder->ip += iext->variant.branch.displacement; + decoder->ip += (uint64_t) (int64_t) + iext->variant.branch.displacement; else { int status; @@ -641,7 +644,7 @@ static int pt_insn_at_skl014(const struct pt_event *ev, /* Check the filter against the branch target. */ ip = insn->ip; ip += insn->size; - ip += iext->variant.branch.displacement; + ip += (uint64_t) (int64_t) iext->variant.branch.displacement; status = pt_filter_addr_check(&config->addr_filter, ip); if (status <= 0) { @@ -698,7 +701,8 @@ static int pt_insn_at_disabled_event(const struct pt_event *ev, ip = insn->ip; ip += insn->size; - ip += iext->variant.branch.displacement; + ip += (uint64_t) (int64_t) + iext->variant.branch.displacement; if (ip != ev->variant.disabled.ip) break; diff --git a/contrib/processor-trace/libipt/src/pt_last_ip.c b/contrib/processor-trace/libipt/src/pt_last_ip.c index 3c98c9c3c95a..a6a82b7cbb4e 100644 --- a/contrib/processor-trace/libipt/src/pt_last_ip.c +++ b/contrib/processor-trace/libipt/src/pt_last_ip.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_msec_cache.c b/contrib/processor-trace/libipt/src/pt_msec_cache.c index da946e0552d2..c5db101bedb8 100644 --- a/contrib/processor-trace/libipt/src/pt_msec_cache.c +++ b/contrib/processor-trace/libipt/src/pt_msec_cache.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, Intel Corporation + * Copyright (c) 2017-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_packet.c b/contrib/processor-trace/libipt/src/pt_packet.c index e237427ec127..8ec46f7db450 100644 --- a/contrib/processor-trace/libipt/src/pt_packet.c +++ b/contrib/processor-trace/libipt/src/pt_packet.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_packet_decoder.c b/contrib/processor-trace/libipt/src/pt_packet_decoder.c index bf1a1bd0843e..685ae49c3fb1 100644 --- a/contrib/processor-trace/libipt/src/pt_packet_decoder.c +++ b/contrib/processor-trace/libipt/src/pt_packet_decoder.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -35,6 +35,7 @@ #include #include +#include int pt_pkt_decoder_init(struct pt_packet_decoder *decoder, @@ -87,20 +88,34 @@ void pt_pkt_free_decoder(struct pt_packet_decoder *decoder) int pt_pkt_sync_forward(struct pt_packet_decoder *decoder) { - const uint8_t *pos, *sync; + const uint8_t *pos, *sync, *begin; + ptrdiff_t space; int errcode; if (!decoder) return -pte_invalid; + begin = decoder->config.begin; sync = decoder->sync; pos = decoder->pos; if (!pos) - pos = decoder->config.begin; + pos = begin; if (pos == sync) pos += ptps_psb; + if (pos < begin) + return -pte_internal; + + /* Start a bit earlier so we find PSB that have been partially consumed + * by a preceding packet. + */ + space = pos - begin; + if (ptps_psb <= space) + space = ptps_psb - 1; + + pos -= space; + errcode = pt_sync_forward(&sync, pos, &decoder->config); if (errcode < 0) return errcode; @@ -166,7 +181,7 @@ int pt_pkt_get_offset(const struct pt_packet_decoder *decoder, uint64_t *offset) if (!pos) return -pte_nosync; - *offset = pos - begin; + *offset = (uint64_t) (int64_t) (pos - begin); return 0; } @@ -184,7 +199,7 @@ int pt_pkt_get_sync_offset(const struct pt_packet_decoder *decoder, if (!sync) return -pte_nosync; - *offset = sync - begin; + *offset = (uint64_t) (int64_t) (sync - begin); return 0; } diff --git a/contrib/processor-trace/libipt/src/pt_query_decoder.c b/contrib/processor-trace/libipt/src/pt_query_decoder.c index 1941ae4d2f47..888972039d02 100644 --- a/contrib/processor-trace/libipt/src/pt_query_decoder.c +++ b/contrib/processor-trace/libipt/src/pt_query_decoder.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -560,20 +560,34 @@ static int pt_qry_apply_cyc(struct pt_time *time, struct pt_time_cal *tcal, int pt_qry_sync_forward(struct pt_query_decoder *decoder, uint64_t *ip) { - const uint8_t *pos, *sync; + const uint8_t *pos, *sync, *begin; + ptrdiff_t space; int errcode; if (!decoder) return -pte_invalid; + begin = decoder->config.begin; sync = decoder->sync; pos = decoder->pos; if (!pos) - pos = decoder->config.begin; + pos = begin; if (pos == sync) pos += ptps_psb; + if (pos < begin) + return -pte_internal; + + /* Start a bit earlier so we find PSB that have been partially consumed + * by a preceding packet. + */ + space = pos - begin; + if (ptps_psb <= space) + space = ptps_psb - 1; + + pos -= space; + errcode = pt_sync_forward(&sync, pos, &decoder->config); if (errcode < 0) return errcode; @@ -653,7 +667,7 @@ int pt_qry_get_offset(const struct pt_query_decoder *decoder, uint64_t *offset) if (!pos) return -pte_nosync; - *offset = pos - begin; + *offset = (uint64_t) (int64_t) (pos - begin); return 0; } @@ -671,7 +685,7 @@ int pt_qry_get_sync_offset(const struct pt_query_decoder *decoder, if (!sync) return -pte_nosync; - *offset = sync - begin; + *offset = (uint64_t) (int64_t) (sync - begin); return 0; } @@ -1043,6 +1057,10 @@ int pt_qry_decode_psb(struct pt_query_decoder *decoder) if (size < 0) return size; + errcode = pt_tcal_update_psb(&decoder->tcal, &decoder->config); + if (errcode < 0) + return errcode; + decoder->pos += size; errcode = pt_qry_read_psb_header(decoder); @@ -2835,6 +2853,7 @@ static int pt_qry_find_ovf_fup(const struct pt_query_decoder *decoder) int pt_qry_decode_ovf(struct pt_query_decoder *decoder) { + struct pt_time_cal tcal; struct pt_time time; int status, offset; @@ -2851,8 +2870,18 @@ int pt_qry_decode_ovf(struct pt_query_decoder *decoder) /* Reset the decoder state but preserve timing. */ time = decoder->time; + tcal = decoder->tcal; + pt_qry_reset(decoder); + decoder->time = time; + if (decoder->config.flags.variant.query.keep_tcal_on_ovf) { + status = pt_tcal_update_ovf(&tcal, &decoder->config); + if (status < 0) + return status; + + decoder->tcal = tcal; + } /* We must consume the OVF before we search for the binding packet. */ decoder->pos += ptps_ovf; diff --git a/contrib/processor-trace/libipt/src/pt_retstack.c b/contrib/processor-trace/libipt/src/pt_retstack.c index cc568367ed1a..34733f25e869 100644 --- a/contrib/processor-trace/libipt/src/pt_retstack.c +++ b/contrib/processor-trace/libipt/src/pt_retstack.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_section.c b/contrib/processor-trace/libipt/src/pt_section.c index 77bae915fb7b..05f8ee4f7467 100644 --- a/contrib/processor-trace/libipt/src/pt_section.c +++ b/contrib/processor-trace/libipt/src/pt_section.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -37,37 +37,40 @@ #include -static char *dupstr(const char *str) -{ - char *dup; - size_t len; - - if (!str) - return NULL; - - len = strlen(str); - dup = malloc(len + 1); - if (!dup) - return NULL; - - return strcpy(dup, str); -} - -struct pt_section *pt_mk_section(const char *filename, uint64_t offset, - uint64_t size) +int pt_mk_section(struct pt_section **psection, const char *filename, + uint64_t offset, uint64_t size) { struct pt_section *section; uint64_t fsize; + size_t flen; void *status; + char *fname; int errcode; - errcode = pt_section_mk_status(&status, &fsize, filename); + if (!psection) + return -pte_internal; + + flen = strnlen(filename, FILENAME_MAX); + if (FILENAME_MAX <= flen) + return -pte_invalid; + + flen += 1; + + fname = malloc(flen); + if (!fname) + return -pte_nomem; + + memcpy(fname, filename, flen); + + errcode = pt_section_mk_status(&status, &fsize, fname); if (errcode < 0) - return NULL; + goto out_fname; /* Fail if the requested @offset lies beyond the end of @file. */ - if (fsize <= offset) + if (fsize <= offset) { + errcode = -pte_invalid; goto out_status; + } /* Truncate @size so the entire range lies within @file. */ fsize -= offset; @@ -75,12 +78,14 @@ struct pt_section *pt_mk_section(const char *filename, uint64_t offset, size = fsize; section = malloc(sizeof(*section)); - if (!section) + if (!section) { + errcode = -pte_nomem; goto out_status; + } memset(section, 0, sizeof(*section)); - section->filename = dupstr(filename); + section->filename = fname; section->status = status; section->offset = offset; section->size = size; @@ -90,26 +95,32 @@ struct pt_section *pt_mk_section(const char *filename, uint64_t offset, errcode = mtx_init(§ion->lock, mtx_plain); if (errcode != thrd_success) { - free(section->filename); free(section); + + errcode = -pte_bad_lock; goto out_status; } errcode = mtx_init(§ion->alock, mtx_plain); if (errcode != thrd_success) { mtx_destroy(§ion->lock); - free(section->filename); free(section); + + errcode = -pte_bad_lock; goto out_status; } #endif /* defined(FEATURE_THREADS) */ - return section; + *psection = section; + return 0; out_status: free(status); - return NULL; + +out_fname: + free(fname); + return errcode; } int pt_section_lock(struct pt_section *section) diff --git a/contrib/processor-trace/libipt/src/pt_section_file.c b/contrib/processor-trace/libipt/src/pt_section_file.c index 299a94eb7d04..d8a898131aa0 100644 --- a/contrib/processor-trace/libipt/src/pt_section_file.c +++ b/contrib/processor-trace/libipt/src/pt_section_file.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_sync.c b/contrib/processor-trace/libipt/src/pt_sync.c index cf604203b17b..53d36e74d529 100644 --- a/contrib/processor-trace/libipt/src/pt_sync.c +++ b/contrib/processor-trace/libipt/src/pt_sync.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -161,11 +161,12 @@ int pt_sync_set(const uint8_t **sync, const uint8_t *pos, int pt_sync_forward(const uint8_t **sync, const uint8_t *pos, const struct pt_config *config) { - const uint8_t *begin, *end; + const uint8_t *begin, *end, *start; if (!sync || !pos || !config) return -pte_internal; + start = pos; begin = config->begin; end = config->end; @@ -194,6 +195,12 @@ int pt_sync_forward(const uint8_t **sync, const uint8_t *pos, if (!current) continue; + /* If @start points inside a PSB, we may find that one. Ignore + * it unless @start points to its beginning. + */ + if (current < start) + continue; + *sync = current; return 0; } diff --git a/contrib/processor-trace/libipt/src/pt_time.c b/contrib/processor-trace/libipt/src/pt_time.c index 8c55ccde0fd6..d1698147b3d1 100644 --- a/contrib/processor-trace/libipt/src/pt_time.c +++ b/contrib/processor-trace/libipt/src/pt_time.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -154,13 +154,19 @@ int pt_time_update_cbr(struct pt_time *time, const struct pt_packet_cbr *packet, const struct pt_config *config) { + uint8_t cbr; + (void) config; if (!time || !packet) return -pte_internal; + cbr = packet->ratio; + if (!cbr) + return -pte_bad_packet; + time->have_cbr = 1; - time->cbr = packet->ratio; + time->cbr = cbr; return 0; } @@ -254,7 +260,7 @@ int pt_time_update_mtc(struct pt_time *time, last_ctc = time->ctc; mtc_freq = config->mtc_freq; - ctc = packet->ctc << mtc_freq; + ctc = (uint32_t) packet->ctc << mtc_freq; /* Store our CTC value if we have or would have reset FC. */ if (time->fc || time->lost_cyc || !have_mtc) @@ -288,14 +294,14 @@ int pt_time_update_mtc(struct pt_time *time, /* The TMA's CTC value didn't provide enough bits - otherwise, * we would have treated the TMA as an MTC. */ - if (last_ctc & ~pt_pl_tma_ctc_mask) + if (last_ctc & ~(uint32_t) pt_pl_tma_ctc_mask) return -pte_internal; /* Split this MTC's CTC value into low and high parts with * respect to the bits provided by TMA. */ - ctc_lo = ctc & pt_pl_tma_ctc_mask; - ctc_hi = ctc & ~pt_pl_tma_ctc_mask; + ctc_lo = ctc & (uint32_t) pt_pl_tma_ctc_mask; + ctc_hi = ctc & ~(uint32_t) pt_pl_tma_ctc_mask; /* We estimate the high-order CTC bits that are not provided by * TMA based on the CTC bits provided by this MTC. @@ -310,7 +316,7 @@ int pt_time_update_mtc(struct pt_time *time, */ if (ctc_lo < last_ctc) { ctc_hi -= 1u << pt_pl_tma_ctc_bit_size; - ctc_hi &= pt_pl_mtc_mask << mtc_freq; + ctc_hi &= (uint32_t) pt_pl_mtc_mask << mtc_freq; } last_ctc |= ctc_hi; @@ -478,6 +484,18 @@ int pt_tcal_set_fcr(struct pt_time_cal *tcal, uint64_t fcr) return 0; } +int pt_tcal_update_psb(struct pt_time_cal *tcal, + const struct pt_config *config) +{ + if (!tcal || !config) + return -pte_internal; + + if (config->errata.skl168) + tcal->check_skl168 = 1; + + return 0; +} + int pt_tcal_update_tsc(struct pt_time_cal *tcal, const struct pt_packet_tsc *packet, const struct pt_config *config) @@ -519,6 +537,10 @@ int pt_tcal_header_tsc(struct pt_time_cal *tcal, if (!last_tsc || !cyc) return 0; + /* Prefer MTC over TSC for calibration. */ + if (tcal->have_mtc) + return 0; + /* Correct a single wrap-around. */ if (tsc < last_tsc) { tsc += 1ull << pt_pl_tsc_bit_size; @@ -569,6 +591,8 @@ int pt_tcal_header_cbr(struct pt_time_cal *tcal, /* If we know the nominal frequency, we can use it for calibration. */ cbr = packet->ratio; + if (!cbr) + return -pte_bad_packet; fcr = (p1 << pt_tcal_fcr_shr) / cbr; @@ -591,7 +615,7 @@ int pt_tcal_update_mtc(struct pt_time_cal *tcal, const struct pt_packet_mtc *packet, const struct pt_config *config) { - uint32_t last_ctc, ctc, ctc_delta, have_mtc; + uint32_t last_ctc, ctc, ctc_delta, have_mtc, check_skl168; uint64_t cyc, fc, fcr; int errcode; @@ -601,8 +625,12 @@ int pt_tcal_update_mtc(struct pt_time_cal *tcal, last_ctc = tcal->ctc; have_mtc = tcal->have_mtc; cyc = tcal->cyc_mtc; + check_skl168 = tcal->check_skl168; - ctc = packet->ctc << config->mtc_freq; + /* This only affects the first MTC after PSB. */ + tcal->check_skl168 = 0; + + ctc = (uint32_t) packet->ctc << config->mtc_freq; /* We need at least two MTC (including this). */ if (!have_mtc) { @@ -645,6 +673,49 @@ int pt_tcal_update_mtc(struct pt_time_cal *tcal, fcr = (fc << pt_tcal_fcr_shr) / cyc; + /* SKL168: Intel(R) PT CYC Packets Can be Dropped When Immediately + * Preceding PSB. + * + * We skip this MTC if we lost one or more MTC since the last PSB or if + * it looks like we lost a wrap CYC packet. + * + * This is not an error but we count that MTC as lost. + */ + if (check_skl168) { + /* If we lost one or more MTC, the case is clear. */ + if ((1u << config->mtc_freq) < ctc_delta) + return 0; + + /* The case is less clear for a lost wrap CYC packet since we do + * have some variation in the number of cycles. + * + * The CYC counter wraps on the affected processors every 4096 + * cycles. For low MTC frequencies (high values), losing one + * may not be noticeable. + * + * We restrict the workaround to higher MTC frequencies (lower + * values). + * + * We also need a previous FCR so we know how many cycles to + * expect. + */ + if ((config->mtc_freq < 10) && pt_tcal_have_fcr(tcal)) { + uint64_t dfc; + + /* We choose a slightly lower adjustment to account for + * some normal variation. + */ + dfc = (tcal->fcr * (cyc + 0xf00)) >> pt_tcal_fcr_shr; + + /* If we didn't drop a wrap CYC, @dfc should be way + * bigger than @fc. If it isn't, we assume that the + * erratum applied. + */ + if (dfc < fc) + return 0; + } + } + errcode = pt_tcal_set_fcr(tcal, fcr); if (errcode < 0) return errcode; @@ -672,3 +743,18 @@ int pt_tcal_update_cyc(struct pt_time_cal *tcal, return 0; } + +int pt_tcal_update_ovf(struct pt_time_cal *tcal, + const struct pt_config *config) +{ + if (!tcal || !config) + return -pte_internal; + + tcal->tsc = 0ull; + tcal->cyc_tsc = 0ull; + tcal->cyc_mtc = 0ull; + tcal->ctc = 0; + tcal->have_mtc = 0; + + return 0; +} diff --git a/contrib/processor-trace/libipt/src/pt_tnt_cache.c b/contrib/processor-trace/libipt/src/pt_tnt_cache.c index 453663063c7f..74a0988c7b20 100644 --- a/contrib/processor-trace/libipt/src/pt_tnt_cache.c +++ b/contrib/processor-trace/libipt/src/pt_tnt_cache.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/pt_version.c b/contrib/processor-trace/libipt/src/pt_version.c index 09d79573e911..203d3d1f0941 100644 --- a/contrib/processor-trace/libipt/src/pt_version.c +++ b/contrib/processor-trace/libipt/src/pt_version.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -32,9 +32,9 @@ struct pt_version pt_library_version(void) { struct pt_version v = { - /* .major = */ PT_VERSION_MAJOR, + /* .major = */ PT_VERSION_MAJOR, /* .minor = */ PT_VERSION_MINOR, - /* .reserved = */ 0, + /* .patch = */ PT_VERSION_PATCH, /* .build = */ PT_VERSION_BUILD, /* .ext = */ PT_VERSION_EXT }; diff --git a/contrib/processor-trace/libipt/src/windows/pt_cpuid.c b/contrib/processor-trace/libipt/src/windows/pt_cpuid.c index 40013b92fa51..4a2460abfd0e 100644 --- a/contrib/processor-trace/libipt/src/windows/pt_cpuid.c +++ b/contrib/processor-trace/libipt/src/windows/pt_cpuid.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/src/windows/pt_section_windows.c b/contrib/processor-trace/libipt/src/windows/pt_section_windows.c index 73b447a44daf..b6229a06c9fa 100644 --- a/contrib/processor-trace/libipt/src/windows/pt_section_windows.c +++ b/contrib/processor-trace/libipt/src/windows/pt_section_windows.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2018, Intel Corporation + * Copyright (c) 2015-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -47,14 +47,14 @@ static int pt_sec_windows_fstat(const char *filename, struct _stat *stat) fd = _open(filename, _O_RDONLY); if (fd == -1) - return -pte_bad_image; + return -pte_bad_file; errcode = _fstat(fd, stat); _close(fd); if (errcode) - return -pte_bad_image; + return -pte_bad_file; return 0; } @@ -98,7 +98,7 @@ static int check_file_status(struct pt_section *section, int fd) errcode = _fstat(fd, &stat); if (errcode) - return -pte_bad_image; + return -pte_bad_file; status = section->status; if (!status) @@ -256,8 +256,8 @@ int pt_section_map(struct pt_section *section) goto out_unlock; } - fh = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + fh = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (fh == INVALID_HANDLE_VALUE) { /* We failed to open the file read-only. Let's try to open it * read-write; maybe our user has the file open for writing. @@ -265,25 +265,24 @@ int pt_section_map(struct pt_section *section) * We will detect changes to the file via fstat(). */ - fh = CreateFile(filename, GENERIC_READ, FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + fh = CreateFileA(filename, GENERIC_READ, FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, + NULL); if (fh == INVALID_HANDLE_VALUE) { - errcode = -pte_bad_image; + errcode = -pte_bad_file; goto out_unlock; } } fd = _open_osfhandle((intptr_t) fh, _O_RDONLY); if (fd == -1) { - errcode = -pte_bad_image; + errcode = -pte_bad_file; goto out_fh; } errcode = check_file_status(section, fd); - if (errcode < 0) { - errcode = -pte_bad_image; + if (errcode < 0) goto out_fd; - } /* We leave the file open on success. It will be closed when the * section is unmapped. @@ -297,7 +296,7 @@ int pt_section_map(struct pt_section *section) */ file = _fdopen(fd, "rb"); if (!file) { - errcode = -pte_bad_image; + errcode = -pte_bad_file; goto out_fd; } diff --git a/contrib/processor-trace/libipt/test/src/ptunit-asid.c b/contrib/processor-trace/libipt/test/src/ptunit-asid.c index 5622fa64f713..b8983939b526 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-asid.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-asid.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-block_cache.c b/contrib/processor-trace/libipt/test/src/ptunit-block_cache.c index 8d9b8889b8ab..906fe319996b 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-block_cache.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-block_cache.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-block_decoder.c b/contrib/processor-trace/libipt/test/src/ptunit-block_decoder.c new file mode 100644 index 000000000000..89de0cb28914 --- /dev/null +++ b/contrib/processor-trace/libipt/test/src/ptunit-block_decoder.c @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ptunit.h" + +#include "pt_block_decoder.h" + +#include "intel-pt.h" + + +/* A test fixture providing a decoder operating on a small buffer. */ +struct test_fixture { + /* The packet_decoder. */ + struct pt_block_decoder decoder; + + /* The configuration. */ + struct pt_config config; + + /* The buffer it operates on. */ + uint8_t buffer[24]; + + /* The test fixture initialization and finalization functions. */ + struct ptunit_result (*init)(struct test_fixture *tfix); + struct ptunit_result (*fini)(struct test_fixture *tfix); +}; + +static struct ptunit_result tfix_init(struct test_fixture *tfix) +{ + struct pt_config *config; + uint8_t *buffer; + int errcode; + + config = &tfix->config; + buffer = tfix->buffer; + + memset(buffer, 0, sizeof(tfix->buffer)); + + pt_config_init(config); + config->begin = buffer; + config->end = buffer + sizeof(tfix->buffer); + + errcode = pt_blk_decoder_init(&tfix->decoder, config); + ptu_int_eq(errcode, 0); + + return ptu_passed(); +} + +static struct ptunit_result decoder_init_null(void) +{ + struct pt_block_decoder decoder; + struct pt_config config; + int errcode; + + errcode = pt_blk_decoder_init(NULL, &config); + ptu_int_eq(errcode, -pte_internal); + + errcode = pt_blk_decoder_init(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result decoder_fini_null(void) +{ + pt_blk_decoder_fini(NULL); + + return ptu_passed(); +} + +static struct ptunit_result alloc_decoder_null(void) +{ + struct pt_block_decoder *decoder; + + decoder = pt_blk_alloc_decoder(NULL); + ptu_null(decoder); + + return ptu_passed(); +} + +static struct ptunit_result free_decoder_null(void) +{ + pt_blk_free_decoder(NULL); + + return ptu_passed(); +} + +static struct ptunit_result sync_forward_null(void) +{ + int errcode; + + errcode = pt_blk_sync_forward(NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_backward_null(void) +{ + int errcode; + + errcode = pt_blk_sync_backward(NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_null(void) +{ + int errcode; + + errcode = pt_blk_sync_set(NULL, 0ull); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_eos(struct test_fixture *tfix) +{ + int errcode; + + errcode = pt_blk_sync_set(&tfix->decoder, sizeof(tfix->buffer) + 1); + ptu_int_eq(errcode, -pte_eos); + + return ptu_passed(); +} + +static struct ptunit_result get_offset_null(void) +{ + struct pt_block_decoder decoder; + uint64_t offset; + int errcode; + + errcode = pt_blk_get_offset(NULL, &offset); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_blk_get_offset(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result get_offset_init(struct test_fixture *tfix) +{ + uint64_t offset; + int errcode; + + errcode = pt_blk_get_offset(&tfix->decoder, &offset); + ptu_int_eq(errcode, -pte_nosync); + + return ptu_passed(); +} + +static struct ptunit_result get_sync_offset_null(void) +{ + struct pt_block_decoder decoder; + uint64_t offset; + int errcode; + + errcode = pt_blk_get_sync_offset(NULL, &offset); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_blk_get_sync_offset(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result get_image_null(void) +{ + const struct pt_image *image; + + image = pt_blk_get_image(NULL); + ptu_null(image); + + return ptu_passed(); +} + +static struct ptunit_result set_image_null(void) +{ + struct pt_image image; + int errcode; + + errcode = pt_blk_set_image(NULL, &image); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_blk_set_image(NULL, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result get_config_null(void) +{ + const struct pt_config *config; + + config = pt_blk_get_config(NULL); + ptu_null(config); + + return ptu_passed(); +} + +static struct ptunit_result get_config(struct test_fixture *tfix) +{ + const struct pt_config *config; + + config = pt_blk_get_config(&tfix->decoder); + ptu_ptr(config); + + return ptu_passed(); +} + +static struct ptunit_result time_null(void) +{ + struct pt_block_decoder decoder; + uint64_t time; + uint32_t lost_mtc, lost_cyc; + int errcode; + + errcode = pt_blk_time(NULL, &time, &lost_mtc, &lost_cyc); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_blk_time(&decoder, NULL, &lost_mtc, &lost_cyc); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result cbr_null(void) +{ + struct pt_block_decoder decoder; + uint32_t cbr; + int errcode; + + errcode = pt_blk_core_bus_ratio(NULL, &cbr); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_blk_core_bus_ratio(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result asid_null(void) +{ + struct pt_block_decoder decoder; + struct pt_asid asid; + int errcode; + + errcode = pt_blk_asid(NULL, &asid, sizeof(asid)); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_blk_asid(&decoder, NULL, sizeof(asid)); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result next_null(void) +{ + struct pt_block_decoder decoder; + struct pt_block block; + int errcode; + + errcode = pt_blk_next(NULL, &block, sizeof(block)); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_blk_next(&decoder, NULL, sizeof(block)); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result event_null(void) +{ + struct pt_block_decoder decoder; + struct pt_event event; + int errcode; + + errcode = pt_blk_event(NULL, &event, sizeof(event)); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_blk_event(&decoder, NULL, sizeof(event)); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +int main(int argc, char **argv) +{ + struct test_fixture tfix; + struct ptunit_suite suite; + + tfix.init = tfix_init; + tfix.fini = NULL; + + suite = ptunit_mk_suite(argc, argv); + + ptu_run(suite, decoder_init_null); + ptu_run(suite, decoder_fini_null); + ptu_run(suite, alloc_decoder_null); + ptu_run(suite, free_decoder_null); + + ptu_run(suite, sync_forward_null); + ptu_run(suite, sync_backward_null); + ptu_run(suite, sync_set_null); + ptu_run_f(suite, sync_set_eos, tfix); + + ptu_run(suite, get_offset_null); + ptu_run_f(suite, get_offset_init, tfix); + ptu_run(suite, get_sync_offset_null); + + ptu_run(suite, get_image_null); + ptu_run(suite, set_image_null); + + ptu_run(suite, get_config_null); + ptu_run_f(suite, get_config, tfix); + + ptu_run(suite, time_null); + ptu_run(suite, cbr_null); + ptu_run(suite, asid_null); + + ptu_run(suite, next_null); + ptu_run(suite, event_null); + + return ptunit_report(&suite); +} diff --git a/contrib/processor-trace/libipt/test/src/ptunit-config.c b/contrib/processor-trace/libipt/test/src/ptunit-config.c index a4332ec112f0..1cf7dbffb0cf 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-config.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-config.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2018, Intel Corporation + * Copyright (c) 2015-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -464,6 +464,67 @@ static struct ptunit_result addr_filter_ip_in_stop_in(void) return ptu_passed(); } +static struct ptunit_result cpu_errata_null(void) +{ + struct pt_errata errata; + struct pt_cpu cpu; + int errcode; + + errcode = pt_cpu_errata(&errata, NULL); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_cpu_errata(NULL, &cpu); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result cpu_errata_unknown(void) +{ + struct pt_errata errata; + struct pt_cpu cpu; + int errcode; + + memset(&cpu, 0, sizeof(cpu)); + + errcode = pt_cpu_errata(&errata, &cpu); + ptu_int_eq(errcode, -pte_bad_cpu); + + return ptu_passed(); +} + +static struct ptunit_result cpu_errata_bad_vendor(void) +{ + struct pt_errata errata; + struct pt_cpu cpu; + int errcode; + + memset(&cpu, 0, sizeof(cpu)); + cpu.vendor = (enum pt_cpu_vendor) 0xffff; + + errcode = pt_cpu_errata(&errata, &cpu); + ptu_int_eq(errcode, -pte_bad_cpu); + + return ptu_passed(); +} + +static struct ptunit_result cpu_errata_bad_cpuid(void) +{ + struct pt_errata errata; + struct pt_cpu cpu; + int errcode; + + memset(&cpu, 0, sizeof(cpu)); + cpu.vendor = pcv_intel; + cpu.family = 6; + cpu.model = 63; + + errcode = pt_cpu_errata(&errata, &cpu); + ptu_int_eq(errcode, -pte_bad_cpu); + + return ptu_passed(); +} + int main(int argc, char **argv) { struct ptunit_suite suite; @@ -492,5 +553,10 @@ int main(int argc, char **argv) ptu_run(suite, addr_filter_ip_out_stop_in); ptu_run(suite, addr_filter_ip_in_stop_in); + ptu_run(suite, cpu_errata_null); + ptu_run(suite, cpu_errata_unknown); + ptu_run(suite, cpu_errata_bad_vendor); + ptu_run(suite, cpu_errata_bad_cpuid); + return ptunit_report(&suite); } diff --git a/contrib/processor-trace/libipt/test/src/ptunit-cpp.cpp b/contrib/processor-trace/libipt/test/src/ptunit-cpp.cpp index dad41362a7a2..f288cbc53141 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-cpp.cpp +++ b/contrib/processor-trace/libipt/test/src/ptunit-cpp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-cpu.c b/contrib/processor-trace/libipt/test/src/ptunit-cpu.c index a82e0f51cea0..bd49368a6fc2 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-cpu.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-cpu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-encoder.c b/contrib/processor-trace/libipt/test/src/ptunit-encoder.c new file mode 100644 index 000000000000..215da2b7e83e --- /dev/null +++ b/contrib/processor-trace/libipt/test/src/ptunit-encoder.c @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ptunit.h" + +#include "pt_encoder.h" + +#include "intel-pt.h" + + +/* A test fixture providing a decoder operating on a small buffer. */ +struct test_fixture { + /* The encoder. */ + struct pt_encoder encoder; + + /* The configuration. */ + struct pt_config config; + + /* The buffer it operates on. */ + uint8_t buffer[24]; + + /* The test fixture initialization and finalization functions. */ + struct ptunit_result (*init)(struct test_fixture *tfix); + struct ptunit_result (*fini)(struct test_fixture *tfix); +}; + +static struct ptunit_result tfix_init(struct test_fixture *tfix) +{ + struct pt_config *config; + uint8_t *buffer; + int errcode; + + config = &tfix->config; + buffer = tfix->buffer; + + memset(buffer, 0, sizeof(tfix->buffer)); + + pt_config_init(config); + config->begin = buffer; + config->end = buffer + sizeof(tfix->buffer); + + errcode = pt_encoder_init(&tfix->encoder, config); + ptu_int_eq(errcode, 0); + + return ptu_passed(); +} + +static struct ptunit_result encoder_init_null(void) +{ + struct pt_encoder encoder; + struct pt_config config; + int errcode; + + errcode = pt_encoder_init(NULL, &config); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_encoder_init(&encoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result encoder_fini_null(void) +{ + pt_encoder_fini(NULL); + + return ptu_passed(); +} + +static struct ptunit_result alloc_encoder_null(void) +{ + struct pt_encoder *encoder; + + encoder = pt_alloc_encoder(NULL); + ptu_null(encoder); + + return ptu_passed(); +} + +static struct ptunit_result free_encoder_null(void) +{ + pt_free_encoder(NULL); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_null(void) +{ + int errcode; + + errcode = pt_enc_sync_set(NULL, 0ull); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_eos(struct test_fixture *tfix) +{ + int errcode; + + errcode = pt_enc_sync_set(&tfix->encoder, sizeof(tfix->buffer) + 1); + ptu_int_eq(errcode, -pte_eos); + + return ptu_passed(); +} + +static struct ptunit_result get_offset_null(void) +{ + struct pt_encoder encoder; + uint64_t offset; + int errcode; + + errcode = pt_enc_get_offset(NULL, &offset); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_enc_get_offset(&encoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result get_offset_init(struct test_fixture *tfix) +{ + uint64_t offset; + int errcode; + + errcode = pt_enc_get_offset(&tfix->encoder, &offset); + ptu_int_eq(errcode, 0); + ptu_uint_eq(offset, 0ull); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_get_offset(struct test_fixture *tfix) +{ + uint64_t offset; + int errcode; + + errcode = pt_enc_sync_set(&tfix->encoder, 1ull); + ptu_int_eq(errcode, 0); + + errcode = pt_enc_get_offset(&tfix->encoder, &offset); + ptu_int_eq(errcode, 0); + ptu_uint_eq(offset, 1ull); + + return ptu_passed(); +} + +static struct ptunit_result get_config_null(void) +{ + const struct pt_config *config; + + config = pt_enc_get_config(NULL); + ptu_null(config); + + return ptu_passed(); +} + +static struct ptunit_result get_config(struct test_fixture *tfix) +{ + const struct pt_config *config; + + config = pt_enc_get_config(&tfix->encoder); + ptu_ptr(config); + + return ptu_passed(); +} + +static struct ptunit_result next_null(void) +{ + struct pt_encoder encoder; + struct pt_packet packet; + int errcode; + + errcode = pt_enc_next(NULL, &packet); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_enc_next(&encoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +int main(int argc, char **argv) +{ + struct test_fixture tfix; + struct ptunit_suite suite; + + tfix.init = tfix_init; + tfix.fini = NULL; + + suite = ptunit_mk_suite(argc, argv); + + ptu_run(suite, encoder_init_null); + ptu_run(suite, encoder_fini_null); + ptu_run(suite, alloc_encoder_null); + ptu_run(suite, free_encoder_null); + + ptu_run(suite, sync_set_null); + ptu_run_f(suite, sync_set_eos, tfix); + + ptu_run(suite, get_offset_null); + ptu_run_f(suite, get_offset_init, tfix); + ptu_run_f(suite, sync_set_get_offset, tfix); + + ptu_run(suite, get_config_null); + ptu_run_f(suite, get_config, tfix); + + ptu_run(suite, next_null); + + return ptunit_report(&suite); +} diff --git a/contrib/processor-trace/libipt/test/src/ptunit-event_queue.c b/contrib/processor-trace/libipt/test/src/ptunit-event_queue.c index 41566e708069..2a962e234e90 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-event_queue.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-event_queue.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-fetch.c b/contrib/processor-trace/libipt/test/src/ptunit-fetch.c index 64c2455ef36b..d5981d56487e 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-fetch.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-fetch.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-ild.c b/contrib/processor-trace/libipt/test/src/ptunit-ild.c index 88d3331ceb6f..6c98397df1fb 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-ild.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-ild.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -690,8 +690,6 @@ int main(int argc, char **argv) { struct ptunit_suite suite; - pt_ild_init(); - suite = ptunit_mk_suite(argc, argv); ptu_run(suite, push); diff --git a/contrib/processor-trace/libipt/test/src/ptunit-image.c b/contrib/processor-trace/libipt/test/src/ptunit-image.c index f635dc366b27..fb8608996c25 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-image.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-image.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -208,15 +208,16 @@ uint64_t pt_section_size(const struct pt_section *section) return section->size; } -struct pt_section *pt_mk_section(const char *file, uint64_t offset, - uint64_t size) +int pt_mk_section(struct pt_section **psection, const char *filename, + uint64_t offset, uint64_t size) { - (void) file; + (void) psection; + (void) filename; (void) offset; (void) size; /* This function is not used by our tests. */ - return NULL; + return -pte_not_supported; } int pt_section_get(struct pt_section *section) diff --git a/contrib/processor-trace/libipt/test/src/ptunit-image_section_cache.c b/contrib/processor-trace/libipt/test/src/ptunit-image_section_cache.c index 1b460b00d996..b94e733ae97f 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-image_section_cache.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-image_section_cache.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Intel Corporation + * Copyright (c) 2016-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -69,8 +69,8 @@ struct pt_section { #endif /* defined(FEATURE_THREADS) */ }; -extern struct pt_section *pt_mk_section(const char *filename, uint64_t offset, - uint64_t size); +extern int pt_mk_section(struct pt_section **psection, const char *filename, + uint64_t offset, uint64_t size); extern int pt_section_get(struct pt_section *section); extern int pt_section_put(struct pt_section *section); @@ -93,45 +93,47 @@ extern int pt_section_read(const struct pt_section *section, uint8_t *buffer, uint16_t size, uint64_t offset); -struct pt_section *pt_mk_section(const char *filename, uint64_t offset, - uint64_t size) +int pt_mk_section(struct pt_section **psection, const char *filename, + uint64_t offset, uint64_t size) { struct pt_section *section; + uint8_t idx; section = malloc(sizeof(*section)); - if (section) { - uint8_t idx; + if (!section) + return -pte_nomem; - memset(section, 0, sizeof(*section)); - section->filename = filename; - section->offset = offset; - section->size = size; - section->ucount = 1; + memset(section, 0, sizeof(*section)); + section->filename = filename; + section->offset = offset; + section->size = size; + section->ucount = 1; - for (idx = 0; idx < sizeof(section->content); ++idx) - section->content[idx] = idx; + for (idx = 0; idx < sizeof(section->content); ++idx) + section->content[idx] = idx; #if defined(FEATURE_THREADS) - { - int errcode; + { + int errcode; - errcode = mtx_init(§ion->lock, mtx_plain); - if (errcode != thrd_success) { - free(section); - section = NULL; - } - - errcode = mtx_init(§ion->alock, mtx_plain); - if (errcode != thrd_success) { - mtx_destroy(§ion->lock); - free(section); - section = NULL; - } + errcode = mtx_init(§ion->lock, mtx_plain); + if (errcode != thrd_success) { + free(section); + return -pte_bad_lock; } -#endif /* defined(FEATURE_THREADS) */ - } - return section; + errcode = mtx_init(§ion->alock, mtx_plain); + if (errcode != thrd_success) { + mtx_destroy(§ion->lock); + free(section); + return -pte_bad_lock; + } + } +#endif /* defined(FEATURE_THREADS) */ + + *psection = section; + + return 0; } static int pt_section_lock(struct pt_section *section) @@ -552,10 +554,12 @@ static struct ptunit_result dfix_init(struct iscache_fixture *cfix) for (idx = 0; idx < num_sections; ++idx) { struct pt_section *section; + int errcode; - section = pt_mk_section("some-filename", + errcode = pt_mk_section(§ion, "some-filename", idx % 3 == 0 ? 0x1000 : 0x2000, idx % 2 == 0 ? 0x1000 : 0x2000); + ptu_int_eq(errcode, 0); ptu_ptr(section); cfix->section[idx] = section; diff --git a/contrib/processor-trace/libipt/test/src/ptunit-insn_decoder.c b/contrib/processor-trace/libipt/test/src/ptunit-insn_decoder.c new file mode 100644 index 000000000000..a45bafa36669 --- /dev/null +++ b/contrib/processor-trace/libipt/test/src/ptunit-insn_decoder.c @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ptunit.h" + +#include "pt_insn_decoder.h" + +#include "intel-pt.h" + + +/* A test fixture providing a decoder operating on a small buffer. */ +struct test_fixture { + /* The packet_decoder. */ + struct pt_insn_decoder decoder; + + /* The configuration. */ + struct pt_config config; + + /* The buffer it operates on. */ + uint8_t buffer[24]; + + /* The test fixture initialization and finalization functions. */ + struct ptunit_result (*init)(struct test_fixture *tfix); + struct ptunit_result (*fini)(struct test_fixture *tfix); +}; + +static struct ptunit_result tfix_init(struct test_fixture *tfix) +{ + struct pt_config *config; + uint8_t *buffer; + int errcode; + + config = &tfix->config; + buffer = tfix->buffer; + + memset(buffer, 0, sizeof(tfix->buffer)); + + pt_config_init(config); + config->begin = buffer; + config->end = buffer + sizeof(tfix->buffer); + + errcode = pt_insn_decoder_init(&tfix->decoder, config); + ptu_int_eq(errcode, 0); + + return ptu_passed(); +} + +static struct ptunit_result decoder_init_null(void) +{ + struct pt_insn_decoder decoder; + struct pt_config config; + int errcode; + + errcode = pt_insn_decoder_init(NULL, &config); + ptu_int_eq(errcode, -pte_internal); + + errcode = pt_insn_decoder_init(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result decoder_fini_null(void) +{ + pt_insn_decoder_fini(NULL); + + return ptu_passed(); +} + +static struct ptunit_result alloc_decoder_null(void) +{ + struct pt_insn_decoder *decoder; + + decoder = pt_insn_alloc_decoder(NULL); + ptu_null(decoder); + + return ptu_passed(); +} + +static struct ptunit_result free_decoder_null(void) +{ + pt_insn_free_decoder(NULL); + + return ptu_passed(); +} + +static struct ptunit_result sync_forward_null(void) +{ + int errcode; + + errcode = pt_insn_sync_forward(NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_backward_null(void) +{ + int errcode; + + errcode = pt_insn_sync_backward(NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_null(void) +{ + int errcode; + + errcode = pt_insn_sync_set(NULL, 0ull); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_eos(struct test_fixture *tfix) +{ + int errcode; + + errcode = pt_insn_sync_set(&tfix->decoder, sizeof(tfix->buffer) + 1); + ptu_int_eq(errcode, -pte_eos); + + return ptu_passed(); +} + +static struct ptunit_result get_offset_null(void) +{ + struct pt_insn_decoder decoder; + uint64_t offset; + int errcode; + + errcode = pt_insn_get_offset(NULL, &offset); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_insn_get_offset(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result get_offset_init(struct test_fixture *tfix) +{ + uint64_t offset; + int errcode; + + errcode = pt_insn_get_offset(&tfix->decoder, &offset); + ptu_int_eq(errcode, -pte_nosync); + + return ptu_passed(); +} + +static struct ptunit_result get_sync_offset_null(void) +{ + struct pt_insn_decoder decoder; + uint64_t offset; + int errcode; + + errcode = pt_insn_get_sync_offset(NULL, &offset); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_insn_get_sync_offset(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result get_config_null(void) +{ + const struct pt_config *config; + + config = pt_insn_get_config(NULL); + ptu_null(config); + + return ptu_passed(); +} + +static struct ptunit_result get_image_null(void) +{ + const struct pt_image *image; + + image = pt_insn_get_image(NULL); + ptu_null(image); + + return ptu_passed(); +} + +static struct ptunit_result set_image_null(void) +{ + struct pt_image image; + int errcode; + + errcode = pt_insn_set_image(NULL, &image); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_insn_set_image(NULL, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result get_config(struct test_fixture *tfix) +{ + const struct pt_config *config; + + config = pt_insn_get_config(&tfix->decoder); + ptu_ptr(config); + + return ptu_passed(); +} + +static struct ptunit_result time_null(void) +{ + struct pt_insn_decoder decoder; + uint64_t time; + uint32_t lost_mtc, lost_cyc; + int errcode; + + errcode = pt_insn_time(NULL, &time, &lost_mtc, &lost_cyc); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_insn_time(&decoder, NULL, &lost_mtc, &lost_cyc); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result cbr_null(void) +{ + struct pt_insn_decoder decoder; + uint32_t cbr; + int errcode; + + errcode = pt_insn_core_bus_ratio(NULL, &cbr); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_insn_core_bus_ratio(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result asid_null(void) +{ + struct pt_insn_decoder decoder; + struct pt_asid asid; + int errcode; + + errcode = pt_insn_asid(NULL, &asid, sizeof(asid)); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_insn_asid(&decoder, NULL, sizeof(asid)); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result next_null(void) +{ + struct pt_insn_decoder decoder; + struct pt_insn insn; + int errcode; + + errcode = pt_insn_next(NULL, &insn, sizeof(insn)); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_insn_next(&decoder, NULL, sizeof(insn)); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result event_null(void) +{ + struct pt_insn_decoder decoder; + struct pt_event event; + int errcode; + + errcode = pt_insn_event(NULL, &event, sizeof(event)); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_insn_event(&decoder, NULL, sizeof(event)); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +int main(int argc, char **argv) +{ + struct test_fixture tfix; + struct ptunit_suite suite; + + tfix.init = tfix_init; + tfix.fini = NULL; + + suite = ptunit_mk_suite(argc, argv); + + ptu_run(suite, decoder_init_null); + ptu_run(suite, decoder_fini_null); + ptu_run(suite, alloc_decoder_null); + ptu_run(suite, free_decoder_null); + + ptu_run(suite, sync_forward_null); + ptu_run(suite, sync_backward_null); + ptu_run(suite, sync_set_null); + ptu_run_f(suite, sync_set_eos, tfix); + + ptu_run(suite, get_offset_null); + ptu_run_f(suite, get_offset_init, tfix); + ptu_run(suite, get_sync_offset_null); + + ptu_run(suite, get_image_null); + ptu_run(suite, set_image_null); + + ptu_run(suite, get_config_null); + ptu_run_f(suite, get_config, tfix); + + ptu_run(suite, time_null); + ptu_run(suite, cbr_null); + ptu_run(suite, asid_null); + + ptu_run(suite, next_null); + ptu_run(suite, event_null); + + return ptunit_report(&suite); +} diff --git a/contrib/processor-trace/libipt/test/src/ptunit-last_ip.c b/contrib/processor-trace/libipt/test/src/ptunit-last_ip.c index bac47a33c3ed..002e9c551a6a 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-last_ip.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-last_ip.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-mapped_section.c b/contrib/processor-trace/libipt/test/src/ptunit-mapped_section.c index 28f0a5bd6779..2b9f563ab82b 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-mapped_section.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-mapped_section.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-msec_cache.c b/contrib/processor-trace/libipt/test/src/ptunit-msec_cache.c index d3926c9a0967..7f6e979f33e4 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-msec_cache.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-msec_cache.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, Intel Corporation + * Copyright (c) 2017-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-packet.c b/contrib/processor-trace/libipt/test/src/ptunit-packet.c index c064081f9968..34df21a994b1 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-packet.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-packet.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-packet_decoder.c b/contrib/processor-trace/libipt/test/src/ptunit-packet_decoder.c new file mode 100644 index 000000000000..5659f9acec33 --- /dev/null +++ b/contrib/processor-trace/libipt/test/src/ptunit-packet_decoder.c @@ -0,0 +1,274 @@ +/* + * Copyright (c) 2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ptunit.h" + +#include "pt_packet_decoder.h" + +#include "intel-pt.h" + + +/* A test fixture providing a decoder operating on a small buffer. */ +struct test_fixture { + /* The packet_decoder. */ + struct pt_packet_decoder decoder; + + /* The configuration. */ + struct pt_config config; + + /* The buffer it operates on. */ + uint8_t buffer[24]; + + /* The test fixture initialization and finalization functions. */ + struct ptunit_result (*init)(struct test_fixture *tfix); + struct ptunit_result (*fini)(struct test_fixture *tfix); +}; + +static struct ptunit_result tfix_init(struct test_fixture *tfix) +{ + struct pt_config *config; + uint8_t *buffer; + int errcode; + + config = &tfix->config; + buffer = tfix->buffer; + + memset(buffer, 0, sizeof(tfix->buffer)); + + pt_config_init(config); + config->begin = buffer; + config->end = buffer + sizeof(tfix->buffer); + + errcode = pt_pkt_decoder_init(&tfix->decoder, config); + ptu_int_eq(errcode, 0); + + return ptu_passed(); +} + +static struct ptunit_result decoder_init_null(void) +{ + struct pt_packet_decoder decoder; + struct pt_config config; + int errcode; + + errcode = pt_pkt_decoder_init(NULL, &config); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_pkt_decoder_init(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result decoder_fini_null(void) +{ + pt_pkt_decoder_fini(NULL); + + return ptu_passed(); +} + +static struct ptunit_result alloc_decoder_null(void) +{ + struct pt_packet_decoder *decoder; + + decoder = pt_pkt_alloc_decoder(NULL); + ptu_null(decoder); + + return ptu_passed(); +} + +static struct ptunit_result free_decoder_null(void) +{ + pt_pkt_free_decoder(NULL); + + return ptu_passed(); +} + +static struct ptunit_result sync_forward_null(void) +{ + int errcode; + + errcode = pt_pkt_sync_forward(NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_backward_null(void) +{ + int errcode; + + errcode = pt_pkt_sync_backward(NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_null(void) +{ + int errcode; + + errcode = pt_pkt_sync_set(NULL, 0ull); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_eos(struct test_fixture *tfix) +{ + int errcode; + + errcode = pt_pkt_sync_set(&tfix->decoder, sizeof(tfix->buffer) + 1); + ptu_int_eq(errcode, -pte_eos); + + return ptu_passed(); +} + +static struct ptunit_result get_offset_null(void) +{ + struct pt_packet_decoder decoder; + uint64_t offset; + int errcode; + + errcode = pt_pkt_get_offset(NULL, &offset); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_pkt_get_offset(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result get_offset_init(struct test_fixture *tfix) +{ + uint64_t offset; + int errcode; + + errcode = pt_pkt_get_offset(&tfix->decoder, &offset); + ptu_int_eq(errcode, -pte_nosync); + + return ptu_passed(); +} + +static struct ptunit_result sync_set_get_offset(struct test_fixture *tfix) +{ + uint64_t offset; + int errcode; + + errcode = pt_pkt_sync_set(&tfix->decoder, 1ull); + ptu_int_eq(errcode, 0); + + errcode = pt_pkt_get_offset(&tfix->decoder, &offset); + ptu_int_eq(errcode, 0); + ptu_uint_eq(offset, 1ull); + + return ptu_passed(); +} + +static struct ptunit_result get_sync_offset_null(void) +{ + struct pt_packet_decoder decoder; + uint64_t offset; + int errcode; + + errcode = pt_pkt_get_sync_offset(NULL, &offset); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_pkt_get_sync_offset(&decoder, NULL); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +static struct ptunit_result get_config_null(void) +{ + const struct pt_config *config; + + config = pt_pkt_get_config(NULL); + ptu_null(config); + + return ptu_passed(); +} + +static struct ptunit_result get_config(struct test_fixture *tfix) +{ + const struct pt_config *config; + + config = pt_pkt_get_config(&tfix->decoder); + ptu_ptr(config); + + return ptu_passed(); +} + +static struct ptunit_result next_null(void) +{ + struct pt_packet_decoder decoder; + struct pt_packet packet; + int errcode; + + errcode = pt_pkt_next(NULL, &packet, sizeof(packet)); + ptu_int_eq(errcode, -pte_invalid); + + errcode = pt_pkt_next(&decoder, NULL, sizeof(packet)); + ptu_int_eq(errcode, -pte_invalid); + + return ptu_passed(); +} + +int main(int argc, char **argv) +{ + struct test_fixture tfix; + struct ptunit_suite suite; + + tfix.init = tfix_init; + tfix.fini = NULL; + + suite = ptunit_mk_suite(argc, argv); + + ptu_run(suite, decoder_init_null); + ptu_run(suite, decoder_fini_null); + ptu_run(suite, alloc_decoder_null); + ptu_run(suite, free_decoder_null); + + ptu_run(suite, sync_forward_null); + ptu_run(suite, sync_backward_null); + ptu_run(suite, sync_set_null); + ptu_run_f(suite, sync_set_eos, tfix); + + ptu_run(suite, get_offset_null); + ptu_run_f(suite, get_offset_init, tfix); + ptu_run_f(suite, sync_set_get_offset, tfix); + ptu_run(suite, get_sync_offset_null); + + ptu_run(suite, get_config_null); + ptu_run_f(suite, get_config, tfix); + + ptu_run(suite, next_null); + + return ptunit_report(&suite); +} diff --git a/contrib/processor-trace/libipt/test/src/ptunit-query.c b/contrib/processor-trace/libipt/test/src/ptunit-query.c index c47ad1223ed2..e22a3e9896bc 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-query.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-query.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -60,16 +60,16 @@ struct ptu_decoder_fixture { }; /* An invalid address. */ -static const uint64_t pt_dfix_bad_ip = (1ull << 62) - 1; +static const uint64_t pt_dfix_bad_ip = (1ull << 62) - 1ull; /* A sign-extended address. */ static const uint64_t pt_dfix_sext_ip = 0xffffff00ff00ff00ull; /* The highest possible address. */ -static const uint64_t pt_dfix_max_ip = (1ull << 47) - 1; +static const uint64_t pt_dfix_max_ip = (1ull << 47) - 1ull; /* The highest possible cr3 value. */ -static const uint64_t pt_dfix_max_cr3 = ((1ull << 47) - 1) & ~0x1f; +static const uint64_t pt_dfix_max_cr3 = ((1ull << 47) - 1ull) & ~0x1full; /* Synchronize the decoder at the beginning of the trace stream, avoiding the * initial PSB header. diff --git a/contrib/processor-trace/libipt/test/src/ptunit-retstack.c b/contrib/processor-trace/libipt/test/src/ptunit-retstack.c index 743eee7b127d..4386601df73e 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-retstack.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-retstack.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-section-file.c b/contrib/processor-trace/libipt/test/src/ptunit-section-file.c index 753de13a3d21..9e04ccbfbc07 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-section-file.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-section-file.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2018, Intel Corporation + * Copyright (c) 2015-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-section.c b/contrib/processor-trace/libipt/test/src/ptunit-section.c index 058bf853589e..6b752c00b90c 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-section.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-section.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -162,10 +162,12 @@ static struct ptunit_result create(struct section_fixture *sfix) const char *name; uint8_t bytes[] = { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }; uint64_t offset, size; + int errcode; sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); name = pt_section_filename(sfix->section); @@ -182,8 +184,10 @@ static struct ptunit_result create(struct section_fixture *sfix) static struct ptunit_result create_bad_offset(struct section_fixture *sfix) { - sfix->section = pt_mk_section(sfix->name, 0x10ull, 0x0ull); - ptu_null(sfix->section); + int errcode; + + errcode = pt_mk_section(&sfix->section, sfix->name, 0x10ull, 0x0ull); + ptu_int_eq(errcode, -pte_invalid); return ptu_passed(); } @@ -193,10 +197,12 @@ static struct ptunit_result create_truncated(struct section_fixture *sfix) const char *name; uint8_t bytes[] = { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }; uint64_t offset, size; + int errcode; sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, UINT64_MAX); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, UINT64_MAX); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); name = pt_section_filename(sfix->section); @@ -213,7 +219,10 @@ static struct ptunit_result create_truncated(struct section_fixture *sfix) static struct ptunit_result create_empty(struct section_fixture *sfix) { - sfix->section = pt_mk_section(sfix->name, 0x0ull, 0x10ull); + int errcode; + + errcode = pt_mk_section(&sfix->section, sfix->name, 0x0ull, 0x10ull); + ptu_int_eq(errcode, -pte_invalid); ptu_null(sfix->section); return ptu_passed(); @@ -359,7 +368,8 @@ static struct ptunit_result get_overflow(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); sfix->section->ucount = UINT16_MAX; @@ -380,7 +390,8 @@ static struct ptunit_result attach_overflow(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); sfix->section->acount = UINT16_MAX; @@ -401,7 +412,8 @@ static struct ptunit_result attach_bad_ucount(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); sfix->section->acount = 2; @@ -421,7 +433,8 @@ static struct ptunit_result map_change(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); sfix_write(sfix, bytes); @@ -439,7 +452,8 @@ static struct ptunit_result map_put(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_map(sfix->section); @@ -461,7 +475,8 @@ static struct ptunit_result unmap_nomap(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_unmap(sfix->section); @@ -477,7 +492,8 @@ static struct ptunit_result map_overflow(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); sfix->section->mcount = UINT16_MAX; @@ -497,7 +513,8 @@ static struct ptunit_result get_put(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_get(sfix->section); @@ -523,7 +540,8 @@ static struct ptunit_result attach_detach(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); sfix->section->ucount += 2; @@ -553,7 +571,8 @@ static struct ptunit_result attach_bad_iscache(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); sfix->section->ucount += 2; @@ -580,7 +599,8 @@ static struct ptunit_result detach_bad_iscache(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_attach(sfix->section, &iscache); @@ -602,7 +622,8 @@ static struct ptunit_result map_unmap(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_map(sfix->section); @@ -630,7 +651,8 @@ static struct ptunit_result attach_map(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_attach(sfix->section, &iscache); @@ -666,7 +688,8 @@ static struct ptunit_result attach_bad_map(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_attach(sfix->section, &iscache); @@ -691,7 +714,8 @@ static struct ptunit_result attach_map_overflow(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_attach(sfix->section, &iscache); @@ -716,7 +740,8 @@ static struct ptunit_result read(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); @@ -742,7 +767,8 @@ static struct ptunit_result read_null(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); @@ -770,7 +796,8 @@ static struct ptunit_result read_offset(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); @@ -795,7 +822,8 @@ static struct ptunit_result read_truncated(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); @@ -819,7 +847,8 @@ static struct ptunit_result read_from_truncated(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x2ull, 0x10ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x2ull, 0x10ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); @@ -843,7 +872,8 @@ static struct ptunit_result read_nomem(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); @@ -866,7 +896,8 @@ static struct ptunit_result read_overflow(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); @@ -890,7 +921,8 @@ static struct ptunit_result read_overflow_32bit(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); @@ -914,7 +946,8 @@ static struct ptunit_result read_nomap(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_read(sfix->section, buffer, 1, 0x0ull); @@ -932,7 +965,8 @@ static struct ptunit_result read_unmap_map(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + status = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(status, 0); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); @@ -1071,7 +1105,8 @@ static struct ptunit_result stress(struct section_fixture *sfix, sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); #if defined(FEATURE_THREADS) @@ -1097,7 +1132,8 @@ static struct ptunit_result init_no_bcache(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_map(sfix->section); @@ -1120,7 +1156,8 @@ static struct ptunit_result bcache_alloc_free(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_map(sfix->section); @@ -1149,7 +1186,8 @@ static struct ptunit_result bcache_alloc_twice(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_map(sfix->section); @@ -1174,7 +1212,8 @@ static struct ptunit_result bcache_alloc_nomap(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_alloc_bcache(sfix->section); @@ -1191,7 +1230,8 @@ static struct ptunit_result memsize_nomap(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_memsize(sfix->section, &memsize); @@ -1209,7 +1249,8 @@ static struct ptunit_result memsize_unmap(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_map(sfix->section); @@ -1233,7 +1274,8 @@ static struct ptunit_result memsize_map_nobcache(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_map(sfix->section); @@ -1260,7 +1302,8 @@ static struct ptunit_result memsize_map_bcache(struct section_fixture *sfix) sfix_write(sfix, bytes); - sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); + errcode = pt_mk_section(&sfix->section, sfix->name, 0x1ull, 0x3ull); + ptu_int_eq(errcode, 0); ptu_ptr(sfix->section); errcode = pt_section_map(sfix->section); @@ -1298,31 +1341,55 @@ static struct ptunit_result sfix_init(struct section_fixture *sfix) static struct ptunit_result sfix_fini(struct section_fixture *sfix) { - int thrd; + char *filename; + FILE *file; + int thrd, errcode; ptu_test(ptunit_thrd_fini, &sfix->thrd); - for (thrd = 0; thrd < sfix->thrd.nthreads; ++thrd) - ptu_int_eq(sfix->thrd.result[thrd], 0); - if (sfix->section) { pt_section_put(sfix->section); sfix->section = NULL; } - if (sfix->file) { - fclose(sfix->file); - sfix->file = NULL; + filename = sfix->name; + file = sfix->file; + sfix->name = NULL; + sfix->file = NULL; - if (sfix->name) - remove(sfix->name); + /* Try removing the file while we still have it open to avoid races + * with others re-using the temporary filename. + * + * On some systems that may not be possible and we can choose between: + * + * - guaranteed leaking files or + * - running the risk of removing someone elses file + * + * We choose the latter. Assuming those systems behave consistently, + * removing someone elses file should only succeed if it isn't open at + * the moment we try removing it. Given that this is a temporary file, + * we should be able to rule out accidental name clashes with + * non-termporary files. + */ + if (filename && file) { + errcode = remove(filename); + if (!errcode) { + free(filename); + filename = NULL; + } } - if (sfix->name) { - free(sfix->name); - sfix->name = NULL; + if (file) + fclose(file); + + if (filename) { + (void) remove(filename); + free(filename); } + for (thrd = 0; thrd < sfix->thrd.nthreads; ++thrd) + ptu_int_eq(sfix->thrd.result[thrd], 0); + return ptu_passed(); } diff --git a/contrib/processor-trace/libipt/test/src/ptunit-sync.c b/contrib/processor-trace/libipt/test/src/ptunit-sync.c index 343f9d92886c..b42304f5e663 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-sync.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-sync.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/contrib/processor-trace/libipt/test/src/ptunit-time.c b/contrib/processor-trace/libipt/test/src/ptunit-time.c index 5beb623c20bc..c6a1c4715221 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-time.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-time.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018, Intel Corporation + * Copyright (c) 2014-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -207,6 +207,22 @@ static struct ptunit_result tcal_cbr_null(struct time_fixture *tfix) return ptu_passed(); } +static struct ptunit_result tcal_cbr_zero(struct time_fixture *tfix) +{ + struct pt_packet_cbr packet; + struct pt_config config; + int errcode; + + config = tfix->config; + config.nom_freq = 1; + packet.ratio = 0; + + errcode = pt_tcal_update_cbr(&tfix->tcal, &packet, &config); + ptu_int_eq(errcode, -pte_bad_packet); + + return ptu_passed(); +} + static struct ptunit_result tcal_mtc_null(struct time_fixture *tfix) { struct pt_packet_mtc packet; @@ -279,6 +295,19 @@ static struct ptunit_result cbr(struct time_fixture *tfix) return ptu_passed(); } +static struct ptunit_result cbr_zero(struct time_fixture *tfix) +{ + struct pt_packet_cbr packet; + int errcode; + + packet.ratio = 0; + + errcode = pt_time_update_cbr(&tfix->time, &packet, &tfix->config); + ptu_int_eq(errcode, -pte_bad_packet); + + return ptu_passed(); +} + static struct ptunit_result tma(struct time_fixture *tfix) { struct pt_packet_tma packet; @@ -353,11 +382,13 @@ int main(int argc, char **argv) ptu_run_f(suite, query_cbr_none, tfix); ptu_run_f(suite, tcal_cbr_null, tfix); + ptu_run_f(suite, tcal_cbr_zero, tfix); ptu_run_f(suite, tcal_mtc_null, tfix); ptu_run_f(suite, tcal_cyc_null, tfix); ptu_run_f(suite, tsc, tfix); ptu_run_f(suite, cbr, tfix); + ptu_run_f(suite, cbr_zero, tfix); ptu_run_f(suite, tma, tfix); ptu_run_f(suite, mtc, tfix); ptu_run_f(suite, cyc, tfix); diff --git a/contrib/processor-trace/libipt/test/src/ptunit-tnt_cache.c b/contrib/processor-trace/libipt/test/src/ptunit-tnt_cache.c index 56631ca04f4f..f207ca02f755 100644 --- a/contrib/processor-trace/libipt/test/src/ptunit-tnt_cache.c +++ b/contrib/processor-trace/libipt/test/src/ptunit-tnt_cache.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2018, Intel Corporation + * Copyright (c) 2013-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/lib/libipt/Makefile b/lib/libipt/Makefile index e320218293c6..df300e699bc0 100644 --- a/lib/libipt/Makefile +++ b/lib/libipt/Makefile @@ -17,7 +17,6 @@ LIB= ipt SHLIB_MAJOR=0 SRCS= \ - init.c \ pt_asid.c \ pt_block_cache.c \ pt_block_decoder.c \ @@ -34,6 +33,7 @@ SRCS= \ pt_insn_decoder.c \ pt_insn.c \ pt_last_ip.c \ + pt_msec_cache.c \ pt_packet_decoder.c \ pt_packet.c \ pt_query_decoder.c \ @@ -57,7 +57,8 @@ CFLAGS+= \ -DPT_VERSION_BUILD=0 \ -DPT_VERSION_EXT=\"\" \ -DPT_VERSION_MAJOR=1 \ - -DPT_VERSION_MINOR=6 + -DPT_VERSION_MINOR=6 \ + -DPT_VERSION_PATCH=0 INCS= \ intel-pt.h \