From patchwork Wed Sep 30 14:56:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 7294021 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 9E947BEEA4 for ; Wed, 30 Sep 2015 09:37:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9D2A420641 for ; Wed, 30 Sep 2015 09:37:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8934520640 for ; Wed, 30 Sep 2015 09:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932083AbbI3Jhu (ORCPT ); Wed, 30 Sep 2015 05:37:50 -0400 Received: from mail-bn1bon0130.outbound.protection.outlook.com ([157.56.111.130]:1248 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755259AbbI3Jhp (ORCPT ); Wed, 30 Sep 2015 05:37:45 -0400 Received: from BLUPR03CA002.namprd03.prod.outlook.com (10.255.124.19) by DM2PR0301MB1280.namprd03.prod.outlook.com (10.160.221.149) with Microsoft SMTP Server (TLS) id 15.1.274.16; Wed, 30 Sep 2015 09:23:25 +0000 Received: from BN1AFFO11FD007.protection.gbl (10.255.124.4) by BLUPR03CA002.outlook.office365.com (10.255.124.19) with Microsoft SMTP Server (TLS) id 15.1.286.20 via Frontend Transport; Wed, 30 Sep 2015 09:23:25 +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 BN1AFFO11FD007.mail.protection.outlook.com (10.58.52.67) with Microsoft SMTP Server (TLS) id 15.1.274.4 via Frontend Transport; Wed, 30 Sep 2015 09:23:25 +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 t8U9NCDT000590; Wed, 30 Sep 2015 02:23:21 -0700 From: Bharat Bhushan To: , , CC: , , , , , Bharat Bhushan Subject: [RFC PATCH 3/6] vfio: Extend iommu-info to return MSIs automap state Date: Wed, 30 Sep 2015 20:26:26 +0530 Message-ID: <1443624989-24346-3-git-send-email-Bharat.Bhushan@freescale.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1443624989-24346-1-git-send-email-Bharat.Bhushan@freescale.com> References: <1443624989-24346-1-git-send-email-Bharat.Bhushan@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD007; 1:Bc0pmE3y9eqhh0PdIU4WVP+74Uu9FezimHYf2dPpqll7m+v/PBWoxyPc/mlkYhMPEG0P0KeKoF4O2Qd03bo66Ajnhiu8s7lk8SOeaRZmEpuYT1A1K2AEBvjQBzF1vFosq491O8bnLPKkXB/Jf50IiUr9KBkJwqwb0kMsX5o1apbdhWC7ran15zhVamNTeCLp61fzRw/nGjm+LoS97bXrCCQ8DxTr1dvPS9/pNHoLnS1boRe6X/etmTfFdJkTveIf+6UBykvBYw+2KqC6V6Vp7iCpFKcwcxDrNDQ70CaY1uJWtHW8ulHz3jAr1jcoIGf+yx/ZwIFBn40OlPvuB4O6+n1QzohOvFID+TNPWi4GFbop1vaJL/g1k3x8p5UjR1V+oczavCjwkOlLvuFD4sHbPJHf1VwdS7kry99iTiXxZNSxc0mFyqm/6aQiMGnLEevi X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(3190300001)(189002)(199003)(85426001)(77156002)(2950100001)(62966003)(92566002)(77096005)(64706001)(46102003)(11100500001)(68736005)(87936001)(2171001)(50226001)(47776003)(76506005)(86362001)(229853001)(50986999)(48376002)(2201001)(19580395003)(19580405001)(76176999)(5007970100001)(106466001)(105606002)(97736004)(81156007)(5001770100001)(107886002)(5001960100002)(4001540100001)(189998001)(6806005)(5003940100001)(36756003)(5001830100001)(104016004)(5001860100001)(50466002)(5008740100001)(4001430100001)(2101003)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB1280; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1280; 2:IANQVfi/Dz1S0P4oOWB5EsxPdsx4CiheC2mluUxBRSGesFE8W+oI+WIRw7FyccsFUTSUiMqyWOkggfHpa0s205tquHXRUYNuiqxHCzSQnWP9LEyikoDfX3v/VdtYMA5NM/10b7b4oqHsRwc4CDMa5xf5eZOKD4Bx7rpwX5VWuFg=; 3:3rPaz4VOGMK46f1bxANlq1zc09nefpPu/x9+UTwD4cjL0khRTL/4rQWw7dpeTyACOVptvoqvn9iXY44dq/YpQdshN/kKl93DUmtHZ0duG2PNRaYhDtes2VZdL29bgUE7WdRzjNbKIC6ApN8Rj0v5GepR1RBZaHEzakbGDLWS8vYztwVYHfDWdoH5SAP6FbMS4Hk7YL8gyDuVv7SmpLKNKurxxcwI6lE2wTl+czufTek=; 25:so6g8dSUw3xFRW4P+DjssjKT0klG8RhI7pkS1Tr3RV06bl/gFTgV8zxg8Eu85AlTifrshYrzkOhETm7s9O1uwuYvigExnOSMX3rhXSzBuArAuPjgzaWnnyPFEDGdnjmW7SnfrcN40/QlkJp/3Cy+h4ke7J0oaUtsBHjQ/Xlka3T86n7z67q6dWpBXl+hJozmlOZHuwSEw6q9E4+BZ4O2jE53g3XjhY8muAt3u53MYFbhG92v6YS6rA6MBKRdBla5S0t3x/RINvDKlX2U9Pwljw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1280; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1280; 20:MWC8qLw7XsPR55kEOsjmJ8yQ1vc09QxkCdE4ZC38Kih3M0loJ6w8Oy5W9/KNA9uP1ENPqxi3YiGvcE8i/daMIYWVkprqULDrkf7MK4RsMuza3FsbfLgYJ/Bq5vKPJ/3YW1H4juj6NlRcEmTtQ6IX0HkLrllRUA9DLVlGBIwkfgGO2YI//X1P3Rd5KgNiCUjaIJziTY6iHinH+q8T2dnPlmPaDbHXDwHKNIHimI2yMIDxLEpb47bg2A54vt9IYXiweERmeI13bT7Cvj0AcAgi+YqcvJ8ekOc8AnWc36dZKkTi7lUH1EIQihWltsdU6dS+rUzU/fXAZ+6GS/AHxjR/MhaGBOCtwamY0sRL5+YujuY=; 4:1n/CKhdPP/aIsLMJlcbRL7kha8VEicMB5ZSrK2ii+UQL5xjZEDbuLlDVAgmTS6My3V0Do8vcGekxOP0lad8mTXHZO/5H+YpW7KOD1cqc4jO8DOc+fqdwWGFhUIG/fADm1JVwJOx+7K4gjRll5O+O8rl8L8SsvSQIB3BlHEEgkA8XTxul6iXTs7KLG3yyMRIJ0V6+lBlMPPTMwhvbwFQTRLXvLStMP8eeSfBspkbq7H0wqErSAx//dJrokvUHsuTXARLqse3kOvyvBXz7VeiDqnY6jMtTWMRSX+ZsJHmPD3jx/WBlRLKkO4sDGNF4sCqgVLqrlIhb4wILBiLgNe8EVXDmiBWmxMBYXi4te1FPjWs= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(3002001); SRVR:DM2PR0301MB1280; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1280; X-Forefront-PRVS: 071518EF63 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB1280; 23:JtoMtJX5Oew0eUtexkNw3JZVMlDui01rSqUHsVm?= =?us-ascii?Q?ISC2vGe+fraiYPK3tXrOS5tndTRrMDPQUi7sdp0FkCQjcBOe80VpOnLV+Li6?= =?us-ascii?Q?tbLrr2Mpm1H/UhNI+FLOH6FzRpp0IJk2vlklaxsq98rPwzLKkBC1WYYruHUT?= =?us-ascii?Q?7qomuSGnRc5ka7knehFDRzN63EXUF6MJgEucuYrEDhIKT6o8DvxT1qEfOair?= =?us-ascii?Q?2l6b1rqvr8eQIUbUQ90HBPq/73jxtjSZJ/YtkkMMsc7T/mu2sm13MLLB6p0b?= =?us-ascii?Q?YCGvfp2W4YRAocexlEf3PMK4vv4H3E9QMWEUeFNRU23Ka+Lkh3AL0AMGjRY4?= =?us-ascii?Q?D9b8T4MeE+qeNVQGGqxVxuy68NnNn0AdnCM2gPqcjL/THJrAJriOLKKn6lBd?= =?us-ascii?Q?GGGitb2WeReo4O+4gBp8wLTfrm4l8JB3QnOVjO7HaMs1NvdvGdQMuizmU3Yg?= =?us-ascii?Q?vuGWkVPyZb2BbniYk3DR2oqxjLfrjDelkZj55nOSDPMXRpr0lgPWmYSfm+tt?= =?us-ascii?Q?f/nFVou4e5hEWGFSMuRKTx+oexIY+DM8NLEpSnqQ5ZGU2VATTOa38gOejoL4?= =?us-ascii?Q?sX1M7H3LfE885p1BQJrLSEO2ROdkpJLjUDMrkxyDYH4Tdpaus+artlvhuMTZ?= =?us-ascii?Q?w8mWtoSIdjhKx2XLz66eqzcsqqqxwyU0EMCXh5bERbWXvpad3qaDnYXoPf92?= =?us-ascii?Q?3IgDB10zc0/UoVTZUvxZ6v45BQTEWGbPqLeV0oAUQcRc6Qr8BDYeo9ozLW8b?= =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qBCnyrU5ZB6WTWoASkUE=; 20:fP1Pk4kPz9xyYpWtjlKxa2DVrYqZkhEFEhEr+h5ztgvxh4H9ICgVzPCBAD7W0JErrlUTwpcsuGmNCMNyWKht5A== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2015 09:23:25.1625 (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: DM2PR0301MB1280 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 allows the user-space to know whether msi-pages are automatically mapped with some magic iova or not. Even if the msi-pages are automatically mapped, still user-space wants to over-ride the automatic iova selection for msi-mapping. For this user-space need to know whether it is allowed to change the automatic mapping or not and this API provides this mechanism. Follow up patches will provide how to over-ride this. Signed-off-by: Bharat Bhushan --- drivers/vfio/vfio_iommu_type1.c | 32 ++++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index fa5d3e4..3315fb6 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; + bool allow_msi_reconfig; struct list_head reserved_iova_list; }; @@ -1117,6 +1118,23 @@ static int vfio_domains_have_iommu_cache(struct vfio_iommu *iommu) return ret; } +static +int vfio_domains_get_msi_maps(struct vfio_iommu *iommu, + struct iommu_domain_msi_maps *msi_maps) +{ + struct vfio_domain *d; + int ret; + + mutex_lock(&iommu->lock); + /* All domains have same msi-automap property, pick first */ + d = list_first_entry(&iommu->domain_list, struct vfio_domain, next); + ret = iommu_domain_get_attr(d->domain, DOMAIN_ATTR_MSI_MAPPING, + msi_maps); + mutex_unlock(&iommu->lock); + + return ret; +} + static long vfio_iommu_type1_ioctl(void *iommu_data, unsigned int cmd, unsigned long arg) { @@ -1138,6 +1156,8 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, } } else if (cmd == VFIO_IOMMU_GET_INFO) { struct vfio_iommu_type1_info info; + struct iommu_domain_msi_maps msi_maps; + int ret; minsz = offsetofend(struct vfio_iommu_type1_info, iova_pgsizes); @@ -1149,6 +1169,18 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, info.flags = 0; + ret = vfio_domains_get_msi_maps(iommu, &msi_maps); + if (ret) + return ret; + + if (msi_maps.override_automap) { + info.flags |= VFIO_IOMMU_INFO_MSI_ALLOW_RECONFIG; + iommu->allow_msi_reconfig = true; + } + + if (msi_maps.automap) + info.flags |= VFIO_IOMMU_INFO_MSI_AUTOMAP; + info.iova_pgsizes = vfio_pgsize_bitmap(iommu); return copy_to_user((void __user *)arg, &info, minsz); diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 1abd1a9..9998f6e 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -391,6 +391,9 @@ struct vfio_iommu_type1_info { __u32 argsz; __u32 flags; #define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */ +#define VFIO_IOMMU_INFO_MSI_AUTOMAP (1 << 1) /* MSI pages are auto-mapped + in iommu */ +#define VFIO_IOMMU_INFO_MSI_ALLOW_RECONFIG (1 << 2) /* Allows reconfig automap*/ __u64 iova_pgsizes; /* Bitmap of supported page sizes */ };