Files
compute-runtime/shared/source/command_stream/tbx_command_stream_receiver_hw.h
Jack Myers 5f78147e16 fix: hotfix for svmcpu tbx uploads
Test program in the linked, related issue
is crashing in tbx mode. Tbx server indicated
upload of invalid memory was made before exit.

Running with debug messages showed that the
problematic upload was an svmcpu buffer when
running neo with separate cpu and gpu
buffers for shared memory management.

Using this info, the problem was narrowed down
to a missing unprotect call in page fault manager
related code, resulting in a protected(invalid)
memory region getting uploaded to tbx.

It is unclear yet why this unprotect call was not made,
since other svmcpu buffers were uploaded without issue.

This hotfix forces the unprotect call in the fault handler,
which allows the test program to run to completion. However,
there is now a failing test case.

Considering the critical nature of the associated
NEO issue and that this patch should unblock
the work depending on the fix, this hotfix should
get merged regardless of the failing test case.

In the meantime, I will continue triaging the
failing test and will implement a proper fix
once the root cause is isolated.

Related-To: NEO-13404
Signed-off-by: Jack Myers <jack.myers@intel.com>
2025-03-14 04:47:21 +01:00

119 lines
5.4 KiB
C++

/*
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/command_stream/command_stream_receiver_simulated_hw.h"
#include "shared/source/command_stream/tbx_command_stream_receiver.h"
#include "shared/source/command_stream/wait_status.h"
#include "shared/source/memory_manager/address_mapper.h"
#include "shared/source/memory_manager/page_table.h"
#include <array>
#include <set>
namespace NEO {
class AubSubCaptureManager;
class TbxStream;
class CpuPageFaultManager;
template <typename GfxFamily>
class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFamily> {
protected:
typedef CommandStreamReceiverSimulatedHw<GfxFamily> BaseClass;
using AUB = typename AUBFamilyMapper<GfxFamily>::AUB;
using BaseClass::forceSkipResourceCleanupRequired;
using BaseClass::getParametersForMemory;
using BaseClass::osContext;
using BaseClass::pollForCompletion;
uint32_t getMaskAndValueForPollForCompletion() const;
bool getpollNotEqualValueForPollForCompletion() const;
void flushSubmissionsAndDownloadAllocations(TaskCountType taskCount, bool skipAllocationsDownload);
MOCKABLE_VIRTUAL uint64_t getNonBlockingDownloadTimeoutMs() const {
return 2000; // 2s
}
bool isAllocTbxFaultable(GraphicsAllocation *gfxAlloc);
void registerAllocationWithTbxFaultMngrIfTbxFaultable(GraphicsAllocation *gfxAllocation, void *cpuAddress, size_t size);
void allowCPUMemoryAccessIfTbxFaultable(GraphicsAllocation *gfxAllocation, void *cpuAddress, size_t size);
void protectCPUMemoryAccessIfTbxFaultable(GraphicsAllocation *gfxAllocation, void *cpuAddress, size_t size);
void protectCPUMemoryFromWritesIfTbxFaultable(GraphicsAllocation *gfxAllocation, void *cpuAddress, size_t size);
public:
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::initAdditionalMMIO;
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::aubManager;
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::hardwareContextController;
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::engineInfo;
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::stream;
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::peekExecutionEnvironment;
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::writeMemory;
SubmissionStatus flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
WaitStatus waitForTaskCountWithKmdNotifyFallback(TaskCountType taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep, QueueThrottle throttle) override;
WaitStatus waitForCompletionWithTimeout(const WaitParams &params, TaskCountType taskCountToWait) override;
void downloadAllocations(bool blockingWait, TaskCountType taskCount) override;
void downloadAllocationTbx(GraphicsAllocation &gfxAllocation);
void removeDownloadAllocation(GraphicsAllocation *alloc) override;
void processEviction() override;
SubmissionStatus processResidency(ResidencyContainer &allocationsForResidency, uint32_t handleId) override;
void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) override;
bool writeMemory(GraphicsAllocation &gfxAllocation, bool isChunkCopy, uint64_t gpuVaChunkOffset, size_t chunkSize) override;
void writeMMIO(uint32_t offset, uint32_t value) override;
bool expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation) override;
AubSubCaptureStatus checkAndActivateAubSubCapture(const std::string &kernelName) override;
// Family specific version
MOCKABLE_VIRTUAL void submitBatchBufferTbx(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits, bool overrideRingHead);
void pollForCompletion(bool skipTaskCountCheck) override;
void dumpAllocation(GraphicsAllocation &gfxAllocation) override;
static CommandStreamReceiver *create(const std::string &baseName,
bool withAubDump,
ExecutionEnvironment &executionEnvironment,
uint32_t rootDeviceIndex,
const DeviceBitfield deviceBitfield);
TbxCommandStreamReceiverHw(ExecutionEnvironment &executionEnvironment,
uint32_t rootDeviceIndex,
const DeviceBitfield deviceBitfield);
~TbxCommandStreamReceiverHw() override;
void initializeEngine() override;
MOCKABLE_VIRTUAL MemoryManager *getMemoryManager() {
return CommandStreamReceiver::getMemoryManager();
}
MOCKABLE_VIRTUAL CpuPageFaultManager *getTbxPageFaultManager();
TbxStream tbxStream;
std::unique_ptr<AubSubCaptureManager> subCaptureManager;
uint32_t aubDeviceId;
bool streamInitialized = false;
std::unique_ptr<PhysicalAddressAllocator> physicalAddressAllocator;
std::unique_ptr<std::conditional<is64bit, PML4, PDPE>::type> ppgtt;
std::unique_ptr<PDPE> ggtt;
// remap CPU VA -> GGTT VA
AddressMapper gttRemap;
std::set<GraphicsAllocation *> allocationsForDownload = {};
CommandStreamReceiverType getType() const override {
return CommandStreamReceiverType::tbx;
}
bool dumpTbxNonWritable = false;
bool isEngineInitialized = false;
};
} // namespace NEO