From patchwork Wed Mar 4 16:07:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 5937491 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C0977BF440 for ; Wed, 4 Mar 2015 16:09:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D69FC20295 for ; Wed, 4 Mar 2015 16:09:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C204220272 for ; Wed, 4 Mar 2015 16:09:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759199AbbCDQIw (ORCPT ); Wed, 4 Mar 2015 11:08:52 -0500 Received: from mail-we0-f171.google.com ([74.125.82.171]:45169 "EHLO mail-we0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759170AbbCDQIu (ORCPT ); Wed, 4 Mar 2015 11:08:50 -0500 Received: by wesp10 with SMTP id p10so45145937wes.12 for ; Wed, 04 Mar 2015 08:08:49 -0800 (PST) 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=8BEJFRR0gv0rX37QdEY+YjBoeHAxcXXR07WvaIU8B44=; b=CUBLpfqseDrV/dme6IXyJTRpJ1zNRLsYN0rORnqaqYka0QabpAepZbcnxzqAgx9PLz kE74chjp7vlnsQ0p1GgMEfljJIv99sLGZEVQkGdx5j7mMJDghgO8CqyGhU4+ZQsHKLEc 1onvHXLbPKhesy+a3sSj0ysxz5a1y3+HMHO7CFoce2Xazy25YYbEUr2bri0phQS4lURN at6LG9iadr5MdRH2BiS5Kbbc6EIhnUEN3MZC6R8Dnqo4iXS3jREKZr8s93AfTqcUCqYK aFuzFSjYuYNfe86iQJOkppSC6OXZLN8AKevXT0MJ0X2JOF6o1XiZY1omWPXBg5aEzsVw jncg== X-Gm-Message-State: ALoCoQlGecehG3sMJCeKYsLw9e9uv5qCtN8j2dfLt4TCtwb2aNv5+/hdQnKIp8B8WMrdXZYQeX6J X-Received: by 10.194.90.210 with SMTP id by18mr9287127wjb.80.1425485329766; Wed, 04 Mar 2015 08:08:49 -0800 (PST) Received: from localhost (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by mx.google.com with ESMTPSA id hs7sm25809071wib.4.2015.03.04.08.08.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Mar 2015 08:08:48 -0800 (PST) From: Baptiste Reynal To: iommu@lists.linux-foundation.org, kvmarm@lists.cs.columbia.edu Cc: eric.auger@linaro.org, alex.williamson@redhat.com, tech@virtualopensystems.com, Antonios Motakis , Baptiste Reynal , kvm@vger.kernel.org (open list:VFIO DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 4/4] vfio: type1: implement the VFIO_DMA_MAP_FLAG_NOEXEC flag Date: Wed, 4 Mar 2015 17:07:54 +0100 Message-Id: <1425485274-5709-5-git-send-email-b.reynal@virtualopensystems.com> X-Mailer: git-send-email 2.3.1 In-Reply-To: <1425485274-5709-1-git-send-email-b.reynal@virtualopensystems.com> References: <1425485274-5709-1-git-send-email-b.reynal@virtualopensystems.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Antonios Motakis Some IOMMU drivers, such as the ARM SMMU driver, make available the IOMMU_NOEXEC flag to set the page tables for a device as XN (execute never). This affects devices such as the ARM PL330 DMA Controller, which respects this flag and will refuse to fetch DMA instructions from memory where the XN flag has been set. The flag can be used only if all IOMMU domains behind the container support the IOMMU_NOEXEC flag. Also, if any mappings are created with the flag, any new domains with devices will have to support it as well. Signed-off-by: Antonios Motakis Signed-off-by: Baptiste Reynal --- drivers/vfio/vfio_iommu_type1.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index a5847e8..ec313e5 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -591,6 +591,12 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu, if (!prot || !size || (size | iova | vaddr) & mask) return -EINVAL; + if (map->flags & VFIO_DMA_MAP_FLAG_NOEXEC) { + if (!vfio_domains_have_iommu_cap(iommu, IOMMU_CAP_NOEXEC)) + return -EINVAL; + prot |= IOMMU_NOEXEC; + } + /* Don't allow IOVA or virtual address wrap */ if (iova + size - 1 < iova || vaddr + size - 1 < vaddr) return -EINVAL; @@ -672,11 +678,20 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, for (; n; n = rb_next(n)) { struct vfio_dma *dma; + const struct iommu_ops *ops = domain->domain->ops; dma_addr_t iova; dma = rb_entry(n, struct vfio_dma, node); iova = dma->iova; + /* + * if any of the mappings to be replayed has the NOEXEC flag + * set, then the new iommu domain must support it + */ + if ((dma->prot & IOMMU_NOEXEC) && + !(ops->capable(IOMMU_CAP_NOEXEC))) + return -EINVAL; + while (iova < dma->iova + dma->size) { phys_addr_t phys = iommu_iova_to_phys(d->domain, iova); size_t size; @@ -969,6 +984,11 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, return 0; return vfio_domains_have_iommu_cap(iommu, IOMMU_CAP_CACHE_COHERENCY); + case VFIO_DMA_NOEXEC_IOMMU: + if (!iommu) + return 0; + return vfio_domains_have_iommu_cap(iommu, + IOMMU_CAP_NOEXEC); default: return 0; } @@ -992,7 +1012,8 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, } else if (cmd == VFIO_IOMMU_MAP_DMA) { struct vfio_iommu_type1_dma_map map; uint32_t mask = VFIO_DMA_MAP_FLAG_READ | - VFIO_DMA_MAP_FLAG_WRITE; + VFIO_DMA_MAP_FLAG_WRITE | + VFIO_DMA_MAP_FLAG_NOEXEC; minsz = offsetofend(struct vfio_iommu_type1_dma_map, size);