Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3932859imm; Mon, 8 Oct 2018 11:55:14 -0700 (PDT) X-Google-Smtp-Source: ACcGV60JmT8KiwexagEYM15ey+/UY3zgIq+8SDN9npJF+4bW0mNkbcaFYvHp/NADwlmfI43wkEEs X-Received: by 2002:a63:5747:: with SMTP id h7-v6mr22390076pgm.423.1539024914513; Mon, 08 Oct 2018 11:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024914; cv=none; d=google.com; s=arc-20160816; b=iQjYn5PuSYNbjpChcDUbut33TnSa/6Ael8P7l3j1nL6Ab94VO0b152IWfQIFA5AJ6r YaQkl3V8Lx0PZ2tOuYgHN7oTbJs0CeVINtEsy3SekN8Mn/Yjwm1QEOP4bI1TYKA8KL2O s1XJGxsOlWt98hGc5l6dBLN4e905fau6zxidmRitZ/lnlbGbmX4Dqd9FYgeT/E86/EPM ZZRwZxQH3B6SZN+3P//z4KlivGKtcFYyS9VV9MwDEP5Txts0mov+FDBkl4rEgTd4bBhD BdspKU4zO4ggpAxineLkLSZvpvctWZU+JA9nqMedvrfO8GQevYnp4q8dpXuZw+p85bdf QcVw== 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=BhuUHsrLb0r3I5oX1BGz6JZlzZXs5TbiRtCepD3VKbE=; b=XnKpe2aLdkRK5VhD0YhKHs5y8r5aSbyQBjUBBgW/ayMbLzXJD5kpGQNu0y0Ri+HryN D3um7tLTOrnD7gZQV71fz0pV2XBwrAcQyAGZ0lrfkmdUhawoP2W+8mDvKpg/6mcxkJwr oUbIV5e1bca82lljXRRRRMER98n50qCwFRmT9nb+8wqoAnmKgG6Lw+rN5kdTUtipzlam ijAd3n2YE0C/ABhYCRkjcu8te++A2pP3nh25q97ckE1y9SZJEwuPgsnSA1MEYtygNoZC wRNQVEOdVI69/9sNCQiKUzChfkwtIOev7/OPZ9GtSkSdwuF51Os1B1tFQOQ7zCg6Lb3G 3fKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xgJWYpTP; 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 r12-v6si1928793pga.346.2018.10.08.11.54.59; Mon, 08 Oct 2018 11:55:14 -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=xgJWYpTP; 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 S1732800AbeJICGw (ORCPT + 99 others); Mon, 8 Oct 2018 22:06:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:57270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732269AbeJICGv (ORCPT ); Mon, 8 Oct 2018 22:06:51 -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 84652204FD; Mon, 8 Oct 2018 18:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024823; bh=lpv9k0VRBQ7nlSHmSE+6FJNBJC1YmFYYFzbaGKQiMfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xgJWYpTPkmupI80GiZKNhZpj6nJxQ4/YhV+vkoFeQCcxFVeCMFtTVfPUR6GDZttkw vD7KOC2oMIIuyHsrNdto8aGlGDXDtaL/Cp1czXn0xjJgDAvN2B38DEiGKqrMydrfGo 4+omuqo3s8cooDoGA1LODidsyz1T+BHBZN6jhgD8= 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.18 141/168] xen: avoid crash in disable_hotplug_cpu Date: Mon, 8 Oct 2018 20:32:01 +0200 Message-Id: <20181008175625.392700786@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@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.18-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)