qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

coccinelle: new inplace-byteswaps.cocci to remove inplace-byteswapping calls

Add a new Coccinelle script which replaces uses of the inplace
byteswapping functions *_to_cpus() and cpu_to_*s() with their
not-in-place equivalents. This is useful for where the swapping
is done on members of a packed struct -- taking the address
of the member to pass it to an inplace function is undefined
behaviour in C.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20181009181612.10633-1-peter.maydell@linaro.org

+65
+65
scripts/coccinelle/inplace-byteswaps.cocci
··· 1 + // Replace uses of in-place byteswapping functions with calls to the 2 + // equivalent not-in-place functions. This is necessary to avoid 3 + // undefined behaviour if the expression being swapped is a field in a 4 + // packed struct. 5 + 6 + @@ 7 + expression E; 8 + @@ 9 + -be16_to_cpus(&E); 10 + +E = be16_to_cpu(E); 11 + @@ 12 + expression E; 13 + @@ 14 + -be32_to_cpus(&E); 15 + +E = be32_to_cpu(E); 16 + @@ 17 + expression E; 18 + @@ 19 + -be64_to_cpus(&E); 20 + +E = be64_to_cpu(E); 21 + @@ 22 + expression E; 23 + @@ 24 + -cpu_to_be16s(&E); 25 + +E = cpu_to_be16(E); 26 + @@ 27 + expression E; 28 + @@ 29 + -cpu_to_be32s(&E); 30 + +E = cpu_to_be32(E); 31 + @@ 32 + expression E; 33 + @@ 34 + -cpu_to_be64s(&E); 35 + +E = cpu_to_be64(E); 36 + @@ 37 + expression E; 38 + @@ 39 + -le16_to_cpus(&E); 40 + +E = le16_to_cpu(E); 41 + @@ 42 + expression E; 43 + @@ 44 + -le32_to_cpus(&E); 45 + +E = le32_to_cpu(E); 46 + @@ 47 + expression E; 48 + @@ 49 + -le64_to_cpus(&E); 50 + +E = le64_to_cpu(E); 51 + @@ 52 + expression E; 53 + @@ 54 + -cpu_to_le16s(&E); 55 + +E = cpu_to_le16(E); 56 + @@ 57 + expression E; 58 + @@ 59 + -cpu_to_le32s(&E); 60 + +E = cpu_to_le32(E); 61 + @@ 62 + expression E; 63 + @@ 64 + -cpu_to_le64s(&E); 65 + +E = cpu_to_le64(E);