From patchwork Fri Dec 16 22:30:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 9478607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D6EAD607EE for ; Fri, 16 Dec 2016 22:31:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C831828581 for ; Fri, 16 Dec 2016 22:31:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCE002866B; Fri, 16 Dec 2016 22:31:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B228328581 for ; Fri, 16 Dec 2016 22:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762101AbcLPWbP (ORCPT ); Fri, 16 Dec 2016 17:31:15 -0500 Received: from mail-pf0-f172.google.com ([209.85.192.172]:36457 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753596AbcLPWbD (ORCPT ); Fri, 16 Dec 2016 17:31:03 -0500 Received: by mail-pf0-f172.google.com with SMTP id 189so15989047pfz.3 for ; Fri, 16 Dec 2016 14:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=10ufklCG6ZxIlDEChkRZqc2AqE5KTeal4phEGZ8+PNI=; b=aexhuWK5ygM6IICNhd5+wb+eoA0ehHBy6JFZyoRXUQFTL9wOhVtRvnuPfU0djfL2uy YYMeeyGcjkNfzuB4RemL1woiJuHcdvj1x6LpzRIgQ7VX8PjvRZgepTvzT5KkLfn8qBJ7 hM3UIq8po/GzTKMqViELGp15APgRIK8FDJO1/vbbjUZlyTJJ1hTCDQ2HD6k0xCRUaP2W aaa7Vb6sflGUefpk1xSv54vHQzZ2VO1j5ABZmC9wQQbPdUvmuG/sJplD8VMzPWL5ZbiO Fq13JZyEJB7rfm3S1Aua+rYoWu9yhCAkwbN3I7h6Zh0Wy6kaK8ohKEstt0jJcvXL4blI 5O/w== 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=10ufklCG6ZxIlDEChkRZqc2AqE5KTeal4phEGZ8+PNI=; b=WdOF9o5ygMVKRj/zlf3PXD889vbRCzmQt93J/tGI1yDo0vNEgWfey/jT0h5TS5Gmwz V42FGXFNaXq7pNaOEvESpFX9kpMNd+v30azg+E7eNwoopU19VycoR9G/0gRpmYNH9CNi 2qII9Av8UKCozpn/1hFLKfZ9EU39FYvVAknChjuFjAZieyEU0V7YJjy8aKAy8hgQsXoE sJ62MhitJmd2WX6vUfU0bRkkExdpr/fbm6/ZUpdomO/YwztDaRyydx/pbwYbepLZptT3 96AnmTe6tU8O2jDGywRc8p+/etZcRQb2zLLGcMD2MkxJdO5LHtGcEuHtizSFPZI/Ue1F y8jQ== X-Gm-Message-State: AKaTC009cqlxw9evITtx8MZNDpExKVMSx/ZmzO0OK2KsB4ASboy0ljHHFPZr9WS/HhtiVvYW X-Received: by 10.84.216.24 with SMTP id m24mr11615114pli.26.1481927461951; Fri, 16 Dec 2016 14:31:01 -0800 (PST) Received: from dmatlack.sea.corp.google.com ([100.100.206.82]) by smtp.gmail.com with ESMTPSA id u3sm14103510pfk.3.2016.12.16.14.31.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Dec 2016 14:31:01 -0800 (PST) From: David Matlack To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, peterz@infradead.org, haokexin@gmail.com, mpe@ellerman.id.au, yongjun_wei@trendmicro.com.cn, rusty@rustcorp.com.au, jbaron@akamai.com, David Matlack Subject: [PATCH 2/2] KVM: x86: flush pending lapic jump label updates on module unload Date: Fri, 16 Dec 2016 14:30:36 -0800 Message-Id: <1481927436-104568-2-git-send-email-dmatlack@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1481927436-104568-1-git-send-email-dmatlack@google.com> References: <1481927436-104568-1-git-send-email-dmatlack@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP KVM's lapic emulation uses static_key_deferred (apic_{hw,sw}_disabled). These are implemented with delayed_work structs which can still be pending when the KVM module is unloaded. We've seen this cause kernel panics when the kvm_intel module is quickly reloaded. Use the new static_key_deferred_flush() API to flush pending updates on module unload. Signed-off-by: David Matlack Reviewed-by: Radim Krčmář --- arch/x86/kvm/lapic.c | 6 ++++++ arch/x86/kvm/lapic.h | 1 + arch/x86/kvm/x86.c | 1 + 3 files changed, 8 insertions(+) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 34a66b2..1b80fa3 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2426,3 +2426,9 @@ void kvm_lapic_init(void) jump_label_rate_limit(&apic_hw_disabled, HZ); jump_label_rate_limit(&apic_sw_disabled, HZ); } + +void kvm_lapic_exit(void) +{ + static_key_deferred_flush(&apic_hw_disabled); + static_key_deferred_flush(&apic_sw_disabled); +} diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index e0c8023..ff8039d 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -110,6 +110,7 @@ static inline bool kvm_hv_vapic_assist_page_enabled(struct kvm_vcpu *vcpu) int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data); void kvm_lapic_init(void); +void kvm_lapic_exit(void); #define VEC_POS(v) ((v) & (32 - 1)) #define REG_POS(v) (((v) >> 5) << 4) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8f86c0c..da386bf 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6007,6 +6007,7 @@ int kvm_arch_init(void *opaque) void kvm_arch_exit(void) { + kvm_lapic_exit(); perf_unregister_guest_info_callbacks(&kvm_guest_cbs); if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))