Skip to contentSkip to conversation

vhost-user: pass message as a pointer to process_message_reply()

PATCH In review Maxime Coquelin 3 participants 5 messages May 24, 2017 – May 25, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vhost-user: pass message as a pointer to process_message_reply()

process_message_reply() was recently updated to get full message content instead of only its request field.

There is no need to copy all the struct content into the stack, so just pass its pointer as const.

Cc Zhiyong Yang <[email protected]>
Fixes 60cd11024f41 ("hw/virtio: fix vhost user fails to startup when MQ")

---
V2:
- Make msg pointer const (Marc-Andre)
- Apply R-b's

 hw/virtio/vhost-user.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/virtio/vhost-user.c +6 -6
index b87a176..dde094a 100644
@@ -162,11 +162,11 @@ fail:
 }
 
 static int process_message_reply(struct vhost_dev *dev,
-                                 VhostUserMsg msg)
+                                 const VhostUserMsg *msg)
 {
     VhostUserMsg msg_reply;
 
-    if ((msg.flags & VHOST_USER_NEED_REPLY_MASK) == 0) {
+    if ((msg->flags & VHOST_USER_NEED_REPLY_MASK) == 0) {
         return 0;
     }
 
@@ -174,10 +174,10 @@ static int process_message_reply(struct vhost_dev *dev,
         return -1;
     }
 
-    if (msg_reply.request != msg.request) {
+    if (msg_reply.request != msg->request) {
         error_report("Received unexpected msg type."
                      "Expected %d received %d",
-                     msg.request, msg_reply.request);
+                     msg->request, msg_reply.request);
         return -1;
     }
 
@@ -324,7 +324,7 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
     }
 
     if (reply_supported) {
-        return process_message_reply(dev, msg);
+        return process_message_reply(dev, &msg);
     }
 
     return 0;
@@ -716,7 +716,7 @@ static int vhost_user_net_set_mtu(struct vhost_dev *dev, uint16_t mtu)
 
     /* If reply_ack supported, slave has to ack specified MTU is valid */
     if (reply_supported) {
-        return process_message_reply(dev, msg);
+        return process_message_reply(dev, &msg);
     }
 
     return 0;
Signature · 1 line
2.9.4
Reviewed-by on v2 1/1
#1 lore raw

Hi

Quoted 12 lines · Maxime Coquelin

process_message_reply() was recently updated to get full message content instead of only its request field.

There is no need to copy all the struct content into the stack, so just pass its pointer as const.

Cc Zhiyong Yang <[email protected]>
Fixes 60cd11024f41 ("hw/virtio: fix vhost user fails to startup when MQ")
Quoted 60 lines

---
V2:
- Make msg pointer const (Marc-Andre)
- Apply R-b's

 hw/virtio/vhost-user.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/virtio/vhost-user.c +5 -5
index b87a176..dde094a 100644
@@ -162,11 +162,11 @@ fail:
 }
 
 static int process_message_reply(struct vhost_dev *dev,
-                                 VhostUserMsg msg)
+                                 const VhostUserMsg *msg)
 {
     VhostUserMsg msg_reply;
 
-    if ((msg.flags & VHOST_USER_NEED_REPLY_MASK) == 0) {
+    if ((msg->flags & VHOST_USER_NEED_REPLY_MASK) == 0) {
         return 0;
     }
 
@@ -174,10 +174,10 @@ static int process_message_reply(struct vhost_dev
 *dev,
         return -1;
     }
 
-    if (msg_reply.request != msg.request) {
+    if (msg_reply.request != msg->request) {
         error_report("Received unexpected msg type."
                      "Expected %d received %d",
-                     msg.request, msg_reply.request);
+                     msg->request, msg_reply.request);
         return -1;
     }
@@ -324,7 +324,7 @@ static int vhost_user_set_mem_table(struct vhost_dev
 *dev,
     }
 
     if (reply_supported) {
-        return process_message_reply(dev, msg);
+        return process_message_reply(dev, &msg);
     }
 
     return 0;
hw/virtio/vhost-user.c +1 -1
@@ -716,7 +716,7 @@ static int vhost_user_net_set_mtu(struct vhost_dev
 *dev, uint16_t mtu)
 
     /* If reply_ack supported, slave has to ack specified MTU is valid */
     if (reply_supported) {
-        return process_message_reply(dev, msg);
+        return process_message_reply(dev, &msg);
     }
 
     return 0;
Quoted 5 lines

--
2.9.4

--

Marc-André Lureau

#2 lore raw
In reply to Maxime Coquelin
Quoted 11 lines · Maxime Coquelin

process_message_reply() was recently updated to get full message content instead of only its request field.

There is no need to copy all the struct content into the stack, so just pass its pointer as const.

Cc Zhiyong Yang <[email protected]>
Fixes 60cd11024f41 ("hw/virtio: fix vhost user fails to startup when MQ")

Why "Fixes"? It's not a bugfix, is it? Passing a pointer is slightly cleaner but it's not a big deal IMHO. I'll apply but would like to get clarification on this tag.

Quoted 59 lines

---
V2:
- Make msg pointer const (Marc-Andre)
- Apply R-b's

 hw/virtio/vhost-user.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/virtio/vhost-user.c +6 -6
index b87a176..dde094a 100644
@@ -162,11 +162,11 @@ fail:
 }
 
 static int process_message_reply(struct vhost_dev *dev,
-                                 VhostUserMsg msg)
+                                 const VhostUserMsg *msg)
 {
     VhostUserMsg msg_reply;
 
-    if ((msg.flags & VHOST_USER_NEED_REPLY_MASK) == 0) {
+    if ((msg->flags & VHOST_USER_NEED_REPLY_MASK) == 0) {
         return 0;
     }
 
@@ -174,10 +174,10 @@ static int process_message_reply(struct vhost_dev *dev,
         return -1;
     }
 
-    if (msg_reply.request != msg.request) {
+    if (msg_reply.request != msg->request) {
         error_report("Received unexpected msg type."
                      "Expected %d received %d",
-                     msg.request, msg_reply.request);
+                     msg->request, msg_reply.request);
         return -1;
     }
 
@@ -324,7 +324,7 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
     }
 
     if (reply_supported) {
-        return process_message_reply(dev, msg);
+        return process_message_reply(dev, &msg);
     }
 
     return 0;
@@ -716,7 +716,7 @@ static int vhost_user_net_set_mtu(struct vhost_dev *dev, uint16_t mtu)
 
     /* If reply_ack supported, slave has to ack specified MTU is valid */
     if (reply_supported) {
-        return process_message_reply(dev, msg);
+        return process_message_reply(dev, &msg);
     }
 
     return 0;
Signature · 1 line
2.9.4
#3 lore raw
Quoted 13 lines · Michael S. Tsirkin
Quoted 11 lines · Maxime Coquelin

process_message_reply() was recently updated to get full message content instead of only its request field.

There is no need to copy all the struct content into the stack, so just pass its pointer as const.

Cc Zhiyong Yang <[email protected]>
Fixes 60cd11024f41 ("hw/virtio: fix vhost user fails to startup when MQ")
Quoted 3 lines

Why "Fixes"? It's not a bugfix, is it? Passing a pointer is slightly cleaner but it's not a big deal IMHO. I'll apply but would like to get clarification on this tag.

Right, this is not a bug fix.
I noticed this while rebasing my Vhost-user IOMMU series, which will call this function much more often than currently. That said, I haven't done any measurements, and I don't believe it will have a noticeable impact.

Feel free to remove the "Fixes:" line when applying, or I can resend if you prefer.

Maxime

#4 lore raw
Quoted 26 lines · Maxime Coquelin
Quoted 13 lines · Michael S. Tsirkin
Quoted 11 lines · Maxime Coquelin

process_message_reply() was recently updated to get full message content instead of only its request field.

There is no need to copy all the struct content into the stack, so just pass its pointer as const.

Cc Zhiyong Yang <[email protected]>
Fixes 60cd11024f41 ("hw/virtio: fix vhost user fails to startup when MQ")
Quoted 3 lines

Why "Fixes"? It's not a bugfix, is it? Passing a pointer is slightly cleaner but it's not a big deal IMHO. I'll apply but would like to get clarification on this tag.

Right, this is not a bug fix.
I noticed this while rebasing my Vhost-user IOMMU series, which will call this function much more often than currently. That said, I haven't done any measurements, and I don't believe it will have a noticeable impact.

Quoted 4 lines

Feel free to remove the "Fixes:" line when applying, or I can resend if you prefer.

Maxime

Applied no need to resend.