public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Cornelia Huck <cohuck@redhat.com>,
	Kevin Tian <kevin.tian@intel.com>,
	kvm@vger.kernel.org, Longfang Liu <liulongfang@huawei.com>,
	Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>,
	Yishai Hadas <yishaih@nvidia.com>,
	Abhishek Sahu <abhsahu@nvidia.com>,
	Kirti Wankhede <kwankhede@nvidia.com>
Subject: Re: [PATCH v3 1/2] vfio/pci: Have all VFIO PCI drivers store the vfio_pci_core_device in drvdata
Date: Thu, 5 May 2022 15:34:21 -0300	[thread overview]
Message-ID: <20220505183421.GU49344@nvidia.com> (raw)
In-Reply-To: <20220505121047.5b798dd6.alex.williamson@redhat.com>

On Thu, May 05, 2022 at 12:10:47PM -0600, Alex Williamson wrote:

> > +	/* Drivers must set the vfio_pci_core_device to their drvdata */
> > +	if (WARN_ON(vdev != dev_get_drvdata(&vdev->pdev->dev)))
> > +		return -EINVAL;
> > +
> 
> The ordering seems off, if we only validate in the core enable function
> then we can only guarantee drvdata is correct once the user has opened
> the device.  However, we start invoking power management controls,
> which Abhishek proposes moving to runtime pm, from the core register
> device function.  Therefore we've not validated drvdata for anything we
> might do in the background, not under the direction of the user.

It is just a guard to make it obvious to someone testing the driver
that something has gone wrong, ie in backporting or something. 

It is not intended to be protective against drivers that are actually
wrong and installed in the system.

I added this because I felt a driver could silently be wrong and never
hit a PM or AER callback during some basic testing to catch a crash or
whatever.

> I'd also rather see the variant driver fail to register with the core
> than to see a failure opening the device an arbitrary time later.

It still permits a driver to be wrong, eg all the drivers are like
this today:

	ret = vfio_pci_core_register_device(&hisi_acc_vdev->core_device);
	if (ret)
		goto out_free;
	dev_set_drvdata(&pdev->dev, &hisi_acc_vdev->core_device);

So a WARN_ON inside register_device will not catch the mistake, as
this is the common pattern it isn't as helpful.

Jason

  reply	other threads:[~2022-05-05 18:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04 19:01 [PATCH v3 0/2] Remove vfio_device_get_from_dev() Jason Gunthorpe
2022-05-04 19:01 ` [PATCH v3 1/2] vfio/pci: Have all VFIO PCI drivers store the vfio_pci_core_device in drvdata Jason Gunthorpe
2022-05-05 18:10   ` Alex Williamson
2022-05-05 18:34     ` Jason Gunthorpe [this message]
2022-05-05 18:54       ` Alex Williamson
2022-05-05 19:28         ` Jason Gunthorpe
2022-05-04 19:01 ` [PATCH v3 2/2] vfio/pci: Remove vfio_device_get_from_dev() Jason Gunthorpe
2022-05-04 20:20   ` Kirti Wankhede
2022-05-04 21:36     ` Jason Gunthorpe
2022-05-06 21:08     ` Alex Williamson
2022-05-04 19:30 ` [PATCH v3 0/2] " Jason Gunthorpe

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=20220505183421.GU49344@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=abhsahu@nvidia.com \
    --cc=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=liulongfang@huawei.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=yishaih@nvidia.com \
    /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