From patchwork Wed Sep 9 02:57:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11764823 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63AD4618 for ; Wed, 9 Sep 2020 02:57:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 419CC21973 for ; Wed, 9 Sep 2020 02:57:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DIqZrTRZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728911AbgIIC5a (ORCPT ); Tue, 8 Sep 2020 22:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726642AbgIIC53 (ORCPT ); Tue, 8 Sep 2020 22:57:29 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3389C061573; Tue, 8 Sep 2020 19:57:28 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id o20so841936pfp.11; Tue, 08 Sep 2020 19:57:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=vXOzzvFu8SFrA4CAW0a5T7SuJva0VHxNKr87gI4K2Fc=; b=DIqZrTRZTRJ1OQx/gOPEn4+bM4FE3kN3Pg7Y1cIbESXDVl3/dT6jxYK0HBucFeO7OH 9PSAaZa8eQSzRVcIL5+Ti9OGTR5SPfbeEbFL2y64trz9pbdzgrKLarv7T2yVUfzPIQtm Oe5WA+z6Fzt/n3M3l+rqemMeFMcbeP+rpqKIsRUXxu9QZDj2UMYDWG8k4uRGEzEJU8Xv YwvqLqFh/gNUVkflSITbzA2H17NXytY7SP/0IA8+G7gvpkB0eDY3bOHA+b8Dhpdfb86M vH/1th6Vo61XWN543f7kXUFP0yIhCdGka9tASpxUWYyHZLEstsfkR1DhwqHGzsrlUWqn 3xMw== 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; bh=vXOzzvFu8SFrA4CAW0a5T7SuJva0VHxNKr87gI4K2Fc=; b=heVHNII4dqZFJ1m4XFt3iW0qK7iXw/XLmHTRoOfcPmSXQ4/+o/zt45OlPoq+tGsEnk 1ZZkBBwsVBayiYmyW+De3K0QfmI0Fmd8rE/21CNNcb8OZvobWshRZTzV0NOh+Qi8ZJpe xwmisH3NJYpgHYxlpc2sUAOtb4vjTY7v9T24rafK2CK6cEoaUAZYNj5bpT8x1MGStOng amcJamK8Qb6rDE66zVnDKsQVIkj4Oh6xPmWW7KIAu7+L2arYVvJrjdmUjKZkzaELvGCj 49grEGXSWEn5he/0nwlW8y6VKu6/yOhmawzJ2csgbJi1F3/97cr/Z58B8gd0+nlgOWvf qcHQ== X-Gm-Message-State: AOAM532nzteqJryRFhiCcleu5c10/6vFI6dm3sX4taKDHa33GbS18GOo IYp/81PqTGnvY/hfxMBbQ8oy/21hlsA= X-Google-Smtp-Source: ABdhPJzGpaGuJQnM7F8oIR4SzaXXvnjaLCqKupxziP9tdtgxwwwc5Vq+NYKCHC3fSRB3Ihot2TIN9w== X-Received: by 2002:a63:c64c:: with SMTP id x12mr1341486pgg.433.1599620247986; Tue, 08 Sep 2020 19:57:27 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id l9sm556063pgg.29.2020.09.08.19.57.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Sep 2020 19:57:27 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "Paul K ." , "# v5 . 8-rc1+" Subject: [PATCH RESEND 1/3] KVM: SVM: Get rid of handle_fastpath_set_msr_irqoff() Date: Wed, 9 Sep 2020 10:57:15 +0800 Message-Id: <1599620237-13156-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Wanpeng Li Analysis from Sean: | svm->next_rip is reset in svm_vcpu_run() only after calling | svm_exit_handlers_fastpath(), which will cause SVM's | skip_emulated_instruction() to write a stale RIP. Let's get rid of handle_fastpath_set_msr_irqoff() in svm_exit_handlers_fastpath() to have a quick fix. Reported-by: Paul K. Suggested-by: Sean Christopherson Cc: Paul K. Cc: # v5.8-rc1+ Fixes: 404d5d7bff0d (KVM: X86: Introduce more exit_fastpath_completion enum values) Signed-off-by: Wanpeng Li --- arch/x86/kvm/svm/svm.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 19e622a..c61bc3b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3349,11 +3349,6 @@ static void svm_cancel_injection(struct kvm_vcpu *vcpu) static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu) { - if (!is_guest_mode(vcpu) && - to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR && - to_svm(vcpu)->vmcb->control.exit_info_1) - return handle_fastpath_set_msr_irqoff(vcpu); - return EXIT_FASTPATH_NONE; } From patchwork Wed Sep 9 02:57:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11764827 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF10D618 for ; Wed, 9 Sep 2020 02:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1A2820EDD for ; Wed, 9 Sep 2020 02:57:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u1A3ot8K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729935AbgIIC5n (ORCPT ); Tue, 8 Sep 2020 22:57:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726801AbgIIC5g (ORCPT ); Tue, 8 Sep 2020 22:57:36 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 099BEC061573; Tue, 8 Sep 2020 19:57:34 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id x123so855512pfc.7; Tue, 08 Sep 2020 19:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6Ci4JG02FAd7t2hb7z9AKMELCxudpUg5ze3327gd91Y=; b=u1A3ot8Ky7B2j9GgvIOk9jfuL8tdo9WyRMr8t9ugobDiQR196NOocxCyUE2qeLsy9f eA85NvUbNVXPTTJlbQtJg2ytBP2SLANU7Jjm/kGwmiidjSbb2Pb/U7JMA6+963A52BwE 4hhEh/MevUxjxgKqTCGD2QiMvTj2cVEN6aopW84VuV3moCDJWH0C8aieeiFIc5UXx01Q XcCWUrNjkeTxdIEA8/GW0Vq3bT9FF6GGBNMZI79UxT6gI6V7Dd8CNv29hR98eoWv4/Wx TnzntkA6kH4v+3VW21eqo4otD7ZnuYBYYu7Gz2e+vTwxGSGYTLjlWFvCHaEgCvjGMvYS jcGw== 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:in-reply-to :references; bh=6Ci4JG02FAd7t2hb7z9AKMELCxudpUg5ze3327gd91Y=; b=L3GgezGOC3cLPBsGETRKL/RSfkSmFP7ZdvJzGcU/Rv1UiR8LCEUPatdbuuQC59XqjU HoTz1GIIsBxLpeSeAb+7PklU+S2cqEt50iip3xuSv8Ip54CiV9YAMhcCQWBgUCaRewE+ Byluwu4N3skYWoAfV64/8/0bFAYACQnmVwq5UICZi/64oL4N+mauJ+eWiMk9E59GmEQ1 8DJGJTQ8uFHHNWemagEdWgnbmDGa78tT7XHp7W0Q8sXgGaEAz5jT7I/xsApOeMi1AmX4 JYPi0DL4rphbI2yOOVT8TRA33pkTllmIsTF2Qlnfyl1gDT6J7w3E31kpBHnNRkmzmSCt WT2Q== X-Gm-Message-State: AOAM532Pt+gG8FmGkUgCSS48dTicbLRKUPw4P0dCy43fq8JI/VYxh2Lp EccAsQC2Z23NXMBsM2fyJe6DD3cviLI= X-Google-Smtp-Source: ABdhPJy9r3B86GKGUKXdY2u00hxgmHa5G1Fs6cZ1Avi+W/4ehJwNJ6YKLerD4CUUGZKUidURW1i6zg== X-Received: by 2002:a65:6707:: with SMTP id u7mr1295575pgf.449.1599620250966; Tue, 08 Sep 2020 19:57:30 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id l9sm556063pgg.29.2020.09.08.19.57.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Sep 2020 19:57:30 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "Paul K ." Subject: [PATCH RESEND 2/3] KVM: SVM: Move svm_complete_interrupts() into svm_vcpu_run() Date: Wed, 9 Sep 2020 10:57:16 +0800 Message-Id: <1599620237-13156-2-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599620237-13156-1-git-send-email-wanpengli@tencent.com> References: <1599620237-13156-1-git-send-email-wanpengli@tencent.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Wanpeng Li Moving svm_complete_interrupts() into svm_vcpu_run() which can align VMX and SVM with respect to completing interrupts. Suggested-by: Sean Christopherson Cc: Paul K. Signed-off-by: Wanpeng Li --- arch/x86/kvm/svm/svm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index c61bc3b..74bcf0a 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2938,8 +2938,6 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) if (npt_enabled) vcpu->arch.cr3 = svm->vmcb->save.cr3; - svm_complete_interrupts(svm); - if (is_guest_mode(vcpu)) { int vmexit; @@ -3530,6 +3528,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) SVM_EXIT_EXCP_BASE + MC_VECTOR)) svm_handle_mce(svm); + svm_complete_interrupts(svm); + vmcb_mark_all_clean(svm->vmcb); return exit_fastpath; } From patchwork Wed Sep 9 02:57:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11764825 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87E6B618 for ; Wed, 9 Sep 2020 02:57:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6032E216C4 for ; Wed, 9 Sep 2020 02:57:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P63Oird4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729691AbgIIC5m (ORCPT ); Tue, 8 Sep 2020 22:57:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726642AbgIIC5f (ORCPT ); Tue, 8 Sep 2020 22:57:35 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13759C061755; Tue, 8 Sep 2020 19:57:34 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id c196so999109pfc.0; Tue, 08 Sep 2020 19:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ohIW29ciAv1DCA5L2Ue/toPc76GmU7pThdqKIDSGsEE=; b=P63Oird4WMQWLoVFobqNtzk1rmw4TgJHg0uGLtgFbJTyK1YxZYSUCxbfU3vq2roVpj S5C+RUhCGyXyNOLIks8FKd20hF3No3hycjNtGO/VMy4Xcx88a0Z+wwT/1V/E49JLWWF3 MoWPz8SMeDWPEP/y+K0Xh+yK+CHv2vCAO8ddyz8+SVbEbaey2Q7+l49CkLmEUakMa7TW d97zzQCLOj+1nEhnoPRVlZv2NeicHZU5WUD8fWc/JoD3x+7JnuhkWWLrZEYdkhQqS+/a +VEkWaCinNMWeie5rIbkEE1GyrMUpzH0iyO5J9KyR/DHWEDWci/VfVlzehidR5SyhdAU PwLw== 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:in-reply-to :references; bh=ohIW29ciAv1DCA5L2Ue/toPc76GmU7pThdqKIDSGsEE=; b=WkOlxHsAAWLB+rnxpBOV2ZGNpb9DIw4fYTkHT6jbh3rBjSmeMB+gwGvVwMB2TLknBw ctzf6Io2B6osK556BVdcdvysxUd/saBEsm8JDaea1dv60ZkKYgMLIAPa/B5tYQaLC6mM KkljsfdDpQErIUINIXgu69aB1EK+rU+6XxGfDjgxkMJnc6ZQyyHY7XpWmMjlm9dRxNEE Vh4HvjX0nMq6JMXtIShi7aVZ8btwaJ+P8ltL64GHeWV+KVFcYOakv/aMnqWm0R9X6+qf d6CyiNdqUNzOVND2Dh9EOXhh/oxJ8OUtRROpXogF/6TgoKdA0U2kjyDjIWwljnlAawaS NuZg== X-Gm-Message-State: AOAM533leCxJH0yQv6WqDW0VaYGigBJUdb6dNwBhhG09atH9HnrP2nTF XBQM8Y/faeZfJkuSdUoJgpPv4uFWOhQ= X-Google-Smtp-Source: ABdhPJyhb4qzJRiur9+RdUfsh5WETGYJrYPj2iB9nPZkNoX+uAzV8FYI7+LV/UIn8hboPOmLRTeAGg== X-Received: by 2002:a63:5b4c:: with SMTP id l12mr1284500pgm.243.1599620253902; Tue, 08 Sep 2020 19:57:33 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id l9sm556063pgg.29.2020.09.08.19.57.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Sep 2020 19:57:33 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "Paul K ." Subject: [PATCH RESEND 3/3] KVM: SVM: Reenable handle_fastpath_set_msr_irqoff() after complete_interrupts() Date: Wed, 9 Sep 2020 10:57:17 +0800 Message-Id: <1599620237-13156-3-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599620237-13156-1-git-send-email-wanpengli@tencent.com> References: <1599620237-13156-1-git-send-email-wanpengli@tencent.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Wanpeng Li Moving the call to svm_exit_handlers_fastpath() after svm_complete_interrupts() since svm_complete_interrupts() consumes rip and reenable the function handle_fastpath_set_msr_irqoff() call in svm_exit_handlers_fastpath(). Suggested-by: Sean Christopherson Cc: Paul K. Signed-off-by: Wanpeng Li --- arch/x86/kvm/svm/svm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 74bcf0a..ac819f0 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3347,6 +3347,11 @@ static void svm_cancel_injection(struct kvm_vcpu *vcpu) static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu) { + if (!is_guest_mode(vcpu) && + to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR && + to_svm(vcpu)->vmcb->control.exit_info_1) + return handle_fastpath_set_msr_irqoff(vcpu); + return EXIT_FASTPATH_NONE; } @@ -3495,7 +3500,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) stgi(); /* Any pending NMI will happen here */ - exit_fastpath = svm_exit_handlers_fastpath(vcpu); if (unlikely(svm->vmcb->control.exit_code == SVM_EXIT_NMI)) kvm_after_interrupt(&svm->vcpu); @@ -3529,6 +3533,7 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) svm_handle_mce(svm); svm_complete_interrupts(svm); + exit_fastpath = svm_exit_handlers_fastpath(vcpu); vmcb_mark_all_clean(svm->vmcb); return exit_fastpath;