diff --git a/drivers/char/adsprpc.c b/drivers/char/adsprpc.c index 42f3fa604a10..92b120dd2567 100644 --- a/drivers/char/adsprpc.c +++ b/drivers/char/adsprpc.c @@ -66,9 +66,6 @@ #define ADSP_MMAP_ADD_PAGES_LLC 0x3000 #define FASTRPC_DMAHANDLE_NOMAP (16) -#define FASTRPC_ENOSUCH 39 -#define VMID_SSC_Q6 5 -#define VMID_ADSP_Q6 6 #define DEBUGFS_SIZE 3072 #define UL_SIZE 25 #define PID_SIZE 10 @@ -735,9 +732,16 @@ static void fastrpc_buf_free(struct fastrpc_buf *buf, int cache) vmid = fl->apps->channel[fl->cid].vmid; if (vmid) { int srcVM[2] = {VMID_HLOS, vmid}; + int hyp_err = 0; - hyp_assign_phys(buf->phys, buf_page_size(buf->size), + hyp_err = hyp_assign_phys(buf->phys, + buf_page_size(buf->size), srcVM, 2, destVM, destVMperm, 1); + if (hyp_err) { + ADSPRPC_ERR( + "rh hyp unassign failed with %d for phys 0x%llx, size %zu\n", + hyp_err, buf->phys, buf->size); + } } trace_fastrpc_dma_free(fl->cid, buf->phys, buf->size); dma_free_attrs(fl->sctx->smmu.dev, buf->size, buf->virt, @@ -810,7 +814,7 @@ static int fastrpc_mmap_find(struct fastrpc_file *fl, int fd, struct hlist_node *n; if ((va + len) < va) - return -EOVERFLOW; + return -EFAULT; if (mflags == ADSP_MMAP_HEAP_ADDR || mflags == ADSP_MMAP_REMOTE_HEAP_ADDR) { spin_lock(&me->hlock); @@ -849,7 +853,7 @@ static int fastrpc_mmap_find(struct fastrpc_file *fl, int fd, *ppmap = match; return 0; } - return -ENOTTY; + return -ENXIO; } static int fastrpc_alloc_cma_memory(dma_addr_t *region_phys, void **vaddr, @@ -858,15 +862,17 @@ static int fastrpc_alloc_cma_memory(dma_addr_t *region_phys, void **vaddr, struct fastrpc_apps *me = &gfa; if (me->dev == NULL) { - pr_err("device adsprpc-mem is not initialized\n"); + ADSPRPC_ERR( + "failed to allocate CMA memory, device adsprpc-mem is not initialized\n"); return -ENODEV; } *vaddr = dma_alloc_attrs(me->dev, size, region_phys, GFP_KERNEL, dma_attr); if (IS_ERR_OR_NULL(*vaddr)) { - pr_err("adsprpc: %s: %s: dma_alloc_attrs failed for size 0x%zx, returned %pK\n", - current->comm, __func__, size, (*vaddr)); - return -ENOMEM; + ADSPRPC_ERR( + "dma_alloc_attrs failed for device %s size 0x%zx dma_attr %lu, returned %ld\n", + dev_name(me->dev), size, dma_attr, PTR_ERR(*vaddr)); + return -ENOBUFS; } return 0; } @@ -930,8 +936,12 @@ static void fastrpc_mmap_free(struct fastrpc_mmap *map, uint32_t flags) map->refs--; if (!map->refs) hlist_del_init(&map->hn); - if (map->refs > 0) + if (map->refs > 0) { + ADSPRPC_WARN( + "multiple references for remote heap size %zu va 0x%lx ref count is %d\n", + map->size, map->va, map->refs); return; + } } else { map->refs--; if (!map->refs) @@ -943,8 +953,8 @@ static void fastrpc_mmap_free(struct fastrpc_mmap *map, uint32_t flags) map->flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { if (me->dev == NULL) { - pr_err("adsprpc: %s: %s: failed to free remote heap allocation\n", - current->comm, __func__); + ADSPRPC_ERR( + "failed to free remote heap allocation, device is not initialized\n"); return; } trace_fastrpc_dma_free(-1, map->phys, map->size); @@ -972,10 +982,17 @@ static void fastrpc_mmap_free(struct fastrpc_mmap *map, uint32_t flags) vmid = fl->apps->channel[fl->cid].vmid; if (vmid && map->phys) { + int hyp_err = 0; int srcVM[2] = {VMID_HLOS, vmid}; - hyp_assign_phys(map->phys, buf_page_size(map->size), + hyp_err = hyp_assign_phys(map->phys, + buf_page_size(map->size), srcVM, 2, destVM, destVMperm, 1); + if (hyp_err) { + ADSPRPC_ERR( + "rh hyp unassign failed with %d for phys 0x%llx, size %zu\n", + hyp_err, map->phys, map->size); + } } trace_fastrpc_dma_unmap(fl->cid, map->phys, map->size); if (!IS_ERR_OR_NULL(map->table)) @@ -1009,16 +1026,20 @@ static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd, struct scatterlist *sgl = NULL; VERIFY(err, cid >= ADSP_DOMAIN_ID && cid < NUM_CHANNELS); - if (err) + if (err) { + err = -ECHRNG; goto bail; + } chan = &apps->channel[cid]; if (!fastrpc_mmap_find(fl, fd, va, len, mflags, 1, ppmap)) return 0; map = kzalloc(sizeof(*map), GFP_KERNEL); VERIFY(err, !IS_ERR_OR_NULL(map)); - if (err) + if (err) { + err = -ENOMEM; goto bail; + } INIT_HLIST_NODE(&map->hn); map->flags = mflags; map->refs = 1; @@ -1041,11 +1062,20 @@ static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd, map->va = (uintptr_t)region_vaddr; } else if (mflags == FASTRPC_DMAHANDLE_NOMAP) { VERIFY(err, !IS_ERR_OR_NULL(map->buf = dma_buf_get(fd))); - if (err) + if (err) { + ADSPRPC_ERR("dma_buf_get failed for fd %d ret %ld\n", + fd, PTR_ERR(map->buf)); + err = -EBADFD; goto bail; - VERIFY(err, !dma_buf_get_flags(map->buf, &flags)); - if (err) + } + err = dma_buf_get_flags(map->buf, &flags); + if (err) { + ADSPRPC_ERR( + "dma_buf_get_flags failed for fd %d ret %d\n", + fd, err); + err = -EFAULT; goto bail; + } map->secure = flags & ION_FLAG_SECURE; map->uncached = 1; map->va = 0; @@ -1053,42 +1083,70 @@ static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd, VERIFY(err, !IS_ERR_OR_NULL(map->attach = dma_buf_attach(map->buf, me->dev))); - if (err) + if (err) { + ADSPRPC_ERR( + "dma_buf_attach for fd %d failed to map buffer on SMMU device %s ret %ld\n", + fd, dev_name(me->dev), PTR_ERR(map->attach)); + err = -EFAULT; goto bail; + } map->attach->dma_map_attrs |= DMA_ATTR_SKIP_CPU_SYNC; VERIFY(err, !IS_ERR_OR_NULL(map->table = dma_buf_map_attachment(map->attach, DMA_BIDIRECTIONAL))); - if (err) + if (err) { + ADSPRPC_ERR( + "dma_buf_map_attachment for fd %d failed on device %s ret %ld\n", + fd, dev_name(me->dev), PTR_ERR(map->table)); + err = -EFAULT; goto bail; + } VERIFY(err, map->table->nents == 1); - if (err) + if (err) { + ADSPRPC_ERR( + "multiple scatter-gather entries (%u) present for NOMAP fd %d\n", + map->table->nents, fd); + err = -EFAULT; goto bail; + } map->phys = sg_dma_address(map->table->sgl); map->size = len; trace_fastrpc_dma_map(fl->cid, fd, map->phys, map->size, len, mflags, map->attach->dma_map_attrs); } else { if (map->attr && (map->attr & FASTRPC_ATTR_KEEP_MAP)) { - pr_info("adsprpc: %s: buffer mapped with persist attr 0x%x\n", - __func__, (unsigned int)map->attr); + ADSPRPC_INFO("buffer mapped with persist attr 0x%x\n", + (unsigned int)map->attr); map->refs = 2; } VERIFY(err, !IS_ERR_OR_NULL(map->buf = dma_buf_get(fd))); - if (err) + if (err) { + ADSPRPC_ERR("dma_buf_get failed for fd %d ret %ld\n", + fd, PTR_ERR(map->buf)); + err = -EBADFD; goto bail; - VERIFY(err, !dma_buf_get_flags(map->buf, &flags)); - if (err) + } + err = dma_buf_get_flags(map->buf, &flags); + if (err) { + ADSPRPC_ERR( + "dma_buf_get_flags failed for fd %d ret %d\n", + fd, err); + err = -EFAULT; goto bail; - + } map->secure = flags & ION_FLAG_SECURE; if (map->secure) { if (!fl->secsctx) err = fastrpc_session_alloc(chan, 1, &fl->secsctx); - if (err) + if (err) { + ADSPRPC_ERR( + "fastrpc_session_alloc failed for fd %d ret %d\n", + fd, err); + err = -ENOSR; goto bail; + } } if (map->secure) sess = fl->secsctx; @@ -1096,8 +1154,12 @@ static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd, sess = fl->sctx; VERIFY(err, !IS_ERR_OR_NULL(sess)); - if (err) + if (err) { + ADSPRPC_ERR( + "session is invalid for fd %d, secure flag %d\n", + fd, map->secure); goto bail; + } map->uncached = !(flags & ION_FLAG_CACHED); if (map->attr & FASTRPC_ATTR_NOVA && !sess->smmu.coherent) @@ -1105,8 +1167,14 @@ static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd, VERIFY(err, !IS_ERR_OR_NULL(map->attach = dma_buf_attach(map->buf, sess->smmu.dev))); - if (err) + if (err) { + ADSPRPC_ERR( + "dma_buf_attach for fd %d failed to map buffer on SMMU device %s ret %ld\n", + fd, dev_name(sess->smmu.dev), + PTR_ERR(map->attach)); + err = -EFAULT; goto bail; + } map->attach->dma_map_attrs |= DMA_ATTR_DELAYED_UNMAP; map->attach->dma_map_attrs |= DMA_ATTR_EXEC_MAPPING; @@ -1122,12 +1190,23 @@ static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd, VERIFY(err, !IS_ERR_OR_NULL(map->table = dma_buf_map_attachment(map->attach, DMA_BIDIRECTIONAL))); - if (err) + if (err) { + ADSPRPC_ERR( + "dma_buf_map_attachment for fd %d failed on device %s ret %ld\n", + fd, dev_name(sess->smmu.dev), + PTR_ERR(map->table)); + err = -EFAULT; goto bail; + } if (!sess->smmu.enabled) { VERIFY(err, map->table->nents == 1); - if (err) + if (err) { + ADSPRPC_ERR( + "multiple scatter-gather entries (%u) present for fd %d mapped on SMMU disabled device\n", + map->table->nents, fd); + err = -EFAULT; goto bail; + } } map->phys = sg_dma_address(map->table->sgl); @@ -1152,8 +1231,13 @@ static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd, err = hyp_assign_phys(map->phys, buf_page_size(map->size), srcVM, 1, destVM, destVMperm, 2); - if (err) + if (err) { + ADSPRPC_ERR( + "rh hyp assign failed with %d for phys 0x%llx, size %zu\n", + err, map->phys, map->size); + err = -EADDRNOTAVAIL; goto bail; + } } map->va = va; } @@ -1200,8 +1284,10 @@ static int fastrpc_buf_alloc(struct fastrpc_file *fl, size_t size, buf = NULL; VERIFY(err, NULL != (buf = kzalloc(sizeof(*buf), GFP_KERNEL))); - if (err) + if (err) { + err = -ENOMEM; goto bail; + } INIT_HLIST_NODE(&buf->hn); buf->fl = fl; buf->virt = NULL; @@ -1223,9 +1309,10 @@ static int fastrpc_buf_alloc(struct fastrpc_file *fl, size_t size, VERIFY(err, !IS_ERR_OR_NULL(buf->virt)); } if (err) { - err = ENOMEM; - pr_err("adsprpc: %s: %s: dma_alloc_attrs failed for size 0x%zx, returned %pK\n", - current->comm, __func__, size, buf->virt); + ADSPRPC_ERR( + "dma_alloc_attrs failed for size 0x%zx, returned %pK\n", + size, buf->virt); + err = -ENOBUFS; goto bail; } if (fl->sctx->smmu.cb) @@ -1242,8 +1329,13 @@ static int fastrpc_buf_alloc(struct fastrpc_file *fl, size_t size, err = hyp_assign_phys(buf->phys, buf_page_size(size), srcVM, 1, destVM, destVMperm, 2); - if (err) + if (err) { + ADSPRPC_DEBUG( + "rh hyp assign failed with %d for phys 0x%llx, size %zu\n", + err, buf->phys, size); + err = -EADDRNOTAVAIL; goto bail; + } } if (remote) { @@ -1273,8 +1365,12 @@ static int context_restore_interrupted(struct fastrpc_file *fl, spin_lock(&fl->hlock); hlist_for_each_entry_safe(ictx, n, &fl->clst.interrupted, hn) { if (ictx->pid == current->pid) { - if (invoke->sc != ictx->sc || ictx->fl != fl) - err = -1; + if (invoke->sc != ictx->sc || ictx->fl != fl) { + err = -EINVAL; + ADSPRPC_ERR( + "interrupted sc (0x%x) or fl (%pK) does not match with invoke sc (0x%x) or fl (%pK)\n", + ictx->sc, ictx->fl, invoke->sc, fl); + } else { ctx = ictx; hlist_del_init(&ctx->hn); @@ -1340,8 +1436,14 @@ static int context_build_overlap(struct smq_invoke_ctx *ctx) ctx->overs[i].end = ctx->overs[i].start + lpra[i].buf.len; if (lpra[i].buf.len) { VERIFY(err, ctx->overs[i].end > ctx->overs[i].start); - if (err) + if (err) { + err = -EFAULT; + ADSPRPC_ERR( + "Invalid address 0x%llx and size %zu\n", + (uintptr_t)lpra[i].buf.pv, + lpra[i].buf.len); goto bail; + } } ctx->overs[i].raix = i; ctx->overps[i] = &ctx->overs[i]; @@ -1380,9 +1482,9 @@ bail: #define K_COPY_FROM_USER(err, kernel, dst, src, size) \ do {\ if (!(kernel))\ - VERIFY(err, 0 == copy_from_user((dst),\ + err = copy_from_user((dst),\ (void const __user *)(src),\ - (size)));\ + (size));\ else\ memmove((dst), (src), (size));\ } while (0) @@ -1390,8 +1492,8 @@ bail: #define K_COPY_TO_USER(err, kernel, dst, src, size) \ do {\ if (!(kernel))\ - VERIFY(err, 0 == copy_to_user((void __user *)(dst),\ - (src), (size)));\ + err = copy_to_user((void __user *)(dst),\ + (src), (size));\ else\ memmove((dst), (src), (size));\ } while (0) @@ -1419,8 +1521,10 @@ static int context_alloc(struct fastrpc_file *fl, uint32_t kernel, sizeof(*ctx->overps) * (bufs); VERIFY(err, NULL != (ctx = kzalloc(sizeof(*ctx) + size, GFP_KERNEL))); - if (err) + if (err) { + err = -ENOMEM; goto bail; + } INIT_HLIST_NODE(&ctx->hn); INIT_LIST_HEAD(&ctx->asyncn); @@ -1435,28 +1539,43 @@ static int context_alloc(struct fastrpc_file *fl, uint32_t kernel, K_COPY_FROM_USER(err, kernel, (void *)ctx->lpra, invoke->pra, bufs * sizeof(*ctx->lpra)); - if (err) + if (err) { + ADSPRPC_ERR( + "copy from user failed with %d for remote arguments list\n", + err); + err = -EFAULT; goto bail; + } if (invokefd->fds) { K_COPY_FROM_USER(err, kernel, ctx->fds, invokefd->fds, bufs * sizeof(*ctx->fds)); - if (err) + if (err) { + ADSPRPC_ERR( + "copy from user failed with %d for fd list\n", + err); + err = -EFAULT; goto bail; + } } else { ctx->fds = NULL; } if (invokefd->attrs) { K_COPY_FROM_USER(err, kernel, ctx->attrs, invokefd->attrs, bufs * sizeof(*ctx->attrs)); - if (err) + if (err) { + ADSPRPC_ERR( + "copy from user failed with %d for attribute list\n", + err); + err = -EFAULT; goto bail; + } } ctx->crc = (uint32_t *)invokefd->crc; ctx->handle = invoke->handle; ctx->sc = invoke->sc; if (bufs) { - VERIFY(err, 0 == context_build_overlap(ctx)); + VERIFY(err, 0 == (err = context_build_overlap(ctx))); if (err) goto bail; } @@ -1497,7 +1616,10 @@ static int context_alloc(struct fastrpc_file *fl, uint32_t kernel, spin_unlock_irqrestore(&chan->ctxlock, irq_flags); VERIFY(err, ii < FASTRPC_CTX_MAX); if (err) { - pr_err("adsprpc: out of context memory\n"); + ADSPRPC_ERR( + "adsprpc: out of context table entries for handle 0x%x, sc 0x%x\n", + ctx->handle, ctx->sc); + err = -ENOKEY; goto bail; } trace_fastrpc_context_alloc((uint64_t)ctx, @@ -1535,8 +1657,9 @@ static void context_free(struct smq_invoke_ctx *ctx) if (i < FASTRPC_CTX_MAX && chan->ctxtable[i] == ctx) { chan->ctxtable[i] = NULL; } else { - pr_warn("adsprpc: %s: %s: encoded table ID %u is invalid (handle 0x%x, sc 0x%x)\n", - current->comm, __func__, i, ctx->handle, ctx->sc); + ADSPRPC_WARN( + "encoded table ID %u is invalid (handle 0x%x, sc 0x%x)\n", + i, ctx->handle, ctx->sc); for (i = 0; i < FASTRPC_CTX_MAX; i++) { if (chan->ctxtable[i] == ctx) { chan->ctxtable[i] = NULL; @@ -1872,8 +1995,10 @@ static int get_args(uint32_t kernel, struct smq_invoke_ctx *ctx) mstart = ctx->overps[oix]->mstart; mend = ctx->overps[oix]->mend; VERIFY(err, (mend - mstart) <= LONG_MAX); - if (err) + if (err) { + err = -EFAULT; goto bail; + } copylen += mend - mstart; } totallen = ALIGN(totallen, BALIGN) + copylen; @@ -1941,8 +2066,14 @@ static int get_args(uint32_t kernel, struct smq_invoke_ctx *ctx) offset = buf_page_start(buf) - vma->vm_start; up_read(¤t->mm->mmap_sem); VERIFY(err, offset < (uintptr_t)map->size); - if (err) + if (err) { + ADSPRPC_ERR( + "buffer address is invalid for the fd passed for %d address 0x%llx and size %zu\n", + i, (uintptr_t)lpra[i].buf.pv, + lpra[i].buf.len); + err = -EFAULT; goto bail; + } } pages[idx].addr = map->phys + offset; pages[idx].size = num << PAGE_SHIFT; @@ -1996,9 +2127,20 @@ static int get_args(uint32_t kernel, struct smq_invoke_ctx *ctx) if (i < inbufs) { K_COPY_FROM_USER(err, kernel, uint64_to_ptr(buf), lpra[i].buf.pv, len); - if (err) + if (err) { + ADSPRPC_ERR( + "copy from user failed with %d for dst 0x%llx, src %pK, size 0x%zx, arg %d\n", + err, buf, lpra[i].buf.pv, len, i+1); + err = -EFAULT; goto bail; + } } + ADSPRPC_DEBUG( + "copied non ion buffer sc 0x%x pv 0x%llx, mend 0x%llx mstart 0x%llx, len %zu size %zu\n", + sc, rpra[i].buf.pv, + ctx->overps[oix]->mend, + ctx->overps[oix]->mstart, + rpra[i].buf.len, map->size); args = args + mlen; rlen -= mlen; } @@ -2028,11 +2170,12 @@ static int get_args(uint32_t kernel, struct smq_invoke_ctx *ctx) DMA_TO_DEVICE); dma_buf_end_cpu_access(map->buf, DMA_TO_DEVICE); - pr_debug("Debug: adsprpc: %s: %s: sc 0x%x pv 0x%llx, mend 0x%llx mstart 0x%llx, len %zu size %zu\n", - current->comm, __func__, sc, - rpra[i].buf.pv, ctx->overps[oix]->mend, - ctx->overps[oix]->mstart, - rpra[i].buf.len, map->size); + ADSPRPC_DEBUG( + "sc 0x%x pv 0x%llx, mend 0x%llx mstart 0x%llx, len %zu size %zu\n", + sc, rpra[i].buf.pv, + ctx->overps[oix]->mend, + ctx->overps[oix]->mstart, + rpra[i].buf.len, map->size); } else { uintptr_t offset; uint64_t flush_len; @@ -2064,12 +2207,13 @@ static int get_args(uint32_t kernel, struct smq_invoke_ctx *ctx) dma_buf_end_cpu_access_partial( map->buf, DMA_TO_DEVICE, offset, flush_len); - pr_debug("Debug: adsprpc: %s: %s: sc 0x%x vm_start 0x%llx pv 0x%llx, offset 0x%llx, mend 0x%llx mstart 0x%llx, len %zu size %zu\n", - current->comm, __func__, sc, - vma->vm_start, rpra[i].buf.pv, offset, - ctx->overps[oix]->mend, - ctx->overps[oix]->mstart, - rpra[i].buf.len, map->size); + ADSPRPC_DEBUG( + "sc 0x%x vm_start 0x%llx pv 0x%llx, offset 0x%llx, mend 0x%llx mstart 0x%llx, len %zu size %zu\n", + sc, vma->vm_start, + rpra[i].buf.pv, offset, + ctx->overps[oix]->mend, + ctx->overps[oix]->mstart, + rpra[i].buf.len, map->size); } } } @@ -2116,8 +2260,13 @@ static int put_args(uint32_t kernel, struct smq_invoke_ctx *ctx, ctx->lpra[i].buf.pv, uint64_to_ptr(rpra[i].buf.pv), rpra[i].buf.len); - if (err) + if (err) { + ADSPRPC_ERR( + "Invalid size 0x%llx for output argument %d ret %ld\n", + rpra[i].buf.len, i+1, err); + err = -EFAULT; goto bail; + } } else { mutex_lock(&ctx->fl->map_mutex); fastrpc_mmap_free(ctx->maps[i], 0); @@ -2182,11 +2331,12 @@ static void inv_args(struct smq_invoke_ctx *ctx) DMA_TO_DEVICE); dma_buf_end_cpu_access(map->buf, DMA_FROM_DEVICE); - pr_debug("Debug: adsprpc: %s: %s: sc 0x%x pv 0x%llx, mend 0x%llx mstart 0x%llx, len %zu size %zu\n", - current->comm, __func__, sc, - rpra[over].buf.pv, ctx->overps[i]->mend, - ctx->overps[i]->mstart, - rpra[over].buf.len, map->size); + ADSPRPC_DEBUG( + "sc 0x%x pv 0x%llx, mend 0x%llx mstart 0x%llx, len %zu size %zu\n", + sc, rpra[over].buf.pv, + ctx->overps[i]->mend, + ctx->overps[i]->mstart, + rpra[over].buf.len, map->size); } else { uintptr_t offset; uint64_t inv_len; @@ -2219,12 +2369,13 @@ static void inv_args(struct smq_invoke_ctx *ctx) dma_buf_end_cpu_access_partial(map->buf, DMA_FROM_DEVICE, offset, inv_len); - pr_debug("Debug: adsprpc: %s: %s: sc 0x%x vm_start 0x%llx pv 0x%llx, offset 0x%llx, mend 0x%llx mstart 0x%llx, len %zu size %zu\n", - current->comm, __func__, sc, - vma->vm_start, rpra[over].buf.pv, - offset, ctx->overps[i]->mend, - ctx->overps[i]->mstart, - rpra[over].buf.len, map->size); + ADSPRPC_DEBUG( + "sc 0x%x vm_start 0x%llx pv 0x%llx, offset 0x%llx, mend 0x%llx mstart 0x%llx, len %zu size %zu\n", + sc, vma->vm_start, + rpra[over].buf.pv, + offset, ctx->overps[i]->mend, + ctx->overps[i]->mstart, + rpra[over].buf.len, map->size); } } } @@ -2264,7 +2415,7 @@ static int fastrpc_invoke_send(struct smq_invoke_ctx *ctx, mutex_lock(&channel_ctx->rpmsg_mutex); VERIFY(err, !IS_ERR_OR_NULL(channel_ctx->rpdev)); if (err) { - err = -ECONNRESET; + err = -ENODEV; mutex_unlock(&channel_ctx->rpmsg_mutex); goto bail; } @@ -2344,8 +2495,8 @@ static void fastrpc_wait_for_completion(struct smq_invoke_ctx *ctx, if (!ctx) { /* This failure is not expected */ err = *ptr_interrupted = EFAULT; - pr_err("Error %d: adsprpc: %s: %s: ctx is NULL, cannot wait for response\n", - err, current->comm, __func__); + ADSPRPC_ERR("ctx is NULL, cannot wait for response err %d\n", + err); return; } wakeTime = ctx->early_wake_time; @@ -2391,8 +2542,8 @@ static void fastrpc_wait_for_completion(struct smq_invoke_ctx *ctx, ctx->is_work_done = true; goto bail; } - pr_info("adsprpc: %s: %s: poll timeout for handle 0x%x, sc 0x%x\n", - __func__, current->comm, ctx->handle, ctx->sc); + ADSPRPC_INFO("poll timeout for handle 0x%x, sc 0x%x\n", + ctx->handle, ctx->sc); if (async) { spin_lock_irqsave(&ctx->fl->aqlock, flags); if (!ctx->is_work_done) @@ -2426,8 +2577,9 @@ static void fastrpc_wait_for_completion(struct smq_invoke_ctx *ctx, break; default: *ptr_interrupted = EBADR; - pr_err("Error: adsprpc: %s: unsupported response flags 0x%x for handle 0x%x, sc 0x%x\n", - current->comm, ctx->rsp_flags, ctx->handle, ctx->sc); + ADSPRPC_ERR( + "unsupported response flags 0x%x for handle 0x%x, sc 0x%x\n", + ctx->rsp_flags, ctx->handle, ctx->sc); goto bail; } /* end of switch */ } while (!ctx->is_work_done); @@ -2467,8 +2619,8 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode, VERIFY(err, cid >= ADSP_DOMAIN_ID && cid < NUM_CHANNELS && fl->sctx != NULL); if (err) { - pr_err("adsprpc: ERROR: %s: kernel session not initialized yet for %s\n", - __func__, current->comm); + ADSPRPC_ERR("kernel session not initialized yet for %s\n", + current->comm); err = -EBADR; goto bail; } @@ -2484,18 +2636,21 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode, VERIFY(err, invoke->handle != FASTRPC_STATIC_HANDLE_DSP_UTILITIES); if (err) { - pr_err("adsprpc: ERROR: %s: user application %s trying to send a kernel RPC message to channel %d, handle 0x%x\n", - __func__, current->comm, cid, invoke->handle); + err = -EINVAL; + ADSPRPC_ERR( + "user application %s trying to send a kernel RPC message to channel %d, handle 0x%x\n", + cid, invoke->handle); goto bail; } } if (!kernel) { - err = context_restore_interrupted(fl, inv, &ctx); + VERIFY(err, 0 == (err = context_restore_interrupted(fl, + inv, &ctx))); if (err) goto bail; if (fl->sctx->smmu.faults) - err = FASTRPC_ENOSUCH; + err = -EDESTADDRREQ; if (err) goto bail; if (ctx) { @@ -2506,13 +2661,13 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode, } } - VERIFY(err, 0 == context_alloc(fl, kernel, inv, &ctx)); + VERIFY(err, 0 == (err = context_alloc(fl, kernel, inv, &ctx))); if (err) goto bail; isasyncinvoke = (ctx->asyncjob.isasyncjob ? true : false); if (REMOTE_SCALARS_LENGTH(ctx->sc)) { PERF(fl->profile, GET_COUNTER(perf_counter, PERF_GETARGS), - VERIFY(err, 0 == get_args(kernel, ctx)); + VERIFY(err, 0 == (err = get_args(kernel, ctx))); PERF_END); if (err) goto bail; @@ -2523,7 +2678,8 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode, PERF_END); PERF(fl->profile, GET_COUNTER(perf_counter, PERF_LINK), - VERIFY(err, 0 == fastrpc_invoke_send(ctx, kernel, invoke->handle)); + VERIFY(err, 0 == (err = fastrpc_invoke_send(ctx, + kernel, invoke->handle))); PERF_END); if (err) @@ -2537,9 +2693,10 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode, goto bail; if (!ctx->is_work_done) { - err = EPROTO; - pr_err("Error: adsprpc: %s: %s: WorkDone state is invalid for handle 0x%x, sc 0x%x\n", - __func__, current->comm, invoke->handle, ctx->sc); + err = -ETIMEDOUT; + ADSPRPC_ERR( + "WorkDone state is invalid for handle 0x%x, sc 0x%x\n", + invoke->handle, ctx->sc); goto bail; } @@ -2552,7 +2709,7 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode, goto bail; PERF(fl->profile, GET_COUNTER(perf_counter, PERF_PUTARGS), - VERIFY(err, 0 == put_args(kernel, ctx, invoke->pra)); + VERIFY(err, 0 == (err = put_args(kernel, ctx, invoke->pra))); PERF_END); if (err) goto bail; @@ -2565,7 +2722,7 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode, else if (ctx) context_free(ctx); if (fl->ssrcount != fl->apps->channel[cid].ssrcount) - err = ECONNRESET; + err = -ECONNRESET; invoke_end: if (fl->profile && !interrupted) @@ -2605,9 +2762,9 @@ read_async_job: if (ctx) { fastrpc_wait_for_completion(ctx, &interrupted, 0, 1); if (!ctx->is_work_done) {//In valid workdone state - pr_debug("Error: adsprpc:%s:%s: Async early wake response did not reach on time for thread %d handle 0x%x, sc 0x%x\n", - __func__, current->comm, ctx->pid, - ctx->handle, ctx->sc); + ADSPRPC_DEBUG( + "Async early wake response did not reach on time for thread %d handle 0x%x, sc 0x%x\n", + ctx->pid, ctx->handle, ctx->sc); goto read_async_job; } async_res->jobid = ctx->asyncjob.jobid; @@ -2624,8 +2781,7 @@ read_async_job: if (ierr) goto bail; } else {//Retry again if ctx is NULL - pr_err("Error: adsprpc: %s: %s: Invalid async job wake up\n", - current->comm, __func__); + ADSPRPC_ERR("Invalid async job wake up\n"); goto read_async_job; } bail: @@ -2727,8 +2883,10 @@ static int fastrpc_get_spd_session(char *name, int *session, int *cid) break; } VERIFY(err, i < NUM_CHANNELS && j < NUM_SESSIONS); - if (err) + if (err) { + err = -EUSERS; goto bail; + } *cid = i; *session = j; bail: @@ -2844,8 +3002,8 @@ static int fastrpc_init_create_dynamic_process(struct fastrpc_file *fl, VERIFY(err, uproc->attrs & FASTRPC_MODE_UNSIGNED_MODULE); if (err) { err = -EINVAL; - pr_err("Error: adsprpc: %s: %s: untrusted app trying to offload to signed remote process\n", - __func__, current->comm); + ADSPRPC_ERR( + "untrusted app trying to offload to signed remote process\n"); goto bail; } } @@ -2860,8 +3018,8 @@ static int fastrpc_init_create_dynamic_process(struct fastrpc_file *fl, gid = sorted_lists_intersection(fl->gidlist.gids, fl->gidlist.gidcount, gfa.gidlist.gids, gfa.gidlist.gidcount); if (gid) { - pr_info("adsprpc: %s: %s (PID %d, GID %u) is a privileged process\n", - __func__, current->comm, fl->tgid, gid); + ADSPRPC_INFO("PID %d, GID %u is a privileged process\n", + fl->tgid, gid); uproc->attrs |= FASTRPC_MODE_PRIVILEGED; } @@ -2873,8 +3031,7 @@ static int fastrpc_init_create_dynamic_process(struct fastrpc_file *fl, VERIFY(err, !init->mem); if (err) { err = -EINVAL; - pr_err("adsprpc: %s: %s: ERROR: donated memory allocated in userspace\n", - current->comm, __func__); + ADSPRPC_ERR("donated memory allocated in userspace\n"); goto bail; } /* Free any previous donated memory */ @@ -2991,12 +3148,16 @@ static int fastrpc_init_create_static_process(struct fastrpc_file *fl, proc_name = kzalloc(init->filelen, GFP_KERNEL); VERIFY(err, !IS_ERR_OR_NULL(proc_name)); - if (err) + if (err) { + err = -ENOMEM; goto bail; + } err = copy_from_user((void *)proc_name, (void __user *)init->file, init->filelen); - if (err) + if (err) { + err = -EFAULT; goto bail; + } fl->pd = 1; inbuf.pgid = fl->tgid; @@ -3033,9 +3194,10 @@ static int fastrpc_init_create_static_process(struct fastrpc_file *fl, hlosvm, 1, rhvm->vmid, rhvm->vmperm, rhvm->vmcount); if (err) { - pr_err("adsprpc: %s: %s: rh hyp assign failed with %d for phys 0x%llx, size %zu\n", - __func__, current->comm, + ADSPRPC_ERR( + "rh hyp assign failed with %d for phys 0x%llx, size %zu\n", err, phys, size); + err = -EADDRNOTAVAIL; goto bail; } rh_hyp_done = 1; @@ -3084,9 +3246,9 @@ bail: rhvm->vmid, rhvm->vmcount, hlosvm, hlosvmperm, 1); if (hyp_err) - pr_warn("adsprpc: %s: %s: rh hyp unassign failed with %d for phys 0x%llx of size %zu\n", - __func__, current->comm, - hyp_err, phys, size); + ADSPRPC_WARN( + "rh hyp unassign failed with %d for phys 0x%llx of size %zu\n", + hyp_err, phys, size); } mutex_lock(&fl->map_mutex); fastrpc_mmap_free(mem, 0); @@ -3105,6 +3267,15 @@ static int fastrpc_init_process(struct fastrpc_file *fl, && init->memlen < INIT_MEMLEN_MAX); if (err) goto bail; + if (err) { + ADSPRPC_ERR( + "file size 0x%x or init memory 0x%x is more than max allowed file size 0x%x or init len 0x%x\n", + init->filelen, init->memlen, + INIT_FILELEN_MAX, INIT_MEMLEN_MAX); + err = -EFBIG; + goto bail; + } + err = fastrpc_channel_open(fl); if (err) goto bail; @@ -3153,8 +3324,10 @@ static int fastrpc_send_cpuinfo_to_dsp(struct fastrpc_file *fl) remote_arg_t ra[2]; VERIFY(err, fl && fl->cid >= ADSP_DOMAIN_ID && fl->cid < NUM_CHANNELS); - if (err) + if (err) { + err = -ECHRNG; goto bail; + } cpuinfo = me->channel[fl->cid].cpuinfo_todsp; /* return success if already updated to remote processor */ @@ -3236,8 +3409,8 @@ static int fastrpc_get_info_from_dsp(struct fastrpc_file *fl, bail: if (err) - pr_err("adsprpc: %s: %s: could not obtain dsp information, err val 0x%x\n", - current->comm, __func__, err); + ADSPRPC_ERR("could not obtain dsp information, err val %d\n", + err); return err; } @@ -3252,6 +3425,10 @@ static int fastrpc_get_info_from_kernel( struct fastrpc_dsp_capabilities *dsp_cap_ptr; VERIFY(err, cap->domain < NUM_CHANNELS); + if (err) { + err = -ECHRNG; + goto bail; + } /* * Check if number of attribute IDs obtained from userspace @@ -3312,9 +3489,7 @@ static int fastrpc_get_info_from_kernel( * can try to query dsp again */ dsp_cap_ptr->is_cached = 0; - pr_warn("adsprpc: %s: %s: returned bad domain support value %d\n", - current->comm, - __func__, + ADSPRPC_WARN("returned bad domain support value %d\n", domain_support); goto bail; } @@ -3337,17 +3512,25 @@ static int fastrpc_release_current_dsp_process(struct fastrpc_file *fl) int tgid = 0; VERIFY(err, fl->cid >= ADSP_DOMAIN_ID && fl->cid < NUM_CHANNELS); - if (err) + if (err) { + err = -ECHRNG; goto bail; + } VERIFY(err, fl->sctx != NULL); - if (err) + if (err) { + err = -EBADR; goto bail; + } VERIFY(err, fl->apps->channel[fl->cid].rpdev != NULL); - if (err) + if (err) { + err = -ENODEV; goto bail; + } VERIFY(err, fl->apps->channel[fl->cid].issubsystemup == 1); - if (err) + if (err) { + err = -ECONNRESET; goto bail; + } tgid = fl->tgid; ra[0].buf.pv = (void *)&tgid; ra[0].buf.len = sizeof(tgid); @@ -3361,8 +3544,9 @@ static int fastrpc_release_current_dsp_process(struct fastrpc_file *fl) VERIFY(err, 0 == (err = fastrpc_internal_invoke(fl, FASTRPC_MODE_PARALLEL, 1, &ioctl))); if (err && fl->dsp_proc_init) - pr_err("adsprpc: %s: releasing DSP process failed with %d (0x%x) for %s\n", - __func__, err, err, current->comm); + ADSPRPC_ERR( + "releasing DSP process failed with %d (0x%x) for %s\n", + err, err, current->comm); bail: return err; } @@ -3559,14 +3743,15 @@ static int fastrpc_mmap_on_dsp(struct fastrpc_file *fl, uint32_t flags, me->channel[fl->cid].rhvm.vmperm, me->channel[fl->cid].rhvm.vmcount); if (err) { - pr_err("adsprpc: %s: %s: rh hyp assign failed with %d for phys 0x%llx, size %zd\n", - __func__, current->comm, - err, phys, size); + ADSPRPC_ERR( + "rh hyp assign failed with %d for phys 0x%llx, size %zu\n", + err, phys, size); + err = -EADDRNOTAVAIL; err = fastrpc_unmap_on_dsp(fl, *raddr, phys, size, flags); if (err) { - pr_err("adsprpc: %s: %s: failed to unmap %d for phys 0x%llx, size %zd\n", - __func__, current->comm, + ADSPRPC_ERR( + "failed to unmap %d for phys 0x%llx, size %zd\n", err, phys, size); } goto bail; @@ -3622,9 +3807,10 @@ static int fastrpc_munmap_on_dsp_rh(struct fastrpc_file *fl, uint64_t phys, me->channel[fl->cid].rhvm.vmcount, destVM, destVMperm, 1); if (err) { - pr_err("adsprpc: %s: %s: rh hyp unassign failed with %d for phys 0x%llx, size %zd\n", - __func__, current->comm, + ADSPRPC_ERR( + "rh hyp unassign failed with %d for phys 0x%llx, size %zu\n", err, phys, size); + err = -EADDRNOTAVAIL; goto bail; } } @@ -3645,7 +3831,8 @@ static int fastrpc_munmap_on_dsp(struct fastrpc_file *fl, uintptr_t raddr, goto bail; if (flags == ADSP_MMAP_HEAP_ADDR || flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { - VERIFY(err, !fastrpc_munmap_on_dsp_rh(fl, phys, size, flags)); + VERIFY(err, !(err = fastrpc_munmap_on_dsp_rh(fl, phys, + size, flags))); if (err) goto bail; } @@ -3662,8 +3849,10 @@ static int fastrpc_mmap_remove_ssr(struct fastrpc_file *fl) struct ramdump_segment *ramdump_segments_rh = NULL; VERIFY(err, fl->cid == RH_CID); - if (err) + if (err) { + err = -EBADR; goto bail; + } do { match = NULL; spin_lock(&me->hlock); @@ -3714,8 +3903,10 @@ static int fastrpc_mmap_remove_pdr(struct fastrpc_file *fl) if (err) goto bail; VERIFY(err, cid == fl->cid); - if (err) + if (err) { + err = -EBADR; goto bail; + } if (!me->channel[fl->cid].spd[session].ispdup && me->channel[fl->cid].spd[session].pdrhandle) { err = -ENOTCONN; @@ -3725,8 +3916,8 @@ static int fastrpc_mmap_remove_pdr(struct fastrpc_file *fl) me->channel[fl->cid].spd[session].prevpdrcount) { err = fastrpc_mmap_remove_ssr(fl); if (err) - pr_warn("adsprpc: %s: %s: failed to unmap remote heap (err %d)\n", - __func__, current->comm, err); + ADSPRPC_WARN("failed to unmap remote heap (err %d)\n", + err); me->channel[fl->cid].spd[session].prevpdrcount = me->channel[fl->cid].spd[session].pdrcount; } @@ -3769,10 +3960,11 @@ static int fastrpc_internal_munmap(struct fastrpc_file *fl, VERIFY(err, fl->dsp_proc_init == 1); if (err) { - pr_err("adsprpc: ERROR: %s: user application %s trying to unmap without initialization\n", - __func__, current->comm); - err = EBADR; - return err; + ADSPRPC_ERR( + "user application %s trying to unmap without initialization\n", + current->comm); + err = -EHOSTDOWN; + goto bail; } mutex_lock(&fl->internal_map_mutex); @@ -3790,8 +3982,8 @@ static int fastrpc_internal_munmap(struct fastrpc_file *fl, spin_unlock(&fl->hlock); if (free) { - VERIFY(err, !fastrpc_munmap_on_dsp(fl, free->raddr, - free->phys, free->size, free->flags)); + VERIFY(err, !(err = fastrpc_munmap_on_dsp(fl, free->raddr, + free->phys, free->size, free->flags))); if (err) goto bail; fastrpc_buf_free(rbuf, 0); @@ -3800,12 +3992,13 @@ static int fastrpc_internal_munmap(struct fastrpc_file *fl, } mutex_lock(&fl->map_mutex); - VERIFY(err, !fastrpc_mmap_remove(fl, -1, ud->vaddrout, ud->size, &map)); + VERIFY(err, !(err = fastrpc_mmap_remove(fl, -1, ud->vaddrout, + ud->size, &map))); mutex_unlock(&fl->map_mutex); if (err) goto bail; - VERIFY(err, !fastrpc_munmap_on_dsp(fl, map->raddr, - map->phys, map->size, map->flags)); + VERIFY(err, !(err = fastrpc_munmap_on_dsp(fl, map->raddr, + map->phys, map->size, map->flags))); if (err) goto bail; mutex_lock(&fl->map_mutex); @@ -3828,21 +4021,25 @@ static int fastrpc_internal_munmap_fd(struct fastrpc_file *fl, struct fastrpc_mmap *map = NULL; VERIFY(err, (fl && ud)); - if (err) + if (err) { + err = -EINVAL; goto bail; + } VERIFY(err, fl->dsp_proc_init == 1); if (err) { - pr_err("adsprpc: ERROR: %s: user application %s trying to unmap without initialization\n", - __func__, current->comm); - err = EBADR; + ADSPRPC_ERR( + "user application %s trying to unmap without initialization\n", + current->comm); + err = -EHOSTDOWN; goto bail; } mutex_lock(&fl->map_mutex); - if (fastrpc_mmap_find(fl, ud->fd, ud->va, ud->len, 0, 0, &map)) { - pr_err("adsprpc: mapping not found to unmap fd 0x%x, va 0x%llx, len 0x%x\n", + err = fastrpc_mmap_find(fl, ud->fd, ud->va, ud->len, 0, 0, &map); + if (err) { + ADSPRPC_ERR( + "mapping not found to unmap fd 0x%x, va 0x%llx, len 0x%x, err %d\n", ud->fd, (unsigned long long)ud->va, - (unsigned int)ud->len); - err = -1; + (unsigned int)ud->len, err); mutex_unlock(&fl->map_mutex); goto bail; } @@ -3965,18 +4162,19 @@ static int fastrpc_internal_mmap(struct fastrpc_file *fl, VERIFY(err, fl->dsp_proc_init == 1); if (err) { - pr_err("adsprpc: ERROR: %s: user application %s trying to map without initialization\n", - __func__, current->comm); - err = EBADR; + ADSPRPC_ERR( + "user application %s trying to map without initialization\n", + current->comm); + err = -EHOSTDOWN; goto bail; } mutex_lock(&fl->internal_map_mutex); if ((ud->flags == ADSP_MMAP_ADD_PAGES) || (ud->flags == ADSP_MMAP_ADD_PAGES_LLC)) { if (ud->vaddrin) { - err = EINVAL; - pr_err("adsprpc: %s: %s: ERROR: adding user allocated pages is not supported\n", - current->comm, __func__); + err = -EINVAL; + ADSPRPC_ERR( + "adding user allocated pages is not supported\n"); goto bail; } dma_attr = DMA_ATTR_EXEC_MAPPING | @@ -3997,9 +4195,9 @@ static int fastrpc_internal_mmap(struct fastrpc_file *fl, uintptr_t va_to_dsp; mutex_lock(&fl->map_mutex); - VERIFY(err, !fastrpc_mmap_create(fl, ud->fd, 0, + VERIFY(err, !(err = fastrpc_mmap_create(fl, ud->fd, 0, (uintptr_t)ud->vaddrin, ud->size, - ud->flags, &map)); + ud->flags, &map))); mutex_unlock(&fl->map_mutex); if (err) goto bail; @@ -4009,8 +4207,8 @@ static int fastrpc_internal_mmap(struct fastrpc_file *fl, va_to_dsp = 0; else va_to_dsp = (uintptr_t)map->va; - VERIFY(err, 0 == fastrpc_mmap_on_dsp(fl, ud->flags, va_to_dsp, - map->phys, map->size, &raddr)); + VERIFY(err, 0 == (err = fastrpc_mmap_on_dsp(fl, ud->flags, + va_to_dsp, map->phys, map->size, &raddr))); if (err) goto bail; map->raddr = raddr; @@ -4048,16 +4246,17 @@ static int fastrpc_session_alloc_locked(struct fastrpc_channel_ctx *chan, } } if (idx >= chan->sesscount) { - err = EUSERS; - pr_err("adsprpc: ERROR %d: %s: max concurrent sessions limit (%d) already reached on %s\n", - err, __func__, chan->sesscount, chan->subsys); + err = -EUSERS; + ADSPRPC_ERR( + "max concurrent sessions limit (%d) already reached on %s err %d\n", + chan->sesscount, chan->subsys, err); goto bail; } chan->session[idx].smmu.faults = 0; } else { VERIFY(err, me->dev != NULL); if (err) { - err = -ECONNREFUSED; + err = -ENODEV; goto bail; } chan->session[0].dev = me->dev; @@ -4075,7 +4274,7 @@ static inline int get_cid_from_rpdev(struct rpmsg_device *rpdev) VERIFY(err, !IS_ERR_OR_NULL(rpdev)); if (err) - return -EINVAL; + return -ENODEV; if (!strcmp(rpdev->dev.parent->of_node->name, "cdsp")) cid = CDSP_DOMAIN_ID; @@ -4096,21 +4295,22 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) VERIFY(err, !IS_ERR_OR_NULL(rpdev)); if (err) - return -EINVAL; + return -ENODEV; cid = get_cid_from_rpdev(rpdev); VERIFY(err, cid >= ADSP_DOMAIN_ID && cid < NUM_CHANNELS); - if (err) + if (err) { + err = -ECHRNG; goto bail; + } mutex_lock(&gcinfo[cid].rpmsg_mutex); gcinfo[cid].rpdev = rpdev; mutex_unlock(&gcinfo[cid].rpmsg_mutex); - pr_info("adsprpc: %s: opened rpmsg channel for %s\n", - __func__, gcinfo[cid].subsys); - + ADSPRPC_INFO("opened rpmsg channel for %s\n", + gcinfo[cid].subsys); bail: if (err) - pr_err("adsprpc: rpmsg probe of %s cid %d failed\n", + ADSPRPC_ERR("rpmsg probe of %s cid %d failed\n", rpdev->dev.parent->of_node->name, cid); return err; } @@ -4122,22 +4322,26 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) struct fastrpc_apps *me = &gfa; VERIFY(err, !IS_ERR_OR_NULL(rpdev)); - if (err) + if (err) { + err = -ENODEV; return; + } cid = get_cid_from_rpdev(rpdev); VERIFY(err, cid >= ADSP_DOMAIN_ID && cid < NUM_CHANNELS); - if (err) + if (err) { + err = -ECHRNG; goto bail; + } mutex_lock(&gcinfo[cid].rpmsg_mutex); gcinfo[cid].rpdev = NULL; mutex_unlock(&gcinfo[cid].rpmsg_mutex); fastrpc_notify_drivers(me, cid); - pr_info("adsprpc: %s: closed rpmsg channel of %s\n", - __func__, gcinfo[cid].subsys); + ADSPRPC_INFO("closed rpmsg channel of %s\n", + gcinfo[cid].subsys); bail: if (err) - pr_err("adsprpc: rpmsg remove of %s cid %d failed\n", + ADSPRPC_ERR("rpmsg remove of %s cid %d failed\n", rpdev->dev.parent->of_node->name, cid); } @@ -4155,8 +4359,10 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data, cid = get_cid_from_rpdev(rpdev); VERIFY(err, (cid >= ADSP_DOMAIN_ID && cid <= NUM_CHANNELS)); - if (err) + if (err) { + err = -ECHRNG; goto bail; + } chan = &me->channel[cid]; VERIFY(err, (rsp && len >= sizeof(*rsp))); @@ -4198,10 +4404,12 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data, bail_unlock: spin_unlock_irqrestore(&chan->ctxlock, irq_flags); bail: - if (err) - pr_err("adsprpc: ERROR: %s: invalid response (data %pK, len %d) from remote subsystem (err %d)\n", - __func__, data, len, err); - + if (err) { + ADSPRPC_ERR( + "invalid response data %pK, len %d from remote subsystem err %d\n", + data, len, err); + err = -ENOKEY; + } return err; } @@ -4331,8 +4539,10 @@ static ssize_t fastrpc_debugfs_read(struct file *filp, char __user *buffer, char title[UL_SIZE] = "========================="; fileinfo = kzalloc(DEBUGFS_SIZE, GFP_KERNEL); - if (!fileinfo) + if (!fileinfo) { + ret = -ENOMEM; goto bail; + } if (fl == NULL) { len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, "\n%s %s %s\n", title, " CHANNEL INFO ", title); @@ -4541,9 +4751,9 @@ static int fastrpc_channel_open(struct fastrpc_file *fl) VERIFY(err, fl && fl->sctx && fl->cid >= 0 && fl->cid < NUM_CHANNELS); if (err) { - pr_err("adsprpc: ERROR: %s: kernel session not initialized yet for %s\n", - __func__, current->comm); - err = EBADR; + ADSPRPC_ERR("kernel session not initialized yet for %s\n", + current->comm); + err = -EBADR; return err; } cid = fl->cid; @@ -4551,7 +4761,7 @@ static int fastrpc_channel_open(struct fastrpc_file *fl) mutex_lock(&me->channel[cid].rpmsg_mutex); VERIFY(err, NULL != me->channel[cid].rpdev); if (err) { - err = -ENOTCONN; + err = -ENODEV; mutex_unlock(&me->channel[cid].rpmsg_mutex); goto bail; } @@ -4561,7 +4771,7 @@ static int fastrpc_channel_open(struct fastrpc_file *fl) if (me->channel[cid].ssrcount != me->channel[cid].prevssrcount) { if (!me->channel[cid].issubsystemup) { - err = -ENOTCONN; + err = -ECONNREFUSED; mutex_unlock(&me->channel[cid].smd_mutex); goto bail; } @@ -4573,9 +4783,9 @@ static int fastrpc_channel_open(struct fastrpc_file *fl) mutex_lock(&fl->map_mutex); err = fastrpc_mmap_remove_ssr(fl); if (err) - pr_warn("adsprpc: %s: %s: failed to unmap remote heap for %s (err %d)\n", - __func__, current->comm, - me->channel[cid].subsys, err); + ADSPRPC_WARN( + "failed to unmap remote heap for %s (err %d)\n", + me->channel[cid].subsys, err); mutex_unlock(&fl->map_mutex); me->channel[cid].prevssrcount = me->channel[cid].ssrcount; @@ -4593,9 +4803,9 @@ static inline void fastrpc_register_wakeup_source(struct device *dev, wake_source = wakeup_source_register(dev, client_name); if (IS_ERR_OR_NULL(wake_source)) { - pr_err("adsprpc: Error: %s: %s: wakeup_source_register failed for dev %s, client %s with err %ld\n", - __func__, current->comm, dev_name(dev), - client_name, PTR_ERR(wake_source)); + ADSPRPC_ERR( + "wakeup_source_register failed for dev %s, client %s with err %ld\n", + dev_name(dev), client_name, PTR_ERR(wake_source)); return; } *device_wake_source = wake_source; @@ -4616,13 +4826,16 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) VERIFY(err, ((dev_minor == MINOR_NUM_DEV) || (dev_minor == MINOR_NUM_SECURE_DEV))); if (err) { - pr_err("adsprpc: Invalid dev minor num %d\n", dev_minor); + ADSPRPC_ERR("Invalid dev minor num %d\n", + dev_minor); return err; } VERIFY(err, NULL != (fl = kzalloc(sizeof(*fl), GFP_KERNEL))); - if (err) + if (err) { + err = -ENOMEM; return err; + } context_list_ctor(&fl->clst); spin_lock_init(&fl->hlock); @@ -4699,8 +4912,8 @@ static int fastrpc_set_process_info(struct fastrpc_file *fl) fl->debugfs_file = debugfs_create_file(fl->debug_buf, 0644, debugfs_root, fl, &debugfs_fops); if (!fl->debugfs_file) - pr_warn("Error: %s: %s: failed to create debugfs file %s\n", - current->comm, __func__, fl->debug_buf); + ADSPRPC_WARN("failed to create debugfs file %s\n", + fl->debug_buf); return err; } @@ -4719,8 +4932,10 @@ static int fastrpc_get_info(struct fastrpc_file *fl, uint32_t *info) if (fl->cid == -1) { cid = *info; VERIFY(err, cid < NUM_CHANNELS); - if (err) + if (err) { + err = -ECHRNG; goto bail; + } /* Check to see if the device node is non-secure */ if (fl->dev_minor == MINOR_NUM_DEV) { /* @@ -4759,19 +4974,25 @@ static int fastrpc_internal_control(struct fastrpc_file *fl, unsigned int latency; VERIFY(err, !IS_ERR_OR_NULL(fl) && !IS_ERR_OR_NULL(fl->apps)); - if (err) + if (err) { + err = -EBADF; goto bail; + } VERIFY(err, !IS_ERR_OR_NULL(cp)); - if (err) + if (err) { + err = -EINVAL; goto bail; + } switch (cp->req) { case FASTRPC_CONTROL_LATENCY: latency = cp->lp.enable == FASTRPC_LATENCY_CTRL_ENB ? fl->apps->latency : PM_QOS_DEFAULT_VALUE; VERIFY(err, latency != 0); - if (err) + if (err) { + err = -EINVAL; goto bail; + } if (!fl->qos_request) { pm_qos_add_request(&fl->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, latency); @@ -4787,8 +5008,9 @@ static int fastrpc_internal_control(struct fastrpc_file *fl, break; case FASTRPC_CONTROL_WAKELOCK: if (fl->dev_minor != MINOR_NUM_SECURE_DEV) { - pr_err("adsprpc: %s: %s: PM voting not allowed for non-secure device node %d\n", - current->comm, __func__, fl->dev_minor); + ADSPRPC_ERR( + "PM voting not allowed for non-secure device node %d\n", + fl->dev_minor); err = -EPERM; goto bail; } @@ -4864,16 +5086,20 @@ static int fastrpc_getperf(struct fastrpc_ioctl_perf *ioctl_perf, K_COPY_FROM_USER(err, 0, ioctl_perf, param, sizeof(*ioctl_perf)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } ioctl_perf->numkeys = PERF_KEY_MAX; if (ioctl_perf->keys) { char *keys = PERF_KEYS; K_COPY_TO_USER(err, 0, (void *)ioctl_perf->keys, keys, strlen(keys)+1); - if (err) + if (err) { + err = -EFAULT; goto bail; + } } if (ioctl_perf->data) { struct fastrpc_perf *perf = NULL, *fperf = NULL; @@ -4896,8 +5122,10 @@ static int fastrpc_getperf(struct fastrpc_ioctl_perf *ioctl_perf, } } K_COPY_TO_USER(err, 0, param, ioctl_perf, sizeof(*ioctl_perf)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } bail: return err; } @@ -4909,15 +5137,19 @@ static int fastrpc_control(struct fastrpc_ioctl_control *cp, K_COPY_FROM_USER(err, 0, cp, param, sizeof(*cp)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_internal_control(fl, cp))); if (err) goto bail; if (cp->req == FASTRPC_CONTROL_KALLOC) { K_COPY_TO_USER(err, 0, param, cp, sizeof(*cp)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } } bail: return err; @@ -4932,8 +5164,10 @@ static int fastrpc_get_dsp_info( K_COPY_FROM_USER(err, 0, cap, param, sizeof(struct fastrpc_ioctl_capability)); VERIFY(err, cap->domain < NUM_CHANNELS); - if (err) + if (err) { + err = -ECHRNG; goto bail; + } err = fastrpc_get_info_from_kernel(cap, fl); if (err) @@ -4979,47 +5213,61 @@ static inline int fastrpc_mmap_device_ioctl(struct fastrpc_file *fl, case FASTRPC_IOCTL_MEM_MAP: K_COPY_FROM_USER(err, 0, &p->mem_map, param, sizeof(p->mem_map)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_internal_mem_map(fl, &p->mem_map))); if (err) goto bail; K_COPY_TO_USER(err, 0, param, &p->mem_map, sizeof(p->mem_map)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } break; case FASTRPC_IOCTL_MEM_UNMAP: K_COPY_FROM_USER(err, 0, &p->mem_unmap, param, sizeof(p->mem_unmap)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_internal_mem_unmap(fl, &p->mem_unmap))); if (err) goto bail; K_COPY_TO_USER(err, 0, param, &p->mem_unmap, sizeof(p->mem_unmap)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } break; case FASTRPC_IOCTL_MMAP: K_COPY_FROM_USER(err, 0, &p->mmap, param, sizeof(p->mmap)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_internal_mmap(fl, &p->mmap))); if (err) goto bail; K_COPY_TO_USER(err, 0, param, &p->mmap, sizeof(p->mmap)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } break; case FASTRPC_IOCTL_MUNMAP: K_COPY_FROM_USER(err, 0, &p->munmap, param, sizeof(p->munmap)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_internal_munmap(fl, &p->munmap))); if (err) @@ -5028,22 +5276,28 @@ static inline int fastrpc_mmap_device_ioctl(struct fastrpc_file *fl, case FASTRPC_IOCTL_MMAP_64: K_COPY_FROM_USER(err, 0, &p->mmap64, param, sizeof(p->mmap64)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } get_fastrpc_ioctl_mmap_64(&p->mmap64, &i.mmap); VERIFY(err, 0 == (err = fastrpc_internal_mmap(fl, &i.mmap))); if (err) goto bail; put_fastrpc_ioctl_mmap_64(&p->mmap64, &i.mmap); K_COPY_TO_USER(err, 0, param, &p->mmap64, sizeof(p->mmap64)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } break; case FASTRPC_IOCTL_MUNMAP_64: K_COPY_FROM_USER(err, 0, &p->munmap64, param, sizeof(p->munmap64)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } get_fastrpc_ioctl_munmap_64(&p->munmap64, &i.munmap); VERIFY(err, 0 == (err = fastrpc_internal_munmap(fl, &i.munmap))); @@ -5053,15 +5307,17 @@ static inline int fastrpc_mmap_device_ioctl(struct fastrpc_file *fl, case FASTRPC_IOCTL_MUNMAP_FD: K_COPY_FROM_USER(err, 0, &p->munmap_fd, param, sizeof(p->munmap_fd)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_internal_munmap_fd(fl, &p->munmap_fd))); if (err) goto bail; break; default: - err = -ENOTTY; + err = -EINVAL; pr_info("bad ioctl: %d\n", ioctl_num); break; } @@ -5090,7 +5346,7 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int ioctl_num, spin_lock(&fl->hlock); if (fl->file_close == 1) { - err = -EBADF; + err = -ESHUTDOWN; pr_warn("adsprpc: fastrpc_device_release is happening, So not sending any new requests to DSP\n"); spin_unlock(&fl->hlock); goto bail; @@ -5113,8 +5369,10 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int ioctl_num, if (!size) size = sizeof(struct fastrpc_ioctl_invoke_crc); K_COPY_FROM_USER(err, 0, &p.inv, param, size); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_internal_invoke(fl, fl->mode, 0, &p.inv))); if (err) @@ -5123,8 +5381,10 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int ioctl_num, case FASTRPC_IOCTL_INVOKE2: K_COPY_FROM_USER(err, 0, &p.inv2, param, sizeof(struct fastrpc_ioctl_invoke2)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_internal_invoke2(fl, &p.inv2))); if (err) goto bail; @@ -5140,14 +5400,18 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int ioctl_num, break; case FASTRPC_IOCTL_GETINFO: K_COPY_FROM_USER(err, 0, &info, param, sizeof(info)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_get_info(fl, &info))); if (err) goto bail; K_COPY_TO_USER(err, 0, param, &info, sizeof(info)); - if (err) + if (err) { + err = -EFAULT; goto bail; + } break; case FASTRPC_IOCTL_INIT: p.init.attrs = 0; @@ -5158,8 +5422,10 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int ioctl_num, if (!size) size = sizeof(struct fastrpc_ioctl_init_attrs); K_COPY_FROM_USER(err, 0, &p.init, param, size); - if (err) + if (err) { + err = -EFAULT; goto bail; + } VERIFY(err, 0 == (err = fastrpc_init_process(fl, &p.init))); if (err) goto bail; @@ -5183,7 +5449,7 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int ioctl_num, err = fastrpc_mmap_device_ioctl(fl, ioctl_num, &p, param); break; default: - err = -ENOTTY; + err = -EINVAL; pr_info("bad ioctl: %d\n", ioctl_num); break; } @@ -5376,8 +5642,10 @@ static int fastrpc_cb_probe(struct device *dev) break; } VERIFY(err, i < NUM_CHANNELS); - if (err) + if (err) { + err = -ECHRNG; goto bail; + } cid = i; chan = &gcinfo[i]; VERIFY(err, chan->sesscount < NUM_SESSIONS); @@ -5387,7 +5655,7 @@ static int fastrpc_cb_probe(struct device *dev) err = of_parse_phandle_with_args(dev->of_node, "iommus", "#iommu-cells", 0, &iommuspec); if (err) { - pr_err("adsprpc: %s: parsing iommu arguments failed for %s with err %d\n", + pr_err("Error: adsprpc: %s: parsing iommu arguments failed for %s with err %d\n", __func__, dev_name(dev), err); goto bail; } @@ -5462,13 +5730,14 @@ static void init_secure_vmid_list(struct device *dev, char *prop_name, for (i = 0; i < len; i++) { err = of_property_read_u32_index(dev->of_node, prop_name, i, &rhvmlist[i]); - rhvmpermlist[i] = PERM_READ | PERM_WRITE | PERM_EXEC; - pr_info("adsprpc: %s: secure VMID = %d\n", - __func__, rhvmlist[i]); if (err) { - pr_err("adsprpc: %s: failed to read VMID\n", __func__); + pr_err("Error: adsprpc: %s: failed to read VMID\n", + __func__); goto bail; } + ADSPRPC_INFO("secure VMID = %d\n", + rhvmlist[i]); + rhvmpermlist[i] = PERM_READ | PERM_WRITE | PERM_EXEC; } destvm->vmid = rhvmlist; destvm->vmperm = rhvmpermlist; @@ -5715,8 +5984,10 @@ static int __init fastrpc_device_init(void) MKDEV(MAJOR(me->dev_no), MINOR_NUM_DEV), NULL, DEVICE_NAME); VERIFY(err, !IS_ERR_OR_NULL(me->non_secure_dev)); - if (err) + if (err) { + err = -ENODEV; goto device_create_bail; + } /* Create secure device with minor number for secure device */ me->secure_dev = device_create(me->class, NULL, @@ -5751,7 +6022,7 @@ static int __init fastrpc_device_init(void) err = register_rpmsg_driver(&fastrpc_rpmsg_client); if (err) { - pr_err("adsprpc: %s: register_rpmsg_driver failed with err %d\n", + pr_err("Error: adsprpc: %s: register_rpmsg_driver failed with err %d\n", __func__, err); goto device_create_bail; } diff --git a/drivers/char/adsprpc_shared.h b/drivers/char/adsprpc_shared.h index 2eafed739d23..bf7581005a9e 100644 --- a/drivers/char/adsprpc_shared.h +++ b/drivers/char/adsprpc_shared.h @@ -133,6 +133,19 @@ do {\ } while (0) #endif +#define ADSPRPC_ERR(fmt, args...)\ + pr_err("Error: adsprpc (%d): %s: %s: " fmt, __LINE__,\ + current->comm, __func__, ##args) +#define ADSPRPC_INFO(fmt, args...)\ + pr_info("Info: adsprpc (%d): %s: %s: " fmt, __LINE__,\ + current->comm, __func__, ##args) +#define ADSPRPC_WARN(fmt, args...)\ + pr_warn("Warning: adsprpc (%d): %s: %s: " fmt, __LINE__,\ + current->comm, __func__, ##args) +#define ADSPRPC_DEBUG(fmt, args...)\ + pr_debug("Debug: adsprpc (%d): %s: %s: " fmt, __LINE__,\ + current->comm, __func__, ##args) + #define remote_arg64_t union remote_arg64 struct remote_buf64 {