Received: by 10.213.65.68 with SMTP id h4csp1764809imn; Mon, 19 Mar 2018 12:37:23 -0700 (PDT) X-Google-Smtp-Source: AG47ELtCt3Oh1RbgVkNMmYSgQ6RDPRX4BEX6qVVOQtNUvRfUu3uqOj2k7MB7JDMFE56Pnrbwp3jX X-Received: by 10.99.180.6 with SMTP id s6mr4796708pgf.81.1521488243033; Mon, 19 Mar 2018 12:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521488243; cv=none; d=google.com; s=arc-20160816; b=mEG+ZZ+5w7asRhIPkfMdmvwpA5TYtq/qb23U8YxTrq/CMUkxZIW3Zskh3QGpkqfbqC J0+v5f+IeP+09TbkZ19VZhDhpM09KO4f5XpmcPBmgRt+vMo18H8+/R8mfJuc75/Ro2Fr ghWpIvZjmwyagtoS5mOWDOrDJdDBNuKV+tR1mNZ0R/qrPE7oqumfkfI0gVQs7YSuTjIE MISdPl4wYXMKy5IvpsJMUEzo/8sHykdWzC0Zv8fsjm5U/dKSCHfbtDUcAxdmJMpoLa6Y IIdi25T4F38BEYdVEzQMkn5s62H313vcsOnUKZW5gwGcUb5EZRhMAl0k0nOvSd4Xy8TX LK2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=VFbmXSDDwaMm3+Bu+0xmvHtOKI+C2JmbU5LoRSIjOV8=; b=mromsqUUdTpDaS3X11mmc4o43Jy00HofXpdILTZ4uWXoJoPPAdPcDkNuli9gjIie5e arI3RJsfrJ2Co5lcDRcPMo/SS6Tzle658QPBxzSXooLyAehaaTgp3KvEYpK0WmwRKE7d TpIzg8ZhLz4EcgN7dHj0vXoQdNiy1jz8QaAqlgZJlJbS+BNChmDc7UHfXx7r1d/PIOVQ utQXw7GMyiLAmWHGEcweSVLrZxKLuekTDL9Ldil7FfBBYrhYE1jc/T5Xl97tGnMnB/se fdejwVpGvMDOacrk/w0VPqqSAL74Xpb10A5gKW+cG4eXUJoZ9qeLMO/66b69xjZxeCNY 9+9w== ARC-Authentication-Results: i=1; mx.google.com; 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 4-v6si505175plh.540.2018.03.19.12.37.08; Mon, 19 Mar 2018 12:37:22 -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; 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 S936119AbeCSTfe (ORCPT + 99 others); Mon, 19 Mar 2018 15:35:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48612 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031272AbeCSSWi (ORCPT ); Mon, 19 Mar 2018 14:22:38 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D2BB012A2; Mon, 19 Mar 2018 18:22:37 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaofeng Wang , Long Li , Bjorn Helgaas , "K. Y. Srinivasan" , Sasha Levin Subject: [PATCH 4.9 061/241] PCI: hv: Lock PCI bus on device eject Date: Mon, 19 Mar 2018 19:05:26 +0100 Message-Id: <20180319180753.729464994@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Long Li [ Upstream commit 414428c5da1c71986727c2fa5cdf1ed071e398d7 ] A PCI_EJECT message can arrive at the same time we are calling pci_scan_child_bus() in the workqueue for the previous PCI_BUS_RELATIONS message or in create_root_hv_pci_bus(). In this case we could potentially modify the bus from multiple places. Properly lock the bus access. Thanks Dexuan Cui for pointing out the race condition in create_root_hv_pci_bus(). Reported-by: Xiaofeng Wang Signed-off-by: Long Li Signed-off-by: Bjorn Helgaas Acked-by: K. Y. Srinivasan Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pci/host/pci-hyperv.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -1206,9 +1206,11 @@ static int create_root_hv_pci_bus(struct hbus->pci_bus->msi = &hbus->msi_chip; hbus->pci_bus->msi->dev = &hbus->hdev->device; + pci_lock_rescan_remove(); pci_scan_child_bus(hbus->pci_bus); pci_bus_assign_resources(hbus->pci_bus); pci_bus_add_devices(hbus->pci_bus); + pci_unlock_rescan_remove(); hbus->state = hv_pcibus_installed; return 0; } @@ -1597,8 +1599,10 @@ static void hv_eject_device_work(struct pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, wslot); if (pdev) { + pci_lock_rescan_remove(); pci_stop_and_remove_bus_device(pdev); pci_dev_put(pdev); + pci_unlock_rescan_remove(); } memset(&ctxt, 0, sizeof(ctxt));