acrn-hypervisor/hypervisor/common/softirq.c
Yifan Liu 5c9456462b hv && config-tool: Add compilation option to disable all interrupts in HV
This patch adds an option CONFIG_KEEP_IRQ_DISABLED to hv (default n) and
config-tool so that when this option is 'y', all interrupts in hv root
mode will be permanently disabled.

With this option to be 'y', all interrupts received in root mode will be
handled in external interrupt vmexit after next VM entry. The postpone
latency is negligible. This new configuration is a requirement from x86
TEE's secure/non-secure interrupt flow support. Many race conditions can be
avoided when keeping IRQ off.

v5:
Rename CONFIG_ACRN_KEEP_IRQ_DISABLED to CONFIG_KEEP_IRQ_DISABLED

v4:
Change CPU_IRQ_ENABLE/DISABLE to
CPU_IRQ_ENABLE_ON_CONFIG/DISABLE_ON_CONFIG and guard them using
CONFIG_ACRN_KEEP_IRQ_DISABLED

v3:
CONFIG_ACRN_DISABLE_INTERRUPT -> CONFIG_ACRN_KEEP_IRQ_DISABLED
Add more comment in commit message

Tracked-On: #6571
Signed-off-by: Yifan Liu <yifan1.liu@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2021-12-10 09:50:17 +08:00

66 lines
1.3 KiB
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <types.h>
#include <asm/lib/bits.h>
#include <asm/cpu.h>
#include <asm/per_cpu.h>
#include <softirq.h>
static softirq_handler softirq_handlers[NR_SOFTIRQS];
void init_softirq(void)
{
}
/*
* @pre: nr will not equal or large than NR_SOFTIRQS
*/
void register_softirq(uint16_t nr, softirq_handler handler)
{
softirq_handlers[nr] = handler;
}
/*
* @pre: nr will not equal or large than NR_SOFTIRQS
*/
void fire_softirq(uint16_t nr)
{
bitmap_set_lock(nr, &per_cpu(softirq_pending, get_pcpu_id()));
}
static void do_softirq_internal(uint16_t cpu_id)
{
volatile uint64_t *softirq_pending_bitmap =
&per_cpu(softirq_pending, cpu_id);
uint16_t nr = ffs64(*softirq_pending_bitmap);
while (nr < NR_SOFTIRQS) {
bitmap_clear_lock(nr, softirq_pending_bitmap);
(*softirq_handlers[nr])(cpu_id);
nr = ffs64(*softirq_pending_bitmap);
}
}
/*
* @pre: this function will only be called with irq disabled
*/
void do_softirq(void)
{
uint16_t cpu_id = get_pcpu_id();
if (per_cpu(softirq_servicing, cpu_id) == 0U) {
per_cpu(softirq_servicing, cpu_id) = 1U;
CPU_IRQ_ENABLE_ON_CONFIG();
do_softirq_internal(cpu_id);
CPU_IRQ_DISABLE_ON_CONFIG();
do_softirq_internal(cpu_id);
per_cpu(softirq_servicing, cpu_id) = 0U;
}
}