From patchwork Mon Jul 14 12:09:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 369618 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 151CC140095 for ; Mon, 14 Jul 2014 22:10:40 +1000 (EST) Received: from localhost ([::1]:56990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6f5a-0007Zb-4v for incoming@patchwork.ozlabs.org; Mon, 14 Jul 2014 08:10:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6f52-0007CM-Nk for qemu-devel@nongnu.org; Mon, 14 Jul 2014 08:10:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X6f4t-0006nv-H1 for qemu-devel@nongnu.org; Mon, 14 Jul 2014 08:10:04 -0400 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:41064) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6f4s-0006mx-S1 for qemu-devel@nongnu.org; Mon, 14 Jul 2014 08:09:55 -0400 Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 14 Jul 2014 17:39:51 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp04.in.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 14 Jul 2014 17:39:49 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id C97BAE0053 for ; Mon, 14 Jul 2014 17:41:19 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s6ECBRAv58654930 for ; Mon, 14 Jul 2014 17:41:27 +0530 Received: from d28av01.in.ibm.com (localhost [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s6EC9l81014323 for ; Mon, 14 Jul 2014 17:39:48 +0530 Received: from shangw ([9.192.171.171]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with SMTP id s6EC9jEb014236; Mon, 14 Jul 2014 17:39:46 +0530 Received: by shangw (Postfix, from userid 1000) id 9768B3E0263; Mon, 14 Jul 2014 22:09:44 +1000 (EST) From: Gavin Shan To: qemu-devel@nongnu.org Date: Mon, 14 Jul 2014 22:09:43 +1000 Message-Id: <1405339783-4501-1-git-send-email-gwshan@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.2 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14071412-5564-0000-0000-00000F0CA689 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.4 Cc: aik@ozlabs.ru, alex.williamson@redhat.com, agraf@suse.de, Gavin Shan Subject: [Qemu-devel] [PATCH] sPAPR/IOMMU: Fix TCE entry permission X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The permission of TCE entry should exclude physical base address. Otherwise, unmapping TCE entry can be interpreted to mapping TCE entry wrongly for VFIO devices. Signed-off-by: Gavin Shan Acked-by: Alex Williamson --- hw/misc/vfio.c | 2 +- hw/ppc/spapr_iommu.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index f9426ef..75ccceb 100644 --- a/hw/misc/vfio.c +++ b/hw/misc/vfio.c @@ -2316,7 +2316,7 @@ static void vfio_iommu_map_notify(Notifier *n, void *data) return; } - if (iotlb->perm != IOMMU_NONE) { + if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) { vaddr = memory_region_get_ram_ptr(mr) + xlat; ret = vfio_dma_map(container, iotlb->iova, diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index e603ac1..e223374 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -81,7 +81,7 @@ static IOMMUTLBEntry spapr_tce_translate_iommu(MemoryRegion *iommu, hwaddr addr) ret.iova = addr & page_mask; ret.translated_addr = tce & page_mask; ret.addr_mask = ~page_mask; - ret.perm = tce; + ret.perm = tce & IOMMU_RW; } trace_spapr_iommu_xlate(tcet->liobn, addr, ret.iova, ret.perm, ret.addr_mask); @@ -225,7 +225,7 @@ static target_ulong put_tce_emu(sPAPRTCETable *tcet, target_ulong ioba, entry.iova = ioba & page_mask; entry.translated_addr = tce & page_mask; entry.addr_mask = ~page_mask; - entry.perm = tce; + entry.perm = tce & IOMMU_RW; memory_region_notify_iommu(&tcet->iommu, entry); return H_SUCCESS;