Skip to content

Commit c41f286

Browse files
yonghuahdbkinder
authored andcommitted
hv: revise interfaces description in vlapic
Add comments for APIs: - vlapic_pending_intr(); - vlapic_pending_accepted(); - vlapic_post_intr(); - lapicv_get_pir_desc_paddr(); - vlapic_intr_level(); - vlapic_intr_edge(); - vlapic_set_local_intr(); - vlapic_intr_msi(); Tracked-On: #1595 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
1 parent 4694963 commit c41f286

File tree

2 files changed

+188
-19
lines changed

2 files changed

+188
-19
lines changed

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,35 @@ vlapic_set_intr_ready(struct acrn_vlapic *vlapic, uint32_t vector, bool level)
531531
return 1;
532532
}
533533

534-
/* Post an interrupt to the vcpu running on 'hostcpu'. */
534+
/**
535+
* @brief Send notification vector to target pCPU.
536+
*
537+
* If APICv Posted-Interrupt is enabled and target pCPU is in non-root mode,
538+
* pCPU will sync pending virtual interrupts from PIR to vIRR automatically,
539+
* without VM exit.
540+
* If pCPU in root-mode, virtual interrupt will be injected in next VM entry.
541+
*
542+
* @param[in] dest_pcpu_id Target CPU ID.
543+
*
544+
* @return void
545+
*/
535546
void vlapic_post_intr(uint16_t dest_pcpu_id)
536547
{
537548
send_single_ipi(dest_pcpu_id, VECTOR_POSTED_INTR);
538549
}
539550

551+
/**
552+
* @brief Get physical address to PIR description.
553+
*
554+
* If APICv Posted-interrupt is supported, this address will be configured
555+
* to VMCS "Posted-interrupt descriptor address" field.
556+
*
557+
* @param[in] vcpu Target vCPU
558+
*
559+
* @return physicall address to PIR
560+
*
561+
* @pre vcpu != NULL
562+
*/
540563
uint64_t apicv_get_pir_desc_paddr(struct vcpu *vcpu)
541564
{
542565
struct acrn_vlapic *vlapic;
@@ -1286,6 +1309,19 @@ vlapic_icrlo_write_handler(struct acrn_vlapic *vlapic)
12861309
return 0; /* handled completely in the kernel */
12871310
}
12881311

1312+
/**
1313+
* @brief Get pending virtual interrupts for vLAPIC.
1314+
*
1315+
* @param[in] vlapic Pointer to target vLAPIC data structure
1316+
* @param[inout] vecptr Pointer to vector buffer and will be filled
1317+
* with eligible vector if any.
1318+
*
1319+
* @return 0 - There is no eligible pending vector.
1320+
* @return 1 - There is pending vector.
1321+
*
1322+
* @remark The vector does not automatically transition to the ISR as a
1323+
* result of calling this function.
1324+
*/
12891325
int
12901326
vlapic_pending_intr(const struct acrn_vlapic *vlapic, uint32_t *vecptr)
12911327
{
@@ -1318,6 +1354,21 @@ vlapic_pending_intr(const struct acrn_vlapic *vlapic, uint32_t *vecptr)
13181354
return 0;
13191355
}
13201356

1357+
/**
1358+
* @brief Accept virtual interrupt.
1359+
*
1360+
* Transition 'vector' from IRR to ISR. This function is called with the
1361+
* vector returned by 'vlapic_pending_intr()' when the guest is able to
1362+
* accept this interrupt (i.e. RFLAGS.IF = 1 and no conditions exist that
1363+
* block interrupt delivery).
1364+
*
1365+
* @param[in] vlapic Pointer to target vLAPIC data structure
1366+
* @param[in] vector Target virtual interrupt vector
1367+
*
1368+
* @return void
1369+
*
1370+
* @pre vlapic != NULL
1371+
*/
13211372
void
13221373
vlapic_intr_accepted(struct acrn_vlapic *vlapic, uint32_t vector)
13231374
{
@@ -1879,17 +1930,12 @@ int
18791930
vlapic_set_intr(struct vcpu *vcpu, uint32_t vector, bool level)
18801931
{
18811932
struct acrn_vlapic *vlapic;
1882-
int ret = 0;
1883-
1884-
if (vcpu == NULL) {
1885-
return -EINVAL;
1886-
}
18871933

18881934
/*
18891935
* According to section "Maskable Hardware Interrupts" in Intel SDM
18901936
* vectors 16 through 255 can be delivered through the local APIC.
18911937
*/
1892-
if (vector > 255U) {
1938+
if ((vcpu == NULL) || (vector > 255U)) {
18931939
return -EINVAL;
18941940
}
18951941

@@ -1905,9 +1951,22 @@ vlapic_set_intr(struct vcpu *vcpu, uint32_t vector, bool level)
19051951
vcpu_make_request(vcpu, ACRN_REQUEST_EVENT);
19061952
}
19071953

1908-
return ret;
1954+
return 0;
19091955
}
19101956

1957+
/**
1958+
* @brief Triggers LAPIC local interrupt(LVT).
1959+
*
1960+
* @param[in] vm Pointer to VM data structure
1961+
* @param[in] vcpu_id_arg ID of vCPU, BROADCAST_CPU_ID means triggering
1962+
* interrupt to all vCPUs.
1963+
* @param[in] vector Vector to be fired.
1964+
*
1965+
* @return 0 on success.
1966+
* @return -EINVAL on error that vcpu_id_arg or vector is invalid.
1967+
*
1968+
* @pre vm != NULL
1969+
*/
19111970
int
19121971
vlapic_set_local_intr(struct vm *vm, uint16_t vcpu_id_arg, uint32_t vector)
19131972
{
@@ -1939,6 +1998,18 @@ vlapic_set_local_intr(struct vm *vm, uint16_t vcpu_id_arg, uint32_t vector)
19391998
return error;
19401999
}
19412000

2001+
/**
2002+
* @brief Inject MSI to target VM.
2003+
*
2004+
* @param[in] vm Pointer to VM data structure
2005+
* @param[in] addr MSI address.
2006+
* @param[in] msg MSI data.
2007+
*
2008+
* @return 0 on success.
2009+
* @return non-zero on error that addr is invalid.
2010+
*
2011+
* @pre vm != NULL
2012+
*/
19422013
int
19432014
vlapic_intr_msi(struct vm *vm, uint64_t addr, uint64_t msg)
19442015
{

hypervisor/include/arch/x86/guest/vlapic.h

Lines changed: 109 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
#ifndef VLAPIC_H
3131
#define VLAPIC_H
3232

33+
34+
/**
35+
* @file vlapic.h
36+
*
37+
* @brief public APIs for virtual LAPIC
38+
*/
39+
40+
3341
/*
3442
* 16 priority levels with at most one vector injected per level.
3543
*/
@@ -103,26 +111,72 @@ struct acrn_vlapic {
103111
void vlapic_set_cr8(struct acrn_vlapic *vlapic, uint64_t val);
104112
uint64_t vlapic_get_cr8(const struct acrn_vlapic *vlapic);
105113

106-
/*
107-
* Returns 0 if there is no eligible vector that can be delivered to the
108-
* guest at this time and non-zero otherwise.
114+
/**
115+
* @brief virtual LAPIC
116+
*
117+
* @addtogroup acrn_vlapic ACRN vLAPIC
118+
* @{
119+
*/
120+
121+
122+
/**
123+
* @brief Get pending virtual interrupts for vLAPIC.
124+
*
125+
* @param[in] vlapic Pointer to target vLAPIC data structure
126+
* @param[inout] vecptr Pointer to vector buffer and will be filled
127+
* with eligible vector if any.
109128
*
110-
* If an eligible vector number is found and 'vecptr' is not NULL then it will
111-
* be stored in the location pointed to by 'vecptr'.
129+
* @return 0 - There is no eligible pending vector.
130+
* @return 1 - There is pending vector.
112131
*
113-
* Note that the vector does not automatically transition to the ISR as a
114-
* result of calling this function.
132+
* @remark The vector does not automatically transition to the ISR as a
133+
* result of calling this function.
115134
*/
116135
int vlapic_pending_intr(const struct acrn_vlapic *vlapic, uint32_t *vecptr);
117136

118-
/*
137+
/**
138+
* @brief Accept virtual interrupt.
139+
*
119140
* Transition 'vector' from IRR to ISR. This function is called with the
120141
* vector returned by 'vlapic_pending_intr()' when the guest is able to
121142
* accept this interrupt (i.e. RFLAGS.IF = 1 and no conditions exist that
122143
* block interrupt delivery).
144+
*
145+
* @param[in] vlapic Pointer to target vLAPIC data structure
146+
* @param[in] vector Target virtual interrupt vector
147+
*
148+
* @return void
149+
*
150+
* @pre vlapic != NULL
123151
*/
124152
void vlapic_intr_accepted(struct acrn_vlapic *vlapic, uint32_t vector);
153+
154+
/**
155+
* @brief Send notification vector to target pCPU.
156+
*
157+
* If APICv Posted-Interrupt is enabled and target pCPU is in non-root mode,
158+
* pCPU will sync pending virtual interrupts from PIR to vIRR automatically,
159+
* without VM exit.
160+
* If pCPU in root-mode, virtual interrupt will be injected in next VM entry.
161+
*
162+
* @param[in] dest_pcpu_id Target CPU ID.
163+
*
164+
* @return void
165+
*/
125166
void vlapic_post_intr(uint16_t dest_pcpu_id);
167+
168+
/**
169+
* @brief Get physical address to PIR description.
170+
*
171+
* If APICv Posted-interrupt is supported, this address will be configured
172+
* to VMCS "Posted-interrupt descriptor address" field.
173+
*
174+
* @param[in] vcpu Target vCPU
175+
*
176+
* @return physicall address to PIR
177+
*
178+
* @pre vcpu != NULL
179+
*/
126180
uint64_t apicv_get_pir_desc_paddr(struct vcpu *vcpu);
127181

128182
int vlapic_rdmsr(struct vcpu *vcpu, uint32_t msr, uint64_t *rval);
@@ -136,24 +190,63 @@ int vlapic_set_intr(struct vcpu *vcpu, uint32_t vector, bool level);
136190

137191
#define LAPIC_TRIG_LEVEL true
138192
#define LAPIC_TRIG_EDGE false
193+
/**
194+
* @brief Pend level-trigger mode virtual interrupt to vCPU.
195+
*
196+
* @param[in] vcpu Pointer to target vCPU data structure
197+
* @param[in] vector Vector to be injected.
198+
*
199+
* @return 0 on success.
200+
* @return -EINVAL on error that vector is invalid or vcpu is NULL.
201+
*/
139202
static inline int
140203
vlapic_intr_level(struct vcpu *vcpu, uint32_t vector)
141204
{
142205
return vlapic_set_intr(vcpu, vector, LAPIC_TRIG_LEVEL);
143206
}
144207

208+
/**
209+
* @brief Pend edge-trigger mode virtual interrupt to vCPU.
210+
*
211+
* @param[in] vcpu Pointer to target vCPU data structure
212+
* @param[in] vector Vector to be injected.
213+
*
214+
* @return 0 on success.
215+
* @return -EINVAL on error that vector is invalid or vcpu is NULL.
216+
*/
145217
static inline int
146218
vlapic_intr_edge(struct vcpu *vcpu, uint32_t vector)
147219
{
148220
return vlapic_set_intr(vcpu, vector, LAPIC_TRIG_EDGE);
149221
}
150222

151-
/*
152-
* Triggers the LAPIC local interrupt (LVT) 'vector' on 'cpu'. 'cpu' can
153-
* be set to -1 to trigger the interrupt on all CPUs.
223+
/**
224+
* @brief Triggers LAPIC local interrupt(LVT).
225+
*
226+
* @param[in] vm Pointer to VM data structure
227+
* @param[in] vcpu_id_arg ID of vCPU, BROADCAST_CPU_ID means triggering
228+
* interrupt to all vCPUs.
229+
* @param[in] vector Vector to be fired.
230+
*
231+
* @return 0 on success.
232+
* @return -EINVAL on error that vcpu_id_arg or vector is invalid.
233+
*
234+
* @pre vm != NULL
154235
*/
155236
int vlapic_set_local_intr(struct vm *vm, uint16_t vcpu_id_arg, uint32_t vector);
156237

238+
/**
239+
* @brief Inject MSI to target VM.
240+
*
241+
* @param[in] vm Pointer to VM data structure
242+
* @param[in] addr MSI address.
243+
* @param[in] msg MSI data.
244+
*
245+
* @return 0 on success.
246+
* @return non-zero on error that addr is invalid.
247+
*
248+
* @pre vm != NULL
249+
*/
157250
int vlapic_intr_msi(struct vm *vm, uint64_t addr, uint64_t msg);
158251

159252
void vlapic_deliver_intr(struct vm *vm, bool level, uint32_t dest,
@@ -189,4 +282,9 @@ int apic_write_vmexit_handler(struct vcpu *vcpu);
189282
int veoi_vmexit_handler(struct vcpu *vcpu);
190283
int tpr_below_threshold_vmexit_handler(__unused struct vcpu *vcpu);
191284
void calcvdest(struct vm *vm, uint64_t *dmask, uint32_t dest, bool phys);
285+
286+
/**
287+
* @}
288+
*/
289+
/* End of acrn_vlapic */
192290
#endif /* VLAPIC_H */

0 commit comments

Comments
 (0)