Received: by 10.223.185.116 with SMTP id b49csp2957922wrg; Mon, 5 Mar 2018 11:27:38 -0800 (PST) X-Google-Smtp-Source: AG47ELvTM04FnoZF6pWYJZ3EuAPQXD/CP37W/08lAyY5/jSxBbgAl8/coviehfptUJSd62p2b9Ic X-Received: by 2002:a17:902:684:: with SMTP id 4-v6mr13787467plh.262.1520278058030; Mon, 05 Mar 2018 11:27:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520278057; cv=none; d=google.com; s=arc-20160816; b=GdxGjFJwMIWlco6xem8dnZWG6nW6Y0fZHXEtrBY85+3s7Hey+c7atviUQ1UTfoz+fV p7fc60RU9kuaWQFcNPjaL9ZjOnNRjhiHKt8R2MZBfXsJ6VFj435+lAgB70WL3da6+/H1 Ok6wTu8vi9RE1Fwb6YVrgRHADSCUkQYXK8O+B4u9bLFcj3ap+Bbz/P776d+7WClN3HxC Hhh6fdtRHqevN+DyJvDXFDHadupagtHpxa/q/SRwJtwaArBn0Mn4C++0QPOAlRxMm765 NIi/RmyQ+dT4u3oizlAJdtCKjtCZYZOTSBzMU2s6TWxXRWQWoD9Mk3sbvJ3LHrol9Vuf vWhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=fI09oBugTBMw/6wJrr5UWqNpvgm9pXkZrMeZGwGi6Ao=; b=uF8aV0umlQwTHGFuV+n+To5Bju38XTlz9zm9J+nqbfY6aJqqi4CsvN1xlnrkdu8y95 YPKdEHGcXp5PkH7Db19eReEkcLuvu9UXSLdGMvyF99KmbCrcWS7h5fqANC5U2is8KjUs CTmGdxfzg+AhcvcA5Gr3tWVR+mOqQAN7Fypq6vcQq3KmD0OwgjlzYoFmh8kfFHuQ1TqH thsCQpLo85n6gZfETAIEOt9kJjQGOuTW/12QjElBnyVXWroJvqS0PNpPHqQg6OVPgW24 Ycm4XIiGy0L/WdHZS2tlXIRJzcCKNiDMPscDEHE8Swb/U9VtWHYoAj1umDV+0nFhjnMl fXDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=lReeaGQL; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u19si8714336pgv.195.2018.03.05.11.27.23; Mon, 05 Mar 2018 11:27:37 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=lReeaGQL; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932501AbeCETYq (ORCPT + 99 others); Mon, 5 Mar 2018 14:24:46 -0500 Received: from mail-pu1apc01on0111.outbound.protection.outlook.com ([104.47.126.111]:38336 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752935AbeCETWZ (ORCPT ); Mon, 5 Mar 2018 14:22:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=fI09oBugTBMw/6wJrr5UWqNpvgm9pXkZrMeZGwGi6Ao=; b=lReeaGQLCJj2HwTeaaeNG87idFI8XUKyHNY5v7so6iJxFbk8OYf1gmp8kvGNs+JO+a1pYGF5ztNuSoHu5NUg0txHBAOvsBUlN4naybho+cGCgLFX6Jk57HXw1ADcQB9VrM+E6CWMlwG4GqA75NwQo8+va60jl4RsTSyfevSlID0= Received: from KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM (10.170.167.17) by KL1P15301MB0039.APCP153.PROD.OUTLOOK.COM (10.170.168.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.7; Mon, 5 Mar 2018 19:22:17 +0000 Received: from KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM ([10.170.167.17]) by KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM ([10.170.167.17]) with mapi id 15.20.0588.001; Mon, 5 Mar 2018 19:22:17 +0000 From: Dexuan Cui To: "bhelgaas@google.com" , "linux-pci@vger.kernel.org" , KY Srinivasan , Stephen Hemminger , "olaf@aepfle.de" , "apw@canonical.com" , "jasowang@redhat.com" CC: "linux-kernel@vger.kernel.org" , "driverdev-devel@linuxdriverproject.org" , Haiyang Zhang , "vkuznets@redhat.com" , "marcelo.cerri@canonical.com" , "Michael Kelley (EOSG)" , Dexuan Cui , Jack Morgenstein , "stable@vger.kernel.org" Subject: [PATCH v2 3/6] PCI: hv: serialize the present/eject work items Thread-Topic: [PATCH v2 3/6] PCI: hv: serialize the present/eject work items Thread-Index: AQHTtLdF9VixgM1SgE2S1sRr4R78NQ== Date: Mon, 5 Mar 2018 19:22:17 +0000 Message-ID: <20180305192134.32207-4-decui@microsoft.com> References: <20180305192134.32207-1-decui@microsoft.com> In-Reply-To: <20180305192134.32207-1-decui@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.15.1 authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;KL1P15301MB0039;7:vCnXLLktDG9wM9uw0/ZEZI+QhTjhA/+x1Dw0hTRrqRw6/lQOF1GKhIMe0RuH7yda1Azx4RCgfV52m+yCLTniZOR0aAXXam7BsnUYxjJNx+WRZhjIo28cpWxCbMHhaqImPTZYXskTPY72WWbcbCFwo4YqWWYEphCJffJKpr/kXA2mudZrjezSzSLkRV5WccDVG/WbNyBmp36e9RX0loMOhVW/95gjVnFOevxLbhWJ56nCI6RFH6FGYen2W0VrYhWN;20:BMIgCHOjLa3kcajAuWaXLSlf2Kw+CBdKZxdXT/91Oci7hCpLVG8gHhc7xKSc7nX8geFaELiJkU+YfPGCx3StpwOGHTYiqFvV/AuyeQho9TtswUE0MnWyAqnc6T1NwPNrAvKbbzqQMvxwIPA2IismqGUvDlZOQaIwHu2km3HcQiE= x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 623ac24b-c760-401e-1983-08d582ce68d0 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7193020);SRVR:KL1P15301MB0039; x-ms-traffictypediagnostic: KL1P15301MB0039: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(9452136761055); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231220)(944501244)(52105095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:KL1P15301MB0039;BCL:0;PCL:0;RULEID:;SRVR:KL1P15301MB0039; x-forefront-prvs: 06022AA85F x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39380400002)(396003)(366004)(376002)(39860400002)(199004)(189003)(1076002)(7416002)(5660300001)(6116002)(316002)(76176011)(86362001)(106356001)(36756003)(4326008)(105586002)(2950100002)(77096007)(26005)(25786009)(3846002)(22452003)(110136005)(2201001)(59450400001)(99286004)(102836004)(6506007)(54906003)(186003)(86612001)(8936002)(66066001)(68736007)(3280700002)(81156014)(478600001)(1511001)(14454004)(8676002)(6436002)(81166006)(3660700001)(53936002)(2501003)(10290500003)(2906002)(6486002)(2900100001)(7736002)(6512007)(50226002)(305945005)(10090500001)(97736004)(22906009);DIR:OUT;SFP:1102;SCL:1;SRVR:KL1P15301MB0039;H:KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: oRGgeVPi4o4BUfpQJL9T7XFe43eTi3uunLbbXCJlhMe80sPwYZHajIG9MANgLlE+T85RmNTg6YafFJNyELT+ApohGyn7QZlbPcYvvKttQzC9iuoqTtm+YI6RcYW10vYSJFNrrPHRtA2yGhH4UvR0IMmiKVnaXidCAdkEQXdYLn/l0vrTN3z9zJsURQxJvIzPRCtyM51xwR6gdsly5daFflwrNi8+EU6SnQgh/JG71fPvDtkfO/IA/tLE0aqB4ITtkdKl6rTcI7QZwD8V1aZqZDoBB10A7lgzeCN31BHnKrsJSxvJs4iOvrCzk7iDSkkEWUK+6xodC0nsX5oQ+DdUig== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 623ac24b-c760-401e-1983-08d582ce68d0 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Mar 2018 19:22:17.0320 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1P15301MB0039 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we hot-remove the device, we first receive a PCI_EJECT message and then receive a PCI_BUS_RELATIONS message with bus_rel->device_count =3D=3D = 0. The first message is offloaded to hv_eject_device_work(), and the second is offloaded to pci_devices_present_work(). Both the paths can be running list_del(&hpdev->list_entry), causing general protection fault, because system_wq can run them concurrently. The patch eliminates the race condition. Signed-off-by: Dexuan Cui Tested-by: Adrian Suhov Tested-by: Chris Valean Cc: Vitaly Kuznetsov Cc: Jack Morgenstein Cc: stable@vger.kernel.org Cc: Stephen Hemminger Cc: K. Y. Srinivasan --- drivers/pci/host/pci-hyperv.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 04edb24c92ee..aaee41faf55f 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -461,6 +461,8 @@ struct hv_pcibus_device { struct retarget_msi_interrupt retarget_msi_interrupt_params; =20 spinlock_t retarget_msi_interrupt_lock; + + struct workqueue_struct *wq; }; =20 /* @@ -1770,7 +1772,7 @@ static void hv_pci_devices_present(struct hv_pcibus_d= evice *hbus, spin_unlock_irqrestore(&hbus->device_list_lock, flags); =20 get_hvpcibus(hbus); - schedule_work(&dr_wrk->wrk); + queue_work(hbus->wq, &dr_wrk->wrk); } =20 /** @@ -1845,7 +1847,7 @@ static void hv_pci_eject_device(struct hv_pci_dev *hp= dev) get_pcichild(hpdev, hv_pcidev_ref_pnp); INIT_WORK(&hpdev->wrk, hv_eject_device_work); get_hvpcibus(hpdev->hbus); - schedule_work(&hpdev->wrk); + queue_work(hpdev->hbus->wq, &hpdev->wrk); } =20 /** @@ -2460,11 +2462,17 @@ static int hv_pci_probe(struct hv_device *hdev, spin_lock_init(&hbus->retarget_msi_interrupt_lock); sema_init(&hbus->enum_sem, 1); init_completion(&hbus->remove_event); + hbus->wq =3D alloc_ordered_workqueue("hv_pci_%x", 0, + hbus->sysdata.domain); + if (!hbus->wq) { + ret =3D -ENOMEM; + goto free_bus; + } =20 ret =3D vmbus_open(hdev->channel, pci_ring_size, pci_ring_size, NULL, 0, hv_pci_onchannelcallback, hbus); if (ret) - goto free_bus; + goto destroy_wq; =20 hv_set_drvdata(hdev, hbus); =20 @@ -2533,6 +2541,8 @@ static int hv_pci_probe(struct hv_device *hdev, hv_free_config_window(hbus); close: vmbus_close(hdev->channel); +destroy_wq: + destroy_workqueue(hbus->wq); free_bus: free_page((unsigned long)hbus); return ret; @@ -2612,6 +2622,7 @@ static int hv_pci_remove(struct hv_device *hdev) irq_domain_free_fwnode(hbus->sysdata.fwnode); put_hvpcibus(hbus); wait_for_completion(&hbus->remove_event); + destroy_workqueue(hbus->wq); free_page((unsigned long)hbus); return 0; } --=20 2.7.4