qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Morel <pmorel@linux.vnet.ibm.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: cornelia.huck@de.ibm.com, peter.maydell@linaro.org
Subject: Re: [Qemu-devel] [PATCH 0/7] int128: reparing broken 128 bit memory calculations
Date: Fri, 6 Nov 2015 09:36:37 +0100	[thread overview]
Message-ID: <563C6695.7030507@linux.vnet.ibm.com> (raw)
In-Reply-To: <563B8498.7070804@redhat.com>



On 11/05/2015 05:32 PM, Paolo Bonzini wrote:
>
> On 05/11/2015 17:18, Pierre Morel wrote:
>> The size of a memory area can never be negative.
>> It follows it must be defined as an unsigned value.
>>      
>> Let's modify the memory regions size to unsigned 128 integer
>> and modify accordingly the 128 bit arithmetic.
>>      
>> This makes memory size calculations easier and easier to understand.
>>      
>> I fear loud protest but really, it is a broken concept that
>> obfuscate the code.
> You are right in fearing loud protest, though the protest is for the
> lack of explanation of what is broken.
>
> Since the values are never going to be > 2^65, there is no chance of
> overflow.  On the other hand there are cases where we compute
> start+size-1, and size-1 *could* overflow if you use unsigned integers.
>
> So I am not sure... why?
>
> Paolo
>
Paolo,

The calculation are not broken and it works for actual usage but:

For me, it is the design that is broken, as it uses an integer to represent
something that is fundamentally unsigned like the size of a memory area.

This leads to have UINT64_MAX represented with {1, 0} instead of {0, 
UINT64_MAX}
while {1, 0} is 2^64.
This again leads to have unnecessary and obfuscating transformations 
with int128_2_64()
to test for UINT64_MAX and return {1,0} in memory_region_init() while using
inverse translation test{1,0} and return UINT64_MAX in memory_region_size()

Another concern is that pushing the 31th bit to the 32nd bit may be 
confusing when
used, if ever, with IOMMU or other hardware components using 128bits 
registers.
Considering some Intel IOMMU for example.

The modifications I proposed are also not perfect, I just seen I forgot 
to change a -1 to UINT64_MAX
and I forgot some unnecessary cast. At least.

Pierre

  reply	other threads:[~2015-11-06  8:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 16:18 [Qemu-devel] [PATCH 0/7] int128: reparing broken 128 bit memory calculations Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 1/7] int128: use unsigned 128 bit arithmetic Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 2/7] memory: modify memory size for an unsigned 128bit int Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 3/7] 128bit: adapt core files for unsigned 128bits Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 4/7] 128bit: adapt sparc mmu_helper for UInt128 Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 5/7] 128bit: adapt VFIO for UInt128 arithmetic Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 6/7] 128bit: adapt Virtio " Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 7/7] 128bits: some HW components use 128bit arithmetic Pierre Morel
2015-11-05 16:32 ` [Qemu-devel] [PATCH 0/7] int128: reparing broken 128 bit memory calculations Paolo Bonzini
2015-11-06  8:36   ` Pierre Morel [this message]
2015-11-06 16:33     ` Paolo Bonzini
     [not found]       ` <56408B28.8070408@linux.vnet.ibm.com>
2015-11-09 12:20         ` Paolo Bonzini
2015-11-10  9:08           ` Pierre Morel
2015-11-10 12:12             ` Pierre Morel

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=563C6695.7030507@linux.vnet.ibm.com \
    --to=pmorel@linux.vnet.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).