Set or clear VI bit in hvc_handler just before returning, using count.
A count of enabled/pending interrupts is kept for this purpose whenever
the enabled and pending bits are updated. This handles the case where the
target vCPU was already running on a different physical CPU when an
interrupt was injected and so it had to be kicked by the primary.
Also add comments explaining what happens in case that the target of an
injected interrupt is already running on a different physical CPU.
Also also, add a test for the case of injecting an interrupt ID which is
not enabled, then enabling it later.
Bug: 117270899
Change-Id: I200f547a5a72332a5e24b5109a3e6e7b66c0b59e
diff --git a/inc/hf/cpu.h b/inc/hf/cpu.h
index b477dec..10bb01f 100644
--- a/inc/hf/cpu.h
+++ b/inc/hf/cpu.h
@@ -52,6 +52,12 @@
uint32_t interrupt_enabled[HF_NUM_INTIDS / INTERRUPT_REGISTER_BITS];
/** Bitfield keeping track of which interrupts are pending. */
uint32_t interrupt_pending[HF_NUM_INTIDS / INTERRUPT_REGISTER_BITS];
+ /**
+ * The number of interrupts which are currently both enabled and
+ * pending. i.e. the number of bits set in interrupt_enable &
+ * interrupt_pending.
+ */
+ uint32_t enabled_and_pending_count;
};
struct retval_state {
diff --git a/inc/vmapi/hf/call.h b/inc/vmapi/hf/call.h
index a7c58a2..a8904b6 100644
--- a/inc/vmapi/hf/call.h
+++ b/inc/vmapi/hf/call.h
@@ -167,8 +167,13 @@
* This doesn't cause the vCPU to actually be run immediately; it will be taken
* when the vCPU is next run, which is up to the scheduler.
*
- * Returns 0 on success, or -1 if the target VM or vCPU doesn't exist or
- * the interrupt ID is invalid.
+ * Returns:
+ * - -1 on failure because the target VM or vCPU doesn't exist, the interrupt
+ * ID is invalid, or the current VM is not allowed to inject interrupts to
+ * the target VM.
+ * - 0 on success if no further action is needed.
+ * - 1 if it was called by the primary VM and the primary VM now needs to wake
+ * up or kick the target vCPU.
*/
static inline int64_t hf_inject_interrupt(uint32_t target_vm_id,
uint32_t target_vcpu_idx,