From patchwork Tue Jul 28 09:45:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11688767 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 6DE5E138A for ; Tue, 28 Jul 2020 09:45:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B69320838 for ; Tue, 28 Jul 2020 09:45:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RfYnzTVa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728556AbgG1JpT (ORCPT ); Tue, 28 Jul 2020 05:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728197AbgG1JpR (ORCPT ); Tue, 28 Jul 2020 05:45:17 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79CD0C061794; Tue, 28 Jul 2020 02:45:16 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id u10so108778plr.7; Tue, 28 Jul 2020 02:45:16 -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=YW61uT4gs7NLfpC0VAfH7u18rjoR4roJ54bakldbt1o=; b=RfYnzTVaaiIcgr+9v6Qpt+9Sn4A6BP7Q9yIcBs4oG6bfhviw+3JSTCk5bxF1v0Q9VP CUq/x8J/Q5xlyidW5jaxO5+QUJ1nIMYZT95rI6r8HwIvVYcixErDeg97g06HHpbEo/7F LwwNFv4NhVm7TKSdT4zHjQsYvZhtIh6u86VYKcMqCJCod6yK6Tl5nqYYVoMm8ubtdCGH quJmKGjBIogttIL6DsrSLmV1jPalEf2Fq+43Dty6I0iwCNBjfVc23hz+lt+1g9YQV+SJ 3TP1vfw0eBPVO9iLug6dQSoZVxRimiRsV98IQ6Ahh8vFpJK16eXVvpLLG6ndwl95wNg4 mHkw== 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=YW61uT4gs7NLfpC0VAfH7u18rjoR4roJ54bakldbt1o=; b=S/277hyXeTjAkmgbQCqdwINDdJJWLN12opdg270kTVxjc18S4U4LlQqtNRp3h6DoqW hmfJBS0E/2aPOY8u+8/FBpk4qCPhilA6K8/8PPfbDTvB6bcbrTgDSwqpgtlFPEWBG7qy BhTPoxjwZO7hFV4s8dIuJweqwNCoyUm6dM+SSC74myDwWkaxja6c7KWPozLWrkSzSneB 2VwBSSpbBL6P9S0Q1b1+rt53FtcW1BbtDGRh1knnfbDHtAoIrnagK3F1lOqhOW/TnZcy zCzjj15FAQ+mc7hPYH1bESIMp0kvcH9oSeew5I0/a65t/VTQIaLakn+SXfHAhIY8tF2W +3DA== X-Gm-Message-State: AOAM5321UOlqULWQu45mXdZcC5m+wpiwPbc8Zadf7gKr3JvTSPkbg53F EroCfbUVz8I7Xqe4xn3dT4mrm2Nc X-Google-Smtp-Source: ABdhPJxD6tzllfcRVDmb1xoKhd2jMzTzXphKdkN4ooTcK2t2IBIzxcYpjGFm4Em3KQhe2BXXOgUfSA== X-Received: by 2002:a17:90a:d30c:: with SMTP id p12mr3843893pju.4.1595929515664; Tue, 28 Jul 2020 02:45:15 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id r17sm17969173pfg.62.2020.07.28.02.45.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jul 2020 02:45:15 -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 , stable@vger.kernel.org Subject: [PATCH v2 1/3] KVM: LAPIC: Prevent setting the tscdeadline timer if the lapic is hw disabled Date: Tue, 28 Jul 2020 17:45:04 +0800 Message-Id: <1595929506-9203-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 Prevent setting the tscdeadline timer if the lapic is hw disabled. Fixes: bce87cce88 (KVM: x86: consolidate different ways to test for in-kernel LAPIC) Cc: Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 5bf72fc..4ce2ddd 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2195,7 +2195,7 @@ void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data) { struct kvm_lapic *apic = vcpu->arch.apic; - if (!lapic_in_kernel(vcpu) || apic_lvtt_oneshot(apic) || + if (!kvm_apic_present(vcpu) || apic_lvtt_oneshot(apic) || apic_lvtt_period(apic)) return; From patchwork Tue Jul 28 09:45:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11688765 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 00809138A for ; Tue, 28 Jul 2020 09:45:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC71820829 for ; Tue, 28 Jul 2020 09:45:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bd+wINYD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728561AbgG1JpV (ORCPT ); Tue, 28 Jul 2020 05:45:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728545AbgG1JpT (ORCPT ); Tue, 28 Jul 2020 05:45:19 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03D6DC061794; Tue, 28 Jul 2020 02:45:19 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id j19so11546407pgm.11; Tue, 28 Jul 2020 02:45:18 -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=ll8WCmZeOpOBPrLRP/0beycTFEf8dKZrUNMUWQ1/JDQ=; b=Bd+wINYDCUP8z22guocQAcON4oKrYDx2CgIgsz8nnitTQlq2y+JXpZ6GN/+kc010po POfHgEHzAud6glM01h6FgHQ98/JBoLPT2C+XcK64WAs0bZD9vSN4AoGJLvo/EBpvV/Ud 4AJjxLQPJyLxy9N0ZZ0Kve1ciIIsmicpsinl04IVkDxW0KLwFH6FIWf/RydET4VW+kkJ BueZlIgfCf1i6gAdX8sGoXbW8d6yXcqaCtr2CHmmkvbgS08rCMuARrAufwEmAw11eWA3 WpVTGBRbACsS1CrK+7xHJ19nt1guaMn1CS8qkrAuQh0ysVfSfUogVp2drqcDnxttXl4l paig== 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=ll8WCmZeOpOBPrLRP/0beycTFEf8dKZrUNMUWQ1/JDQ=; b=hq8BOZRyaGh0dq6JxHPwKlHtKusesrjSouwaIn72jDhhLk1h8HDsDZ85Lb6mdE+Ps/ qYxFS+C7HRzcewzRIVZJ2ANEm50o2bBPS51V/erajWiZu1rACOcX19xoHA4JU25E3Jlq +JjfiuJOGoNIR1b1jT82ZQJUbB1YkhoDLQTd3R+HtNESz7zW6jS3jZer9BNxJzoNXUT1 efoUXu3/xBa13xGqw8EHYXcDZIrM+1+30Uwi5uk47ZKqFtsrNoP35BCMT+YXzxnHhjp/ nDRf6FT1czGSZGjWBJblgBhabA3gANh8ELowjSpiJmhJLFbfZCAVaXfApybvOXYzxLpN pNKQ== X-Gm-Message-State: AOAM533hZfKHa0zlBsKvUaFOKEwOROe9osKJzwGfZAcEM63QYPWygHaC wlyBn8OqFz4jpH1OpnXv04oFCUVE X-Google-Smtp-Source: ABdhPJzX4644pR5SThaJH2dX56DH72ENkeS4mx1iIiB2Au6Z2mLpx1MuGv3yo3As09M/O5xzIOYpOQ== X-Received: by 2002:a62:88d4:: with SMTP id l203mr23287682pfd.205.1595929518202; Tue, 28 Jul 2020 02:45:18 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id r17sm17969173pfg.62.2020.07.28.02.45.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jul 2020 02:45:17 -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/3] KVM: LAPIC: Set the APIC_TDCR settable bits Date: Tue, 28 Jul 2020 17:45:05 +0800 Message-Id: <1595929506-9203-2-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595929506-9203-1-git-send-email-wanpengli@tencent.com> References: <1595929506-9203-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 It is a little different between Intel and AMD, Intel's bit 2 is 0 and AMD is reserved. On bare-metal, Intel will refuse to set APIC_TDCR once bits except 0, 1, 3 are setting, however, AMD will accept bits 0, 1, 3 and ignore other bits setting as patch does. Before the patch, we can get back anything what we set to the APIC_TDCR, this patch improves it. Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 4ce2ddd..8f7a14d 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2068,7 +2068,7 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val) case APIC_TDCR: { uint32_t old_divisor = apic->divide_count; - kvm_lapic_set_reg(apic, APIC_TDCR, val); + kvm_lapic_set_reg(apic, APIC_TDCR, val & 0xb); update_divide_count(apic); if (apic->divide_count != old_divisor && apic->lapic_timer.period) { From patchwork Tue Jul 28 09:45:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11688763 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 573D51392 for ; Tue, 28 Jul 2020 09:45:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DB8020829 for ; Tue, 28 Jul 2020 09:45:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zos4drdq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728575AbgG1JpX (ORCPT ); Tue, 28 Jul 2020 05:45:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728564AbgG1JpV (ORCPT ); Tue, 28 Jul 2020 05:45:21 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71394C061794; Tue, 28 Jul 2020 02:45:21 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id k13so1791533plk.13; Tue, 28 Jul 2020 02:45:21 -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=v4hzsRw11Wiw6xr0GvgfYpPF0Q4BnW/4rsf/8GkZyQw=; b=Zos4drdqzuG48wXtTv4pVVnjusmQl20abj+Kz1EqvewUtCnxXvkgMu0kwocJVglioq IGYaSAvrCj7Xt1MwTvrLt/GTXjliBxkNT+YTiZJWKuJI+F0eQxtzPsKj37plB7VyuTSn 7xN+UTf26Hu/SartpedeJofd3RnImxX3lAT0j1Nfq5AjCYKn8uWbFigOEevIfBzcay0l Chljv6Gk/6ZrD3mlVeQHl367jg/cxrG0PLHltEBZnT1E8sat9X3g9KRPskDUUch0z9Cp f+L5WVGo7e8klo7kB0PhQ51xQNZaf6u0hk5/VNPMhXxpUZizcUoJbpsXMSTJHN7duWKc AmWQ== 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=v4hzsRw11Wiw6xr0GvgfYpPF0Q4BnW/4rsf/8GkZyQw=; b=luCF/VdCih1z/QADt95HH5yiJhJmj/yisYGTE3ssq0eO0aNm65iSzYkYPkZHH/ePGa Xv6QvC/0AyUMXBt/NJYh+8jUMRMWghgvXahQjv6U9frPUsMpPjEpoPbqUENXODLsu7XU ZVODNg33Cx8mvTf3gGu3/IR69d+RuxcFUP5jTDERrM08CcoDYxSoXVpld6kcerCyFSKk ZfzRbj9SDnyQ4tTew40ZHCJ7776t1P6NciqSE22xMfRIK+mI6Yv9mgnXQvhOVuOFRzs8 1oFiSON4MO2zABdqNU1q+5Em9C64uk/3wn72O0eqfOOOkptQOkefH5fr6eVKqOGuRahS PfQw== X-Gm-Message-State: AOAM5326Ox1o8QitFORgMJc8/NgHmbwFI/BxAYiAM9/G22nxG8dnJiGh 2PCM7tet8B3wjDI1bB0VXHmfpekJ X-Google-Smtp-Source: ABdhPJxsZ5mYTWHDw/CZGoeaB7OeyI6mv6+zZ2Fpowq9ZFMFVYcxatXVTbH9YxF75bc0dzckLtbQUQ== X-Received: by 2002:a17:902:59d2:: with SMTP id d18mr11673509plj.243.1595929520819; Tue, 28 Jul 2020 02:45:20 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id r17sm17969173pfg.62.2020.07.28.02.45.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jul 2020 02:45:20 -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/3] KVM: SVM: Fix disable pause loop exit/pause filtering capability on SVM Date: Tue, 28 Jul 2020 17:45:06 +0800 Message-Id: <1595929506-9203-3-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595929506-9203-1-git-send-email-wanpengli@tencent.com> References: <1595929506-9203-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 Commit 8566ac8b (KVM: SVM: Implement pause loop exit logic in SVM) drops disable pause loop exit/pause filtering capability completely, I guess it is a merge fault by Radim since disable vmexits capabilities and pause loop exit for SVM patchsets are merged at the same time. This patch reintroduces the disable pause loop exit/pause filtering capability support. We can observe 2.9% hackbench improvement for a 92 vCPUs guest on AMD Rome Server. Reported-by: Haiwei Li Tested-by: Haiwei Li Fixes: 8566ac8b (KVM: SVM: Implement pause loop exit logic in SVM) Signed-off-by: Wanpeng Li --- arch/x86/kvm/svm/svm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index c0da4dd..c20f127 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1090,7 +1090,7 @@ static void init_vmcb(struct vcpu_svm *svm) svm->nested.vmcb = 0; svm->vcpu.arch.hflags = 0; - if (pause_filter_count) { + if (pause_filter_count && !kvm_pause_in_guest(svm->vcpu.kvm)) { control->pause_filter_count = pause_filter_count; if (pause_filter_thresh) control->pause_filter_thresh = pause_filter_thresh; @@ -2693,7 +2693,7 @@ static int pause_interception(struct vcpu_svm *svm) struct kvm_vcpu *vcpu = &svm->vcpu; bool in_kernel = (svm_get_cpl(vcpu) == 0); - if (pause_filter_thresh) + if (!kvm_pause_in_guest(vcpu->kvm)) grow_ple_window(vcpu); kvm_vcpu_on_spin(vcpu, in_kernel); @@ -3780,7 +3780,7 @@ static void svm_handle_exit_irqoff(struct kvm_vcpu *vcpu) static void svm_sched_in(struct kvm_vcpu *vcpu, int cpu) { - if (pause_filter_thresh) + if (!kvm_pause_in_guest(vcpu->kvm)) shrink_ple_window(vcpu); } @@ -3958,6 +3958,9 @@ static void svm_vm_destroy(struct kvm *kvm) static int svm_vm_init(struct kvm *kvm) { + if (!pause_filter_thresh) + kvm->arch.pause_in_guest = true; + if (avic) { int ret = avic_vm_init(kvm); if (ret)