Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2509359imm; Mon, 24 Sep 2018 05:40:28 -0700 (PDT) X-Google-Smtp-Source: ACcGV60IloSnOPkUucaI6g+S8Cg/LqqC7d1nt585SsbZhSiIAq7MpKA3TbTJwYdc+mZBD0ZviZiH X-Received: by 2002:a63:5922:: with SMTP id n34-v6mr7262810pgb.134.1537792827969; Mon, 24 Sep 2018 05:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792827; cv=none; d=google.com; s=arc-20160816; b=T+R+/n/gfmxctir6nFpEApNBkCsKUAGju8SzTzmGavOVQNYXjtbdJ4gGwbShqvUZa0 /rglkswwjbYFhZfTXu3JxqIHVruopHv9jmurZZ5Ap3ugrNE6M+TQMsIfmHL4KZz3FWW7 NpHf7O1fcS61pVHIr7Ix1ya6vdib9S/f6eZJm2NzHUYbLe+Tte6Nn/Dl2bSFdhEZA1Vk dZIUskgfpf0hV3XMmJTg9HTeNsowb2XBpTZOkzVcOcgsYh8YJGDXBGufYNKn96LgWxMt /xJjLv8sHiebj9O5OP5rvRiPrILlYtJdDzG3/9h5nrAbZ5JgSqsVIbSZrY0IpTRXBYtf QvjA== 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; bh=e6dsjxY6aMfKsKtQ5sxi3AtRVSikYiGGLvPhdGcE8kE=; b=krj4kxodM9Y8ArwsiaX64zLQa7h2bfAO8WN8Ruo785UvwWc9bgG1tFI0xBPSdPjFu9 Ns8AdXbjJd6YvWKAWt7Up10LhwO/sPR8sMHzzibWmuYUFzJWrwninqNgsFO8JdIg8wAu EqLz5gqkrlUBYwdpUzBLq+UunIeP4BdDgt9b1WlSEnrrNgAqsIL/v54nOSFGdtP6zC4H IYOvJnZPyUFDCxMtNBXi5Beh2DXkzNkox7uiV3vhxXWRYUKL48YLYZ2u0ceVmZm2MH2h yZyrpHRjv4Tf0TY7EKYNw2FqvmrW20PEEEQ27SXgl+4kA3qMQn3RveE94cp84qTCBfuw Ajzw== ARC-Authentication-Results: i=1; mx.google.com; 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 x185-v6si36486236pfb.306.2018.09.24.05.40.12; Mon, 24 Sep 2018 05:40:27 -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; 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 S2387835AbeIXSjr (ORCPT + 99 others); Mon, 24 Sep 2018 14:39:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58618 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728937AbeIXSjq (ORCPT ); Mon, 24 Sep 2018 14:39:46 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 216F6107F; Mon, 24 Sep 2018 12:37:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pingfan Liu , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 4.18 086/235] drivers/base: stop new probing during shutdown Date: Mon, 24 Sep 2018 13:51:12 +0200 Message-Id: <20180924113113.625835894@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@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: Pingfan Liu [ Upstream commit 3297c8fc65af5d40501ea7cddff1b195cae57e4e ] There is a race window in device_shutdown(), which may cause -1. parent device shut down before child or -2. no shutdown on a new probing device. For 1st, taking the following scenario: device_shutdown new plugin device list_del_init(parent_dev); spin_unlock(list_lock); device_add(child) probe child shutdown parent_dev --> now child is on the tail of devices_kset For 2nd, taking the following scenario: device_shutdown new plugin device device_add(dev) device_lock(dev); ... device_unlock(dev); probe dev --> now, the new occurred dev has no opportunity to shutdown To fix this race issue, just prevent the new probing request. With this logic, device_shutdown() is more similar to dpm_prepare(). Signed-off-by: Pingfan Liu Reviewed-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2809,6 +2809,9 @@ void device_shutdown(void) { struct device *dev, *parent; + wait_for_device_probe(); + device_block_probing(); + spin_lock(&devices_kset->list_lock); /* * Walk the devices list backward, shutting down each in turn.