From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHBJu-0007pu-Db for qemu-devel@nongnu.org; Tue, 21 Nov 2017 11:22:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHBJq-0006zh-Et for qemu-devel@nongnu.org; Tue, 21 Nov 2017 11:22:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41044) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eHBJq-0006zF-62 for qemu-devel@nongnu.org; Tue, 21 Nov 2017 11:22:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68AE0356DE for ; Tue, 21 Nov 2017 16:22:41 +0000 (UTC) Date: Tue, 21 Nov 2017 17:22:36 +0100 From: Igor Mammedov Message-ID: <20171121172236.618c8e08@redhat.com> In-Reply-To: <20171121180202-mutt-send-email-mst@kernel.org> References: <1510834622-28800-1-git-send-email-thuth@redhat.com> <20171120175522.76bf71c3@redhat.com> <20171120223048-mutt-send-email-mst@kernel.org> <20171121142639.3e6d2e79@redhat.com> <20171121164254-mutt-send-email-mst@kernel.org> <20171121165809.1ec4362a@redhat.com> <20171121180202-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] tests/bios-tables-test: Fix endianess problems when passing data to iasl List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Thomas Huth , qemu-devel@nongnu.org On Tue, 21 Nov 2017 18:02:48 +0200 "Michael S. Tsirkin" wrote: > On Tue, Nov 21, 2017 at 04:58:09PM +0100, Igor Mammedov wrote: > > On Tue, 21 Nov 2017 16:47:11 +0200 > > "Michael S. Tsirkin" wrote: > > > > > On Tue, Nov 21, 2017 at 02:26:39PM +0100, Igor Mammedov wrote: > > > > On Mon, 20 Nov 2017 22:32:29 +0200 > > > > "Michael S. Tsirkin" wrote: > > > > > > > > > On Mon, Nov 20, 2017 at 05:55:22PM +0100, Igor Mammedov wrote: > > > > > > On Thu, 16 Nov 2017 13:17:02 +0100 > > > > > > Thomas Huth wrote: > > > > > > > > > > > > > The bios-tables-test was writing out files that we pass to iasl in > > > > > > > with the wrong endianness in the header when running on a big endian > > > > > > > host. So instead of storing mixed endian information in our structures, > > > > > > > let's keep everything in little endian and byte-swap it only when we > > > > > > > need a value in the code. > > > > > > > > > > > > > > Reported-by: Daniel P. Berrange > > > > > > > Buglink: https://bugs.launchpad.net/qemu/+bug/1724570 > > > > > > > Suggested-by: Michael S. Tsirkin > > > > > > > Signed-off-by: Thomas Huth > > > > > > > --- > > > > > > > v2: Fixed vmgenid-test which was accidentially broken in v1 > > > > > > > > > > > > > > tests/acpi-utils.h | 27 +++++---------------------- > > > > > > > tests/bios-tables-test.c | 42 ++++++++++++++++++++++-------------------- > > > > > > > tests/vmgenid-test.c | 22 ++++++++++++---------- > > > > > > > 3 files changed, 39 insertions(+), 52 deletions(-) > > > > > > > > > > > > > > diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h > > > > > > > index f8d8723..d5ca5b6 100644 > > > > > > > --- a/tests/acpi-utils.h > > > > > > > +++ b/tests/acpi-utils.h > > > > > > > @@ -28,24 +28,9 @@ typedef struct { > > > > > > > bool tmp_files_retain; /* do not delete the temp asl/aml */ > > > > > > > } AcpiSdtTable; > > > > > > > > > > > > > > -#define ACPI_READ_FIELD(field, addr) \ > > > > > > > - do { \ > > > > > > > - switch (sizeof(field)) { \ > > > > > > > - case 1: \ > > > > > > > - field = readb(addr); \ > > > > > > > - break; \ > > > > > > > - case 2: \ > > > > > > > - field = readw(addr); \ > > > > > > > - break; \ > > > > > > > - case 4: \ > > > > > > > - field = readl(addr); \ > > > > > > > - break; \ > > > > > > > - case 8: \ > > > > > > > - field = readq(addr); \ > > > > > > > - break; \ > > > > > > > - default: \ > > > > > > > - g_assert(false); \ > > > > > > > - } \ > > > > > > probably it's been discussed but, why not do > > > > > > leXX_to_cpu() > > > > > > here, instead of making each place that access read field > > > > > > to do leXX_to_cpu() manually.? > > > > > > > > > > > > Beside of keeping access to structure in natural host order, > > > > > > it should also be less error-prone as field users don't > > > > > > have to worry about endianness. > > > > > > > > > > Yes, I suggested that. > > > > > The issue is that we don't byte-swap all of the tables > > > > > (we can't, that would require a full ACPI parser). > > > > > So when byte-swapping we end up with a mixed host/LE > > > > > structures. > > ... > > > > What tables/use-cases do you have in mind where we'd need full > > > > ACPI parser /whatever it is/? > > > > > > We dump ACPI tables for parsing by iasl. > > I don't really see a problem here (i.e. how dumping blobs for > > iasl would require byte-swap all of the tables). > > It's not all the tables. We would need to track what is and > what isn't swapped. Why we need track swapping at all? Why not just convert everything to host order and work with that in C code, so we won't have to deal with mixed endianness anywhere in code beside of accessors wrappers? > > Where bios-tables-test.c is concerned we should just read > > a blob from qemu (get its location/len/name) and dump it to > > disk without changing anything in it. > > Exactly. > > > > > > > > > > Keeping it all LE seems cleaner. > > > > > > > > > >