qemu-e2k/target
Colin Xu 6f38dca615 hax: Honor CPUState::halted
QEMU tracks whether a vcpu is halted using CPUState::halted. E.g.,
after initialization or reset, halted is 0 for the BSP (vcpu 0)
and 1 for the APs (vcpu 1, 2, ...). A halted vcpu should not be
handed to the hypervisor to run (e.g. hax_vcpu_run()).

Under HAXM, Android Emulator sometimes boots into a "vcpu shutdown
request" error while executing in SeaBIOS, with the HAXM driver
logging a guest triple fault in vcpu 1, 2, ... at RIP 0x3. That is
ultimately because the HAX accelerator asks HAXM to run those APs
when they are still in the halted state.

Normally, the vcpu thread for an AP will start by looping in
qemu_wait_io_event(), until the BSP kicks it via a pair of IPIs
(INIT followed by SIPI). But because the HAX accelerator does not
honor cpu->halted, it allows the AP vcpu thread to proceed to
hax_vcpu_run() as soon as it receives any kick, even if the kick
does not come from the BSP. It turns out that emulator has a
worker thread which periodically kicks every vcpu thread (possibly
to collect CPU usage data), and if one of these kicks comes before
those by the BSP, the AP will start execution from the wrong RIP,
resulting in the aforementioned SMP boot failure.

The solution is inspired by the KVM accelerator (credit to
Chuanxiao Dong <chuanxiao.dong@intel.com> for the pointer):

1. Get rid of questionable logic that unconditionally resets
   cpu->halted before hax_vcpu_run(). Instead, only reset it at the
   right moments (there are only a few "unhalt" events).
2. Add a check for cpu->halted before hax_vcpu_run().

Note that although the non-Unrestricted Guest (!ug_platform) code
path also forcibly resets cpu->halted, it is left untouched,
because only the UG code path supports SMP guests.

The patch is first merged to android emulator with Change-Id:
I9c5752cc737fd305d7eace1768ea12a07309d716

Cc: Yu Ning <yu.ning@intel.com>
Cc: Chuanxiao Dong <chuanxiao.dong@intel.com>
Signed-off-by: Colin Xu <colin.xu@intel.com>
Message-Id: <20190610021939.13669-1-colin.xu@intel.com>
2019-06-21 02:29:38 +02:00
..
alpha Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
arm target/arm: Check for dp support for dp VFM, not sp 2019-06-18 14:41:29 +01:00
cris Supply missing header guards 2019-06-12 13:20:21 +02:00
hppa Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
i386 hax: Honor CPUState::halted 2019-06-21 02:29:38 +02:00
lm32 Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
m68k Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
microblaze Supply missing header guards 2019-06-12 13:20:21 +02:00
mips Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
moxie Supply missing header guards 2019-06-12 13:20:21 +02:00
nios2 Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
openrisc Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
ppc ppc patch queue 2019-06-12 2019-06-12 14:43:47 +01:00
riscv Supply missing header guards 2019-06-12 13:20:21 +02:00
s390x Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
sh4 Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
sparc Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
tilegx Normalize position of header guard 2019-06-12 13:20:20 +02:00
tricore Supply missing header guards 2019-06-12 13:20:21 +02:00
unicore32 Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
xtensa Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00