From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wv0nb-0000DI-Ox for qemu-devel@nongnu.org; Thu, 12 Jun 2014 04:56:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wv0nS-0003Ac-OL for qemu-devel@nongnu.org; Thu, 12 Jun 2014 04:55:55 -0400 Received: from mail-we0-x22f.google.com ([2a00:1450:400c:c03::22f]:60117) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wv0nS-0003AW-Gk for qemu-devel@nongnu.org; Thu, 12 Jun 2014 04:55:46 -0400 Received: by mail-we0-f175.google.com with SMTP id k48so194728wev.6 for ; Thu, 12 Jun 2014 01:55:45 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <53996B0E.4040808@redhat.com> Date: Thu, 12 Jun 2014 10:55:42 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <20140514154130.10746.1412.stgit@bahia.local> <20140514154230.10746.56297.stgit@bahia.local> <5384A8D2.8050104@redhat.com> <20140529111253.4ff55199@bahia.local> <538708FA.4070309@redhat.com> <20140612094351.6295fd38@bahia.local> In-Reply-To: <20140612094351.6295fd38@bahia.local> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH RFC 8/8] virtio: add endian-ambivalent support to VirtIODevice List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Greg Kurz Cc: Kevin Wolf , Fam Zheng , Anthony Liguori , Juan Quintela , "Michael S. Tsirkin" , Alexander Graf , qemu-devel@nongnu.org, Stefan Hajnoczi , Amit Shah , =?ISO-8859-1?Q?Andreas_F=E4rber?= Il 12/06/2014 09:43, Greg Kurz ha scritto: > Since we know that 0 < max_nr_ports < 32, is it acceptable to guess > the correct endianness with a heuristic ? > > if (max_nr_ports > tswap32(s->config.max_nr_ports)) { > max_nr_ports = bswap32(max_nr_ports); > } > > if (max_nr_ports > tswap32(s->config.max_nr_ports)) { > return -EINVAL; > } Yes, I guess it is acceptable. So first you should fix the code to always serialize fields as big-endian, and then apply this little hack and virtio_tswap on top of the previous change. Paolo