From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bRd2M-0005xh-1i for qemu-devel@nongnu.org; Mon, 25 Jul 2016 06:23:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bRd2J-0003Dq-R6 for qemu-devel@nongnu.org; Mon, 25 Jul 2016 06:23:00 -0400 Date: Mon, 25 Jul 2016 20:18:54 +1000 From: David Gibson Message-ID: <20160725101854.GD17429@voom.fritz.box> References: <1469440764-61619-1-git-send-email-imammedo@redhat.com> <1469440764-61619-3-git-send-email-imammedo@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="g7w8+K/95kPelPD2" Content-Disposition: inline In-Reply-To: <1469440764-61619-3-git-send-email-imammedo@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 2/6] exec: don't use cpu_index to detect if cpu_exec_init()'s been called for cpu List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: qemu-devel@nongnu.org, Paolo Bonzini , Peter Crosthwaite , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Alexander Graf , Riku Voipio , Bharata B Rao , qemu-ppc@nongnu.org --g7w8+K/95kPelPD2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jul 25, 2016 at 11:59:20AM +0200, Igor Mammedov wrote: > Instead use QTAIL's tqe_prev field to detect if cpu's been > placed in list by cpu_exec_init() which is always set if > QTAIL element is in list. >=20 > Fixes SIGSEGV on failure path in case cpu_index is assigned > by board and cpu.relalize() fails before cpu_exec_init() is called. >=20 > In follow up patches, cpu_index will be assigned by boards that > support cpu hot(un)plug and need stable cpu_index that doesn't > depend on order cpus are created/removed. >=20 > Signed-off-by: Igor Mammedov > Reported-by: David Gibson Reviewed-by: David Gibson > --- > v2: > replace setting tqe_prev to NULL in generic QTAIL_REMOVE > with a check and cleanup in cpu_exec_exit() to be on safe side. > And delay QTAIL_REMOVE() change to 2.8. > --- > exec.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) >=20 > diff --git a/exec.c b/exec.c > index 2f57c62..ae45a70 100644 > --- a/exec.c > +++ b/exec.c > @@ -643,13 +643,14 @@ void cpu_exec_exit(CPUState *cpu) > CPUClass *cc =3D CPU_GET_CLASS(cpu); > =20 > cpu_list_lock(); > - if (cpu->cpu_index =3D=3D -1) { > - /* cpu_index was never allocated by this @cpu or was already fre= ed. */ > + if (cpu->node.tqe_prev =3D=3D NULL) { > + /* there is nothing to undo since cpu_exec_init() hasn't been ca= lled */ > cpu_list_unlock(); > return; > } > =20 > QTAILQ_REMOVE(&cpus, cpu, node); > + cpu->node.tqe_prev =3D NULL; > cpu_release_index(cpu); > cpu->cpu_index =3D -1; > cpu_list_unlock(); --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --g7w8+K/95kPelPD2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXleeNAAoJEGw4ysog2bOSrZYQAKxlvE3WpQzaDrp5TdIzagey HZecQJyd6AgJaPO5+MKhFtkN5uASeo7guW6Squ6n6qd5/dRuBKdFZgVJPY+97C9l qT2CvLqmj4Nhj/9lzt05HbJzBWB44rjgv1YQzeLx/oI+ajGtDN/czfL7yI4mzqYw ju5m3nMfz5ZhKucHRXvkP1BQ9CAcZZqpCyJTjiSOxxEGCX2+kHPkQDeQuHlXHKwo oaKI5raonB44ptvX6JEOIo5iqh/+kt5EnfTBUERZhKBNqXsfjAStJMKZR3PkIafB ioeg+GnCRitxBdjxj8FJuyz4CeVA84UgLxWPoNIZwEa6F+Jh/9u05JlhPO8iUiV3 BxHurvi3DOj5NB6aUf0ylVDAjIve2Xtw8XzMXJEvV1SiksTYw58MxVAfNFM/iqgp erxLCzo4bPDOrVtneQpEqKC5zjbgR/o78g90yNZ50W+vcgB/xNkrHKaF0u3iwreb 6iz1QdTLE2yuk0nGMrw7qJfCb8rrR/+rHsuerkKnKYKr7258psNh9PdCcLFqW0sU 9O9w/xxfX+HgXLNS+xeQQO6pooEP1OzhSIJftTJ8LUE894SbZNLYLuDTbD8GPaD2 O5bjCkSPloP4qq6ribqTQ++zNxj1hmBtKTZfjeJqpTYc/D0K1RPEm+3fS7XG0MO9 y4EXZmZx324cED5/n7oB =3BZ4 -----END PGP SIGNATURE----- --g7w8+K/95kPelPD2--