From patchwork Tue Aug 23 18:52:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 74517 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp2252794qga; Tue, 23 Aug 2016 12:11:04 -0700 (PDT) X-Received: by 10.66.9.42 with SMTP id w10mr55694376paa.34.1471979464764; Tue, 23 Aug 2016 12:11:04 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si5117374pap.189.2016.08.23.12.10.56; Tue, 23 Aug 2016 12:11:04 -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 S1754487AbcHWTKe (ORCPT + 27 others); Tue, 23 Aug 2016 15:10:34 -0400 Received: from mail-dm3nam03on0044.outbound.protection.outlook.com ([104.47.41.44]:55616 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754041AbcHWTKa (ORCPT ); Tue, 23 Aug 2016 15:10:30 -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=SOqwoymWOBqzLhC413S9gcukFOD7CjOwSA8WHfnidoU=; b=4o0lp45mRkJ8ZnES1AA7g1mz/tkwOCF/2620O9xc8OdpoM8C+Yx940K6WgCZ4uYYxAs3sClcZ0qWUESwqJpIkPpQbZoYI15jjJw1nsPUb7hZlVZr0ibebBOlWwGKKL/rLBflTyfIeNpGwVmtkfoY4yCegAWhMVVhAtIHgtOTGEI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (114.109.128.54) by DM5PR12MB1452.namprd12.prod.outlook.com (10.172.38.141) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.21; Tue, 23 Aug 2016 18:53:26 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 PATCH v7 06/12] iommu/amd: Adding GALOG interrupt handler Date: Tue, 23 Aug 2016 13:52:37 -0500 Message-ID: <1471978363-13756-7-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471978363-13756-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1471978363-13756-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [114.109.128.54] X-ClientProxiedBy: KL1PR02CA0053.apcprd02.prod.outlook.com (10.167.54.21) To DM5PR12MB1452.namprd12.prod.outlook.com (10.172.38.141) X-MS-Office365-Filtering-Correlation-Id: 038b3d51-6a16-4c4a-9a73-08d3cb86c584 X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1452; 2:8ChZMq+QXEk2MHOZoPYZYf/wZmCezN6faQrIAUnLDhJWNa3HqoK5aCsfnG/Uk3hMrVVeNpXZbL3oZYmuQ21cHC8Y7VgZdNHKKFEmkFO+bDZQyBkDLoJ+QCj5XRd+JpL6utIs+BnyQGbRVhWyaN05brvrR0stTjDiLsUiy8CANufbTNJGom1HJLQABXCHu4ob; 3:S/9MViLTqvH0pV4MPtPVdppT7pj4cLL9XYzKoH7jXS9uXsSpBDAgw7MxCvUNLWQ8fgF29TWaFYH6YhlOTGV8YPFgClMSGh1i/dGdz06YR8uDSIWWjotxPnYWILAH0HG6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cdg0OeB54y9l//l+SnZYJTWwvzeojnDOwJl/aGbh2UidzOevkpWgqFNCd4Azjzuena4QrF+6wr2+HwxHrFl4/tYGzgctoqGHQ5Lg/ARWN9KsXUgAoFMuhXVbMt6ICbWDuPRqBy1jQiisD4vQ90/HUrsjbGNEXkoAFyZTKA6ZJqwLoD1owKz9aQWI5w341HYayIx X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:DM5PR12MB1452; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1452; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1452; 4:aIfvQ7uBYbWvPeRaHP5AURGoeQQcKf66C/ezGLsIzP5bpyGachaBpoV1RKfkLmzWA4WNJwFuYtdqkngaiWRFXrrXULqzXW5e4BLIULTebkuF/IGgL13cIldQdcd5i0Xw3QvIIr4DoZUKOjEHefk4C9kpCnVHVLxTPHwpAsnzRHYnr1W3q3i9wT+XNxYdeLNKbdAQ+5ymXgZQSmLPJ417uAhMDwpow1/U+zGKtiNOx8+sgW3stZoPQvAqmCRkJ39vMXW/SLAJNFxY6XTAFtKKhHIoh08UotTbso4mHieUlsHZF4wC4hdzAWR3Pl9GUF+Pdf/I/KWxu3VhsjgdYOi1Q7CZnOLYzbyyqlxSw9PDeDJDS1djeDFU4nYPoecFULN+tlKr6SCEhUdI1PnHSdiIcv76w9InCuffQfrdo6uz9S0wEP7FI8dgvK2U+k7zeymO X-Forefront-PRVS: 004395A01C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(199003)(189002)(42186005)(76176999)(101416001)(48376002)(50466002)(77096005)(5660300001)(92566002)(105586002)(5003940100001)(36756003)(86362001)(106356001)(66066001)(50986999)(5001770100001)(19580395003)(19580405001)(50226002)(97736004)(189998001)(229853001)(3846002)(2950100001)(47776003)(8676002)(7736002)(6116002)(586003)(81156014)(68736007)(4326007)(2201001)(81166006)(305945005)(7846002)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1452; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; DM5PR12MB1452; 23:PUxSaJydCkKYR81Upvnwx4Wg6AjykVYkZNM03tu4s?= =?us-ascii?Q?Vj1YQKgTizi4V3QVZ0e+BlTDKACM7w8iXDzBL4N/ge/YhkaCqPu9Ngf93Wf4?= =?us-ascii?Q?5tp0B3z0vhrVo83goG2Zt46bkREGKrbdociKhcVquMAPgLtfKAh6t2Cx8cJp?= =?us-ascii?Q?ptUT1CquQ6ZoWVtcpu2RIC7td943fadqdy8MrO6LmHNrysGHgmbXKGoYUeft?= =?us-ascii?Q?zGF1Vthsz/uU1vpzGzxQG/i1l09Z09g9MIQM4fcXvgCivl83WWJVZBZ6BRM5?= =?us-ascii?Q?zYguBJlbFLfpD1nB0K+7qCEZqUeoMAIc146zjDl3sFBR+Ms+jvfR0rl52dsP?= =?us-ascii?Q?9GgGn7okz0E/pYOwNfDsAzZrIJCIBmb0d/EBzmv+Pbl2HZuLu7lZ+JPNqAxq?= =?us-ascii?Q?+YVe7LEi5KorsAKXinrriZWc9UeAKIBvgC6sf20fQD7quodvSrb3iQDh4HLU?= =?us-ascii?Q?BAiQCXs/ch8Y2A++eKXoOTm18tTiVPIyZbmi3xNbWwSez9e8wCEWBCMONTup?= =?us-ascii?Q?dH/SrK8HKt1vKuZ0EYf4eD6Y2T5/7w3696mlfBc52mSD95gGG2k0wqGltAwA?= =?us-ascii?Q?SwW+83NTRtmzk5wPKta4gxXLZMbvhB18VHyzWZDFSNqngMG4tzW99RQiLwXC?= =?us-ascii?Q?MyWgBvc87qTTzkvO/7J/SSjHk79+B6o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:x78b7iE+NngoL+xhK+qHb56RQk7Fk8UKuwav2dds4NNHnNcZcRoZKtGwMHhK8rHqz8m+AnNqGyTu04WFJfQvUQKAdNNK2OBXt/nUQ8/T7Do=; 7:p0LVCvDPIq+F6eV5uprzKfMKueuXuSmSh2atLZeBApxv3hOMfqn0+UZoXBSXUzA8CjGipyBJpvbrmqSNjHSDYxaNMlZ5NOtF4wq30K2bbR8gvkY2/oX+vWymECStiojlnkxYncL/yk8IUrkEshwQXhNAStuUGXtPcLyj/5EMAAbqIZHy/fi93RjwOJde0uNs6qrF+6VfEx91VvD4rWm4Ae28EcIraSK5l2s98dmMPh3VQsP2HGUKwZDWWL/whNEA SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1452; 20:+jT+IHAHN5XyfiT2WC9Ie7MS11BdW4viZhfVA0HD3pkx6KDs5OUw05MzufFqrebZM31Pf+1EAimhhS5cZuUM2KIXvmT5ljLRighynf63Nfby8Nr7crTyYDp9wu69pH0lIQqCG6A+7eoYcec213F1OYaLWeaSXboEfnV9GT8+nk7IJ3Nym3/oonvdbO4EY190IzvV0Rk4U6jvVvgC9yWJxVHxu8NteZRPwsL0AIOR229OBzNYssqf/lgHeJi40/Zg X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2016 18:53:26.0465 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1452 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit This patch adds AMD IOMMU guest virtual APIC log (GALOG) handler. When IOMMU hardware receives an interrupt targeting a blocking vcpu, it creates an entry in the GALOG, and generates an interrupt to notify the AMD IOMMU driver. At this point, the driver processes the log entry, and notify the SVM driver via the registered iommu_ga_log_notifier function. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd_iommu.c | 73 +++++++++++++++++++++++++++++++++++++++++++++-- include/linux/amd-iommu.h | 20 +++++++++++-- 2 files changed, 87 insertions(+), 6 deletions(-) -- 1.9.1 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 52e1e4a..8df3dbf 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -741,14 +741,74 @@ static void iommu_poll_ppr_log(struct amd_iommu *iommu) } } +#ifdef CONFIG_IRQ_REMAP +static int (*iommu_ga_log_notifier)(u32); + +int amd_iommu_register_ga_log_notifier(int (*notifier)(u32)) +{ + iommu_ga_log_notifier = notifier; + + return 0; +} +EXPORT_SYMBOL(amd_iommu_register_ga_log_notifier); + +static void iommu_poll_ga_log(struct amd_iommu *iommu) +{ + u32 head, tail, cnt = 0; + + if (iommu->ga_log == NULL) + return; + + head = readl(iommu->mmio_base + MMIO_GA_HEAD_OFFSET); + tail = readl(iommu->mmio_base + MMIO_GA_TAIL_OFFSET); + + while (head != tail) { + volatile u64 *raw; + u64 log_entry; + + raw = (u64 *)(iommu->ga_log + head); + cnt++; + + /* Avoid memcpy function-call overhead */ + log_entry = *raw; + + /* Update head pointer of hardware ring-buffer */ + head = (head + GA_ENTRY_SIZE) % GA_LOG_SIZE; + writel(head, iommu->mmio_base + MMIO_GA_HEAD_OFFSET); + + /* Handle GA entry */ + switch (GA_REQ_TYPE(log_entry)) { + case GA_GUEST_NR: + if (!iommu_ga_log_notifier) + break; + + pr_debug("AMD-Vi: %s: devid=%#x, ga_tag=%#x\n", + __func__, GA_DEVID(log_entry), + GA_TAG(log_entry)); + + if (iommu_ga_log_notifier(GA_TAG(log_entry)) != 0) + pr_err("AMD-Vi: GA log notifier failed.\n"); + break; + default: + break; + } + } +} +#endif /* CONFIG_IRQ_REMAP */ + +#define AMD_IOMMU_INT_MASK \ + (MMIO_STATUS_EVT_INT_MASK | \ + MMIO_STATUS_PPR_INT_MASK | \ + MMIO_STATUS_GALOG_INT_MASK) + irqreturn_t amd_iommu_int_thread(int irq, void *data) { struct amd_iommu *iommu = (struct amd_iommu *) data; u32 status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); - while (status & (MMIO_STATUS_EVT_INT_MASK | MMIO_STATUS_PPR_INT_MASK)) { - /* Enable EVT and PPR interrupts again */ - writel((MMIO_STATUS_EVT_INT_MASK | MMIO_STATUS_PPR_INT_MASK), + while (status & AMD_IOMMU_INT_MASK) { + /* Enable EVT and PPR and GA interrupts again */ + writel(AMD_IOMMU_INT_MASK, iommu->mmio_base + MMIO_STATUS_OFFSET); if (status & MMIO_STATUS_EVT_INT_MASK) { @@ -761,6 +821,13 @@ irqreturn_t amd_iommu_int_thread(int irq, void *data) iommu_poll_ppr_log(iommu); } +#ifdef CONFIG_IRQ_REMAP + if (status & MMIO_STATUS_GALOG_INT_MASK) { + pr_devel("AMD-Vi: Processing IOMMU GA Log\n"); + iommu_poll_ga_log(iommu); + } +#endif + /* * Hardware bug: ERBT1312 * When re-enabling interrupt (by writing 1 diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h index 2b08e79..465d096 100644 --- a/include/linux/amd-iommu.h +++ b/include/linux/amd-iommu.h @@ -168,11 +168,25 @@ typedef void (*amd_iommu_invalidate_ctx)(struct pci_dev *pdev, int pasid); extern int amd_iommu_set_invalidate_ctx_cb(struct pci_dev *pdev, amd_iommu_invalidate_ctx cb); - -#else +#else /* CONFIG_AMD_IOMMU */ static inline int amd_iommu_detect(void) { return -ENODEV; } -#endif +#endif /* CONFIG_AMD_IOMMU */ + +#if defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) + +/* IOMMU AVIC Function */ +extern int amd_iommu_register_ga_log_notifier(int (*notifier)(u32)); + +#else /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */ + +static inline int +amd_iommu_register_ga_log_notifier(int (*notifier)(u32)) +{ + return 0; +} + +#endif /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */ #endif /* _ASM_X86_AMD_IOMMU_H */