From patchwork Mon Jul 25 09:32:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 72691 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1048333qga; Mon, 25 Jul 2016 02:34:22 -0700 (PDT) X-Received: by 10.66.159.195 with SMTP id xe3mr28298822pab.159.1469439262111; Mon, 25 Jul 2016 02:34:22 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z88si32773471pff.218.2016.07.25.02.34.21; Mon, 25 Jul 2016 02:34:22 -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 S1753041AbcGYJdv (ORCPT + 29 others); Mon, 25 Jul 2016 05:33:51 -0400 Received: from mail-sn1nam01on0076.outbound.protection.outlook.com ([104.47.32.76]:16256 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752941AbcGYJdb (ORCPT ); Mon, 25 Jul 2016 05:33:31 -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=OgsCjWw6aFlX8+OHNNUexW/MhdOLN3VhPeU/XTenzx0=; b=Cd/kyrZdeC6cJFnmkFByUR6ODdQcnrM3HW9l8kVpw+mdVhaLjhdS1cMIgtN1KZS2i0ACUN/WFZKni3cMCGFXlbrGzmAZOibP91VwA2jszZ7HmjOfJ3NqoGW1ipF8LkTkZnAEeyziAQJf3/toImwAgByRgdsMZL9jqzQsubvjWgo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (114.109.128.54) by BLUPR12MB0434.namprd12.prod.outlook.com (10.162.92.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15; Mon, 25 Jul 2016 09:33:05 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 PATCH v5 07/12] iommu/amd: Introduce amd_iommu_update_ga() Date: Mon, 25 Jul 2016 04:32:06 -0500 Message-ID: <1469439131-11308-8-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469439131-11308-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1469439131-11308-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [114.109.128.54] X-ClientProxiedBy: SG2PR06CA0066.apcprd06.prod.outlook.com (10.167.73.162) To BLUPR12MB0434.namprd12.prod.outlook.com (10.162.92.14) X-MS-Office365-Filtering-Correlation-Id: 2027621b-08c6-4d78-023d-08d3b46eb018 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 2:6vGYjnTN/4vZg56ZoW6qYvF3jc+9wVL/l7Y4EvowENHwy5yybXcXncWn8QYq/Ww+J889u8QN8gz77zTTkDB819yxxtRdDx12M91lYhFB/6AXhgZ568iBQtIvD+j+okTOw+zC5K6e9e+Pov1qbhnbTR4NpmLyDWq87cjRnB1NoqU+NkB9enbeYr7m3eafMZ+a; 3:ywyYKHk62g8AXD5U588Y2eOYhrxId29mvahO8HmMwZCpQLCaCoOdK30hr9JA2D/q5hfhrh5mLPxGRL0eIsl1cUUCHdSsrhYwWbrnMSqcD71P5+zCSyPFk+j221tC6OIH X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0434; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 25:CtqLSCe/vO+103Zcy+mfQiSDlwi7lhOXnrI1crx2ddDAPiWs3GpaZo81h3cvlP+hc55Pc3wKxyGfoScJqDje56VYeljlwIPXtE0M4fKyG6t4lUQTmigasizChye0IiCzQ3hbSl4yHbmL4OvavG1LQXnoA29kKQCpv541EPEqXxql1YKdU5H01BldCv1JQiGTS+R1QsFOgjAPmTlucc8VWlcJJi84AX3bt4PWpTDRd2ucsnLwYP6/rla+x4dgxH69hkaxrqChYRf/OsWd8tVcPv8REtnP5BVbR7RKVnhwrj8qJLJK4pnukv4xkVQTnqhvqyra5Qi5winiUf7IIWHsiVNUO93w70VRh+ZSdJXrWnFd6awAIzROliDK4ueGosSmUlvQFwacFPCHBlcPdbKx0WQdHnAaltholn8NCNILn5RylXB2p5Trdwx4I8F9xbnFU1CuPz2MnqhZUP+WLvuhzfvLPDB17rwSuRTO0FSVBg8i66Bw5zqpKYVp+0NburKVBZvvlHPSsd6SdrovwwAYMzHYAs2BCJnbcVWYuLbM0miKmvL88cq0tz+KITmYq4vrMMNEQXaT7eg1Y0Vplo/wa8wh6S0ed/fTiSRVfCkDLxBEmOj+N+Chrne5q2Qe4WLecl0fRES99rUSZwcubx+M2EYBMECy50u9r6JsyObgvE1O+LiqJsDAIRJDKmnqiG61GHFav/nJa1xfFej37vYIO6P1F510YZSX0G7f2P7aEzw=; 31:Ogx/60awjya9NPIt13ijxPyk+VgdOM+FeFGNNOjXimItjYcIOjeE073gIkH+ZSczXd6rnTh6zQZZ2TYtvk1L3SL8Ogy5WBuiG/oQPJS5nu9WBj/kP+zl5gQeU15p3PaMaxgXqRjWDwQxpoe9HEeC/qyY9L2vzvFYy3hnZDDRuNwS50PdSMAOvrQgBseaqGZEI2lONkZB9qDxplH3/KOfQA== X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 20:b0gtvTJ1PGTUgpDHMDi7bJo/1J99b0Cjq36p3AjiDat3k5tuBAQJf+TRVOH+n91jRxMkNW6J6eDSVJlyHaI2YEKSvufSwS9ZuUSkuPajrQ1ebZMUoSC+qso9CiOzk/1E6I2VdIImqbXv4ZyWbn1xHa6uEOCEjrLj6trG+N98VeznIyLMCUiiAKs+SlL0sJiyoFqjsxfJ4KzcMYRD5NGp67lTz1NqnmKLqPN6R7d6aovmgeIhnp3jcrte9++Vu7V03iVJQ7YunPTNBtYuFr1N4Oq+/fFR/n87CuxeLwf1QVWpttsNQct6fXqpKHF6J7JvE1i1+WXzfdZ7x53CbfUqTHm8IdyKSMPlFVirG2UH6781bwtqJ0+6mpwEMV5mbocy8A3QVHFUjfcTsqG1/zfRNAaAghPF28hIHN7PibPtL03hF6PrxIjA9ZPPLjMRPPQ+Ak1fZMjQItdxxSAgUJWsAanIEMp7jPPvZa0C2uN6KFtmFNST1XJfQ6E0HQY19kxu; 4:IWxXM6OzoE2mCzm1NbLNToZZUEwlhY6lPXT3jToCltykr6sWaKX+ESi2BeiqcQaux5sffK/epRNDDmCPX7KSz8fQ3u3OXFkXZfohLzhz/0S+ieTRIiEPncfG4Gy8dDBYjGqnzKqJfPwr3Y/zXg6TEVTE44Q5skWGHpreKdGJ4spuodOdgC8P8M5Io9uiJEkeZi0SyP/2Os6kqw2l9q+947t0Bk9mlPR8101Pz29TtxfpNGOTyfO91WkMqT5vOGO4eOu/ZzRsq9ed420iMTbvEm8gr98CD42DezIQN53mPSxnZOaQnk5m2U78t1iYdaHDLanBxsibyOjzTBBL5UvG2/xCK3BqIqpq8pfuAhn6+Uv7pQpxXyIo1nvx75gt6zkA7+DbwPOnEJVnPErzQL2gPCIRIp8fNv0CfhC2p2HI7F8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:BLUPR12MB0434; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0434; X-Forefront-PRVS: 0014E2CF50 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(189002)(199003)(77096005)(229853001)(50986999)(76176999)(586003)(48376002)(105586002)(19580405001)(81156014)(81166006)(8676002)(97736004)(4326007)(42186005)(5001770100001)(189998001)(2906002)(50226002)(19580395003)(50466002)(7846002)(66066001)(5003940100001)(68736007)(92566002)(86362001)(101416001)(7736002)(305945005)(3846002)(6116002)(2950100001)(106356001)(47776003)(36756003)(33646002)(2201001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0434; 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; BLUPR12MB0434; 23:5c7BcFRISBjJedOP3gA/uFy8jcIIZHFFuj8N29chJ?= =?us-ascii?Q?vAM6CsBV2MZJg3UtChKByCVbEy1f3+DKCgzmSxuAaMYl3kBLWLpMGEiH9EuT?= =?us-ascii?Q?aOl03WnA8g7iCgQCOF1IQeb5dVMQpphJUoGY+vNfUIR/uUHMefhdyMq6VbtW?= =?us-ascii?Q?k0LUnwhvCYIppopbl1RWBQocnSqnvKvQWIcaekgoknREyAwzigBu7gcgUwik?= =?us-ascii?Q?E82hxzsR7jdI01oBylhFJJsEdL4AdlHGbw/OAY19OIW8t/8jLXgFpMXOiqHT?= =?us-ascii?Q?TVLdp9bamcrCyQeNN343dex7EvScs85/ILh41w1nJRdiglBYDU2f9IV1UJFt?= =?us-ascii?Q?04Pt8DdYcrIKYsN0hf+SztR1gxE6yBzd8IoJDNQcwSH+NpQQ7mFNuUyeOTsy?= =?us-ascii?Q?9V0Yg6EXRka0F4f+tEABzt+XxzhOfyocrfHFfLo0iHsojqa0nYiXLeTofola?= =?us-ascii?Q?QSYFm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SmUhKpjEhxx6V1/J1SLo8VjSll5/Fp/VOfO54zUCrVEnjjZ8ZVvbqvkeaCKY/c0ApasNUw8ChbigNoua6kQcaXA2VTfVUQbA==; 5:QxFpc2eFAOJMIrJT/UPSwTnFB1nIQAHRadOWTQeKdZStADtlXLxaez3m9ieV4WeGEKxR5MU0VxnSFTeYd1t3qFS0Jlz1hoti+R8AvDN20l9PFKAuwkLsM3485rBTRf/CaLxxWB/CUBh27XnC7EFZEg==; 24:Uk1ZXx+G0jdvKRA+tmqmfrYLx2RMuVX3MrZxFcy3WuFDB1j2HKVnnXmhzU2MJeNEvgEDdAyMLJIxdBkAUeKgHHwaNkXoLuTC+M30XVkMglg=; 7:gH5BGZxDTe2qkeUvLWcTZrTgzhasruCUjvg1xYVNufI4TtRl3ULYN6isKxdjzeMLeziUh/4OE1t+9h7hBN4sIP7oHoXLZ1R2xzMy25DDwk5On8hfWZtIqCTZoN2C4TfZX2NoFPPB3JgEMxt/7gEOv4Y0diKo1F1Qyjcvar3o2Jg59Cb0gzGembOOtNOJ0Fx+FzRJmu5uuwy2Si33XmCJRP7F7wFN4da4LAOLN0cULIsOb93PB/l/q5kfu8vokZDd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 20:fqmOqram2bXbAmFesIjkOD36gawgy21REjNXqGzBtJOB36TfBRu/y1sz7d4luqTaZHz/huCuIN3kK0fjlwIPUxf7nNZeMNsUZTGDToTxf5Z5AIiYb/LKJueKu+OQHd/jKzYSlQOk+qRAMDTdE098Hilm0mL6y0qPN0g9H0jgFvHaeZlQax9rT4PDWikz0TByVfb/9JChwF94l7fNJEPPgUctM3wLFBhprZglfMBGUr+Y/lkAzg50irU6eqeYb0Cv X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2016 09:33:05.3053 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0434 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 | 50 +++++++++++++++++++++++++++++++++++++++++ drivers/iommu/amd_iommu_types.h | 1 + include/linux/amd-iommu.h | 22 ++++++++++++++++++ 3 files changed, 73 insertions(+) -- 1.9.1 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 861d723..e6a271c 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -4458,4 +4458,54 @@ 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 cpu, u64 base, bool is_run, + struct amd_iommu_pi_data *pi) +{ + struct amd_ir_data *ir_data = pi->ir_data; + int devid = ir_data->irq_2_irte.devid; + struct irte_ga *irte = (struct irte_ga *) ir_data->entry; + struct amd_iommu *iommu; + + if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) + return 0; + + iommu = amd_iommu_rlookup_table[devid]; + if (!iommu) + return -ENODEV; + + if (!irte->lo.fields_vapic.guest_mode) + return 0; + + update_irte_ga((struct irte_ga *)ir_data->ref, devid, base, cpu, is_run); + iommu_flush_irt(iommu, devid); + iommu_completion_wait(iommu); + 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 947c74a..623ee9e 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -824,6 +824,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 465d096..2094d90 100644 --- a/include/linux/amd-iommu.h +++ b/include/linux/amd-iommu.h @@ -22,6 +22,19 @@ #include +/* + * This is mainly used to communicate information back-and-forth + * between SVM and IOMMU for setting up and tearing down posted + * interrupt + */ +struct amd_iommu_pi_data { + struct list_head node; /* For per-vcpu pi_list */ + u32 ga_tag; + bool is_guest_mode; + struct vcpu_data *vcpu_data; + struct amd_ir_data *ir_data; +}; + #ifdef CONFIG_AMD_IOMMU struct task_struct; @@ -179,6 +192,9 @@ static inline int amd_iommu_detect(void) { return -ENODEV; } /* IOMMU AVIC Function */ extern int amd_iommu_register_ga_log_notifier(int (*notifier)(u32)); +extern int +amd_iommu_update_ga(u32 cpu, u64 base, bool is_run, struct amd_iommu_pi_data *pi); + #else /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */ static inline int @@ -187,6 +203,12 @@ amd_iommu_register_ga_log_notifier(int (*notifier)(u32)) return 0; } +static inline int +amd_iommu_update_ga(u32 cpu, u64 base, bool is_run, struct amd_iommu_pi_data *pi) +{ + return 0; +} + #endif /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */ #endif /* _ASM_X86_AMD_IOMMU_H */