Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2763234imb; Mon, 4 Mar 2019 13:35:50 -0800 (PST) X-Google-Smtp-Source: APXvYqwsLQkzlkqU4a9WvT+piDAlKINQ2pEKXaQuz22fVvPWO7xGBap+OXXm+/L+OvsZGxEc5TIx X-Received: by 2002:a17:902:7614:: with SMTP id k20mr22306619pll.298.1551735349953; Mon, 04 Mar 2019 13:35:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551735349; cv=none; d=google.com; s=arc-20160816; b=Yp8QTzVm201O2rcCPJk66qrT2cOMfWR3jHElgGjK1Wu0r5omQlwGEQKTmZOf9HS6JM MVvSl8VtVk4vSA6+Z9VfCKyBTLSjh5S4rhFz5OFsrj1FigEgWwh346THUGHNz3/fxCW8 XF95O+DarsjMmAI0XgerzfFTYgOShKIgmH/UipyMOKnTrLxLsIxJUbozTetmDuiAKO0D ULOG698vXUikkQAvYSBOUxp1rmc7QQwsrNR6QP6B/9UlQWcyQ9rzUM6m4//opc1DaQ8o M4OZKPdu6DMg7TLWDYVpBrwegzOnzIkEW2V6XbG0stPt181Dtm6Tz1ItEGbbLEFoR/El PChA== 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 :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=I6mXG5pEBSPy1IbuUllcnKkUI0oSm7o3lCk621LqegM=; b=ABZwtbWpexbq+2o3bVfzMEBdlQ62XhDBD9vJIcDHlPFikHN+fzMRnhKn2jh7l7VmEv TGauNP/+AxIrLR2Rv2SRpXVXWfC3Rg9t0aD+CcoF408yJoFud/0AmhrNwIzvgijRUaLD XdEb2HQRizLWL1xRkZa7fdzxc4wnul1BOUTOEIggF75SwFkGcvoEL5ttTTJjmY2Is1nD fWROjRwa+kY2hT0Jy00PjP5yqUttJFP0PBrqC1Pfgfk7zulnIHLfnKFjPT/dSae7jsTL 64KvhMCNUyPWaGB3/sISv6vWc5hKfSgKR2DCoxC1KO08hLEYRe4wfxxEA52fRpPRYSEW GqSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ftXULeXU; 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 n6si6106856pgj.96.2019.03.04.13.35.33; Mon, 04 Mar 2019 13:35:49 -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=ftXULeXU; 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 S1726620AbfCDVfD (ORCPT + 99 others); Mon, 4 Mar 2019 16:35:03 -0500 Received: from mail-eopbgr770121.outbound.protection.outlook.com ([40.107.77.121]:59715 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726418AbfCDVez (ORCPT ); Mon, 4 Mar 2019 16:34:55 -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:X-MS-Exchange-SenderADCheck; bh=I6mXG5pEBSPy1IbuUllcnKkUI0oSm7o3lCk621LqegM=; b=ftXULeXUyrrlqJrzoW+H75l+YylVJXhfl61oSbOy5GOhycdSVkoSMTnscI2moDaYTBOYd7xU3zv7FKQ57J4ab6LS0F8d0yBpEw9VmGZkYR+q99xzW0IrOCqv81kboI/gZ94eOEfKeJRwVYx7FoXLe0t12g8tZcKjpR9bySRfmd4= Received: from MN2PR21MB1296.namprd21.prod.outlook.com (20.179.21.154) by MN2PR21MB1183.namprd21.prod.outlook.com (20.179.20.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.4; Mon, 4 Mar 2019 21:34:49 +0000 Received: from MN2PR21MB1296.namprd21.prod.outlook.com ([fe80::8d7a:2ffa:8916:69c3]) by MN2PR21MB1296.namprd21.prod.outlook.com ([fe80::8d7a:2ffa:8916:69c3%3]) with mapi id 15.20.1709.002; Mon, 4 Mar 2019 21:34:49 +0000 From: Dexuan Cui To: "lorenzo.pieralisi@arm.com" , "bhelgaas@google.com" , "linux-pci@vger.kernel.org" , KY Srinivasan , Stephen Hemminger , Michael Kelley , Sasha Levin CC: "linux-hyperv@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "driverdev-devel@linuxdriverproject.org" , Haiyang Zhang , "olaf@aepfle.de" , "apw@canonical.com" , "jasowang@redhat.com" , vkuznets , "marcelo.cerri@canonical.com" , "jackm@mellanox.com" , Dexuan Cui , "stable@vger.kernel.org" Subject: [PATCH 3/3] PCI: hv: Add pci_destroy_slot() in pci_devices_present_work(), if necessary Thread-Topic: [PATCH 3/3] PCI: hv: Add pci_destroy_slot() in pci_devices_present_work(), if necessary Thread-Index: AQHU0tIY8DrNYkUs0k++5L52C5B9ng== Date: Mon, 4 Mar 2019 21:34:49 +0000 Message-ID: <20190304213357.16652-4-decui@microsoft.com> References: <20190304213357.16652-1-decui@microsoft.com> In-Reply-To: <20190304213357.16652-1-decui@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR11CA0010.namprd11.prod.outlook.com (2603:10b6:405:2::20) To MN2PR21MB1296.namprd21.prod.outlook.com (2603:10b6:208:3e::26) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.19.1 x-originating-ip: [107.180.71.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e134f3e4-dcea-4722-b04d-08d6a0e93abe x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:MN2PR21MB1183; x-ms-traffictypediagnostic: MN2PR21MB1183: x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-forefront-prvs: 09669DB681 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(136003)(39860400002)(346002)(366004)(396003)(40224003)(199004)(189003)(26005)(25786009)(6346003)(2501003)(476003)(22452003)(10090500001)(446003)(2616005)(486006)(11346002)(99286004)(6116002)(3846002)(14454004)(478600001)(81156014)(81166006)(316002)(8676002)(7736002)(76176011)(6506007)(386003)(1511001)(106356001)(105586002)(53936002)(6512007)(186003)(7416002)(66066001)(54906003)(110136005)(52116002)(305945005)(6486002)(36756003)(6436002)(102836004)(8936002)(4326008)(68736007)(71200400001)(6636002)(97736004)(86362001)(256004)(2906002)(2201001)(71190400001)(5660300002)(50226002)(10290500003)(1076003)(86612001);DIR:OUT;SFP:1102;SCL:1;SRVR:MN2PR21MB1183;H:MN2PR21MB1296.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: nDY0Sde0G5/4D3jMxa+z8FKC1Rm+TUIkqTrK4LC/OoNtQ9MF07AjuU1d34eV29vW3Wk7M5jzGUF1KOWwPWDinE9wdTQorADNybywnR9lxIPx0nN/g0zftnlmvjiS7r4/4zdA23iCYyoO6Y24tK8XMNLUTQPGQMf7fsdeXXIRKI+tJcr92zQOgJ8Di+sNoaGQIAOOXcRuIv470CMGfpMPaUXlnx/3a3HoveoLZVV8QsEjX4iH4PHroeJkOAH9ueKL7pj7Etkm+XqsEmLTknQR/oKeHCEdMdRsXVdOuV25Xo57rw/xHU+bDM9bA7TKsSRzlleddiTtItmAVhnziVanVlIHFLbDxdlpFOvWVnlXOzNolD2e0FCEqoqUoUuozDaJbw78EvpE/wlTr9JXyHTnESntJoE82SFKaRYM386mzdI= 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: e134f3e4-dcea-4722-b04d-08d6a0e93abe X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Mar 2019 21:34:49.5785 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR21MB1183 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we hot-remove a device, usually the host sends us a PCI_EJECT message, and a PCI_BUS_RELATIONS message with bus_rel->device_count =3D=3D 0. But wh= en we do the quick hot-add/hot-remove test, the host may not send us the PCI_EJECT message, if the guest has not fully finished the initialization by sending the PCI_RESOURCES_ASSIGNED* message to the host, so it's potentially unsafe to only depend on the pci_destroy_slot() in hv_eject_device_work(), though create_root_hv_pci_bus() -> hv_pci_assign_slots() is not called in this case. Note: in this case, the host still sends the guest a PCI_BUS_RELATIONS message with bus_rel->device_count =3D=3D 0. And, in the quick hot-add/hot-remove test, we can have such a race: before pci_devices_present_work() -> new_pcichild_device() adds the new device into hbus->children, we may have already received the PCI_EJECT message, and hence the taklet handler hv_pci_onchannelcallback() may fail to find the "hpdev" by get_pcichild_wslot(hbus, dev_message->wslot.slot), so hv_pci_eject_device() is NOT called; later create_root_hv_pci_bus() -> hv_pci_assign_slots() creates the slot, and the PCI_BUS_RELATIONS message with bus_rel->device_count =3D=3D 0 removes the device from hbus->children,= and we end up being unable to remove the slot in hv_pci_remove() -> hv_pci_remove_slots(). The patch removes the slot in pci_devices_present_work() when the device is removed. This can address the above race. Note 1: pci_devices_present_work() and hv_eject_device_work() run in the singled-threaded hbus->wq, so there is not a double-remove issue for the slot. Note 2: we can't offload hv_pci_eject_device() from hv_pci_onchannelcallback() to the workqueue, because we need hv_pci_onchannelcallback() synchronously call hv_pci_eject_device() to poll the channel's ringbuffer to work around the "hangs in hv_compose_msi_msg()" issue: see commit de0aa7b2f97d ("PCI: hv: Fix 2 hang issues in hv_compose_msi_msg()") Fixes: a15f2c08c708 ("PCI: hv: support reporting serial number as slot info= rmation") Signed-off-by: Dexuan Cui Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-hyperv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/p= ci-hyperv.c index b489412e3502..82acd6155adf 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1776,6 +1776,10 @@ static void pci_devices_present_work(struct work_str= uct *work) hpdev =3D list_first_entry(&removed, struct hv_pci_dev, list_entry); list_del(&hpdev->list_entry); + + if (hpdev->pci_slot) + pci_destroy_slot(hpdev->pci_slot); + put_pcichild(hpdev); } =20 --=20 2.19.1