From 0240f239adf6fb44b242c63cc19c8dc7488a54fd Mon Sep 17 00:00:00 2001 From: dongwonk Date: Thu, 7 Feb 2019 11:04:22 -0800 Subject: [PATCH] check if the whole object region is in 32Bit address space boundary checks the address + size of buffer object to determine whether the object is located within 32bit address space boundary. v2: changed end year to 2019 in ther license term v3: added unit test for checking of flag when size of bo is given. v4: two different unit tests are created to cover two different case separately Change-Id: Ie2df6025fc116aca679dcfe88d858ff240278c39 Signed-off-by: dongwonk --- .../os_interface/linux/drm_buffer_object.cpp | 5 +++-- .../linux/drm_buffer_object_tests.cpp | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/runtime/os_interface/linux/drm_buffer_object.cpp b/runtime/os_interface/linux/drm_buffer_object.cpp index e8e3206c67..b34db9a274 100644 --- a/runtime/os_interface/linux/drm_buffer_object.cpp +++ b/runtime/os_interface/linux/drm_buffer_object.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -114,7 +114,8 @@ void BufferObject::fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_ execObject.offset = this->isSoftpin ? this->offset64 : 0; execObject.flags = this->isSoftpin ? EXEC_OBJECT_PINNED : 0; #ifdef __x86_64__ - execObject.flags |= reinterpret_cast(this->address) & MemoryConstants::zoneHigh ? EXEC_OBJECT_SUPPORTS_48B_ADDRESS : 0; + // set EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag if whole object resides in 32BIT address space boundary + execObject.flags |= (reinterpret_cast(this->address) + this->size) & MemoryConstants::zoneHigh ? EXEC_OBJECT_SUPPORTS_48B_ADDRESS : 0; #endif execObject.rsvd1 = drmContextId; execObject.rsvd2 = 0; diff --git a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp index 6af90a2585..de1a3dae55 100644 --- a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp +++ b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,6 +29,10 @@ class TestedBufferObject : public BufferObject { execObjectPointerFilled = &execObject; } + void setSize(size_t size) { + this->size = size; + } + drm_i915_gem_exec_object2 *execObjectPointerFilled = nullptr; }; @@ -94,19 +98,25 @@ TEST_F(DrmBufferObjectTest, setTiling_ioctlFailed) { EXPECT_FALSE(ret); } -TEST_F(DrmBufferObjectTest, testExecObjectFlags) { +TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedCrosses32BitBoundaryWhenExecIsCalledThen48BitFlagIsSet) { drm_i915_gem_exec_object2 execObject; -#ifdef __x86_64__ memset(&execObject, 0, sizeof(execObject)); - bo->setAddress((void *)((uint64_t)1u << 34)); //anything above 4GB + bo->setAddress((void *)(((uint64_t)1u << 32) - 0x1000u)); + bo->setSize(0x1000); bo->fillExecObject(execObject, 1); + //base address + size > size of 32bit address space EXPECT_TRUE(execObject.flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS); -#endif +} + +TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedWithin32BitBoundaryWhenExecIsCalledThen48BitFlagIsNotSet) { + drm_i915_gem_exec_object2 execObject; memset(&execObject, 0, sizeof(execObject)); - bo->setAddress((void *)((uint64_t)1u << 31)); //anything below 4GB + bo->setAddress((void *)(((uint64_t)1u << 32) - 0x1000u)); + bo->setSize(0xFFF); bo->fillExecObject(execObject, 1); + //base address + size < size of 32bit address space EXPECT_FALSE(execObject.flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS); }