Re: [PATCH v2] pci: fix device presence detection for VFs

Wei Gong
2022-11-09T07:01:13Z

On Tue, Nov 08, 2022 at 11:12:34PM -0600, Bjorn Helgaas wrote:
> On Wed, Nov 09, 2022 at 04:36:17AM +0000, Wei Gong wrote:
> > O Tue, Nov 08, 2022 at 01:02:35PM -0500, Michael S. Tsirkin wrote:
> > > On Tue, Nov 08, 2022 at 11:58:53AM -0600, Bjorn Helgaas wrote:
> > > > On Tue, Nov 08, 2022 at 10:19:07AM -0500, Michael S. Tsirkin wrote:
> > > > > On Tue, Nov 08, 2022 at 09:02:28AM -0600, Bjorn Helgaas wrote:
> > > > > > On Tue, Nov 08, 2022 at 08:53:00AM -0600, Bjorn Helgaas wrote:
> > > > > > > On Wed, Oct 26, 2022 at 02:11:21AM -0400, Michael S. Tsirkin wrote:
> > > > > > > > virtio uses the same driver for VFs and PFs.
> > > > > > > > Accordingly, pci_device_is_present is used to detect
> > > > > > > > device presence. This function isn't currently working
> > > > > > > > properly for VFs since it attempts reading device and
> > > > > > > > vendor ID.
> > > > > > >
> > > > > > > > As VFs are present if and only if PF is present,
> > > > > > > > just return the value for that device.
> > > > > > >
> > > > > > > VFs are only present when the PF is present *and* the PF
> > > > > > > has VF Enable set. Do you care about the possibility that
> > > > > > > VF Enable has been cleared?
> > > >
> > > > I think you missed this question.
> > >
> > > I was hoping Wei will answer that, I don't have the hardware.
> >
> > In my case I don't care that VF Enable has been cleared.
>
> OK, let me rephrase that :)
>
> I think pci_device_is_present(VF) should return "false" if the PF is
> present but VFs are disabled.

I agree.

>
> If you think it should return "true" when the PF is present and VFs
> are disabled, we should explain why.

I don't think it should return "true" when the PF is present and VFS
are disabled.

I think pci_device_is_present(VF) should return "true" if the PF is
present and VFs are enabled.
In the current implementation, it cannot correctly judge whether the
VF is present.
When the PF is present and VFs are enabled, I think it should return
"true", but in fact it returns "false"

Through your comments, I realize that this patch is inaccurate in
judging whether VF present in the case of "the PF is present and
VFs are disabled"

Thinks,
Wei

>
> We would also need to fix the commit log, because "VFs are present if
> and only if PF is present" is not actually true. "VFs are present
> only if PF is present" is true, but "VFs are present if PF is present"
> is not.
>
> Bjorn