From: <dan.j.williams@intel.com>
To: Michael Kelley <mhklinux@outlook.com>,
"dan.j.williams@intel.com" <dan.j.williams@intel.com>,
"bhelgaas@google.com" <bhelgaas@google.com>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
"lukas@wunner.de" <lukas@wunner.de>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Jonathan.Cameron@huawei.com" <Jonathan.Cameron@huawei.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Lorenzo Pieralisi <lpieralisi@kernel.org>,
Rob Herring <robh@kernel.org>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
"open list:Hyper-V/Azure CORE AND DRIVERS"
<linux-hyperv@vger.kernel.org>
Subject: RE: [PATCH 2/3] PCI: Enable host bridge emulation for PCI_DOMAINS_GENERIC platforms
Date: Fri, 18 Jul 2025 12:17:04 -0700 [thread overview]
Message-ID: <687a9db02207e_137e6b10063@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <SN6PR02MB4157A7F41F299608E605E0C5D450A@SN6PR02MB4157.namprd02.prod.outlook.com>
Michael Kelley wrote:
[..]
> > Here is the replacement fixup that I will fold in if it looks good to
> > you:
> >
> > -- 8< --
> > diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> > index cfe9806bdbe4..f1079a438bff 100644
> > --- a/drivers/pci/controller/pci-hyperv.c
> > +++ b/drivers/pci/controller/pci-hyperv.c
> > @@ -3642,9 +3642,9 @@ static int hv_pci_probe(struct hv_device *hdev,
> > {
> > struct pci_host_bridge *bridge;
> > struct hv_pcibus_device *hbus;
> > - u16 dom_req, dom;
> > + int ret, dom;
> > + u16 dom_req;
> > char *name;
> > - int ret;
> >
> > bridge = devm_pci_alloc_host_bridge(&hdev->device, 0);
> > if (!bridge)
> > @@ -3673,8 +3673,7 @@ static int hv_pci_probe(struct hv_device *hdev,
> > * collisions) in the same VM.
> > */
> > dom_req = hdev->dev_instance.b[5] << 8 | hdev->dev_instance.b[4];
> > - dom = pci_bus_find_emul_domain_nr(dom_req);
> > -
>
> As an additional paragraph the larger comment block above, let's include a
> massaged version of the comment associated with HVPCI_DOM_INVALID.
> Perhaps:
>
> *
> * Because Gen1 VMs use domain 0, don't allow picking domain 0 here, even
> * if bytes 4 and 5 of the instance GUID are both zero.
> */
That looks good to me.
>
> > + dom = pci_bus_find_emul_domain_nr(dom_req, 1, U16_MAX);
> > if (dom < 0) {
> > dev_err(&hdev->device,
> > "Unable to use dom# 0x%x or other numbers", dom_req);
> > diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c
> > index f60244ff9ef8..30935fe85af9 100644
> > --- a/drivers/pci/controller/vmd.c
> > +++ b/drivers/pci/controller/vmd.c
> > @@ -881,7 +881,14 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)
> > pci_add_resource_offset(&resources, &vmd->resources[2], offset[1]);
> >
> > sd->vmd_dev = vmd->dev;
> > - sd->domain = pci_bus_find_emul_domain_nr(PCI_DOMAIN_NR_NOT_SET);
> > +
> > + /*
> > + * Emulated domains start at 0x10000 to not clash with ACPI _SEG
> > + * domains. Per ACPI r6.0, sec 6.5.6, _SEG returns an integer, of
> > + * which the lower 16 bits are the PCI Segment Group (domain) number.
> > + * Other bits are currently reserved.
> > + */
> > + sd->domain = pci_bus_find_emul_domain_nr(0, 0x10000, INT_MAX);
> > if (sd->domain < 0)
> > return sd->domain;
> >
> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > index 833ebf2d5213..de42e53f07d0 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -6695,34 +6695,15 @@ static void pci_no_domains(void)
> > #ifdef CONFIG_PCI_DOMAINS
> > static DEFINE_IDA(pci_domain_nr_dynamic_ida);
> >
> > -/*
> > - * Find a free domain_nr either allocated by pci_domain_nr_dynamic_ida or
> > - * fallback to the first free domain number above the last ACPI segment number.
> > - * Caller may have a specific domain number in mind, in which case try to
> > - * reserve it.
> > - *
> > - * Note that this allocation is freed by pci_release_host_bridge_dev().
> > +/**
> > + * pci_bus_find_emul_domain_nr() - allocate a PCI domain number per constraints
> > + * @hint: desired domain, 0 if any id in the range of @min to @max is acceptable
> > + * @min: minimum allowable domain
> > + * @max: maximum allowable domain, no ids higher than INT_MAX will be returned
> > */
> > -int pci_bus_find_emul_domain_nr(int hint)
> > +u32 pci_bus_find_emul_domain_nr(u32 hint, u32 min, u32 max)
>
> Shouldn't the return type here still be "int"? ida_alloc_range() can return a negative
> errno if it fails. And the call sites in hv_pci_probe() and vmd_enable_domain()
> store the return value into an "int".
Yup, good catch.
> Other than that, and my suggested added comment, this looks good.
Thanks!
prev parent reply other threads:[~2025-07-18 19:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250716160835.680486-1-dan.j.williams@intel.com>
[not found] ` <20250716160835.680486-3-dan.j.williams@intel.com>
2025-07-17 17:25 ` [PATCH 2/3] PCI: Enable host bridge emulation for PCI_DOMAINS_GENERIC platforms Michael Kelley
2025-07-17 19:59 ` dan.j.williams
2025-07-17 23:06 ` Michael Kelley
2025-07-18 0:22 ` dan.j.williams
2025-07-18 3:03 ` Michael Kelley
2025-07-18 19:17 ` dan.j.williams [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=687a9db02207e_137e6b10063@dwillia2-xfh.jf.intel.com.notmuch \
--to=dan.j.williams@intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=bhelgaas@google.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=lukas@wunner.de \
--cc=mhklinux@outlook.com \
--cc=robh@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox