From b7b50eb62f6c002fce0d96fe44499107f5090ff8 Mon Sep 17 00:00:00 2001 From: Zhang Zhijie Date: Fri, 2 Jun 2017 14:02:11 +0800 Subject: [PATCH] OP-TEE: fix warning when LPAE is activated on ARM When LPAE is activated, the dma_addr_t type is u64, but pointer is still 32bit on arm32 platform. 1. %pad is used to print dma_addr_t type in log. 2. The member paddr(dma_addr_t type) in struct shm is cast to unsigned long when it needs to be cast to a pointer. The cast is fine as the value of paddr in struct shm is always less than 4G. Change-Id: I1e2112796f657759dfa845258ea19558cb84c4ec Signed-off-by: Zhang Zhijie --- security/optee_linuxdriver/armtz/tee_tz_drv.c | 8 ++--- security/optee_linuxdriver/core/tee_session.c | 8 ++--- security/optee_linuxdriver/core/tee_shm.c | 30 +++++++++---------- .../optee_linuxdriver/core/tee_supp_com.c | 4 +-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/security/optee_linuxdriver/armtz/tee_tz_drv.c b/security/optee_linuxdriver/armtz/tee_tz_drv.c index 58b33f42f11b..824639489a38 100644 --- a/security/optee_linuxdriver/armtz/tee_tz_drv.c +++ b/security/optee_linuxdriver/armtz/tee_tz_drv.c @@ -914,8 +914,8 @@ static struct tee_shm *tz_alloc(struct tee *tee, size_t size, uint32_t flags) } shm->kaddr = tee_shm_pool_p2v(tee->dev, ptee->shm_pool, shm->paddr); if (!shm->kaddr) { - dev_err(tee->dev, "%s: p2v(%p)=0\n", __func__, - (void *)shm->paddr); + dev_err(tee->dev, "%s: p2v(%pad)=0\n", __func__, + &shm->paddr); tee_shm_pool_free(tee->dev, ptee->shm_pool, shm->paddr, NULL); devm_kfree(tee->dev, shm); return ERR_PTR(-EFAULT); @@ -924,8 +924,8 @@ static struct tee_shm *tz_alloc(struct tee *tee, size_t size, uint32_t flags) if (ptee->shm_cached) shm->flags |= TEE_SHM_CACHED; - dev_dbg(tee->dev, "%s: kaddr=%p, paddr=%p, shm=%p, size %x:%x\n", - __func__, shm->kaddr, (void *)shm->paddr, shm, + dev_dbg(tee->dev, "%s: kaddr=%p, paddr=%pad, shm=%p, size %x:%x\n", + __func__, shm->kaddr, &shm->paddr, shm, (unsigned int)shm->size_req, (unsigned int)shm->size_alloc); return shm; diff --git a/security/optee_linuxdriver/core/tee_session.c b/security/optee_linuxdriver/core/tee_session.c index a1b7a71539b4..e49362a9de74 100644 --- a/security/optee_linuxdriver/core/tee_session.c +++ b/security/optee_linuxdriver/core/tee_session.c @@ -589,8 +589,8 @@ static int _init_tee_cmd(struct tee_session *sess, struct tee_cmd_io *cmd_io, if (IS_ERR_OR_NULL(param->params[idx].shm)) goto out; - dev_dbg(_DEV_TEE, "< %d %p:%zd\n", idx, - (void *)param->params[idx].shm->paddr, + dev_dbg(_DEV_TEE, "< %d %pad:%zd\n", idx, + ¶m->params[idx].shm->paddr, param->params[idx].shm->size_alloc); break; @@ -638,8 +638,8 @@ static int _init_tee_cmd(struct tee_session *sess, struct tee_cmd_io *cmd_io, goto out; } - dev_dbg(_DEV_TEE, "< %d %p:%zd\n", idx, - (void *)param->params[idx].shm->paddr, + dev_dbg(_DEV_TEE, "< %d %pad:%zd\n", idx, + ¶m->params[idx].shm->paddr, param->params[idx].shm->size_req); break; diff --git a/security/optee_linuxdriver/core/tee_shm.c b/security/optee_linuxdriver/core/tee_shm.c index 5e310344e95b..6a50a8f7f676 100644 --- a/security/optee_linuxdriver/core/tee_shm.c +++ b/security/optee_linuxdriver/core/tee_shm.c @@ -99,8 +99,8 @@ struct tee_shm *tee_shm_alloc(struct tee *tee, size_t size, uint32_t flags) shm->tee = tee; - dev_dbg(_DEV(tee), "%s: shm=%p, paddr=%p,s=%d/%d app=\"%s\" pid=%d\n", - __func__, shm, (void *)shm->paddr, (int)shm->size_req, + dev_dbg(_DEV(tee), "%s: shm=%p, paddr=%pad,s=%d/%d app=\"%s\" pid=%d\n", + __func__, shm, &shm->paddr, (int)shm->size_req, (int)shm->size_alloc, current->comm, current->pid); pfn = shm->paddr >> PAGE_SHIFT; @@ -276,8 +276,8 @@ static void _tee_shm_dma_buf_release(struct dma_buf *dmabuf) INMSG(); ctx = shm->ctx; - dev_dbg(_DEV(ctx->tee), "%s: shm=%p, paddr=%p,s=%d/%d app=\"%s\" pid=%d\n", - __func__, shm, (void *)shm->paddr, (int)shm->size_req, + dev_dbg(_DEV(ctx->tee), "%s: shm=%p, paddr=%pad,s=%d/%d app=\"%s\" pid=%d\n", + __func__, shm, &shm->paddr, (int)shm->size_req, (int)shm->size_alloc, current->comm, current->pid); tee_shm_free_io(shm); @@ -311,8 +311,8 @@ static int _tee_shm_dma_buf_mmap(struct dma_buf *dmabuf, if (!ret) vma->vm_private_data = (void *)shm; - dev_dbg(_DEV(shm->ctx->tee), "%s: map the shm (p@=%p,s=%dKiB) => %x\n", - __func__, (void *)shm->paddr, (int)size / 1024, + dev_dbg(_DEV(shm->ctx->tee), "%s: map the shm (p@=%pad,s=%dKiB) => %x\n", + __func__, &shm->paddr, (int)size / 1024, (unsigned int)vma->vm_start); OUTMSG(ret); @@ -329,8 +329,8 @@ static void *_tee_shm_dma_buf_kmap(struct dma_buf *db, unsigned long pgnum) { struct tee_shm *shm = db->priv; - dev_dbg(_DEV(shm->ctx->tee), "%s: kmap the shm (p@=%p, v@=%p, s=%zdKiB)\n", - __func__, (void *)shm->paddr, (void *)shm->kaddr, + dev_dbg(_DEV(shm->ctx->tee), "%s: kmap the shm (p@=%pad, v@=%p, s=%zdKiB)\n", + __func__, &shm->paddr, (void *)shm->kaddr, shm->size_alloc / 1024); /* * A this stage, a shm allocated by the tee @@ -470,7 +470,7 @@ int tee_shm_fd_for_rpc(struct tee_context *ctx, struct tee_shm_io *shm_io) if (!list_empty(&tee->list_rpc_shm)) { list_for_each(pshm, &tee->list_rpc_shm) { shm = list_entry(pshm, struct tee_shm, entry); - if ((void *)shm->paddr == shm_io->buffer) + if ((void *)(unsigned long)shm->paddr == shm_io->buffer) goto found; } } @@ -558,8 +558,8 @@ static int tee_shm_db_get(struct tee *tee, struct tee_shm *shm, int fd, shm->flags |= TEEC_MEM_DMABUF; - dev_dbg(_DEV(tee), "fd=%d @p=%p is_tee=%d db=%p\n", fd, - (void *)shm->paddr, sdb->tee_allocated, dma_buf); + dev_dbg(_DEV(tee), "fd=%d @p=%pad is_tee=%d db=%p\n", fd, + &shm->paddr, sdb->tee_allocated, dma_buf); goto exit; buf_unmap: @@ -755,8 +755,8 @@ struct tee_shm *tee_shm_get(struct tee_context *ctx, TEEC_SharedMemory *c_shm, goto err; } - dev_dbg(_DEV(tee), "fd=%d @p=%p\n", - c_shm->d.fd, (void *)shm->paddr); + dev_dbg(_DEV(tee), "fd=%d @p=%pad\n", + c_shm->d.fd, &shm->paddr); } else if (c_shm->d.fd) { ret = tee_shm_db_get(tee, shm, c_shm->d.fd, c_shm->flags, size, offset); @@ -791,8 +791,8 @@ void tee_shm_put(struct tee_context *ctx, struct tee_shm *shm) { struct tee *tee = ctx->tee; - dev_dbg(_DEV(tee), "%s: > shm=%p flags=%08x paddr=%p\n", - __func__, (void *)shm, shm->flags, (void *)shm->paddr); + dev_dbg(_DEV(tee), "%s: > shm=%p flags=%08x paddr=%pad\n", + __func__, (void *)shm, shm->flags, &shm->paddr); BUG_ON(!shm); BUG_ON(!(shm->flags & TEE_SHM_MEMREF)); diff --git a/security/optee_linuxdriver/core/tee_supp_com.c b/security/optee_linuxdriver/core/tee_supp_com.c index b43d9350d164..490cae784cd6 100644 --- a/security/optee_linuxdriver/core/tee_supp_com.c +++ b/security/optee_linuxdriver/core/tee_supp_com.c @@ -58,7 +58,7 @@ enum teec_rpc_result tee_supp_cmd(struct tee *tee, break; alloc->size = size; - alloc->data = (void *)shmint->paddr; + alloc->data = (void *)(unsigned long)shmint->paddr; alloc->shm = shmint; res = TEEC_RPC_OK; @@ -229,7 +229,7 @@ ssize_t tee_supp_write(struct file *filp, const char __user *buffer, buffer, (unsigned int)shm->paddr); rpc->commFromUser.cmds[i].buffer = - (void *)shm->paddr; + (void *)(unsigned long)shm->paddr; } else dev_dbg(tee->dev, " gid2pa(0x%p => NULL\n)", -- 2.34.1