um: time-travel: rework interrupt handling in ext mode
authorJohannes Berg <johannes.berg@intel.com>
Tue, 15 Dec 2020 09:52:24 +0000 (10:52 +0100)
committerRichard Weinberger <richard@nod.at>
Fri, 12 Feb 2021 20:24:27 +0000 (21:24 +0100)
commitc8177aba37cac6b6dd0e5511fde9fc2d9e7f2f38
tree0918ea45e4ccfb6dfded0ec20264450cf23de1a4
parent9b84512cfe601759f66ee594b2d5aa07788251ea
um: time-travel: rework interrupt handling in ext mode

In external time-travel mode, where time is controlled via the
controller application socket, interrupt handling is a little
tricky. For example on virtio, the following happens:
 * we receive a message (that requires an ACK) on the vhost-user socket
 * we add a time-travel event to handle the interrupt
   (this causes communication on the time socket)
 * we ACK the original vhost-user message
 * we then handle the interrupt once the event is triggered

This protocol ensures that the sender of the interrupt only continues
to run in the simulation when the time-travel event has been added.

So far, this was only done in the virtio driver, but it was actually
wrong, because only virtqueue interrupts were handled this way, and
config change interrupts were handled immediately. Additionally, the
messages were actually handled in the real Linux interrupt handler,
but Linux interrupt handlers are part of the simulation and shouldn't
run while there's no time event.

To really do this properly and only handle all kinds of interrupts in
the time-travel event when we are scheduled to run in the simulation,
rework this to plug in to the lower interrupt layers in UML directly:

Add a um_request_irq_tt() function that let's a time-travel aware
driver request an interrupt with an additional timetravel_handler()
that is called outside of the context of the simulation, to handle
the message only. It then adds an event to the time-travel calendar
if necessary, and no "real" Linux code runs outside of the time
simulation.

This also hooks in with suspend/resume properly now, since this new
timetravel_handler() can run while Linux is suspended and interrupts
are disabled, and decide to wake up (or not) the system based on the
message it received. Importantly in this case, it ACKs the message
before the system even resumes and interrupts are re-enabled, thus
allowing the simulation to progress properly.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
arch/um/drivers/virtio_uml.c
arch/um/include/linux/time-internal.h
arch/um/include/shared/irq_kern.h
arch/um/kernel/irq.c
arch/um/kernel/time.c