Skip to content

Commit f0d2f5c

Browse files
Jinank Jainliuw
authored andcommitted
x86/hyperv: Add an interface to do nested hypercalls
According to TLFS, in order to communicate to L0 hypervisor there needs to be an additional bit set in the control register. This communication is required to perform privileged instructions which can only be performed by L0 hypervisor. An example of that could be setting up the VMBus infrastructure. Signed-off-by: Jinank Jain <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Link: https://lore.kernel.org/r/24f9d46d5259a688113e6e5e69e21002647f4949.1672639707.git.jinankjain@linux.microsoft.com Signed-off-by: Wei Liu <[email protected]>
1 parent 7fec185 commit f0d2f5c

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

arch/x86/include/asm/hyperv-tlfs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ struct hv_nested_enlightenments_control {
382382
__u32 reserved:31;
383383
} features;
384384
struct {
385-
__u32 reserved;
385+
__u32 inter_partition_comm:1;
386+
__u32 reserved:31;
386387
} hypercallControls;
387388
} __packed;
388389

arch/x86/include/asm/mshyperv.h

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ static inline u64 hv_do_hypercall(u64 control, void *input, void *output)
7272
return hv_status;
7373
}
7474

75+
/* Hypercall to the L0 hypervisor */
76+
static inline u64 hv_do_nested_hypercall(u64 control, void *input, void *output)
77+
{
78+
return hv_do_hypercall(control | HV_HYPERCALL_NESTED, input, output);
79+
}
80+
7581
/* Fast hypercall with 8 bytes of input and no output */
76-
static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
82+
static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1)
7783
{
78-
u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT;
84+
u64 hv_status;
7985

8086
#ifdef CONFIG_X86_64
8187
{
@@ -103,10 +109,24 @@ static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
103109
return hv_status;
104110
}
105111

112+
static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
113+
{
114+
u64 control = (u64)code | HV_HYPERCALL_FAST_BIT;
115+
116+
return _hv_do_fast_hypercall8(control, input1);
117+
}
118+
119+
static inline u64 hv_do_fast_nested_hypercall8(u16 code, u64 input1)
120+
{
121+
u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED;
122+
123+
return _hv_do_fast_hypercall8(control, input1);
124+
}
125+
106126
/* Fast hypercall with 16 bytes of input */
107-
static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
127+
static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2)
108128
{
109-
u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT;
129+
u64 hv_status;
110130

111131
#ifdef CONFIG_X86_64
112132
{
@@ -137,6 +157,20 @@ static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
137157
return hv_status;
138158
}
139159

160+
static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
161+
{
162+
u64 control = (u64)code | HV_HYPERCALL_FAST_BIT;
163+
164+
return _hv_do_fast_hypercall16(control, input1, input2);
165+
}
166+
167+
static inline u64 hv_do_fast_nested_hypercall16(u16 code, u64 input1, u64 input2)
168+
{
169+
u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED;
170+
171+
return _hv_do_fast_hypercall16(control, input1, input2);
172+
}
173+
140174
extern struct hv_vp_assist_page **hv_vp_assist_page;
141175

142176
static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)

include/asm-generic/hyperv-tlfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ enum HV_GENERIC_SET_FORMAT {
194194
#define HV_HYPERCALL_VARHEAD_OFFSET 17
195195
#define HV_HYPERCALL_VARHEAD_MASK GENMASK_ULL(26, 17)
196196
#define HV_HYPERCALL_RSVD0_MASK GENMASK_ULL(31, 27)
197+
#define HV_HYPERCALL_NESTED BIT_ULL(31)
197198
#define HV_HYPERCALL_REP_COMP_OFFSET 32
198199
#define HV_HYPERCALL_REP_COMP_1 BIT_ULL(32)
199200
#define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32)

0 commit comments

Comments
 (0)