Skip to content

Commit 0bd921a

Browse files
NunoDasNevesliuw
authored andcommitted
hyperv: Add definitions for root partition driver to hv headers
A few additional definitions are required for the mshv driver code (to follow). Introduce those here and clean up a little bit while at it. Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com> Reviewed-by: Roman Kisel <romank@linux.microsoft.com> Reviewed-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com> Reviewed-by: Tianyu Lan <tiala@microsoft.com> Link: https://lore.kernel.org/r/1741980536-3865-10-git-send-email-nunodasneves@linux.microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org> Message-ID: <1741980536-3865-10-git-send-email-nunodasneves@linux.microsoft.com>
1 parent e2575ff commit 0bd921a

File tree

3 files changed

+284
-11
lines changed

3 files changed

+284
-11
lines changed

include/hyperv/hvgdk_mini.h

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct hv_u128 {
1313
u64 high_part;
1414
} __packed;
1515

16-
/* NOTE: when adding below, update hv_status_to_string() */
16+
/* NOTE: when adding below, update hv_result_to_string() */
1717
#define HV_STATUS_SUCCESS 0x0
1818
#define HV_STATUS_INVALID_HYPERCALL_CODE 0x2
1919
#define HV_STATUS_INVALID_HYPERCALL_INPUT 0x3
@@ -51,6 +51,7 @@ struct hv_u128 {
5151
#define HV_HYP_PAGE_SHIFT 12
5252
#define HV_HYP_PAGE_SIZE BIT(HV_HYP_PAGE_SHIFT)
5353
#define HV_HYP_PAGE_MASK (~(HV_HYP_PAGE_SIZE - 1))
54+
#define HV_HYP_LARGE_PAGE_SHIFT 21
5455

5556
#define HV_PARTITION_ID_INVALID ((u64)0)
5657
#define HV_PARTITION_ID_SELF ((u64)-1)
@@ -374,6 +375,10 @@ union hv_hypervisor_version_info {
374375
#define HV_SHARED_GPA_BOUNDARY_ACTIVE BIT(5)
375376
#define HV_SHARED_GPA_BOUNDARY_BITS GENMASK(11, 6)
376377

378+
/* HYPERV_CPUID_FEATURES.ECX bits. */
379+
#define HV_VP_DISPATCH_INTERRUPT_INJECTION_AVAILABLE BIT(9)
380+
#define HV_VP_GHCB_ROOT_MAPPING_AVAILABLE BIT(10)
381+
377382
enum hv_isolation_type {
378383
HV_ISOLATION_TYPE_NONE = 0, /* HV_PARTITION_ISOLATION_TYPE_NONE */
379384
HV_ISOLATION_TYPE_VBS = 1,
@@ -436,36 +441,48 @@ union hv_vp_assist_msr_contents { /* HV_REGISTER_VP_ASSIST_PAGE */
436441
#define HVCALL_WITHDRAW_MEMORY 0x0049
437442
#define HVCALL_MAP_GPA_PAGES 0x004b
438443
#define HVCALL_UNMAP_GPA_PAGES 0x004c
444+
#define HVCALL_INSTALL_INTERCEPT 0x004d
439445
#define HVCALL_CREATE_VP 0x004e
440446
#define HVCALL_DELETE_VP 0x004f
441447
#define HVCALL_GET_VP_REGISTERS 0x0050
442448
#define HVCALL_SET_VP_REGISTERS 0x0051
449+
#define HVCALL_TRANSLATE_VIRTUAL_ADDRESS 0x0052
450+
#define HVCALL_CLEAR_VIRTUAL_INTERRUPT 0x0056
443451
#define HVCALL_DELETE_PORT 0x0058
444452
#define HVCALL_DISCONNECT_PORT 0x005b
445453
#define HVCALL_POST_MESSAGE 0x005c
446454
#define HVCALL_SIGNAL_EVENT 0x005d
447455
#define HVCALL_POST_DEBUG_DATA 0x0069
448456
#define HVCALL_RETRIEVE_DEBUG_DATA 0x006a
449457
#define HVCALL_RESET_DEBUG_SESSION 0x006b
458+
#define HVCALL_MAP_STATS_PAGE 0x006c
459+
#define HVCALL_UNMAP_STATS_PAGE 0x006d
450460
#define HVCALL_ADD_LOGICAL_PROCESSOR 0x0076
451461
#define HVCALL_GET_SYSTEM_PROPERTY 0x007b
452462
#define HVCALL_MAP_DEVICE_INTERRUPT 0x007c
453463
#define HVCALL_UNMAP_DEVICE_INTERRUPT 0x007d
454464
#define HVCALL_RETARGET_INTERRUPT 0x007e
455465
#define HVCALL_NOTIFY_PORT_RING_EMPTY 0x008b
466+
#define HVCALL_REGISTER_INTERCEPT_RESULT 0x0091
456467
#define HVCALL_ASSERT_VIRTUAL_INTERRUPT 0x0094
457468
#define HVCALL_CREATE_PORT 0x0095
458469
#define HVCALL_CONNECT_PORT 0x0096
459470
#define HVCALL_START_VP 0x0099
460471
#define HVCALL_GET_VP_ID_FROM_APIC_ID 0x009a
461472
#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
462473
#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
474+
#define HVCALL_SIGNAL_EVENT_DIRECT 0x00c0
475+
#define HVCALL_POST_MESSAGE_DIRECT 0x00c1
463476
#define HVCALL_DISPATCH_VP 0x00c2
477+
#define HVCALL_GET_GPA_PAGES_ACCESS_STATES 0x00c9
478+
#define HVCALL_ACQUIRE_SPARSE_SPA_PAGE_HOST_ACCESS 0x00d7
479+
#define HVCALL_RELEASE_SPARSE_SPA_PAGE_HOST_ACCESS 0x00d8
464480
#define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db
465481
#define HVCALL_MAP_VP_STATE_PAGE 0x00e1
466482
#define HVCALL_UNMAP_VP_STATE_PAGE 0x00e2
467483
#define HVCALL_GET_VP_STATE 0x00e3
468484
#define HVCALL_SET_VP_STATE 0x00e4
485+
#define HVCALL_GET_VP_CPUID_VALUES 0x00f4
469486
#define HVCALL_MMIO_READ 0x0106
470487
#define HVCALL_MMIO_WRITE 0x0107
471488

@@ -775,10 +792,10 @@ struct hv_message_page {
775792

776793
/* Define timer message payload structure. */
777794
struct hv_timer_message_payload {
778-
__u32 timer_index;
779-
__u32 reserved;
780-
__u64 expiration_time; /* When the timer expired */
781-
__u64 delivery_time; /* When the message was delivered */
795+
u32 timer_index;
796+
u32 reserved;
797+
u64 expiration_time; /* When the timer expired */
798+
u64 delivery_time; /* When the message was delivered */
782799
} __packed;
783800

784801
struct hv_x64_segment_register {
@@ -807,6 +824,8 @@ struct hv_x64_table_register {
807824
u64 base;
808825
} __packed;
809826

827+
#define HV_NORMAL_VTL 0
828+
810829
union hv_input_vtl {
811830
u8 as_uint8;
812831
struct {
@@ -1325,6 +1344,49 @@ struct hv_retarget_device_interrupt { /* HV_INPUT_RETARGET_DEVICE_INTERRUPT */
13251344
struct hv_device_interrupt_target int_target;
13261345
} __packed __aligned(8);
13271346

1347+
enum hv_intercept_type {
1348+
#if defined(CONFIG_X86)
1349+
HV_INTERCEPT_TYPE_X64_IO_PORT = 0x00000000,
1350+
HV_INTERCEPT_TYPE_X64_MSR = 0x00000001,
1351+
HV_INTERCEPT_TYPE_X64_CPUID = 0x00000002,
1352+
#endif
1353+
HV_INTERCEPT_TYPE_EXCEPTION = 0x00000003,
1354+
/* Used to be HV_INTERCEPT_TYPE_REGISTER */
1355+
HV_INTERCEPT_TYPE_RESERVED0 = 0x00000004,
1356+
HV_INTERCEPT_TYPE_MMIO = 0x00000005,
1357+
#if defined(CONFIG_X86)
1358+
HV_INTERCEPT_TYPE_X64_GLOBAL_CPUID = 0x00000006,
1359+
HV_INTERCEPT_TYPE_X64_APIC_SMI = 0x00000007,
1360+
#endif
1361+
HV_INTERCEPT_TYPE_HYPERCALL = 0x00000008,
1362+
#if defined(CONFIG_X86)
1363+
HV_INTERCEPT_TYPE_X64_APIC_INIT_SIPI = 0x00000009,
1364+
HV_INTERCEPT_MC_UPDATE_PATCH_LEVEL_MSR_READ = 0x0000000A,
1365+
HV_INTERCEPT_TYPE_X64_APIC_WRITE = 0x0000000B,
1366+
HV_INTERCEPT_TYPE_X64_MSR_INDEX = 0x0000000C,
1367+
#endif
1368+
HV_INTERCEPT_TYPE_MAX,
1369+
HV_INTERCEPT_TYPE_INVALID = 0xFFFFFFFF,
1370+
};
1371+
1372+
union hv_intercept_parameters {
1373+
/* HV_INTERCEPT_PARAMETERS is defined to be an 8-byte field. */
1374+
u64 as_uint64;
1375+
#if defined(CONFIG_X86)
1376+
/* HV_INTERCEPT_TYPE_X64_IO_PORT */
1377+
u16 io_port;
1378+
/* HV_INTERCEPT_TYPE_X64_CPUID */
1379+
u32 cpuid_index;
1380+
/* HV_INTERCEPT_TYPE_X64_APIC_WRITE */
1381+
u32 apic_write_mask;
1382+
/* HV_INTERCEPT_TYPE_EXCEPTION */
1383+
u16 exception_vector;
1384+
/* HV_INTERCEPT_TYPE_X64_MSR_INDEX */
1385+
u32 msr_index;
1386+
#endif
1387+
/* N.B. Other intercept types do not have any parameters. */
1388+
};
1389+
13281390
/* Data structures for HVCALL_MMIO_READ and HVCALL_MMIO_WRITE */
13291391
#define HV_HYPERCALL_MMIO_MAX_DATA_LENGTH 64
13301392

include/hyperv/hvhdk.h

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,24 @@
1919

2020
#define HV_VP_REGISTER_PAGE_VERSION_1 1u
2121

22+
#define HV_VP_REGISTER_PAGE_MAX_VECTOR_COUNT 7
23+
24+
union hv_vp_register_page_interrupt_vectors {
25+
u64 as_uint64;
26+
struct {
27+
u8 vector_count;
28+
u8 vector[HV_VP_REGISTER_PAGE_MAX_VECTOR_COUNT];
29+
} __packed;
30+
};
31+
2232
struct hv_vp_register_page {
2333
u16 version;
2434
u8 isvalid;
2535
u8 rsvdz;
2636
u32 dirty;
37+
38+
#if IS_ENABLED(CONFIG_X86)
39+
2740
union {
2841
struct {
2942
/* General purpose registers
@@ -95,6 +108,22 @@ struct hv_vp_register_page {
95108
union hv_x64_pending_interruption_register pending_interruption;
96109
union hv_x64_interrupt_state_register interrupt_state;
97110
u64 instruction_emulation_hints;
111+
u64 xfem;
112+
113+
/*
114+
* Fields from this point are not included in the register page save chunk.
115+
* The reserved field is intended to maintain alignment for unsaved fields.
116+
*/
117+
u8 reserved1[0x100];
118+
119+
/*
120+
* Interrupts injected as part of HvCallDispatchVp.
121+
*/
122+
union hv_vp_register_page_interrupt_vectors interrupt_vectors;
123+
124+
#elif IS_ENABLED(CONFIG_ARM64)
125+
/* Not yet supported in ARM */
126+
#endif
98127
} __packed;
99128

100129
#define HV_PARTITION_PROCESSOR_FEATURES_BANKS 2
@@ -299,10 +328,11 @@ union hv_partition_isolation_properties {
299328
#define HV_PARTITION_ISOLATION_HOST_TYPE_RESERVED 0x2
300329

301330
/* Note: Exo partition is enabled by default */
302-
#define HV_PARTITION_CREATION_FLAG_EXO_PARTITION BIT(8)
303-
#define HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED BIT(13)
304-
#define HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED BIT(19)
305-
#define HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE BIT(22)
331+
#define HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED BIT(4)
332+
#define HV_PARTITION_CREATION_FLAG_EXO_PARTITION BIT(8)
333+
#define HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED BIT(13)
334+
#define HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED BIT(19)
335+
#define HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE BIT(22)
306336

307337
struct hv_input_create_partition {
308338
u64 flags;
@@ -349,13 +379,23 @@ struct hv_input_set_partition_property {
349379
enum hv_vp_state_page_type {
350380
HV_VP_STATE_PAGE_REGISTERS = 0,
351381
HV_VP_STATE_PAGE_INTERCEPT_MESSAGE = 1,
382+
HV_VP_STATE_PAGE_GHCB = 2,
352383
HV_VP_STATE_PAGE_COUNT
353384
};
354385

355386
struct hv_input_map_vp_state_page {
356387
u64 partition_id;
357388
u32 vp_index;
358-
u32 type; /* enum hv_vp_state_page_type */
389+
u16 type; /* enum hv_vp_state_page_type */
390+
union hv_input_vtl input_vtl;
391+
union {
392+
u8 as_uint8;
393+
struct {
394+
u8 map_location_provided : 1;
395+
u8 reserved : 7;
396+
};
397+
} flags;
398+
u64 requested_map_location;
359399
} __packed;
360400

361401
struct hv_output_map_vp_state_page {
@@ -365,7 +405,14 @@ struct hv_output_map_vp_state_page {
365405
struct hv_input_unmap_vp_state_page {
366406
u64 partition_id;
367407
u32 vp_index;
368-
u32 type; /* enum hv_vp_state_page_type */
408+
u16 type; /* enum hv_vp_state_page_type */
409+
union hv_input_vtl input_vtl;
410+
u8 reserved0;
411+
} __packed;
412+
413+
struct hv_x64_apic_eoi_message {
414+
u32 vp_index;
415+
u32 interrupt_vector;
369416
} __packed;
370417

371418
struct hv_opaque_intercept_message {
@@ -515,6 +562,13 @@ struct hv_synthetic_timers_state {
515562
u64 reserved[5];
516563
} __packed;
517564

565+
struct hv_async_completion_message_payload {
566+
u64 partition_id;
567+
u32 status;
568+
u32 completion_count;
569+
u64 sub_status;
570+
} __packed;
571+
518572
union hv_input_delete_vp {
519573
u64 as_uint64[2];
520574
struct {
@@ -649,6 +703,57 @@ struct hv_input_set_vp_state {
649703
union hv_input_set_vp_state_data data[];
650704
} __packed;
651705

706+
union hv_x64_vp_execution_state {
707+
u16 as_uint16;
708+
struct {
709+
u16 cpl:2;
710+
u16 cr0_pe:1;
711+
u16 cr0_am:1;
712+
u16 efer_lma:1;
713+
u16 debug_active:1;
714+
u16 interruption_pending:1;
715+
u16 vtl:4;
716+
u16 enclave_mode:1;
717+
u16 interrupt_shadow:1;
718+
u16 virtualization_fault_active:1;
719+
u16 reserved:2;
720+
} __packed;
721+
};
722+
723+
struct hv_x64_intercept_message_header {
724+
u32 vp_index;
725+
u8 instruction_length:4;
726+
u8 cr8:4; /* Only set for exo partitions */
727+
u8 intercept_access_type;
728+
union hv_x64_vp_execution_state execution_state;
729+
struct hv_x64_segment_register cs_segment;
730+
u64 rip;
731+
u64 rflags;
732+
} __packed;
733+
734+
union hv_x64_memory_access_info {
735+
u8 as_uint8;
736+
struct {
737+
u8 gva_valid:1;
738+
u8 gva_gpa_valid:1;
739+
u8 hypercall_output_pending:1;
740+
u8 tlb_locked_no_overlay:1;
741+
u8 reserved:4;
742+
} __packed;
743+
};
744+
745+
struct hv_x64_memory_intercept_message {
746+
struct hv_x64_intercept_message_header header;
747+
u32 cache_type; /* enum hv_cache_type */
748+
u8 instruction_byte_count;
749+
union hv_x64_memory_access_info memory_access_info;
750+
u8 tpr_priority;
751+
u8 reserved1;
752+
u64 guest_virtual_address;
753+
u64 guest_physical_address;
754+
u8 instruction_bytes[16];
755+
} __packed;
756+
652757
/*
653758
* Dispatch state for the VP communicated by the hypervisor to the
654759
* VP-dispatching thread in the root on return from HVCALL_DISPATCH_VP.
@@ -716,6 +821,7 @@ static_assert(sizeof(struct hv_vp_signal_pair_scheduler_message) ==
716821
#define HV_DISPATCH_VP_FLAG_SKIP_VP_SPEC_FLUSH 0x8
717822
#define HV_DISPATCH_VP_FLAG_SKIP_CALLER_SPEC_FLUSH 0x10
718823
#define HV_DISPATCH_VP_FLAG_SKIP_CALLER_USER_SPEC_FLUSH 0x20
824+
#define HV_DISPATCH_VP_FLAG_SCAN_INTERRUPT_INJECTION 0x40
719825

720826
struct hv_input_dispatch_vp {
721827
u64 partition_id;
@@ -730,4 +836,18 @@ struct hv_output_dispatch_vp {
730836
u32 dispatch_event; /* enum hv_vp_dispatch_event */
731837
} __packed;
732838

839+
struct hv_input_modify_sparse_spa_page_host_access {
840+
u32 host_access : 2;
841+
u32 reserved : 30;
842+
u32 flags;
843+
u64 partition_id;
844+
u64 spa_page_list[];
845+
} __packed;
846+
847+
/* hv_input_modify_sparse_spa_page_host_access flags */
848+
#define HV_MODIFY_SPA_PAGE_HOST_ACCESS_MAKE_EXCLUSIVE 0x1
849+
#define HV_MODIFY_SPA_PAGE_HOST_ACCESS_MAKE_SHARED 0x2
850+
#define HV_MODIFY_SPA_PAGE_HOST_ACCESS_LARGE_PAGE 0x4
851+
#define HV_MODIFY_SPA_PAGE_HOST_ACCESS_HUGE_PAGE 0x8
852+
733853
#endif /* _HV_HVHDK_H */

0 commit comments

Comments
 (0)