Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1501908lqa; Mon, 29 Apr 2024 10:09:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXQeLTyjKpaTOybpJPNIiBCMtNPej8gSe6v5RCYEQqXga4OF5t/i1OY+M1aGW0YB4UxWET2MVnacH+29DL+Z21XgV38FdTYwzWddL9ZQA== X-Google-Smtp-Source: AGHT+IEEYF96iKzGhMYserISBKduxFlQkOMARVLUMJdmZKZSbJUOHAVa5nn9I/SmfNODH0gGZfMp X-Received: by 2002:a05:6a21:8804:b0:1af:3857:e652 with SMTP id ta4-20020a056a21880400b001af3857e652mr236473pzc.12.1714410553330; Mon, 29 Apr 2024 10:09:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714410553; cv=pass; d=google.com; s=arc-20160816; b=nT8zsgd9thMyAcafyCxRYGugrKZ13McW2ARYQ9RAWZ3IxVVJp3UrMxQmMaOKT8g0Yf 8iXKnFwMV5QMbpUFEjObIx0miTU/ezeOVoyILJ1bsyl8+5OiTYGHObbBvCC9B9eUbYep 0WOorKPtoF+WROOA4U+kF+s68Ylw+jBpKzpXwZ7AkNh6aOWuaR2z40wZ2v0LxNyL8lHY G4y8H1bRK0BlxC/TMQPOp5VaNBs2KFw1Gdi+2emqSWmWjww3q9GuWyxufcpAmwHNx9eJ bsbJ+nJgvtqn4R5oXUKSc7fZOK7ECJ1NH4JJuPP8adgsrJbIgeQ7vZkOjKrn7B84A/vh /Thg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date:dkim-signature; bh=fVNCfrMgTKnZYQXpYuYyppwOTNCvbGXHOK9td8m3e4I=; fh=dD9PRq9Uhbt9K/aIs1R5KJNAkM6oTJba4JUlGVT6SmA=; b=sFIivTv4kBHY4aLW37t40qG7hu2+ewh9oUgZoQk2b1njjD67aSFuw+UvDlbCd+5TPV M7qdkDcQjqjWP6DcpTaf9pj5yMuEsKOF8awGDE29FQr2vJ3P1bKZuaG9tBhLTgJRcdHw hbG2bkwgAQIH85OjMTg70A3bhSqOQqjsnr2st1xxvHmbG5gv3CZAlz69aaZs4/xDAcan nGjx/q09FtKC+TeeoZS8isPGIfJwrX3nD5/mk6M+qQvm+zwqbmgJKjJr4TAeO7B9Hvns Wol24aYPD09DDSFpaBQBUdne1KVxn3XqMbFotkqqWH/cwywHMKG8jfIcpWuvYSmfI8ya CgSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iMjeCDcp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-162720-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162720-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z129-20020a633387000000b005fe5c7f32e7si15476262pgz.332.2024.04.29.10.09.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 10:09:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162720-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iMjeCDcp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-162720-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162720-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5F534B22A05 for ; Mon, 29 Apr 2024 17:04:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 690568626E; Mon, 29 Apr 2024 17:03:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iMjeCDcp" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A5CF83CBA; Mon, 29 Apr 2024 17:03:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714410238; cv=none; b=Z7N2k9Wwz9RRIyJkUbJEibG4Rs4eZ8TGH1y/FkKTudpkYI0XXzdLvKW3eTeO7JK7ueuj/5xzXoNFZAyW8taXnG6y8ykuJaes6GhwcraTDqk/63QBX3gJBYhW25frwhLN2pOcHSqd2Aou/QrXubhhoYTXl+F21jQUoKRJdRnqF+A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714410238; c=relaxed/simple; bh=N8lmt1eTjPPMtVK/lMhpi6YmGYOP38QLWrQAMXxIhpk=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=pLZ5Pa/iSKULBnfkYdaseQHnjUcOHAM8684MI8l+NzZS5MPliEwWdJgPAOG3gTunhomsfKSGQB54u71EKhVle3bW1BwK36Rqn+y0LHrkbQlnRtDMv4PFQokH1cgcqpIvwdPxqthHmoJL/0nv0ZANoTToGbRS7WW47SRBT8IaZFM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iMjeCDcp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2CC4C4AF14; Mon, 29 Apr 2024 17:03:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714410238; bh=N8lmt1eTjPPMtVK/lMhpi6YmGYOP38QLWrQAMXxIhpk=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=iMjeCDcpPjvgPqcda1yz47UZoN3OK71XgRAyvTJVe+Gc0btCjFlFXoNK4hd0MTP8V ShfJKTu6k6KCW/JNSEyivLMjPDWUTrtHWaUibqxCX8v6qW1n8d2tt9rfKy5qS7Mcg4 7wU4s43tBpofdkubrutgKq4LMJvdjlgxQT6htz8S1dVVToSTjkAwqJUa2eiB34QYmn qg+RQHgI2zW1qLffpQILdRXOoxlntktfbmFj7fQSi/vTzWzRLS7utr2Rji38jtdyvJ scwcgAwAyxaFHxCaV0s1h3ftELgVJWfXi5so5qF3LFU7/vcAsxwFZNfCT+Dfx24yuh 513WiVVFLmFdQ== Date: Mon, 29 Apr 2024 12:03:55 -0500 From: Bjorn Helgaas To: Dexuan Cui Cc: bhelgaas@google.com, wei.liu@kernel.org, kys@microsoft.com, haiyangz@microsoft.com, lpieralisi@kernel.org, linux-pci@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, Boqun.Feng@microsoft.com, sunilmut@microsoft.com, ssengar@microsoft.com Subject: Re: [PATCH] PCI: Add a mutex to protect the global list pci_domain_busn_res_list Message-ID: <20240429170355.GA685838@bhelgaas> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240425225136.GA541002@bhelgaas> On Thu, Apr 25, 2024 at 05:51:38PM -0500, Bjorn Helgaas wrote: > On Thu, Apr 18, 2024 at 06:53:02PM -0700, Dexuan Cui wrote: > > There has been an effort to make the pci-hyperv driver support > > async-probing to reduce the boot time. With async-probing, multiple > > kernel threads can be running hv_pci_probe() -> create_root_hv_pci_bus() -> > > pci_scan_root_bus_bridge() -> pci_bus_insert_busn_res() at the same time to > > update the global list, causing list corruption. > > > > Add a mutex to protect the list. > > I think it's a good idea to support probing multiple PCI root buses in > parallel. > > The problem in get_pci_domain_busn_res() is the global > pci_domain_busn_res_list. I'm not even sure what that list contains, > since it's a lookup by "domain_nr". In the hv case, you probably have > one host bridge per domain, but in general there may be multiple root > buses in the same domain, e.g., > > ACPI: PCI Root Bridge [PC00] (domain 0000 [bus 00-16]) > ACPI: PCI Root Bridge [PC01] (domain 0000 [bus 17-39]) > ACPI: PCI Root Bridge [PC02] (domain 0000 [bus 3a-5c]) > ... > > We only use get_pci_domain_busn_res() for root buses, and we should > know the bus number range for root buses when we set up the struct > pci_host_bridge, so it seems like we should keep the bus number > resource there instead of allocating it in this sort of random place. > > Then we shouldn't need this weird pci_domain_busn_res_list at all. Oops, sorry, I totally missed the point here. The point is that for each domain, we get a new 00-ff range of possible bus numbers. This is independent of the host bridges for that domain that may exist. Then each host bridge will allocate a piece of the 00-ff range. But I do still think get_pci_domain_busn_res() isn't really the best place for this. It seems like it should be at a higher level, connected somehow to domain number allocation, e.g., somewhere related to bridge->domain_nr like the pci_bus_find_domain_nr() path. > > Signed-off-by: Dexuan Cui > > --- > > drivers/pci/probe.c | 25 ++++++++++++++++++------- > > 1 file changed, 18 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c > > index e19b79821dd6..1327fd820b24 100644 > > --- a/drivers/pci/probe.c > > +++ b/drivers/pci/probe.c > > @@ -37,6 +37,7 @@ LIST_HEAD(pci_root_buses); > > EXPORT_SYMBOL(pci_root_buses); > > > > static LIST_HEAD(pci_domain_busn_res_list); > > +static DEFINE_MUTEX(pci_domain_busn_res_list_lock); > > > > struct pci_domain_busn_res { > > struct list_head list; > > @@ -47,14 +48,22 @@ struct pci_domain_busn_res { > > static struct resource *get_pci_domain_busn_res(int domain_nr) > > { > > struct pci_domain_busn_res *r; > > + struct resource *ret; > > > > - list_for_each_entry(r, &pci_domain_busn_res_list, list) > > - if (r->domain_nr == domain_nr) > > - return &r->res; > > + mutex_lock(&pci_domain_busn_res_list_lock); > > + > > + list_for_each_entry(r, &pci_domain_busn_res_list, list) { > > + if (r->domain_nr == domain_nr) { > > + ret = &r->res; > > + goto out; > > + } > > + } > > > > r = kzalloc(sizeof(*r), GFP_KERNEL); > > - if (!r) > > - return NULL; > > + if (!r) { > > + ret = NULL; > > + goto out; > > + } > > > > r->domain_nr = domain_nr; > > r->res.start = 0; > > @@ -62,8 +71,10 @@ static struct resource *get_pci_domain_busn_res(int domain_nr) > > r->res.flags = IORESOURCE_BUS | IORESOURCE_PCI_FIXED; > > > > list_add_tail(&r->list, &pci_domain_busn_res_list); > > - > > - return &r->res; > > + ret = &r->res; > > +out: > > + mutex_unlock(&pci_domain_busn_res_list_lock); > > + return ret; > > } > > > > /* > > -- > > 2.25.1 > >