Adding support in allocating executable memory
Signed-off-by: Ben Goz <ben.goz@amd.com>
[ROCm/ROCR-Runtime commit: bd7e10b0ec]
Este cometimento está contido em:
cometido por
Oded Gabbay
ascendente
a7bdd0fdff
cometimento
46e4e856ed
@@ -420,7 +420,8 @@ typedef struct _HsaMemFlags
|
|||||||
// when setting this entry to 1. Scratch allocation may fail due to limited
|
// when setting this entry to 1. Scratch allocation may fail due to limited
|
||||||
// resources. Application code is required to work without any allocation.
|
// resources. Application code is required to work without any allocation.
|
||||||
// Allocation fails on any node without GPU function.
|
// Allocation fails on any node without GPU function.
|
||||||
unsigned int Reserved : 22;
|
unsigned int ExecAccess : 1;
|
||||||
|
unsigned int Reserved : 21;
|
||||||
} ui32;
|
} ui32;
|
||||||
HSAuint32 Value;
|
HSAuint32 Value;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,8 +26,12 @@
|
|||||||
#include "libhsakmt.h"
|
#include "libhsakmt.h"
|
||||||
#include "linux/kfd_ioctl.h"
|
#include "linux/kfd_ioctl.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include "fmm.h"
|
#include "fmm.h"
|
||||||
|
|
||||||
HSAKMT_STATUS
|
HSAKMT_STATUS
|
||||||
@@ -97,6 +101,7 @@ hsaKmtAllocMemory(
|
|||||||
CHECK_KFD_OPEN();
|
CHECK_KFD_OPEN();
|
||||||
HSAKMT_STATUS result;
|
HSAKMT_STATUS result;
|
||||||
uint32_t gpu_id;
|
uint32_t gpu_id;
|
||||||
|
int err;
|
||||||
|
|
||||||
result = validate_nodeid(PreferredNode, &gpu_id);
|
result = validate_nodeid(PreferredNode, &gpu_id);
|
||||||
if (result != HSAKMT_STATUS_SUCCESS)
|
if (result != HSAKMT_STATUS_SUCCESS)
|
||||||
@@ -108,23 +113,28 @@ hsaKmtAllocMemory(
|
|||||||
return HSAKMT_STATUS_INVALID_PARAMETER;
|
return HSAKMT_STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MemFlags.ui32.HostAccess && !MemFlags.ui32.NonPaged){
|
if (MemFlags.ui32.HostAccess && !MemFlags.ui32.NonPaged) {
|
||||||
int err = posix_memalign(MemoryAddress, page_size, SizeInBytes);
|
err = posix_memalign(MemoryAddress, page_size, SizeInBytes);
|
||||||
if (err == 0)
|
if (err != 0)
|
||||||
return HSAKMT_STATUS_SUCCESS;
|
|
||||||
else
|
|
||||||
return HSAKMT_STATUS_NO_MEMORY;
|
return HSAKMT_STATUS_NO_MEMORY;
|
||||||
|
if (MemFlags.ui32.ExecAccess) {
|
||||||
|
err = mprotect(*MemoryAddress, SizeInBytes, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||||
|
if (err != 0) {
|
||||||
|
free(*MemoryAddress);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HSAKMT_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
else if(!MemFlags.ui32.HostAccess && MemFlags.ui32.NonPaged){
|
|
||||||
*MemoryAddress = fmm_allocate_device(gpu_id, SizeInBytes);
|
|
||||||
if (*MemoryAddress)
|
|
||||||
return HSAKMT_STATUS_SUCCESS;
|
|
||||||
else
|
|
||||||
return HSAKMT_STATUS_NO_MEMORY;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return HSAKMT_STATUS_INVALID_PARAMETER;
|
|
||||||
|
|
||||||
|
if(!MemFlags.ui32.HostAccess && MemFlags.ui32.NonPaged){
|
||||||
|
*MemoryAddress = fmm_allocate_device(gpu_id, SizeInBytes);
|
||||||
|
if (*MemoryAddress == NULL)
|
||||||
|
return HSAKMT_STATUS_NO_MEMORY;
|
||||||
|
return HSAKMT_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HSAKMT_STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
HSAKMT_STATUS
|
HSAKMT_STATUS
|
||||||
|
|||||||
Criar uma nova questão referindo esta
Bloquear um utilizador