Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965569AbcKLAoN (ORCPT ); Fri, 11 Nov 2016 19:44:13 -0500 Received: from mail-by2nam01on0133.outbound.protection.outlook.com ([104.47.34.133]:8506 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934919AbcKLAoL (ORCPT ); Fri, 11 Nov 2016 19:44:11 -0500 From: Jake Oshins To: Dexuan Cui , Bjorn Helgaas , "linux-pci@vger.kernel.org" , "devel@linuxdriverproject.org" CC: "gregkh@linuxfoundation.org" , KY Srinivasan , Haiyang Zhang , "Stephen Hemminger" , Hadden Hoppert , Vitaly Kuznetsov , "jasowang@redhat.com" , "apw@canonical.com" , "olaf@aepfle.de" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH 3/3] PCI: hv: delete the device earlier from hbus->children for hot-remove Thread-Topic: [PATCH 3/3] PCI: hv: delete the device earlier from hbus->children for hot-remove Thread-Index: AdI7Is7s4N8ILPzXQNyHLjEi1hPE1ABWwCzQ Date: Sat, 12 Nov 2016 00:44:06 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=jakeo@microsoft.com; x-originating-ip: [2001:4898:80e8:1::d6] x-microsoft-exchange-diagnostics: 1;SN1PR0301MB2110;7:/TUFgXAHTyyME37AOBQx/LwKza5t8XY0YIhNYp5sbo9wznCvRfuw8IHlQKELL+vk1ptsfKkQRJVBfJNA01Ffebc37uLZa6mPnlVC/YhznRrs/cvfCwaRs9UbMEEueFcAr6YZlfN/N/NPfDMgD/a3XpeYmD6Do6H8gBW98u8CRlxUXVOnJ2mG0J+mkxJw64TBewfZwgDt6a8anwWzKJyaP1IJp83qv1tJhNfZ1a0DffA9gSvSNY32jDsy1DjlGiwoqoC9TIT/hl2Be7TD+zTnkr6JMRDM5G0/jImd0sxATpbb4dwMJQRCo4vFUyJVqbK//nLFpQy2+VzHmTPBdbocpQOsSKdyI9/vEIxiQOWZ+DSXqpmzMFPftIiVDJSDaQ80 x-ms-office365-filtering-correlation-id: cb54f313-90ab-4a39-4b34-08d40a95023e x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:SN1PR0301MB2110; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(211936372134217)(198206253151910); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6060229)(6045074)(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(61426038)(61427038)(6061226)(6046074);SRVR:SN1PR0301MB2110;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0301MB2110; x-forefront-prvs: 01244308DF x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(7916002)(189002)(377454003)(13464003)(199003)(68736007)(8676002)(5660300001)(2900100001)(101416001)(1511001)(81166006)(81156014)(50986999)(3280700002)(54356999)(3660700001)(7696004)(9686002)(305945005)(74316002)(2421001)(77096005)(8990500004)(33656002)(87936001)(7736002)(76176999)(7846002)(92566002)(10290500002)(5005710100001)(229853002)(99286002)(105586002)(106356001)(2201001)(5001770100001)(102836003)(189998001)(86362001)(8936002)(76576001)(3900700001)(2950100002)(97736004)(2561002)(86612001)(2501003)(122556002)(4326007)(6116002)(586003)(2906002)(10090500001);DIR:OUT;SFP:1102;SCL:1;SRVR:SN1PR0301MB2110;H:SN1PR0301MB1598.namprd03.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Nov 2016 00:44:06.8242 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0301MB2110 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uAC0iJx3000653 Content-Length: 2725 Lines: 68 > -----Original Message----- > From: Dexuan Cui > Sent: Wednesday, November 9, 2016 11:20 PM > To: Bjorn Helgaas ; linux-pci@vger.kernel.org; > devel@linuxdriverproject.org > Cc: gregkh@linuxfoundation.org; KY Srinivasan ; > Haiyang Zhang ; Stephen Hemminger > ; Jake Oshins ; Hadden > Hoppert ; Vitaly Kuznetsov > ; jasowang@redhat.com; apw@canonical.com; > olaf@aepfle.de; linux-kernel@vger.kernel.org > Subject: [PATCH 3/3] PCI: hv: delete the device earlier from hbus->children > for hot-remove > > After we send a PCI_EJECTION_COMPLETE message to the host, the host will > immediately send us a PCI_BUS_RELATIONS message with > relations->device_count == 0, so pci_devices_present_work(), running on > another thread, can find the being-ejected device, mark > the hpdev->reported_missing to true, and run list_move_tail()/list_del() > for the device -- this races hv_eject_device_work() -> list_del(). > > The patch moves the list_del() in hv_eject_device_work() to an earlier > place, i.e. before we send PCI_EJECTION_COMPLETE, so later the > pci_devices_present_work() can't see the device. > > Signed-off-by: Dexuan Cui > CC: Jake Oshins > Cc: KY Srinivasan > CC: Haiyang Zhang > CC: Vitaly Kuznetsov > --- > drivers/pci/host/pci-hyperv.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c > index 7590ad0..fe5179d 100644 > --- a/drivers/pci/host/pci-hyperv.c > +++ b/drivers/pci/host/pci-hyperv.c > @@ -1582,6 +1582,10 @@ static void hv_eject_device_work(struct > work_struct *work) > pci_dev_put(pdev); > } > > + spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); > + list_del(&hpdev->list_entry); > + spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags); > + > memset(&ctxt, 0, sizeof(ctxt)); > ejct_pkt = (struct pci_eject_response *)&ctxt.pkt.message; > ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE; > @@ -1590,10 +1594,6 @@ static void hv_eject_device_work(struct > work_struct *work) > sizeof(*ejct_pkt), (unsigned long)&ctxt.pkt, > VM_PKT_DATA_INBAND, 0); > > - spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); > - list_del(&hpdev->list_entry); > - spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags); > - > put_pcichild(hpdev, hv_pcidev_ref_childlist); > put_pcichild(hpdev, hv_pcidev_ref_pnp); > put_hvpcibus(hpdev->hbus); > -- > 2.7.4 This looks good, too. -- Jake Oshins