Fix MemoryRegionSection alignment and comparison
v2 cover Fix MemoryRegionSection alignment and comparison
From: "Dr. David Alan Gilbert" <[email protected]>
This fixes a symptom I've seen on vhost-user on aarch64 where the daemon would be falsely notified of memory region changes that didn't exist.
The underlying problem was me memcmp'ing MemoryRegionSections even though they had padding in.
(Discovered while getting virtiofs working on aarch)
Dave
v2
Split 1st patch and fix spelling [Philippe's review]
Dr. David Alan Gilbert (3):
memory: Align MemoryRegionSections fields
memory: Provide an equality function for MemoryRegionSections
vhost: Fix memory region section comparison
hw/virtio/vhost.c | 9 +++++++-- include/exec/memory.h | 14 +++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-)
Signature · 1 line
2.21.0
PATCH v2 1/3 memory: Align MemoryRegionSections fields
From: "Dr. David Alan Gilbert" <[email protected]>
MemoryRegionSection includes an Int128 'size' field; on some platforms the compiler causes an alignment of this to a 128bit boundary, leaving 8 bytes of dead space. This deadspace can be filled with junk.
Move the size field to the top avoiding unnecessary alignment.
--- include/exec/memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/memory.h +1 -1
@@ -487,10 +487,10 @@ static inline FlatView *address_space_to_flatview(AddressSpace *as)* @nonvolatile: this section is non-volatile */ struct MemoryRegionSection { +Int128 size;MemoryRegion *mr;FlatView *fv;hwaddr offset_within_region; -Int128 size;hwaddr offset_within_address_space;bool readonly;bool nonvolatile;
Signature · 1 line
2.21.0
PATCH v2 2/3 memory: Provide an equality function for MemoryRegionSections
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Provide a comparison function that checks all the fields are the same.
--- include/exec/memory.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/exec/memory.h +12 -0
@@ -496,6 +496,18 @@ struct MemoryRegionSection {bool nonvolatile; }; +static inline bool MemoryRegionSection_eq (MemoryRegionSection *a, +MemoryRegionSection *b) +{ +return a->mr == b->mr && + a->fv == b->fv && + a->offset_within_region == b->offset_within_region && + a->offset_within_address_space == b->offset_within_address_space && +int128_eq (a->size, b->size) && + a->readonly == b->readonly && + a->nonvolatile == b->nonvolatile; +} +/** * memory_region_init: Initialize a memory region *
Signature · 1 line
2.21.0
PATCH v2 3/3 vhost: Fix memory region section comparison
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Using memcmp to compare structures wasn't safe,
as I found out on ARM when I was getting falce miscompares.
Use the helper function for comparing the MRSs.
--- hw/virtio/vhost.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
hw/virtio/vhost.c +7 -2
@@ -451,8 +451,13 @@ static void vhost_commit(MemoryListener *listener) changed = true; }else {/* Same size, lets check the contents */ - changed = n_old_sections &&memcmp (dev->mem_sections, old_sections, - n_old_sections *sizeof (old_sections[0 ])) !=0 ; +for (int i =0 ; i < n_old_sections; i++) { +if (!MemoryRegionSection_eq (&old_sections[i], + &dev->mem_sections[i])) { + changed = true; +break ; + } + } }trace_vhost_commit (dev->started, changed);
Signature · 1 line
2.21.0
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed build test on s390x host. Please find the details below.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with # HEAD pointing to a commit that has the patches applied on top of "base"
# branch set -e
echo
echo "=== ENV ==="
env
echo
echo "=== PACKAGES ==="
rpm -qa
echo
echo "=== UNAME ==="
uname -a
CC=$HOME/bin/cc
INSTALL=$PWD/install
BUILD=$PWD/build
mkdir -p $BUILD $INSTALL
SRC=$PWD
cd $BUILD
$SRC/configure --cc=$CC --prefix=$INSTALL
make -j4
# XXX: we need reliable clean up
# make check -j4 V=1 make install === TEST SCRIPT END ===
CC xtensa-linux-user/accel/stubs/kvm-stub.o CC xtensa-linux-user/accel/tcg/tcg-runtime.o CC xtensa-linux-user/accel/tcg/tcg-runtime-gvec.o
collect2: error: ld returned 1 exit status make[1]: *** [Makefile:209: qemu-x86_64] Error 1
make: *** [Makefile:472: x86_64-linux-user/all] Error 2
make: *** Waiting for unfinished jobs....
The full log is available at
http://patchew.org/logs/[email protected]/testing.s390x/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]