From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X484d-00079H-DX for qemu-devel@nongnu.org; Mon, 07 Jul 2014 08:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X484V-000624-Nj for qemu-devel@nongnu.org; Mon, 07 Jul 2014 08:31:11 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:54143) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X484V-00061t-Id for qemu-devel@nongnu.org; Mon, 07 Jul 2014 08:31:03 -0400 Received: by mail-wi0-f182.google.com with SMTP id bs8so6773129wib.9 for ; Mon, 07 Jul 2014 05:31:02 -0700 (PDT) From: Eric Auger Date: Mon, 7 Jul 2014 13:27:18 +0100 Message-Id: <1404736043-22900-9-git-send-email-eric.auger@linaro.org> In-Reply-To: <1404736043-22900-1-git-send-email-eric.auger@linaro.org> References: <1404736043-22900-1-git-send-email-eric.auger@linaro.org> Subject: [Qemu-devel] [RFC v4 08/13] hw/vfio/common: Add EXEC_FLAG to VFIO DMA mappings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: eric.auger@st.com, christoffer.dall@linaro.org, qemu-devel@nongnu.org, kim.phillips@freescale.com, a.rigo@virtualopensystems.com Cc: peter.maydell@linaro.org, eric.auger@linaro.org, patches@linaro.org, will.deacon@arm.com, agraf@suse.de, stuart.yoder@freescale.com, Bharat.Bhushan@freescale.com, alex.williamson@redhat.com, a.motakis@virtualopensystems.com, kvmarm@lists.cs.columbia.edu From: Alvise Rigo The flag is mandatory for the ARM SMMU so we always add it if the MMIO handles it. Signed-off-by: Alvise Rigo --- hw/vfio/common.c | 9 +++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index ed93cf3..e22f326 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -233,6 +233,11 @@ static int vfio_dma_map(VFIOContainer *container, hwaddr iova, map.flags |= VFIO_DMA_MAP_FLAG_WRITE; } + /* add exec flag */ + if (container->iommu_data.has_exec_cap) { + map.flags |= VFIO_DMA_MAP_FLAG_EXEC; + } + /* * Try the mapping, if it fails with EBUSY, unmap the region and try * again. This shouldn't be necessary, but we sometimes see it in @@ -688,6 +693,10 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as) goto free_container_exit; } + if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_IOMMU_PROT_EXEC)) { + container->iommu_data.has_exec_cap = true; + } + container->iommu_data.type1.listener = vfio_memory_listener; container->iommu_data.release = vfio_listener_release; diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index d19622b..e670ae3 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -76,6 +76,7 @@ typedef struct VFIOContainer { union { VFIOType1 type1; }; + bool has_exec_cap; /* support of exec capability by the IOMMU */ void (*release)(struct VFIOContainer *); } iommu_data; QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 26c218e..b13f7d3 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -30,6 +30,7 @@ */ #define VFIO_DMA_CC_IOMMU 4 +#define VFIO_IOMMU_PROT_EXEC 5 /* * The IOCTL interface is designed for extensibility by embedding the * structure length (argsz) and flags into structures passed between @@ -398,6 +399,7 @@ struct vfio_iommu_type1_dma_map { __u32 flags; #define VFIO_DMA_MAP_FLAG_READ (1 << 0) /* readable from device */ #define VFIO_DMA_MAP_FLAG_WRITE (1 << 1) /* writable from device */ +#define VFIO_DMA_MAP_FLAG_EXEC (1 << 2) /* executable from device */ __u64 vaddr; /* Process virtual address */ __u64 iova; /* IO virtual address */ __u64 size; /* Size of mapping (bytes) */ -- 1.8.3.2