From: Jan Kiszka <[email protected]>

If setup code triggers any event that is to be handled on all CPUs, this
should be processed right before VMM activation. Adding this will
consume the superfluous and to-be-removed flush_vcpu_caches. More
importantly, it will enable handling of update_cat properly on Intel
x86. As there might be more cases in the future, install this pattern
for all archs right from the beginning.

Signed-off-by: Jan Kiszka <[email protected]>
---
 hypervisor/arch/arm-common/control.c      | 7 ++++---
 hypervisor/arch/x86/control.c             | 6 +++---
 hypervisor/arch/x86/include/asm/control.h | 4 +---
 hypervisor/arch/x86/svm.c                 | 6 +++---
 hypervisor/arch/x86/vmx.c                 | 4 ++--
 hypervisor/include/jailhouse/control.h    | 7 ++++++-
 hypervisor/setup.c                        | 5 ++++-
 7 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/hypervisor/arch/arm-common/control.c 
b/hypervisor/arch/arm-common/control.c
index 9fc42761..400490ae 100644
--- a/hypervisor/arch/arm-common/control.c
+++ b/hypervisor/arch/arm-common/control.c
@@ -2,7 +2,7 @@
  * Jailhouse, a Linux-based partitioning hypervisor
  *
  * Copyright (c) ARM Limited, 2014
- * Copyright (c) Siemens AG, 2016
+ * Copyright (c) Siemens AG, 2016-2022
  *
  * Authors:
  *  Jean-Philippe Brucker <[email protected]>
@@ -62,8 +62,9 @@ void arch_park_cpu(unsigned int cpu_id)
        resume_cpu(cpu_id);
 }
 
-static void check_events(struct public_per_cpu *cpu_public)
+void arch_check_events(void)
 {
+       struct public_per_cpu *cpu_public = this_cpu_public();
        bool reset = false;
 
        spin_lock(&cpu_public->control_lock);
@@ -125,7 +126,7 @@ void arch_handle_sgi(u32 irqn, unsigned int count_event)
        case SGI_EVENT:
                cpu_public->stats[JAILHOUSE_CPU_STAT_VMEXITS_MANAGEMENT] +=
                        count_event;
-               check_events(cpu_public);
+               arch_check_events();
                break;
        default:
                printk("WARN: unknown SGI received %d\n", irqn);
diff --git a/hypervisor/arch/x86/control.c b/hypervisor/arch/x86/control.c
index 2bc47a6a..b46347cc 100644
--- a/hypervisor/arch/x86/control.c
+++ b/hypervisor/arch/x86/control.c
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013
+ * Copyright (c) Siemens AG, 2013-2022
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
@@ -160,7 +160,7 @@ void x86_send_init_sipi(unsigned int cpu_id, enum 
x86_init_sipi type,
         */
        if (type == X86_INIT) {
                while (target_data->init_signaled) {
-                       x86_check_events();
+                       arch_check_events();
                        cpu_relax();
                }
        }
@@ -177,7 +177,7 @@ void __attribute__((weak)) cat_update(void)
 {
 }
 
-void x86_check_events(void)
+void arch_check_events(void)
 {
        struct public_per_cpu *cpu_public = this_cpu_public();
        int sipi_vector = -1;
diff --git a/hypervisor/arch/x86/include/asm/control.h 
b/hypervisor/arch/x86/include/asm/control.h
index 2566e115..7b15de35 100644
--- a/hypervisor/arch/x86/include/asm/control.h
+++ b/hypervisor/arch/x86/include/asm/control.h
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2014
+ * Copyright (c) Siemens AG, 2014-2022
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
@@ -19,7 +19,5 @@ enum x86_init_sipi { X86_INIT, X86_SIPI };
 void x86_send_init_sipi(unsigned int cpu_id, enum x86_init_sipi type,
                        int sipi_vector);
 
-void x86_check_events(void);
-
 void __attribute__((noreturn))
 x86_exception_handler(struct exception_frame *frame);
diff --git a/hypervisor/arch/x86/svm.c b/hypervisor/arch/x86/svm.c
index 9b1664a5..1193bd25 100644
--- a/hypervisor/arch/x86/svm.c
+++ b/hypervisor/arch/x86/svm.c
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013
+ * Copyright (c) Siemens AG, 2013-2022
  * Copyright (c) Valentine Sinitsyn, 2014
  *
  * Authors:
@@ -893,7 +893,7 @@ void vcpu_handle_exit(struct per_cpu *cpu_data)
                cpu_public->stats[JAILHOUSE_CPU_STAT_VMEXITS_MANAGEMENT]++;
                /* Temporarily enable GIF to consume pending NMI */
                asm volatile("stgi; clgi" : : : "memory");
-               x86_check_events();
+               arch_check_events();
                goto vmentry;
        case VMEXIT_VMMCALL:
                vcpu_handle_hypercall();
@@ -944,7 +944,7 @@ void vcpu_handle_exit(struct per_cpu *cpu_data)
                        vmcb->eventinj |= SVM_EVENTINJ_ERR_VALID;
                        vmcb->eventinj_err = vmcb->exitinfo1;
                }
-               x86_check_events();
+               arch_check_events();
                goto vmentry;
        /* TODO: Handle VMEXIT_AVIC_NOACCEL and VMEXIT_AVIC_INCOMPLETE_IPI */
        default:
diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c
index 5a69710d..03dfc69a 100644
--- a/hypervisor/arch/x86/vmx.c
+++ b/hypervisor/arch/x86/vmx.c
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013-2016
+ * Copyright (c) Siemens AG, 2013-2022
  * Copyright (c) Valentine Sinitsyn, 2014
  *
  * Authors:
@@ -918,7 +918,7 @@ void vcpu_skip_emulated_instruction(unsigned int inst_len)
 static void vmx_check_events(void)
 {
        vmx_preemption_timer_set_enable(false);
-       x86_check_events();
+       arch_check_events();
 }
 
 static void vmx_handle_exception_nmi(void)
diff --git a/hypervisor/include/jailhouse/control.h 
b/hypervisor/include/jailhouse/control.h
index f2b07c0d..e0c21270 100644
--- a/hypervisor/include/jailhouse/control.h
+++ b/hypervisor/include/jailhouse/control.h
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013
+ * Copyright (c) Siemens AG, 2013-2022
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
@@ -190,6 +190,11 @@ void arch_park_cpu(unsigned int cpu_id);
  */
 void arch_send_event(struct public_per_cpu *target_data);
 
+/**
+ * Check and process any internal events pending for the current CPU.
+ */
+void arch_check_events(void);
+
 /**
  * Performs the architecture-specific steps for mapping a memory region into a
  * cell's address space.
diff --git a/hypervisor/setup.c b/hypervisor/setup.c
index f0ee0896..e4e7fe1f 100644
--- a/hypervisor/setup.c
+++ b/hypervisor/setup.c
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013-2017
+ * Copyright (c) Siemens AG, 2013-2022
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
@@ -261,6 +261,9 @@ int entry(unsigned int cpu_id, struct per_cpu *cpu_data)
                return error;
        }
 
+       /* Process any internal events generated during setup. */
+       arch_check_events();
+
        if (master)
                printk("Activating hypervisor\n");
 
-- 
2.36.1

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20220627131329.3659-2-ralf.ramsauer%40oth-regensburg.de.

Reply via email to