intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: "Liu, Yi L" <yi.l.liu@intel.com>
Cc: "mjrosato@linux.ibm.com" <mjrosato@linux.ibm.com>,
	"jasowang@redhat.com" <jasowang@redhat.com>,
	"Hao, Xudong" <xudong.hao@intel.com>,
	"Duan, Zhenzhong" <zhenzhong.duan@intel.com>,
	"peterx@redhat.com" <peterx@redhat.com>,
	"Xu, Terrence" <terrence.xu@intel.com>,
	"chao.p.peng@linux.intel.com" <chao.p.peng@linux.intel.com>,
	"linux-s390@vger.kernel.org" <linux-s390@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"lulu@redhat.com" <lulu@redhat.com>,
	"Jiang, Yanting" <yanting.jiang@intel.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"nicolinc@nvidia.com" <nicolinc@nvidia.com>,
	Jason Gunthorpe <jgg@nvidia.com>,
	"Zhao, Yan Y" <yan.y.zhao@intel.com>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"eric.auger@redhat.com" <eric.auger@redhat.com>,
	"intel-gvt-dev@lists.freedesktop.org"
	<intel-gvt-dev@lists.freedesktop.org>,
	"yi.y.sun@linux.intel.com" <yi.y.sun@linux.intel.com>,
	"cohuck@redhat.com" <cohuck@redhat.com>,
	"shameerali.kolothum.thodi@huawei.com"
	<shameerali.kolothum.thodi@huawei.com>,
	"suravee.suthikulpanit@amd.com" <suravee.suthikulpanit@amd.com>,
	"robin.murphy@arm.com" <robin.murphy@arm.com>
Subject: Re: [Intel-gfx] [PATCH v3 12/12] vfio/pci: Report dev_id in VFIO_DEVICE_GET_PCI_HOT_RESET_INFO
Date: Thu, 6 Apr 2023 11:53:47 -0600	[thread overview]
Message-ID: <20230406115347.7af28448.alex.williamson@redhat.com> (raw)
In-Reply-To: <DS0PR11MB75292DA91ED15AE94A85EB3DC3919@DS0PR11MB7529.namprd11.prod.outlook.com>

On Thu, 6 Apr 2023 10:02:10 +0000
"Liu, Yi L" <yi.l.liu@intel.com> wrote:

> > From: Jason Gunthorpe <jgg@nvidia.com>
> > Sent: Thursday, April 6, 2023 7:23 AM
> > 
> > On Wed, Apr 05, 2023 at 01:49:45PM -0600, Alex Williamson wrote:
> >   
> > > > > QEMU can make a policy decision today because the kernel provides a
> > > > > sufficiently reliable interface, ie. based on the set of owned groups, a
> > > > > hot-reset is all but guaranteed to work.  
> > > >
> > > > And we don't change that with cdev. If qemu wants to make the policy
> > > > decision it keeps using the exact same _INFO interface to make that
> > > > decision same it has always made.
> > > >
> > > > We weaken the actual reset action to only consider the security side.
> > > >
> > > > Applications that want this exclusive reset group policy simply must
> > > > check it on their own. It is a reasonable API design.  
> > >
> > > I disagree, as I've argued before, the info ioctl becomes so weak and
> > > effectively arbitrary from a user perspective at being able to predict
> > > whether the hot-reset ioctl works that it becomes useless, diminishing
> > > the entire hot-reset info/execute API.  
> > 
> > reset should be strictly more permissive than INFO. If INFO predicts
> > reset is permitted then reset should succeed.
> > 
> > We don't change INFO so it cannot "becomes so weak"  ??
> > 
> > We don't care about the cases where INFO says it will not succeed but
> > reset does (temporarily) succeed.
> > 
> > I don't get what argument you are trying to make or what you think is
> > diminished..
> > 
> > Again, userspace calls INFO, if info says yes then reset *always
> > works*, exactly just like today.
> >
> > Userspace will call reset with a 0 length FD list and it uses a
> > security only check that is strictly more permissive than what
> > get_info will return. So the new check is simple in the kernel and
> > always works in the cases we need it to work.
> > 
> > What is getting things into trouble is insisting that RESET have
> > additional restrictions beyond the minimum checks required for
> > security.
> >   
> > > > I don't view it as a loophole, it is flexability to use the API in a
> > > > way that is different from what qemu wants - eg an app like dpdk may
> > > > be willing to tolerate a reset group that becomes unavailable after
> > > > startup. Who knows, why should we force this in the kernel?  
> > >
> > > Because look at all the problems it's causing to try to introduce these
> > > loopholes without also introducing subtle bugs.  
> > 
> > These problems are coming from tring to do this integrated version,
> > not from my approach!
> > 
> > AFAICT there was nothing wrong with my original plan of using the
> > empty fd list for reset. What Yi has here is some mashup of what you
> > and I both suggested.  
> 
> Hi Alex, Jason,
> 
> could be this reason. So let me try to gather the changes of this series
> does and the impact as far as I know.
> 
> 1) only check the ownership of opened devices in the dev_set
>      in HOT_RESET ioctl.
>      - Impact: it changes the relationship between _INFO  and HOT_RESET.
>        As " Each group must have IOMMU protection established for the
>        ioctl to succeed." in [1], existing design actually means userspace
>        should own all the affected groups before heading to do HOT_RESET.
>        With the change here, the user does not need to ensure all affected
>        groups are opened and it can do hot-reset successfully as long as the
>        devices in the affected group are just un-opened and can be reset.
>     
>        [1] https://patchwork.kernel.org/project/linux-pci/patch/20130814200845.21923.64284.stgit@bling.home/

Where whether a device is opened is subject to change outside of the
user's control.  This essentially allows the user to perform hot-resets
of devices outside of their ownership so long as the device is not
used elsewhere, versus the current requirement that the user own all the
affected groups, which implies device ownership.  It's not been
justified why this feature needs to exist, imo.
 
> 2) Allow passing zero-length fd array to do hot reset
>     - Impact: this uses the iommufd as ownership check in the kernel side.
>       It is only supposed to be used by the users that open cdev instead of
>       users that open group. The drawback is that it cannot cover the noiommu
>       devices as noiommu does not use iommufd at all. But it works well for
>       most cases.

The "only supposed to be used" is problematic here, we're extending all
the interfaces to transparently accept group and device fds, but here
we need to make a distinction because the ioctl needs to perform one
way for groups and another way for devices, which it currently doesn't
do.  As above, I've not seen sufficient justification for this other
than references to reducing complexity, but the only userspace expected
to make use of this interface already has equivalent complexity.
 
> 3) Allow hot reset be successful when the dev_set is singleton
>      - Impact: this makes sense but it seems to mess up the boundary between
>      the group path and cdev path w.r.t. the usage of zero-length fd approach.
>      The group path can succeed to do hot reset even if it is passing an empty
>      fd array if the dev_set happens to be singleton.

Again, what is the justification for requiring this, it seems to be
only a hack towards no-iommu support with cdev, which we can achieve by
other means.  Why have we not needed this in the group model?  It
introduces subtle loopholes, so while maybe we could, I don't see why we
should, therefore I cannot agree with "this makes sense".

> 4) Allow passing device fd to do hot reset
>     - Impact: this is a new way for hot reset. should have no impact.
> 
> 5) Extend the _INFO to report devid
>     - Impact: this changes the way user to decode the info reported back.
>     devid and groupid are returned per the way the queried device is opened.
>     Since it was suggested to support the scenario in which some devices
>     are opened via cdev while some devices are opened via group. This makes
>     us to return invalid_devid for the device that is opened via group if
>     it is affected by the hot reset of a device that is opened via cdev.
>     
>     This was proposed to support the future device fd passing usage which is
>     only available in cdev path.

I think this is fundamentally flawed because of the scope of the
dev-id.  We can only provide dev-ids for devices which belong to the
same iommufd of the calling device, thus there are multiple instances
where no dev-id can be provided.  The group-id and bdf are static
properties of the devices, regardless of their ownership.  The bdf
provides the specific device level association while the group-id
indicates implied, static ownership.

> To me the major confusion is from 1) and 3). 1) changes the meaning of
> _INFO and HOT_RESET, while 3) messes up the boundary.

As above, I think 2) is also an issue.

> Here is my thought:
> 
> For 1), it was proposed due to below reason[2]. We'd like to make a scenario
> that works in the group path be workable in cdev path as well. But IMHO, we
> may just accept that cdev path cannot work for such scenario to avoid sublte
> change to uapi. Otherwise, we need to have another HOT_RESET ioctl or a
> hint in HOT_RESET ioctl to tell the kernel  whether relaxed ownership check
> is expected. Maybe this is awkward. But if we want to keep it, we'd do it
> with the awareness by user.
> 
> [2] https://lore.kernel.org/kvm/Y%2FdobS6gdSkxnPH7@nvidia.com/

The group association is that relaxed ownership test.  Yes, there are
corner cases where we have a dual function card with separate IOMMU
groups, where a user owning function 0 could do a bus reset because
function 1 is temporarily unused, but so what, what good is that, have
we ever had an issue raised because of this?  The user can't rely on
the unopened state of the other function.  It's an entirely
opportunistic optimization.

The much more typical scenario is that a multi-function device does not
provide isolation, all the functions are in the same group and because
of the association of the group the user has implied ownership of the
other devices for the purpose of a reset.

> For 3), it was proposed when discussing the hot reset for noiommu[3]. But
> it does not make hot reset always workable for noiommu in cdev, just in
> case dev_set is singleton. So it is more of a general optimization that can
> make the kernel skip the ownership check. But to make use of it, we may
> need to test it before sanitizing the group fds from user or the iommufd
> check. Maybe the dev_set singleton test in this series is not well placed.
> If so, I can further modify it.
> 
> [3] https://lore.kernel.org/kvm/ZACX+Np%2FIY7ygqL5@nvidia.com/

As above, this seems to be some optimization related to no-iommu for
cdev because we don't have an iommufd association for the device in
no-iommu mode.  Note however that the current group interface doesn't
care about the IOMMU context of the devices.  We only need proof that
the user owns the affected groups.  So why are we bringing iommufd
context anywhere into this interface, here or the null-array interface?

It seems like the minor difference with cdev is that a) we're passing
device fds rather than group fds, and b) those device fds need to be
validated as having device access to complete the proof of ownership
relative to the group.  Otherwise we add capabilities to
DEVICE_GET_INFO to support the device fd passing model where the user
doesn't know the device group or bdf and allow the reset ioctl itself
to accept device fds (extracting the group relationship for those which
the user has configured for access).  Thanks,

Alex


  reply	other threads:[~2023-04-06 17:53 UTC|newest]

Thread overview: 145+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-01 14:44 [Intel-gfx] [PATCH v3 00/12] Introduce new methods for verifying ownership in vfio PCI hot reset Yi Liu
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 01/12] vfio/pci: Update comment around group_fd get in vfio_pci_ioctl_pci_hot_reset() Yi Liu
2023-04-04 13:59   ` Eric Auger
2023-04-04 14:37     ` Liu, Yi L
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 02/12] vfio/pci: Only check ownership of opened devices in hot reset Yi Liu
2023-04-04 13:59   ` Eric Auger
2023-04-04 14:37     ` Liu, Yi L
2023-04-04 15:18       ` Eric Auger
2023-04-04 15:29         ` Liu, Yi L
2023-04-04 15:59           ` Eric Auger
2023-04-05 11:41             ` Jason Gunthorpe
2023-04-05 15:14               ` Eric Auger
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 03/12] vfio/pci: Move the existing hot reset logic to be a helper Yi Liu
2023-04-04 13:59   ` Eric Auger
2023-04-04 14:24     ` Liu, Yi L
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 04/12] vfio-iommufd: Add helper to retrieve iommufd_ctx and devid for vfio_device Yi Liu
2023-04-04 15:28   ` Eric Auger
2023-04-04 21:48     ` Alex Williamson
2023-04-21  7:11       ` Liu, Yi L
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 05/12] vfio/pci: Allow passing zero-length fd array in VFIO_DEVICE_PCI_HOT_RESET Yi Liu
2023-04-04 16:54   ` Eric Auger
2023-04-04 20:18   ` Alex Williamson
2023-04-05  7:55     ` Liu, Yi L
2023-04-05  8:01       ` Liu, Yi L
2023-04-05 15:36         ` Alex Williamson
2023-04-05 16:46           ` Jason Gunthorpe
2023-04-05  8:02     ` Eric Auger
2023-04-05  8:09       ` Liu, Yi L
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 06/12] vfio: Refine vfio file kAPIs for vfio PCI hot reset Yi Liu
2023-04-05  8:27   ` Eric Auger
2023-04-05  9:23     ` Liu, Yi L
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 07/12] vfio: Accpet device file from vfio PCI hot reset path Yi Liu
2023-04-04 20:31   ` Alex Williamson
2023-04-05  8:07   ` Eric Auger
2023-04-05  8:10     ` Liu, Yi L
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 08/12] vfio/pci: Renaming for accepting device fd in " Yi Liu
2023-04-04 21:23   ` Alex Williamson
2023-04-05  9:32   ` Eric Auger
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 09/12] vfio/pci: Accept device fd in VFIO_DEVICE_PCI_HOT_RESET ioctl Yi Liu
2023-04-05  9:36   ` Eric Auger
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 10/12] vfio: Mark cdev usage in vfio_device Yi Liu
2023-04-05 11:48   ` Eric Auger
2023-04-21  7:06     ` Liu, Yi L
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 11/12] iommufd: Define IOMMUFD_INVALID_ID in uapi Yi Liu
2023-04-04 21:00   ` Alex Williamson
2023-04-05  9:31     ` Liu, Yi L
2023-04-05 15:13       ` Alex Williamson
2023-04-05 15:17         ` Liu, Yi L
2023-04-05 11:46   ` Eric Auger
2023-04-01 14:44 ` [Intel-gfx] [PATCH v3 12/12] vfio/pci: Report dev_id in VFIO_DEVICE_GET_PCI_HOT_RESET_INFO Yi Liu
2023-04-03  9:25   ` Liu, Yi L
2023-04-03 15:01     ` Alex Williamson
2023-04-03 15:22       ` Liu, Yi L
2023-04-03 15:32         ` Alex Williamson
2023-04-03 16:12           ` Jason Gunthorpe
2023-04-07 10:09       ` Liu, Yi L
2023-04-07 12:03         ` Alex Williamson
2023-04-07 13:24           ` Liu, Yi L
2023-04-07 13:51             ` Alex Williamson
2023-04-07 14:04               ` Liu, Yi L
2023-04-07 15:14                 ` Alex Williamson
2023-04-07 15:47                   ` Liu, Yi L
2023-04-07 21:07                     ` Alex Williamson
2023-04-08  5:07                       ` Liu, Yi L
2023-04-08 14:20                         ` Alex Williamson
2023-04-09 11:58                           ` Yi Liu
2023-04-09 13:29                             ` Alex Williamson
2023-04-10  8:48                               ` Liu, Yi L
2023-04-10 14:41                                 ` Alex Williamson
2023-04-10 15:18                                   ` Liu, Yi L
2023-04-10 15:23                                     ` Alex Williamson
2023-04-11 13:34                               ` Jason Gunthorpe
2023-04-11 13:33                       ` Jason Gunthorpe
2023-04-11  6:16           ` Liu, Yi L
2023-04-04 22:20   ` Alex Williamson
2023-04-05 12:19   ` Eric Auger
2023-04-05 14:04     ` Liu, Yi L
2023-04-05 16:25       ` Alex Williamson
2023-04-05 16:37         ` Jason Gunthorpe
2023-04-05 16:52           ` Alex Williamson
2023-04-05 17:23             ` Jason Gunthorpe
2023-04-05 18:56               ` Alex Williamson
2023-04-05 19:18                 ` Alex Williamson
2023-04-05 19:21                 ` Jason Gunthorpe
2023-04-05 19:49                   ` Alex Williamson
2023-04-05 23:22                     ` Jason Gunthorpe
2023-04-06 10:02                       ` Liu, Yi L
2023-04-06 17:53                         ` Alex Williamson [this message]
2023-04-07 10:09                           ` Liu, Yi L
2023-04-11 13:24                           ` Jason Gunthorpe
2023-04-11 15:54                             ` Alex Williamson
2023-04-11 17:11                               ` Alex Williamson
2023-04-11 18:40                                 ` Jason Gunthorpe
2023-04-11 21:58                                   ` Alex Williamson
2023-04-12  0:01                                     ` Jason Gunthorpe
2023-04-12  7:27                                       ` Tian, Kevin
2023-04-12 15:05                                         ` Jason Gunthorpe
2023-04-12 17:01                                           ` Alex Williamson
2023-04-13  2:57                                           ` Tian, Kevin
2023-04-12 10:09                                       ` Liu, Yi L
2023-04-12 16:54                                         ` Alex Williamson
2023-04-12 16:50                                       ` Alex Williamson
2023-04-12 20:06                                         ` Jason Gunthorpe
2023-04-13  8:25                                           ` Tian, Kevin
2023-04-13 11:50                                             ` Jason Gunthorpe
2023-04-13 14:35                                               ` Liu, Yi L
2023-04-13 14:41                                                 ` Jason Gunthorpe
2023-04-13 18:07                                               ` Alex Williamson
2023-04-14  9:11                                                 ` Tian, Kevin
2023-04-14 11:38                                                   ` Liu, Yi L
2023-04-14 17:10                                                     ` Alex Williamson
2023-04-17  4:20                                                       ` Liu, Yi L
2023-04-17 19:01                                                         ` Alex Williamson
2023-04-17 19:31                                                           ` Jason Gunthorpe
2023-04-17 20:06                                                             ` Alex Williamson
2023-04-18  3:24                                                               ` Tian, Kevin
2023-04-18  4:10                                                                 ` Alex Williamson
2023-04-18  5:02                                                                   ` Tian, Kevin
2023-04-18 12:59                                                                     ` Jason Gunthorpe
2023-04-18 16:44                                                                     ` Alex Williamson
2023-04-18 10:34                                                                   ` Liu, Yi L
2023-04-18 16:49                                                                     ` Alex Williamson
2023-04-18 12:57                                                               ` Jason Gunthorpe
2023-04-18 18:39                                                                 ` Alex Williamson
2023-04-20 12:10                                                                   ` Liu, Yi L
2023-04-20 14:08                                                                     ` Alex Williamson
2023-04-21 22:35                                                                       ` Jason Gunthorpe
2023-04-23 14:46                                                                         ` Liu, Yi L
2023-04-26  7:22                                                                       ` Liu, Yi L
2023-04-26 13:20                                                                         ` Alex Williamson
2023-04-26 15:08                                                                           ` Liu, Yi L
2023-04-14 16:34                                                   ` Alex Williamson
2023-04-17 13:39                                                   ` Jason Gunthorpe
2023-04-18  1:28                                                     ` Tian, Kevin
2023-04-18 10:23                                                     ` Liu, Yi L
2023-04-18 13:02                                                       ` Jason Gunthorpe
2023-04-23 10:28                                                         ` Liu, Yi L
2023-04-24 17:38                                                           ` Jason Gunthorpe
2023-04-17 14:05                                                 ` Jason Gunthorpe
2023-04-12  7:14                                     ` Tian, Kevin
2023-04-06  6:34                     ` Liu, Yi L
2023-04-06 17:07                       ` Alex Williamson
2023-04-05 17:58         ` Eric Auger
2023-04-06  5:31           ` Liu, Yi L
2023-04-01 14:47 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for Introduce new methods for verifying ownership in vfio PCI hot reset (rev4) Patchwork

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=20230406115347.7af28448.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=cohuck@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-gvt-dev@lists.freedesktop.org \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=lulu@redhat.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=nicolinc@nvidia.com \
    --cc=peterx@redhat.com \
    --cc=robin.murphy@arm.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=terrence.xu@intel.com \
    --cc=xudong.hao@intel.com \
    --cc=yan.y.zhao@intel.com \
    --cc=yanting.jiang@intel.com \
    --cc=yi.l.liu@intel.com \
    --cc=yi.y.sun@linux.intel.com \
    --cc=zhenzhong.duan@intel.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;
as well as URLs for NNTP newsgroup(s).