From patchwork Sun May 11 17:13:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvise Rigo X-Patchwork-Id: 347803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 6A49114007E for ; Mon, 12 May 2014 03:14:30 +1000 (EST) Received: from localhost ([::1]:33734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjXKW-0008Mo-1v for incoming@patchwork.ozlabs.org; Sun, 11 May 2014 13:14:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjXJv-0007ZE-Or for qemu-devel@nongnu.org; Sun, 11 May 2014 13:13:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WjXJp-0005XC-L5 for qemu-devel@nongnu.org; Sun, 11 May 2014 13:13:51 -0400 Received: from mail-wg0-f49.google.com ([74.125.82.49]:38666) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjXJp-0005X7-G4 for qemu-devel@nongnu.org; Sun, 11 May 2014 13:13:45 -0400 Received: by mail-wg0-f49.google.com with SMTP id m15so6032492wgh.32 for ; Sun, 11 May 2014 10:13:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b6v0Xc4Lk0OnbKHNcYsDv/VsNVlHv2SKxEurwh1Km0g=; b=JUSsq3kNtuW6PRsHw7XxSUspkjLzoExUO2L7T4XlC+u9rXTma6PgUdvxFPnUeFHwGr RGS3deQgyXPfj8VuS/+xW4NWe3PUhdQWG3dtECbbsY1xAoOiTjGbUINN0B2xO5WaVyRF ZsnzsyHOz4eE+L/6vF09agJge/CnwdvXgHQO6B9DynERnO1j0CuY/KBq03LzJxWVLLDz n2MUuOb/4S81kKk75/5+WGB0JYkiAae3fEgl2wqyGDjxPm1CiIQTUl+3AXbDohUOCicu ZMSwhiee20XmX4RRaYNmdMGSnrFEL0UiM+0xjO52JRcdPfZ/qUjADmFYkuyo/6zgwwZ4 iVcg== X-Gm-Message-State: ALoCoQlvQG0ONEl2IHdv6noqVxz3j+/ZVB4WFdDFmUm5EXOodn/pHQHChaSsC6uppdhssUin0GFL X-Received: by 10.180.93.163 with SMTP id cv3mr12106826wib.3.1399828424884; Sun, 11 May 2014 10:13:44 -0700 (PDT) Received: from localhost.localdomain (AGrenoble-651-1-595-48.w90-42.abo.wanadoo.fr. [90.42.235.48]) by mx.google.com with ESMTPSA id fq2sm11326154wib.2.2014.05.11.10.13.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 May 2014 10:13:43 -0700 (PDT) From: Alvise Rigo To: qemu-devel@nongnu.org, a.motakis@virtualopensystems.com, eric.auger@st.com, kim.phillips@linaro.org Date: Sun, 11 May 2014 19:13:32 +0200 Message-Id: <1399828415-13007-2-git-send-email-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1399828415-13007-1-git-send-email-a.rigo@virtualopensystems.com> References: <1399828415-13007-1-git-send-email-a.rigo@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.49 Cc: Andrew Jones , Alexey Kardashevskiy , Michael Tokarev , Alvise Rigo , Alex Williamson , Paolo Bonzini , tech@virtualopensystems.com Subject: [Qemu-devel] [RFC v2 1/4] Add EXEC_FLAG to VFIO DMA mappings 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 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 +++++++++ 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 9d1f723..a805c5d 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -107,6 +107,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 @@ -352,6 +357,10 @@ static int vfio_connect_container(VFIOGroup *group) return -errno; } + 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/hw/vfio/vfio-common.h b/hw/vfio/vfio-common.h index 21148ef..1abbd1a 100644 --- a/hw/vfio/vfio-common.h +++ b/hw/vfio/vfio-common.h @@ -35,6 +35,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(, VFIOGroup) group_list; diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 17c58e0..95a02c5 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -24,6 +24,7 @@ #define VFIO_TYPE1_IOMMU 1 #define VFIO_SPAPR_TCE_IOMMU 2 +#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 @@ -392,6 +393,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) */