drivers/hv/hv_common.c
Source file repositories/reference/linux-study-clean/drivers/hv/hv_common.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hv/hv_common.c- Extension
.c- Size
- 24998 bytes
- Lines
- 866
- Domain
- Driver Families
- Bucket
- drivers/hv
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/acpi.hlinux/export.hlinux/bitfield.hlinux/cpumask.hlinux/sched/task_stack.hlinux/panic_notifier.hlinux/ptrace.hlinux/random.hlinux/efi.hlinux/kdebug.hlinux/kmsg_dump.hlinux/sizes.hlinux/slab.hlinux/dma-map-ops.hlinux/set_memory.hhyperv/hvhdk.hasm/mshyperv.h
Detected Declarations
struct hv_status_infofunction hv_common_freefunction hv_die_panic_notify_crashfunction hv_kmsg_dumpfunction hv_kmsg_dump_unregisterfunction hv_kmsg_dump_registerfunction hv_output_page_existsfunction hv_get_partition_idfunction get_vtlfunction hv_common_initfunction ms_hyperv_late_initfunction hv_common_cpu_initfunction hv_common_cpu_diefunction hv_common_cpu_initfunction hv_query_ext_capfunction hv_setup_dma_opsfunction hv_is_hibernation_supportedfunction __hv_read_ref_counterfunction hv_is_isolation_supportedfunction hv_isolation_type_snpfunction hv_isolation_type_tdxfunction hv_setup_vmbus_handlerfunction hv_remove_vmbus_handlerfunction hv_setup_mshv_handlerfunction hv_setup_kexec_handlerfunction hv_remove_kexec_handlerfunction hv_setup_crash_handlerfunction hv_remove_crash_handlerfunction hyperv_cleanupfunction hv_ghcb_hypercallfunction hv_tdx_hypercallfunction hv_enable_coco_interruptfunction hv_para_set_sint_proxyfunction hv_para_get_synic_registerfunction hv_para_set_synic_registerfunction hv_identify_partition_typefunction recoverablefunction hv_result_to_errnoexport hv_current_partition_idexport hv_curr_partition_typeexport hv_nestedexport ms_hypervexport hv_vp_indexexport hv_max_vp_indexexport hyperv_pcpu_input_argexport hyperv_pcpu_output_argexport hv_synic_eventring_tailexport hv_query_ext_cap
Annotated Snippet
struct hv_status_info {
char *string;
int errno;
u16 code;
};
/*
* Note on the errno mappings:
* A failed hypercall is usually only recoverable (or loggable) near
* the call site where the HV_STATUS_* code is known. So the errno
* it gets converted to is not too useful further up the stack.
* Provide a few mappings that could be useful, and revert to -EIO
* as a fallback.
*/
static const struct hv_status_info hv_status_infos[] = {
#define _STATUS_INFO(status, errno) { #status, (errno), (status) }
_STATUS_INFO(HV_STATUS_SUCCESS, 0),
_STATUS_INFO(HV_STATUS_INVALID_HYPERCALL_CODE, -EINVAL),
_STATUS_INFO(HV_STATUS_INVALID_HYPERCALL_INPUT, -EINVAL),
_STATUS_INFO(HV_STATUS_INVALID_ALIGNMENT, -EIO),
_STATUS_INFO(HV_STATUS_INVALID_PARAMETER, -EINVAL),
_STATUS_INFO(HV_STATUS_ACCESS_DENIED, -EIO),
_STATUS_INFO(HV_STATUS_INVALID_PARTITION_STATE, -EIO),
_STATUS_INFO(HV_STATUS_OPERATION_DENIED, -EIO),
_STATUS_INFO(HV_STATUS_UNKNOWN_PROPERTY, -EIO),
_STATUS_INFO(HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE, -EIO),
_STATUS_INFO(HV_STATUS_INSUFFICIENT_MEMORY, -ENOMEM),
_STATUS_INFO(HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY, -ENOMEM),
_STATUS_INFO(HV_STATUS_INSUFFICIENT_ROOT_MEMORY, -ENOMEM),
_STATUS_INFO(HV_STATUS_INSUFFICIENT_CONTIGUOUS_ROOT_MEMORY, -ENOMEM),
_STATUS_INFO(HV_STATUS_INVALID_PARTITION_ID, -EINVAL),
_STATUS_INFO(HV_STATUS_INVALID_VP_INDEX, -EINVAL),
_STATUS_INFO(HV_STATUS_NOT_FOUND, -EIO),
_STATUS_INFO(HV_STATUS_INVALID_PORT_ID, -EINVAL),
_STATUS_INFO(HV_STATUS_INVALID_CONNECTION_ID, -EINVAL),
_STATUS_INFO(HV_STATUS_INSUFFICIENT_BUFFERS, -EIO),
_STATUS_INFO(HV_STATUS_NOT_ACKNOWLEDGED, -EIO),
_STATUS_INFO(HV_STATUS_INVALID_VP_STATE, -EIO),
_STATUS_INFO(HV_STATUS_NO_RESOURCES, -EIO),
_STATUS_INFO(HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED, -EIO),
_STATUS_INFO(HV_STATUS_INVALID_LP_INDEX, -EINVAL),
_STATUS_INFO(HV_STATUS_INVALID_REGISTER_VALUE, -EINVAL),
_STATUS_INFO(HV_STATUS_INVALID_LP_INDEX, -EIO),
_STATUS_INFO(HV_STATUS_INVALID_REGISTER_VALUE, -EIO),
_STATUS_INFO(HV_STATUS_OPERATION_FAILED, -EIO),
_STATUS_INFO(HV_STATUS_TIME_OUT, -EIO),
_STATUS_INFO(HV_STATUS_CALL_PENDING, -EIO),
_STATUS_INFO(HV_STATUS_VTL_ALREADY_ENABLED, -EIO),
#undef _STATUS_INFO
};
static inline const struct hv_status_info *find_hv_status_info(u64 hv_status)
{
int i;
u16 code = hv_result(hv_status);
for (i = 0; i < ARRAY_SIZE(hv_status_infos); ++i) {
const struct hv_status_info *info = &hv_status_infos[i];
if (info->code == code)
return info;
}
return NULL;
}
/* Convert a hypercall result into a linux-friendly error code. */
int hv_result_to_errno(u64 status)
{
const struct hv_status_info *info;
/* hv_do_hypercall() may return U64_MAX, hypercalls aren't possible */
if (unlikely(status == U64_MAX))
return -EOPNOTSUPP;
info = find_hv_status_info(status);
if (info)
return info->errno;
return -EIO;
}
EXPORT_SYMBOL_GPL(hv_result_to_errno);
const char *hv_result_to_string(u64 status)
{
const struct hv_status_info *info;
if (unlikely(status == U64_MAX))
return "Hypercall page missing!";
Annotation
- Immediate include surface: `linux/types.h`, `linux/acpi.h`, `linux/export.h`, `linux/bitfield.h`, `linux/cpumask.h`, `linux/sched/task_stack.h`, `linux/panic_notifier.h`, `linux/ptrace.h`.
- Detected declarations: `struct hv_status_info`, `function hv_common_free`, `function hv_die_panic_notify_crash`, `function hv_kmsg_dump`, `function hv_kmsg_dump_unregister`, `function hv_kmsg_dump_register`, `function hv_output_page_exists`, `function hv_get_partition_id`, `function get_vtl`, `function hv_common_init`.
- Atlas domain: Driver Families / drivers/hv.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.