On Wed, 5 Oct 2016 09:34:05 +0200 Greg Kurz wrote: > On Wed, 5 Oct 2016 12:14:05 +1100 > David Gibson wrote: > [...] > You convinced me. The tswaps in qtest.c are toxic and should be removed. > > Thanks for the clarification. > Rewind. Cedric and I spent the whole day thinking about that, based on Peter's inputs. The conclusion is: the qtest accelerator replaces the real world CPU and and the test program simulates what the CPU actually does when running the guest driver code in a specific situation. If the guest driver performs a store to the device, and the CPU and device have different endianness, cpu_to_xxYY() in the driver code boils down to bswapYY(). Doing things like writel(cpu_to_beYY()) in the test program is thus wrong since it involves the host endianness, and the test program no longer simulates what the real CPU would do. The test program must hence do writel(bswapYY()) and send that to qtest. If the host endianness differs from the simulated CPU, the value is in wrong order and must be byteswapped before being handed over to the memory layer. This explains why qtest calls tswapYY() before cpu_physical_memory_write(). Cheers. -- Greg