Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3758597imj; Tue, 12 Feb 2019 04:15:11 -0800 (PST) X-Google-Smtp-Source: AHgI3IY0JTWid0XjDKJ13iDfajZYF0ioAmRcif9bSd+MgrlKm9eQBpnlVkbb7tgvsEhxiWQnBVgF X-Received: by 2002:aa7:8281:: with SMTP id s1mr3682529pfm.120.1549973711334; Tue, 12 Feb 2019 04:15:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549973711; cv=none; d=google.com; s=arc-20160816; b=r5LvHtXuzS93LCK5cLnXD5zlllxJgJ4Jo36p5VvyIQH6/a7TT9ta7vAePb7Ajcdr9X Z5SGbxUkt5JJO157vk/m1RdXM/uramzCGctZDxJbtnvbzgCCw31dtkM+E4zABkb3QaTk u7JGnGMzgu9dnLPJ8p/mwk563i9beSbGKgoDINlmxjquWtk4kw0+HaYfk2MPKA2VxBv6 /XbkShwOZnxQOom25pVOOZT7JiW8mKuAWntTA7TFf1Eg3g+MqWCcXIdCQUe3DsQAtEBJ XL/DsKqvtuSPU65NdzJqos1gR9nUlWSLNrRWRPn0PNiOiYuZw9N+kEx2cfMz2zrvQo8f NEYg== 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=nvlXLd/sespio9gwVQ3sMDvxeaCm4/ms8VVFJTbiPhE=; b=fXT/G54VBGGxf31Nu5LOYhZRqlZD36PPd/0PGYPMnytB8MYNwt1rqRsuESyDpwenhU hvV4zvXe9Q+eCxL075Qnk6iTxL44IA5ICmYBAc3j+1GoxEiXPmV5ZviMfU6+KHyTq4HF w7+TvcSqeQWaPqZkfHzsD/C/xLCc38hSd4+pYaQkrQEvHjCdL4vxQva1U1v5jyjx1Az8 6G506dsneHdqW1lQ9Y3ATF8ry3A91l7qqSuG550y6SMzmsyWTY4Zkwf7pOioEXJHWfmX /6FqKLUpuAUzlWMQkfcnY59PRiE2JweNCA5ADjSbvm/ptWJz6mUKoeSxa5Iw1WSsnllY w25A== 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 d75si223020pga.403.2019.02.12.04.14.55; Tue, 12 Feb 2019 04:15:11 -0800 (PST) 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 S1729236AbfBLMM5 (ORCPT + 99 others); Tue, 12 Feb 2019 07:12:57 -0500 Received: from foss.arm.com ([217.140.101.70]:36586 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726565AbfBLMMy (ORCPT ); Tue, 12 Feb 2019 07:12:54 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F2A8780D; Tue, 12 Feb 2019 04:12:53 -0800 (PST) Received: from e107981-ln.cambridge.arm.com (e107981-ln.cambridge.arm.com [10.1.197.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D1C6E3F589; Tue, 12 Feb 2019 04:12:51 -0800 (PST) Date: Tue, 12 Feb 2019 12:12:42 +0000 From: Lorenzo Pieralisi To: Dexuan Cui Cc: Bjorn Helgaas , "linux-pci@vger.kernel.org" , Stephen Hemminger , "linux-kernel@vger.kernel.org" , "driverdev-devel@linuxdriverproject.org" , KY Srinivasan , Haiyang Zhang , Sasha Levin , Michael Kelley Subject: Re: [PATCH] PCI: hv: Add hv_pci_remove_slots() when we unload the driver Message-ID: <20190212121235.GA23166@e107981-ln.cambridge.arm.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 07, 2019 at 08:36:32PM +0000, Dexuan Cui wrote: > > When we unload pci-hyperv, the host doesn't send us a PCI_EJECT message. > In this case we also need to make sure the sysfs pci slot directory > is removed, otherwise "cat /sys/bus/pci/slots/2/address" will trigger > "BUG: unable to handle kernel paging request". And, if we unload/reload > the driver several times, we'll have multiple pci slot directories in > /sys/bus/pci/slots/ like this: > > 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 > > The patch adds the missing code, and in hv_eject_device_work() it also > moves pci_destroy_slot() to an earlier place where we hold the pci lock. This patch fixes three bugs: 1) set hpdev->pci_slot to NULL 2) move code destroying the slot inside a locked region in hv_eject_device_work() 3) Add missing slots removal code in hv_pci_remove() We need three patches, not one. (1) and (2), I am not entirely sure we want them in stable kernels, since they are potential bugs, waiting for your input. Lorenzo > Fixes: a15f2c08c708 ("PCI: hv: support reporting serial number as slot information") > Signed-off-by: Dexuan Cui > Cc: stable@vger.kernel.org > Cc: Stephen Hemminger > --- > drivers/pci/controller/pci-hyperv.c | 23 ++++++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c > index 9ba4d12c179c..6b4773727525 100644 > --- 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 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 > @@ -1887,6 +1902,10 @@ static void hv_eject_device_work(struct work_struct *work) > pci_lock_rescan_remove(); > pci_stop_and_remove_bus_device(pdev); > pci_dev_put(pdev); > + if (hpdev->pci_slot) { > + pci_destroy_slot(hpdev->pci_slot); > + hpdev->pci_slot = NULL; > + } > pci_unlock_rescan_remove(); > } > > @@ -1894,9 +1913,6 @@ static void hv_eject_device_work(struct work_struct *work) > list_del(&hpdev->list_entry); > spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags); > > - if (hpdev->pci_slot) > - pci_destroy_slot(hpdev->pci_slot); > - > memset(&ctxt, 0, sizeof(ctxt)); > ejct_pkt = (struct pci_eject_response *)&ctxt.pkt.message; > ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE; > @@ -2682,6 +2698,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.19.1 >