hv: add max_len for sbuf_put param

sbuf_put copies sbuf->ele_size of data, and puts into ring. Currently
this function assumes that data size from caller is no less than
sbuf->ele_size.

But as sbuf->ele_size is usually setup by some sources outside of the HV
(e.g., the service VM), it is not meant to be trusted. So caller should
provide the max length of the data for safety reason. sbuf_put() will
return UINT32_MAX if max_len of data is less than element size.

Additionally, a helper function sbuf_put_many() is added for putting
multiple entries.

Tracked-On: #8547
Signed-off-by: Wu Zhou <wu.zhou@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Wu Zhou
2023-08-16 11:23:56 +08:00
committed by acrnsi-robot
parent 056f4abcfb
commit 925e3d95b4
7 changed files with 57 additions and 31 deletions

View File

@@ -91,18 +91,14 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
/* Check whether output to memory */
if (do_mem_log) {
uint32_t i, msg_len;
uint32_t msg_len;
struct shared_buf *sbuf = per_cpu(sbuf, pcpu_id)[ACRN_HVLOG];
/* If sbuf is not ready, we just drop the massage */
if (sbuf != NULL) {
msg_len = strnlen_s(buffer, LOG_MESSAGE_MAX_SIZE);
for (i = 0U; i < (((msg_len - 1U) / LOG_ENTRY_SIZE) + 1U);
i++) {
(void)sbuf_put(sbuf, (uint8_t *)buffer +
(i * LOG_ENTRY_SIZE));
}
(void)sbuf_put_many(sbuf, LOG_ENTRY_SIZE, (uint8_t *)buffer,
LOG_ENTRY_SIZE * (((msg_len - 1U) / LOG_ENTRY_SIZE) + 1));
}
}
}