From patchwork Wed Sep 30 14:56:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 7293961 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 5CA5D9F1D5 for ; Wed, 30 Sep 2015 09:23:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 70A8E20693 for ; Wed, 30 Sep 2015 09:23:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 50EFE20687 for ; Wed, 30 Sep 2015 09:23:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754619AbbI3JXj (ORCPT ); Wed, 30 Sep 2015 05:23:39 -0400 Received: from mail-bn1bon0113.outbound.protection.outlook.com ([157.56.111.113]:8875 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751545AbbI3JXf (ORCPT ); Wed, 30 Sep 2015 05:23:35 -0400 Received: from DM2PR03CA0008.namprd03.prod.outlook.com (10.141.96.18) by BN3PR0301MB1265.namprd03.prod.outlook.com (10.161.209.145) with Microsoft SMTP Server (TLS) id 15.1.280.20; Wed, 30 Sep 2015 09:23:33 +0000 Received: from BN1AFFO11FD011.protection.gbl (2a01:111:f400:7c10::144) by DM2PR03CA0008.outlook.office365.com (2a01:111:e400:2428::18) with Microsoft SMTP Server (TLS) id 15.1.286.20 via Frontend Transport; Wed, 30 Sep 2015 09:23:33 +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 BN1AFFO11FD011.mail.protection.outlook.com (10.58.52.71) with Microsoft SMTP Server (TLS) id 15.1.274.4 via Frontend Transport; Wed, 30 Sep 2015 09:23:32 +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 t8U9NCDV000590; Wed, 30 Sep 2015 02:23:28 -0700 From: Bharat Bhushan To: , , CC: , , , , , Bharat Bhushan Subject: [RFC PATCH 5/6] vfio-pci: Create iommu mapping for msi interrupt Date: Wed, 30 Sep 2015 20:26:28 +0530 Message-ID: <1443624989-24346-5-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; BN1AFFO11FD011; 1:/lQ23Xx22ckcmlbVt/62NQNmzuZDGQ05k0ntR/vgHE7HSEfsP4697AIUU0uPho0xyMfUDYmgXrqWPZaEGDsAN7vInC+RLGHOYr4FqmZyxfd8tumIJnTJhuWxVyXWYsfHM/VA8Ht+SBTjJpKYliIsbnTwC+R5i6PpM3zFdnTLJJIflE3TbU1uVaEKUiIwLm1eV6aLvYm3qfc5AG2DNUW18CEUD0A7/3h12BBdT1yL18vXmZX4B3cpxQpiCu54ZqZS4hlZqeahwajtwM/oVGjRk+Fd2UKO5T1pa08tzI0l6yQEKzlSmCpobH64FndhrLM8/ChTGwsGgmaStRa9Hn/a36j/Fd1HqtmeCDh1/3cLab0nUxdj84zGkGRWGYPZUXCP63ShRAJZ0vuXlxT7AwBpdN1lWSvhkBvIGji4RIIFE4AW51WGS11QPANW2NqrEBvi X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1110001)(1109001)(339900001)(3190300001)(189002)(199003)(62966003)(2201001)(77156002)(77096005)(47776003)(6806005)(5001830100001)(97736004)(68736005)(4001540100001)(5001860100001)(64706001)(81156007)(5003940100001)(104016004)(5001770100001)(36756003)(46102003)(5007970100001)(11100500001)(107886002)(189998001)(5001960100002)(19580405001)(86362001)(2171001)(5001920100001)(5008740100001)(105606002)(76176999)(2950100001)(50466002)(76506005)(87936001)(85426001)(19580395003)(50986999)(229853001)(106466001)(50226001)(48376002)(92566002)(2101003)(4001430100001)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN3PR0301MB1265; 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; BN3PR0301MB1265; 2:T8va4SU1zYK3hBcPI2ePNHFyeW40ezmxNJwD8vMVLdRBSDUu2ilcl23OKuCt23Y6nfn5Z+mDMRqUYEyUPV8yZJm+WXn14A3okTzxXZJUaUJ2+g5IXgyEPXzLU97lcHg8W04uENEmFz2xL+p9VDfdJQwF7JQE1URPXRjcs7SDoeg=; 3:AkvH2E6zRyKC/xeCDZ6+Jf0koAtEKJDH8HsfQrAgrlf9MTHx4Z3F5oG0t6rbhmx7zFNBfA0/yJQAF0B7/DbhI688wzOT8CfCCjuHVsJrhWSBRPfthpHSZDdkCnoqjSWCY5bEjXt7A1OloYAA2FG7ZXBVtLD6pOZZykSBz6At3KnFpJiRQTChRVd4K+Qgo0QS8G54PE+jbKeXSEGMJz+b2n8vLdWqbZ6Y8kpAIE0LrI0=; 25:Wr7HE0mqGScLnm+hPgU+OOtA+RLBrE1qQ1dLITD1B9I9f6RAvcMTxFVyzN+gUjVu1u/jg5C+81LrUh9JxofDCLUbT6AH50+yb2SEbAY52+KMg68/pGkHInlOHnh1o+KxhiWOAI7cfZ2mthOOa9R68jVwPON6r8XIWqYnU+/9NVDIO4FfuXNaRZPzW/yowo7UbA6N5traItaoKncxWAC4KdGMf+74yL+skvjg4GdOIAsRPp8UPH6OUPli8B3B27K3Mu10yTWF+YpkKqaDKi3I5w== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0301MB1265; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1265; 20:4kv90o8EgxW3l01Zd8UuIUspb8m/pGJtCs+4dAr+ulJdzx41vYuaebGXUQN16nb1rswebt56xYYUHUWTz4QAVPJ06k2+pn99RHJRvq7BMf0YmRA7WuX+SYzYTPyYuZDfmrojz4YZYc0xXDeC83O4cikKQRWLaRUispNFy+OZqhdBOb/g5G/8uuLtpC+80YsSYxWZm80G290DogOI7R6uGWg27WgqEvmSY9dJF65Cp2y6MJJPJv+ZIZoCoVSHZcw22zj7opLloaCplUo9TVCA/ygE32gyXUSuSzD7gzslpKoixL3+9wswxWTRb2tXSNP0JoTRsWCXhusPe4e6XJ3P+hmwmxSrPqmDPMNZZ3Gao8g=; 4:GjpToHdImIcFsnUikofq3kemMESCfjFK3qZ0FQr9NTNLvr0Ib4SKP5kgndGSrWk1mGaq8ac1B3Q/4YHOlHRxTK1rgIqbcHaxfwNADNTvaXJF7wZZCvm/aIiEoFoRimzAGLTI5k8C5WhqHxJ+/7Wi9tcsuWbNlVZ873Q8z6aYloQ18AOTFyPHKTLrnQuJEi2kqK+xegoNSbIgNyhwOufl59kVbPZK4Qt9pTZ+dDBHubhTTwtFzGdOJ5mMex6CaKoWkuxtzU7fMIUGDtgMWSYFPhn0GVb7S4ewe7CMionEbrDvxjsCJLX46NPFvJrAxfiJHjxPVxoODxEDD71qdwkiUQdcrzfGPBEd6rZ8vOm7x44= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(3002001); SRVR:BN3PR0301MB1265; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0301MB1265; X-Forefront-PRVS: 071518EF63 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0301MB1265; 23:AVWnWoSV0yZgWGko3mOeloQ4lBwNHeHuqtIisHl?= =?us-ascii?Q?tUNr/KDBv9piwKYETSIxX+QuFm3QX3XnZAfheVe3mUECRby2FlQ15eZZcGu1?= =?us-ascii?Q?R+2NyDcpDX51I0r5BJwurbm5k8KA8L572dar+7j5XPWX/sBrA04DRD4EMUdZ?= =?us-ascii?Q?CrlIWnZYIefdSSNduKVOsoB9lt5q8Pe753uqVyppTzvH0mJvl3+ZVt0RMqUz?= =?us-ascii?Q?1XwwR3ujjev2qApC93XU5g6dmyd+2LUlPFb9rx4GL1/2LyuhntrNuwYdltbU?= =?us-ascii?Q?LHf1sDvRv5+0XiE906kZH7D/MMwL1uBytzqxgxp16NZHH9+iTMxTKl2rF9xc?= =?us-ascii?Q?rjnS2i9aAm6l1nJBnlkZaBdosup6BfK6rn3PzSA5tuQ3LWmj3ul9RjAMOn10?= =?us-ascii?Q?UNvf4KkscMCfCpkvVmR8xSIciSbh375mwGCW4WGT02CU6ilyiIlG26rc6X0T?= =?us-ascii?Q?CpvZaqZmdl+VUIWBW3vrzjUJfgRZNzKeER1j4+Fo4HnPyLZEi1rBaCNbWtUN?= =?us-ascii?Q?5+P9alDqsbDi3StsXpSkBCOyvenI65cJr2O605N2cIpYhqt/dvvSx+UjAja2?= =?us-ascii?Q?tT3UPgI2XZm34WYFmL77wqHd/snkI68bT3747ufLTGkgXKfXs2WkKHXdZoB/?= =?us-ascii?Q?/ywwQXh+HOn673QPMQLjLqgbuKORWuaIy1wiK7qPcOZVI+2dndPribBUKqW4?= =?us-ascii?Q?j4QwidSfzWnlLr0+9NqJZ6Ch015uEA/6zkkjKBB97EosyCJspTG0ym8LGk56?= =?us-ascii?Q?WJfw7OBtxge6qoyG0QvOfLjvFFYV4IeZA3fAdtUQmNZTmHRdZsGLxcfoewj2?= =?us-ascii?Q?PatTmJS+nWcN+HIXlXoAyHPX3b414iwr4VuHkKhBWBpZ3Aw3flmAP0L1T+pn?= =?us-ascii?Q?bDXKlf4kBhIXnaExaQ0VS2bQBvy/ur7vRruTCh8QluGv/ZD2sWNDlkVkkBxf?= =?us-ascii?Q?DciPRabEXFnJ9ADVECJMe24+/i6/f00+Cl7SIH7thxixLwo8EBBZzMs5HTHT?= =?us-ascii?Q?ipmKGmsEm8cpDjcM/9z9Xa72yrdpdscJjISgtwh0loW1XrsrxIG3haDuZeB0?= =?us-ascii?Q?NArp7JI4OnMGXq82fPL+aDbuCaVDW2taK3OvKsq/UYWDsc2TKxs4qtp8SKNu?= =?us-ascii?Q?ik/+ZPsrDIFJEkO37Mk1m4qa5NLeAT3RhjsWJclPBsQejYK6sraiS8xQIoWK?= =?us-ascii?Q?neWmZjBaeyMJp3XqX+4TRfs+w428TAuoCyoibIMEQEnLVzHu/QU9GT4E02h5?= =?us-ascii?Q?U/6OeEy1O9X3xA7TL0T5eZSuDlhzSR0lXDXO8HEV94twIWhmByJrrWjROq+n?= =?us-ascii?Q?9ebUviUiOYyOzn/l1CqJnobg3T3DUihy7QMbaqGAGcz2jC3jtE5MLuWA5Swz?= =?us-ascii?Q?4mUAKDJxIEw2IZUji69cIXN5LolKBuvb5I+vNWOrj4O9gYHQkN1NEcygznqo?= =?us-ascii?Q?sN/jmbEM+XA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1265; 5:Qi3zpfIoXc0V8dxWndECMr2x9L52ddxCPWPQkGWkoGhI7LBw5l4mfMs4yBUXEh36NZriv/mYO022ZJWGboYyJiOkbbqbT0pUXp2swSmDxdKm7Y3F2FDfI7aRXFcQ8tXwOF3UHuwNKErEo4ux0fLnag==; 24:KqTqCW5AClP7K2XFka3+B6+ONVF/C+ELQEKYWMbt4ig0YkcYH2tf1wWqGmLOmM82rPogJvRRYslurMxjoa7DdjNfFMakjOYnEf8u79a11wQ=; 20:ZvaHxzzllOBCoagJjUb/EyatU/NMmV5g8Qm1Tmcu9zoq+TNjAgWdSC7PVAWALRLLqOZ9n+T1S/fyPWQkrLLD1A== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2015 09:23:32.4108 (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: BN3PR0301MB1265 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 An MSI-address is allocated and programmed in pcie device during interrupt configuration. Now for a pass-through device, try to create the iommu mapping for this allocted/programmed msi-address. If the iommu mapping is created and the msi address programmed in the pcie device is different from msi-iova as per iommu programming then reconfigure the pci device to use msi-iova as msi address. Signed-off-by: Bharat Bhushan --- drivers/vfio/pci/vfio_pci_intrs.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 1f577b4..c9690af 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -312,13 +312,23 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, int irq = msix ? vdev->msix[vector].vector : pdev->irq + vector; char *name = msix ? "vfio-msix" : "vfio-msi"; struct eventfd_ctx *trigger; + struct msi_msg msg; + struct vfio_device *device; + uint64_t msi_addr, msi_iova; int ret; if (vector >= vdev->num_ctx) return -EINVAL; + device = vfio_device_get_from_dev(&pdev->dev); + if (device == NULL) + return -EINVAL; + if (vdev->ctx[vector].trigger) { free_irq(irq, vdev->ctx[vector].trigger); + get_cached_msi_msg(irq, &msg); + msi_iova = ((u64)msg.address_hi << 32) | msg.address_lo; + vfio_device_unmap_msi(device, msi_iova, PAGE_SIZE); kfree(vdev->ctx[vector].name); eventfd_ctx_put(vdev->ctx[vector].trigger); vdev->ctx[vector].trigger = NULL; @@ -346,12 +356,11 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, * cached value of the message prior to enabling. */ if (msix) { - struct msi_msg msg; - get_cached_msi_msg(irq, &msg); pci_write_msi_msg(irq, &msg); } + ret = request_irq(irq, vfio_msihandler, 0, vdev->ctx[vector].name, trigger); if (ret) { @@ -360,6 +369,29 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, return ret; } + /* Re-program the new-iova in pci-device in case there is + * different iommu-mapping created for programmed msi-address. + */ + get_cached_msi_msg(irq, &msg); + msi_iova = 0; + msi_addr = (u64)(msg.address_hi) << 32 | (u64)(msg.address_lo); + ret = vfio_device_map_msi(device, msi_addr, PAGE_SIZE, &msi_iova); + if (ret) { + free_irq(irq, vdev->ctx[vector].trigger); + kfree(vdev->ctx[vector].name); + eventfd_ctx_put(trigger); + return ret; + } + + /* Reprogram only if iommu-mapped iova is different from msi-address */ + if (msi_iova && (msi_iova != msi_addr)) { + msg.address_hi = (u32)(msi_iova >> 32); + /* Keep Lower bits from original msi message address */ + msg.address_lo &= PAGE_MASK; + msg.address_lo |= (u32)(msi_iova & 0x00000000ffffffff); + pci_write_msi_msg(irq, &msg); + } + vdev->ctx[vector].trigger = trigger; return 0;