From 240b97706fe4199df183b22979856015386441ee Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Tue, 16 Jun 2020 10:12:15 +0200 Subject: [PATCH] Fallback into legacy IOCTLs in case of incorrect topology data Change-Id: Ibf0a3885729ab6cf5888534677ff73b875d142c1 Signed-off-by: Bartosz Dunajski --- .../unit_test/os_interface/linux/drm_mock.cpp | 19 +++++++--- .../linux/hw_info_config_linux_tests.cpp | 36 +++++++++++++++++++ shared/source/os_interface/linux/drm_neo.cpp | 2 +- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/opencl/test/unit_test/os_interface/linux/drm_mock.cpp b/opencl/test/unit_test/os_interface/linux/drm_mock.cpp index 49ae39ddae..ccd04c0672 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_mock.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_mock.cpp @@ -7,6 +7,9 @@ #include "opencl/test/unit_test/os_interface/linux/drm_mock.h" +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/helpers/hw_info.h" + #include const int DrmMock::mockFd; @@ -164,9 +167,13 @@ int DrmMock::ioctl(unsigned long request, void *arg) { if (request == DRM_IOCTL_I915_QUERY && arg != nullptr) { auto queryArg = static_cast(arg); auto queryItemArg = reinterpret_cast(queryArg->items_ptr); + + auto realEuCount = rootDeviceEnvironment.getHardwareInfo()->gtSystemInfo.EUCount; + auto dataSize = std::ceil(realEuCount / 8.0); + if (queryItemArg->length == 0) { if (queryItemArg->query_id == DRM_I915_QUERY_TOPOLOGY_INFO) { - queryItemArg->length = sizeof(drm_i915_query_topology_info) + std::ceil(this->StoredEUVal / 8.0); + queryItemArg->length = sizeof(drm_i915_query_topology_info) + dataSize; return 0; } } else { @@ -176,13 +183,15 @@ int DrmMock::ioctl(unsigned long request, void *arg) { return -1; } topologyArg->max_slices = this->StoredSVal; - topologyArg->max_subslices = this->StoredSSVal / this->StoredSVal; - topologyArg->max_eus_per_subslice = this->StoredEUVal / this->StoredSSVal; + topologyArg->max_subslices = this->StoredSVal ? (this->StoredSSVal / this->StoredSVal) : 0; + topologyArg->max_eus_per_subslice = this->StoredSSVal ? (this->StoredEUVal / this->StoredSSVal) : 0; + if (this->disableSomeTopology) { - memset(topologyArg->data, 0xCA, std::ceil(this->StoredEUVal / 8.0)); + memset(topologyArg->data, 0xCA, dataSize); } else { - memset(topologyArg->data, 0xFF, std::ceil(this->StoredEUVal / 8.0)); + memset(topologyArg->data, 0xFF, dataSize); } + return 0; } } diff --git a/opencl/test/unit_test/os_interface/linux/hw_info_config_linux_tests.cpp b/opencl/test/unit_test/os_interface/linux/hw_info_config_linux_tests.cpp index bdaaa3aec2..e3332dd13b 100644 --- a/opencl/test/unit_test/os_interface/linux/hw_info_config_linux_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/hw_info_config_linux_tests.cpp @@ -258,6 +258,42 @@ TEST_F(HwInfoConfigTestLinuxDummy, whenFailGettingTopologyThenFallbackToEuCountI EXPECT_NE(-1, ret); } +TEST_F(HwInfoConfigTestLinuxDummy, givenInvalidTopologyDataWhenConfiguringThenReturnError) { + auto storedSVal = drm->StoredSVal; + auto storedSSVal = drm->StoredSSVal; + auto storedEUVal = drm->StoredEUVal; + + { + // 0 euCount + drm->StoredSVal = storedSVal; + drm->StoredSSVal = storedSSVal; + drm->StoredEUVal = 0; + + int sliceCount, subSliceCount, euCount; + EXPECT_FALSE(drm->queryTopology(sliceCount, subSliceCount, euCount)); + } + + { + // 0 subSliceCount + drm->StoredSVal = storedSVal; + drm->StoredSSVal = 0; + drm->StoredEUVal = storedEUVal; + + int sliceCount, subSliceCount, euCount; + EXPECT_FALSE(drm->queryTopology(sliceCount, subSliceCount, euCount)); + } + + { + // 0 sliceCount + drm->StoredSVal = 0; + drm->StoredSSVal = storedSSVal; + drm->StoredEUVal = storedEUVal; + + int sliceCount, subSliceCount, euCount; + EXPECT_FALSE(drm->queryTopology(sliceCount, subSliceCount, euCount)); + } +} + TEST_F(HwInfoConfigTestLinuxDummy, dummyNegativeFailingConfigureCustom) { drm->StoredDeviceID = 10; diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index f2f035201c..921b12cd7a 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -402,7 +402,7 @@ bool Drm::queryTopology(int &sliceCount, int &subSliceCount, int &euCount) { } } - return true; + return (sliceCount && subSliceCount && euCount); } Drm::~Drm() = default;