virt: haven: rm_core: Re-use alloc'd message when sending requests

No need to allocate a message queue buffer for each message queue
fragment, re-use the same one.

Change-Id: I5743a704ec08732a2e405724ba795d2d8cea90e3
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Signed-off-by: Srinivasarao Pathipati <quic_c_spathi@quicinc.com>
This commit is contained in:
Srinivasarao Pathipati 2022-10-10 15:59:12 +05:30
commit 8651cbc06a

View file

@ -507,8 +507,8 @@ static int hh_rm_send_request(u32 message_id,
unsigned long tx_flags;
u32 num_fragments = 0;
size_t payload_size;
void *send_buff;
int i, ret;
void *msg;
int i, ret = 0;
num_fragments = (req_buff_size + HH_RM_MAX_MSG_SIZE_BYTES - 1) /
HH_RM_MAX_MSG_SIZE_BYTES;
@ -525,11 +525,15 @@ static int hh_rm_send_request(u32 message_id,
return -E2BIG;
}
msg = kzalloc(HH_RM_MAX_MSG_SIZE_BYTES, GFP_KERNEL);
if (!msg)
return -ENOMEM;
if (mutex_lock_interruptible(&hh_rm_send_lock)) {
return -ERESTARTSYS;
ret = -ERESTARTSYS;
goto free_msg;
}
/* 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) {
payload_size = HH_RM_MAX_MSG_SIZE_BYTES;
@ -538,13 +542,10 @@ static int hh_rm_send_request(u32 message_id,
payload_size = buff_size_remaining;
}
send_buff = kzalloc(sizeof(*hdr) + payload_size, GFP_KERNEL);
if (!send_buff) {
mutex_unlock(&hh_rm_send_lock);
return -ENOMEM;
}
memset(msg, 0, HH_RM_MAX_MSG_SIZE_BYTES);
/* Fill header */
hdr = msg;
hdr = send_buff;
hdr->version = HH_RM_RPC_HDR_VERSION_ONE;
hdr->hdr_words = HH_RM_RPC_HDR_WORDS;
hdr->type = i == 0 ? HH_RM_RPC_TYPE_REQ : HH_RM_RPC_TYPE_CONT;
@ -552,11 +553,12 @@ static int hh_rm_send_request(u32 message_id,
hdr->seq = connection->seq;
hdr->msg_id = message_id;
memcpy(send_buff + sizeof(*hdr), req_buff_curr, payload_size);
/* Copy payload */
memcpy(msg + sizeof(*hdr), req_buff_curr, payload_size);
req_buff_curr += payload_size;
/* Force the last fragment (or the request type)
* to be sent immediately to the receiver
/* Force the last fragment to be sent immediately to
* the receiver
*/
tx_flags = (i == num_fragments) ? HH_MSGQ_TX_PUSH : 0;
@ -565,25 +567,17 @@ static int hh_rm_send_request(u32 message_id,
message_id == HH_RM_RPC_MSG_ID_CALL_VM_CONSOLE_FLUSH)
udelay(800);
ret = hh_msgq_send(hh_rm_msgq_desc, send_buff,
ret = hh_msgq_send(hh_rm_msgq_desc, msg,
sizeof(*hdr) + payload_size, tx_flags);
/*
* In the case of a success, the hypervisor would have consumed
* the buffer. While in the case of a failure, we are going to
* quit anyways. Hence, free the buffer regardless of the
* return value.
*/
kfree(send_buff);
if (ret) {
mutex_unlock(&hh_rm_send_lock);
return ret;
}
if (ret)
break;
}
mutex_unlock(&hh_rm_send_lock);
return 0;
free_msg:
kfree(msg);
return ret;
}
/**