Skip to content

Commit be35fb4

Browse files
hargar19namancse
authored andcommitted
Drivers: hv: hv_common: use meaningful errnos for hypercall statuses
Several HV_STATUS_* codes were collapsed to -EIO in commit 3817854 ("hyperv: Log hypercall status codes as strings") when hv_result_to_errno() was converted from a switch statement to a table-driven lookup. The change was a side-effect of consolidating string/errno mappings into one place; the commit message focused on adding hv_status_printk() for debugging. The previous OOT helper hv_status_to_errno() (in v6.12) preserved more meaningful errnos for several codes that have natural POSIX counterparts. The collapse-to-EIO loses information at call sites that key behavior on the converted errno (for example mshv_vtl_configure_reg_page() whitelists -EINVAL/-EACCES to fall back gracefully when the host refuses to install the register-page overlay; with -EIO that call site now hits a BUG()). Restore the semantically meaningful mappings for the affected statuses: HV_STATUS_ACCESS_DENIED -EIO -> -EACCES HV_STATUS_OPERATION_DENIED -EIO -> -EACCES HV_STATUS_UNKNOWN_PROPERTY -EIO -> -EINVAL HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE -EIO -> -EINVAL HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED -EIO -> -EOPNOTSUPP EACCES is the canonical errno for permission denied, EINVAL for invalid argument, and EOPNOTSUPP for unsupported operations. These mappings match both their <errno.h> definitions and the established meanings in the OOT v6.12 helper. Also drop two duplicate _STATUS_INFO() rows for HV_STATUS_INVALID_LP_INDEX and HV_STATUS_INVALID_REGISTER_VALUE that were leftover from the original table conversion. find_hv_status_info() is first-match-wins so the dead rows were not reachable, but they are confusing on review. Impact analysis --------------- The change only matters at sites that distinguish between specific errnos (e.g. `ret == -EIO` vs `ret == -EACCES`). To confirm safety, the entire kernel tree was audited for equality comparisons against any of the affected errnos in Hyper-V-touching code: $ git grep -nE '(ret|status|err|rc|r)[[:space:]]*==[[:space:]]*\ -(EACCES|EBADFD|ENOTRECOVERABLE|EOPNOTSUPP|EIO|EINVAL|ENOMEM)' \ -- drivers/hv/ arch/x86/hyperv/ arch/arm64/hyperv/ \ drivers/iommu/hyperv-iommu.c Results in Hyper-V code: drivers/hv/hv_balloon.c: ret == -EEXIST | ret == -EAGAIN (not in table) drivers/hv/mshv_eventfd.c: ret == -EAGAIN (not in table) drivers/hv/connection.c: ret == -ETIMEDOUT (not in table) drivers/hv/mshv_vtl_main.c: ret == -EINVAL || ret == -EACCES (the consumer this patch fixes) No other in-tree code path inspects -EOPNOTSUPP, -EACCES, -EINVAL or -EIO from a hypercall result to make a behavioral decision. The remaining HV_STATUS_* codes that 3817854 mapped to -EIO are therefore left as -EIO; nothing keys behavior off the distinction today. Signed-off-by: Hardik Garg <hargar@microsoft.com>
1 parent edd55b4 commit be35fb4

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

drivers/hv/hv_common.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,11 +869,11 @@ static const struct hv_status_info hv_status_infos[] = {
869869
_STATUS_INFO(HV_STATUS_INVALID_HYPERCALL_INPUT, -EINVAL),
870870
_STATUS_INFO(HV_STATUS_INVALID_ALIGNMENT, -EIO),
871871
_STATUS_INFO(HV_STATUS_INVALID_PARAMETER, -EINVAL),
872-
_STATUS_INFO(HV_STATUS_ACCESS_DENIED, -EIO),
872+
_STATUS_INFO(HV_STATUS_ACCESS_DENIED, -EACCES),
873873
_STATUS_INFO(HV_STATUS_INVALID_PARTITION_STATE, -EIO),
874-
_STATUS_INFO(HV_STATUS_OPERATION_DENIED, -EIO),
875-
_STATUS_INFO(HV_STATUS_UNKNOWN_PROPERTY, -EIO),
876-
_STATUS_INFO(HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE, -EIO),
874+
_STATUS_INFO(HV_STATUS_OPERATION_DENIED, -EACCES),
875+
_STATUS_INFO(HV_STATUS_UNKNOWN_PROPERTY, -EINVAL),
876+
_STATUS_INFO(HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE, -EINVAL),
877877
_STATUS_INFO(HV_STATUS_INSUFFICIENT_MEMORY, -ENOMEM),
878878
_STATUS_INFO(HV_STATUS_INVALID_PARTITION_ID, -EINVAL),
879879
_STATUS_INFO(HV_STATUS_INVALID_VP_INDEX, -EINVAL),
@@ -884,11 +884,9 @@ static const struct hv_status_info hv_status_infos[] = {
884884
_STATUS_INFO(HV_STATUS_NOT_ACKNOWLEDGED, -EIO),
885885
_STATUS_INFO(HV_STATUS_INVALID_VP_STATE, -EIO),
886886
_STATUS_INFO(HV_STATUS_NO_RESOURCES, -EIO),
887-
_STATUS_INFO(HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED, -EIO),
887+
_STATUS_INFO(HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED, -EOPNOTSUPP),
888888
_STATUS_INFO(HV_STATUS_INVALID_LP_INDEX, -EINVAL),
889889
_STATUS_INFO(HV_STATUS_INVALID_REGISTER_VALUE, -EINVAL),
890-
_STATUS_INFO(HV_STATUS_INVALID_LP_INDEX, -EIO),
891-
_STATUS_INFO(HV_STATUS_INVALID_REGISTER_VALUE, -EIO),
892890
_STATUS_INFO(HV_STATUS_OPERATION_FAILED, -EIO),
893891
_STATUS_INFO(HV_STATUS_TIME_OUT, -EIO),
894892
_STATUS_INFO(HV_STATUS_CALL_PENDING, -EIO),

0 commit comments

Comments
 (0)