From: Laurent Vivier <laurent@vivier.eu>
To: Max Filippov <jcmvbkbc@gmail.com>
Cc: Richard Henderson <richard.henderson@linaro.org>,
qemu-devel <qemu-devel@nongnu.org>,
Peter Maydell <peter.maydell@linaro.org>,
Riku Voipio <riku.voipio@iki.fi>
Subject: Re: [Qemu-devel] [PATCH v3] linux-user: fix preadv/pwritev offsets
Date: Thu, 5 Apr 2018 18:33:06 +0200 [thread overview]
Message-ID: <31415928-bff1-7c2b-ec01-a56d708a7002@vivier.eu> (raw)
In-Reply-To: <CAMo8Bf+9h2vSMcQQftkh0DDLNJbHV_beGARSn2RaB_MjkRMtFg@mail.gmail.com>
Le 05/04/2018 à 18:27, Max Filippov a écrit :
> On Thu, Apr 5, 2018 at 8:52 AM, Laurent Vivier <laurent@vivier.eu> wrote:
>> Why don't you try to de-construct then re-construct the offset?
>
> It would require 128-bit arithmetic on 64-bit host.
>
>> Kernel commit
>> 601cc11d054a "Make non-compat preadv/pwritev use native register size"
>> is interesting.
>>
>> static inline abi_llong target_pos_from_hilo(abi_ulong high,
>> abi_ulong low)
>> {
>> #define TARGET_HALF_LONG_BITS (TARGET_LONG_BITS / 2)
>> return (((abi_llong)high << TARGET_HALF_LONG_BITS) <<
>> TARGET_HALF_LONG_BITS) | low;
>> }
>>
>> #define HOST_HALF_LONG_BITS (HOST_LONG_BITS / 2)
>>
>> abi_llong pos = target_pos_from_hilo(arg4, arg5);
>> ret = get_errno(safe_preadv(arg1, vec, arg3,
>> pos,
>> (pos >> HOST_HALF_LONG_BITS) >> HOST_HALF_LONG_BITS));
>>
>> It looks simpler, but perhaps I miss something
>> (it's just cut&paste, I don't pretend to understand that code...)?
>
> If we decide that host unsigned long long is wide enough to represent
> meaningful file positions then this function may be simplified to
> something like
>
> unsigned long long off = (unsigned long long)tlow |
> ((unsigned long long)thigh << (TARGET_LONG_BITS / 2)) << (TARGET_LONG_BITS / 2);
> *hlow = (unsigned long)off;
> *hhigh = (unsigned long)((off >> (HOST_LONG_BITS / 2)) >> (HOST_LONG_BITS / 2));
>
> There's also a bug that the target may specify an offset not representable
> on the host, that will get truncated and point to a different location in the
> file, possibly resulting in data corruption.
I don't think it can happen, because "long long" is always 64bit, so it
fits in two 32bit (long is 32bit on 32bit, 64bit on 64bit).
Thanks,
Laurent
prev parent reply other threads:[~2018-04-05 16:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-05 13:47 [Qemu-devel] [PATCH v3] linux-user: fix preadv/pwritev offsets Max Filippov
2018-04-05 15:52 ` Laurent Vivier
2018-04-05 16:27 ` Max Filippov
2018-04-05 16:33 ` Laurent Vivier [this message]
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=31415928-bff1-7c2b-ec01-a56d708a7002@vivier.eu \
--to=laurent@vivier.eu \
--cc=jcmvbkbc@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=riku.voipio@iki.fi \
/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).