Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp468700yba; Wed, 15 May 2019 04:39:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOu9uuXEBXOUSfORJvwWpDP0h/i7dlVq9WPbLzGKk+RJ1hQvvpndUVrQ9RKrZAVBCJJT17 X-Received: by 2002:a63:cc4e:: with SMTP id q14mr42405695pgi.84.1557920393831; Wed, 15 May 2019 04:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920393; cv=none; d=google.com; s=arc-20160816; b=LhjVjPI2seiR7NUvcNBW8nkrlO/K7sJlz0tsENDKNhqCMfot4eG5jHS2isY4i3nvk0 mGupLFnNPp8wkS6oqYPXXSu37yvmZGN35VbHsCLhsb9nFHLP8pondWjD8AScM99y1pNF PQ3NYkzY6G4Vf4KUTiVJyKlx3HRQcBBnK91d3WEP4moPMGwmhpp3tCiGdWLdaDYxj8qt lWpWPz2v9PWFT2e6nEhhMDC4El8J2Npi//ERaE7DmLFr3KXC7A/0+ooSVOeaCT60kEoa pKdiZhCzu4NOgGm0mFLUBywyl8f4uB2J0Y/HTlBHXj+Sbmlvb+zIMNkhqQHj13Ng9Q/w CezA== 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=nGIzO0jRFbeSlCGtFlZMfvCWvhULb4boH/kNooB2+8M=; b=rGqDNY8/3s76dC7e2EpwEIGmTq0RDRdvnodKpdNM+MdvdZQbQsJHy695iv4UbP4nUu Sk9CCyjwYGEchUoDv0Vx9zcrvFDr2Y+KPP4BRi1vpyYqH3iz4of5xwsTjaY171Nb2qeL Z2O3rPDVoFxzsuIaCe472FVks0U83lp2dD4WNl5LNkGu7drIHByl0dpR6eevK3MYy1cv i0JiQ+X/x/K4gm4yxdJTPYIN4AB0glNmZB+Lp1bZoHYpztTRrtgL7PEifym6graKtmNj uqn3TzynUsiLHXyPEiWOWAECBHOhfiveyur5r0UpsKML0bXKKWJU5hMlWPHzUoll7Jwl HCQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2Z/03CD/"; 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 z143si1828856pfc.38.2019.05.15.04.39.39; Wed, 15 May 2019 04:39:53 -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="2Z/03CD/"; 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 S1733029AbfEOLhu (ORCPT + 99 others); Wed, 15 May 2019 07:37:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:43408 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727939AbfEOLbi (ORCPT ); Wed, 15 May 2019 07:31:38 -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 C517C2084F; Wed, 15 May 2019 11:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919897; bh=hntAyRFrvw6Cr9yi4hm6U6Z3YwulC1viRtaaSaqeOA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2Z/03CD/ogprc5LpOkCqJ6Lt3IpHMI1aS+nZaXWGBNZ1E7Na+JN1f4gBKBR6d6TcB Z2i+hjYY/yVoJ7DUVeiYXPPVoZ6siHNLDrXDIMssFsOsEhSCWPGkkENTNrYg2IWyxZ 9hsdtdNG7b3qMjWiF+fwT0ixqnjKhziG8RMsf6T0= 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 Subject: [PATCH 5.0 136/137] PCI: hv: Add pci_destroy_slot() in pci_devices_present_work(), if necessary Date: Wed, 15 May 2019 12:56:57 +0200 Message-Id: <20190515090703.727867468@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@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 From: Dexuan Cui commit 340d455699400f2c2c0f9b3f703ade3085cdb501 upstream. 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 == 0. When we execute 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() because the code path 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 == 0. In the quick hot-add/hot-remove test, we can have such a race before the code path pci_devices_present_work() -> new_pcichild_device() adds the new device into the hbus->children list, we may have already received the PCI_EJECT message, and since the tasklet handler hv_pci_onchannelcallback() may fail to find the "hpdev" by calling get_pcichild_wslot(hbus, dev_message->wslot.slot) hv_pci_eject_device() is not called; Later, by continuing execution create_root_hv_pci_bus() -> hv_pci_assign_slots() creates the slot and the PCI_BUS_RELATIONS message with bus_rel->device_count == 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() Remove the slot in pci_devices_present_work() when the device is removed to address this race. 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. We cannot offload hv_pci_eject_device() from hv_pci_onchannelcallback() to the workqueue, because we need the hv_pci_onchannelcallback() synchronously call hv_pci_eject_device() to poll the channel ringbuffer to work around the "hangs in hv_compose_msi_msg()" issue fixed in commit de0aa7b2f97d ("PCI: hv: Fix 2 hang issues in hv_compose_msi_msg()") Fixes: a15f2c08c708 ("PCI: hv: support reporting serial number as slot information") Signed-off-by: Dexuan Cui [lorenzo.pieralisi@arm.com: rewritten commit log] Signed-off-by: Lorenzo Pieralisi Reviewed-by: Stephen Hemminger Reviewed-by: Michael Kelley Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/pci/controller/pci-hyperv.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1781,6 +1781,10 @@ static void pci_devices_present_work(str hpdev = 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); }