Skip to content

Commit

Permalink
Resolved memory allocation for signed PD in userspace issue
Browse files Browse the repository at this point in the history
Signed-off-by: Chanikya Prakash Gettiboina <[email protected]>
  • Loading branch information
Chanikya Prakash Gettiboina authored and quic-ekangupt committed Jun 11, 2024
1 parent db5f681 commit b2edf2b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 61 deletions.
2 changes: 0 additions & 2 deletions inc/fastrpc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ struct fastrpc_map {
* domainsupport - Legacy field, should be 1 always.
* kmem_support - Stores whether kernel can allocate memory for signed process
* dev - file descriptor returned by open(<fastrpc_device_node>)
* pdmem - Memory to store DSP process configurations
* cphandle, msghandle, lsitenerhandle, remotectlhandle, adspperfhandle - static
* handles created for the stub files loaded by fastRPC.
* procattrs - Attributes for the DSP Process. Stores information like debug process,
Expand Down Expand Up @@ -336,7 +335,6 @@ struct handle_list {
int setmode;
uint32_t mode;
uint32_t info;
void* pdmem;
remote_handle64 cphandle;
remote_handle64 msghandle;
remote_handle64 listenerhandle;
Expand Down
3 changes: 1 addition & 2 deletions src/apps_mem_imp.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ __QAIC_IMPL(apps_mem_request_map64)(int heapid, uint32 lflags, uint32 rflags,
(rflags != ADSP_MMAP_ADD_PAGES_LLC)) ||
(((rflags == ADSP_MMAP_ADD_PAGES) ||
(rflags == ADSP_MMAP_ADD_PAGES_LLC)) &&
(!is_kernel_alloc_supported(-1, -1) ||
(unsigned_module && ualloc_support)))) {
(unsigned_module && ualloc_support))) {
VERIFYC(NULL != (buf = rpcmem_alloc_internal(heapid, lflags, len)),
AEE_ENORPCMEMORY);
fd = rpcmem_to_fd_internal(buf);
Expand Down
60 changes: 3 additions & 57 deletions src/fastrpc_apps_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -3074,10 +3074,6 @@ static void domain_deinit(int domain) {
__func__, olddev, domain, t_kill);
FASTRPC_ATRACE_END();
}
if (hlist[domain].pdmem) {
rpcmem_free_internal(hlist[domain].pdmem);
hlist[domain].pdmem = NULL;
}
hlist[domain].proc_sharedbuf_cur_addr = NULL;
if (hlist[domain].proc_sharedbuf) {
rpcmem_free_internal(hlist[domain].proc_sharedbuf);
Expand Down Expand Up @@ -3305,37 +3301,6 @@ static void get_process_testsig(apps_std_FILE *fp, uint64 *ptrlen) {
return;
}

int is_kernel_alloc_supported(int dev, int domain) {
int nErr = 0;

if (!is_domain_valid(domain))
return 0;

if (hlist && !hlist[domain].kmem_support) {
struct fastrpc_ctrl_kalloc kalloc = {0};

kalloc.kalloc_support = -ENOTTY;
nErr = ioctl_control(dev, DSPRPC_KALLOC_SUPPORT, &kalloc);
if (!nErr) {
if (kalloc.kalloc_support != 1 &&
(((int32_t)kalloc.kalloc_support != -ENOTTY) ||
((int32_t)kalloc.kalloc_support != -ENXIO) ||
((int32_t)kalloc.kalloc_support != -EINVAL))) {
nErr = AEE_ERPC;
FARF(ERROR,
"Error 0x%x: IOCTL control for kernel alloc support failed with "
"%d for domain %d errno %s",
nErr, kalloc.kalloc_support, domain, strerror(errno));
return 0;
}
hlist[domain].kmem_support = kalloc.kalloc_support;
}
}
nErr = ((hlist[domain].kmem_support == 1) ? hlist[domain].kmem_support : 0);

return nErr;
}

static int open_shell(int domain_id, apps_std_FILE *fh, int unsigned_shell) {
char *absName = NULL;
char *shell_absName = NULL;
Expand Down Expand Up @@ -3536,8 +3501,8 @@ static int remote_init(int domain) {
int pd_type = 0, errno_save = 0;
uint32_t info = domain & DOMAIN_ID_MASK;
int one_mb = 1024 * 1024, shared_buf_support = 0;
char *file = NULL, *mem = NULL;
int flags = 0, filelen = 0, memlen = 0, filefd = -1, memfd = -1;
char *file = NULL;
int flags = 0, filelen = 0, memlen = 0, filefd = -1;

FARF(RUNTIME_RPC_HIGH, "starting %s for domain %d", __func__, domain);
/*
Expand Down Expand Up @@ -3689,20 +3654,6 @@ static int remote_init(int domain) {
siglen = 0;
fsig = -1;
}
if (!is_kernel_alloc_supported(dev, domain)) {
FARF(RUNTIME_RPC_HIGH,
"Allocating DSP donated memory in userspace for domain %d",
domain);
memlen =
ALIGN_B(STD_MAX(DEFAULT_PD_INITMEM_SIZE, (int)len * 4), one_mb);
if (hlist[domain].pd_initmem_size > (uint32_t)memlen)
memlen = ALIGN_B(hlist[domain].pd_initmem_size, one_mb);
mem = rpcmem_alloc_internal(
0, RPCMEM_HEAP_DEFAULT | RPCMEM_HEAP_UNCACHED, (size_t)memlen);
VERIFYC(mem, AEE_ENORPCMEMORY);
memfd = rpcmem_to_fd_internal(mem);
VERIFYC(memfd != -1, AEE_ERPC);
}

if (!(FASTRPC_MODE_UNSIGNED_MODULE & hlist[domain].procattrs)) {
memlen = hlist[domain].pd_initmem_size;
Expand All @@ -3726,7 +3677,7 @@ static int remote_init(int domain) {
}
}
ioErr = ioctl_init(dev, flags, hlist[domain].procattrs, (byte *)file,
filelen, filefd, mem, memlen, memfd, siglen);
filelen, filefd, NULL, memlen, -1, siglen);
if (ioErr) {
nErr = ioErr;
if (errno == ECONNREFUSED) {
Expand All @@ -3745,17 +3696,12 @@ static int remote_init(int domain) {
}
hlist[domain].dev = dev;
dev = -1;
hlist[domain].pdmem = mem;
hlist[domain].disable_exit_logs = 0;
}
bail:
// errno is being set to 0 in apps_std_fclose and we need original errno to
// return proper error to user call
errno_save = errno;
if (nErr && mem) {
rpcmem_free_internal(mem);
mem = NULL;
}
if (file) {
rpcmem_free_internal(file);
file = NULL;
Expand Down

0 comments on commit b2edf2b

Please sign in to comment.