[PATCH 2/4] HV: Introduce new API exec_smp_call


Kaige Fu
 

This patch introduces a new exec_smp_call to execute the smp call
funtion on target CPUs. Currently, it is only called by kick_notification.
And we will call it in NMI notification function in coming patch.

Signed-off-by: Kaige Fu <kaige.fu@...>
---
hypervisor/arch/x86/notify.c | 25 ++++++++++++++++---------
hypervisor/include/arch/x86/irq.h | 1 +
2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/hypervisor/arch/x86/notify.c b/hypervisor/arch/x86/notify.c
index e5cb2000..d67fdabd 100644
--- a/hypervisor/arch/x86/notify.c
+++ b/hypervisor/arch/x86/notify.c
@@ -18,25 +18,32 @@ static uint32_t notification_irq = IRQ_INVALID;

static uint64_t smp_call_mask = 0UL;

-/* run in interrupt context */
-static void kick_notification(__unused uint32_t irq, __unused void *data)
+/**
+ * @brief Execute smp call function on this running physical cpu.
+ */
+void exec_smp_call(void)
{
- /* Notification vector is used to kick taget cpu out of non-root mode.
- * And it also serves for smp call.
- */
+
uint16_t pcpu_id = get_pcpu_id();

- if (bitmap_test(pcpu_id, &smp_call_mask)) {
- struct smp_call_info_data *smp_call =
- &per_cpu(smp_call_info, pcpu_id);
+ if (bitmap_test_and_clear_lock(pcpu_id, &smp_call_mask)) {
+ struct smp_call_info_data *smp_call = &per_cpu(smp_call_info, pcpu_id);

if (smp_call->func != NULL) {
smp_call->func(smp_call->data);
}
- bitmap_clear_lock(pcpu_id, &smp_call_mask);
}
}

+/* run in interrupt context */
+static void kick_notification(__unused uint32_t irq, __unused void *data)
+{
+ /* Notification vector is used to kick taget cpu out of non-root mode.
+ * And it also serves for smp call.
+ */
+ exec_smp_call();
+}
+
static void notify_cpus(uint64_t mask)
{
uint16_t pcpu_id = ffs64(mask);
diff --git a/hypervisor/include/arch/x86/irq.h b/hypervisor/include/arch/x86/irq.h
index 2c96e11e..7ecbe171 100644
--- a/hypervisor/include/arch/x86/irq.h
+++ b/hypervisor/include/arch/x86/irq.h
@@ -88,6 +88,7 @@ struct smp_call_info_data {
};

void smp_call_function(uint64_t mask, smp_call_func_t func, void *data);
+void exec_smp_call(void);
bool is_notification_nmi(const struct acrn_vm *vm);

void init_default_irqs(uint16_t cpu_id);
--
2.20.0

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.