KVM: VMX: avoid double list add with VT-d posted interrupts
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 6 Jun 2017 10:57:05 +0000 (12:57 +0200)
committerRaspbian kernel package updater <root@raspbian.org>
Sun, 8 Oct 2017 01:09:38 +0000 (01:09 +0000)
commitf0f88ac43d4ee475c13dbc75d6e15223425c67d7
treec8eb02ec198d455a65443b41c13a6048a1a6b24f
parente54b40775fce54f71d9cb16bd1c5d156354711e2
KVM: VMX: avoid double list add with VT-d posted interrupts

commit 8b306e2f3c41939ea528e6174c88cfbfff893ce1 upstream.

In some cases, for example involving hot-unplug of assigned
devices, pi_post_block can forget to remove the vCPU from the
blocked_vcpu_list.  When this happens, the next call to
pi_pre_block corrupts the list.

Fix this in two ways.  First, check vcpu->pre_pcpu in pi_pre_block
and WARN instead of adding the element twice in the list.  Second,
always do the list removal in pi_post_block if vcpu->pre_pcpu is
set (not -1).

The new code keeps interrupts disabled for the whole duration of
pi_pre_block/pi_post_block.  This is not strictly necessary, but
easier to follow.  For the same reason, PI.ON is checked only
after the cmpxchg, and to handle it we just call the post-block
code.  This removes duplication of the list removal code.

Cc: Huangweidong <weidong.huang@huawei.com>
Cc: Gonglei <arei.gonglei@huawei.com>
Cc: wangxin <wangxinxin.wang@huawei.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Tested-by: Longpeng (Mike) <longpeng2@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/vmx.c