mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-04-28 11:43:56 +00:00
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>
49 lines
994 B
C
49 lines
994 B
C
/*
|
|
* Copyright (C) 2020-2023 Intel Corporation.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <util.h>
|
|
#include <acrn_hv_defs.h>
|
|
#include <asm/guest/vm.h>
|
|
#include <vm_event.h>
|
|
#include <sbuf.h>
|
|
|
|
int32_t init_vm_event(struct acrn_vm *vm, uint64_t *hva)
|
|
{
|
|
struct shared_buf *sbuf = (struct shared_buf *)hva;
|
|
int ret = -1;
|
|
|
|
stac();
|
|
if (sbuf != NULL) {
|
|
if (sbuf->magic == SBUF_MAGIC) {
|
|
vm->sw.vm_event_sbuf = sbuf;
|
|
spinlock_init(&vm->vm_event_lock);
|
|
ret = 0;
|
|
}
|
|
}
|
|
clac();
|
|
|
|
return ret;
|
|
}
|
|
|
|
int32_t send_vm_event(struct acrn_vm *vm, struct vm_event *event)
|
|
{
|
|
struct shared_buf *sbuf = (struct shared_buf *)vm->sw.vm_event_sbuf;
|
|
int32_t ret = -ENODEV;
|
|
uint32_t size_sent;
|
|
|
|
if (sbuf != NULL) {
|
|
spinlock_obtain(&vm->vm_event_lock);
|
|
size_sent = sbuf_put(sbuf, (uint8_t *)event, sizeof(*event));
|
|
spinlock_release(&vm->vm_event_lock);
|
|
if (size_sent == sizeof(struct vm_event)) {
|
|
arch_fire_hsm_interrupt();
|
|
ret = 0;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|