From patchwork Sat Oct 9 00:11:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12546723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 828E3C433EF for ; Sat, 9 Oct 2021 00:11:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63F2060FC3 for ; Sat, 9 Oct 2021 00:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243997AbhJIANM (ORCPT ); Fri, 8 Oct 2021 20:13:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243974AbhJIANJ (ORCPT ); Fri, 8 Oct 2021 20:13:09 -0400 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 EF352C061755 for ; Fri, 8 Oct 2021 17:11:13 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id u9-20020a0cf889000000b003834c01c6e8so2913141qvn.4 for ; Fri, 08 Oct 2021 17:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=Jpbo+B/GhwXgwxD1by7/DXTldt+Mb436guJudBghH8A=; b=C8410r5ajEijJDUgktftizTQ2SFhw825HDX8x4RMiSyJDTLrbUC7tx9Q5aLXxnfm+l msNYG80c9PcM3gKhl5ayhrxTDm/3M4hf2CsQEC3juu0lxJSF0Ue+Rm4r8fMraYSSms/Y fQnnhcjtr/0tpVg3bED+ZM8BxcEi1ABpHyVhOriyWd9gCz6BTZ91pHwVk16b4mrfhhgq hgeK8F3oD17jRUT0OBQyJZ/mg3oJECgTeCUvLAOZ09BvqGNgkvwOdrSr9k4M0H6e2qNQ hsxK11/1GniyFj+JsUSswG4Vxcz1wDQJsfBct0fZaG0Wk+CDfjyspOgs4mZVrFZLJaKy ppJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Jpbo+B/GhwXgwxD1by7/DXTldt+Mb436guJudBghH8A=; b=z+ZhmfIeluyAZ7vvxnBwa0Z46LrBMkJNsxUlySMND/4/IAo6g1bH0U2x776GdxdT37 KGFZv/BwsgV0X2h+4cjM39lXXjH1p3twalhqBGxulA0rZ/Rg28YkGakSnPfZK+k00OTP Ta+nWIPTUA+1G9ac7nRKvtRs+3vmmIN7plbknloOnzs8LL3h8rlxuS34XlJwI4GWOQp4 2MVuh4WpA5war0x4boK4agAsolPGD1v98PZhPT6mnCem81vxf/C28hXukLf6mHGvKFuy OThMhdPo8DLh6ztGwdn2fMvpjjrXwpOVLNQH6Tyb9Huo+uim1oHAiAMuV/CPfxCiRXVB lKQg== X-Gm-Message-State: AOAM532kGHuyyCsS05v65IpoMLF1dgeDuU+PSTkA8dLJeWO1XL7HfVtd A+zmXwU+Sg6nzU76PDPFskUpFjtLJ/c= X-Google-Smtp-Source: ABdhPJwi03qK1ZV9VOpWwjVXNzCrboIXvkE07AK1H+8yFhag5kzKnREdL38PD0yNe4Pzbm7Qg5F6nGLc5oU= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:ac8:430e:: with SMTP id z14mr1441247qtm.208.1633738272984; Fri, 08 Oct 2021 17:11:12 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 17:11:04 -0700 In-Reply-To: <20211009001107.3936588-1-seanjc@google.com> Message-Id: <20211009001107.3936588-2-seanjc@google.com> Mime-Version: 1.0 References: <20211009001107.3936588-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH 1/4] x86/irq: Ensure PI wakeup handler is unregistered before module unload From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Paolo Bonzini Cc: "H. Peter Anvin" , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a synchronize_rcu() after setting the posted interrupt wakeup handler to ensure all readers, i.e. in-flight IRQ handlers, see the new handler before returning to the caller. If the caller is an exiting module and is unregistering its handler, failure to wait could result in the IRQ handler jumping into an unloaded module. Fixes: f6b3c72c2366 ("x86/irq: Define a global vector for VT-d Posted-Interrupts") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kernel/irq.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c index e28f6a5d14f1..20773d315308 100644 --- a/arch/x86/kernel/irq.c +++ b/arch/x86/kernel/irq.c @@ -293,6 +293,7 @@ void kvm_set_posted_intr_wakeup_handler(void (*handler)(void)) kvm_posted_intr_wakeup_handler = handler; else kvm_posted_intr_wakeup_handler = dummy_handler; + synchronize_rcu(); } EXPORT_SYMBOL_GPL(kvm_set_posted_intr_wakeup_handler); From patchwork Sat Oct 9 00:11:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12546725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 941EFC433F5 for ; Sat, 9 Oct 2021 00:11:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DDB960FC2 for ; Sat, 9 Oct 2021 00:11:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244003AbhJIANO (ORCPT ); Fri, 8 Oct 2021 20:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243989AbhJIANL (ORCPT ); Fri, 8 Oct 2021 20:13:11 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0128EC061755 for ; Fri, 8 Oct 2021 17:11:16 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v203-20020a25c5d4000000b005bb21580411so2035045ybe.19 for ; Fri, 08 Oct 2021 17:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=bAloFfewj/zQRYhL5ulk5e0QyHM9EAunSNgXmDCR8AM=; b=ST0iL+WBV2iExe7rpojaTs4LjOuY0fc83FuN072lnEaXnt15bunbZZxjQIpMpHk9Az pADA8vjy5X05YVjPEyR2dJhczHcLph93LPTl/FDMc5XqqvXOu0+emZe6f+l6d/0qE8eD YXCwVZPS1e3ImmfezavyIEMi22XQV8lCVEV0cvoFpHRpFjnKqRGsRxobytIg6KWRRaAo 9LCpz+qqDho/SaSTJ0fvl8nx5o51AstfZiaWitJT5cVihQ4ZWmNvMwcYFPXxCWKw9xqs 9t5joeDe09xEjni5/DNRH/qv0/YdtycZ2Qcm5Q0IIisvoZM6jRESnhO56J0slezWX3Yq X33Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=bAloFfewj/zQRYhL5ulk5e0QyHM9EAunSNgXmDCR8AM=; b=PESsivRUM53WQxmADrWomXWARcd3rNqDeFArlJ4+MWbg0zqrDT7rfQ30IvMSVoPURE HMM990gW5W+tw+0s0HHkjeVdpZDeZvkm6IdZ0phWnNTGelrQiwlIhJz46W67OB52xgiu 11CPoviVXc6EyBko5XT5fco58Ed+gRRHsQCHPpI+/VBeo/YsPQ9Nqsp4iMzHbrS9i3nl mVo43fdAvuvBjOkxSOdoU7jJx59LNZ6wNurYM5MJ9Hr0KBkeQ9tj0f1sRY0zJrD6dvMv YuZqHjE3wrH8WpqW0EZv+1oB6Ywa2lLkypgstvZ74RaKy8uam1NhqyM443IgImIdlE+s xLYA== X-Gm-Message-State: AOAM531Bh8CpI1nm+jaAqQvCdSoGMe7AiwymxEinqng5AwcOhcH2XuQi +litt9LuBcD53NbwW6j34vrRwd6yxrM= X-Google-Smtp-Source: ABdhPJzaXyLqc9LGIGZZ0X+2cVMG5q4bA4joIE0G1sjVHAYtPKe19e3qhXZKrHz4zpJSfPstsB49oxJ0V/4= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:a25:6115:: with SMTP id v21mr6954932ybb.462.1633738275190; Fri, 08 Oct 2021 17:11:15 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 17:11:05 -0700 In-Reply-To: <20211009001107.3936588-1-seanjc@google.com> Message-Id: <20211009001107.3936588-3-seanjc@google.com> Mime-Version: 1.0 References: <20211009001107.3936588-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH 2/4] KVM: VMX: Unregister posted interrupt wakeup handler on hardware unsetup From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Paolo Bonzini Cc: "H. Peter Anvin" , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Unregister KVM's posted interrupt wakeup handler during unsetup so that a spurious interrupt that arrives after kvm_intel.ko is unloaded doesn't call into freed memory. Fixes: bf9f6ac8d749 ("KVM: Update Posted-Interrupts Descriptor when vCPU is blocked") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 1c8b2b6e7ed9..bfdcdb399212 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7553,6 +7553,8 @@ static void vmx_migrate_timers(struct kvm_vcpu *vcpu) static void hardware_unsetup(void) { + kvm_set_posted_intr_wakeup_handler(NULL); + if (nested) nested_vmx_hardware_unsetup(); @@ -7881,8 +7883,6 @@ static __init int hardware_setup(void) vmx_x86_ops.request_immediate_exit = __kvm_request_immediate_exit; } - kvm_set_posted_intr_wakeup_handler(pi_wakeup_handler); - kvm_mce_cap_supported |= MCG_LMCE_P; if (pt_mode != PT_MODE_SYSTEM && pt_mode != PT_MODE_HOST_GUEST) @@ -7906,6 +7906,9 @@ static __init int hardware_setup(void) r = alloc_kvm_area(); if (r) nested_vmx_hardware_unsetup(); + + kvm_set_posted_intr_wakeup_handler(pi_wakeup_handler); + return r; } From patchwork Sat Oct 9 00:11:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12546727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34578C433FE for ; Sat, 9 Oct 2021 00:11:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B93D60FC3 for ; Sat, 9 Oct 2021 00:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244016AbhJIANQ (ORCPT ); Fri, 8 Oct 2021 20:13:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244007AbhJIANO (ORCPT ); Fri, 8 Oct 2021 20:13:14 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F553C061570 for ; Fri, 8 Oct 2021 17:11:18 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id x16-20020a25b910000000b005b6b7f2f91cso14876900ybj.1 for ; Fri, 08 Oct 2021 17:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=XhfDVnt1beDya8hVZyf7CTBukIbNlfCHrkpgQCH938o=; b=TRPXxZj4iqlwsifNPPr5NQYrh0m9NndJIcDL/e//ZaHWWqTcWAE83hNZmBtkdKIOqm ru8XS0uQ8OLgq7kE2FmDEH5Toem+oOnJtuXSUv/9M9/KeA2hcyd+OSkcDHL/prriBcq0 Gs2ydI4KAEaZRLM2yz8QQp/QXqzzu8r2z8NmmkgFOjk4JD/6+iTVU/34yGIVrFg7DOty 6I0pCtv4RHANaLD5Zi76klyVsHKh69PD+pT57BPgGn3e8pyJN1Kt4jZkLELBQHVhDBxH XMhyN2U1l5PeNqeypfS6qluZnJulwo5Q1DgXZAEre5NijdEqMo/kcUmlnHknBuZUt27d 5/Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=XhfDVnt1beDya8hVZyf7CTBukIbNlfCHrkpgQCH938o=; b=1sLOzYY93zQqncNTJZnNrao7RZgJ8m68qFtascVOAMl1Z1Wy5Z2ObXYjTKmPN2DRMm 4+GeCRtd9XCjgY4eE035PNmm13SZw1gQIUbcripksTK7+w+DuezuWIwFZ5Eyplwe1gV4 O91iTrN2DKo+gRInv03Of0pDVGsYP1HCgIGcTXiUvhNSa7Dx3UP2Ea5yhzrEgOWL9oT8 hTKfW2WjoqALuZOEwuK0hLpVVM/zCplLMy/KKdU79ktQxQ6pGGgCAAioyJ9C8b64dP7Q SVG8mxTVuC/4DDZSx79OxIXI5/BFeX1B652k/hTEdHhclBKwUAlttCLX9Q5AXq/uE7oz ihfw== X-Gm-Message-State: AOAM533HLlmglTuL8Qr3Fni4vtSWV2JEUMXCVTHb4UDqS3YaOch+e+Bi XO6X67+Ap60QAbCgikzkg7WRVyeSRBk= X-Google-Smtp-Source: ABdhPJxvoC0RVW5CYS2eGcmMKc5glkCde6sHEUyfLdTt66CAgiPbCwoMRfD3El8+WoTYw0/nrSQeKEA2mBc= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:a25:5b83:: with SMTP id p125mr6827386ybb.277.1633738277403; Fri, 08 Oct 2021 17:11:17 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 17:11:06 -0700 In-Reply-To: <20211009001107.3936588-1-seanjc@google.com> Message-Id: <20211009001107.3936588-4-seanjc@google.com> Mime-Version: 1.0 References: <20211009001107.3936588-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH 3/4] x86/irq: KVM: Harden posted interrupt (un)registration paths From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Paolo Bonzini Cc: "H. Peter Anvin" , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Split the register and unregister paths for the posted interrupt wakeup handler, and WARN on conditions that are blatant bugs, e.g. attempting to overwrite an existing handler, unregistering the wrong handler, etc... This is very much a "low hanging fruit" hardening, e.g. a broken module could foul things up by doing concurrent registration from multiple CPUs. Drop the use of a dummy handler so that the rejection logic can use a simple NULL check. There is zero benefit to blindly calling into a dummy handler. Note, the registration path doesn't require synchronization, as it's the caller's responsibility to not generate interrupts it cares about until after its handler is registered, i.e. there can't be a relevant in-flight interrupt. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/irq.h | 3 ++- arch/x86/kernel/irq.c | 29 ++++++++++++++++++++--------- arch/x86/kvm/vmx/vmx.c | 4 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h index 768aa234cbb4..c79014c2443d 100644 --- a/arch/x86/include/asm/irq.h +++ b/arch/x86/include/asm/irq.h @@ -30,7 +30,8 @@ struct irq_desc; extern void fixup_irqs(void); #ifdef CONFIG_HAVE_KVM -extern void kvm_set_posted_intr_wakeup_handler(void (*handler)(void)); +extern void kvm_register_posted_intr_wakeup_handler(void (*handler)(void)); +extern void kvm_unregister_posted_intr_wakeup_handler(void (*handler)(void)); #endif extern void (*x86_platform_ipi_callback)(void); diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c index 20773d315308..97f452cc84be 100644 --- a/arch/x86/kernel/irq.c +++ b/arch/x86/kernel/irq.c @@ -284,18 +284,26 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_x86_platform_ipi) #endif #ifdef CONFIG_HAVE_KVM -static void dummy_handler(void) {} -static void (*kvm_posted_intr_wakeup_handler)(void) = dummy_handler; +static void (*kvm_posted_intr_wakeup_handler)(void); -void kvm_set_posted_intr_wakeup_handler(void (*handler)(void)) +void kvm_register_posted_intr_wakeup_handler(void (*handler)(void)) { - if (handler) - kvm_posted_intr_wakeup_handler = handler; - else - kvm_posted_intr_wakeup_handler = dummy_handler; + if (WARN_ON_ONCE(!handler || kvm_posted_intr_wakeup_handler)) + return; + + WRITE_ONCE(kvm_posted_intr_wakeup_handler, handler); +} +EXPORT_SYMBOL_GPL(kvm_register_posted_intr_wakeup_handler); + +void kvm_unregister_posted_intr_wakeup_handler(void (*handler)(void)) +{ + if (WARN_ON_ONCE(!handler || handler != kvm_posted_intr_wakeup_handler)) + return; + + WRITE_ONCE(kvm_posted_intr_wakeup_handler, NULL); synchronize_rcu(); } -EXPORT_SYMBOL_GPL(kvm_set_posted_intr_wakeup_handler); +EXPORT_SYMBOL_GPL(kvm_unregister_posted_intr_wakeup_handler); /* * Handler for POSTED_INTERRUPT_VECTOR. @@ -311,9 +319,12 @@ DEFINE_IDTENTRY_SYSVEC_SIMPLE(sysvec_kvm_posted_intr_ipi) */ DEFINE_IDTENTRY_SYSVEC(sysvec_kvm_posted_intr_wakeup_ipi) { + void (*handler)(void) = READ_ONCE(kvm_posted_intr_wakeup_handler); + ack_APIC_irq(); inc_irq_stat(kvm_posted_intr_wakeup_ipis); - kvm_posted_intr_wakeup_handler(); + if (handler) + handler(); } /* diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index bfdcdb399212..9164f1870d49 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7553,7 +7553,7 @@ static void vmx_migrate_timers(struct kvm_vcpu *vcpu) static void hardware_unsetup(void) { - kvm_set_posted_intr_wakeup_handler(NULL); + kvm_unregister_posted_intr_wakeup_handler(pi_wakeup_handler); if (nested) nested_vmx_hardware_unsetup(); @@ -7907,7 +7907,7 @@ static __init int hardware_setup(void) if (r) nested_vmx_hardware_unsetup(); - kvm_set_posted_intr_wakeup_handler(pi_wakeup_handler); + kvm_register_posted_intr_wakeup_handler(pi_wakeup_handler); return r; } From patchwork Sat Oct 9 00:11:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12546729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8645C433F5 for ; Sat, 9 Oct 2021 00:11:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE95760FD8 for ; Sat, 9 Oct 2021 00:11:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244025AbhJIANR (ORCPT ); Fri, 8 Oct 2021 20:13:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244019AbhJIANQ (ORCPT ); Fri, 8 Oct 2021 20:13:16 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C3E4C061570 for ; Fri, 8 Oct 2021 17:11:20 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id x15-20020a056902102f00b005ba71cd7dbfso4629625ybt.8 for ; Fri, 08 Oct 2021 17:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=/g/tOaytboKKQOf+1WV4h8GWSGDE4X+3J8EYHQwrp48=; b=dM5GcUBC4uMTGPNF4YR4bnr1ZgyBMq3RrHdn3dxrMFd1OqNYwuPw0LKgXiTWm10Ago DgpK5fdXT87SdyBOo9HFnddv/ZoFYhXxr4eHhMI4P44Tj+FmTitwCVPNcNHlyGTCnct7 BgRFbVMkpmMFsmqO1Dxmph2LGVyAx/4tpwDVw/xLttAJuqUiKwT0xMqGw5rD1IpwRsM7 vLPyYBDl/1hO465P8EtQySNDbI6uJUdSQER3fjkDo/Wu5Q1sUgGEC4bllCorz6abSH9s m81z3U7B+zKGj9K5hqY6DcGYtrY5dV/VWYy77W9labka29M3wwW+5w/r0R1/XoBtcXl/ 5ohw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=/g/tOaytboKKQOf+1WV4h8GWSGDE4X+3J8EYHQwrp48=; b=oBovcggOrNMzawHO2LWtg2jzgE8Y0qsNmHs0q8MOuH51/ITCEuoyZCuCwLdWh4pOra bVupcuFGKQuIZU1ZH0uVsENZQ5AD4IC72+rj4C7YijBg24MTkDjI99dCPjdyF0t0zVFG WROjl3QzNb2JVjsO2W6Ptya2xXhEhCXqdBw213P9CcUHSFnR2qRWnlMNH9/6zjhoxAjY 363QPy7KnDEocPSl4ejWeb6VFITronRGSs2FOyDe8H6WIILCZ8uUQIGtcyBx2JfPUstP O5dg7dp54QoRdUr8kbQGiR+dc9WvDNQ3GWG/PqQ/Av7KAo/xSfhwXpVxxnA6TE+U36Wh 0fxA== X-Gm-Message-State: AOAM531n06SXgOmCD+/38YFASdG5FFDhhWTFtk19/x56ZKbDoVb3wu8O rmkMwB24aRKoO+IXa2lax7q1Kq/kk0w= X-Google-Smtp-Source: ABdhPJxJjGOM6Gbdy2LWdjKNDGtaMgEMVcgeWJJ3VdMuQ2qNKXmEiiPiaTDADxdDoZZjGQeWEzOLK8Z/hwg= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:a25:393:: with SMTP id 141mr6606723ybd.534.1633738279590; Fri, 08 Oct 2021 17:11:19 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 17:11:07 -0700 In-Reply-To: <20211009001107.3936588-1-seanjc@google.com> Message-Id: <20211009001107.3936588-5-seanjc@google.com> Mime-Version: 1.0 References: <20211009001107.3936588-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH 4/4] KVM: VMX: Register posted interrupt wakeup handler iff APICv is enabled From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Paolo Bonzini Cc: "H. Peter Anvin" , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Don't bother registering a posted interrupt wakeup handler if APICv is disabled, KVM utilizes the wakeup vector if and only if APICv is enabled. Practically speaking, there's no meaningful functional change as KVM's wakeup handler is a glorified nop if there are no vCPUs using posted interrupts, not to mention that nothing in the system should be sending wakeup interrupts when APICv is disabled. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 9164f1870d49..df9ad4675215 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7553,7 +7553,8 @@ static void vmx_migrate_timers(struct kvm_vcpu *vcpu) static void hardware_unsetup(void) { - kvm_unregister_posted_intr_wakeup_handler(pi_wakeup_handler); + if (enable_apicv) + kvm_unregister_posted_intr_wakeup_handler(pi_wakeup_handler); if (nested) nested_vmx_hardware_unsetup(); @@ -7907,7 +7908,8 @@ static __init int hardware_setup(void) if (r) nested_vmx_hardware_unsetup(); - kvm_register_posted_intr_wakeup_handler(pi_wakeup_handler); + if (enable_apicv) + kvm_register_posted_intr_wakeup_handler(pi_wakeup_handler); return r; }