From patchwork Thu Sep 10 09:50:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11767285 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 D75F692C for ; Thu, 10 Sep 2020 09:51:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD92121582 for ; Thu, 10 Sep 2020 09:51:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YMfqaa8x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730486AbgIJJvW (ORCPT ); Thu, 10 Sep 2020 05:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729781AbgIJJvE (ORCPT ); Thu, 10 Sep 2020 05:51:04 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A868C061573; Thu, 10 Sep 2020 02:51:04 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id 34so3935863pgo.13; Thu, 10 Sep 2020 02:51:04 -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=cdLm++xYkcDurXtOuboxDgxpAJcdgeOErpU/g8ChEs0=; b=YMfqaa8x3VnmAW238O4aMYbWh8YpJvMiNexqZYyhRbQfHPkg05ZBKLaD5SMzm6EF3b RZV8uJMMz6SvQ8anjIMo3AcFo8Ngd+Y1ObHkrdzz9aBivexABBpCWABoUwn8SiwOzug2 jRbyqwM6e/r2S1dFECbpseje/9r4I89d7me4hNIbTUxqgCeLeCOzM9kQLdcKhJDGgLcQ F2vUqSQqJIfF0VQ/3X3AwJz4QZwR24izr+rwNKTLEIWV0TORwYBGPOdBQPkY891vAvNg 6BemgllzAGTdycAALowGnWJIFeGuKqIihs2Q50n2A/0W74emODcM/ME8ZXkfo1Ivqwhj AfDw== 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=cdLm++xYkcDurXtOuboxDgxpAJcdgeOErpU/g8ChEs0=; b=I0zo5PjAJVuM1I8+PHdeLV4rceqdEiIWjzcYdshSHlCoPcjAmoxzTWUK/daRbwieQR kEge//iuy+fzmGVwAymyDwkgbg+IDQwambVbIdZbadqG0Ar2Suof2k9Ref7ww4RSC+4Y 6M5TgK4IllR/ayuqAFIwtGanQoV2/3WeAIfRVdmKCiWQCaeGFCsvTvdWfFWqurkOzdfz +Z8bPXIF8roOdI5H3RjW/OdDArSASm/utKBU/M4dxk5xPrTHqt5aSQrS3ImIyl4gEwSs G+3mbJql4Z2ht7e1uU5V+LCCPhGQbdjhlrh6mIKvoX37e6GZhIJ1ZlfoifxEzsF8xgUC iaBQ== X-Gm-Message-State: AOAM530oD9tW1ZcJ8DoRTh3Sbqt11Y4vMNOxrbmLesn/1fSsvcAmvpAS ZKXK5zWZiXhqWvfKCChoRV9kveEPXTg= X-Google-Smtp-Source: ABdhPJxOb7Bzcz7WquKtLWovKvX25s8F05+NUPa+yNzWmnHRS8zIOvHL10P8R3RK3KCDcdhoXOwFZQ== X-Received: by 2002:a63:1d5a:: with SMTP id d26mr3735967pgm.432.1599731460205; Thu, 10 Sep 2020 02:51:00 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id e1sm2576534pfl.162.2020.09.10.02.50.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 02:50:59 -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 Subject: [PATCH v2 1/9] KVM: LAPIC: Return 0 when getting the tscdeadline timer if the lapic is hw disabled Date: Thu, 10 Sep 2020 17:50:36 +0800 Message-Id: <1599731444-3525-2-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599731444-3525-1-git-send-email-wanpengli@tencent.com> References: <1599731444-3525-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 Return 0 when getting the tscdeadline timer if the lapic is hw disabled. Suggested-by: Paolo Bonzini Reviewed-by: Sean Christopherson Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 35cca2e..81bf6a8 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2183,8 +2183,7 @@ u64 kvm_get_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic = vcpu->arch.apic; - if (!lapic_in_kernel(vcpu) || - !apic_lvtt_tscdeadline(apic)) + if (!kvm_apic_present(vcpu) || !apic_lvtt_tscdeadline(apic)) return 0; return apic->lapic_timer.tscdeadline; From patchwork Thu Sep 10 09:50:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11767283 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 D21E6698 for ; Thu, 10 Sep 2020 09:51:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8BD420882 for ; Thu, 10 Sep 2020 09:51:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Aaeqm3WF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730504AbgIJJvq (ORCPT ); Thu, 10 Sep 2020 05:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730361AbgIJJvF (ORCPT ); Thu, 10 Sep 2020 05:51:05 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C55FC061756; Thu, 10 Sep 2020 02:51:05 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id 5so3968666pgl.4; Thu, 10 Sep 2020 02:51:05 -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=5+FqItlch5fXU8bS1/CLLF6Rlk1KCJ6HSP/u17LZEpg=; b=Aaeqm3WFVgxo0hI9bAZyTv+C5cRXDd5iDOaTxdTyLIXZ+clzbAz42qQeWKI2f6tavq L/GsJ9MtAB/aGUronpyzAHKB6IJ9rsWptmtV5xNBACKPaGfxEUOdcAr9S/WrSrjBkAYb X6MyKNwYhWTBr4Jf6gbvfPAAvvpPTYCfCMqM7A3Ko+it2ABrqQ9NiytmHJrfUvzR8W5k xZM0G8KHVvHJg3oMPsVnTUIXyQNxkEThhbUICn8AJcgq5ZrrnIvAghaQR8pcOfzw6eQm URfvNVSHtXaKVIjRMl2o1RDHNFgbqVuvPwO3ucjx5DmKGHMrHqYcte5p4G2+D5SqdoC/ Dk/g== 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=5+FqItlch5fXU8bS1/CLLF6Rlk1KCJ6HSP/u17LZEpg=; b=PhG31yeA4yye2PTbCwF9tb0tfF9mJvwFJP1K2DJ1LPhRMXAG1zO5lvLRgkzJbTeJrf +myg8+7k9gJYMnx4fdgJqBoe3/6MJWRpllNdnkhhocisCFz42/ylm/Tf+rru1ZO4hBo9 StbcNdrY91+Avnqj5PZJ6cnmKD8Cd0UP+jJJNUNJf3nVmXWyVAoMfK1oO8NOltqS+yKv ReZGVHoO8mE5ocD2KdeqpdytsIH2ixSGbZus/Apm0VvOgAK1u2BS7TgYObNeYLNkGe2B LbwbATuaEgVBtq9s5LYatl8S5kX6X+iMjDnwRkc9YKP1elE6eBHRn9iK5c5UVl3t6iq2 NW0w== X-Gm-Message-State: AOAM532J3hvXSOfcp7qN9c2+T6YSSgLCiVRGbda9j3A6BuO3K9Ke9ZVN vYnDXRtA87UeA4i+jTn+N6WnhoKiLGU= X-Google-Smtp-Source: ABdhPJwKETbw88dtvX26SyEyDJqeuANaiFEjg5cUIBWYLYvx7Q5v2Dfu7MvFSUqsduZ5VzQmzi8xDQ== X-Received: by 2002:a63:4b63:: with SMTP id k35mr3916705pgl.142.1599731462899; Thu, 10 Sep 2020 02:51:02 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id e1sm2576534pfl.162.2020.09.10.02.51.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 02:51:02 -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 Subject: [PATCH v2 2/9] KVM: LAPIC: Guarantee the timer is in tsc-deadline mode when setting Date: Thu, 10 Sep 2020 17:50:37 +0800 Message-Id: <1599731444-3525-3-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599731444-3525-1-git-send-email-wanpengli@tencent.com> References: <1599731444-3525-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 Check apic_lvtt_tscdeadline() mode directly instead of apic_lvtt_oneshot() and apic_lvtt_period() to guarantee the timer is in tsc-deadline mode when wrmsr MSR_IA32_TSCDEADLINE. Reviewed-by: Sean Christopherson Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 81bf6a8..33aab20 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2193,8 +2193,7 @@ void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data) { struct kvm_lapic *apic = vcpu->arch.apic; - if (!kvm_apic_present(vcpu) || apic_lvtt_oneshot(apic) || - apic_lvtt_period(apic)) + if (!kvm_apic_present(vcpu) || !apic_lvtt_tscdeadline(apic)) return; hrtimer_cancel(&apic->lapic_timer.timer); From patchwork Thu Sep 10 09:50:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11767309 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 A7E4492C for ; Thu, 10 Sep 2020 09:55:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FFD42074B for ; Thu, 10 Sep 2020 09:55:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F8Am6Rdm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730677AbgIJJzZ (ORCPT ); Thu, 10 Sep 2020 05:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730400AbgIJJvG (ORCPT ); Thu, 10 Sep 2020 05:51:06 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A099C061757; Thu, 10 Sep 2020 02:51:06 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id 34so3935966pgo.13; Thu, 10 Sep 2020 02:51:06 -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=aZ2ai2L5F/iERellRc/FhiA4bgMeRmHk5nCXIpo3Znc=; b=F8Am6Rdm3ufNw7+FDdsXU9EFqxzfXlTe1JDzL4WnKkbhHHoSJDBlS4br77nLfsZsUJ OCtihh7Upioru26Pzz7FyVeE7wN2KX2qF2UregF/sz6/gtVOEWfH/FaP6Q9Igp2EB/P4 Cwsf2qE8vJFtHOsiccv2xUtFgNmsne1U+gT0XGLSwA6QoGK5f3paPzvxzvTDd0jtO0K6 5WwxOhiLFl5XJhCotBITcB2V66n4pA6HVwSIXk4fda3QfiF5RwLJKqkpK7e0VlO9sM8u JL6/ibfIZk/oOINC0w+IUg4CBdCyCtMZ0QCCIbKW7wO1Q0Ai8Y7+7Pmv/zmfQKddHCTI Fj0Q== 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=aZ2ai2L5F/iERellRc/FhiA4bgMeRmHk5nCXIpo3Znc=; b=L3cJSgmCsa3QcwZjyzNJusJW5BvJS9KvvBm7wpvKZmeQEYtZdhj7Uz0lnWJAJ6iyWd Vbkc3cIz5+JQfcT9/w4dmVq6vn96sRfs6+KZ/6/G3K/4BZ8sLA8IIhcfWcMXy7FyyxEz jWJxMqaCrJQeMxJse6DGG3PeCZzTfZR25AGJWA4TmcaFs+h8PnUrn+Nh2jzkC/zF6sKp pBX/8Ug2QyVJId+un+BRtzGObOZM1TGzUbWbbTy05mt2CHywewHq432SJ1iy6fCQvDa7 NaMnrRZorqBC0DevAXqpGk3WHSJFelh2YOmpOI6jTZNfVKmKN1awqx3O3be7F6TxvHej ib1w== X-Gm-Message-State: AOAM531nHl/Izwd4AjpsAAXCY/ATNoBupOIfw356392M47LEsHJGyIwG urehle+zMvCoh6bgtiP8j+N5je8FynY= X-Google-Smtp-Source: ABdhPJyozM0bNbb8hwh7gXPLyZTwZwjiImgWvel+Zpd64c+7bvUk9x6pBPd6KYjSAAro5RASbpBUTQ== X-Received: by 2002:a62:fcc1:: with SMTP id e184mr4690330pfh.152.1599731465614; Thu, 10 Sep 2020 02:51:05 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id e1sm2576534pfl.162.2020.09.10.02.51.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 02:51:05 -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 Subject: [PATCH v2 3/9] KVM: LAPIC: Fix updating DFR missing apic map recalculation Date: Thu, 10 Sep 2020 17:50:38 +0800 Message-Id: <1599731444-3525-4-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599731444-3525-1-git-send-email-wanpengli@tencent.com> References: <1599731444-3525-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 There is missing apic map recalculation after updating DFR, if it is INIT RESET, in x2apic mode, local apic is software enabled before. This patch fix it by introducing the function kvm_apic_set_dfr() to be called in INIT RESET handling path. Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 33aab20..e446bdf 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -310,6 +310,12 @@ static inline void kvm_apic_set_ldr(struct kvm_lapic *apic, u32 id) atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY); } +static inline void kvm_apic_set_dfr(struct kvm_lapic *apic, u32 val) +{ + kvm_lapic_set_reg(apic, APIC_DFR, val); + atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY); +} + static inline u32 kvm_apic_calc_x2apic_ldr(u32 id) { return ((id >> 4) << 16) | (1 << (id & 0xf)); @@ -1984,10 +1990,9 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val) break; case APIC_DFR: - if (!apic_x2apic_mode(apic)) { - kvm_lapic_set_reg(apic, APIC_DFR, val | 0x0FFFFFFF); - atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY); - } else + if (!apic_x2apic_mode(apic)) + kvm_apic_set_dfr(apic, val | 0x0FFFFFFF); + else ret = 1; break; @@ -2301,7 +2306,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event) SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT)); apic_manage_nmi_watchdog(apic, kvm_lapic_get_reg(apic, APIC_LVT0)); - kvm_lapic_set_reg(apic, APIC_DFR, 0xffffffffU); + kvm_apic_set_dfr(apic, 0xffffffffU); apic_set_spiv(apic, 0xff); kvm_lapic_set_reg(apic, APIC_TASKPRI, 0); if (!apic_x2apic_mode(apic)) From patchwork Thu Sep 10 09:50:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11767307 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 7EEB792C for ; Thu, 10 Sep 2020 09:55:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4942521582 for ; Thu, 10 Sep 2020 09:55:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RpOegm/l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730649AbgIJJzS (ORCPT ); Thu, 10 Sep 2020 05:55:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730426AbgIJJvJ (ORCPT ); Thu, 10 Sep 2020 05:51:09 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F13BAC0613ED; Thu, 10 Sep 2020 02:51:08 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id l191so3964225pgd.5; Thu, 10 Sep 2020 02:51:08 -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=czOly1540I6BKqMoR9raepWwmmlZQ0MNBG9xzJ8lIuk=; b=RpOegm/l6JpCENCZQdON8OVqhPsf8h5roKmEBsTCAGzJiC3MLll5p4GTTdM0INZ4Qr XbAP/KFa1mixl8oSn/OYM15dDPAo9rw4qwupXyL/YvskJ6coTKspuB8G5tuBZR6VWrcU oCcHAV0HiKMq7vfraDc7ELRfAuNMwuG/oN/4eg+2PMLRbqXbPnOcxhEEsH7kZLuKuOC1 cKCrgh84NW4pRU/GwYi61dtdVeBwyPJTIjsH5Y2qN4ItiPEp+VcFQYw8QTowT7i/QKAA PRx9J8pi8v9RLq5yPlAF6oa+W7KdQCkfp7OlMBFQ57OYWhHOgAQfh8CB53NC7helHJPr Xe7A== 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=czOly1540I6BKqMoR9raepWwmmlZQ0MNBG9xzJ8lIuk=; b=aZ8wy+I6PE91Q2PHCJbqnz7/XKYuEB7RaqvDWeVHn3dDRKIg631o3UWK8/f9a6TvXO ZUfL6yBNvVpAZG7BxMbFC+KKerOzistQfqVscj6+7EsBWXowKIeMcOlo+XFlXRiHdKxT lyolYOoSbGNQUFbfRaV1pUg4a21h2u3Ffgwx9IqobyaTlyfskA/G8fCzYW6Bbjy0/W1G 0zDTQs3ZKYA4uoXA5xZ2Gaqq0D0ryesCg+f3g9EetmJ8id9C+MgylcfKNdtWboWeOfrT dvUMFUF3Mg6EIKu9CmqabuE5X8JNk2vPMM9PNThMPLUT2Ag07OxfKqJe14bk2yAl1ARb qspQ== X-Gm-Message-State: AOAM533Afhqg9IvspXkxtbrQzk430gbzFDwEcNvM+tqvwQF6PqJ9Qv39 ae02OCGqulhgLDD7PMCh65jmk7zuaeA= X-Google-Smtp-Source: ABdhPJxGjSfsVATKZs0iOBS1CNkwsW0OZPfU49sSnMDfaxsKL5FQfeF8hebA9K+CfzAnRkXSEE0XpA== X-Received: by 2002:a05:6a00:808:b029:13e:d13d:a05d with SMTP id m8-20020a056a000808b029013ed13da05dmr4512317pfk.35.1599731468294; Thu, 10 Sep 2020 02:51:08 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id e1sm2576534pfl.162.2020.09.10.02.51.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 02:51:07 -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 Subject: [PATCH v2 4/9] KVM: VMX: Don't freeze guest when event delivery causes an APIC-access exit Date: Thu, 10 Sep 2020 17:50:39 +0800 Message-Id: <1599731444-3525-5-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599731444-3525-1-git-send-email-wanpengli@tencent.com> References: <1599731444-3525-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 According to SDM 27.2.4, Event delivery causes an APIC-access VM exit. Don't report internal error and freeze guest when event delivery causes an APIC-access exit, it is handleable and the event will be re-injected during the next vmentry. Signed-off-by: Wanpeng Li --- arch/x86/kvm/vmx/vmx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 819c185..a544351 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6054,6 +6054,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) (exit_reason != EXIT_REASON_EXCEPTION_NMI && exit_reason != EXIT_REASON_EPT_VIOLATION && exit_reason != EXIT_REASON_PML_FULL && + exit_reason != EXIT_REASON_APIC_ACCESS && exit_reason != EXIT_REASON_TASK_SWITCH)) { vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV; From patchwork Thu Sep 10 09:50:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11767305 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 3D5DC698 for ; Thu, 10 Sep 2020 09:54:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13D5F21941 for ; Thu, 10 Sep 2020 09:54:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="r7Dro3Ow" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730501AbgIJJyD (ORCPT ); Thu, 10 Sep 2020 05:54:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729449AbgIJJvQ (ORCPT ); Thu, 10 Sep 2020 05:51:16 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6CADC061795; Thu, 10 Sep 2020 02:51:11 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id w7so4330625pfi.4; Thu, 10 Sep 2020 02:51:11 -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=kx7whO6ZCYHRATUGoFzPCq1CCU2l01VHTCUDbZIVyWI=; b=r7Dro3OwHZ7zTknULumOSLG9JV8KHr4ktmvsDyXpvuHYyFrHiK+OmM+t+zYql34ltP Yf2QHFkojLEZ1sNbCB97p6joWTF0dfIutegAMxIRWyyMuiXjWXeJZQ/SooxQEkJ7k6uR xi8ek+C2F/Yk9YzK7oVOJg186oDGUYN4nAvrppEf0lpytO5Hf7pzXroZKYemPB7+sYKy oSroWn1hXE8J0gB0aiDeDRK/RGydEHqAiIzhwrn+TqEDNZsWQ87qa69nogMW3DApTR/q a1f1p4v3uV8d2kpclG6C8Ira+n/NBqbmOdhVMF2+P4HkPdm3z8LDBBkk/acIunrhxcl2 uzuA== 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=kx7whO6ZCYHRATUGoFzPCq1CCU2l01VHTCUDbZIVyWI=; b=M05rqCxo/vbCUjYvO2b0lgSBLr8y0OEisW0/yIOEeyvaCnfevCvGajKzrurlbFyAOw RmvS/8sZS5PqvY2Tgulwxr1wddZXxInK5Oq9JAnkpsWJy7cGAVlbA+vG/Z0u8tgzs7nf gCf07W+KWa9KiKFFOdl0wl3DJb8L8JDUHLWQahEuE+wx9O3eASUkvreZw8kVnHQjePFO qFlEnT/u+C8s0cSbJC5tDw/NnnisGHkedCI/AsgcxTRu9ssZhF+6Mb3S71eusB3WMbFk 6AMkQnGmMmlMCOlfQ70B6eL4iGWk+DiGfYUwYZn4TmaOlcVetwLD2j2bfi/qkgyUhY84 qByQ== X-Gm-Message-State: AOAM533N31sVyXUmpq+5wvrqy0NPK5v7j51sKEzjYnqSNUg4GgWNiseV 1+5VpidMXUE+OtEj3ozIKIz+Qw0apcY= X-Google-Smtp-Source: ABdhPJxIfzznZfSjzdpMV+TClLMq+JvquGerhc18a2TLYYe0aNJ/PJMsL7TI6MrTC38L77qdtaJgMw== X-Received: by 2002:aa7:988d:: with SMTP id r13mr4713746pfl.93.1599731470981; Thu, 10 Sep 2020 02:51:10 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id e1sm2576534pfl.162.2020.09.10.02.51.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 02:51:10 -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 Subject: [PATCH v2 5/9] KVM: LAPIC: Narrow down the kick target vCPU Date: Thu, 10 Sep 2020 17:50:40 +0800 Message-Id: <1599731444-3525-6-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599731444-3525-1-git-send-email-wanpengli@tencent.com> References: <1599731444-3525-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 The kick after setting KVM_REQ_PENDING_TIMER is used to handle the timer fires on a different pCPU which vCPU is running on, this kick is expensive since memory barrier, rcu, preemption disable/enable operations. We don't need this kick when injecting already-expired timer, we also should call out the VMX preemption timer case, which also passes from_timer_fn=false but doesn't need a kick because kvm_lapic_expired_hv_timer() is called from the target vCPU. Reviewed-by: Sean Christopherson Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 4 +++- arch/x86/kvm/x86.c | 6 ------ arch/x86/kvm/x86.h | 1 - 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index e446bdf..3b32d3b 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1642,7 +1642,9 @@ static void apic_timer_expired(struct kvm_lapic *apic, bool from_timer_fn) } atomic_inc(&apic->lapic_timer.pending); - kvm_set_pending_timer(vcpu); + kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu); + if (from_timer_fn) + kvm_vcpu_kick(vcpu); } static void start_sw_tscdeadline(struct kvm_lapic *apic) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d39d6cf..dcf4494 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1774,12 +1774,6 @@ static s64 get_kvmclock_base_ns(void) } #endif -void kvm_set_pending_timer(struct kvm_vcpu *vcpu) -{ - kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu); - kvm_vcpu_kick(vcpu); -} - static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) { int version; diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 995ab69..ea20b8b 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -246,7 +246,6 @@ static inline bool kvm_vcpu_latch_init(struct kvm_vcpu *vcpu) return is_smm(vcpu) || kvm_x86_ops.apic_init_signal_blocked(vcpu); } -void kvm_set_pending_timer(struct kvm_vcpu *vcpu); void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip); void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr); From patchwork Thu Sep 10 09:50:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11767287 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 36A99698 for ; Thu, 10 Sep 2020 09:52:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D2BE20882 for ; Thu, 10 Sep 2020 09:52:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d3yUxF+w" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730586AbgIJJwO (ORCPT ); Thu, 10 Sep 2020 05:52:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730381AbgIJJvQ (ORCPT ); Thu, 10 Sep 2020 05:51:16 -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 631EAC061796; Thu, 10 Sep 2020 02:51:14 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id d6so4310995pfn.9; Thu, 10 Sep 2020 02:51:14 -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=gufdorb42rxA796FKLZhr27r+MpQ8Lg+JA5WYF7LC2E=; b=d3yUxF+w3w8haeWR3Vy+vCCEh0dNiyZEJrGs6Lh5O9GF7k55o9jPHkloPd98LUNmgO SHU1bsr3jZr6xGkviMlUYUH/Rs7VUfDUdDUt6FqBSr7S2ZLoym92Lzy77K1FVpLTNcr2 E2ulQhXDyyEdrfGW3NpA11T7saQogULFFPsJ60VZF9/16qMQG+nXt1BrHiohXT6jmlj8 mfs9rkVHL9Fz6h8Q6j4YVpT9sEODD03bfY2DQ2wc1qhYEIByvzD4wULIAV1vQy+wrJyg UcmDaJOXVXyjQ5pP/9MYfiaNpXNfW4c/vdTMt6ShNkTqAJ5c7oLWlFpeaipK2SOb4BSr /j6g== 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=gufdorb42rxA796FKLZhr27r+MpQ8Lg+JA5WYF7LC2E=; b=l+IcbcElu8Ovc2zOt6D38QNSd3NmUN60XWj8smJXDA/Ve24EToy3qodLNwhLNfBx1J QkFr60+pVLiQ6YlMNXjx47Shy4YUjIHQbmbbIGvLzOqh7Hah0EaipzLbhjKnCaJEKW1Q cMjASxyCFkEj4krx3obxbhXwMq470BZp8vDGY3Jdn2fglJym15lwn2AGNDDF47yeHoCB vijW+jFkXQYmWk8PnZq9am4XNMY3hYAf2XQ23jrG3uQyLvoi8Q8/4K/zvssOPInl5uYy oj2FKrv8QyESnMvRpDmf78AyLxy5BVBka/UfbLFC/qu580i/jwK7Kmvaqi4rsc14RObI q7sA== X-Gm-Message-State: AOAM531mCrBOwk2pZ9OMIF1SewjHiYGS1VJFo272clVw73F11nyQFty8 SWDaClJNlIEyrYYXSAC3dqoUxb0SR7I= X-Google-Smtp-Source: ABdhPJxMWA1T1JI6YEp2ljHyfvQ74aImtlJz0UWdT2EcjTb5+nnHsfx9R+3I4NmN9DFm4UqVOglNYA== X-Received: by 2002:a63:c40d:: with SMTP id h13mr3806713pgd.185.1599731473755; Thu, 10 Sep 2020 02:51:13 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id e1sm2576534pfl.162.2020.09.10.02.51.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 02:51:13 -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 Subject: [PATCH v2 6/9] KVM: LAPIC: Reduce world switch latency caused by timer_advance_ns Date: Thu, 10 Sep 2020 17:50:41 +0800 Message-Id: <1599731444-3525-7-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599731444-3525-1-git-send-email-wanpengli@tencent.com> References: <1599731444-3525-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 All the checks in lapic_timer_int_injected(), __kvm_wait_lapic_expire(), and these function calls waste cpu cycles when the timer mode is not tscdeadline. We can observe ~1.3% world switch time overhead by kvm-unit-tests/vmexit.flat vmcall testing on AMD server. This patch reduces the world switch latency caused by timer_advance_ns feature when the timer mode is not tscdeadline by simpling move the check against apic->lapic_timer.expired_tscdeadline much earlier. Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 11 +++++------ arch/x86/kvm/svm/svm.c | 4 +--- arch/x86/kvm/vmx/vmx.c | 4 +--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 3b32d3b..51ed4f0 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1582,9 +1582,6 @@ static void __kvm_wait_lapic_expire(struct kvm_vcpu *vcpu) struct kvm_lapic *apic = vcpu->arch.apic; u64 guest_tsc, tsc_deadline; - if (apic->lapic_timer.expired_tscdeadline == 0) - return; - tsc_deadline = apic->lapic_timer.expired_tscdeadline; apic->lapic_timer.expired_tscdeadline = 0; guest_tsc = kvm_read_l1_tsc(vcpu, rdtsc()); @@ -1599,7 +1596,10 @@ static void __kvm_wait_lapic_expire(struct kvm_vcpu *vcpu) void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu) { - if (lapic_timer_int_injected(vcpu)) + if (lapic_in_kernel(vcpu) && + vcpu->arch.apic->lapic_timer.expired_tscdeadline && + vcpu->arch.apic->lapic_timer.timer_advance_ns && + lapic_timer_int_injected(vcpu)) __kvm_wait_lapic_expire(vcpu); } EXPORT_SYMBOL_GPL(kvm_wait_lapic_expire); @@ -1635,8 +1635,7 @@ static void apic_timer_expired(struct kvm_lapic *apic, bool from_timer_fn) } if (kvm_use_posted_timer_interrupt(apic->vcpu)) { - if (apic->lapic_timer.timer_advance_ns) - __kvm_wait_lapic_expire(vcpu); + kvm_wait_lapic_expire(vcpu); kvm_apic_inject_pending_timer_irqs(apic); return; } diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 0194336..19e622a 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3456,9 +3456,7 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) clgi(); kvm_load_guest_xsave_state(vcpu); - if (lapic_in_kernel(vcpu) && - vcpu->arch.apic->lapic_timer.timer_advance_ns) - kvm_wait_lapic_expire(vcpu); + kvm_wait_lapic_expire(vcpu); /* * If this vCPU has touched SPEC_CTRL, restore the guest's value if diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index a544351..d6e1656 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6800,9 +6800,7 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) if (enable_preemption_timer) vmx_update_hv_timer(vcpu); - if (lapic_in_kernel(vcpu) && - vcpu->arch.apic->lapic_timer.timer_advance_ns) - kvm_wait_lapic_expire(vcpu); + kvm_wait_lapic_expire(vcpu); /* * If this vCPU has touched SPEC_CTRL, restore the guest's value if From patchwork Thu Sep 10 09:50:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11767289 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 544D1698 for ; Thu, 10 Sep 2020 09:52:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2800220882 for ; Thu, 10 Sep 2020 09:52:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dytL7qeh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730433AbgIJJw2 (ORCPT ); Thu, 10 Sep 2020 05:52:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730418AbgIJJvS (ORCPT ); Thu, 10 Sep 2020 05:51:18 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83B0AC061573; Thu, 10 Sep 2020 02:51:17 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id a9so2767626pjg.1; Thu, 10 Sep 2020 02:51:17 -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=Blehx/RsCjxhexTNdBAbuV+NrcKDgCDuzEEOkebWnFE=; b=dytL7qehQzztnlbUdBSM8T5hf+VxNOCBpL/24z5fs4Kg5gVwvOyEerh/JykbVMXXv0 tn2DODpVzgu0YUGpAWKe8ATUON1qJzdQAui4lTpWUKwofInyzwM38QOuzvw0L6YJg1bP MVrI0CCBWnOJUoHBFq+Spuvz+5ehyQG7A4wbKWIsz5YEgf5weqcwLIy5h9YHj4BIdZte i5HVgsh1Ok4N9OGMMT5k8YDlHj6U/iVS8U1hYWGkuEy0eWkeOzj33blIpajczrVEEflB SyQ54fiGEPRmC7axVm3rWj0itegV1UObql+KQTgHNfDgE4GLUXWzuoPr8RHDCnXd/E3M VAWQ== 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=Blehx/RsCjxhexTNdBAbuV+NrcKDgCDuzEEOkebWnFE=; b=h57be6nbsS8N5yCvInj0Y9rK/HiqpH4Lt0w8RhS1V7MBofeQkdndYJgSWCx8xyogWM XeDEbLhQ17Z/Xhb67lPxtCaVG/dQbN1T70Prxp7qBXTEZ8mIuNW3LWlX556BMwGxaM5Z 4S6cuAeYsEDB0BI+QN3QM2wFNVta1ZhasH7h3hFbaB4989ACCa3tqAV5W1OQwLNOt2uX TJAHCzZR8J4jAWq2UlHuIgUmMKR1G6Yz5gEuogDUT5/ReQmRbByJayWpS0zyIjz4sCL/ cSK7t8tB9JruwMbAW1ercSwDOWFFSh3qElQqNsLnF9mo9ahkaOxcVT8Wanif+LvuwCTl DMvg== X-Gm-Message-State: AOAM5329rHmfJQv0vzx471rdPedvXEnwHFiR2vz+QS17JY0Jc8Q3wcza J/phQJoX2FkGTjxqeTkokyvjYVejYMc= X-Google-Smtp-Source: ABdhPJyQezQj+HJONXN4Ke47XI1Q9agwTLjxeb7n5zht75GG9c5NPJXGphDDb74zuOyJ46e84mNGYg== X-Received: by 2002:a17:90a:4687:: with SMTP id z7mr4537393pjf.144.1599731476796; Thu, 10 Sep 2020 02:51:16 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id e1sm2576534pfl.162.2020.09.10.02.51.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 02:51:16 -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 v2 7/9] KVM: SVM: Get rid of handle_fastpath_set_msr_irqoff() Date: Thu, 10 Sep 2020 17:50:42 +0800 Message-Id: <1599731444-3525-8-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599731444-3525-1-git-send-email-wanpengli@tencent.com> References: <1599731444-3525-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 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 Reviewed-by: Vitaly Kuznetsov 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 Thu Sep 10 09:50:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11767303 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 EBCBD698 for ; Thu, 10 Sep 2020 09:54:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C842220829 for ; Thu, 10 Sep 2020 09:54:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VjRprMti" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730598AbgIJJyG (ORCPT ); Thu, 10 Sep 2020 05:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730487AbgIJJvW (ORCPT ); Thu, 10 Sep 2020 05:51:22 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FDB9C061756; Thu, 10 Sep 2020 02:51:20 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id 5so3969021pgl.4; Thu, 10 Sep 2020 02:51:20 -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=8zHqH3bYwOpt/fl66BhVTKbXCR1yhQYjhkRrfj5pdDI=; b=VjRprMti9hsYYvaafHw5p2Qte8v6onDPZtBdKHdHzzAIdAWJyU1+vcqBU2Puvh1cf+ jdX3EO8F9KxV/y+7+raQO+rn3uOOIWvCGTT7A0kJ+i9+gRg1om9GA8ryjQSbIy+uAjJ9 0McDaMrYmxLWIPn8nASuSXlwV0BzTly/jtB2K+x8PwpW+f4tJ26XHenPLEQZ/hdyIvLC BFD7LRxq0MS7jyt9fmoVyjG0yNw+zvDaaq63LGmFSlozXwoMIhJhjN8nbf9IybycEOIH 81IxGLMlDxCglfwFvPfmpgApFm8Rn5AJdVVwJQMIM8UiMOyvuthBI/ZwePTxdb+9zTr1 0Kag== 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=8zHqH3bYwOpt/fl66BhVTKbXCR1yhQYjhkRrfj5pdDI=; b=RMfJXYLdC8sAHQiQm1wJNV797r4cg+tg/npGNhsVzZcCTrUDPk7IPS0Vij4ZcLIKxB zhD0WP8vXGPOf2F0UhzH6sMGhChqr+LPR7Kd5tO9zlz4M1oz/lt+y2b/TSS6pEOr96Ed Gm9nMA6IqmoIvs2shxZO14S6Tj/mEQiNWqnTO9G3tziNSIe8QOUY4cUuBID1PlgnT+vZ 2NhIx9yCniiUisZ9VAbS/iSBd9dQmgIsP74vo55C7HlC3NPd2s5YkqA3UhpOCJYBW8hS GV5S4aNxBB6sIja5lzXNFXiS5faXKCmIGj8GHHHM0/M0EegVBDKB9yOZlsz1AAcqJEUY KSKg== X-Gm-Message-State: AOAM533BifNXw/0tOU7elk2iAsHNNMEuIl/zh5p40T2ryW2GWUf6x3tD EdU9k1hrPIp5J+v4z90GC1b6riwqkTA= X-Google-Smtp-Source: ABdhPJy+Kw9FZXlSZos28NS770cn0ADEa/un0w+Jc2NoI8ezE6vme1iy/APwXHxMLocPXxAm0Xba5A== X-Received: by 2002:aa7:8f0b:0:b029:13e:d13d:a0fb with SMTP id x11-20020aa78f0b0000b029013ed13da0fbmr4566622pfr.23.1599731479685; Thu, 10 Sep 2020 02:51:19 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id e1sm2576534pfl.162.2020.09.10.02.51.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 02:51:19 -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 v2 8/9] KVM: SVM: Move svm_complete_interrupts() into svm_vcpu_run() Date: Thu, 10 Sep 2020 17:50:43 +0800 Message-Id: <1599731444-3525-9-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599731444-3525-1-git-send-email-wanpengli@tencent.com> References: <1599731444-3525-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 Reviewed-by: Vitaly Kuznetsov Cc: Paul K. Signed-off-by: Wanpeng Li --- arch/x86/kvm/svm/svm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index c61bc3b..dafc14d 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,7 @@ 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 Thu Sep 10 09:50:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11767299 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 D54B4698 for ; Thu, 10 Sep 2020 09:54:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACC6C20829 for ; Thu, 10 Sep 2020 09:54:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g4OTNybu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730340AbgIJJx5 (ORCPT ); Thu, 10 Sep 2020 05:53:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730493AbgIJJvX (ORCPT ); Thu, 10 Sep 2020 05:51:23 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59C69C061757; Thu, 10 Sep 2020 02:51:23 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id d16so643743pll.13; Thu, 10 Sep 2020 02:51:23 -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=j7htwJAeNCUvO4S5RlNc3DOtl4dol2zJUiU0SUBRc+I=; b=g4OTNybujZoa7EfwmXbgUf10fX2yhnMBDkP8tJ5tNWEG9sjZ5epA/K3eLzMxz1tbCc eK7ZwnexxYAOUkQU5ImT2eBA9xTip3+TuhGkeZRL92U65cpTF4lGQDy/n3AD0mHCds3p YPPOMZhZmbm21D+itxzUDBs21JkNXl/SUTjrS18rlK/s5YeMZaTZosXCBhFZ6baXMfGI v1T8YtnbuWyD6F3qNEhCvpnIPOKWWeRKofKSjxmGLN+eZ5Q4rRye/RL4kihEZ/e5e+Fb fQBzo6IkB0d5KC7wdHd1wizK7rtpj5K81KZePnxjZ0H1pCmH+94E83weAfwQdVHgTbvE Si/A== 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=j7htwJAeNCUvO4S5RlNc3DOtl4dol2zJUiU0SUBRc+I=; b=BK6lmQHIdjH/TY0au8/GKSIIA0oGum+3+6wOci5/NI2bXO2Jn+p6QLrjzaQS/+4/mL GC66yjzB2Or1ix8psDuHcDDM4IbIDfXvS0EP2a8OxpHxzFh8V2Y/48vfqOEQhdmjMQJg 8mGt/DuvFIOf1HETNHXYEw6foISqq0PIHY8qAdp+Gflbn3ysL+iFjV8SU9Vjhqnuclwu 8d+Vd5BOKbu/qcIu1p3jEZJYpsxS2Af4R7MjWUZUbPzIceOGmgNWWwmAMftl3HSDVcMJ rnlLFdhHuPxPv+8R/axdC3GvLY5A25ZVrf2J7gM0uvJPMZhQfEF3sZwFBxflzb8mq1YK 9PKg== X-Gm-Message-State: AOAM531irvgYX1gK2DOqCZezSKBA5z/vxD4MipaiQZrz5VhOjuy+bWa7 6Jpun/UQgwyQDnHCixTK2kXQ2JVLh6s= X-Google-Smtp-Source: ABdhPJy4Ec5AtTKMudbwxwexym3/hbq7B0Y99oDBkr+P3nbMIpcYhmxvpIYlbBI23hq8NAJ/xNL2+w== X-Received: by 2002:a17:902:10f:: with SMTP id 15mr4779290plb.121.1599731482578; Thu, 10 Sep 2020 02:51:22 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id e1sm2576534pfl.162.2020.09.10.02.51.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 02:51:22 -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 v2 9/9] KVM: SVM: Reenable handle_fastpath_set_msr_irqoff() after complete_interrupts() Date: Thu, 10 Sep 2020 17:50:44 +0800 Message-Id: <1599731444-3525-10-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599731444-3525-1-git-send-email-wanpengli@tencent.com> References: <1599731444-3525-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 Reviewed-by: Vitaly Kuznetsov Cc: Paul K. Signed-off-by: Wanpeng Li --- arch/x86/kvm/svm/svm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index dafc14d..b3e3429 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3347,6 +3347,10 @@ static void svm_cancel_injection(struct kvm_vcpu *vcpu) static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu) { + if (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 +3499,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); @@ -3530,6 +3533,12 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) svm_complete_interrupts(svm); vmcb_mark_all_clean(svm->vmcb); + + if (is_guest_mode(vcpu)) + return EXIT_FASTPATH_NONE; + + exit_fastpath = svm_exit_handlers_fastpath(vcpu); + return exit_fastpath; }