From 992a1eeed6346569c4b5b146ce13b55c9d4bf0da Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Mon, 11 Mar 2024 16:42:31 -0700 Subject: [PATCH] ANDROID: virt: gunyah: Move send_lock around req and reply Gunyah resource manager has limited internal buffering to send messages to VMs and it is possible to fill the buffer and cause RM to drop replies. Prevent the "drop" scenario by serializing the entire send/receive RPC flow. Bug: 330201551 Change-Id: I65f2f6daf495eb24e1bc120a6a4d0b84c966e3cc Signed-off-by: Elliot Berman Signed-off-by: Elliot Berman --- drivers/virt/gunyah/rsc_mgr.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/virt/gunyah/rsc_mgr.c b/drivers/virt/gunyah/rsc_mgr.c index c320c9ceaf8a..768b18460a43 100644 --- a/drivers/virt/gunyah/rsc_mgr.c +++ b/drivers/virt/gunyah/rsc_mgr.c @@ -537,10 +537,6 @@ static int gunyah_rm_send_request(struct gunyah_rm *rm, u32 message_id, hdr_template.seq = cpu_to_le16(message->reply.seq); hdr_template.msg_id = cpu_to_le32(message_id); - ret = mutex_lock_interruptible(&rm->send_lock); - if (ret) - return ret; - do { *hdr = hdr_template; @@ -562,7 +558,6 @@ static int gunyah_rm_send_request(struct gunyah_rm *rm, u32 message_id, FIELD_PREP(RM_RPC_FRAGMENTS_MASK, cont_fragments); } while (buf_size_remaining); - mutex_unlock(&rm->send_lock); return ret; } @@ -610,6 +605,7 @@ int gunyah_rm_call(struct gunyah_rm *rm, u32 message_id, const void *req_buf, return ret; message.reply.seq = lower_16_bits(seq_id); + mutex_lock(&rm->send_lock); /* Send the request to the Resource Manager */ ret = gunyah_rm_send_request(rm, message_id, req_buf, req_buf_size, &message); @@ -653,6 +649,7 @@ int gunyah_rm_call(struct gunyah_rm *rm, u32 message_id, const void *req_buf, } out: + mutex_unlock(&rm->send_lock); xa_erase(&rm->call_xarray, message.reply.seq); return ret; }