On Thu, May 21, 2020 at 02:11:37PM -0700, Ranjani Sridharan wrote: > On Wed, 2020-05-20 at 09:54 -0300, Jason Gunthorpe wrote: > > On Wed, May 20, 2020 at 12:02:25AM -0700, Jeff Kirsher wrote: > > > From: Ranjani Sridharan <ranjani.sridharan@xxxxxxxxxxxxxxx> > > > > > > A client in the SOF (Sound Open Firmware) context is a > > > device that needs to communicate with the DSP via IPC > > > messages. The SOF core is responsible for serializing the > > > IPC messages to the DSP from the different clients. One > > > example of an SOF client would be an IPC test client that > > > floods the DSP with test IPC messages to validate if the > > > serialization works as expected. Multi-client support will > > > also add the ability to split the existing audio cards > > > into multiple ones, so as to e.g. to deal with HDMI with a > > > dedicated client instead of adding HDMI to all cards. > > > > > > This patch introduces descriptors for SOF client driver > > > and SOF client device along with APIs for registering > > > and unregistering a SOF client driver, sending IPCs from > > > a client device and accessing the SOF core debugfs root entry. > > > > > > Along with this, add a couple of new members to struct > > > snd_sof_dev that will be used for maintaining the list of > > > clients. > > > > If you want to use sound as the rational for virtual bus then drop > > the > > networking stuff and present a complete device/driver pairing based > > on > > this sound stuff instead. > > > > > +int sof_client_dev_register(struct snd_sof_dev *sdev, > > > + const char *name) > > > +{ > > > + struct sof_client_dev *cdev; > > > + struct virtbus_device *vdev; > > > + unsigned long time, timeout; > > > + int ret; > > > + > > > + cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); > > > + if (!cdev) > > > + return -ENOMEM; > > > + > > > + cdev->sdev = sdev; > > > + init_completion(&cdev->probe_complete); > > > + vdev = &cdev->vdev; > > > + vdev->match_name = name; > > > + vdev->dev.parent = sdev->dev; > > > + vdev->release = sof_client_virtdev_release; > > > + > > > + /* > > > + * Register virtbus device for the client. > > > + * The error path in virtbus_register_device() calls > > > put_device(), > > > + * which will free cdev in the release callback. > > > + */ > > > + ret = virtbus_register_device(vdev); > > > + if (ret < 0) > > > + return ret; > > > + > > > + /* make sure the probe is complete before updating client list > > > */ > > > + timeout = msecs_to_jiffies(SOF_CLIENT_PROBE_TIMEOUT_MS); > > > + time = wait_for_completion_timeout(&cdev->probe_complete, > > > timeout); > > > > This seems bonkers - the whole point of something like virtual bus is > > to avoid madness like this. > > Thanks for your review, Jason. The idea of the times wait here is to > make the registration of the virtbus devices synchronous so that the > SOF core device has knowledge of all the clients that have been able to > probe successfully. This part is domain-specific and it works very well > in the audio driver case. This need to be hot plug safe. What if the module for this driver is not available until later in boot? What if the user unplugs the driver? What if the kernel runs probing single threaded? It is really unlikely you can both have the requirement that things be synchronous and also be doing all the other lifetime details properly.. Jason