Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3944849imm; Mon, 8 Oct 2018 12:05:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV61pgwMzQWX7WsIe035n9fUsa6bOsIwNSKfKliGrxKtrPefHHlb/Nw4DUbC39BAjLAcsp2fa X-Received: by 2002:a63:3e06:: with SMTP id l6-v6mr21293870pga.96.1539025555433; Mon, 08 Oct 2018 12:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539025555; cv=none; d=google.com; s=arc-20160816; b=Q1BYphfn+4NYEdfBlE2o3fihafWlL11r6KkrCVTITxEiZLZISyq7fr0BnMz9LHTDSc keGo7OAdGrKPHfxMDozbX1884LNO7l9L3wv2PAEwxDbfyIQsNWknzJQ1Pf47aaQKDtaM 8FZ1pugc3jHdCvzPyiHjqPHDBGDYaTzaRHr4pRAtPoch4v7ItrWLrn5r1WWOLgB2Ai3U dtnYU2cC23iDDBhMp0pGbwiKy7rYXYLQ8a/vG5Gz5luxosnNkMo/zdOYwgmHlxIK2M8G dAdTIrp2+B7hQFlFIQ8lXa8C2Lr69LpDf0b5Fu2oZnzTwO7nYNDfu9LHq+2pyfv5xZx4 1QLA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IA65L6WAOoN2E3kb0yH0PVPX4x5MTZlh6ipYXTGvgqQ=; b=M2mcY57kg5jk+RZCKXOqCZ0ZTgkH7cQxG7oCoQWGmmphDznN9Q3I+J1B7uZzrtwnDy Ee4PISRea8VMUXkkhSGsnTwrnOncmWsDOP/B4lslCtM36rMiMjFnnxEI8m3Q2o2bB2v8 ZFugZptff46iyttZ0TD/1HiHAjKVN2xPfJ1xMbt9j7X5swnqBslgPz8v/p86IQ/3qSHV tDe0DaP40QX1pH1EiKV7jMqIpm6T3tNrHz0Ml7APIADBoCaHCTP7YVdLELra5Izwhwoc O3bDUPGedfSRTpjPLIpKJknlu2fd/efYE6RjIko9ghZ9cy5FuOSjH0GBcQz8J2XRWYJV jVyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IvbFToik; 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 g17-v6si18409915pfo.130.2018.10.08.12.05.40; Mon, 08 Oct 2018 12:05:55 -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=IvbFToik; 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 S1730751AbeJIB5d (ORCPT + 99 others); Mon, 8 Oct 2018 21:57:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:45466 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728026AbeJIB5c (ORCPT ); Mon, 8 Oct 2018 21:57:32 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 49A8A2064A; Mon, 8 Oct 2018 18:44:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024266; bh=WEvr1WTZ4LEYJpfVPbJvGgz7B+Hs2YbWyaAiYgAAaj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IvbFToikPDBEO7cUZBmJqEnOMrPMTf43DcQIchJpXqxvEzsQKaqVq4Ww9ZZysnAwg scnsov69PIuKK/OQ2JuRTwnOQuXMe3fvFJzof7WyvUfB1jYMMHVmjKHUt+TNazW/OM vSzsuibWAUd85iRn/rV0UJ10E6sXiBnQxKo+L+HI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Olaf Hering , Juergen Gross , Boris Ostrovsky , Sasha Levin Subject: [PATCH 4.14 77/94] xen: avoid crash in disable_hotplug_cpu Date: Mon, 8 Oct 2018 20:31:58 +0200 Message-Id: <20181008175610.196887565@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175605.067676667@linuxfoundation.org> References: <20181008175605.067676667@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Olaf Hering [ Upstream commit 3366cdb6d350d95466ee430ac50f3c8415ca8f46 ] The command 'xl vcpu-set 0 0', issued in dom0, will crash dom0: BUG: unable to handle kernel NULL pointer dereference at 00000000000002d8 PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP NOPTI CPU: 7 PID: 65 Comm: xenwatch Not tainted 4.19.0-rc2-1.ga9462db-default #1 openSUSE Tumbleweed (unreleased) Hardware name: Intel Corporation S5520UR/S5520UR, BIOS S5500.86B.01.00.0050.050620101605 05/06/2010 RIP: e030:device_offline+0x9/0xb0 Code: 77 24 00 e9 ce fe ff ff 48 8b 13 e9 68 ff ff ff 48 8b 13 e9 29 ff ff ff 48 8b 13 e9 ea fe ff ff 90 66 66 66 66 90 41 54 55 53 87 d8 02 00 00 01 0f 85 88 00 00 00 48 c7 c2 20 09 60 81 31 f6 RSP: e02b:ffffc90040f27e80 EFLAGS: 00010203 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000 RDX: ffff8801f3800000 RSI: ffffc90040f27e70 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff820e47b3 R09: 0000000000000000 R10: 0000000000007ff0 R11: 0000000000000000 R12: ffffffff822e6d30 R13: dead000000000200 R14: dead000000000100 R15: ffffffff8158b4e0 FS: 00007ffa595158c0(0000) GS:ffff8801f39c0000(0000) knlGS:0000000000000000 CS: e033 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000000002d8 CR3: 00000001d9602000 CR4: 0000000000002660 Call Trace: handle_vcpu_hotplug_event+0xb5/0xc0 xenwatch_thread+0x80/0x140 ? wait_woken+0x80/0x80 kthread+0x112/0x130 ? kthread_create_worker_on_cpu+0x40/0x40 ret_from_fork+0x3a/0x50 This happens because handle_vcpu_hotplug_event is called twice. In the first iteration cpu_present is still true, in the second iteration cpu_present is false which causes get_cpu_device to return NULL. In case of cpu#0, cpu_online is apparently always true. Fix this crash by checking if the cpu can be hotplugged, which is false for a cpu that was just removed. Also check if the cpu was actually offlined by device_remove, otherwise leave the cpu_present state as it is. Rearrange to code to do all work with device_hotplug_lock held. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross Signed-off-by: Boris Ostrovsky Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/xen/cpu_hotplug.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) --- a/drivers/xen/cpu_hotplug.c +++ b/drivers/xen/cpu_hotplug.c @@ -19,15 +19,16 @@ static void enable_hotplug_cpu(int cpu) static void disable_hotplug_cpu(int cpu) { - if (cpu_online(cpu)) { - lock_device_hotplug(); + if (!cpu_is_hotpluggable(cpu)) + return; + lock_device_hotplug(); + if (cpu_online(cpu)) device_offline(get_cpu_device(cpu)); - unlock_device_hotplug(); - } - if (cpu_present(cpu)) + if (!cpu_online(cpu) && cpu_present(cpu)) { xen_arch_unregister_cpu(cpu); - - set_cpu_present(cpu, false); + set_cpu_present(cpu, false); + } + unlock_device_hotplug(); } static int vcpu_online(unsigned int cpu)