RE: [PATCH] PCI: hv: Don't use container_of() on non-vPCI buses in config block ops

From: Dexuan Cui

Date: Fri Dec 04 2026 - 00:46:14 EST


> From: Michael Kelley <mhklinux@xxxxxxxxxxx>
> Sent: Friday, November 20, 2026 9:41 AM
> ...
Hi Michael, sorry for the late reply!

> In addition to hv_read_config_block(), hv_write_config_block(), and
> hv_register_block_invalidate(), there are two other functions in
> pci-hyperv.c that do the same mapping of a struct pci_dev to a
> struct hv_pcibus_device:
>
> hv_irq_retarget_interrupt()
> hv_compose_msi_msg()
>
> Also, hv_pcifront_read_config() and hv_pcifront_write_config()
> do the same thing, but starting with a struct pci_bus instead of
> a struct pci_dev. Maybe hv_pci_dev_to_hbus() should become
> hv_pci_bus_to_hbus(), and callers can pass pdev->bus as the
> first argument if need be.

Good suggestion! Will make a v2.

> Finally, there's hv_pci_reset_device(), which currently does the
> same sysdata container_of() trick, but based on the bridge. Even
> so, the struct pci_dev as also available, so hv_pci_reset_device()
> could use hv_pci_dev_to_hbus().

I agree, but so far hv_pci_reset_device() is only in the PCI tree's
"next" branch and is not in the "for-linus" branch. I suppose this
patch should be based on "for-linus", and should go in the mainline
first as part of v7.4; v7.5-rc1 should have hv_pci_reset_device(),
and I can post a follow-up patch for it.

> This a long way of saying that there's a consistency argument
> for using hv_pci_dev_to_hbus() [or hv_pci_bus_to_hbus()]
> throughout pci-hyperv.c instead of just on the hvpci_block_ops
> functions.

This patch is tagged for stable, so I hope the patch can be as
small as possible, but maybe I can make 2 patches: #1 only
changes the hvpci_block_ops and is tagged for stable; #2 only
changes the other functions and is not tagged for stable.

> Separately, it seems a bit fragile for this mapping to depend
> on the sysdata memory being allocated as part of the struct
> hv_pcibus_device (vs. a dynamic allocation, for example). Of
> course, that's the current code, and it works. But I'm
> trying to think through whether there's a better way to do
> the mapping. Just my random musings and not something
> that needs to be covered in this patch ....
>
> Michael

It looks like it's a standard practice to pass a private pointer to
bridge->sysdata, and later when we have a pci_bus pointer,
we can get the private pointer via pci_bus->sysdata, and use
it. This doesn't look fragile to me.

I checked
grep 'bridge->sysdata = ' drivers/pci/ -nr
and found a lot of drivers following the same pattern.

Thanks,
Dexuan