From nobody Sat Oct 25 11:02:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521224502020651.4358525117631; Fri, 16 Mar 2018 11:21:42 -0700 (PDT) Received: from localhost ([::1]:58921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewtz2-00033k-PY for importer@patchew.org; Fri, 16 Mar 2018 14:21:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewty5-0002bc-M8 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 14:20:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewty2-0000JC-4p for qemu-devel@nongnu.org; Fri, 16 Mar 2018 14:20:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45382 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewty1-0000Io-VR for qemu-devel@nongnu.org; Fri, 16 Mar 2018 14:20:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 056F24068040; Fri, 16 Mar 2018 18:20:26 +0000 (UTC) Received: from redhat.com (ovpn-124-13.rdu2.redhat.com [10.10.124.13]) by smtp.corp.redhat.com (Postfix) with SMTP id A57EEDEECA; Fri, 16 Mar 2018 18:20:21 +0000 (UTC) Date: Fri, 16 Mar 2018 20:20:21 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1521224390-425343-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 18:20:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 18:20:27 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] vhost-user: avoid misaligned access X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jay Zhou Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Michael S. Tsirkin --- 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 vho= st_dev *dev, bool reply_supported =3D virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_REPLY_= ACK); VhostUserMsg msg_reply; + VhostUserMemory memory =3D {}; int region_i, msg_i; =20 VhostUserMsg msg =3D { @@ -407,10 +408,11 @@ static int vhost_user_set_mem_table_postcopy(struct v= host_dev *dev, msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; } =20 - 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 =3D memory; =20 fd_num =3D msg.payload.memory.nregions; =20 @@ -549,16 +551,19 @@ static int vhost_user_set_mem_table(struct vhost_dev = *dev, .hdr.request =3D VHOST_USER_SET_MEM_TABLE, .hdr.flags =3D VHOST_USER_VERSION, }; + VhostUserMemory memory =3D {}; =20 if (reply_supported) { msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; } =20 - 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; } =20 + msg.payload.memory =3D memory; + fd_num =3D msg.payload.memory.nregions; =20 if (!fd_num) { @@ -1575,8 +1580,11 @@ static void vhost_user_set_used_memslots(struct vhos= t_dev *dev) { int fds[VHOST_MEMORY_MAX_NREGIONS]; VhostUserMsg msg; + VhostUserMemory memory =3D {}; + + vhost_user_prepare_msg(dev, &memory, fds); =20 - vhost_user_prepare_msg(dev, &msg.payload.memory, fds); + msg.payload.memory =3D memory; } =20 const VhostOps user_ops =3D { --=20 MST