Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4478843imb; Wed, 6 Mar 2019 14:35:24 -0800 (PST) X-Google-Smtp-Source: APXvYqwzAOKBrIAM2klhXJ4hbE4vrwVSbFJrmBPp1VeZKUrlQq67cUETzrF5IHF4YYKVcfvLjUwc X-Received: by 2002:a65:5142:: with SMTP id g2mr8436353pgq.149.1551911724703; Wed, 06 Mar 2019 14:35:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551911724; cv=none; d=google.com; s=arc-20160816; b=vj895BFCWkLNekRhelPI/zCkZmgJrDUC1rSbwqYWb9xPECnV8LTE+Z2mNg860HO9G8 Q8XZlwgO38CLAOlVROLD+dJU4jFMowQB8zS8k1JvEv1xZcbygGLiApV/Ux6y541bXVTK J9rS9vqOiJ1/oNFQMa3RhcppBn8nWkHTIXsa0BP+rL/gJ9YGUsSAHwqDWYd87D2gdJx3 7hEzJMMOuJAPQd9Vkf2D+/bQSDozzOFKE/5UXpFwiC7hlyBAqUzxXuss5WTE5ihuTEjL qZrEtvSs8iBX5MT++wgR/Dlr46FoRRkP4kobOr1ehniLy+IuhGegV2l5ZnzRgAlKA1Yu D/gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=8D7Sf0mD6YxbnM03UcMbBrIRmstH4Tr5Ao51x/UVvSA=; b=Qos7iKPJ2pEQVd3mHeLHeseeUyME01k//3tZZx8yixpu417iFR3iqso0Dg8+GmG9Zp 0zJ7F2Q4lp19jnfU1+xpVsfSCyKN8PrH4B5BoFxo4YR1p1xzGAVbQUKoHGbuU4YDb4k8 YPpBmWYxW5zeU1b4IgGzY15kD/iPXzHvQPr/tn54eGWxOMsH7/U1phwO4ZTvWB+cDDRy jsIy0Kr0UGIPG9Ljpiu5JYNw2cv8QBsHMwkTKpV1c/L+Kmph7kJzHjTjpLpEOCmsZ6hJ AT1C9EFQpAb5z3tINeYwA/3uEyZIJhKZJ21ssicsnTItU5ElHBQLkb/+4VWFaEPbR/Kr P3Eg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d16si2293840pgb.443.2019.03.06.14.35.09; Wed, 06 Mar 2019 14:35:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727465AbfCFWem (ORCPT + 99 others); Wed, 6 Mar 2019 17:34:42 -0500 Received: from terminus.zytor.com ([198.137.202.136]:51011 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726715AbfCFWem (ORCPT ); Wed, 6 Mar 2019 17:34:42 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x26MYT1a1911782 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 6 Mar 2019 14:34:29 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x26MYSPg1911778; Wed, 6 Mar 2019 14:34:28 -0800 Date: Wed, 6 Mar 2019 14:34:28 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Kairui Song Message-ID: Cc: mingo@kernel.org, tglx@linutronix.de, vkuznets@redhat.com, bp@alien8.de, linux-kernel@vger.kernel.org, dyoung@redhat.com, kys@microsoft.com, haiyangz@microsoft.com, kasong@redhat.com, sthemmin@microsoft.com, sashal@kernel.org, hpa@zytor.com Reply-To: dyoung@redhat.com, kys@microsoft.com, sthemmin@microsoft.com, sashal@kernel.org, hpa@zytor.com, haiyangz@microsoft.com, tglx@linutronix.de, mingo@kernel.org, bp@alien8.de, vkuznets@redhat.com, linux-kernel@vger.kernel.org, kasong@redhat.com In-Reply-To: <20190306111827.14131-1-kasong@redhat.com> References: <20190306111827.14131-1-kasong@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/hyperv: Fix kernel panic when kexec on HyperV Git-Commit-ID: 179fb36abb097976997f50733d5b122a29158cba X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 179fb36abb097976997f50733d5b122a29158cba Gitweb: https://git.kernel.org/tip/179fb36abb097976997f50733d5b122a29158cba Author: Kairui Song AuthorDate: Wed, 6 Mar 2019 19:18:27 +0800 Committer: Thomas Gleixner CommitDate: Wed, 6 Mar 2019 23:27:44 +0100 x86/hyperv: Fix kernel panic when kexec on HyperV After commit 68bb7bfb7985 ("X86/Hyper-V: Enable IPI enlightenments"), kexec fails with a kernel panic: kexec_core: Starting new kernel BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS Hyper-V UEFI Release v3.0 03/02/2018 RIP: 0010:0xffffc9000001d000 Call Trace: ? __send_ipi_mask+0x1c6/0x2d0 ? hv_send_ipi_mask_allbutself+0x6d/0xb0 ? mp_save_irq+0x70/0x70 ? __ioapic_read_entry+0x32/0x50 ? ioapic_read_entry+0x39/0x50 ? clear_IO_APIC_pin+0xb8/0x110 ? native_stop_other_cpus+0x6e/0x170 ? native_machine_shutdown+0x22/0x40 ? kernel_kexec+0x136/0x156 That happens if hypercall based IPIs are used because the hypercall page is reset very early upon kexec reboot, but kexec sends IPIs to stop CPUs, which invokes the hypercall and dereferences the unusable page. To fix his, reset hv_hypercall_pg to NULL before the page is reset to avoid any misuse, IPI sending will fall back to the non hypercall based method. This only happens on kexec / kdump so just setting the pointer to NULL is good enough. Fixes: 68bb7bfb7985 ("X86/Hyper-V: Enable IPI enlightenments") Signed-off-by: Kairui Song Signed-off-by: Thomas Gleixner Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Cc: Sasha Levin Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Vitaly Kuznetsov Cc: Dave Young Cc: devel@linuxdriverproject.org Link: https://lkml.kernel.org/r/20190306111827.14131-1-kasong@redhat.com --- arch/x86/hyperv/hv_init.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 7abb09e2eeb8..d3f42b6bbdac 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -406,6 +406,13 @@ void hyperv_cleanup(void) /* Reset our OS id */ wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0); + /* + * Reset hypercall page reference before reset the page, + * let hypercall operations fail safely rather than + * panic the kernel for using invalid hypercall page + */ + hv_hypercall_pg = NULL; + /* Reset the hypercall page */ hypercall_msr.as_uint64 = 0; wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);