Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1432588imm; Thu, 6 Sep 2018 23:31:53 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbRFpgtX60zAEAyyWpAb+JcG2rxtlbExVkEepplS7+v6Bta5+GmO2CQkXQ2jPpZGpo8L6DJ X-Received: by 2002:a17:902:6b83:: with SMTP id p3-v6mr6493431plk.133.1536301913651; Thu, 06 Sep 2018 23:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536301913; cv=none; d=google.com; s=arc-20160816; b=KKTDyVdsrelbhiw9jyALsMy6Mi8DHFthWisU7mLMq/WKRYD0Xa7C2YQwsRaEdNLHn4 AZIi9jO+vIV0FhxeXFl+u4Eul82RZlSYdhPhgw+/VKglOmm0O9Rq6utSOmtDouEit/l8 /wXSNOhoiSanSL5pQwOqs/VhiExfIBVVAXsVoscfi4tHNGVDh3tXnCofJi0+ZB1ETdK8 EtJCZFwQbDLVI4SpTUGjwLi6lKX+1vNPDJp1aZPzbUBftxplMD5u6OaMVvAAo9Y38GhB Ngk0kusZDBZRuiQU3/uKZXO35+ISTAF3QsW001z+ywUWuFrd9S9IDTNLjL/mey8sGtaY VpKw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=cwEJ9C8V6KAN2Ttw1o9DQLmvSmDwpPXA3xq2qVepOkM=; b=1BO9dVUy7RuJ3JAL9d0f1Zz9nqG32Jz+hW+8NYfkOxiOsH90EMh2xClXwkzk4gJQer W9RUsp0um6nbx6AyKAHtiYjFWF2gQqi6mogu1W9kY55HrrtRhFpn/Qq89bx7qvirrpcg GqlevyEIAwpVeYqZQRl5dyfLnacsiHXhDcblSClhdiHPFQZCwXRY030HXkoC07P3kH4N 7nSn7fqgHy1lKvR1ULlbzsi1PAg2BsadNqtBQsWjw/szur+iUaV7zLPlczRSu319SFvM puNgI7msJ97Va3z7Lqs3WudG6KeJ1YdzZtlofb3c2Un/JytoWQGxE2c+6Ufqj5bTgyJR MrwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@aepfle.de header.s=strato-dkim-0002 header.b=ffCahTeD; 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 5-v6si7517548pls.431.2018.09.06.23.31.37; Thu, 06 Sep 2018 23:31:53 -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=fail header.i=@aepfle.de header.s=strato-dkim-0002 header.b=ffCahTeD; 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 S1727529AbeIGLJz (ORCPT + 99 others); Fri, 7 Sep 2018 07:09:55 -0400 Received: from mo4-p01-ob.smtp.rzone.de ([85.215.255.54]:13588 "EHLO mo4-p01-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726017AbeIGLJy (ORCPT ); Fri, 7 Sep 2018 07:09:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1536301826; s=strato-dkim-0002; d=aepfle.de; h=Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=cwEJ9C8V6KAN2Ttw1o9DQLmvSmDwpPXA3xq2qVepOkM=; b=ffCahTeDft1nuzwN9V4VT0UoGZRJrN3iK0QaQb8TrwUnp17t2QylMWMwc6uH+yQQ3y V1hJ1k6qoEPyLUTp75EIqrhHAJtIdCnwNZGEJEIQrolciCGMq9/vdAJmTR+u+f2b/Ogr mYB8jPul8gQe2Ok+9GVtdxN5Dk56Jk5ktjQ94BlhPN+zhhAOCJqTMGapvzH71dZzmAlq nA/cL9D5A7m7vDjv1mHfRyFtsnUGF12Jg2Q/qvKp6sBqnWS0uJdNPzCcTDth27Pjco+j RaId4NjV8GZG0CN33JqpedAwm8LDvpNT2G+GmYJTNsZGtUFGhO3jKBy1ZERZnD45lf5b JYyw== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgc0/lb4QMstw0mqi/C51hpW50R4vli8caicjAbM" X-RZG-CLASS-ID: mo00 Received: from sender by smtp.strato.de (RZmta 44.0 AUTH) with ESMTPSA id L0862bu876UPD8e (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Fri, 7 Sep 2018 08:30:25 +0200 (CEST) From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Boris Ostrovsky , Juergen Gross , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3] xen: avoid crash in disable_hotplug_cpu Date: Fri, 7 Sep 2018 08:30:23 +0200 Message-Id: <20180907063023.16913-1-olaf@aepfle.de> X-Mailer: git-send-email 2.16.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Olaf Hering --- drivers/xen/cpu_hotplug.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/xen/cpu_hotplug.c b/drivers/xen/cpu_hotplug.c index d4265c8ebb22..68f9f663da08 100644 --- a/drivers/xen/cpu_hotplug.c +++ b/drivers/xen/cpu_hotplug.c @@ -19,11 +19,15 @@ static void enable_hotplug_cpu(int cpu) static void disable_hotplug_cpu(int cpu) { + if (!cpu_is_hotpluggable(cpu)) + return; if (cpu_online(cpu)) { lock_device_hotplug(); device_offline(get_cpu_device(cpu)); unlock_device_hotplug(); } + if (cpu_online(cpu)) + return; if (cpu_present(cpu)) xen_arch_unregister_cpu(cpu);