qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"John Snow" <jsnow@redhat.com>,
	"Sam Eiderman" <shmuel.eiderman@oracle.com>
Cc: Fam Zheng <fam@euphon.net>,
	Peter Maydell <peter.maydell@linaro.org>,
	Thomas Huth <thuth@redhat.com>,
	Qemu-block <qemu-block@nongnu.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Laurent Vivier <lvivier@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Max Reitz <mreitz@redhat.com>,
	"Gonglei \(Arei\)" <arei.gonglei@huawei.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>
Subject: Re: [PULL v2 0/8] Ide patches
Date: Tue, 8 Oct 2019 23:58:42 +0200	[thread overview]
Message-ID: <6b00dc74-7267-8ce8-3271-5db269edb1b7@redhat.com> (raw)
In-Reply-To: <e0945918-d1cf-abf8-218a-6c5e8be80b70@redhat.com>

On 10/07/19 19:55, Philippe Mathieu-Daudé wrote:
> On 10/7/19 7:35 PM, John Snow wrote:
>> On 10/7/19 8:33 AM, Peter Maydell wrote:
>>> On Thu, 3 Oct 2019 at 20:33, John Snow <jsnow@redhat.com> wrote:
>>>>
>>>> The following changes since commit
>>>> 7f21573c822805a8e6be379d9bcf3ad9effef3dc:
>>>>
>>>>    Merge remote-tracking branch
>>>> 'remotes/huth-gitlab/tags/pull-request-2019-10-01' into staging
>>>> (2019-10-01 13:13:38 +0100)
>>>>
>>>> are available in the Git repository at:
>>>>
>>>>    https://github.com/jnsnow/qemu.git tags/ide-pull-request
>>>>
>>>> for you to fetch changes up to
>>>> f6d61c9509c56eea3cdd2d23b40d285601b1c1ca:
>>>>
>>>>    hd-geo-test: Add tests for lchs override (2019-10-03 14:36:54 -0400)
>>>>
>>>> ----------------------------------------------------------------
>>>> Pull request V2
>>>>
>>>> - Added signoff into the mirrored commits themselves (vs just the
>>>> email)
>>>> - Kudos to `stg-foreach stg edit --sign`
>>>>
>>>> ----------------------------------------------------------------
>>>
>>> Hi; the new tests in hd-geo-test seem to hang on
>>> big-endian hosts (both s390x and ppc64 hung here):
>>>
>>> linux1@lxub05:~/qemu/build/all$ QTEST_QEMU_IMG=./qemu-img
>>> QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64
>>> ./tests/hd-geo-test
>>> /x86_64/hd-geo/ide/none: OK
>>> /x86_64/hd-geo/ide/drive/cd_0: OK
>>> /x86_64/hd-geo/ide/drive/mbr/blank: OK
>>> /x86_64/hd-geo/ide/drive/mbr/lba: OK
>>> /x86_64/hd-geo/ide/drive/mbr/chs: OK
>>> /x86_64/hd-geo/ide/device/mbr/blank: OK
>>> /x86_64/hd-geo/ide/device/mbr/lba: OK
>>> /x86_64/hd-geo/ide/device/mbr/chs: OK
>>> /x86_64/hd-geo/ide/device/user/chs: OK
>>> /x86_64/hd-geo/ide/device/user/chst: OK
>>> /x86_64/hd-geo/override/ide:
>>>
>>
>> :(
>>
>>>
>>> thanks
>>> -- PMM
>>>
>>
>> Sam, can you investigate this?
> 
> Not seeing my T-b tags makes me grumble because I don't remember which I
> reviewed and need to go check on the list.
> 
> If the error is a endianess bug related to fw_cfg, you can add the
> "-trace fw_cfg*" in hd-geo-test::create_args() and rerun the tests on a
> BE system, the bug should appear straightly on stdout.
> 
> Are FWLCHSEntry fields little-endian? Shouldn't
> get_boot_devices_lchs_list() use some le32_to_cpu() call for the LCHS
> values?
> 

*One* problem is most likely in the find_fw_cfg_file() function, in patch 8.

+static uint16_t find_fw_cfg_file(QFWCFG *fw_cfg,
+                                 const char *filename)
+{
+    struct QemuCfgFile qfile;
+    uint32_t count, e;
+    uint16_t select;
+
+    count = qfw_cfg_get_u32(fw_cfg, FW_CFG_FILE_DIR);
+    count = be32_to_cpu(count);
+    for (select = 0, e = 0; e < count; e++) {
+        qfw_cfg_read_data(fw_cfg, &qfile, sizeof(qfile));
+        if (!strcmp(filename, qfile.name)) {
+            select = be16_to_cpu(qfile.select);
+        }
+    }
+
+    return select;
+}

Note qfw_cfg_get_u32():

uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key)
{
    uint32_t value;
    qfw_cfg_get(fw_cfg, key, &value, sizeof(value));
    return le32_to_cpu(value);
}

This function assumes that the wire encoding of the value read is little
endian. So, calling this function is wrong; and calling be32_to_cpu()
afterwards does not help. Namely:

* On LE hosts, the find_fw_cfg_file() function happens to work, because:

- the le32_to_cpu() call in qfw_cfg_get_u32() does nothing (it's identity),
- the subsequent be32_to_cpu() call in find_fw_cfg_file() corresponds to
the *blob-specific* encoding of the "count" field, in the fw_cfg
directory blob. (Which is BE) Therefore we perform the one byte-swap
that we need.

* On BE hosts, stuff breaks, because:

- the le32_to_cpu() call in qfw_cfg_get_u32() swaps the byte-order,
- the subsequent be32_to_cpu() call in find_fw_cfg_file() does nothing,
- thus, ultimately we have byte-swapped the contents of the "count"
field of the directory blob, even though the blob-specific wire format
thereof is *already* BE (= host-endian). On a BE host, all in all, there
should be zero byte swaps for consuming "count".

Now, how to fix this: eliminate
- QemuCfgFile,
- find_fw_cfg_file(),
- and read_fw_cfg_file()

altogether, and call qfw_cfg_get_file(), from "tests/libqos/fw_cfg.c".

Some other tests look up fw_cfg directory entries with that function
already (see call sites in "tests/fw_cfg-test.c").

Thanks
Laszlo


  reply	other threads:[~2019-10-08 22:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03 19:32 [PULL v2 0/8] Ide patches John Snow
2019-10-03 19:32 ` [PULL v2 1/8] block: Refactor macros - fix tabbing John Snow
2019-10-03 19:32 ` [PULL v2 2/8] block: Support providing LCHS from user John Snow
2019-10-03 19:32 ` [PULL v2 3/8] bootdevice: Add interface to gather LCHS John Snow
2019-10-03 19:32 ` [PULL v2 4/8] scsi: Propagate unrealize() callback to scsi-hd John Snow
2019-10-03 19:32 ` [PULL v2 5/8] bootdevice: Gather LCHS from all relevant devices John Snow
2019-10-03 19:32 ` [PULL v2 6/8] bootdevice: Refactor get_boot_devices_list John Snow
2019-10-03 19:32 ` [PULL v2 7/8] bootdevice: FW_CFG interface for LCHS values John Snow
2019-10-03 19:32 ` [PULL v2 8/8] hd-geo-test: Add tests for lchs override John Snow
2019-10-03 20:48 ` [PULL v2 0/8] Ide patches no-reply
2019-10-07 12:33 ` Peter Maydell
2019-10-07 17:35   ` John Snow
2019-10-07 17:55     ` Philippe Mathieu-Daudé
2019-10-08 21:58       ` Laszlo Ersek [this message]
2019-10-08 22:55         ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6b00dc74-7267-8ce8-3271-5db269edb1b7@redhat.com \
    --to=lersek@redhat.com \
    --cc=arei.gonglei@huawei.com \
    --cc=fam@euphon.net \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=shmuel.eiderman@oracle.com \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).