From 0db6d0eafa86f7158c5d51e3c63d04b853fee94f Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Mon, 16 Mar 2020 09:12:03 -0700 Subject: [PATCH] haven: Clean up payload sizes VMID is represented inconsistently in payload structs. Consistently use hh_vmid_t to reduce mistakes around sizing of vmid. IRQ notify request payload was also incorrectly formatted according to specification. Change-Id: I0875655f69946eb0af609c67bdfdfa0dab5c7acc Signed-off-by: Elliot Berman --- drivers/virt/haven/hh_rm_drv_private.h | 37 +++++++++++++++----------- drivers/virt/haven/hh_rm_iface.c | 8 +++--- include/linux/haven/hh_rm_drv.h | 13 ++++----- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/drivers/virt/haven/hh_rm_drv_private.h b/drivers/virt/haven/hh_rm_drv_private.h index 8f68668630c8..933e22ab736d 100644 --- a/drivers/virt/haven/hh_rm_drv_private.h +++ b/drivers/virt/haven/hh_rm_drv_private.h @@ -94,8 +94,8 @@ struct hh_vm_property { /* Call: VM_ALLOCATE */ struct hh_vm_allocate_req_payload { - u8 vmid:4; - u8 reserved:4; + hh_vmid_t vmid; + u16 reserved; } __packed; struct hh_vm_allocate_resp_payload { @@ -104,8 +104,8 @@ struct hh_vm_allocate_resp_payload { /* Call: VM_START */ struct hh_vm_start_req_payload { - u8 vmid:4; - u8 reserved:4; + hh_vmid_t vmid; + u16 reserved; } __packed; struct hh_vm_start_resp_payload { @@ -114,14 +114,14 @@ struct hh_vm_start_resp_payload { /* Call: CONSOLE_OPEN, CONSOLE_CLOSE, CONSOLE_FLUSH */ struct hh_vm_console_common_req_payload { - u32 vmid; - u32 reserved0; + hh_vmid_t vmid; + u16 reserved0; } __packed; /* Call: CONSOLE_WRITE */ struct hh_vm_console_write_req_payload { - u32 vmid; - u32 num_bytes; + hh_vmid_t vmid; + u16 num_bytes; u8 data[0]; } __packed; @@ -134,14 +134,14 @@ struct hh_vm_console_write_req_payload { #define HH_RM_RES_TYPE_VCPU 4 struct hh_vm_get_hyp_res_req_payload { - u16 vmid; + hh_vmid_t vmid; u16 reserved; } __packed; struct hh_vm_get_hyp_res_resp_entry { u8 res_type; u8 reserved; - u16 partner_vmid; + hh_vmid_t partner_vmid; u32 resource_handle; u32 resource_label; u32 cap_id_low; @@ -168,6 +168,7 @@ struct hh_vm_irq_accept_resp_payload { /* Call: VM_IRQ_LEND */ struct hh_vm_irq_lend_req_payload { hh_vmid_t vmid; + u16 reserved; s32 virq; s32 label; } __packed; @@ -182,12 +183,16 @@ struct hh_vm_irq_lend_resp_payload { struct hh_vm_irq_notify_req_payload { hh_virq_handle_t virq; - u16 flags; - u16 reserved0; - u32 reserved1; - struct { - u32 num_vmids; - u64 vmids[0]; + u8 flags; + u8 reserved0; + u16 reserved1; + struct __packed { + u16 num_vmids; + u16 reserved; + struct __packed { + hh_vmid_t vmid; + u16 reserved; + } vmids[0]; } optional[0]; } __packed; diff --git a/drivers/virt/haven/hh_rm_iface.c b/drivers/virt/haven/hh_rm_iface.c index 3e61747b8a4d..99087ee464ff 100644 --- a/drivers/virt/haven/hh_rm_iface.c +++ b/drivers/virt/haven/hh_rm_iface.c @@ -263,12 +263,12 @@ static int hh_rm_vm_irq_notify(const hh_vmid_t *vmids, unsigned int num_vmids, if (!(flags & HH_VM_IRQ_NOTIFY_FLAGS_LENT) && num_vmids) return -EINVAL; - if (num_vmids > U32_MAX) + if (num_vmids > U16_MAX) return -EINVAL; req_payload_size = sizeof(*req_payload); if (flags & HH_VM_IRQ_NOTIFY_FLAGS_LENT) - req_payload_size += sizeof(req_payload->optional) + + req_payload_size += sizeof(*(req_payload->optional)) + (sizeof(req_payload->optional->vmids[0]) * num_vmids); req_payload = kzalloc(req_payload_size, GFP_KERNEL); @@ -280,12 +280,12 @@ static int hh_rm_vm_irq_notify(const hh_vmid_t *vmids, unsigned int num_vmids, if (flags & HH_VM_IRQ_NOTIFY_FLAGS_LENT) { req_payload->optional[0].num_vmids = num_vmids; for (i = 0; i < num_vmids; i++) - req_payload->optional[0].vmids[i] = vmids[i]; + req_payload->optional[0].vmids[i].vmid = vmids[i]; } resp_payload = hh_rm_call(HH_RM_RPC_MSG_ID_CALL_VM_IRQ_NOTIFY, - &req_payload, sizeof(req_payload), + req_payload, req_payload_size, &resp_payload_size, &reply_err_code); kfree(req_payload); if (reply_err_code || IS_ERR_OR_NULL(resp_payload)) { diff --git a/include/linux/haven/hh_rm_drv.h b/include/linux/haven/hh_rm_drv.h index 0dbe699fc41c..9b3325b231c9 100644 --- a/include/linux/haven/hh_rm_drv.h +++ b/include/linux/haven/hh_rm_drv.h @@ -143,7 +143,7 @@ struct hh_notify_vmid_desc { #define HH_RM_OS_STATUS_RUN 4 struct hh_rm_notif_vm_status_payload { - u16 vmid; + hh_vmid_t vmid; u16 reserved; u8 vm_status; u8 os_status; @@ -151,20 +151,21 @@ struct hh_rm_notif_vm_status_payload { } __packed; struct hh_rm_notif_vm_irq_lent_payload { - u16 owner_vmid; - u32 virq_handle; - u32 virq_label; + hh_vmid_t owner_vmid; + u16 reserved; + hh_virq_handle_t virq_handle; + hh_label_t virq_label; } __packed; struct hh_rm_notif_vm_irq_released_payload { - u32 virq_handle; + hh_virq_handle_t virq_handle; } __packed; /* VM Services */ #define HH_RM_NOTIF_VM_CONSOLE_CHARS 0X56100080 struct hh_rm_notif_vm_console_chars { - u16 vmid; + hh_vmid_t vmid; u16 num_bytes; u8 bytes[0]; } __packed;