From patchwork Wed Sep 30 14:56:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 7293941 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1D80D9F1D5 for ; Wed, 30 Sep 2015 09:23:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CDE1220687 for ; Wed, 30 Sep 2015 09:23:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B14520648 for ; Wed, 30 Sep 2015 09:23:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753639AbbI3JXZ (ORCPT ); Wed, 30 Sep 2015 05:23:25 -0400 Received: from mail-bn1bn0109.outbound.protection.outlook.com ([157.56.110.109]:36512 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750768AbbI3JXW (ORCPT ); Wed, 30 Sep 2015 05:23:22 -0400 Received: from BLUPR0301CA0016.namprd03.prod.outlook.com (10.162.113.154) by BN3PR0301MB1266.namprd03.prod.outlook.com (10.161.209.146) with Microsoft SMTP Server (TLS) id 15.1.280.20; Wed, 30 Sep 2015 09:23:19 +0000 Received: from BY2FFO11FD018.protection.gbl (2a01:111:f400:7c0c::104) by BLUPR0301CA0016.outlook.office365.com (2a01:111:e400:5259::26) with Microsoft SMTP Server (TLS) id 15.1.286.20 via Frontend Transport; Wed, 30 Sep 2015 09:23:18 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD018.mail.protection.outlook.com (10.1.14.106) with Microsoft SMTP Server (TLS) id 15.1.274.4 via Frontend Transport; Wed, 30 Sep 2015 09:23:18 +0000 Received: from localhost.ap.freescale.net ([10.232.132.243]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t8U9NCDR000590; Wed, 30 Sep 2015 02:23:14 -0700 From: Bharat Bhushan To: , , CC: , , , , , Bharat Bhushan Subject: [RFC PATCH 1/6] vfio: Add interface for add/del reserved iova region Date: Wed, 30 Sep 2015 20:26:24 +0530 Message-ID: <1443624989-24346-1-git-send-email-Bharat.Bhushan@freescale.com> X-Mailer: git-send-email 1.9.3 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD018; 1:5YftYelpUPoKWlDW437r0myNS2CxpSp6Dy1VUy8v++YmXenkMpU5DzhvCmNIFmFwAwN8miOQnc0HwICqLr+9OsnPbQ+NQ4iC848PYdh9cF/QeIFXqNt0j1ksx4pjbIJEIGx92of2Fw5MUATRN6pOb/5zrInQZyZ4Ui1UbofPh0RJFE5CMEvcw327CFsXu1sCY2qlwZTYSF/+VulCmXylFfiXrlbz3POkQvBgRvg5sJ0UwPf5cHADS8f5QdIOqg24sj0+e5qS/Jk8mLezrOUqHKGdi7f/ua+oLrHJY2VzxlI75UJ9aCbesEASmQONJxaVAHHPYqLlp67CbsY3v0Fp6WWlKh3I6pqC2TyqhOx2RCgPTCa5eFBbQark9QrZiA4g3z0097Mx3xvx5v9ESm10bGcO1Vrgg3+GoosPh4QOkK2uRu9kkSYmkBmp7RR3GpNf X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1110001)(1109001)(3190300001)(339900001)(199003)(189002)(81156007)(5003940100001)(97736004)(4001540100001)(86362001)(5001830100001)(2201001)(5001860100001)(92566002)(62966003)(48376002)(85426001)(87936001)(36756003)(5001960100002)(50986999)(107886002)(189998001)(47776003)(5008740100001)(19580395003)(104016004)(5001770100001)(19580405001)(50226001)(77156002)(5001920100001)(11100500001)(76506005)(229853001)(46102003)(77096005)(2171001)(5007970100001)(106466001)(50466002)(6806005)(105606002)(68736005)(64706001)(217873001)(4001430100001)(2101003); DIR:OUT; SFP:1102; SCL:1; SRVR:BN3PR0301MB1266; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1266; 2:n76jE5hLUVZU55TP67hMjR9ri66JxWGEEtzZCA6dsaRkicxJZP+tvA4A86zHsLaNzxqHppo2Xu+1yIPbUGxUTmitTGVTDTU621Dpf0uYTyRsfDhSH9168qekN0at/i79SVVUGiJ/CGJR3ZqhfuuRyJlC9aViTKYMfMgxiN/BwzQ=; 3:m6zbBJIxZ+lBK7gm460AiShVYk6uoYpgqYme7VTN6culeZpZOLoLqpbjCNOepwrT0BiGpVGaN2HM5sGObogKtPAsymvWWXn8vRVTryaon5s71jGWfF1/quBpfqlHLK/d9B0mvOtZ1UgIusN1pCYfWezWU3vGmgUG7zCRL/Rg+a1FrOHinj6w7th14SsETNO7v58sSlYEosJJ91STThFTudsLr4y9ow0VFNtrf/30/mY=; 25:bDDgemSSnS3B8jFgVw8cR5ow1IYMLfuzD39Q3sUbxGaAAlEyWJLAf/6wrZ5C+gY68sIFBtJ00yQ8qZ5xEwXiNuwzv9YPydIm3xrt7pgNrCmfWTjxcSuMeseAascSKgxrVhXdtkCMY5WUjglOzrSODgT6QMt5raRCo0zG6i0IAVWr2AeUa0yTDXovrBcJISx8AIQtnfxiam3Pqdx6YsBm4vUyTYjEcL0cfnxNO3SmuSW9CXXuV/i3Cfh86/F8KhQYWZaln7Am/6w8HmmU1ZgYaA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0301MB1266; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1266; 20:hxezlmbhWRYUjcKtrpvY24qE1iZrFhJhuAKPUme0pRWAQvqT+9044F6NrBd9Fb4NqvuNoWMhgBRzHPx+8okMLjwGLjdjqcFJaIdD9cMn2UsJnSReWxLgMUJ1VXGiBVTGZGGUZv+LkZ6+wvAGsxgf1K5AWHL77kChXILW51pqdS7nVivYZsZDADFhuXNUu6bVllQbYUTCYa6WXQSIVwLi96C2ave/eqHkYQPzU6UaEVWPk0vlUa03Rjol+tBvkX85CA4bW9lOzsjg3SYkCewHBPawxckTwZJF93O/nRSWipa6Lj6tNLEF+/2IoCInASpLeI1Il573wlLIq2vDi/Dw/ZSdHjpCBOzK7G2/fljnblg=; 4:TLozfni//6oRvk+taclNVPZgQh4y+60CPp//RvE8SU32+fNglXz85+s4bl7nJN1HO1s7KQmJTjWUKgT/ueJPZQ4lr4m0/Xd2kPBOhznDnnigb3RbUD6s2txxwjNn2o1dp+zT22/ixBDbu4JmdNyrM/qBuTa2vsjs+Zn++O74aj2es1VPFVqb2xjbLdhgPbGeMqtohzMOO21soQFoVMiPLCAHZTx/XIShfXA/MSFg0iiJExbAmKzXlIw6agKFPORk8gHV8RWQ5VQ0i0TGlVIFUyPp4Dqv/FfE2lDadcJFcd0cXBgeJsl9V9UwiZTZceb7D3UWgc4efHuE4D87NVyNZ7SDkFLt5wTBX1tw/UZOjRg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(3002001); SRVR:BN3PR0301MB1266; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0301MB1266; X-Forefront-PRVS: 071518EF63 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0301MB1266; 23:BoRHqP4ZKH2MPgIaiJs4x+rBg0jbxzRCjFBzQu2?= =?us-ascii?Q?XFgGrQg+S47UgWElvbsdDMXNyjNmaNYm8DrAvGrCiRBOKoGkmH1d5Sc+Zb2S?= =?us-ascii?Q?STfewbzuDwHNRSu7x1BZNPG5x3Ex2Z2xWdx4PxRFem/CWeWEQLgS4+3askTg?= =?us-ascii?Q?K+WJGjZiFkKZYeDGLv3sXk10RdxHiE2r9Gz+zcTdG5XTriaHjswYncPvh1p4?= =?us-ascii?Q?cK7CUnAi9Amzsm+73YhuLfe5y4GBk2cY6SXhwgLkFUgebmyGIVUTSe0eyBK7?= =?us-ascii?Q?37LGUwwrjug9pxQeOKk+mofCPIeVkhJ6LK3W/SI7HsxXFkR9QxSrVNKsGcOr?= =?us-ascii?Q?7VlsUdoCFqvaj8SgTdWhwNAMty3IMpuClXg82PWkz5ZiLa2q345q0zjfI6iW?= =?us-ascii?Q?hHW7x1RMYFUEeog+Y7Uo2nVycEgyG/y9+MRzPD10AQt3sx0QobVkzYarNWvv?= =?us-ascii?Q?KXj2TlyX3veqeppF0b5RWEhz5EsuRxrCKxqKxSdaqXaIviUqXYHAVRuRr09R?= =?us-ascii?Q?R7faMoJK3El9VhGEgnhLbKXEMX7Ln67aFo8As83+NMIiGcwPs7xz6HELu6Gm?= =?us-ascii?Q?uwVzuSmJQBr6dAN2SJ2lmCe/xC/vahEOavFi/69MOvLTRsu6iuQLv2lGUovr?= =?us-ascii?Q?qKLXuOFxHk3bhMUalia5lSDoZWHiprT6G+ddVXGgeVSizhsQHE/Q8xpkdm7f?= =?us-ascii?Q?CZEXBgGy0rl4GJZTobk8WBLQbTg0rDWNlM6BtSt0me4rjp4q4Z+vUsPhBM/j?= =?us-ascii?Q?p1UbeOxq6Z8KoDhJ8p0jazPpN7lMV84mezREtm6Vgtiy963uZcpR/ej1neDQ?= =?us-ascii?Q?Vymv/mlNMyKU4ejps9nYR/JVJ7Rdy/MZgBbT8G98fpqTrH4qPb8/m7t49I9P?= =?us-ascii?Q?uDAFfJhsXah9GQDAGRBMgDRGPaTlAeXiui/IaqPTwaCyPPE+cudx2hufAIk2?= =?us-ascii?Q?lTHG/XY1WdyOendW5T/97Xn2dwweS7v1ONbAz+jOSkRxhAPEsk23FzMPlZYn?= =?us-ascii?Q?+hp2jCY4THsnbVFfLo82ndIfQyj6O31pucCba4Vxkgook0JxJkS56xSvlNNk?= =?us-ascii?Q?UTffsK8U5YedDOwg+N+QA8+U+o4EA40QbfF54Te/qYz6HOjufewMTp/8MV+S?= =?us-ascii?Q?kk/d9Mpjuc4ZOoad8/BWRfW4Fgncbzj+0JBXxd2/+OUmtWJSjh20Zsduq6fs?= =?us-ascii?Q?gY4OBKFhYWDNVZN2jN2NZUktrGf41Zfb0Sex8BTOzMpEK9FWjGwTtQqbrL7U?= =?us-ascii?Q?VBVzTGmDrqxpycV93PtaGAtSH2JdLBg/ap8hzlmczEMmjIWJI+jJGPjtDWzR?= =?us-ascii?Q?Kxj6oNV+ybVxJxGohXRoP7VP/uLp0mk+zOYFmCRKXYFM+RdqvTFYy5dnb9J6?= =?us-ascii?Q?5mI+1RMwxkPSRuDF6on/9TaEyRKw=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1266; 5:v7cWw83YQ3KsceCDmMdpuU2LL7iBghvODMuMUJaFfT2vX+fhn9Jnos6gMMCevCWd/5nt7+Io5bdOjV3iJMjaghkG4oYaomb8cqlxI914eNKTBVUIOdKTzzokG1M009b8eAbBPNmrMDY8AP8p57supw==; 24:Okt1wzurx5RwPglswYIme5FyBs0dGEP0MhOHeyuZjapWx5ut7ghSArkHth0i4KTnn+SM2fPbpyqxC8NRbNj89I/cHyBnoxA3Pu22j+vikVg=; 20:AYX9LgbRZTX7M15eQ6l0UglSZe5erNZS3qU5N7EzCqCMpRGHt/Bse5F6t9DWNR2RAq51PgC1OG4lqp2vQjrnrg== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2015 09:23:18.1928 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0301MB1266 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_03_06, RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham 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 This Patch adds the VFIO APIs to add and remove reserved iova regions. The reserved iova region can be used for mapping some specific physical address in iommu. Currently we are planning to use this interface for adding iova regions for creating iommu of msi-pages. But the API are designed for future extension where some other physical address can be mapped. Signed-off-by: Bharat Bhushan --- drivers/vfio/vfio_iommu_type1.c | 201 +++++++++++++++++++++++++++++++++++++++- include/uapi/linux/vfio.h | 43 +++++++++ 2 files changed, 243 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 57d8c37..fa5d3e4 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -59,6 +59,7 @@ struct vfio_iommu { struct rb_root dma_list; bool v2; bool nesting; + struct list_head reserved_iova_list; }; struct vfio_domain { @@ -77,6 +78,15 @@ struct vfio_dma { int prot; /* IOMMU_READ/WRITE */ }; +struct vfio_resvd_region { + dma_addr_t iova; + size_t size; + int prot; /* IOMMU_READ/WRITE */ + int refcount; /* ref count of mappings */ + uint64_t map_paddr; /* Mapped Physical Address */ + struct list_head next; +}; + struct vfio_group { struct iommu_group *iommu_group; struct list_head next; @@ -106,6 +116,38 @@ static struct vfio_dma *vfio_find_dma(struct vfio_iommu *iommu, return NULL; } +/* This function must be called with iommu->lock held */ +static bool vfio_overlap_with_resvd_region(struct vfio_iommu *iommu, + dma_addr_t start, size_t size) +{ + struct vfio_resvd_region *region; + + list_for_each_entry(region, &iommu->reserved_iova_list, next) { + if (region->iova < start) + return (start - region->iova < region->size); + else if (start < region->iova) + return (region->iova - start < size); + + return (region->size > 0 && size > 0); + } + + return false; +} + +/* This function must be called with iommu->lock held */ +static +struct vfio_resvd_region *vfio_find_resvd_region(struct vfio_iommu *iommu, + dma_addr_t start, size_t size) +{ + struct vfio_resvd_region *region; + + list_for_each_entry(region, &iommu->reserved_iova_list, next) + if (region->iova == start && region->size == size) + return region; + + return NULL; +} + static void vfio_link_dma(struct vfio_iommu *iommu, struct vfio_dma *new) { struct rb_node **link = &iommu->dma_list.rb_node, *parent = NULL; @@ -580,7 +622,8 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu, mutex_lock(&iommu->lock); - if (vfio_find_dma(iommu, iova, size)) { + if (vfio_find_dma(iommu, iova, size) || + vfio_overlap_with_resvd_region(iommu, iova, size)) { mutex_unlock(&iommu->lock); return -EEXIST; } @@ -626,6 +669,127 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu, return ret; } +/* This function must be called with iommu->lock held */ +static +int vfio_iommu_resvd_region_del(struct vfio_iommu *iommu, + dma_addr_t iova, size_t size, int prot) +{ + struct vfio_resvd_region *res_region; + + res_region = vfio_find_resvd_region(iommu, iova, size); + /* Region should not be mapped in iommu */ + if (res_region == NULL || res_region->map_paddr) + return -EINVAL; + + list_del(&res_region->next); + kfree(res_region); + return 0; +} + +/* This function must be called with iommu->lock held */ +static int vfio_iommu_resvd_region_add(struct vfio_iommu *iommu, + dma_addr_t iova, size_t size, int prot) +{ + struct vfio_resvd_region *res_region; + + /* Check overlap with with dma maping and reserved regions */ + if (vfio_find_dma(iommu, iova, size) || + vfio_find_resvd_region(iommu, iova, size)) + return -EEXIST; + + res_region = kzalloc(sizeof(*res_region), GFP_KERNEL); + if (res_region == NULL) + return -ENOMEM; + + res_region->iova = iova; + res_region->size = size; + res_region->prot = prot; + res_region->refcount = 0; + res_region->map_paddr = 0; + + list_add(&res_region->next, &iommu->reserved_iova_list); + + return 0; +} + +static +int vfio_handle_reserved_region_add(struct vfio_iommu *iommu, + struct vfio_iommu_reserved_region_add *region) +{ + dma_addr_t iova = region->iova; + size_t size = region->size; + int flags = region->flags; + uint64_t mask; + int prot = 0; + int ret; + + /* Verify that none of our __u64 fields overflow */ + if (region->size != size || region->iova != iova) + return -EINVAL; + + mask = ((uint64_t)1 << __ffs(vfio_pgsize_bitmap(iommu))) - 1; + + WARN_ON(mask & PAGE_MASK); + + if (flags & VFIO_IOMMU_RES_REGION_READ) + prot |= IOMMU_READ; + if (flags & VFIO_IOMMU_RES_REGION_WRITE) + prot |= IOMMU_WRITE; + + if (!prot || !size || (size | iova) & mask) + return -EINVAL; + + /* Don't allow IOVA wrap */ + if (iova + size - 1 < iova) + return -EINVAL; + + mutex_lock(&iommu->lock); + + if (region->flags & VFIO_IOMMU_RES_REGION_ADD) { + ret = vfio_iommu_resvd_region_add(iommu, iova, size, prot); + if (ret) { + mutex_unlock(&iommu->lock); + return ret; + } + } + + mutex_unlock(&iommu->lock); + return 0; +} + +static +int vfio_handle_reserved_region_del(struct vfio_iommu *iommu, + struct vfio_iommu_reserved_region_del *region) +{ + dma_addr_t iova = region->iova; + size_t size = region->size; + int flags = region->flags; + int ret; + + if (!(flags & VFIO_IOMMU_RES_REGION_DEL)) + return -EINVAL; + + mutex_lock(&iommu->lock); + + /* Check for the region */ + if (vfio_find_resvd_region(iommu, iova, size) == NULL) { + mutex_unlock(&iommu->lock); + return -EINVAL; + } + + /* remove the reserved region */ + if (region->flags & VFIO_IOMMU_RES_REGION_DEL) { + ret = vfio_iommu_resvd_region_del(iommu, iova, size, flags); + if (ret) { + mutex_unlock(&iommu->lock); + return ret; + } + } + + mutex_unlock(&iommu->lock); + return 0; +} + static int vfio_bus_type(struct device *dev, void *data) { struct bus_type **bus = data; @@ -905,6 +1069,7 @@ static void *vfio_iommu_type1_open(unsigned long arg) } INIT_LIST_HEAD(&iommu->domain_list); + INIT_LIST_HEAD(&iommu->reserved_iova_list); iommu->dma_list = RB_ROOT; mutex_init(&iommu->lock); @@ -1020,6 +1185,40 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, return ret; return copy_to_user((void __user *)arg, &unmap, minsz); + } else if (cmd == VFIO_IOMMU_RESERVED_REGION_ADD) { + struct vfio_iommu_reserved_region_add region; + long ret; + + minsz = offsetofend(struct vfio_iommu_reserved_region_add, + size); + if (copy_from_user(®ion, (void __user *)arg, minsz)) + return -EFAULT; + + if (region.argsz < minsz) + return -EINVAL; + + ret = vfio_handle_reserved_region_add(iommu, ®ion); + if (ret) + return ret; + + return copy_to_user((void __user *)arg, ®ion, minsz); + } else if (cmd == VFIO_IOMMU_RESERVED_REGION_DEL) { + struct vfio_iommu_reserved_region_del region; + long ret; + + minsz = offsetofend(struct vfio_iommu_reserved_region_del, + size); + if (copy_from_user(®ion, (void __user *)arg, minsz)) + return -EFAULT; + + if (region.argsz < minsz) + return -EINVAL; + + ret = vfio_handle_reserved_region_del(iommu, ®ion); + if (ret) + return ret; + + return copy_to_user((void __user *)arg, ®ion, minsz); } return -ENOTTY; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index b57b750..1abd1a9 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -440,6 +440,49 @@ struct vfio_iommu_type1_dma_unmap { #define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15) #define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16) +/**************** Reserved IOVA region specific APIs **********************/ + +/* + * VFIO_IOMMU_RESERVED_REGION_ADD - _IO(VFIO_TYPE, VFIO_BASE + 17, + * struct vfio_iommu_reserved_region_add) + * This is used to add a reserved iova region. + * @flags - Input: VFIO_IOMMU_RES_REGION_ADD flag is for adding + * a reserved region. + * Also pass READ/WRITE/IOMMU flags to be used in iommu mapping. + * @iova - Input: IOVA base address of reserved region + * @size - Input: Size of the reserved region + * Return: 0 on success, -errno on failure + */ +struct vfio_iommu_reserved_region_add { + __u32 argsz; + __u32 flags; +#define VFIO_IOMMU_RES_REGION_ADD (1 << 0) /* Add a reserved region */ +#define VFIO_IOMMU_RES_REGION_READ (1 << 1) /* readable region */ +#define VFIO_IOMMU_RES_REGION_WRITE (1 << 2) /* writable region */ + __u64 iova; + __u64 size; +}; +#define VFIO_IOMMU_RESERVED_REGION_ADD _IO(VFIO_TYPE, VFIO_BASE + 17) + +/* + * VFIO_IOMMU_RESERVED_REGION_DEL - _IO(VFIO_TYPE, VFIO_BASE + 18, + * struct vfio_iommu_reserved_region_del) + * This is used to delete an existing reserved iova region. + * @flags - VFIO_IOMMU_RES_REGION_DEL flag is for deleting a region use, + * only a unmapped region can be deleted. + * @iova - Input: IOVA base address of reserved region + * @size - Input: Size of the reserved region + * Return: 0 on success, -errno on failure + */ +struct vfio_iommu_reserved_region_del { + __u32 argsz; + __u32 flags; +#define VFIO_IOMMU_RES_REGION_DEL (1 << 0) /* unset the reserved region */ + __u64 iova; + __u64 size; +}; +#define VFIO_IOMMU_RESERVED_REGION_DEL _IO(VFIO_TYPE, VFIO_BASE + 18) + /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */ /*