Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4563760imu; Tue, 29 Jan 2019 03:53:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN6TOkEErWbcoYoW0aa61N8NwUzKU7xTVe/9IRbadPiPxN8pXhqJClnCPf20RyVaRf5mMlKB X-Received: by 2002:a65:4683:: with SMTP id h3mr22424745pgr.225.1548762793732; Tue, 29 Jan 2019 03:53:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548762793; cv=none; d=google.com; s=arc-20160816; b=i5CCk9ygTx8yyowZZIP0Rozzo9nEMl3L+nAd9CbttRTosDIRQmcbeMzVvcax8rnrJg VwZ7bz+iOSu886IvPThwn6Du7YdtFDNYgXWX2ddE6IJhlj1DsbJX5VKvi91qKAfjIfIu ZF/d96BE1jJtWwKjhhRt4hpV9rV7XQHNakstxNQfefqYujMFTWqVwz/3S5kl/C1YKT8R +xkLTVqe+gry8A+xUynPs4UjFphdzUy+77jovcL1+fDaobVMKUpsv2zxi78CjU6py/uo 2j5wBSgvmUiHfh/W4YIDdAFbxslGI2TclL+4AXv887j1AjvREHmWc8c4h3ILrZ2uTJuy S8AA== 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=BNePETpLqFkjmwzk/YIGclFkXypjIhBdrVYJHwRbk3A=; b=qrZt8ZLIkeb/2mvXOL7+YsvRq6LX3A2Jr45u+2T96qrluPG5CrbIE9lUY7tvHgSe0k MhpBmUKJF5/33b5CBvX0kBHwkPCz8KGMMCYvnMTwURgO8ULf44HPUMbxSp/SHcoHNBaA 9laVReHrZ+EtXBwJkryS9iKw/zsNdJNO3161GklvYWDTXZT6S6R03Z6zfK6YX4CUQO+A HJKVt5O6OcWAR0VEa92eNMwUZsYtytdKOlDE/BdLJswc5fo4mI2sjUTcBgAUwb8CGV35 10iA6/g0mAgIhdj6FN87DyWNXnIgVVat7KktmhTsVWMVVMEqqmPhCBozsBIMZ301cAbX /nlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U4POsPMa; 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 l33si37047701pld.142.2019.01.29.03.52.58; Tue, 29 Jan 2019 03:53:13 -0800 (PST) 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=U4POsPMa; 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 S1732188AbfA2Lwv (ORCPT + 99 others); Tue, 29 Jan 2019 06:52:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:44734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732174AbfA2Lwt (ORCPT ); Tue, 29 Jan 2019 06:52:49 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 1D1DF2083B; Tue, 29 Jan 2019 11:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548762768; bh=JzfI4ceL5RNcEyd59AvoOvbj1sUvCMg8kStymtsPkRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U4POsPMaI2gPhWJf5pMRnzIBd4L5jFu3FiZAhhcgXZ7co3jhXZTDvxvYJZvfuH2zm 5e+K+EO5AzRhP5DIIn7On1VBoAKXeq3IW0SZo1zfpqhZDRoNyQCyHt2hUe5uqXQuPE QWKAOiTYxEfhcYoXrrwtb3RUTd7lxfpuupkwTC3g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gerald Schaefer , Martin Schwidefsky Subject: [PATCH 4.9 16/44] s390/smp: fix CPU hotplug deadlock with CPU rescan Date: Tue, 29 Jan 2019 12:36:11 +0100 Message-Id: <20190129113141.324243699@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129113139.826927690@linuxfoundation.org> References: <20190129113139.826927690@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gerald Schaefer commit b7cb707c373094ce4008d4a6ac9b6b366ec52da5 upstream. smp_rescan_cpus() is called without the device_hotplug_lock, which can lead to a dedlock when a new CPU is found and immediately set online by a udev rule. This was observed on an older kernel version, where the cpu_hotplug_begin() loop was still present, and it resulted in hanging chcpu and systemd-udev processes. This specific deadlock will not show on current kernels. However, there may be other possible deadlocks, and since smp_rescan_cpus() can still trigger a CPU hotplug operation, the device_hotplug_lock should be held. For reference, this was the deadlock with the old cpu_hotplug_begin() loop: chcpu (rescan) systemd-udevd echo 1 > /sys/../rescan -> smp_rescan_cpus() -> (*) get_online_cpus() (increases refcount) -> smp_add_present_cpu() (new CPU found) -> register_cpu() -> device_add() -> udev "add" event triggered -----------> udev rule sets CPU online -> echo 1 > /sys/.../online -> lock_device_hotplug_sysfs() (this is missing in rescan path) -> device_online() -> (**) device_lock(new CPU dev) -> cpu_up() -> cpu_hotplug_begin() (loops until refcount == 0) -> deadlock with (*) -> bus_probe_device() -> device_attach() -> device_lock(new CPU dev) -> deadlock with (**) Fix this by taking the device_hotplug_lock in the CPU rescan path. Cc: Signed-off-by: Gerald Schaefer Signed-off-by: Martin Schwidefsky Signed-off-by: Greg Kroah-Hartman --- arch/s390/kernel/smp.c | 4 ++++ drivers/s390/char/sclp_config.c | 2 ++ 2 files changed, 6 insertions(+) --- a/arch/s390/kernel/smp.c +++ b/arch/s390/kernel/smp.c @@ -1139,7 +1139,11 @@ static ssize_t __ref rescan_store(struct { int rc; + rc = lock_device_hotplug_sysfs(); + if (rc) + return rc; rc = smp_rescan_cpus(); + unlock_device_hotplug(); return rc ? rc : count; } static DEVICE_ATTR(rescan, 0200, NULL, rescan_store); --- a/drivers/s390/char/sclp_config.c +++ b/drivers/s390/char/sclp_config.c @@ -59,7 +59,9 @@ static void sclp_cpu_capability_notify(s static void __ref sclp_cpu_change_notify(struct work_struct *work) { + lock_device_hotplug(); smp_rescan_cpus(); + unlock_device_hotplug(); } static void sclp_conf_receiver_fn(struct evbuf_header *evbuf)