Fixed crash in direct submission dtor

Crash on an attempt to read from tag address when ring is not started

Related-to: NEO-5869

Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
Milczarek, Slawomir
2021-12-05 22:32:20 +00:00
committed by Compute-Runtime-Automation
parent 68aea5bf62
commit 88121a6f24
4 changed files with 69 additions and 5 deletions

View File

@@ -760,6 +760,68 @@ struct DrmCommandStreamBlitterDirectSubmissionTest : public DrmCommandStreamDire
std::unique_ptr<OsContext> osContext;
};
struct DrmDirectSubmissionFunctionsCalled {
bool stopRingBuffer;
bool wait;
bool deallocateResources;
};
template <typename GfxFamily>
struct MockDrmDirectSubmissionToTestDtor : public DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>> {
MockDrmDirectSubmissionToTestDtor<GfxFamily>(Device &device, OsContext &osContext, DrmDirectSubmissionFunctionsCalled &functionsCalled)
: DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>>(device, osContext), functionsCalled(functionsCalled) {
}
~MockDrmDirectSubmissionToTestDtor() override {
if (ringStart) {
stopRingBuffer();
wait(static_cast<uint32_t>(this->currentTagData.tagValue));
}
deallocateResources();
}
using DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>>::ringStart;
bool stopRingBuffer() override {
functionsCalled.stopRingBuffer = true;
return true;
}
void wait(uint32_t taskCountToWait) override {
functionsCalled.wait = true;
}
void deallocateResources() override {
functionsCalled.deallocateResources = true;
}
DrmDirectSubmissionFunctionsCalled &functionsCalled;
};
HWTEST_TEMPLATED_F(DrmCommandStreamDirectSubmissionTest, givenEnabledDirectSubmissionWhenDtorIsCalledButRingIsNotStartedThenDontCallStopRingBufferNorWaitForTagValue) {
DrmDirectSubmissionFunctionsCalled functionsCalled{};
auto directSubmission = std::make_unique<MockDrmDirectSubmissionToTestDtor<FamilyType>>(*device.get(), *device->getDefaultEngine().osContext, functionsCalled);
ASSERT_NE(nullptr, directSubmission);
EXPECT_FALSE(directSubmission->ringStart);
directSubmission.reset();
EXPECT_FALSE(functionsCalled.stopRingBuffer);
EXPECT_FALSE(functionsCalled.wait);
EXPECT_TRUE(functionsCalled.deallocateResources);
}
template <typename GfxFamily>
struct MockDrmDirectSubmissionToTestRingStop : public DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>> {
MockDrmDirectSubmissionToTestRingStop<GfxFamily>(Device &device, OsContext &osContext)
: DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>>(device, osContext) {
}
using DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>>::ringStart;
};
HWTEST_TEMPLATED_F(DrmCommandStreamDirectSubmissionTest, givenEnabledDirectSubmissionWhenStopRingBufferIsCalledThenClearRingStart) {
auto directSubmission = std::make_unique<MockDrmDirectSubmissionToTestRingStop<FamilyType>>(*device.get(), *device->getDefaultEngine().osContext);
ASSERT_NE(nullptr, directSubmission);
directSubmission->stopRingBuffer();
EXPECT_FALSE(directSubmission->ringStart);
}
template <typename GfxFamily>
struct MockDrmDirectSubmission : public DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>> {
using DrmDirectSubmission<GfxFamily, RenderDispatcher<GfxFamily>>::currentTagData;

View File

@@ -61,7 +61,7 @@ class DirectSubmissionHw {
bool initialize(bool submitOnInit);
bool stopRingBuffer();
MOCKABLE_VIRTUAL bool stopRingBuffer();
bool startRingBuffer();
@@ -73,7 +73,7 @@ class DirectSubmissionHw {
static constexpr size_t prefetchSize = 8 * MemoryConstants::cacheLineSize;
static constexpr size_t prefetchNoops = prefetchSize / sizeof(uint32_t);
bool allocateResources();
void deallocateResources();
MOCKABLE_VIRTUAL void deallocateResources();
MOCKABLE_VIRTUAL bool makeResourcesResident(DirectSubmissionAllocations &allocations);
virtual bool allocateOsResources() = 0;
virtual bool submit(uint64_t gpuAddress, size_t size) = 0;

View File

@@ -34,7 +34,7 @@ class DrmDirectSubmission : public DirectSubmissionHw<GfxFamily, Dispatcher> {
uint64_t updateTagValue() override;
void getTagAddressValue(TagData &tagData) override;
void wait(uint32_t taskCountToWait);
MOCKABLE_VIRTUAL void wait(uint32_t taskCountToWait);
TagData currentTagData;
volatile uint32_t *tagAddress;

View File

@@ -50,8 +50,10 @@ DrmDirectSubmission<GfxFamily, Dispatcher>::DrmDirectSubmission(Device &device,
template <typename GfxFamily, typename Dispatcher>
inline DrmDirectSubmission<GfxFamily, Dispatcher>::~DrmDirectSubmission() {
if (this->ringStart) {
this->stopRingBuffer();
this->wait(static_cast<uint32_t>(this->currentTagData.tagValue));
}
this->deallocateResources();
}