Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2732721ybh; Mon, 5 Aug 2019 06:02:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqy86sMhrFBAw9CAQ/vwZ1paOCR1vjrKJ5iypxMjUxVIOMnp1UgigYXTyGaK7GFMShU1CstH X-Received: by 2002:a17:90b:94:: with SMTP id bb20mr18458179pjb.16.1565010161471; Mon, 05 Aug 2019 06:02:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565010161; cv=none; d=google.com; s=arc-20160816; b=KZdZvjQ1ZEYSKk3ZhYrXFKH8mmirKnSuPDmwHJiIjMOhTl+1E7vI59C71+ktcUm1HK zOBrAyUnKFAzblgdMZ8Dx5DaVZFbTx6upBXdJpRfAkiITDbM24BjMjF+3yLGV5UuoXyb X6K23FyS+Z8YFXWm5Bo65kBEp3uxfiLEwhSG0VN+EbHWZppFHG2sJa9KN8MXRJ5Of76b cFn600r3E5GX0DJddaNLniy1Oa3hc/e2dG4B77bLM2Zvge3/bJrC218FYHYRdNQejnSe ATcJUvP/bQRBQqU5vLdahoMnH7ffwmTvyd5X8Y5r75FNzsqW1cihVWKqKojrL/mOxvLG eDYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8ePiLKeT29+Vvh7oz4ldQVRBy+0ijaMj0NTIawhCiaE=; b=mvVxuoFjaI0rjsMIbleqVePpl3iO0ly2ID7nDVwjQVGCNBTvt6Hbx77jvJZ+PfhAyY 1jUxwirF2vcWKJPaAhLclWtCh25CITZndnWvUZQ5M8VWhMQXUp7SQc5ssihx6P4mHDEX n9bq9N5QjXfZj3oPBjXHaaDC1CjwbzoFcd7E0/XNromhwH5qfN4MhFWYsVPQ8Q0H3SCG YhLGNNf+sx+fGJosVMOxB9Mzl8axuEhil8RCYY65frfJmVzkP5rhLAv3pwbCxCiavo8r F3ukGp+wI/Bke7y/jR6HrYRDWS4UZf9khlY6zTavzyHqn8do2qmvGIME/rhWgAMDoGJr c1YA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si30723357pgh.434.2019.08.05.06.02.24; Mon, 05 Aug 2019 06:02:41 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728468AbfHENA2 (ORCPT + 99 others); Mon, 5 Aug 2019 09:00:28 -0400 Received: from mga07.intel.com ([134.134.136.100]:45596 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726508AbfHENA1 (ORCPT ); Mon, 5 Aug 2019 09:00:27 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Aug 2019 05:59:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,349,1559545200"; d="scan'208";a="192414268" Received: from lahna.fi.intel.com (HELO lahna) ([10.237.72.157]) by fmsmga001.fm.intel.com with SMTP; 05 Aug 2019 05:59:49 -0700 Received: by lahna (sSMTP sendmail emulation); Mon, 05 Aug 2019 15:59:48 +0300 Date: Mon, 5 Aug 2019 15:59:48 +0300 From: Mika Westerberg To: Lukas Wunner Cc: Bjorn Helgaas , "Rafael J. Wysocki" , Keith Busch , Andy Shevchenko , Sinan Kaya , Kai Heng Feng , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] PCI: pciehp: Prevent deadlock on disconnect Message-ID: <20190805125948.GO2640@lahna.fi.intel.com> References: <20190618125051.2382-1-mika.westerberg@linux.intel.com> <20190618125051.2382-2-mika.westerberg@linux.intel.com> <20190805111854.al5bj3q2gdng5ai6@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190805111854.al5bj3q2gdng5ai6@wunner.de> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.11.4 (2019-03-13) 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 01:18:54PM +0200, Lukas Wunner wrote: > On Tue, Jun 18, 2019 at 03:50:51PM +0300, Mika Westerberg wrote: > > If there are more than one PCIe switch with hotplug downstream ports > > hot-removing them leads to a following deadlock: > [...] > > What happens here is that the whole hierarchy is runtime resumed and the > > parent PCIe downstream port, who got the hot-remove event, starts > > removing devices below it taking pci_lock_rescan_remove() lock. When the > > child PCIe port is runtime resumed it calls pciehp_check_presence() > > which ends up calling pciehp_card_present() and pciehp_check_link_active(). > > Both of these read their parts of PCIe config space by calling helper > > function pcie_capability_read_word(). Now, this function notices that > > the underlying device is already gone and returns PCIBIOS_DEVICE_NOT_FOUND > > with the capability value set to 0. When pciehp gets this value it > > thinks that its child device is also hot-removed and schedules its IRQ > > thread to handle the event. > > > > The deadlock happens when the child's IRQ thread runs and tries to > > acquire pci_lock_rescan_remove() which is already taken by the parent > > and the parent waits for the child's IRQ thread to finish. > > > > We can prevent this from happening by checking the return value of > > pcie_capability_read_word() and if it is PCIBIOS_DEVICE_NOT_FOUND stop > > performing any hot-removal activities. > > IIUC this patch only avoids the deadlock if the child hotplug port happens > to be runtime suspended when it is surprise removed. The deadlock isn't > avoided if is runtime resumed. > > This patch I posted last year should cover both cases: > > https://patchwork.kernel.org/patch/10468065/ > > However, as I've noted in this follow-up to the patch, I don't consider > my solution a proper fix either: > > https://patchwork.kernel.org/patch/10468065/#22206721 > > Rather, the problem should be addressed by unbinding PCI drivers without > holding pci_lock_rescan_remove(). > > I'm truly sorry but I haven't been able to make much progress on this > as I got caught up with other things. Part of the problem is that this > is volunteer work. Maybe someone's interested in hiring me to work on it? > Resume available on request. (But I'll get to it sooner or later whether > paid or not, unless someone else beats me to it. :-) ) In any case we should do something about this sooner rather than later as this is really annoying issue and starts to affect more and more people. This patch avoids touching the hardware as soon as we detect it is gone already preventing the issue so I think it is the right thing to do regardless. Having "perfect" fix sounds good but in the meantime I think we should have a fix that at least prevents the most common case from happening which here means unplugging 2 or more devices. Up to Bjorn of course :)