Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5579322img; Wed, 27 Mar 2019 11:04:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwauHJWiqGVJ4gT0PfvGWQmOIvneVEDNVFlfbxJj4oeUGbcLO+ergqXguUnpE7hi2NhG6xT X-Received: by 2002:a62:1a0d:: with SMTP id a13mr2365790pfa.198.1553709855463; Wed, 27 Mar 2019 11:04:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553709855; cv=none; d=google.com; s=arc-20160816; b=B/42C+QbvJnAImSh+pBBeQJY3vvE/hWCWUf2mZFP7tTMWvXfiszt8ppDzyrtGljSaC 5lGWs2QO9ImQLybLwncOHllyC9M0sG105fC3HE7omFWKU0WLz95qmzqd7UQ68nEs5Jc0 RxZy2j5pzXCMBiQTlGCSRNupQbm+1WXjwSpRDcLGypX1f2wW1F4uvN6wpHjbAoy5NDQ1 1mGwwKFmlm89e2rFbwCuf4GuCfE9UEHZ+qq4JmhrXR37JFpa0YhnOvqqxmxrHxTh90i/ BbSVpevXWNXwQWj/yXEjswd7TLOcNOGaX2P0Zyh5VfFdZBUoXW0ox5hHxZL5OVReH4WU 7rKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LKF69VCJEq5G8AR5T0DWhKUOrNrzQStU1/bbeeIm2pM=; b=0F5Pbt05NYswM7EZJ+GlyxfGrHEB1iqRe2E0HAPcZ0hzbR/OTqizobGkXCqbelv4oH VuxhDFdF1XAvpLjLvQ+H4kzZhTxBPG2GCNJHMz+9ezLMbJ/ImzrtfE9ilMKO7iPbnaye hwYZ4u2VHJ/bcb0yVB/nT1J2YpBarT9d54pOYBqhJxpIGwyOwCpFidAsMaN/l3JH0wOn mgQtkNeK4bh2Y73kmnCSyoLxKoLOLAaATCDPgCd/Gh3oRJwZyl8JlkzQCWMYKTNdvspN 8QARvtnCTDvgqD3jo7vDhWLwA3YSjcupuNfPuKXw4ZKSVsjEDYwQktsAQ0xWHy8kdIC+ Dddw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HnYiaGT6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7si19358043plr.73.2019.03.27.11.03.59; Wed, 27 Mar 2019 11:04:15 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=HnYiaGT6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731513AbfC0SCr (ORCPT + 99 others); Wed, 27 Mar 2019 14:02:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:42670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731250AbfC0SCp (ORCPT ); Wed, 27 Mar 2019 14:02:45 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE2DD2087C; Wed, 27 Mar 2019 18:02:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709764; bh=PUA1LnDi4edmet7U8OlkBDruuRPientmusEN8OTIQis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HnYiaGT6mdbM8o+bofFzx/WzFTxUYvIJjT0ygiJ9CqG5lKo65f3Jdt15u4g8rf5QY 4rCer/u0rKHLqRoOhgtKEY0qAYM2GH9WkWLv1oVVEPnuket3DvnneJ1YbUkK4IDEAF kuw/v+ICJKQwbj2mZRRhtrBLTe3nhfLshHBPSNW0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kairui Song , Thomas Gleixner , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Sasha Levin , Borislav Petkov , "H. Peter Anvin" , Vitaly Kuznetsov , Dave Young , devel@linuxdriverproject.org, linux-hyperv@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 028/262] x86/hyperv: Fix kernel panic when kexec on HyperV Date: Wed, 27 Mar 2019 13:58:03 -0400 Message-Id: <20190327180158.10245-28-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kairui Song [ Upstream commit 179fb36abb097976997f50733d5b122a29158cba ] 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 Signed-off-by: Sasha Levin --- 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); -- 2.19.1