Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3324063imm; Sun, 30 Sep 2018 17:50:28 -0700 (PDT) X-Google-Smtp-Source: ACcGV629natOPc7vkeQN9lbecV8pGYMY5lpc4zKJkUQLiXDNoReoXb4wQOo4id+QbmGN8wyUoPyg X-Received: by 2002:a17:902:101:: with SMTP id 1-v6mr9139951plb.15.1538355028211; Sun, 30 Sep 2018 17:50:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538355028; cv=none; d=google.com; s=arc-20160816; b=SLKjMfFyd+J2R83HJINCt8c6DIMb6qr+LpKKfhf2Y6VNT88hS1yEJ4JEdNKeAnNoEg egmwpVL2r3KU6/mQ8X2WbfJ07QbVz/RkC/8+3XjrNkPwIp2QaoHfuuAnmfDaNW0q3IiG rN79k8nalCduoCYQvZ5b83RROp4lQ5VQZLnV2/G2NW/iSHd9RnIAYlLqMDBXvjKvg3/7 jtZm73euC5SztHFESoJHB+PHzmWkfOicwqQzEQQ/dostp5f1C2w6FTL8Yl3PYt6aEzbq h5uJNtaMPQtvcmBO1O9gjAPdOr41yM3Hq74eoW6h1sOcGqF8dut5JfIzJb5F5gL8LW9o ee5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=oHCJyi6zW4RGTB4Bbj+9Goy95foR9Mt8NduAxPpOl1o=; b=Bs6HknkEtlz2Qt+Hj/hVYCgE9AULq334LOW5Kld91BRgoA03AvHYEcPZ3nruZhyZKh WlTmOWyWLd7RwFj5WdB3q/aho1Xu0qu0XykdL9vlRtzkF3aBku9zr8IEjqO3jPG4i+zq qnW6k3eYGVu5O8UNsgHIYvPNPmmO9Js3QHu7eTS0sxr9bpGSw1+q9fDm8Q4viu9n5sef AcD9gGHmT+wxuAywGGQKzph7R/SVA6TtpO3dkisFUi79gy5dQnWWHsigBS80VOKqN1LI oJ1MN+sPpdrC4AT/9hHI3nNb4pJG2MfPvZIHxzCPRi5QfoS2/zGP8pZ2dxAOYbhBTotp hfzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Mw+52nyk; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7-v6si4773785plt.11.2018.09.30.17.50.13; Sun, 30 Sep 2018 17:50:28 -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=@microsoft.com header.s=selector1 header.b=Mw+52nyk; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729408AbeJAHOt (ORCPT + 99 others); Mon, 1 Oct 2018 03:14:49 -0400 Received: from mail-by2nam03on0120.outbound.protection.outlook.com ([104.47.42.120]:46043 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726604AbeJAHOs (ORCPT ); Mon, 1 Oct 2018 03:14:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oHCJyi6zW4RGTB4Bbj+9Goy95foR9Mt8NduAxPpOl1o=; b=Mw+52nykAAQZRNIHYLucl79SA4dc/trcxH6Wquie7SsdVdUJMEUR5IU6/mFRRfyHPiLWf3tHUMMKISm+U/C6eZO5c9QOEJxXBDyVrPKMxhmoeHFEu8+6L/0IiB4RwZOVDF9IVSUWWAmzqv//mj+iV5qayHNNt/u9yUWlDCYbbkI= Received: from CY4PR21MB0776.namprd21.prod.outlook.com (10.173.192.22) by CY4PR21MB0696.namprd21.prod.outlook.com (10.175.121.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.6; Mon, 1 Oct 2018 00:39:37 +0000 Received: from CY4PR21MB0776.namprd21.prod.outlook.com ([fe80::54e2:88e0:b622:b36]) by CY4PR21MB0776.namprd21.prod.outlook.com ([fe80::54e2:88e0:b622:b36%5]) with mapi id 15.20.1228.006; Mon, 1 Oct 2018 00:39:37 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Olaf Hering , Boris Ostrovsky , Sasha Levin Subject: [PATCH AUTOSEL 4.18 63/65] xen: avoid crash in disable_hotplug_cpu Thread-Topic: [PATCH AUTOSEL 4.18 63/65] xen: avoid crash in disable_hotplug_cpu Thread-Index: AQHUWR8aYUHyxCu1GEyoAuh1nfx0aQ== Date: Mon, 1 Oct 2018 00:38:42 +0000 Message-ID: <20181001003754.146961-63-alexander.levin@microsoft.com> References: <20181001003754.146961-1-alexander.levin@microsoft.com> In-Reply-To: <20181001003754.146961-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CY4PR21MB0696;6:IfzYTaEyaKC/Ix3Ktzs4Yzzmo2uZ2k5yKP4jqDvUprrdCdt1BgTp2lPqJIcmT5YP/XesXjqIKbcnznw4uCv48gI6f2xjASpX5/3RrbHxbWp7kjkgj8C6mopt3oXGWrXgdfLj5s6iY7Z4VkzslJPAkkgrCon+Ep7ulovcyH77r0MdzBE/5gTdi4D32ZJeiQNetXag97iVviyg+LyPEJFyIlbWJPZtru0uCjk9ybXKntndMDtLXBuuJOoEcyBvRnucpsJ/QD342KTwTk5FAGgw99ClMdn95T0eXJgtX/t9NdqUmqZN96ILE4oXsjrS2uDB0AM3riLX2lp6gDilm0qzjqVG7/A9EO3eIPO82A7tEeeJNAdSofhFnTWnfyVp71yNehFfCM6qPwHXyq+LHfXygtpPAXOx5VMFBfNFixERjggi+TAexFyiGk/ya0SXNFe+7loircLP9J2N9gUtlZARXw==;5:TLVnACnb2FikOv1lxLKIUjD29D29vY8laJkxxh1annq1Cb+gcoPXgjCtbye3EBbtByypa5Cb4hZs8bj4bHl0P3wAXUYRnLIEfahGCTluKz9RpmNJ7KR4HdT3RLEMpddUCTTReKfXzVY8KG8RY/rfSzm+18/8ojolkvMdhtZQCdc=;7:GaRJ4tVT0PMtXAHN5BJFHcoD2P8DP5c85dpXUQmVM6cnn+/d8A2W1qddCQ1uCabQDMbkAC+dBZ1w2x0ameRNmR21rJ5ANeIB9dQLJZmGqSGENLzPEnVAF1PLn9p1VkGJH+ucpLDIorvFVn+mmjSC2ljGW9P/fawBV2Qii514Vp7EkVNHCAslYgoidoadCht/fbErdOuYML5NmLLvIkkvuZzivCZLj2K8vwLMseDNd+M0JK8Eo4uYt1+QXiqyiqUI x-ms-office365-filtering-correlation-id: d8fc9255-063a-471a-9d26-08d627365d8a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7193020);SRVR:CY4PR21MB0696; x-ms-traffictypediagnostic: CY4PR21MB0696: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(146099531331640)(28532068793085)(89211679590171); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231355)(944501410)(52105095)(2018427008)(93006095)(93001095)(10201501046)(6055026)(149066)(150057)(6041310)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991041);SRVR:CY4PR21MB0696;BCL:0;PCL:0;RULEID:;SRVR:CY4PR21MB0696; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(39860400002)(396003)(346002)(136003)(366004)(189003)(199004)(3846002)(6116002)(5250100002)(71200400001)(97736004)(217873002)(71190400001)(1076002)(76176011)(6506007)(99286004)(11346002)(26005)(86362001)(36756003)(2501003)(446003)(2906002)(86612001)(102836004)(2616005)(476003)(14454004)(107886003)(10090500001)(14444005)(4326008)(34290500001)(316002)(486006)(22452003)(256004)(186003)(66066001)(53936002)(305945005)(25786009)(2900100001)(106356001)(6486002)(105586002)(7736002)(6512007)(81156014)(81166006)(6666003)(8936002)(8676002)(5660300001)(68736007)(54906003)(110136005)(6436002)(10290500003)(72206003)(478600001);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR21MB0696;H:CY4PR21MB0776.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: yPJj6bt0Z7M8JQBDniva123wsfiYkjJK5tFsVrQqJgZQ2z/noPaHR/KMwC7x6qS9+dWByoYfI9QfAVWCFtbPv/KJc4bgc3IskoHUirgD0ACJKTlh+8h9EI1t1MwVW2mvb9sEbnpkkcOcl62W/L2eOrbu+wY+KX7Oipbv2o1dPuPuW5FI4hfKW0rfjL+eMw+Z3rrj9FJxk+u85tIkiu3GcdMc8uqwN026YTHUpj7aF2GDM4XPGdupJJod3zmeU4+Lyj2B19kZRKkF2rsGgwQ9bz6q6I52R9giqA6hiDc9VuVIGOQb6duumUNEHsOvPLJgpEZLMYNsJcSU++Ji+QMdoA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8fc9255-063a-471a-9d26-08d627365d8a X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 00:38:42.0821 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR21MB0696 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 0= 0 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:000000000000000= 0 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 --- drivers/xen/cpu_hotplug.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/xen/cpu_hotplug.c b/drivers/xen/cpu_hotplug.c index d4265c8ebb22..b1357aa4bc55 100644 --- a/drivers/xen/cpu_hotplug.c +++ b/drivers/xen/cpu_hotplug.c @@ -19,15 +19,16 @@ static void enable_hotplug_cpu(int cpu) =20 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(); } =20 static int vcpu_online(unsigned int cpu) --=20 2.17.1