From patchwork Mon Nov 20 09:17:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 10066187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E793C60375 for ; Mon, 20 Nov 2017 09:17:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF037290A2 for ; Mon, 20 Nov 2017 09:17:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D328129163; Mon, 20 Nov 2017 09:17:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 854EB290A2 for ; Mon, 20 Nov 2017 09:17:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751107AbdKTJRK (ORCPT ); Mon, 20 Nov 2017 04:17:10 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:41621 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751027AbdKTJRI (ORCPT ); Mon, 20 Nov 2017 04:17:08 -0500 Received: by mail-pg0-f66.google.com with SMTP id p9so6885852pgc.8; Mon, 20 Nov 2017 01:17:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wO7go1x0Rr57/21CSfkMQ0Ex6gBq3rjZjBJFGO5ttOI=; b=YwKY4K+sntwXI+0qxAbtkoqGq15IPC6ui49wp4TAyJsDUbOypcotjrhmKu3hzpWeKs G2e0fGyRLSVqyXrtNZFUT7LuyT84P7oADR+kliGQ6vLOzre2Xlz7BAtJJ25ZrGPdMeQU f14aB0qio0o88aTqIw0j5gptg4FxEeyM7Ht33Rr0l4UEiDpglQAZ1u7yxpgojj6c3cHR RSKR+FmQgha4FSRqy0R/yW/J3Ce4z2smHNCZecO/hyfGsT8ysmKR0gUDV6eaORO5dYgw grZE3GWMI7T8WIe2wcZzGLN8+B6+BwjlpW5Al859lruEukGfrgosBqay2QQzjOMP7P+8 /Umg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wO7go1x0Rr57/21CSfkMQ0Ex6gBq3rjZjBJFGO5ttOI=; b=YbEIThYHBKOHHVuV1nK07ffAoxhN23/vJpXSalWZeuPMubJJ1CdJq1zRTJ2u6kr/EF 7wy5slYZIkl9iEQ8LithYTwZWm9E96xLxevkvpd9LK3gFdchTD0LQiySGUYXR0i36gPU jNOik6VHoLkmtO9RBXWghJgzVTihplgsgOxOibMxONNlCMTb05MRBo6pf+9K1kxESMvM /A6eBGkC0L3k3wp/WP1drIucVnQ9L5AQWA3h2h59ZPcPUoqkpZY+KAs0Oc2dkpWYbD8s OjMrr2mFeWActbky0RFnXP1l/51aud4yEll9EqpEV8L+FzYKEUS46WonDfYEp8pki233 P9tA== X-Gm-Message-State: AJaThX6IFYanNuhogD7JPt3Oz0vgG8ubK/5LpxilQ1YBLZnR9EdFvPH4 oJTJ5FXPzClMti5i+ea8+LruLw== X-Google-Smtp-Source: AGs4zMa4EFH5y2xv6NuCdF4YrkdhoWF4n3J083nBxiXAESIQFO5qnXQEykIoEmTLU++6dCC/Z0CtBg== X-Received: by 10.99.98.67 with SMTP id w64mr13129048pgb.213.1511169427844; Mon, 20 Nov 2017 01:17:07 -0800 (PST) Received: from localhost ([203.205.141.123]) by smtp.gmail.com with ESMTPSA id d6sm19082280pfc.29.2017.11.20.01.17.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 01:17:07 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li , Nadav Amit , Dmitry Vyukov Subject: [PATCH] KVM: VMX: Fix rflags cache during vCPU reset Date: Mon, 20 Nov 2017 01:17:03 -0800 Message-Id: <1511169423-15671-1-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li Reported by syzkaller: *** Guest State *** CR0: actual=0x0000000080010031, shadow=0x0000000060000010, gh_mask=fffffffffffffff7 CR4: actual=0x0000000000002061, shadow=0x0000000000000000, gh_mask=ffffffffffffe8f1 CR3 = 0x000000002081e000 RSP = 0x000000000000fffa RIP = 0x0000000000000000 RFLAGS=0x00023000 DR7 = 0x0000000000000002 .......................... ------------[ cut here ]------------ WARNING: CPU: 6 PID: 24431 at /home/kernel/linux/arch/x86/kvm//x86.c:7302 kvm_arch_vcpu_ioctl_run+0x651/0x2ea0 [kvm] CPU: 6 PID: 24431 Comm: reprotest Tainted: G W OE 4.14.0+ #26 RIP: 0010:kvm_arch_vcpu_ioctl_run+0x651/0x2ea0 [kvm] RSP: 0018:ffff880291d179e0 EFLAGS: 00010202 Call Trace: ? synchronize_rcu.part.59+0x9b/0xf0 ? synchronize_rcu_expedited+0xa0/0xa0 ? kfree_call_rcu+0x20/0x20 ? trace_raw_output_rcu_utilization+0x70/0x70 ? kvm_arch_vcpu_runnable+0x220/0x220 [kvm] ? wait_for_completion+0x222/0x2a0 ? __wait_rcu_gp+0x1d3/0x230 ? kvm_vcpu_ioctl+0x479/0x880 [kvm] kvm_vcpu_ioctl+0x479/0x880 [kvm] ? kvm_dev_ioctl+0xba0/0xba0 [kvm] ? pick_next_task_fair+0x629/0xce0 ? sched_clock+0x1b/0x20 ? check_chain_key+0x131/0x1e0 ? lock_acquire+0x2c0/0x2c0 ? check_flags.part.44+0x62/0x250 ? check_chain_key+0x131/0x1e0 ? __lock_acquire+0xd2e/0x1cb0 do_vfs_ioctl+0x142/0x9a0 ? ioctl_preallocate+0x150/0x150 ? lock_acquire+0x2c0/0x2c0 ? lock_acquire+0x118/0x2c0 ? __lock_is_held+0x4b/0xe0 ? __fget+0x16a/0x250 SyS_ioctl+0x74/0x80 entry_SYSCALL_64_fastpath+0x23/0x9a The syzkaller testcase tries to setup the processor specific debug registers and configure vCPU for handling guest debug events through KVM_SET_GUEST_DEBUG. The KVM_SET_GUEST_DEBUG ioctl will get and set rflags in order to set TF bit if single step is needed. All regs' caches are reset to avail and GUEST_RFLAGS vmcs field is reset to 0x2 during vCPU reset. However, the cache of rflags is not reset during vCPU reset. The function vmx_get_rflags() returns an unreset rflags cache value since the cache is marked avail, it is 0 after boot. Vmentry fails if the rflags reserved bit 1 is 0. This patch fixes it by resetting both the GUEST_RFLAGS vmcs field and its cache to 0x2 during vCPU reset. Reported-by: Dmitry Vyukov Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Nadav Amit Cc: Dmitry Vyukov Signed-off-by: Wanpeng Li Reviewed-by: David Hildenbrand --- arch/x86/kvm/vmx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index b348920..131fa1c 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -5590,6 +5590,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) vmcs_write64(GUEST_IA32_DEBUGCTL, 0); } + vmx->rflags = 0x02; vmcs_writel(GUEST_RFLAGS, 0x02); kvm_rip_write(vcpu, 0xfff0);