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 {