Adding DisableDeepBind debug flag

Related-To: NEO-4946

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2021-02-23 14:03:54 +01:00
committed by Compute-Runtime-Automation
parent c686fb250e
commit 66f4c75aea
14 changed files with 96 additions and 8 deletions

View File

@@ -77,6 +77,8 @@ if(WIN32)
else() else()
list(APPEND IGDRCL_SRCS_offline_compiler_tests list(APPEND IGDRCL_SRCS_offline_compiler_tests
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_thread_linux.cpp ${NEO_SHARED_DIRECTORY}/os_interface/linux/os_thread_linux.cpp
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
) )
endif() endif()

View File

@@ -1,5 +1,5 @@
# #
# Copyright (C) 2018-2020 Intel Corporation # Copyright (C) 2018-2021 Intel Corporation
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# #
@@ -27,6 +27,8 @@ else()
${CMAKE_CURRENT_SOURCE_DIR}/linux/safety_guard_caller_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux/safety_guard_caller_linux.cpp
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.cpp ${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.cpp
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.h ${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.h
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
) )
endif() endif()

View File

@@ -1,19 +1,42 @@
/* /*
* Copyright (C) 2020 Intel Corporation * Copyright (C) 2020-2021 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
*/ */
#include "shared/source/os_interface/linux/os_library_linux.h" #include "shared/source/os_interface/linux/os_library_linux.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <dlfcn.h>
namespace NEO { namespace NEO {
namespace SysCalls {
extern int dlOpenFlags;
extern bool dlOpenCalled;
} // namespace SysCalls
TEST(OsLibraryTest, WhenCreatingFullSystemPathThenProperPathIsConstructed) { TEST(OsLibraryTest, WhenCreatingFullSystemPathThenProperPathIsConstructed) {
auto fullPath = OsLibrary::createFullSystemPath("test"); auto fullPath = OsLibrary::createFullSystemPath("test");
EXPECT_STREQ("test", fullPath.c_str()); EXPECT_STREQ("test", fullPath.c_str());
} }
TEST(OsLibraryTest, GivenDisableDeepBindFlagWhenOpeningLibraryThenRtldDeepBindFlagIsNotPassed) {
DebugManagerStateRestore restorer;
VariableBackup<int> dlOpenFlagsBackup{&NEO::SysCalls::dlOpenFlags, 0};
VariableBackup<bool> dlOpenCalledBackup{&NEO::SysCalls::dlOpenCalled, false};
DebugManager.flags.DisableDeepBind.set(1);
auto lib = std::make_unique<Linux::OsLibrary>("abc");
EXPECT_TRUE(NEO::SysCalls::dlOpenCalled);
EXPECT_EQ(0, NEO::SysCalls::dlOpenFlags & RTLD_DEEPBIND);
}
} // namespace NEO } // namespace NEO

View File

@@ -13,6 +13,7 @@
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <dlfcn.h>
#include <iostream> #include <iostream>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -23,6 +24,8 @@ namespace NEO {
namespace SysCalls { namespace SysCalls {
uint32_t closeFuncCalled = 0u; uint32_t closeFuncCalled = 0u;
int closeFuncArgPassed = 0; int closeFuncArgPassed = 0;
int dlOpenFlags = 0;
bool dlOpenCalled = 0;
constexpr int fakeFileDescriptor = 123; constexpr int fakeFileDescriptor = 123;
uint32_t vmId = 0; uint32_t vmId = 0;
bool makeFakeDevicePath = false; bool makeFakeDevicePath = false;
@@ -43,6 +46,13 @@ int open(const char *file, int flags) {
} }
return 0; return 0;
} }
void *dlopen(const char *filename, int flag) {
dlOpenFlags = flag;
dlOpenCalled = true;
return ::dlopen(filename, flag);
}
int ioctl(int fileDescriptor, unsigned long int request, void *arg) { int ioctl(int fileDescriptor, unsigned long int request, void *arg) {
if (fileDescriptor == fakeFileDescriptor) { if (fileDescriptor == fakeFileDescriptor) {
if (request == DRM_IOCTL_VERSION) { if (request == DRM_IOCTL_VERSION) {

View File

@@ -214,3 +214,4 @@ ForceBtpPrefetchMode = -1
OverrideProfilingTimerResolution = -1 OverrideProfilingTimerResolution = -1
PreferCopyEngineForCopyBufferToBuffer = -1 PreferCopyEngineForCopyBufferToBuffer = -1
EnableStaticPartitioning = -1 EnableStaticPartitioning = -1
DisableDeepBind = 0

View File

@@ -83,7 +83,9 @@ else()
list(APPEND CLOC_LIB_SRCS_LIB list(APPEND CLOC_LIB_SRCS_LIB
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.cpp ${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.cpp
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.h ${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.h
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
${NEO_SOURCE_DIR}/opencl/source/dll/linux/options_linux.cpp ${NEO_SOURCE_DIR}/opencl/source/dll/linux/options_linux.cpp
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
) )
endif() endif()

View File

@@ -0,0 +1,15 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/os_library_linux.h"
namespace NEO {
namespace Linux {
void adjustLibraryFlags(int &dlopenFlag) {
}
} // namespace Linux
} // namespace NEO

View File

@@ -230,3 +230,4 @@ DECLARE_DEBUG_VARIABLE(bool, ReturnRawGpuTimestamps, false, "Driver returns raw
DECLARE_DEBUG_VARIABLE(bool, ForcePerDssBackedBufferProgramming, false, "Always program per-DSS memory backed buffer in preamble") DECLARE_DEBUG_VARIABLE(bool, ForcePerDssBackedBufferProgramming, false, "Always program per-DSS memory backed buffer in preamble")
DECLARE_DEBUG_VARIABLE(bool, DisableAtomicForPostSyncs, false, "When enabled, post syncs are not tracked with atomics") DECLARE_DEBUG_VARIABLE(bool, DisableAtomicForPostSyncs, false, "When enabled, post syncs are not tracked with atomics")
DECLARE_DEBUG_VARIABLE(bool, UseCommandBufferHeaderSizeForWddmQueueSubmission, true, "0: Page size (4096), 1: sizeof(COMMAND_BUFFER_HEADER)") DECLARE_DEBUG_VARIABLE(bool, UseCommandBufferHeaderSizeForWddmQueueSubmission, true, "0: Page size (4096), 1: sizeof(COMMAND_BUFFER_HEADER)")
DECLARE_DEBUG_VARIABLE(bool, DisableDeepBind, false, "Disable passing RTLD_DEEPBIND flag to all dlopen calls.")

View File

@@ -47,6 +47,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h ${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h
${CMAKE_CURRENT_SOURCE_DIR}/os_interface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h
${CMAKE_CURRENT_SOURCE_DIR}/os_library_helper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.h ${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.cpp

View File

@@ -0,0 +1,21 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/os_interface/linux/os_library_linux.h"
#include <dlfcn.h>
namespace NEO {
namespace Linux {
void adjustLibraryFlags(int &dlopenFlag) {
if (DebugManager.flags.DisableDeepBind.get()) {
dlopenFlag &= ~RTLD_DEEPBIND;
}
}
} // namespace Linux
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017-2020 Intel Corporation * Copyright (C) 2017-2021 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -8,6 +8,7 @@
#include "shared/source/os_interface/linux/os_library_linux.h" #include "shared/source/os_interface/linux/os_library_linux.h"
#include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/debug_helpers.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include <dlfcn.h> #include <dlfcn.h>
@@ -32,15 +33,16 @@ namespace Linux {
OsLibrary::OsLibrary(const std::string &name) { OsLibrary::OsLibrary(const std::string &name) {
if (name.empty()) { if (name.empty()) {
this->handle = dlopen(0, RTLD_LAZY); this->handle = SysCalls::dlopen(0, RTLD_LAZY);
} else { } else {
#ifdef SANITIZER_BUILD #ifdef SANITIZER_BUILD
constexpr auto dlopenFlag = RTLD_LAZY; auto dlopenFlag = RTLD_LAZY;
#else #else
constexpr auto dlopenFlag = RTLD_LAZY | RTLD_DEEPBIND; auto dlopenFlag = RTLD_LAZY | RTLD_DEEPBIND;
/* Background: https://github.com/intel/compute-runtime/issues/122 */ /* Background: https://github.com/intel/compute-runtime/issues/122 */
#endif #endif
this->handle = dlopen(name.c_str(), dlopenFlag); adjustLibraryFlags(dlopenFlag);
this->handle = SysCalls::dlopen(name.c_str(), dlopenFlag);
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017-2020 Intel Corporation * Copyright (C) 2017-2021 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -11,6 +11,8 @@
namespace NEO { namespace NEO {
namespace Linux { namespace Linux {
void adjustLibraryFlags(int &dlopenFlag);
class OsLibrary : public NEO::OsLibrary { class OsLibrary : public NEO::OsLibrary {
private: private:
void *handle; void *handle;

View File

@@ -13,6 +13,7 @@ namespace NEO {
namespace SysCalls { namespace SysCalls {
int close(int fileDescriptor); int close(int fileDescriptor);
int open(const char *file, int flags); int open(const char *file, int flags);
void *dlopen(const char *filename, int flag);
int ioctl(int fileDescriptor, unsigned long int request, void *arg); int ioctl(int fileDescriptor, unsigned long int request, void *arg);
int getDevicePath(int deviceFd, char *buf, size_t &bufSize); int getDevicePath(int deviceFd, char *buf, size_t &bufSize);
int access(const char *pathname, int mode); int access(const char *pathname, int mode);

View File

@@ -7,6 +7,7 @@
#include "shared/source/os_interface/linux/sys_calls.h" #include "shared/source/os_interface/linux/sys_calls.h"
#include <dlfcn.h>
#include <fcntl.h> #include <fcntl.h>
#include <iostream> #include <iostream>
#include <stdio.h> #include <stdio.h>
@@ -27,6 +28,10 @@ int ioctl(int fileDescriptor, unsigned long int request, void *arg) {
return ::ioctl(fileDescriptor, request, arg); return ::ioctl(fileDescriptor, request, arg);
} }
void *dlopen(const char *filename, int flag) {
return ::dlopen(filename, flag);
}
int access(const char *pathName, int mode) { int access(const char *pathName, int mode) {
return ::access(pathName, mode); return ::access(pathName, mode);
} }