Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp200548yba; Mon, 20 May 2019 07:18:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQV6HmbahagCqvW8UH4y+NMPxAKjjmrzoVAaFdzyGOFrWP6Fr4WpFoZYgR62I85fQ3ZsNb X-Received: by 2002:a62:2b82:: with SMTP id r124mr72258194pfr.235.1558361915040; Mon, 20 May 2019 07:18:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558361915; cv=none; d=google.com; s=arc-20160816; b=hscLHAGlyBcNE5t4Kn2BeXRavZ2Z1ad3Exz2vOuyJ4jnwMnU0hFwW1h614PrZgApJM wGFH+6hE1EYbv90wRws/+vOTNqO9bASTiownlNbhA2Hrjt2xThxqkk+iKOnuGg3TkXe/ KRDz4UW6Twy+JKoTOCgAdfDcjxdzvSL/8GKLJgsdQkUYQeZnjI5KLfw3Ie+m6juIYCjl bSWVrF4EB38GTp/bAalvlP7kDXWzkXzqtRq6+GSSOcC0xkC7sSJKma4XTVCwytnedn2E sUNq5AgEIzgS0SJSXU6Y5kX4eau2aK64p0/DJulZh9B73t8Y/IN+eq4ThDES4zW3/l12 SMYw== 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=CUHkXCZZertJbcv6aUAX88MUqeXfnv/BaPYcx/hpFMk=; b=Do0vxyN4mkb5eB56o53NMzHUk9sVeaZct5EE3q9LNtwku0V+9CABwUGeO59I2xQlA9 DbHAB5cUPfir4OVG6fql+YwC72gB1rlHnp3C02vEeSOpr8ziN4wwGlLNdCTqumDJEh5E Ro2KHxqXj+aOdfZsyoCHxcttIMHBmY7aYKm851fxNXwkeXmxUnLoWDUaU5MpCb1LkfcZ Y3GPVW29WArwr3uZBTGSMhJjgtgK6nbtJU3vF44tCPKjm243LrM8BUcukV89+OpLPHVY N90edEzZPjh5WZULPWLBtqWab0zYBDtmrhCRehMTmEFVaEHU0IJriOYildtXVH97c9oI 2Z3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g1qw6m9z; 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 ay8si17643765plb.218.2019.05.20.07.18.19; Mon, 20 May 2019 07:18:35 -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=g1qw6m9z; 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 S1733166AbfETMSj (ORCPT + 99 others); Mon, 20 May 2019 08:18:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:59708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387720AbfETMSe (ORCPT ); Mon, 20 May 2019 08:18:34 -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 5923521019; Mon, 20 May 2019 12:18:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354713; bh=03B4r+gdfV3zZKsrGh0pxXl2QtZADUcF3UWhdO37XDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g1qw6m9zTb0hnI5WBav8eL4V55CaScqX7S9YHxcOu6x6pmDzuxY62LWQcSx8tWPtA lLx6KEXn5OurUJT95YAcNyMpQSu/2odGYWkoxDwv+tu36/qfAdH0792yDgBeRe52Al hhmFlsjURL7hWeyQxf9xQbIW+swt7zcbSJcI/MOo= 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 , Sasha Levin Subject: [PATCH 4.14 04/63] PCI: hv: Add hv_pci_remove_slots() when we unload the driver Date: Mon, 20 May 2019 14:13:43 +0200 Message-Id: <20190520115231.769898685@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115231.137981521@linuxfoundation.org> References: <20190520115231.137981521@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 [ Upstream commit 15becc2b56c6eda3d9bf5ae993bafd5661c1fad1 ] 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: Sasha Levin --- drivers/pci/host/pci-hyperv.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 292450c7da625..a5825bbcded72 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -1513,6 +1513,21 @@ static void hv_pci_assign_slots(struct hv_pcibus_device *hbus) } } +/* + * 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 @@ -2719,6 +2734,7 @@ static int hv_pci_remove(struct hv_device *hdev) 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; } -- 2.20.1