Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4557904imu; Tue, 29 Jan 2019 03:46:23 -0800 (PST) X-Google-Smtp-Source: ALg8bN7kgSJt49SD0F9Qaidzk3HWpQEr39wIebHOXaGXJI2bhjDvmn1FNoQAgboRMVXD7Sw+vp5H X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr25132596plg.222.1548762383614; Tue, 29 Jan 2019 03:46:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548762383; cv=none; d=google.com; s=arc-20160816; b=o7+W3Ed9hwGhaIC7Q8n+DxwF8aA6FfXSKHCkO4aWtj++XXBOdDV4r4jWiyaZZCI5TO VM0u5X8ZMfmNpnenGt2yBcOTdRvyRBHG5W21y5iWgo0gLCWcuqFT7WjJS4UU6qrV4GTl XBs/NYVXO0nF9+XRgUwcPlvxrVn+FemIiGDWGivmiTWebISOt1l4mGKef0ZRZ3kW0gPq vX2xUAdLun1IftzP2VbhEUWAcPAu3IK3B1QmaG3+AiuZGq0bsFbLkFP94NfUiZ88Wi4M xbNRlH/uQhGim19I2f8d7iSnz+zNzKi81PjvID1UB3t646TRMvNMSllps5FPRMMwvtsY wmTw== 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=gYf61/P4BOnL+42dgjP5btNV3VjUfOKYXl7wZBGGA+c=; b=LxSjrwcOMJkGOhZLCUZbhuIEvpPRC64sc158AvF7v0Fo77Qcp2Wi96qUtrwIzCsqy3 e3PKW3X/ieXNI99MJCVp3aj+vvGWtJmiDNsq6b+j5gjR6k8A4Wl3TT08iI/nd36I9LLH LdtIqrj0HDmagTacmZLqMID+zbws6g1ehc1BtK+vZfyUPWgroQKIusWAEkQ2Xsc4rAlO 6NzR9NKaTBAmKnP0K+0IEfd3UoWnVV0BfQ5zM6OxTb4XWs6r0frAm5t37K9f2n70uNoZ Z2CN/sgtaFYrMdtsJmUDa/QDP8l+KzuDRuAIz9InNHgTyGPk6SR1H5fti4cvvjldg63f /l/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NAKWtnhM; 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 b30si36740622pla.285.2019.01.29.03.46.08; Tue, 29 Jan 2019 03:46:23 -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=NAKWtnhM; 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 S1729750AbfA2LoM (ORCPT + 99 others); Tue, 29 Jan 2019 06:44:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:34378 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730496AbfA2LoJ (ORCPT ); Tue, 29 Jan 2019 06:44:09 -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 649B32083B; Tue, 29 Jan 2019 11:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548762248; bh=jkFoBsBlqrwLYn/0lSb7x7cGrG8WKG8hIuF0o0u1Opg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NAKWtnhMSe6rdTPgE5OF8Cy5KZman0VJEVoumcwO1LRYkKVqdeZA/kEtX8s1mMw5B 7ErPy8xc3kcrQAgYlb+jFdO6ECQ5KBKF2yVA+DpaBrOf7lbhC8TgtMK3kHPLO2EBEr iFsOub+ckR2LndLhA0VpzWXlP3XcVrIlF/z4RNvk= 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.19 041/103] s390/smp: fix CPU hotplug deadlock with CPU rescan Date: Tue, 29 Jan 2019 12:35:18 +0100 Message-Id: <20190129113201.963851972@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129113159.567154026@linuxfoundation.org> References: <20190129113159.567154026@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.19-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 @@ -1152,7 +1152,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_WO(rescan); --- a/drivers/s390/char/sclp_config.c +++ b/drivers/s390/char/sclp_config.c @@ -60,7 +60,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)