From patchwork Wed Jun 1 16:51:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 12867066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7D90C433EF for ; Wed, 1 Jun 2022 16:52:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348736AbiFAQwx (ORCPT ); Wed, 1 Jun 2022 12:52:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240328AbiFAQwv (ORCPT ); Wed, 1 Jun 2022 12:52:51 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 562843336E for ; Wed, 1 Jun 2022 09:52:46 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 220C61063; Wed, 1 Jun 2022 09:52:46 -0700 (PDT) Received: from donnerap.arm.com (donnerap.cambridge.arm.com [10.1.197.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7227D3F66F; Wed, 1 Jun 2022 09:52:45 -0700 (PDT) From: Andre Przywara To: Will Deacon , Julien Thierry Cc: Alexandru Elisei , kvm@vger.kernel.org Subject: [PATCH kvmtool 1/4] virtio/mmio: avoid unaligned accesses Date: Wed, 1 Jun 2022 17:51:35 +0100 Message-Id: <20220601165138.3135246-2-andre.przywara@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601165138.3135246-1-andre.przywara@arm.com> References: <20220601165138.3135246-1-andre.przywara@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The virtio-mmio code is using unaligned accesses, to its struct virtio_mmio, as revealed by -fsanitize=undefined. A closer inspection reveals that this is due to a misplaced u8 member in struct virtio_mmio, and it inheriting the "packed" attribute from struct virtio_mmio_hdr. The simplest fix for the issue is to just move the "u8 irq" member to the end, so that even with the "packed" attribute in effect, the other members stay all naturally aligned. Signed-off-by: Andre Przywara --- include/kvm/virtio-mmio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/kvm/virtio-mmio.h b/include/kvm/virtio-mmio.h index 6bc50bd1..13dcccb6 100644 --- a/include/kvm/virtio-mmio.h +++ b/include/kvm/virtio-mmio.h @@ -45,10 +45,10 @@ struct virtio_mmio { u32 addr; void *dev; struct kvm *kvm; - u8 irq; struct virtio_mmio_hdr hdr; struct device_header dev_hdr; struct virtio_mmio_ioevent_param ioeventfds[VIRTIO_MMIO_MAX_VQ]; + u8 irq; }; int virtio_mmio_signal_vq(struct kvm *kvm, struct virtio_device *vdev, u32 vq);