From patchwork Fri Jul 20 08:36:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiwei Bie X-Patchwork-Id: 10536209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 626A3602CA for ; Fri, 20 Jul 2018 08:38:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 591A2293ED for ; Fri, 20 Jul 2018 08:38:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DAA7293F2; Fri, 20 Jul 2018 08:38:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EFA5E293ED for ; Fri, 20 Jul 2018 08:38:12 +0000 (UTC) Received: from localhost ([::1]:46947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgQvT-0008Mq-L5 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 20 Jul 2018 04:38:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgQub-0008MY-3t for qemu-devel@nongnu.org; Fri, 20 Jul 2018 04:37:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgQuX-0006n1-WD for qemu-devel@nongnu.org; Fri, 20 Jul 2018 04:37:17 -0400 Received: from mga05.intel.com ([192.55.52.43]:17683) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgQuX-0006mn-Mj for qemu-devel@nongnu.org; Fri, 20 Jul 2018 04:37:13 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jul 2018 01:37:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,378,1526367600"; d="scan'208";a="59229365" Received: from debian.sh.intel.com ([10.67.104.228]) by orsmga006.jf.intel.com with ESMTP; 20 Jul 2018 01:37:08 -0700 From: Tiwei Bie To: mst@redhat.com, jasowang@redhat.com Date: Fri, 20 Jul 2018 16:36:44 +0800 Message-Id: <20180720083644.1431-1-tiwei.bie@intel.com> X-Mailer: git-send-email 2.18.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [PATCH] vhost: check region type before casting 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: Peter Maydell , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Check region type first before casting the memory region to IOMMUMemoryRegion. Otherwise QEMU will abort with below error message when casting non-IOMMU memory region: vhost_iommu_region_add: Object 0x561f28bce4f0 is not an instance of type qemu:iommu-memory-region Fixes: cb1efcf462a2 ("iommu: Add IOMMU index argument to notifier APIs") Cc: Peter Maydell Signed-off-by: Tiwei Bie Reviewed-by: Peter Maydell Acked-by: Jason Wang --- hw/virtio/vhost.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index b129cb9ddd..d4cb5894a8 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -663,12 +663,14 @@ static void vhost_iommu_region_add(MemoryListener *listener, struct vhost_iommu *iommu; Int128 end; int iommu_idx; - IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr); + IOMMUMemoryRegion *iommu_mr; if (!memory_region_is_iommu(section->mr)) { return; } + iommu_mr = IOMMU_MEMORY_REGION(section->mr); + iommu = g_malloc0(sizeof(*iommu)); end = int128_add(int128_make64(section->offset_within_region), section->size);