[Qemu-devel] [PATCH 09/71] vhost-user-test: support VHOST_USER_PROTOCOL_F_CROSS_ENDIAN

Paolo Bonzini posted 71 patches 7 years, 2 months ago
[Qemu-devel] [PATCH 09/71] vhost-user-test: support VHOST_USER_PROTOCOL_F_CROSS_ENDIAN
Posted by Paolo Bonzini 7 years, 2 months ago
This will be useful to run the qtest for ppc64 targets on (for example)
x86_64 hosts.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/vhost-user-test.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index 6a805e6..82fc6c5 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -51,6 +51,7 @@
 #define VHOST_USER_F_PROTOCOL_FEATURES 30
 #define VHOST_USER_PROTOCOL_F_MQ 0
 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
+#define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN   6
 
 #define VHOST_LOG_PAGE 0x1000
 
@@ -251,7 +252,7 @@ static void wait_for_fds(TestServer *s)
 
 static void read_guest_mem_server(TestServer *s)
 {
-    uint32_t *guest_mem;
+    uint8_t *guest_mem;
     int i, j;
     size_t size;
 
@@ -278,8 +279,8 @@ static void read_guest_mem_server(TestServer *s)
         g_assert(guest_mem != MAP_FAILED);
         guest_mem += (s->memory.regions[i].mmap_offset / sizeof(*guest_mem));
 
-        for (j = 0; j < 256; j++) {
-            uint32_t a = readl(s->memory.regions[i].guest_phys_addr + j*4);
+        for (j = 0; j < 1024; j++) {
+            uint32_t a = readb(s->memory.regions[i].guest_phys_addr + j);
             uint32_t b = guest_mem[j];
 
             g_assert_cmpint(a, ==, b);
@@ -367,6 +368,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
         msg.flags |= VHOST_USER_REPLY_MASK;
         msg.size = sizeof(m.payload.u64);
         msg.payload.u64 = 1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD;
+        msg.payload.u64 |= 1 << VHOST_USER_PROTOCOL_F_CROSS_ENDIAN;
         if (s->queues > 1) {
             msg.payload.u64 |= 1 << VHOST_USER_PROTOCOL_F_MQ;
         }
-- 
1.8.3.1



Re: [Qemu-devel] [PATCH 09/71] vhost-user-test: support VHOST_USER_PROTOCOL_F_CROSS_ENDIAN
Posted by Thomas Huth 7 years, 2 months ago
On 2018-12-03 16:32, Paolo Bonzini wrote:
> This will be useful to run the qtest for ppc64 targets on (for example)
> x86_64 hosts.
> 
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tests/vhost-user-test.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
> index 6a805e6..82fc6c5 100644
> --- a/tests/vhost-user-test.c
> +++ b/tests/vhost-user-test.c
> @@ -51,6 +51,7 @@
>  #define VHOST_USER_F_PROTOCOL_FEATURES 30
>  #define VHOST_USER_PROTOCOL_F_MQ 0
>  #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
> +#define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN   6
>  
>  #define VHOST_LOG_PAGE 0x1000
>  
> @@ -251,7 +252,7 @@ static void wait_for_fds(TestServer *s)
>  
>  static void read_guest_mem_server(TestServer *s)
>  {
> -    uint32_t *guest_mem;
> +    uint8_t *guest_mem;
>      int i, j;
>      size_t size;
>  
> @@ -278,8 +279,8 @@ static void read_guest_mem_server(TestServer *s)
>          g_assert(guest_mem != MAP_FAILED);
>          guest_mem += (s->memory.regions[i].mmap_offset / sizeof(*guest_mem));
>  
> -        for (j = 0; j < 256; j++) {
> -            uint32_t a = readl(s->memory.regions[i].guest_phys_addr + j*4);
> +        for (j = 0; j < 1024; j++) {
> +            uint32_t a = readb(s->memory.regions[i].guest_phys_addr + j);

Can't you simply use memread() intead?

 Thomas

Re: [Qemu-devel] [PATCH 09/71] vhost-user-test: support VHOST_USER_PROTOCOL_F_CROSS_ENDIAN
Posted by Paolo Bonzini 7 years, 2 months ago
On 06/12/18 17:15, Thomas Huth wrote:
>>  
>> -        for (j = 0; j < 256; j++) {
>> -            uint32_t a = readl(s->memory.regions[i].guest_phys_addr + j*4);
>> +        for (j = 0; j < 1024; j++) {
>> +            uint32_t a = readb(s->memory.regions[i].guest_phys_addr + j);
> Can't you simply use memread() intead?

Yes, I guess I could do memread + memcmp, but I wanted to change the
code as little as possible here.

Paolo

Re: [Qemu-devel] [PATCH 09/71] vhost-user-test: support VHOST_USER_PROTOCOL_F_CROSS_ENDIAN
Posted by Thomas Huth 7 years, 2 months ago
On 2018-12-06 21:06, Paolo Bonzini wrote:
> On 06/12/18 17:15, Thomas Huth wrote:
>>>  
>>> -        for (j = 0; j < 256; j++) {
>>> -            uint32_t a = readl(s->memory.regions[i].guest_phys_addr + j*4);
>>> +        for (j = 0; j < 1024; j++) {
>>> +            uint32_t a = readb(s->memory.regions[i].guest_phys_addr + j);
>> Can't you simply use memread() intead?
> 
> Yes, I guess I could do memread + memcmp, but I wanted to change the
> code as little as possible here.

OK, fair.

Reviewed-by: Thomas Huth <thuth@redhat.com>