From patchwork Fri Jan 15 22:03:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12024229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99052C43381 for ; Fri, 15 Jan 2021 22:05:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67AE7239FC for ; Fri, 15 Jan 2021 22:05:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727132AbhAOWEr (ORCPT ); Fri, 15 Jan 2021 17:04:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726059AbhAOWEq (ORCPT ); Fri, 15 Jan 2021 17:04:46 -0500 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8545C061796 for ; Fri, 15 Jan 2021 14:04:03 -0800 (PST) Received: by mail-qv1-xf4a.google.com with SMTP id i20so8993903qvk.18 for ; Fri, 15 Jan 2021 14:04:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=945mZt11W/e1Cpr0kux35fc/oPlYVUnDMXl7cGh3YTM=; b=Yr1kAU4CG074m4dxfzKdbDRb4kKVYmOtLuUvFV4BkhGqFcrk+mQDMyPPg5uboFJ3Am wsLXuIay1J8LcDKkxThYDs+tX/wrEnaCXYHI2XtodoBK8qftJCm97N0mNUrrY3hBaL3a la48DizDpshlWYMoedKHESMVL/q/JXWPGrhZw+Jg+k+QPzfg96oT0B85TtwjTJGW1rNC n5o8DEmkzot0v9Ikh7XVZuH6yJWEFyCW7D8lAbNj7Y7ydcwPUtVeQ5drOj04QtMExVuU KUST7RwIFuHGmsLYMpFxRZgRs6Zjt4C8bZUDu38neVfW+UUqr/Hi97D+myZidRsO9JK/ NP0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=945mZt11W/e1Cpr0kux35fc/oPlYVUnDMXl7cGh3YTM=; b=b9LcKsDep2VEztYbW+q5Km0j15VMD1eeqY1frRpnDtH47uQDEI+IdpzFibjha0MQJm 5mntMaLcJpuAh3b0/H9VkE5wjUtoyQz80+X9fjKoqeBj7rvZzY9YLKP1n+fxCdVYohYL Nh5cLwiTh+Pu28aaT9noUbphkRLhX+XOA17uIjMC4BWpa1XoG0WNZ4amh1ck1ia+217/ +0C190zd+sSyy4+7hAxT9RTHoV98uxiwKkJ6bZr1H0H3b4cWV9VBzyt1Pd75qEo8qtFd 1kLjmg6b/X7C+JwilXHDdbkMDFD01EjvRBpnkWkXQuU9UPNp2ZNuqVhTLkRryAciDGHm /G+w== X-Gm-Message-State: AOAM530bPjzSbN35cks6bK7wDk6zN/7G8lqQYm8xgpdwbX1FpIJS+b0A HZiMhXh7KF1bHiP88chjgZ6IG/1B+vE= X-Google-Smtp-Source: ABdhPJyt07jGMmHQFCoFeqGCZ1Bu0ZBh9pKPci86yZRNoZyB2kLRYs8TpCw2UxNarA98HdV3SjMy8aXFUys= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) (user=seanjc job=sendgmr) by 2002:ad4:4431:: with SMTP id e17mr13861250qvt.21.1610748242838; Fri, 15 Jan 2021 14:04:02 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 15 Jan 2021 14:03:53 -0800 In-Reply-To: <20210115220354.434807-1-seanjc@google.com> Message-Id: <20210115220354.434807-2-seanjc@google.com> Mime-Version: 1.0 References: <20210115220354.434807-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 1/2] x86/apic: Export x2apic_mode for use by KVM in "warm" path From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, luferry Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Export x2apic_mode so that KVM can query whether x2APIC is active without having to incur the RDMSR in x2apic_enabled(). When Posted Interrupts are in use for a guest with an assigned device, KVM ends up checking for x2APIC at least once every time a vCPU halts. KVM could obviously snapshot x2apic_enabled() to avoid the RDMSR, but that's rather silly given that x2apic_mode holds the exact info needed by KVM. Signed-off-by: Sean Christopherson --- arch/x86/kernel/apic/apic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index 6bd20c0de8bc..dea2b44966ca 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -1743,6 +1743,7 @@ void apic_ap_setup(void) #ifdef CONFIG_X86_X2APIC int x2apic_mode; +EXPORT_SYMBOL_GPL(x2apic_mode); enum { X2APIC_OFF, From patchwork Fri Jan 15 22:03:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12024231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF0B3C4332B for ; Fri, 15 Jan 2021 22:05:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9684D239EE for ; Fri, 15 Jan 2021 22:05:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727463AbhAOWE6 (ORCPT ); Fri, 15 Jan 2021 17:04:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727423AbhAOWE5 (ORCPT ); Fri, 15 Jan 2021 17:04:57 -0500 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F9C1C061757 for ; Fri, 15 Jan 2021 14:04:06 -0800 (PST) Received: by mail-qv1-xf4a.google.com with SMTP id h1so8993168qvr.7 for ; Fri, 15 Jan 2021 14:04:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=2h5JADF5aibKmlPcIhEIz6Cci5P07JwXVRYCu6RYD34=; b=nvLE1t9zvMfH3Xl0Rv9Mqj6PggnwUHlZoedRba/027S3GxjVyLStkyWuTjbWcDQPo9 asSNihwxRbVSQG7RjNB2AnGIHhMGF1AsPGkf26oIo9qVAt2/6nlL/CXa+brtFY8YeSIg 7ABAY6FvrxJLXtURLJuoWH5cEoxAMfakMKUql1Oeppexsqg4Mq44i8nJL0fSEwQbjBCV o/ByBVR0JfNYT0WH7nWE2AM5VvqlJf6+pIf3mrdskpgU9obgQQcqDeKTwej7YJ42ciC5 m4UioeT4shrWJ93T3MXI3BG3wAHtoIkMWcvqpKzjbbWUPK5AUAZN6BRd11wJnF+dXy5c i8/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=2h5JADF5aibKmlPcIhEIz6Cci5P07JwXVRYCu6RYD34=; b=SinfMnEzVuyZlQqR+ycQ+7sHGSitR8GPBhJIJN2BhFSKvmPi3Q5Q7k4L7j3muqikMa znKDxt2wK++SkI/sShsdhw9jZmNMMcPV6nrvovEJQxOD9ma3rY2LCliuiI1Iz4NginIW mF+MSZN9euKCOj22mJPh7ZbVWZ4quHkEfEp5DlnPMg/MySP2M6HIYGxtaqfvOI1cuRFa XZ1V8jJIu74U80hGSIpZjYT/+wfRgwVdrFGlP4hxAYI4Bgr3fq/nRk5v3vc9hWqCAdFT jkDJk4pzbLUIjfNERazBcXi6nQqLuzoNyn0S6c3tDcvycuqGaWJXv7xnz5hk9RiUxHh6 nS8Q== X-Gm-Message-State: AOAM530UEH8YTAAwhECPDjh7lXDUOoEYACiBmQbkJhn6i7QS6G+nLAsZ JlOzZ/GaVAyaME9iZr+x9z2FxPaV+jk= X-Google-Smtp-Source: ABdhPJx0BCCAbCBkZkETT6SrAr9envoXwfD3Zg1e2yzg9Q8/oP8UGerV8n+UTszb/CTE6FQ+5DmEJjbTYW8= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) (user=seanjc job=sendgmr) by 2002:ad4:5986:: with SMTP id ek6mr14361313qvb.57.1610748245270; Fri, 15 Jan 2021 14:04:05 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 15 Jan 2021 14:03:54 -0800 In-Reply-To: <20210115220354.434807-1-seanjc@google.com> Message-Id: <20210115220354.434807-3-seanjc@google.com> Mime-Version: 1.0 References: <20210115220354.434807-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 2/2] KVM: VMX: Use x2apic_mode to avoid RDMSR when querying PI state From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, luferry Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use x2apic_mode instead of x2apic_enabled() when adjusting the destination ID during Posted Interrupt updates. This avoids the costly RDMSR that is hidden behind x2apic_enabled(). Reported-by: luferry Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/posted_intr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index f02962dcc72c..4831bc44ce66 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -54,7 +54,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) dest = cpu_physical_id(cpu); - if (x2apic_enabled()) + if (x2apic_mode) new.ndst = dest; else new.ndst = (dest << 8) & 0xFF00; @@ -104,7 +104,7 @@ static void __pi_post_block(struct kvm_vcpu *vcpu) dest = cpu_physical_id(vcpu->cpu); - if (x2apic_enabled()) + if (x2apic_mode) new.ndst = dest; else new.ndst = (dest << 8) & 0xFF00; @@ -174,7 +174,7 @@ int pi_pre_block(struct kvm_vcpu *vcpu) */ dest = cpu_physical_id(vcpu->pre_pcpu); - if (x2apic_enabled()) + if (x2apic_mode) new.ndst = dest; else new.ndst = (dest << 8) & 0xFF00;