<div dir="auto">Depends on architecture. On i386 and amd64 there is zero impact for exams.<div dir="auto"><br></div><div dir="auto">32 bit arm would be impacted, but considering dbus is not heavily used by anything in the first place, and there is 1000 other instructions around, the impact would be extremely small if any. Most likely it will be actually faster.</div><div dir="auto"><br></div><div dir="auto">I do see real world misaligned reads on alpha, and I did trace it to mentioned function . Thus the bug.</div><div dir="auto"><br></div><div dir="auto">If there is some other code in dbus that ensures pointers are aligned, then something is not quite working, because CPU complains on alpha to me.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 18 Jul 2019, 19:17 Simon McVittie, <<a href="mailto:smcv@debian.org" target="_blank" rel="noreferrer">smcv@debian.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Control: severity -1 normal<br>
Control: tags -1 + upstream<br>
<br>
On Thu, 18 Jul 2019 at 17:15:09 +0200, Witold Baryluk wrote:<br>
> In this case, value is often not aligned to native uint64 alignement,<br>
> and dereference does lead to a CPU trap on some architectures<br>
> and some compilers.<br>
<br>
Do you have evidence of libdbus accessing misaligned pointers in real use,<br>
or is this concern based on compiler warnings or reading the source code?<br>
<br>
libdbus goes to considerable lengths to ensure that marshalling always<br>
acts on correctly aligned pointers, despite appearances to the contrary:<br>
the message wire-format is designed to ensure that all values are<br>
naturally-aligned, and commit 6327adafe20603fce3c7507e20f300e07398b517<br>
(first released in dbus 1.4.x in 2011) asserts at compile time that this<br>
is sufficient to give them their correct alignment.<br>
<br>
However, it is not immediately obvious to a reader or to the compiler<br>
that this is the case, and in particular you'll get compiler warnings<br>
when building dbus on strongly-aligned architectures like ARM.<br>
<br>
> I suggest to change all dereferences to types bigger than 1 byte to<br>
> use memcpy<br>
<br>
I have been meaning to try this for a while (git says my work-in-progress<br>
branch is from 2015), but this is hampered by not having a realistic<br>
benchmark that can assess whether it improves or reduces performance.<br>
<br>
> On 32-bit arm, it will pesimize correctly to read and combined aligned<br>
> reads (which is in total 3 extra instructions). On architectures like<br>
> 32-bit ARM, and Alpha (64-bit), MIPS (both 32 and 64 bit), 32-bit PowerPC<br>
> the resulting code with memcpy will in fact be faster than current code,<br>
> because it will not trap and emulate read in kernel, which is very slow.<br>
<br>
If the current code is, in fact, always accessing correctly-aligned<br>
pointers (so the trap-and-emulate case is something that could in theory<br>
happen, and would be slow if it happened, but is never actually reached),<br>
how much of a performance hit is expected for using memcpy and having the<br>
pessimized code generated?<br>
<br>
smcv<br>
</blockquote></div>