From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzOF6-0000sC-1Q for qemu-devel@nongnu.org; Fri, 12 Dec 2014 06:18:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzOEx-0006Sb-03 for qemu-devel@nongnu.org; Fri, 12 Dec 2014 06:18:39 -0500 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:34111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzOEw-0006SX-Ot for qemu-devel@nongnu.org; Fri, 12 Dec 2014 06:18:30 -0500 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 12 Dec 2014 11:18:29 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6FA5417D8042 for ; Fri, 12 Dec 2014 11:18:50 +0000 (GMT) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sBCBIR8C63045646 for ; Fri, 12 Dec 2014 11:18:27 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sBC6FBPv019845 for ; Fri, 12 Dec 2014 01:15:12 -0500 Date: Fri, 12 Dec 2014 12:18:25 +0100 From: Cornelia Huck Message-ID: <20141212121825.6c09af4d.cornelia.huck@de.ibm.com> In-Reply-To: <20141212115538.2aa96fd2@oc7435384737.ibm.com> References: <1418304322-7546-1-git-send-email-cornelia.huck@de.ibm.com> <1418304322-7546-13-git-send-email-cornelia.huck@de.ibm.com> <20141212115538.2aa96fd2@oc7435384737.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH RFC v6 12/20] virtio: disallow late feature changes for virtio-1 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Huth Cc: rusty@rustcorp.com.au, mst@redhat.com, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org On Fri, 12 Dec 2014 11:55:38 +0100 Thomas Huth wrote: > On Thu, 11 Dec 2014 14:25:14 +0100 > Cornelia Huck wrote: > > > For virtio-1 devices, the driver must not attempt to set feature bits > > after it set FEATURES_OK in the device status. Simply reject it in > > that case. > > > > Signed-off-by: Cornelia Huck > > --- > > hw/virtio/virtio.c | 16 ++++++++++++++-- > > include/hw/virtio/virtio.h | 2 ++ > > 2 files changed, 16 insertions(+), 2 deletions(-) > > > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > > index 57190ba..a3dd67b 100644 > > --- a/hw/virtio/virtio.c > > +++ b/hw/virtio/virtio.c > > @@ -978,7 +978,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) > > vmstate_save_state(f, &vmstate_virtio, vdev); > > } > > > > -int virtio_set_features(VirtIODevice *vdev, uint64_t val) > > +static int __virtio_set_features(VirtIODevice *vdev, uint64_t val) > > Maybe avoid the double underscores here? But unfortunately, I also fail > to come up with a better suggestion for a name here ... virtio_set_features_nocheck()? This function is only called within virtio.c anyway... > > > { > > BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); > > VirtioBusClass *vbusk = VIRTIO_BUS_GET_CLASS(qbus); > > @@ -994,6 +994,18 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val) > > return bad ? -1 : 0; > > } > > > > +int virtio_set_features(VirtIODevice *vdev, uint64_t val) > > +{ > > + /* > > + * The driver must not attempt to set features after feature negotiation > > + * has finished. > > + */ > > + if (vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) { > > + return -EINVAL; > > + } > > Hmm, according to your patch description, the FEATURES_OK check only > applies to virtio-1.0 devices ... so shouldn't there be a check for > virtio-1 here? Or did I miss something? A device in legacy mode will never have FEATURES_OK set. But it is a bit non-obvious - maybe adding a check for VERSION_1 does not hurt. > > > + return __virtio_set_features(vdev, val); > > +} > > Thomas