qemu-e2k/include/qemu
Peter Maydell 77b1757090 include/qemu/bswap.h: Use __builtin_memcpy() in accessor functions
In the accessor functions ld*_he_p() and st*_he_p() we use memcpy()
to perform a load or store to a pointer which might not be aligned
for the size of the type. We rely on the compiler to optimize this
memcpy() into an efficient load or store instruction where possible.
This is required for good performance, but at the moment it is also
required for correct operation, because some users of these functions
require that the access is atomic if the pointer is aligned, which
will only be the case if the compiler has optimized out the memcpy().
(The particular example where we discovered this is the virtio
vring_avail_idx() which calls virtio_lduw_phys_cached() which
eventually ends up calling lduw_he_p().)

Unfortunately some compile environments, such as the fortify-source
setup used in Alpine Linux, define memcpy() to a wrapper function
in a way that inhibits this compiler optimization.

The correct long-term fix here is to add a set of functions for
doing atomic accesses into AddressSpaces (and to other relevant
families of accessor functions like the virtio_*_phys_cached()
ones), and make sure that callsites which want atomic behaviour
use the correct functions.

In the meantime, switch to using __builtin_memcpy() in the
bswap.h accessor functions. This will make us robust against things
like this fortify library in the short term. In the longer term
it will mean that we don't end up with these functions being really
badly-performing even if the semantics of the out-of-line memcpy()
are correct.

Reported-by: Fernando Casas Schössow <casasfernando@outlook.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20190318112938.8298-1-peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2019-04-09 18:34:21 +02:00
..
atomic128.h tcg: add early clober modifier in atomic16_cmpxchg on aarch64 2019-02-06 03:38:39 +00:00
atomic.h atomics: Set ATOMIC_REG_SIZE=8 for MIPS n32 2019-01-03 17:52:52 +01:00
base64.h
bcd.h
bitmap.h bitmap: bitmap_count_one_with_offset 2019-03-06 10:49:17 +00:00
bitops.h
bswap.h include/qemu/bswap.h: Use __builtin_memcpy() in accessor functions 2019-04-09 18:34:21 +02:00
buffer.h
compiler.h linux-user: Fix compilation with clang 3.4 2019-01-22 06:26:31 +01:00
config-file.h
coroutine_int.h coroutine: avoid co_queue_wakeup recursion 2018-03-27 13:05:28 +01:00
coroutine.h block: Add missing locking in bdrv_co_drain_bh_cb() 2018-09-25 15:50:15 +02:00
cpuid.h
crc32c.h
cutils.h cutils: Fix qemu_strtosz() & friends to reject non-finite sizes 2018-12-13 19:10:06 +01:00
drm.h util: promote qemu_egl_rendernode_open() to libqemuutil 2018-08-27 10:51:44 +02:00
envlist.h
error-report.h qemu-error: make use of {error, warn}_report_once_cond 2018-09-24 17:13:07 +02:00
event_notifier.h
fifo8.h
fifo32.h
filemonitor.h filemon: fix watch IDs to avoid potential wraparound issues 2019-04-02 13:52:02 +01:00
fprintf-fn.h
futex.h
hbitmap.h Revert "hbitmap: Add @advance param to hbitmap_iter_next()" 2019-01-15 18:26:50 -05:00
help_option.h
host-utils.h includes: Replace QEMU_GNUC_PREREQ with "__has_builtin || !defined(__clang__)" 2018-12-12 10:01:13 +01:00
id.h
int128.h
iov.h block: enhance QEMUIOVector structure 2019-02-22 09:42:13 +00:00
iova-tree.h util: remove redundant include of glib.h and add osdep.h 2018-06-29 12:22:28 +01:00
jhash.h
job.h blockjob: Lie better in child_job_drained_poll() 2018-09-25 15:50:15 +02:00
lockable.h lockable: workaround GCC link issue with ASAN 2018-03-06 14:01:27 +01:00
log-for-trace.h log-for-trace.h: Split out parts of log.h used by trace.h 2018-03-12 11:10:20 +00:00
log.h tcg: Optionally log FPU state in TCG -d cpu logging 2018-05-15 14:58:44 +01:00
main-loop.h slirp: replace global polling with per-instance & notifier 2019-02-07 15:49:08 +02:00
memfd.h hostmem-memfd: add checks before adding hostmem-memfd & properties 2018-10-02 18:47:55 +02:00
mmap-alloc.h mmap-alloc: fix hugetlbfs misaligned length in ppc64 2019-02-04 18:44:20 +11:00
module.h tests: qgraph API for the qtest driver framework 2019-03-07 17:28:24 +01:00
notify.h
option_int.h qemu/queue.h: simplify reverse access to QTAILQ 2019-01-11 15:46:55 +01:00
option.h option: Make option help nicer to read 2018-11-05 15:17:48 +01:00
osdep.h hostmem-file: reject invalid pmem file sizes 2019-03-11 10:44:19 -03:00
path.h
pmem.h migration/ram: ensure write persistence on loading all data to PMEM. 2018-08-10 13:29:39 +03:00
processor.h
qdist.h
qht.h qht: constify qht_statistics_init 2018-09-26 08:55:54 -07:00
qsp.h qsp: support call site coalescing 2018-08-23 18:46:25 +02:00
queue.h queue: fix QTAILQ_FOREACH_REVERSE_SAFE 2019-02-05 16:50:21 +01:00
range.h Don't talk about the LGPL if the file is licensed under the GPL 2019-01-30 10:51:20 +01:00
ratelimit.h
rcu_queue.h qemu/queue.h: reimplement QTAILQ without pointer-to-pointers 2019-01-11 15:46:55 +01:00
rcu.h membarrier: introduce qemu/sys_membarrier.h 2018-03-12 16:12:47 +01:00
readline.h
seqlock.h seqlock: add QemuLockable support 2018-08-23 18:46:25 +02:00
sockets.h sockets: move fd_is_socket() into common sockets code 2018-03-13 18:06:06 +00:00
stats64.h
sys_membarrier.h membarrier: add --enable-membarrier 2018-03-12 16:12:47 +01:00
systemd.h
thread-posix.h qsp: QEMU's Synchronization Profiler 2018-08-23 18:46:25 +02:00
thread-win32.h qsp: QEMU's Synchronization Profiler 2018-08-23 18:46:25 +02:00
thread.h include/qemu/thread.h: Document qemu_thread_atexit* API 2018-11-06 21:35:06 +01:00
throttle-options.h
throttle.h Include less of the generated modular QAPI headers 2018-03-02 13:45:50 -06:00
timed-average.h
timer.h * RTC fixes (Artem) 2018-10-19 19:01:07 +01:00
typedefs.h net: Introduce announce timer 2019-03-05 11:27:41 +08:00
unicode.h json: Reject invalid UTF-8 sequences 2018-08-24 20:26:37 +02:00
units.h block: Eliminate the S_1KiB, S_2KiB, ... macros 2019-02-01 13:46:45 +01:00
uri.h
uuid.h uuid: Make qemu_uuid_bswap() take and return a QemuUUID 2019-02-01 13:46:45 +01:00
vfio-helpers.h Clean up includes 2018-12-20 10:29:08 +01:00
win_dump_defs.h dump: move Windows dump structures definitions 2018-10-02 19:09:12 +02:00
xattr.h
xxhash.h xxhash: match output against the original xxhash32 2018-12-17 06:04:44 +03:00