-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[TSan] Add instrumentation of AVX2 and AVX512 instructions #74636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 14 commits
5091125
e543457
0415d2c
893b94f
1f9ad09
f6368e4
80554ae
5ce165c
fea56d7
bfa17f8
78dbd65
420a350
f5e62a2
9702a23
e21da01
a8891dc
26cd861
d34a62a
08ffa12
4770219
d372015
fcec776
dc846ed
d1fabd6
12b0fe9
9b970b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "tsan_interface_avx2.h" | ||
|
||
#include <immintrin.h> | ||
#include <inttypes.h> | ||
#include <stdint.h> | ||
#include <unistd.h> | ||
|
||
#include "sanitizer_common/sanitizer_internal_defs.h" | ||
#include "sanitizer_common/sanitizer_ptrauth.h" | ||
#include "tsan_interface_ann.h" | ||
#include "tsan_rtl.h" | ||
|
||
#define CALLERPC ((uptr)__builtin_return_address(0)) | ||
|
||
using namespace __tsan; | ||
|
||
#ifdef __AVX__ | ||
extern "C" void __tsan_scatter_vector4(__m256i vaddr, int size, uint8_t mask) { | ||
void *addr[4] = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We always cast it to something else and never use it as 'void*', so I would do s/void*/uptr/ to remove at least 1 cast. |
||
_mm256_store_si256((__m256i *)addr, vaddr); | ||
uptr pc = CALLERPC; | ||
ThreadState *thr = cur_thread(); | ||
for (int i = 0; i < 4; i++) | ||
if ((mask >> i) & 1) | ||
UnalignedMemoryAccess(thr, pc, (uptr)addr[i], size, kAccessWrite); | ||
} | ||
|
||
extern "C" void __tsan_gather_vector4(__m256i vaddr, int size, uint8_t mask) { | ||
void *addr[4] = {}; | ||
_mm256_store_si256((__m256i *)addr, vaddr); | ||
uptr pc = CALLERPC; | ||
ThreadState *thr = cur_thread(); | ||
for (int i = 0; i < 4; i++) | ||
if ((mask >> i) & 1) | ||
UnalignedMemoryAccess(thr, pc, (uptr)addr[i], size, kAccessRead); | ||
} | ||
#endif /*__AVX__*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//===-- tsan_interface_avx2.h ------------------------------------- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file is a part of ThreadSanitizer (TSan), a race detector. | ||
// | ||
// The functions declared in this header will be inserted by the instrumentation | ||
// module. | ||
// This header can be included by the instrumented program or by TSan tests. | ||
//===----------------------------------------------------------------------===// | ||
#ifndef TSAN_INTERFACE_AVX2_H | ||
#define TSAN_INTERFACE_AVX2_H | ||
|
||
#include <immintrin.h> | ||
#include <sanitizer_common/sanitizer_internal_defs.h> | ||
#include <stdint.h> | ||
using __sanitizer::tid_t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not seem to be used. |
||
using __sanitizer::uptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not seem to be used. |
||
|
||
// This header should NOT include any other headers. | ||
// All functions in this header are extern "C" and start with __tsan_. | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#if !SANITIZER_GO | ||
# ifdef __AVX__ | ||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_scatter_vector4(__m256i vaddr, | ||
int width, | ||
uint8_t mask); | ||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_gather_vector4(__m256i vaddr, | ||
int width, | ||
uint8_t mask); | ||
# endif /*__AVX__*/ | ||
#endif // SANITIZER_GO | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
#endif /*TSAN_INTERFACE_AVX2_H*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "tsan_interface_avx512.h" | ||
|
||
#include <immintrin.h> | ||
#include <inttypes.h> | ||
#include <stdint.h> | ||
#include <unistd.h> | ||
|
||
#include "sanitizer_common/sanitizer_internal_defs.h" | ||
#include "sanitizer_common/sanitizer_ptrauth.h" | ||
#include "tsan_interface_ann.h" | ||
#include "tsan_rtl.h" | ||
|
||
#define CALLERPC ((uptr)__builtin_return_address(0)) | ||
|
||
using namespace __tsan; | ||
|
||
#ifdef __AVX512F__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't it be better to always compile this file with -mavx512f? |
||
extern "C" void __tsan_scatter_vector8(__m512i vaddr, int size, uint8_t mask) { | ||
void *addr[8] = {}; | ||
__m256i v256_1 = _mm512_castsi512_si256(vaddr); | ||
__m256i v256_2 = _mm512_extracti64x4_epi64(vaddr, 1); | ||
_mm256_store_si256((__m256i *)addr, v256_1); | ||
_mm256_store_si256((__m256i *)&(addr[4]), v256_2); | ||
uptr pc = CALLERPC; | ||
ThreadState *thr = cur_thread(); | ||
for (int i = 0; i < 8; i++) | ||
if ((mask >> i) & 1) | ||
UnalignedMemoryAccess(thr, pc, (uptr)addr[i], size, kAccessWrite); | ||
} | ||
|
||
extern "C" void __tsan_gather_vector8(__m512i vaddr, int size, uint8_t mask) { | ||
void *addr[8] = {}; | ||
__m256i v256_1 = _mm512_castsi512_si256(vaddr); | ||
__m256i v256_2 = _mm512_extracti64x4_epi64(vaddr, 1); | ||
_mm256_store_si256((__m256i *)addr, v256_1); | ||
_mm256_store_si256((__m256i *)(&addr[4]), v256_2); | ||
uptr pc = CALLERPC; | ||
ThreadState *thr = cur_thread(); | ||
for (int i = 0; i < 8; i++) | ||
if ((mask >> i) & 1) | ||
UnalignedMemoryAccess(thr, pc, (uptr)addr[i], size, kAccessRead); | ||
} | ||
#endif /*__AVX512F__*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//===-- tsan_interface_avx512.h ----------------------------------- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file is a part of ThreadSanitizer (TSan), a race detector. | ||
// | ||
// The functions declared in this header will be inserted by the instrumentation | ||
// module. | ||
// This header can be included by the instrumented program or by TSan tests. | ||
//===----------------------------------------------------------------------===// | ||
#ifndef TSAN_INTERFACE_AVX512_H | ||
#define TSAN_INTERFACE_AVX512_H | ||
|
||
#include <immintrin.h> | ||
#include <sanitizer_common/sanitizer_internal_defs.h> | ||
#include <stdint.h> | ||
using __sanitizer::tid_t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not seem to be used. |
||
using __sanitizer::uptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not seem to be used. |
||
|
||
// This header should NOT include any other headers. | ||
// All functions in this header are extern "C" and start with __tsan_. | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#if !SANITIZER_GO | ||
# ifdef __AVX512F__ | ||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_scatter_vector8(__m512i vaddr, | ||
int width, | ||
uint8_t mask); | ||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_gather_vector8(__m512i vaddr, | ||
int width, | ||
uint8_t mask); | ||
# endif /*__AVX512F__*/ | ||
#endif // SANITIZER_GO | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
#endif /*TSAN_INTERFACE_AVX512_H*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to export this header always?
The compiler is not necessary used on the machine where the it's built.
If we include it unconditionally, it will also make cmake files simpler.