Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp474546yba; Wed, 15 May 2019 04:47:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqz92u4wysE2jttwjibUj4qWDSeFWVFWs3Mcc3g3Oo7NRkyX2Ga5POPXQ2mayimSAjCEDizu X-Received: by 2002:a63:a08:: with SMTP id 8mr43115981pgk.46.1557920844121; Wed, 15 May 2019 04:47:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920844; cv=none; d=google.com; s=arc-20160816; b=Wwjy6z3GYc9K8dzYrU7QE6KVmd4H/Mh/pe/qmUYVUTXo6CO7UEcdHt3y/Da5fFKbq+ 9T5LFwO7E+lRVnzqiDdVXz/tX07TnF0v6N8yisn0ZrRHFymfMu6RwgF/NGx2cRxTEhHj nhlq+Ih/EMJukziWG7iaj7EO4XjegCwQXoIcxdsR9flD02WdSmN87zcKwXVWBd7u/o5M we32bVp2/4ACX5pWQs9TPHruH5iS9JEdxGzu64YU4DBOifOExnA8tp1W43JcKdVGyG2V Y6m7npT+nM1mly3jo/38aqjBLZS/UXTIKRmDjOtCwgID/V7JWHJ1gBZJnCGg2oJlZOc1 eIOQ== 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=S5FviCM4S0NGiHKRtv91vwYyFVtUe8HemZve3IOz9MwonPwrROQttmSkHNj7H7HbEj /8rLqzsBn+BP975udXnmyu3ARy7A/FmP4W2Dj7TFTUBywjfYHrT2V086D5V/IeQg5Y2v 24wlOykqqn7+X9t+BCkN1wiOoVpVBigHeq8tjhsijWNHgF2cm4YahHrWqpKGwoKsQWzT ojOrJTqeSBFMS0BYXGUKH2x5E707UxP8kUkHw5RUb7y9s3JeMNxg8KtkGiTE+IXhae+3 1+gTn0hV7z+aoByZxePPJl/DTs9Ydy6TfcqodkiyH+Iv2yXNvlobgUzQLxZnal1MJzKS l6DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DvXQ2+N+; 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 e37si1628913plb.10.2019.05.15.04.47.09; Wed, 15 May 2019 04:47:24 -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=DvXQ2+N+; 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 S1732166AbfEOLqI (ORCPT + 99 others); Wed, 15 May 2019 07:46:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:36446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732025AbfEOLZj (ORCPT ); Wed, 15 May 2019 07:25:39 -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 1A4A2206BF; Wed, 15 May 2019 11:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919538; bh=hntAyRFrvw6Cr9yi4hm6U6Z3YwulC1viRtaaSaqeOA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DvXQ2+N+7aocL6bHBzUHOgkReqyb6U3J76Fh0PWjeo1fw6SaYmnF6+JicRbLon01n eBcMNkXHv4QO+G/572NqpaCEEX4Aiagqm5KLehRrh6WEpKv34laazVKfWmqnoJ2Csy ABZpOxMJdtpTuQ1b/pIGaLtJtl7AvhCVaYlouYGI= 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 4.19 113/113] PCI: hv: Add pci_destroy_slot() in pci_devices_present_work(), if necessary Date: Wed, 15 May 2019 12:56:44 +0200 Message-Id: <20190515090702.312252361@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090652.640988966@linuxfoundation.org> References: <20190515090652.640988966@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); }