Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp463217yba; Wed, 15 May 2019 04:33:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXZOvCkDEGk/fiXNmHi7YsjFI2gKWJhRgJiXs4v0perHX8lXfmDRijewoUJRSoNB6Pk4YZ X-Received: by 2002:a63:f315:: with SMTP id l21mr43345128pgh.417.1557920008333; Wed, 15 May 2019 04:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920008; cv=none; d=google.com; s=arc-20160816; b=TpHOhXGTbmWZHQINWx35p07QtUiqqgYoXjY8fbj9lQPFL0jyBtQwlzBy60evYAJ3Nb NAtkiYR+2+oLOrsXmj8um8ZkrBZ9xrVDZE9Li4CMv+Rklc5U58gHIfx5q07+fo5aEiSf AS3K+/i/yvCWSB6/a5QhPNKgHV0skj/U/1sc+PjG5zFrHSTz/amr0ENqZb/wiHCV1GhL ApxvresBtXJyrKe6YvDVlBKE2eTljF6hFwwjPLT7Daxmv29E0KKfWsN1nnHobxPQzLgx PgDDWv182nElJiFZXlmYCj7y2yqkVZ+6CfX251E/QTAvdIe0LrQCw5Eg1O2ven/tH4j5 CgiQ== 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=mEtIR51ojOWEBpHjL+5M79khqhqd6Zkf7bMsj9gpsZE=; b=u7UB85TBUFGTBwMrrgshdnjRLBbjdnMiIgx0ItkrRm+5LU7yGNFOFgMZ/shf3JqJ4d sQNoHXTOmymmIGxtMRGZHNYeNWv4XlZvzptsssJyNnW3dvhktBvhRpXHWVC8QnhQacD1 9TkG4jC2V7odW7+0nYC4wQt0ivyYG0CiWyUWqVRzGooa9yaqApt69RixYGlPWN0roOdA vFljRoglHfIwJgR0TDbiAh9+kZ82VFEpWWVAwPcsW7wKunnry1wi22d4Q1cwKy4Dsboe l3nTPnB8gEw6ziYYaHX1ZVAZSrN8UK2kvUZPdz8GBPUdPfBm8/OuCBixA5gJ+ypnIbGx 03FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O2OIbU2g; 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 f90si1585295plb.25.2019.05.15.04.33.13; Wed, 15 May 2019 04:33:28 -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; dkim=pass header.i=@kernel.org header.s=default header.b=O2OIbU2g; 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 S1726980AbfEOLbj (ORCPT + 99 others); Wed, 15 May 2019 07:31:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:43344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732904AbfEOLbf (ORCPT ); Wed, 15 May 2019 07:31:35 -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 127F92084A; Wed, 15 May 2019 11:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919894; bh=FojP+nXiRvBcWpMCM3FS04aD2Od+btT7ex4k/BSAnjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O2OIbU2gaJDoBt06Hcl7LaKQkWJH2EeA1nS2wvnHYTqtbUg7AS+2Ae0QMufp4cO5x R/26sownMIBjTMdsLm4r95zf471hEH2tla62CUT/U6FM6LN+QsCrq7szzdMEML9JlC nbmkNjc0u5Wa6roqYyQunjAQTj70LcS3+ZAlKBBQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dexuan Cui , Lorenzo Pieralisi , Stephen Hemminger , Michael Kelley Subject: [PATCH 5.0 135/137] PCI: hv: Add hv_pci_remove_slots() when we unload the driver Date: Wed, 15 May 2019 12:56:56 +0200 Message-Id: <20190515090703.665227215@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@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: Dexuan Cui commit 15becc2b56c6eda3d9bf5ae993bafd5661c1fad1 upstream. When we unload the pci-hyperv host controller driver, the host does not send us a PCI_EJECT message. In this case we also need to make sure the sysfs PCI slot directory is removed, otherwise a command on a slot file eg: "cat /sys/bus/pci/slots/2/address" will trigger a "BUG: unable to handle kernel paging request" and, if we unload/reload the driver several times we would end up with stale slot entries in PCI slot directories in /sys/bus/pci/slots/ root@localhost:~# ls -rtl /sys/bus/pci/slots/ total 0 drwxr-xr-x 2 root root 0 Feb 7 10:49 2 drwxr-xr-x 2 root root 0 Feb 7 10:49 2-1 drwxr-xr-x 2 root root 0 Feb 7 10:51 2-2 Add the missing code to remove the PCI slot and fix the current behaviour. Fixes: a15f2c08c708 ("PCI: hv: support reporting serial number as slot information") Signed-off-by: Dexuan Cui [lorenzo.pieralisi@arm.com: reformatted the log] Signed-off-by: Lorenzo Pieralisi Reviewed-by: Stephen Hemminger Reviewed-by: Michael Kelley Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/pci/controller/pci-hyperv.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1491,6 +1491,21 @@ static void hv_pci_assign_slots(struct h } } +/* + * Remove entries in sysfs pci slot directory. + */ +static void hv_pci_remove_slots(struct hv_pcibus_device *hbus) +{ + struct hv_pci_dev *hpdev; + + list_for_each_entry(hpdev, &hbus->children, list_entry) { + if (!hpdev->pci_slot) + continue; + pci_destroy_slot(hpdev->pci_slot); + hpdev->pci_slot = NULL; + } +} + /** * create_root_hv_pci_bus() - Expose a new root PCI bus * @hbus: Root PCI bus, as understood by this driver @@ -2685,6 +2700,7 @@ static int hv_pci_remove(struct hv_devic pci_lock_rescan_remove(); pci_stop_root_bus(hbus->pci_bus); pci_remove_root_bus(hbus->pci_bus); + hv_pci_remove_slots(hbus); pci_unlock_rescan_remove(); hbus->state = hv_pcibus_removed; }