From 8c70fc6160de520abab8385e5e6b1056c8385d16 Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Thu, 26 May 2022 21:00:43 -0700 Subject: [PATCH] mem-buf: Define MEM_BUF_ALLOC_RELINQUISH_RESP message type When below sequence is run back-to-back, -ENOMEM is occasionally returned by MEM_BUF_IOC_REMOTE_ALLOC. ioctl(MEM_BUF_IOC_REMOTE_ALLOC, args) fd = args.fd close(fd) This occurs because the message sent from TUIVM to PVM as part of the file release callback is asynchonous. Resolve this by adding a new message type which indicates when PVM has completed the free operation. Additionally, define a separate obj_id instead of reusing the transaction id for this purpose. Change-Id: Iea458ec80cd14bd08848192371d0bb71cdc5de60 Signed-off-by: Patrick Daly --- drivers/soc/qcom/mem_buf/mem-buf-dev-gh.c | 2 + drivers/soc/qcom/mem_buf/mem-buf-gh.c | 126 +++++++++++++++------- drivers/soc/qcom/mem_buf/mem-buf-msgq.c | 64 ++++++++++- drivers/soc/qcom/mem_buf/mem-buf-msgq.h | 36 +++++-- drivers/soc/qcom/mem_buf/trace-mem-buf.h | 37 +++++++ 5 files changed, 216 insertions(+), 49 deletions(-) diff --git a/drivers/soc/qcom/mem_buf/mem-buf-dev-gh.c b/drivers/soc/qcom/mem_buf/mem-buf-dev-gh.c index a990ed5a47ab..fe369baf210b 100644 --- a/drivers/soc/qcom/mem_buf/mem-buf-dev-gh.c +++ b/drivers/soc/qcom/mem_buf/mem-buf-dev-gh.c @@ -22,6 +22,8 @@ EXPORT_TRACEPOINT_SYMBOL(receive_relinquish_msg); EXPORT_TRACEPOINT_SYMBOL(send_alloc_resp_msg); EXPORT_TRACEPOINT_SYMBOL(receive_alloc_resp_msg); EXPORT_TRACEPOINT_SYMBOL(mem_buf_alloc_info); +EXPORT_TRACEPOINT_SYMBOL(send_relinquish_resp_msg); +EXPORT_TRACEPOINT_SYMBOL(receive_relinquish_resp_msg); struct gh_acl_desc *mem_buf_vmid_perm_list_to_gh_acl(int *vmids, int *perms, unsigned int nr_acl_entries) diff --git a/drivers/soc/qcom/mem_buf/mem-buf-gh.c b/drivers/soc/qcom/mem_buf/mem-buf-gh.c index 85296e0be184..8e145e37cd89 100644 --- a/drivers/soc/qcom/mem_buf/mem-buf-gh.c +++ b/drivers/soc/qcom/mem_buf/mem-buf-gh.c @@ -64,7 +64,7 @@ struct mem_buf_rmt_msg { * memory * @dst_vmids: The VMIDs that have access to the memory * @dst_perms: The access permissions for the VMIDs that can access the memory - * @txn_id: The transaction ID that corresponds to this memory buffer + * @obj_id: Uniquely identifies this object. */ struct mem_buf_xfer_mem { size_t size; @@ -78,7 +78,7 @@ struct mem_buf_xfer_mem { u32 nr_acl_entries; int *dst_vmids; int *dst_perms; - u32 txn_id; + u32 obj_id; }; /** @@ -102,7 +102,7 @@ struct mem_buf_xfer_mem { * @filp: Pointer to the file structure for the membuf * @entry: List head for maintaing a list of memory buffers that have been * provided by remote VMs. - * @txn: The transaction associated with a memory buffer + * @obj_id: Uniquely identifies this object. */ struct mem_buf_desc { size_t size; @@ -116,8 +116,10 @@ struct mem_buf_desc { void *dst_data; struct file *filp; struct list_head entry; - void *txn; + u32 obj_id; }; +static DEFINE_IDR(mem_buf_obj_idr); +static DEFINE_MUTEX(mem_buf_idr_mutex); struct mem_buf_xfer_dmaheap_mem { char name[MEM_BUF_MAX_DMAHEAP_NAME_LEN]; @@ -125,6 +127,28 @@ struct mem_buf_xfer_dmaheap_mem { struct dma_buf_attachment *attachment; }; +static int mem_buf_alloc_obj_id(void) +{ + int ret; + + mutex_lock(&mem_buf_idr_mutex); + ret = idr_alloc_cyclic(&mem_buf_obj_idr, NULL, 0, INT_MAX, GFP_KERNEL); + mutex_unlock(&mem_buf_idr_mutex); + if (ret < 0) { + pr_err("%s: failed to allocate obj id rc: %d\n", + __func__, ret); + return ret; + } + return ret; +} + +static void mem_buf_destroy_obj_id(u32 obj_id) +{ + mutex_lock(&mem_buf_idr_mutex); + idr_remove(&mem_buf_obj_idr, obj_id); + mutex_unlock(&mem_buf_idr_mutex); +} + /* Functions invoked when treating allocation requests from other VMs. */ static int mem_buf_rmt_alloc_dmaheap_mem(struct mem_buf_xfer_mem *xfer_mem) { @@ -272,7 +296,13 @@ struct mem_buf_xfer_mem *mem_buf_prep_xfer_mem(void *req_msg) if (!xfer_mem) return ERR_PTR(-ENOMEM); - xfer_mem->txn_id = get_alloc_req_txn_id(req_msg); + ret = mem_buf_alloc_obj_id(); + if (ret < 0) { + pr_err("%s failed to allocate obj_id: %d\n", __func__, ret); + goto err_idr_alloc; + } + xfer_mem->obj_id = ret; + xfer_mem->size = get_alloc_req_size(req_msg); xfer_mem->mem_type = mem_type; xfer_mem->nr_acl_entries = nr_acl_entries; @@ -282,21 +312,27 @@ struct mem_buf_xfer_mem *mem_buf_prep_xfer_mem(void *req_msg) if (ret) { pr_err("%s failed to create VMID and permissions list: %d\n", __func__, ret); - kfree(xfer_mem); - return ERR_PTR(ret); + goto err_alloc_vmid_perm_list; } mem_type_data = mem_buf_alloc_xfer_mem_type_data(mem_type, arb_payload); if (IS_ERR(mem_type_data)) { pr_err("%s: failed to allocate mem type specific data: %d\n", __func__, PTR_ERR(mem_type_data)); - kfree(xfer_mem->dst_vmids); - kfree(xfer_mem->dst_perms); - kfree(xfer_mem); - return ERR_CAST(mem_type_data); + ret = PTR_ERR(mem_type_data); + goto err_alloc_xfer_mem_type_data; } xfer_mem->mem_type_data = mem_type_data; INIT_LIST_HEAD(&xfer_mem->entry); return xfer_mem; + +err_alloc_xfer_mem_type_data: + kfree(xfer_mem->dst_vmids); + kfree(xfer_mem->dst_perms); +err_alloc_vmid_perm_list: + mem_buf_destroy_obj_id(xfer_mem->obj_id); +err_idr_alloc: + kfree(xfer_mem); + return ERR_PTR(ret); } static void mem_buf_free_xfer_mem(struct mem_buf_xfer_mem *xfer_mem) @@ -305,6 +341,7 @@ static void mem_buf_free_xfer_mem(struct mem_buf_xfer_mem *xfer_mem) xfer_mem->mem_type_data); kfree(xfer_mem->dst_vmids); kfree(xfer_mem->dst_perms); + mem_buf_destroy_obj_id(xfer_mem->obj_id); kfree(xfer_mem); } @@ -430,6 +467,7 @@ static void mem_buf_alloc_req_work(struct work_struct *work) void *resp_msg; struct mem_buf_xfer_mem *xfer_mem; gh_memparcel_handle_t hdl = 0; + u32 obj_id = 0; int ret; trace_receive_alloc_req(req_msg); @@ -442,9 +480,10 @@ static void mem_buf_alloc_req_work(struct work_struct *work) } else { ret = 0; hdl = xfer_mem->hdl; + obj_id = xfer_mem->obj_id; } - resp_msg = mem_buf_construct_alloc_resp(req_msg, ret, hdl); + resp_msg = mem_buf_construct_alloc_resp(req_msg, ret, hdl, obj_id); kfree(rmt_msg->msg); kfree(rmt_msg); @@ -480,13 +519,14 @@ static void mem_buf_relinquish_work(struct work_struct *work) struct mem_buf_xfer_mem *xfer_mem_iter, *tmp, *xfer_mem = NULL; struct mem_buf_rmt_msg *rmt_msg = to_rmt_msg(work); struct mem_buf_alloc_relinquish *relinquish_msg = rmt_msg->msg; - u32 relinquish_txn_id = get_relinquish_req_txn_id(relinquish_msg); + u32 obj_id = get_relinquish_req_obj_id(relinquish_msg); + void *resp_msg; trace_receive_relinquish_msg(relinquish_msg); mutex_lock(&mem_buf_xfer_mem_list_lock); list_for_each_entry_safe(xfer_mem_iter, tmp, &mem_buf_xfer_mem_list, entry) - if (xfer_mem_iter->txn_id == relinquish_txn_id) { + if (xfer_mem_iter->obj_id == obj_id) { xfer_mem = xfer_mem_iter; list_del(&xfer_mem->entry); break; @@ -496,8 +536,15 @@ static void mem_buf_relinquish_work(struct work_struct *work) if (xfer_mem) mem_buf_cleanup_alloc_req(xfer_mem, relinquish_msg->hdl); else - pr_err("%s: transferred memory with txn_id 0x%x not found\n", - __func__, relinquish_txn_id); + pr_err("%s: transferred memory with obj_id 0x%x not found\n", + __func__, obj_id); + + resp_msg = mem_buf_construct_relinquish_resp(relinquish_msg); + if (!IS_ERR(resp_msg)) { + trace_send_relinquish_resp_msg(resp_msg); + mem_buf_msgq_send(mem_buf_msgq_hdl, resp_msg); + kfree(resp_msg); + } kfree(rmt_msg->msg); kfree(rmt_msg); @@ -519,6 +566,7 @@ static int mem_buf_alloc_resp_hdlr(void *hdlr_data, void *msg_buf, size_t size, pr_err("%s remote allocation failed rc: %d\n", __func__, ret); } else { membuf->memparcel_hdl = get_alloc_resp_hdl(alloc_resp); + membuf->obj_id = get_alloc_resp_obj_id(alloc_resp); } return ret; @@ -577,10 +625,15 @@ static void mem_buf_relinquish_hdlr(void *hdlr_data, void *_buf, size_t size) static int mem_buf_request_mem(struct mem_buf_desc *membuf) { + struct mem_buf_txn *txn; void *alloc_req_msg; int ret; - alloc_req_msg = mem_buf_construct_alloc_req(membuf->txn, membuf->size, membuf->acl_desc, + txn = mem_buf_init_txn(mem_buf_msgq_hdl, membuf); + if (IS_ERR(txn)) + return PTR_ERR(txn); + + alloc_req_msg = mem_buf_construct_alloc_req(txn, membuf->size, membuf->acl_desc, membuf->src_mem_type, membuf->src_data, membuf->trans_type); if (IS_ERR(alloc_req_msg)) { @@ -599,23 +652,28 @@ static int mem_buf_request_mem(struct mem_buf_desc *membuf) if (ret < 0) goto out; - ret = mem_buf_txn_wait(membuf->txn); + ret = mem_buf_txn_wait(txn); if (ret < 0) goto out; out: + mem_buf_destroy_txn(mem_buf_msgq_hdl, txn); return ret; } -static void __mem_buf_relinquish_mem(u32 txn_id, u32 memparcel_hdl) +static void __mem_buf_relinquish_mem(u32 obj_id, u32 memparcel_hdl) { - void *relinquish_msg; + void *relinquish_msg, *txn; int ret; - relinquish_msg = mem_buf_construct_relinquish_msg(txn_id, memparcel_hdl); - if (IS_ERR(relinquish_msg)) + txn = mem_buf_init_txn(mem_buf_msgq_hdl, NULL); + if (IS_ERR(txn)) return; + relinquish_msg = mem_buf_construct_relinquish_msg(txn, obj_id, memparcel_hdl); + if (IS_ERR(relinquish_msg)) + goto err_construct_relinquish_msg; + trace_send_relinquish_msg(relinquish_msg); ret = mem_buf_msgq_send(mem_buf_msgq_hdl, relinquish_msg); @@ -630,6 +688,12 @@ static void __mem_buf_relinquish_mem(u32 txn_id, u32 memparcel_hdl) __func__, ret); else pr_debug("%s: allocation relinquish message sent\n", __func__); + + /* Wait for response */ + mem_buf_txn_wait(txn); + +err_construct_relinquish_msg: + mem_buf_destroy_txn(mem_buf_msgq_hdl, txn); } /* @@ -642,7 +706,6 @@ static void mem_buf_relinquish_mem(struct mem_buf_desc *membuf) int perms[] = {PERM_READ | PERM_WRITE | PERM_EXEC}; struct sg_table *sgt; struct mem_buf_lend_kernel_arg arg; - u32 txn_id = mem_buf_retrieve_txn_id(membuf->txn); if (membuf->memparcel_hdl != MEM_BUF_MEMPARCEL_INVALID) { if (membuf->trans_type != GH_RM_TRANS_TYPE_DONATE) { @@ -651,7 +714,7 @@ static void mem_buf_relinquish_mem(struct mem_buf_desc *membuf) return; } - return __mem_buf_relinquish_mem(txn_id, membuf->memparcel_hdl); + return __mem_buf_relinquish_mem(membuf->obj_id, membuf->memparcel_hdl); } sgt = dup_gh_sgl_desc_to_sgt(membuf->sgl_desc); @@ -669,15 +732,15 @@ static void mem_buf_relinquish_mem(struct mem_buf_desc *membuf) goto err_free_sgt; membuf->memparcel_hdl = arg.memparcel_hdl; - __mem_buf_relinquish_mem(txn_id, membuf->memparcel_hdl); + __mem_buf_relinquish_mem(membuf->obj_id, membuf->memparcel_hdl); err_free_sgt: sg_free_table(sgt); kfree(sgt); } -static void mem_buf_relinquish_memparcel_hdl(void *hdlr_data, u32 txn_id, gh_memparcel_handle_t hdl) +static void mem_buf_relinquish_memparcel_hdl(void *hdlr_data, u32 obj_id, gh_memparcel_handle_t hdl) { - __mem_buf_relinquish_mem(txn_id, hdl); + __mem_buf_relinquish_mem(obj_id, hdl); } static int get_mem_buf(void *membuf_desc); @@ -863,7 +926,6 @@ static int mem_buf_buffer_release(struct inode *inode, struct file *filp) mem_buf_relinquish_mem(membuf); out_free_mem: - mem_buf_destroy_txn(mem_buf_msgq_hdl, membuf->txn); mem_buf_free_mem_type_data(membuf->dst_mem_type, membuf->dst_data); mem_buf_free_mem_type_data(membuf->src_mem_type, membuf->src_data); kvfree(membuf->sgl_desc); @@ -941,12 +1003,6 @@ static void *mem_buf_alloc(struct mem_buf_allocation_data *alloc_data) goto err_alloc_dst_data; } - membuf->txn = mem_buf_init_txn(mem_buf_msgq_hdl, membuf); - if (IS_ERR(membuf->txn)) { - ret = PTR_ERR(membuf->txn); - goto err_init_txn; - } - trace_mem_buf_alloc_info(membuf->size, membuf->src_mem_type, membuf->dst_mem_type, membuf->acl_desc); ret = mem_buf_request_mem(membuf); @@ -992,8 +1048,6 @@ static void *mem_buf_alloc(struct mem_buf_allocation_data *alloc_data) err_map_mem_s2: mem_buf_relinquish_mem(membuf); err_mem_req: - mem_buf_destroy_txn(mem_buf_msgq_hdl, membuf->txn); -err_init_txn: mem_buf_free_mem_type_data(membuf->dst_mem_type, membuf->dst_data); err_alloc_dst_data: mem_buf_free_mem_type_data(membuf->src_mem_type, membuf->src_data); diff --git a/drivers/soc/qcom/mem_buf/mem-buf-msgq.c b/drivers/soc/qcom/mem_buf/mem-buf-msgq.c index 8130ca1592b1..90bbbb3c9474 100644 --- a/drivers/soc/qcom/mem_buf/mem-buf-msgq.c +++ b/drivers/soc/qcom/mem_buf/mem-buf-msgq.c @@ -140,7 +140,8 @@ EXPORT_SYMBOL(mem_buf_construct_alloc_req); * sharing, or lending). */ void *mem_buf_construct_alloc_resp(void *req_msg, s32 alloc_ret, - gh_memparcel_handle_t memparcel_hdl) + gh_memparcel_handle_t memparcel_hdl, + u32 obj_id) { struct mem_buf_alloc_req *req = req_msg; struct mem_buf_alloc_resp *resp_msg = kzalloc(sizeof(*resp_msg), GFP_KERNEL); @@ -153,6 +154,7 @@ void *mem_buf_construct_alloc_resp(void *req_msg, s32 alloc_ret, resp_msg->hdr.msg_size = sizeof(*resp_msg); resp_msg->ret = alloc_ret; resp_msg->hdl = memparcel_hdl; + resp_msg->obj_id = obj_id; return resp_msg; } @@ -160,12 +162,15 @@ EXPORT_SYMBOL(mem_buf_construct_alloc_resp); /* * mem_buf_construct_relinquish_msg: Construct a relinquish message. - * @txn_id: The transaction ID that corresponds to the memory that is being relinquished. + * @mem_buf_txn: The transaction object. + * @obj_id: Uniquely identifies an object. * @memparcel_hdl: The memparcel that corresponds to the memory that is being relinquished. */ -void *mem_buf_construct_relinquish_msg(u32 txn_id, gh_memparcel_handle_t memparcel_hdl) +void *mem_buf_construct_relinquish_msg(void *mem_buf_txn, u32 obj_id, + gh_memparcel_handle_t memparcel_hdl) { struct mem_buf_alloc_relinquish *relinquish_msg; + struct mem_buf_txn *txn = mem_buf_txn; relinquish_msg = kzalloc(sizeof(*relinquish_msg), GFP_KERNEL); if (!relinquish_msg) @@ -173,13 +178,35 @@ void *mem_buf_construct_relinquish_msg(u32 txn_id, gh_memparcel_handle_t memparc relinquish_msg->hdr.msg_type = MEM_BUF_ALLOC_RELINQUISH; relinquish_msg->hdr.msg_size = sizeof(*relinquish_msg); - relinquish_msg->hdr.txn_id = txn_id; + relinquish_msg->hdr.txn_id = txn->txn_id; + relinquish_msg->obj_id = obj_id; relinquish_msg->hdl = memparcel_hdl; return relinquish_msg; } EXPORT_SYMBOL(mem_buf_construct_relinquish_msg); +/* + * mem_buf_construct_relinquish_resp: Construct a relinquish resp message. + * @msg: The msg to reply to. + */ +void *mem_buf_construct_relinquish_resp(void *_msg) +{ + struct mem_buf_alloc_relinquish *msg = _msg; + struct mem_buf_alloc_relinquish *resp; + + resp = kzalloc(sizeof(*resp), GFP_KERNEL); + if (!resp) + return ERR_PTR(-ENOMEM); + + resp->hdr.msg_type = MEM_BUF_ALLOC_RELINQUISH_RESP; + resp->hdr.msg_size = sizeof(*resp); + resp->hdr.txn_id = msg->hdr.txn_id; + + return resp; +} +EXPORT_SYMBOL(mem_buf_construct_relinquish_resp); + int mem_buf_retrieve_txn_id(void *mem_buf_txn) { struct mem_buf_txn *txn = mem_buf_txn; @@ -308,7 +335,8 @@ static void mem_buf_process_alloc_resp(struct mem_buf_msgq_desc *desc, void *buf * it can be reclaimed. */ if (!alloc_resp->ret) { - desc->msgq_ops->relinquish_memparcel_hdl(desc->hdlr_data, hdr->txn_id, + desc->msgq_ops->relinquish_memparcel_hdl(desc->hdlr_data, + alloc_resp->obj_id, alloc_resp->hdl); } } else { @@ -319,6 +347,29 @@ static void mem_buf_process_alloc_resp(struct mem_buf_msgq_desc *desc, void *buf mutex_unlock(&desc->idr_mutex); } +static void mem_buf_process_relinquish_resp(struct mem_buf_msgq_desc *desc, + void *buf, size_t size) +{ + struct mem_buf_txn *txn; + struct mem_buf_alloc_relinquish *relinquish_resp_msg = buf; + + if (size != sizeof(*relinquish_resp_msg)) { + pr_err("%s response received is not of correct size\n", + __func__); + return; + } + trace_receive_relinquish_resp_msg(relinquish_resp_msg); + + mutex_lock(&desc->idr_mutex); + txn = idr_find(&desc->txn_idr, relinquish_resp_msg->hdr.txn_id); + if (!txn) + pr_err("%s no txn associated with id: %d\n", __func__, + relinquish_resp_msg->hdr.txn_id); + else + complete(&txn->txn_done); + mutex_unlock(&desc->idr_mutex); +} + static void mem_buf_process_msg(struct mem_buf_msgq_desc *desc, void *buf, size_t size) { struct mem_buf_msg_hdr *hdr = buf; @@ -340,6 +391,9 @@ static void mem_buf_process_msg(struct mem_buf_msgq_desc *desc, void *buf, size_ case MEM_BUF_ALLOC_RELINQUISH: desc->msgq_ops->relinquish_hdlr(desc->hdlr_data, buf, size); break; + case MEM_BUF_ALLOC_RELINQUISH_RESP: + mem_buf_process_relinquish_resp(desc, buf, size); + break; default: pr_err("%s: received message of unknown type: %d\n", __func__, hdr->msg_type); diff --git a/drivers/soc/qcom/mem_buf/mem-buf-msgq.h b/drivers/soc/qcom/mem_buf/mem-buf-msgq.h index f533c645c413..7615066217c3 100644 --- a/drivers/soc/qcom/mem_buf/mem-buf-msgq.h +++ b/drivers/soc/qcom/mem_buf/mem-buf-msgq.h @@ -19,11 +19,13 @@ * allocation request issued by the receiving VM * @MEM_BUF_ALLOC_RELINQUISH: The message is a notification from another VM * that the receiving VM can reclaim the memory. + * @MEM_BUF_ALLOC_RELINQUISH_RESP: Indicates completion of MEM_BUF_ALLOC_RELINQUISH. */ enum mem_buf_msg_type { MEM_BUF_ALLOC_REQ, MEM_BUF_ALLOC_RESP, MEM_BUF_ALLOC_RELINQUISH, + MEM_BUF_ALLOC_RELINQUISH_RESP, MEM_BUF_ALLOC_REQ_MAX, }; @@ -73,11 +75,13 @@ struct mem_buf_alloc_req { * receiving VM. This field is only meaningful if the allocation on the remote * VM was carried out successfully, as denoted by @ret. * (i.e. memory donation, sharing, or lending). + * @obj_id: Unique identifier for the memory object associated with handle. */ struct mem_buf_alloc_resp { struct mem_buf_msg_hdr hdr; s32 ret; u32 hdl; + u32 obj_id; } __packed; /** @@ -86,10 +90,12 @@ struct mem_buf_alloc_resp { * another VM. * @hdr: Message header * @hdl: The memparcel handle associated with the memory. + * @obj_id: Unique identifier for the memory object associated with handle. */ struct mem_buf_alloc_relinquish { struct mem_buf_msg_hdr hdr; u32 hdl; + u32 obj_id; } __packed; /* @@ -111,7 +117,7 @@ struct mem_buf_msgq_ops { void (*alloc_req_hdlr)(void *hdlr_data, void *msg, size_t size); int (*alloc_resp_hdlr)(void *hdlr_data, void *msg, size_t size, void *resp_buf); void (*relinquish_hdlr)(void *hdlr_data, void *msg, size_t size); - void (*relinquish_memparcel_hdl)(void *hdlr_data, u32 txn_id, + void (*relinquish_memparcel_hdl)(void *hdlr_data, u32 obj_id, gh_memparcel_handle_t memparcel_hdl); }; @@ -176,9 +182,14 @@ static inline u32 get_alloc_resp_hdl(struct mem_buf_alloc_resp *resp) return resp->hdl; } -static inline u32 get_relinquish_req_txn_id(struct mem_buf_alloc_relinquish *relinquish_msg) +static inline u32 get_alloc_resp_obj_id(struct mem_buf_alloc_resp *resp) { - return relinquish_msg->hdr.txn_id; + return resp->obj_id; +} + +static inline u32 get_relinquish_req_obj_id(struct mem_buf_alloc_relinquish *relinquish_msg) +{ + return relinquish_msg->obj_id; } #if IS_ENABLED(CONFIG_QCOM_MEM_BUF_MSGQ) @@ -198,8 +209,11 @@ void *mem_buf_construct_alloc_req(void *mem_buf_txn, size_t alloc_size, enum mem_buf_mem_type src_mem_type, void *src_data, u32 trans_type); void *mem_buf_construct_alloc_resp(void *req_msg, s32 alloc_ret, - gh_memparcel_handle_t memparcel_hdl); -void *mem_buf_construct_relinquish_msg(u32 txn_id, gh_memparcel_handle_t memparcel_hdl); + gh_memparcel_handle_t memparcel_hdl, + u32 obj_id); +void *mem_buf_construct_relinquish_msg(void *mem_buf_txn, u32 obj_id, + gh_memparcel_handle_t memparcel_hdl); +void *mem_buf_construct_relinquish_resp(void *_msg); #else static inline void *mem_buf_msgq_register(const char *msgq_name, struct mem_buf_msgq_hdlr_info *info) @@ -240,13 +254,19 @@ static inline void *mem_buf_construct_alloc_req(void *mem_buf_txn, size_t alloc_ } static inline void *mem_buf_construct_alloc_resp(void *req_msg, s32 alloc_ret, - gh_memparcel_handle_t memparcel_hdl) + gh_memparcel_handle_t memparcel_hdl, + u32 obj_id) { return ERR_PTR(-ENODEV); } -static inline void *mem_buf_construct_relinquish_msg(u32 txn_id, - gh_memparcel_handle_t memparcel_hdl) +static inline void *mem_buf_construct_relinquish_msg(void *mem_buf_txn, u32 obj_id, + gh_memparcel_handle_t memparcel_hdl) +{ + return ERR_PTR(-ENODEV); +} + +static inline void *mem_buf_construct_relinquish_resp(void *_msg) { return ERR_PTR(-ENODEV); } diff --git a/drivers/soc/qcom/mem_buf/trace-mem-buf.h b/drivers/soc/qcom/mem_buf/trace-mem-buf.h index 8f7d0c2f6c10..8b909a9c4895 100644 --- a/drivers/soc/qcom/mem_buf/trace-mem-buf.h +++ b/drivers/soc/qcom/mem_buf/trace-mem-buf.h @@ -55,6 +55,8 @@ static char __maybe_unused *msg_type_to_str(enum mem_buf_msg_type type) return "MEM_BUF_ALLOC_RESP"; else if (type == MEM_BUF_ALLOC_RELINQUISH) return "MEM_BUF_ALLOC_RELINQUISH"; + else if (type == MEM_BUF_ALLOC_RELINQUISH_RESP) + return "MEM_BUF_ALLOC_RELINQUISH_RESP"; return NULL; } @@ -223,6 +225,41 @@ DEFINE_EVENT(alloc_resp_class, receive_alloc_resp_msg, TP_ARGS(resp) ); +DECLARE_EVENT_CLASS(relinquish_resp_class, + + TP_PROTO(struct mem_buf_alloc_relinquish *resp), + + TP_ARGS(resp), + + TP_STRUCT__entry( + __field(u32, txn_id) + __string(msg_type, msg_type_to_str(resp->hdr.msg_type)) + ), + + TP_fast_assign( + __entry->txn_id = resp->hdr.txn_id; + __assign_str(msg_type, msg_type_to_str(resp->hdr.msg_type)); + ), + + TP_printk("txn_id: %d msg_type: %s", + __entry->txn_id, __get_str(msg_type) + ) +); + +DEFINE_EVENT(relinquish_resp_class, send_relinquish_resp_msg, + + TP_PROTO(struct mem_buf_alloc_relinquish *resp), + + TP_ARGS(resp) +); + +DEFINE_EVENT(relinquish_resp_class, receive_relinquish_resp_msg, + + TP_PROTO(struct mem_buf_alloc_relinquish *resp), + + TP_ARGS(resp) +); + TRACE_EVENT(lookup_sgl, TP_PROTO(struct gh_sgl_desc *sgl_desc, int ret,