acrn-hypervisor/hypervisor
Yifan Liu d575edf79a hv: Change sched_event structure to resolve data race in event handling
Currently the sched event handling may encounter data race problem, and
as a result some vcpus might be stalled forever.

One example can be wbinvd handling where more than 1 vcpus are doing
wbinvd concurrently. The following is a possible execution of 3 vcpus:
-------
0                            1                           2
                             req [Note: 0]
                             req bit0 set [Note: 1]
                             IPI -> 0
                             req bit2 set
                             IPI -> 2
                                                         VMExit
                                                         req bit2 cleared
                                                         wait
                                                         vcpu2 descheduled

VMExit
req bit0 cleared
wait
vcpu0 descheduled
                             signal 0
                             event0->set=true
                             wake 0

                             signal 2
                             event2->set=true [Note: 3]
                             wake 2
                                                         vcpu2 scheduled
                                                         event2->set=false
                                                         resume

                                                         req
                                                         req bit0 set
                                                         IPI -> 0
                                                         req bit1 set
                                                         IPI -> 1
                             (doesn't matter)
vcpu0 scheduled [Note: 4]
                                                         signal 0
                                                         event0->set=true
                                                         (no wake) [Note: 2]
event0->set=false                                        (the rest doesn't matter)
resume

Any VMExit
req bit0 cleared
wait
idle running

(blocked forever)

Notes:
0: req: vcpu_make_request(vcpu, ACRN_REQUEST_WAIT_WBINVD).
1: req bit: Bit in pending_req_bits. Bit0 stands for bit for vcpu0.
2: In function signal_event, At this time the event->waiting_thread
    is not NULL, so wake_thread will not execute
3: eventX: struct sched_event of vcpuX.
4: In function wait_event, the lock does not strictly cover the execution between
    schedule() and event->set=false, so other threads may kick in.
-----

As shown in above example, before the last random VMExit, vcpu0 ended up
with request bit set but event->set==false, so blocked forever.

This patch proposes to change event->set from a boolean variable to an
integer. The semantic is very similar to a semaphore. The wait_event
will add 1 to this value, and block when this value is > 0, whereas signal_event
will decrease this value by 1.

It may happen that this value was decreased to a negative number but that
is OK. As long as the wait_event and signal_event are paired and
program order is observed (that is, wait_event always happens-before signal_event
on a single vcpu), this value will eventually be 0.

Tracked-On: #6405
Signed-off-by: Yifan Liu <yifan1.liu@intel.com>
2021-08-20 08:11:40 +08:00
..
acpi_parser hv: dm: Use new power management data structures 2021-07-15 11:53:54 +08:00
arch/x86 HV: Combine the acpi loading fucntion to one place 2021-08-19 20:00:45 +08:00
boot HV: Add implements of 32bit and 64bit elf loader 2021-08-19 20:00:45 +08:00
bsp/ld HV: add a specific stack space used in CPU booting 2020-04-29 13:56:40 +08:00
common hv: Change sched_event structure to resolve data race in event handling 2021-08-20 08:11:40 +08:00
debug HV: debug: support 64bit BAR pci uart with 32bit space 2021-08-04 10:10:35 +08:00
dm hv: mmiodev: a minor bug fix about refine acrn_mmiodev data structure 2021-08-19 12:01:35 +08:00
hw hv: ensure PTM root is always enabled in hw 2021-05-27 09:00:50 +08:00
include hv: Change sched_event structure to resolve data race in event handling 2021-08-20 08:11:40 +08:00
lib HV: replace merge_cmdline api with strncat_s 2020-06-08 13:30:04 +08:00
quirks hv: tpm2: do tpm2 fixup for security vm 2021-08-11 14:45:55 +08:00
release hv: debug: Add hv console callback to VM-exit event 2021-07-22 10:08:23 +08:00
scripts config_tools: remove obsolete kconfig files 2021-08-09 09:25:02 +08:00
MAINTAINERS update home page information 2018-05-15 17:19:39 +08:00
Makefile HV: Add elf loader sketch 2021-08-19 20:00:45 +08:00
README.rst doc: fix utf-8 punctuation, branding, spelling 2019-03-14 09:13:58 -07:00

ACRN Hypervisor
###############

The open source `Project ACRN`_ defines a device hypervisor reference stack and
an architecture for running multiple software subsystems, managed securely, on
a consolidated system by means of a virtual machine manager. It also defines a
reference framework implementation for virtual device emulation, called the
"ACRN Device Model".

The ACRN Hypervisor is a Type 1 reference hypervisor stack, running directly on
the bare-metal hardware, and is suitable for a variety of IoT and embedded
device solutions. The ACRN hypervisor addresses the gap that currently exists
between datacenter hypervisors, and hard partitioning hypervisors. The ACRN
hypervisor architecture partitions the system into different functional
domains, with carefully selected guest OS sharing optimizations for IoT and
embedded devices.

You can find out more about Project ACRN on the `Project ACRN documentation`_
website.

.. _`Project ACRN`: https://projectacrn.org
.. _`ACRN Hypervisor`: https://github.com/projectacrn/acrn-hypervisor
.. _`Project ACRN documentation`: https://projectacrn.github.io/