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

tests/tcg: better detect truncated reads

If we've truncated a wider read we can detect the condition earlier by
looking at the number of zeros we've read. So we don't trip up on
cases where we have written zeros to the start of the buffer we also
ensure we only start each offset read from the right address.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

+31 -5
+31 -5
tests/tcg/multiarch/system/memory.c
··· 208 208 209 209 for (i = 0; i < max; i++) { 210 210 uint8_t b1, b2, b3, b4; 211 + int zeros = 0; 211 212 word = *ptr++; 212 213 213 214 b1 = word >> 24 & 0xff; ··· 215 216 b3 = word >> 8 & 0xff; 216 217 b4 = word & 0xff; 217 218 219 + zeros += (b1 == 0 ? 1 : 0); 220 + zeros += (b2 == 0 ? 1 : 0); 221 + zeros += (b3 == 0 ? 1 : 0); 222 + zeros += (b4 == 0 ? 1 : 0); 223 + if (zeros > 1) { 224 + ml_printf("Error @ %p, more zeros than expected: %d, %d, %d, %d", 225 + ptr - 1, b1, b2, b3, b4); 226 + return false; 227 + } 228 + 218 229 if ((b1 < b2 && b1 != 0) || 219 230 (b2 < b3 && b2 != 0) || 220 231 (b3 < b4 && b3 != 0)) { ··· 238 249 239 250 for (i = 0; i < max; i++) { 240 251 uint8_t b1, b2, b3, b4, b5, b6, b7, b8; 252 + int zeros = 0; 241 253 word = *ptr++; 242 254 243 255 b1 = ((uint64_t) (word >> 56)) & 0xff; ··· 249 261 b7 = (word >> 8) & 0xff; 250 262 b8 = (word >> 0) & 0xff; 251 263 264 + zeros += (b1 == 0 ? 1 : 0); 265 + zeros += (b2 == 0 ? 1 : 0); 266 + zeros += (b3 == 0 ? 1 : 0); 267 + zeros += (b4 == 0 ? 1 : 0); 268 + zeros += (b5 == 0 ? 1 : 0); 269 + zeros += (b6 == 0 ? 1 : 0); 270 + zeros += (b7 == 0 ? 1 : 0); 271 + zeros += (b8 == 0 ? 1 : 0); 272 + if (zeros > 1) { 273 + ml_printf("Error @ %p, more zeros than expected: %d, %d, %d, %d, %d, %d, %d, %d", 274 + ptr - 1, b1, b2, b3, b4, b5, b6, b7, b8); 275 + return false; 276 + } 277 + 252 278 if ((b1 < b2 && b1 != 0) || 253 279 (b2 < b3 && b2 != 0) || 254 280 (b3 < b4 && b3 != 0) || ··· 272 298 read_test_data_u32, 273 299 read_test_data_u64 }; 274 300 275 - bool do_unsigned_reads(void) 301 + bool do_unsigned_reads(int start_off) 276 302 { 277 303 int i; 278 304 bool ok = true; ··· 280 306 for (i = 0; i < ARRAY_SIZE(read_ufns) && ok; i++) { 281 307 #if CHECK_UNALIGNED 282 308 int off; 283 - for (off = 0; off < 8 && ok; off++) { 309 + for (off = start_off; off < 8 && ok; off++) { 284 310 ok = read_ufns[i](off); 285 311 } 286 312 #else 287 - ok = read_ufns[i](0); 313 + ok = read_ufns[i](start_off); 288 314 #endif 289 315 } 290 316 ··· 298 324 int i; 299 325 for (i = 0; i < 8 && ok; i++) { 300 326 fn(i); 301 - ok = do_unsigned_reads(); 327 + ok = do_unsigned_reads(i); 302 328 } 303 329 #else 304 330 fn(0); 305 - return do_unsigned_reads(); 331 + return do_unsigned_reads(0); 306 332 #endif 307 333 } 308 334