From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPqla-000106-0z for qemu-devel@nongnu.org; Fri, 05 Sep 2014 06:29:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPqlU-0001zU-Aj for qemu-devel@nongnu.org; Fri, 05 Sep 2014 06:29:17 -0400 Received: from mail-we0-x232.google.com ([2a00:1450:400c:c03::232]:61095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPqlU-0001zJ-2s for qemu-devel@nongnu.org; Fri, 05 Sep 2014 06:29:12 -0400 Received: by mail-we0-f178.google.com with SMTP id q58so92953wes.9 for ; Fri, 05 Sep 2014 03:29:11 -0700 (PDT) Date: Fri, 5 Sep 2014 11:29:08 +0100 From: Stefan Hajnoczi Message-ID: <20140905102908.GA27649@stefanha-thinkpad.redhat.com> References: <1409835061-19989-1-git-send-email-david.marchand@6wind.com> <1409835061-19989-4-git-send-email-david.marchand@6wind.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OgqxwSJOaUobr8KG" Content-Disposition: inline In-Reply-To: <1409835061-19989-4-git-send-email-david.marchand@6wind.com> Subject: Re: [Qemu-devel] [PATCH v5 3/3] ivshmem: add check on protocol version in QEMU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Marchand Cc: kvm@vger.kernel.org, claudio.fontana@huawei.com, qemu-devel@nongnu.org, armbru@redhat.com, arei.gonglei@huawei.com, mkletzan@redhat.com, pbonzini@redhat.com, jani.kokkonen@huawei.com, cam@cs.ualberta.ca --OgqxwSJOaUobr8KG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 04, 2014 at 02:51:01PM +0200, David Marchand wrote: > diff --git a/contrib/ivshmem-client/ivshmem-client.c b/contrib/ivshmem-cl= ient/ivshmem-client.c > index ad210c8..0c4e016 100644 > --- a/contrib/ivshmem-client/ivshmem-client.c > +++ b/contrib/ivshmem-client/ivshmem-client.c > @@ -184,10 +184,18 @@ ivshmem_client_connect(IvshmemClient *client) > goto err_close; > } > =20 > - /* first, we expect our index + a fd =3D=3D -1 */ > + /* first, we expect a protocol version */ > + if (read_one_msg(client, &tmp, &fd) < 0 || > + (tmp !=3D IVSHMEM_PROTOCOL_VERSION) || fd !=3D -1) { > + debug_log(client, "cannot read from server\n"); > + goto err_close; > + } > + debug_log(client, "our_id=3D%ld\n", client->local.id); This debug_log() is probably not intentional. local.id will always be -1 here so the output is not useful. > +static void ivshmem_check_version(void *opaque, const uint8_t * buf, int= flags) > +{ > + IVShmemState *s =3D opaque; > + PCIDevice *dev =3D PCI_DEVICE(s); > + int tmp; > + long version; > + > + memcpy(&version, buf, sizeof(long)); > + tmp =3D qemu_chr_fe_get_msgfd(s->server_chr); > + if (tmp !=3D -1 || version !=3D IVSHMEM_PROTOCOL_VERSION) { > + fprintf(stderr, "incompatible version, you are connecting to a i= vhsmem-" > + "server using a different protocol please check your set= up\n"); > + qemu_chr_delete(s->server_chr); > + s->server_chr =3D NULL; > + return; > + } > + > + IVSHMEM_DPRINTF("version check ok, finish init and switch to real ch= ardev " > + "handler\n"); > + > + pci_register_bar(dev, 2, s->ivshmem_attr, &s->bar); Not sure if it is okay to delay PCI initialization to a fd hander callback. If the version message is too slow the guest could see the PCI adapter without the BAR! Did you move this code in order to prevent the guest from accessing the device before it has connected to the server? Perhaps the device needs a state field that tracks whether or not it is ready for operation. Any access before RUNNING state is reached will be ignored (?). --OgqxwSJOaUobr8KG Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUCZB0AAoJEJykq7OBq3PIpgcH/3NnEf+ryW+VWBZF4mIKUN+6 3esZcdQErnnaIF5VCRs9F1yaISveB+bfXqHdxA1hEYn1ZOIYQdEu9ynOWtTQmFut yoowHnek15DM5mpOV9PCX18kmduU1+bWmcX0JmHpUcuzS7msg2gyz8AQMYDB2vDx ulG5Ae6Aki0tp0jONLYpGub5y6ugB+8cZe8M2RFlkxyTPB1CF2wOSy/HhQoayXLB 7GP8rvV6nqTIfA0rt7FuPL7elHdtswKzSuyFx7BH8T7I/7qQgXiT7j5LwabQhH5h Tmt5KB9GKtIfp77qtVs0QxSg/UPRrVrXrVD/5pH403dQRlI0CdZDNMzL5lVBxjM= =qCh1 -----END PGP SIGNATURE----- --OgqxwSJOaUobr8KG--