From 78c7d9e598fdf4938f4efaa4a6adec1b0834268a Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Fri, 20 Mar 2020 10:09:26 -0700 Subject: [PATCH] haven: rm: Send requests atomically to RM RM core driver can send out multiple requests in parallel to RM, e.g. 00111002302222113456111 (numbers indicate seq-id, and the recursion of a number indicates fragments). RM can only process one request at a time and would reject any messages unrelated to the request it was first receiving. Thus, add a lock to enforce requests are sent sequentially. Change-Id: I1e75dd40d7b8bf47ca4120f33c70f1ee452ba7b1 Signed-off-by: Elliot Berman --- drivers/virt/haven/hh_rm_core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/virt/haven/hh_rm_core.c b/drivers/virt/haven/hh_rm_core.c index 750506262dfe..511ba2403f80 100644 --- a/drivers/virt/haven/hh_rm_core.c +++ b/drivers/virt/haven/hh_rm_core.c @@ -54,6 +54,7 @@ static struct hh_msgq_desc *hh_rm_msgq_desc; static DEFINE_MUTEX(hh_rm_call_idr_lock); static DEFINE_IDR(hh_rm_call_idr); static struct hh_rm_connection *curr_connection; +static DEFINE_MUTEX(hh_rm_send_lock); static DEFINE_IDA(hh_rm_free_virq_ida); static struct device_node *hh_rm_intc; @@ -501,6 +502,10 @@ static int hh_rm_send_request(u32 message_id, return -E2BIG; } + if (mutex_lock_interruptible(&hh_rm_send_lock)) { + return -ERESTARTSYS; + } + /* Consider also the 'request' packet for the loop count */ for (i = 0; i <= num_fragments; i++) { if (buff_size_remaining > HH_RM_MAX_MSG_SIZE_BYTES) { @@ -511,8 +516,10 @@ static int hh_rm_send_request(u32 message_id, } send_buff = kzalloc(sizeof(*hdr) + payload_size, GFP_KERNEL); - if (!send_buff) + if (!send_buff) { + mutex_unlock(&hh_rm_send_lock); return -ENOMEM; + } hdr = send_buff; hdr->version = HH_RM_RPC_HDR_VERSION_ONE; @@ -541,10 +548,13 @@ static int hh_rm_send_request(u32 message_id, */ kfree(send_buff); - if (ret) + if (ret) { + mutex_unlock(&hh_rm_send_lock); return ret; + } } + mutex_unlock(&hh_rm_send_lock); return 0; }