From patchwork Tue Nov 24 07:48:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Fedin X-Patchwork-Id: 7688051 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 30C4BBF90C for ; Tue, 24 Nov 2015 07:48:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6CA05207B4 for ; Tue, 24 Nov 2015 07:48:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 84231207D2 for ; Tue, 24 Nov 2015 07:48:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752746AbbKXHsr (ORCPT ); Tue, 24 Nov 2015 02:48:47 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:46106 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752161AbbKXHsp (ORCPT ); Tue, 24 Nov 2015 02:48:45 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NYB00CC27169R30@mailout2.w1.samsung.com> for kvm@vger.kernel.org; Tue, 24 Nov 2015 07:48:42 +0000 (GMT) X-AuditID: cbfec7f4-f79026d00000418a-89-5654165a4220 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id CF.5A.16778.A5614565; Tue, 24 Nov 2015 07:48:42 +0000 (GMT) Received: from fedinw7x64.rnd.samsung.ru ([106.109.131.169]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NYB00IUT70MMX40@eusync4.samsung.com>; Tue, 24 Nov 2015 07:48:42 +0000 (GMT) From: Pavel Fedin To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Alex Williamson , Marc Zyngier , Thomas Gleixner , Jason Cooper , Manish Jaggi Subject: [PATCH 1/3] vfio: Introduce map and unmap operations Date: Tue, 24 Nov 2015 10:48:19 +0300 Message-id: <03cd37db6ae711fd6c94d59bf3b76efa726c7cda.1448350806.git.p.fedin@samsung.com> X-Mailer: git-send-email 2.4.4 In-reply-to: References: In-reply-to: References: X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKLMWRmVeSWpSXmKPExsVy+t/xa7pRYiFhBp1HDSy+/e9hs2hccpnF Ys7UQouPp46zW/y984/N4mvTVzaLzZumMjuwe6yZt4bRY8OJflaPhgPnWTzenTvH7nF+0xpm j/f7rrJ5fN4kF8AexWWTkpqTWZZapG+XwJVxctpV9oIVQhULZs5lamDs5+9i5OSQEDCRWLpq ISOELSZx4d56ti5GLg4hgaWMEm8fzgVLCAm0MUlcXFcAYrMJqEuc/vqBBcQWETCVOHexnRGk gVngHKPE/lWbmUESwgK2Egtn32cDsVkEVCU+nbsNNohXIFpi35SJ7BDb5CSuXJ8OVsMpYC7R v+YMC8QyM4lzM9uZcYlPYORfwMiwilE0tTS5oDgpPddQrzgxt7g0L10vOT93EyMkML/sYFx8 zOoQowAHoxIP74yi4DAh1sSy4srcQ4wSHMxKIrzLXwGFeFMSK6tSi/Lji0pzUosPMUpzsCiJ 887d9T5ESCA9sSQ1OzW1ILUIJsvEwSnVwMgrVr/5Ise2ssaLN9ZtPTBBw+/Wk0hJk4a1bT/c 9zT8NOJz+xD8nTFCo/lQ+3+1ZOlnQk3Pqp/FORwI/5sVah3DxDtr+kURr/DnVs6tTltnMM3X N7ab1jBZJ3qJovfJA9eaX+x8qWHZaCzo+kzg6o2XdxZn685N4Ci67bxbbVpA0mnH39HXfJVY ijMSDbWYi4oTAavZzhNIAgAA Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 These new functions allow direct mapping and unmapping of addresses on the given IOMMU. They will be used for mapping MSI hardware. Signed-off-by: Pavel Fedin --- drivers/vfio/vfio_iommu_type1.c | 29 +++++++++++++++++++++++++++++ include/linux/vfio.h | 4 +++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 59d47cb..17506eb 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -558,6 +558,33 @@ unwind: return ret; } +static int vfio_iommu_type1_map(void *iommu_data, dma_addr_t iova, + phys_addr_t paddr, long npage, int prot) +{ + struct vfio_iommu *iommu = iommu_data; + int ret; + + mutex_lock(&iommu->lock); + ret = vfio_iommu_map(iommu, iova, paddr >> PAGE_SHIFT, npage, prot); + mutex_unlock(&iommu->lock); + + return ret; +} + +static void vfio_iommu_type1_unmap(void *iommu_data, dma_addr_t iova, + long npage) +{ + struct vfio_iommu *iommu = iommu_data; + struct vfio_domain *d; + + mutex_lock(&iommu->lock); + + list_for_each_entry_reverse(d, &iommu->domain_list, next) + iommu_unmap(d->domain, iova, npage << PAGE_SHIFT); + + mutex_unlock(&iommu->lock); +} + static int vfio_dma_do_map(struct vfio_iommu *iommu, struct vfio_iommu_type1_dma_map *map) { @@ -1046,6 +1073,8 @@ static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = { .ioctl = vfio_iommu_type1_ioctl, .attach_group = vfio_iommu_type1_attach_group, .detach_group = vfio_iommu_type1_detach_group, + .map = vfio_iommu_type1_map, + .unmap = vfio_iommu_type1_unmap, }; static int __init vfio_iommu_type1_init(void) diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 610a86a..061038a 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -75,7 +75,9 @@ struct vfio_iommu_driver_ops { struct iommu_group *group); void (*detach_group)(void *iommu_data, struct iommu_group *group); - + int (*map)(void *iommu_data, dma_addr_t iova, + phys_addr_t paddr, long npage, int prot); + void (*unmap)(void *iommu_data, dma_addr_t iova, long npage); }; extern int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);