On Thu, 29 Apr 2021 15:13:47 -0300 Jason Gunthorpe <jgg@xxxxxxxxxx> wrote: > On Thu, Apr 29, 2021 at 01:58:55PM +0200, Cornelia Huck wrote: > > > > This seems like one of these cases where using the mdev GUID API > > > was not a great fit. The ccs_driver should have just directly > > > created a vfio_device and not gone into the mdev guid lifecycle > > > world. > > > > I don't remember much of the discussion back then, but I don't think > > the explicit generation of devices was the part we needed, but rather > > some other kind of mediation -- probably iommu related, as subchannels > > don't have that concept on their own. Anyway, too late to change now. > > The mdev part does three significant things: > - Provide a lifecycle model based on sysfs and the GUIDs > - Hackily inject itself into the VFIO IOMMU code as a special case > - Force the creation of a unique iommu group as the group FD is > mandatory to get the device FD. > > This is why PASID is such a mess for mdev because it requires even > more special hacky stuff to link up the dummy IOMMU but still operate > within the iommu group of the parent device. > > I can see an alternative arrangement using the /dev/ioasid idea that > is a lot less hacky and does not force the mdev guid lifecycle on > everyone that wants to create vfio_device. I have not followed that discussion -- do you have a summary or a pointer? > > > > I almost did this, but couldn't figure out how the lifetime of the > > > ccs_driver callbacks are working relative to the lifetime of the mdev > > > device since they also reach into these structs. Maybe they can't be > > > called for some css related reason? > > > > Moving allocations to the mdev driver probe makes sense, I guess. We > > should also move enabling the subchannel to that point in time (I don't > > remember why we enable it in the css probe function, and can't think of > > a good reason for that; obviously needs to be paired with quiescing and > > disabling the subchannel in the mdev driver remove function); that > > leaves the uevent dance (which can hopefully also be removed, if some > > discussed changes are implemented in the common I/O layer) and fencing > > QDIO. > > > > Regarding the other callbacks, > > - vfio_ccw_sch_irq should not be invoked if the subchannel is not > > enabled; maybe log a message before returning for !private. > > - vfio_ccw_sch_remove should be able to return 0 for !private (nothing > > to quiesce, if the subchannel is not enabled). > > - vfio_ccw_sch_shutdown has nothing to do for !private (same reason.) > > - In vfio_ccw_sch_event, we should either skip the fsm_event and the > > state change for !private, or return 0 in that case. > > - vfio_ccw_chp_event already checks for !private. Not sure whether we > > should try to update some control blocks and return -ENODEV if the > > subchannel is not operational, but it's probably not needed. > > All the checks for !private need some kind of locking. The driver core > model is that the 'struct device_driver' callbacks are all called > under the device_lock (this prevents the driver unbinding during the > callback). I didn't check if ccs does this or not.. probe/remove/shutdown are basically a forward of the callbacks at the bus level. The css bus should make sure that we serialize irq/sch_event/chp_event with probe/remove. > > So if we NULL drvdata under the device_lock everything can be > quite simple here. > > Jason >