qemu-e2k/include/qemu
Markus Armbruster 43c64a093d host-utils: Proactively fix pow2floor(), switch to unsigned
The function's stated contract is simple enough: "round down to the
nearest power of 2".  Suggests the domain is the representable numbers
>= 1, because that's the smallest power of two.

The implementation doesn't check for domain errors, but returns
garbage instead:

* For negative arguments, pow2floor() returns -2^63, which is not even
  a power of two, let alone the nearest one.

  What sort of works is passing *unsigned* arguments >= 2^63.  The
  implicit conversion to signed is implementation defined, but
  commonly yields the (negative) two's complement.  pow2floor() then
  returns -2^63.  Callers that convert that back to unsigned get the
  correct value 2^63.

* For a zero argument, pow2floor() shifts right by 64.  Undefined
  behavior.  Common actual behavior is to shift by 0, yielding -2^63.

Fix by switching from int64_t to uint64_t and amending the contract to
map zero to zero.

Callers are fine with that:

* memory_access_size()

  This function makes no sense unless the argument is positive and the
  return value fits into int.

* raw_refresh_limits()

  Passes an int between 1 and BDRV_REQUEST_MAX_BYTES.

* iscsi_refresh_limits()

  Passes an integer between 0 and INT_MAX, converts the result to
  uint32_t.  Passing zero would be undefined behavior, but commonly
  yield zero.  The patch gives us the zero without the undefined
  behavior.

* cache_init()

  Passes a positive int64_t argument.

* xbzrle_cache_resize()

  Passes a positive int64_t argument (>= TARGET_PAGE_SIZE, actually).

* spapr_node0_size()

  Passes a positive uint64_t argument, and converts the result to
  hwaddr, i.e. uint64_t.

* spapr_populate_memory()

  Passes a positive hwaddr argument, and converts the result to
  hwaddr.

Cc: Juan Quintela <quintela@redhat.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1501148776-16890-3-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2017-09-06 14:37:25 +01:00
..
acl.h Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
atomic.h docs: fix broken paths to docs/devel/atomics.txt 2017-07-31 13:12:47 +03:00
base64.h Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
bcd.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
bitmap.h bitmap: add bitmap_copy_and_clear_atomic 2017-04-24 10:12:28 +02:00
bitops.h vnc: replace hweight_long() with ctpopl() 2017-05-12 12:36:02 +02:00
bswap.h bswap.h: Document cpu_to_* and *_to_cpu conversion functions 2016-07-12 15:08:53 +01:00
buffer.h Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
compiler.h use _Static_assert in QEMU_BUILD_BUG_ON 2017-05-05 12:09:59 +02:00
config-file.h arch_init: Remove unnecessary default_config_files table 2017-01-23 21:25:36 -02:00
coroutine.h coroutine-lock: add qemu_co_rwlock_downgrade and qemu_co_rwlock_upgrade 2017-07-17 11:28:15 +08:00
coroutine_int.h aio: introduce aio_co_schedule and aio_co_wake 2017-02-21 11:14:07 +00:00
cpuid.h util: Introduce include/qemu/cpuid.h 2017-07-24 12:42:55 +01:00
crc32c.h
cutils.h util/cutils: Change qemu_strtosz*() from int64_t to uint64_t 2017-02-23 20:35:36 +01:00
envlist.h
error-report.h error: Functions to report warnings and informational messages 2017-07-13 13:49:54 +02:00
event_notifier.h event_notifier: cleanups around event_notifier_set_handler 2017-01-16 17:52:35 +01:00
fifo8.h Clean up header guards that don't match their file name 2016-07-12 16:19:16 +02:00
fifo32.h
fprintf-fn.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
futex.h qemu-thread: optimize QemuLockCnt with futexes on Linux 2017-01-16 13:25:18 +00:00
hbitmap.h qmp: add x-debug-block-dirty-bitmap-sha256 2017-07-11 17:44:59 +02:00
help_option.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
host-utils.h host-utils: Proactively fix pow2floor(), switch to unsigned 2017-09-06 14:37:25 +01:00
id.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
int128.h tcg: Add atomic128 helpers 2016-10-26 08:29:01 -07:00
iov.h
jhash.h Jhash: add linux kernel jhashtable in qemu 2016-09-27 17:54:21 +08:00
log.h log: Add locking to large logging blocks 2016-11-01 10:29:03 -06:00
main-loop.h main_loop: Make main_loop_wait() return void 2017-07-04 14:39:28 +02:00
memfd.h
mmap-alloc.h exec, kvm, target-ppc: Move getrampagesize() to common code 2017-03-03 11:30:59 +11:00
module.h qmp: Dumb down how we run QMP command registration 2017-03-05 09:02:10 +01:00
notify.h
option.h keyval: New keyval_parse() 2017-03-07 16:07:46 +01:00
option_int.h Clean up header guards that don't match their file name 2016-07-12 16:19:16 +02:00
osdep.h osdep: Add runtime OFD lock detection 2017-08-11 14:12:44 +02:00
path.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
processor.h
qdist.h clean-includes: run it once more 2016-06-16 18:39:03 +02:00
qht.h include: Fix typos found by codespell 2017-01-24 23:26:52 +03:00
queue.h migration: migrate QTAILQ 2017-01-24 17:54:47 +00:00
range.h range: Replace internal representation of Range 2016-07-04 16:49:33 +03:00
ratelimit.h blockjob: Track job ratelimits via bytes, not sectors 2017-07-10 13:18:06 +02:00
rcu.h Revert "rcu: do not create thread in pthread_atfork callback" 2017-08-08 10:40:19 +02:00
rcu_queue.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
readline.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
seqlock.h seqlock: use atomic writes for the sequence 2016-10-04 10:00:26 +02:00
sockets.h util: remove the obsolete non-blocking connect 2017-09-05 13:21:58 +01:00
stats64.h util: add stats64 module 2017-06-16 07:55:00 +08:00
systemd.h qemu-ga: obey LISTEN_PID when using systemd socket activation 2017-03-19 11:12:12 +01:00
thread-posix.h qemu-thread: Assert locks are initialized before using 2017-07-04 14:39:28 +02:00
thread-win32.h qemu-thread: Assert locks are initialized before using 2017-07-04 14:39:28 +02:00
thread.h qemu-thread: optimize QemuLockCnt with futexes on Linux 2017-01-16 13:25:18 +00:00
throttle-options.h throttle: factor out duplicate code 2017-02-28 10:31:46 +01:00
throttle.h throttle: Make burst_length 64bit and add range checks 2017-08-29 16:54:45 +01:00
timed-average.h
timer.h timer.h: Provide better monotonic time 2017-06-13 14:56:59 +01:00
typedefs.h qapi: Introduce a first class 'null' type 2017-07-24 13:35:11 +02:00
unicode.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
uri.h Remove unused function declarations 2016-09-15 15:32:22 +03:00
uuid.h vl: Switch qemu_uuid to QemuUUID 2016-09-23 11:42:52 +08:00
xattr.h include: Fix typos found by codespell 2017-01-24 23:26:52 +03:00