From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkFKp-0000LG-OU for qemu-devel@nongnu.org; Wed, 05 Jun 2013 11:09:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkFKn-0007mc-Jm for qemu-devel@nongnu.org; Wed, 05 Jun 2013 11:09:11 -0400 Received: from [2001:41d0:8:2b42::1] (port=50613 helo=ns232118.ovh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkFKn-0007mP-Dv for qemu-devel@nongnu.org; Wed, 05 Jun 2013 11:09:09 -0400 Message-ID: <51AF548D.70007@greensocs.com> Date: Wed, 05 Jun 2013 17:09:01 +0200 From: Frederic Konrad MIME-Version: 1.0 References: <1370362965-3937-1-git-send-email-jlarrew@linux.vnet.ibm.com> <1370362965-3937-2-git-send-email-jlarrew@linux.vnet.ibm.com> <51AE2564.4080705@suse.de> In-Reply-To: <51AE2564.4080705@suse.de> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/3] virtio: add bus_plugged() callback to VirtioDeviceClass List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-15?Q?Andreas_F=E4rber?= Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , jasowang@redhat.com, Jesse Larrew , qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, Anthony Liguori On 04/06/2013 19:35, Andreas F=E4rber wrote: > Hi, > > Am 04.06.2013 18:22, schrieb Jesse Larrew: >> Virtio devices are initialized prior to plugging them into a bus. Howe= ver, >> other initializations (such as host_features) don't occur until after = the >> device is plugged into the bus. If a device needs to modify it's >> configuration based on host_features, then it needs to be notified whe= n the >> bus is attached and host_features is available for use. >> >> This patch extends struct VirtioDeviceClass to add a bus_plugged() met= hod. >> If implemented by a device, it will be called after the device is atta= ched >> to a bus. >> >> Signed-off-by: Jesse Larrew > I think this is backwards... > > First of all, why is host_features not available before? Hi Andreas, The major issue here is that host_features is modified after virtio=20 devices are inited. in virtio_pci_device_plugged: proxy->host_features |=3D 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY; proxy->host_features |=3D 0x1 << VIRTIO_F_BAD_FEATURE; proxy->host_features =3D virtio_bus_get_vdev_features(bus, proxy->host_features); and virtio_pci_device_plugged must be called after the virtio device is=20 inited. > A hook on the bus makes sense because it allows central handling for an= y > devices on that bus. > However for a device, first TypeInfo::instance_init is run, then > qdev_set_parent_bus() connects the bus and finally DeviceClass::realize > is run - and we want to postpone realize further in the future. > > So why can't this be in VirtioDevice's or VirtIONet's realize method? A= t > realize time we should definitely be on the bus in this case. I.e., Is that possible with hotplugging virtio device on virtio-mmio? > create vdev->config only after we know how large it needs to be rather > than creating and later resizing it, which might fail. > > Regards, > Andreas > Fred