Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2419611ybl; Sun, 11 Aug 2019 01:08:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFWwk4JV+ur2oH2uGTDHOfr8aEcf2e7PpY6Mf3w6CwRYhuiA1yECtbqaNoBSGn6eBTqNbN X-Received: by 2002:a63:6888:: with SMTP id d130mr24146800pgc.197.1565510914449; Sun, 11 Aug 2019 01:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565510914; cv=none; d=google.com; s=arc-20160816; b=RLZLO0MFfWEHIW9tMPZK/RsheatjcMXPxpkeWgWITA7PiOJpU4uIiz/EUYmpFfGYzc lo6iS2R5dnCl2p1wfFaq/lz7TAKXA3eg4UJVIjaEcGYTeRyAGZJ1/EP/QMuKqwkJgZT4 KMahn1PiJCv1oacXUzOvzvgsBr+mAv+BY1FvNWo6qPj2X0ohJ6ELerO2wfn2YGDcyf3u YM7fI6DhPGGp630AIUcL+PtFZtriU+anJjanUIXzL/fcCsyD7ozPwpH4R1FQcQmGwF/9 GtIQbS0y0P3QqxT3NK/+zMp8CSIQklW0WK0JKgsFJgptvr4wa/rTs1HHaBwugKgNchSF EALg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=7UP+okm2FBQAQPLWKTytuzlb1iq3+RWi5gHaNdOwV/4=; b=bGi0uAKtBzvCzYRvOihMv+DiIBqPYY+JtNoJQUCPuANCu9xwa4pLBKiPZggq+JRX4k DCskt6oC2B7BJzwha7D8hKe0oGUZz+zMfenuCU8fOajvNwbtAgO0Plmm4A6JMyMcAHBD 0yDcYW0mW+mqSYHmshWsRj1q+Whq+k7z+a0yJ0us+TmOgSDb6y8eWKVsSMiizUAV9KJC +J0ytwz+6t26E7eC2q6bYHCDh9o8g1GBSZW7GR7T69pq3g4pHYeCaYEulvD85YcKHx0n A2kAcMz/r1Fe5rZF3kkJoPifNp2iiMP2Cft5qZZLOEvLiyTPVxBpnFq1i1ROvbxLSKJ8 hQxw== 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 t11si54346523pgu.16.2019.08.11.01.08.19; Sun, 11 Aug 2019 01:08:34 -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 S1726558AbfHKIHH (ORCPT + 99 others); Sun, 11 Aug 2019 04:07:07 -0400 Received: from bmailout1.hostsharing.net ([83.223.95.100]:53355 "EHLO bmailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbfHKIHG (ORCPT ); Sun, 11 Aug 2019 04:07:06 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id 2520F30001A46; Sun, 11 Aug 2019 10:07:04 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id F0A83F5A33; Sun, 11 Aug 2019 10:07:03 +0200 (CEST) Date: Sun, 11 Aug 2019 10:07:03 +0200 From: Lukas Wunner To: Xiongfeng Wang Cc: helgaas@kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] pciehp: fix a race between pciehp and removing operations by sysfs Message-ID: <20190811080703.qfnlzfutgamoxzti@wunner.de> References: <1565008378-4733-1-git-send-email-wangxiongfeng2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1565008378-4733-1-git-send-email-wangxiongfeng2@huawei.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 05, 2019 at 08:32:58PM +0800, Xiongfeng Wang wrote: > When we remove a slot by sysfs. > 'pci_stop_and_remove_bus_device_locked()' will be called. This function > will get the global mutex lock 'pci_rescan_remove_lock', and remove the > slot. If the irq thread 'pciehp_ist' is still running, we will wait > until it exits. > > If a pciehp interrupt happens immediately after we remove the slot by > sysfs, but before we free the pciehp irq in > 'pci_stop_and_remove_bus_device_locked()'. 'pciehp_ist' will hung > because the global mutex lock 'pci_rescan_remove_lock' is held by the > sysfs operation. But the sysfs operation is waiting for the pciehp irq > thread 'pciehp_ist' ends. Then a hung task occurs. > > So this two kinds of operation, removing the slot triggered by pciehp > interrupt and removing through 'sysfs', should not be excuted at the > same time. This patch add a global variable to mark that one of these > operations is under processing. When this variable is set, if another > operation is requested, it will be rejected. It seems this patch involves an ABI change wherein "remove" as documented in Documentation/ABI/testing/sysfs-bus-pci may now fail and need a retry, possibly breaking existing scripts which write to this file. ABI changes are fairly problematic. The return value -EWOULDBLOCK (which is identical to -EAGAIN) might be more appropriate than -EINVAL. Another problem is that this patch only addresses deadlocks occurring because of a "remove" via sysfs and a simultaneous surprise removal (or button press removal). However the same kind of deadlock may occur because of two simultaneous surprise removals if one of the two devices is a parent of the other. It would be better to have a solution which addresses all types of deadlocks caused by the pci_rescan_remove_lock(). I provided you with a suggestion in this e-mail: https://lore.kernel.org/linux-pci/20190805114053.srbngho3wbziy2uy@wunner.de/ "What you can do is add a flag to struct pci_dev (or the priv_flags embedded therein) to indicate that a device is about to be removed. Set this flag on all children of the device being removed before acquiring pci_lock_rescan_remove() and avoid taking that lock in pciehp_unconfigure_device() if the flag is set on the hotplug port. But again, that approach is just a band-aid and the real fix is to unbind devices without holding the lock." Thanks, Lukas