Skip to content

Commit 498ad39

Browse files
yakuizhaosuryasaimadhu
authored andcommitted
x86/acrn: Use HYPERVISOR_CALLBACK_VECTOR for ACRN guest upcall vector
Use the HYPERVISOR_CALLBACK_VECTOR to notify an ACRN guest. Co-developed-by: Jason Chen CJ <[email protected]> Signed-off-by: Jason Chen CJ <[email protected]> Signed-off-by: Zhao Yakui <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: x86-ml <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent ec7972c commit 498ad39

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ config JAILHOUSE_GUEST
838838
config ACRN_GUEST
839839
bool "ACRN Guest support"
840840
depends on X86_64
841+
select X86_HV_CALLBACK_VECTOR
841842
help
842843
This option allows to run Linux as guest in the ACRN hypervisor. ACRN is
843844
a flexible, lightweight reference open-source hypervisor, built with

arch/x86/entry/entry_64.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,11 @@ apicinterrupt3 HYPERV_STIMER0_VECTOR \
11421142
hv_stimer0_callback_vector hv_stimer0_vector_handler
11431143
#endif /* CONFIG_HYPERV */
11441144

1145+
#if IS_ENABLED(CONFIG_ACRN_GUEST)
1146+
apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
1147+
acrn_hv_callback_vector acrn_hv_vector_handler
1148+
#endif
1149+
11451150
idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=IST_INDEX_DB ist_offset=DB_STACK_OFFSET
11461151
idtentry int3 do_int3 has_error_code=0 create_gap=1
11471152
idtentry stack_segment do_stack_segment has_error_code=1

arch/x86/include/asm/acrn.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_X86_ACRN_H
3+
#define _ASM_X86_ACRN_H
4+
5+
extern void acrn_hv_callback_vector(void);
6+
#ifdef CONFIG_TRACING
7+
#define trace_acrn_hv_callback_vector acrn_hv_callback_vector
8+
#endif
9+
10+
extern void acrn_hv_vector_handler(struct pt_regs *regs);
11+
#endif /* _ASM_X86_ACRN_H */

arch/x86/kernel/cpu/acrn.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
*
1010
*/
1111

12+
#include <linux/interrupt.h>
13+
#include <asm/acrn.h>
14+
#include <asm/apic.h>
15+
#include <asm/desc.h>
1216
#include <asm/hypervisor.h>
17+
#include <asm/irq_regs.h>
1318

1419
static uint32_t __init acrn_detect(void)
1520
{
@@ -18,6 +23,8 @@ static uint32_t __init acrn_detect(void)
1823

1924
static void __init acrn_init_platform(void)
2025
{
26+
/* Setup the IDT for ACRN hypervisor callback */
27+
alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, acrn_hv_callback_vector);
2128
}
2229

2330
static bool acrn_x2apic_available(void)
@@ -30,6 +37,29 @@ static bool acrn_x2apic_available(void)
3037
return false;
3138
}
3239

40+
static void (*acrn_intr_handler)(void);
41+
42+
__visible void __irq_entry acrn_hv_vector_handler(struct pt_regs *regs)
43+
{
44+
struct pt_regs *old_regs = set_irq_regs(regs);
45+
46+
/*
47+
* The hypervisor requires that the APIC EOI should be acked.
48+
* If the APIC EOI is not acked, the APIC ISR bit for the
49+
* HYPERVISOR_CALLBACK_VECTOR will not be cleared and then it
50+
* will block the interrupt whose vector is lower than
51+
* HYPERVISOR_CALLBACK_VECTOR.
52+
*/
53+
entering_ack_irq();
54+
inc_irq_stat(irq_hv_callback_count);
55+
56+
if (acrn_intr_handler)
57+
acrn_intr_handler();
58+
59+
exiting_irq();
60+
set_irq_regs(old_regs);
61+
}
62+
3363
const __initconst struct hypervisor_x86 x86_hyper_acrn = {
3464
.name = "ACRN",
3565
.detect = acrn_detect,

0 commit comments

Comments
 (0)