From patchwork Wed Jul 13 13:20:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 71956 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1148339qga; Wed, 13 Jul 2016 11:43:31 -0700 (PDT) X-Received: by 10.98.59.205 with SMTP id w74mr5870493pfj.156.1468435411304; Wed, 13 Jul 2016 11:43:31 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gu10si3202451pac.8.2016.07.13.11.43.30; Wed, 13 Jul 2016 11:43:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753048AbcGMR6Y (ORCPT + 30 others); Wed, 13 Jul 2016 13:58:24 -0400 Received: from mail-by2nam01on0052.outbound.protection.outlook.com ([104.47.34.52]:28256 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750933AbcGMR6N (ORCPT ); Wed, 13 Jul 2016 13:58:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=wHrXNgvuyylEfoKwDdgfGNPjOfAFV6sVRpfXy5rcDYI=; b=LCmuV1t1JdQJbj+6UalkzdXtadzz88p9Nw5KPb8BX7ww+HeeuQs/ZZlKXLIpFNdGX5ZOYEtaelp68vRf4W84oqOrjhMqv1NsTcfpmqlLGrkMXK2Nvx0iZGyTmqk+Z/PoJLZMdHoLM9kf9DOaWmZ5xvKfcAPOeVRc5GomBlSCR2o= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (114.109.128.54) by SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) with Microsoft SMTP Server (TLS) id 15.1.534.14; Wed, 13 Jul 2016 13:21:30 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 PATCH v4 07/11] iommu/amd: Introduce amd_iommu_update_ga() Date: Wed, 13 Jul 2016 08:20:28 -0500 Message-ID: <1468416032-7692-8-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468416032-7692-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1468416032-7692-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [114.109.128.54] X-ClientProxiedBy: SIXPR04CA0024.apcprd04.prod.outlook.com (10.162.171.14) To SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) X-MS-Office365-Filtering-Correlation-Id: 92272559-29b4-4193-f242-08d3ab209b84 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 2:3gNRTYPFZcdK0iTh3jSlWB+lTcvwXGLggqtvnHldTkzqDnqNAORyYD8gz+DLQ2vTcuydmtHkLOdSwvFdL6OC7ksq6CzaQ+eEu9V3j/3qZTmXeifumwk+pJXXZFsSIIe5xKr9SKS3Kp5v1l/9CSSNe6D29HPHrtin9foAn6hg6KfBmlAybIk+yfJbyo6nR4RW; 3:BycHTC+Qv3pTdHT20LnTj3gu9mCwkmmPPX8VM0y8Jf4tnV/SRzjjX/nw1RJ+FFpi3xPaFguiDn+hP+DbRUhWzfzzoNNQQoYMRfvD71Opavhcdzu4mnahX5CaW9Ggti64 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID: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/+aNE2SO6NJg==; 20:i+QXEt5wrLluJ3N7QMkj5aGonUQGbZ3mtIyvVKyGf4krnVn2gvZsbbf8uWoqSzKxxHdu7ed6mii0Ay8LfaEltoi3+kcDSTVRyVd2cEaud0AAS66xYjU2m2PKHRJtZuz4qiW8ulSDiJ9S79aUkpBJBo+vvytJhq2efdfOW8raxLeMoGk3XNxHecX9cOU0nqscbHt14VZ5rBDGUbnKoy3Xu0Xyu/nYfCycYNMOldaCf+H+JhiGSkj4LOyxOF3jY9df6MJQTJR/TVD6y+EFzVSSe4tId2hdaZ2kDVPhHLufFIIJbu1XemugJIn2z+Mg1qIsyKQzJWUOw3yoqERvwK6uFPBFlb74/a/rl3MaGCPsdtMTANsbkX7mGH//XbNOq6BuPnWfRIKEJM63ACmhoDZfCNtxoWNbwIAmownOuX2+6sG/1R8BTDrlci80JZWbR5wvYo6sdSAxNYpANaGs2d1T7mVNt7I2Kc8Ok1O1/MJGtQ2RH6AYNuNRut7grQbXLYho X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:SN1PR12MB0445; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0445; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 4:ehsuaKWT7DzSOSMj8N5aMxYtRH1sacEryeclu4R7Q7g+2xBCXCwHJGZckzzxby7EI7H1PVVEZxwi2+pZyLOfvcYfqcYtE1TFAao72y97uQrUPnGI3B5moi3lDsvwxVAeDOdwcwOAC4syP8e+lEn+ww3+du2AyPmgsoKCLKkX0mCj2KG8+PrixbjvbIWUjs0StvM+KDz/YqVThPsq1iy65t5n7QiQawZwsB2d+c5B1obXEuZNX+89UG5CCAWkQA6A7VQ4dq9T9/aXF9avE5fUNMthU2WHqGPgkGPaminmeArBeWCPsMwsBdozDjrzGDeZYCA7ukKlNVO3PfC1NcBgV6xmKDlB0f0Cliuan4YHBqgys2pPsiFhAeq2QzF1qRxFY9qqCspGgRhit9fL8P+2fVWm8JgmOobfNARbwUDWMV4= X-Forefront-PRVS: 000227DA0C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(189002)(199003)(229853001)(101416001)(77096005)(8676002)(6116002)(2950100001)(42186005)(586003)(81156014)(81166006)(2201001)(3846002)(50986999)(4326007)(76176999)(50466002)(36756003)(5003940100001)(68736007)(105586002)(305945005)(47776003)(66066001)(86362001)(7846002)(50226002)(2906002)(48376002)(92566002)(106356001)(19580405001)(7736002)(33646002)(97736004)(189998001)(5001770100001)(19580395003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0445; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0445; 23:olWH2sHMP3GvME0oOzYMUnuzdZLd924tRkh0H8xcE?= =?us-ascii?Q?9NW9Hp71GQQLMqXcRr0pk6AZ/hMY3duU1yW00LWAYsqjUZBIFYoRPQzwAfvs?= =?us-ascii?Q?6UVczTJfxflrm9SRBo1Tlw3iJx2qCDPaqnmXbzxRDfT7GIxZntJuodpISEoO?= =?us-ascii?Q?/JRRFRDvoMrwzz1k1s5wdrzy3zoxxxURHwJhbhN0qgki06pBnpoEZCnfyZN0?= =?us-ascii?Q?EaTutqL6gfx/B+ZyRuX/seLMDXoeUGSSDgVoLVspz8qkdE1+/DsjM4U3cpev?= =?us-ascii?Q?I967nBCxEDJhbNGP4yygyTh56UvGDhn0vBVCEcb0FULHxN1UAQ1ZNEi+RtJx?= =?us-ascii?Q?yU+yb6ldfGfFiWt9FDNkKmwJN8wVxm3nP6Xbx9KHzY3XpYSFHhq7onDgG98x?= =?us-ascii?Q?iW7j1hQeiClvR6OKqxN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ArrivalTime: 13 Jul 2016 13:21:30.0653 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0445 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit Introduces a new IOMMU API, amd_iommu_update_ga(), which allows KVM (SVM) to update existing posted interrupt IOMMU IRTE when load/unload vcpu. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd_iommu.c | 65 +++++++++++++++++++++++++++++++++++++++++ drivers/iommu/amd_iommu_types.h | 1 + include/linux/amd-iommu.h | 9 ++++++ 3 files changed, 75 insertions(+) -- 1.9.1 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index fe9b005..4a337dc 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -4461,4 +4461,69 @@ int amd_iommu_create_irq_domain(struct amd_iommu *iommu) return 0; } + +static int +update_irte_ga(struct irte_ga *irte, unsigned int devid, + u64 base, int cpu, bool is_run) +{ + struct irq_remap_table *irt = get_irq_table(devid, false); + unsigned long flags; + + if (!irt) + return -ENODEV; + + spin_lock_irqsave(&irt->lock, flags); + + if (irte->lo.fields_vapic.guest_mode) { + irte->hi.fields.ga_root_ptr = (base >> 12); + if (cpu >= 0) + irte->lo.fields_vapic.destination = cpu; + irte->lo.fields_vapic.is_run = is_run; + barrier(); + } + + spin_unlock_irqrestore(&irt->lock, flags); + + return 0; +} + +int amd_iommu_update_ga(u32 vcpu_id, u32 cpu, u32 vm_id, + u64 base, bool is_run) +{ + unsigned long flags; + struct amd_iommu *iommu; + + if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) + return 0; + + for_each_iommu(iommu) { + struct amd_ir_data *ir_data; + + spin_lock_irqsave(&iommu->gatag_ir_hash_lock, flags); + + /* Note: + * We need to update all interrupt remapping table entries + * for targeting the specified vcpu. Here, we use gatag + * as a hash key and iterate through all entries in the bucket. + */ + hash_for_each_possible(iommu->gatag_ir_hash, ir_data, hnode, + AMD_IOMMU_GATAG(vm_id, vcpu_id)) { + struct irte_ga *irte = (struct irte_ga *) ir_data->entry; + + if (!irte->lo.fields_vapic.guest_mode) + continue; + + update_irte_ga((struct irte_ga *)ir_data->ref, + ir_data->irq_2_irte.devid, + base, cpu, is_run); + iommu_flush_irt(iommu, ir_data->irq_2_irte.devid); + iommu_completion_wait(iommu); + } + + spin_unlock_irqrestore(&iommu->gatag_ir_hash_lock, flags); + } + + return 0; +} +EXPORT_SYMBOL(amd_iommu_update_ga); #endif diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index 2ed353b..52160c8 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -844,6 +844,7 @@ struct amd_ir_data { union { struct msi_msg msi_entry; }; + void *ref; /* Pointer to the actual irte */ }; #ifdef CONFIG_IRQ_REMAP diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h index 940fdd8..a6fc022 100644 --- a/include/linux/amd-iommu.h +++ b/include/linux/amd-iommu.h @@ -179,6 +179,9 @@ static inline int amd_iommu_detect(void) { return -ENODEV; } /* IOMMU AVIC Function */ extern int amd_iommu_register_ga_log_notifier(int (*notifier)(int, int)); +extern int +amd_iommu_update_ga(u32 vcpu_id, u32 cpu, u32 vm_id, u64 base, bool is_run); + #else /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */ static inline int @@ -187,6 +190,12 @@ amd_iommu_register_ga_log_notifier(int (*notifier)(int, int)) return 0; } +static inline int +amd_iommu_update_ga(u32 vcpu_id, u32 cpu, u32 vm_id, u64 base, bool is_run) +{ + return 0; +} + #endif /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */ #endif /* _ASM_X86_AMD_IOMMU_H */