From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Jay Zhou <jianjay.zhou@huawei.com>
Subject: [Qemu-devel] [PATCH] vhost-user: avoid misaligned access
Date: Fri, 16 Mar 2018 20:20:21 +0200 [thread overview]
Message-ID: <1521224390-425343-1-git-send-email-mst@redhat.com> (raw)
We can't pass a pointer to memory field directly since
it's within a packed structure, so isn't aligned.
Pass a pointer on stack and copy.
Fixes: 30c4cc7 ("vhost: used_memslots refactoring")
Cc: Jay Zhou <jianjay.zhou@huawei.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
I had to apply this to fix make check errors with clang.
Pls review, test and ack.
Thanks!
hw/virtio/vhost-user.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index c12fdd9..a44ee7f 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -396,6 +396,7 @@ static int vhost_user_set_mem_table_postcopy(struct vhost_dev *dev,
bool reply_supported = virtio_has_feature(dev->protocol_features,
VHOST_USER_PROTOCOL_F_REPLY_ACK);
VhostUserMsg msg_reply;
+ VhostUserMemory memory = {};
int region_i, msg_i;
VhostUserMsg msg = {
@@ -407,10 +408,11 @@ static int vhost_user_set_mem_table_postcopy(struct vhost_dev *dev,
msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
}
- if (vhost_user_prepare_msg(dev, &msg.payload.memory, fds) < 0) {
+ if (vhost_user_prepare_msg(dev, &memory, fds) < 0) {
error_report("Failed preparing vhost-user memory table msg");
return -1;
}
+ msg.payload.memory = memory;
fd_num = msg.payload.memory.nregions;
@@ -549,16 +551,19 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
.hdr.request = VHOST_USER_SET_MEM_TABLE,
.hdr.flags = VHOST_USER_VERSION,
};
+ VhostUserMemory memory = {};
if (reply_supported) {
msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
}
- if (vhost_user_prepare_msg(dev, &msg.payload.memory, fds) < 0) {
+ if (vhost_user_prepare_msg(dev, &memory, fds) < 0) {
error_report("Failed preparing vhost-user memory table msg");
return -1;
}
+ msg.payload.memory = memory;
+
fd_num = msg.payload.memory.nregions;
if (!fd_num) {
@@ -1575,8 +1580,11 @@ static void vhost_user_set_used_memslots(struct vhost_dev *dev)
{
int fds[VHOST_MEMORY_MAX_NREGIONS];
VhostUserMsg msg;
+ VhostUserMemory memory = {};
+
+ vhost_user_prepare_msg(dev, &memory, fds);
- vhost_user_prepare_msg(dev, &msg.payload.memory, fds);
+ msg.payload.memory = memory;
}
const VhostOps user_ops = {
--
MST
next reply other threads:[~2018-03-16 18:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-16 18:20 Michael S. Tsirkin [this message]
2018-03-20 2:01 ` [Qemu-devel] [PATCH] vhost-user: avoid misaligned access Zhoujian (jay)
2018-03-20 2:36 ` Michael S. Tsirkin
2018-03-20 7:05 ` Igor Mammedov
2018-03-20 11:55 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1521224390-425343-1-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=jianjay.zhou@huawei.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).