Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1684208ybz; Thu, 16 Apr 2020 13:38:34 -0700 (PDT) X-Google-Smtp-Source: APiQypInu8T7NUO8lMD+tQlvDoYiKHYL0bpX91lv0Uky9nuxs6XpG+eNfgq91EN3COf+n4YMgfb0 X-Received: by 2002:a17:906:1ccb:: with SMTP id i11mr11298103ejh.101.1587069513855; Thu, 16 Apr 2020 13:38:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587069513; cv=none; d=google.com; s=arc-20160816; b=pFq72YC32R995J1EFsbROrxRTNdc3gm9Qt0jxSyIbcbJDyeAl/I218RCsfPaDVmyWf Jwh03F2vMr0WCuWAUkNPUeyXHtlZxTmC6mtKorBt3rOwq8loucgqSqIFFlXDzoSGnpVa QG1KFYTRkEXpeMddYZYjzlllBE7xNxtj6laE0d1SBSB3dgfOIDDMxTU+nKwoK3r78ZNZ FRQyeDbRKDuJk1cGGKF2Br77zx32C2IbQweM6sekxy4XQvzYz0cljVadjV9mMeejSqqB 6lqdGxQ3VUyCC5y289TrZAzNlrNvqCXvenlYe/Nwa0sddEDnahpbPZ8LUzhvbs/7odII x2aA== 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=4+NOer7xcBJLjfN4H3OD0gUU/Qx+Z82Bw/XxuGPQ+bk=; b=1IcEWTB/XGs68KYAU+f9y4h76eIomuFF/EBpQ4j1DviYoTutr93tneGZvcZnaQgqCn NmY2xw/pGvk2ygBSeWx+DVQcvOvQ2+WmQQPbNGqgzW7jjYLUNckHsSCpxP1tyGYBmXwU pvo0ytbyijIjkeO+XjPL407qco167IeA3fxd4UtvggUmDZj02nBzGnZWZXOMqoQWY8Sr d08GHImPVP4DZ++IjkxfGFI31tsELVNzP2xtCtmvsec6zCsn7m0M2l21j7/d8lo1Bk3D 9TZojlzKodTreFH2KIS1XyXq9Jux0bHRIVP/S8P/Zk8yzcCLCnv4K/loMYV26Y+lCRik uZ0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C4ZIymjf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p6si12625257ejj.173.2020.04.16.13.38.11; Thu, 16 Apr 2020 13:38:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C4ZIymjf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442883AbgDPP5k (ORCPT + 99 others); Thu, 16 Apr 2020 11:57:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:37326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2895756AbgDPN2Y (ORCPT ); Thu, 16 Apr 2020 09:28:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 88E99206E9; Thu, 16 Apr 2020 13:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587043703; bh=QSkXV98D3bYlOYnTg+eURXDtc02pydxmQZRaKXYxric=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C4ZIymjfONuANs7GBkA5r8d94gBNefghUcmaL626DZQ0vqn9ox8GfLiktRrupJc6j dNwuBLbXH39Mr5xMuD8L1oyxNeNA7YOWwjmPAhEKIVo60tXR0058V6PCXqy4ovYntU tHnfHCtJa+J6vViKUIdsQBJpEeCqeFp0Kmpda6Bc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Hoyer , Lukas Wunner , Bjorn Helgaas , Keith Busch Subject: [PATCH 4.19 064/146] PCI: pciehp: Fix indefinite wait on sysfs requests Date: Thu, 16 Apr 2020 15:23:25 +0200 Message-Id: <20200416131251.645432763@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131242.353444678@linuxfoundation.org> References: <20200416131242.353444678@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Lukas Wunner commit 3e487d2e4aa466decd226353755c9d423e8fbacc upstream. David Hoyer reports that powering pciehp slots up or down via sysfs may hang: The call to wait_event() in pciehp_sysfs_enable_slot() and _disable_slot() does not return because ctrl->ist_running remains true. This flag, which was introduced by commit 157c1062fcd8 ("PCI: pciehp: Avoid returning prematurely from sysfs requests"), signifies that the IRQ thread pciehp_ist() is running. It is set to true at the top of pciehp_ist() and reset to false at the end. However there are two additional return statements in pciehp_ist() before which the commit neglected to reset the flag to false and wake up waiters for the flag. That omission opens up the following race when powering up the slot: * pciehp_ist() runs because a PCI_EXP_SLTSTA_PDC event was requested by pciehp_sysfs_enable_slot() * pciehp_ist() turns on slot power via the following call stack: pciehp_handle_presence_or_link_change() -> pciehp_enable_slot() -> __pciehp_enable_slot() -> board_added() -> pciehp_power_on_slot() * after slot power is turned on, the link comes up, resulting in a PCI_EXP_SLTSTA_DLLSC event * the IRQ handler pciehp_isr() stores the event in ctrl->pending_events and returns IRQ_WAKE_THREAD * the IRQ thread is already woken (it's bringing up the slot), but the genirq code remembers to re-run the IRQ thread after it has finished (such that it can deal with the new event) by setting IRQTF_RUNTHREAD via __handle_irq_event_percpu() -> __irq_wake_thread() * the IRQ thread removes PCI_EXP_SLTSTA_DLLSC from ctrl->pending_events via board_added() -> pciehp_check_link_status() in order to deal with presence and link flaps per commit 6c35a1ac3da6 ("PCI: pciehp: Tolerate initially unstable link") * after pciehp_ist() has successfully brought up the slot, it resets ctrl->ist_running to false and wakes up the sysfs requester * the genirq code re-runs pciehp_ist(), which sets ctrl->ist_running to true but then returns with IRQ_NONE because ctrl->pending_events is empty * pciehp_sysfs_enable_slot() is finally woken but notices that ctrl->ist_running is true, hence continues waiting The only way to get the hung task going again is to trigger a hotplug event which brings down the slot, e.g. by yanking out the card. The same race exists when powering down the slot because remove_board() likewise clears link or presence changes in ctrl->pending_events per commit 3943af9d01e9 ("PCI: pciehp: Ignore Link State Changes after powering off a slot") and thereby may cause a re-run of pciehp_ist() which returns with IRQ_NONE without resetting ctrl->ist_running to false. Fix by adding a goto label before the teardown steps at the end of pciehp_ist() and jumping to that label from the two return statements which currently neglect to reset the ctrl->ist_running flag. Fixes: 157c1062fcd8 ("PCI: pciehp: Avoid returning prematurely from sysfs requests") Link: https://lore.kernel.org/r/cca1effa488065cb055120aa01b65719094bdcb5.1584530321.git.lukas@wunner.de Reported-by: David Hoyer Signed-off-by: Lukas Wunner Signed-off-by: Bjorn Helgaas Reviewed-by: Keith Busch Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/pciehp_hpc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -627,17 +627,15 @@ static irqreturn_t pciehp_ist(int irq, v if (atomic_fetch_and(~RERUN_ISR, &ctrl->pending_events) & RERUN_ISR) { ret = pciehp_isr(irq, dev_id); enable_irq(irq); - if (ret != IRQ_WAKE_THREAD) { - pci_config_pm_runtime_put(pdev); - return ret; - } + if (ret != IRQ_WAKE_THREAD) + goto out; } synchronize_hardirq(irq); events = atomic_xchg(&ctrl->pending_events, 0); if (!events) { - pci_config_pm_runtime_put(pdev); - return IRQ_NONE; + ret = IRQ_NONE; + goto out; } /* Check Attention Button Pressed */ @@ -666,10 +664,12 @@ static irqreturn_t pciehp_ist(int irq, v pciehp_handle_presence_or_link_change(slot, events); up_read(&ctrl->reset_lock); + ret = IRQ_HANDLED; +out: pci_config_pm_runtime_put(pdev); ctrl->ist_running = false; wake_up(&ctrl->requester); - return IRQ_HANDLED; + return ret; } static int pciehp_poll(void *data)