From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=52622 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PFmTx-000436-IZ for qemu-devel@nongnu.org; Tue, 09 Nov 2010 06:35:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PFmTa-0005LQ-SL for qemu-devel@nongnu.org; Tue, 09 Nov 2010 06:35:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1445) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PFmTa-0005Ks-Li for qemu-devel@nongnu.org; Tue, 09 Nov 2010 06:34:58 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oA9BYu8K022171 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Nov 2010 06:34:56 -0500 Date: Tue, 9 Nov 2010 13:34:53 +0200 From: "Michael S. Tsirkin" Message-ID: <20101109113453.GA22705@redhat.com> References: <1288623114-14439-1-git-send-email-kraxel@redhat.com> <20101108174752.GC8498@redhat.com> <4CD91661.6030102@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4CD91661.6030102@redhat.com> Subject: [Qemu-devel] Re: [PATCH] add VMSTATE_BOOL List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org On Tue, Nov 09, 2010 at 10:37:37AM +0100, Gerd Hoffmann wrote: > Hi, > > >>+#define VMSTATE_BOOL_ARRAY(_f, _s, _n) \ > >>+ VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0) > >>+ > > > >Why don't we pack the bits? > > Point being? As long as we don't save *big* arrays of bools it > simply isn't worth the effort IMHO. And for big arrays we'll > probably wouldn't use bool in the first place ... > > >>+/* bool */ > >>+ > >>+static int get_bool(QEMUFile *f, void *pv, size_t size) > >>+{ > >>+ bool *v = pv; > >>+ *v = qemu_get_byte(f); > >>+ return 0; > > > >We must really validate that the value is 0 or 1. > >If it's not, we will get undefined behaviour. > > I disagree. > > You indeed have a bug in case your bool ends up with a value being > neither 0 nor 1. That is completely independant from savevm/loadvm > though, it can trip you up even in case you don't save/load the VM > at all. I was wrong about undefined behaviour. Sorry. What this implementation does is treat byte value '\0' as boolean false, any other value as true. I think we should verify that value is 0 or 1 and fail migration otherwise, to make it more robust. > >>+} > >>+ > >>+static void put_bool(QEMUFile *f, void *pv, size_t size) > >>+{ > >>+ bool *v = pv; > >>+ qemu_put_byte(f, *v); > > > >Is there a guarantee that bool is a single byte, BTW? > > No. bool must be 0 or 1 though, and a single byte is big enough to > keep that information. > > cheers, > Gerd Right.