From patchwork Mon Jul 25 09:32:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 72690 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1048102qga; Mon, 25 Jul 2016 02:33:51 -0700 (PDT) X-Received: by 10.98.16.193 with SMTP id 62mr28147626pfq.132.1469439227881; Mon, 25 Jul 2016 02:33:47 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mu1si26395721pab.286.2016.07.25.02.33.47; Mon, 25 Jul 2016 02:33:47 -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 S1752997AbcGYJdm (ORCPT + 29 others); Mon, 25 Jul 2016 05:33:42 -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 S1752885AbcGYJd2 (ORCPT ); Mon, 25 Jul 2016 05:33:28 -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=RmB9mfIVxTKnrttATGXGbbIDvsV5JG4RdlZyOtDd/Rk=; b=Pr4SAUxsvYSvwOIIaqlC7y+YzKsGVqjZQmpjnp37897mLtOEWDoblGaIMSX3ZV3ehjQZVzzG7JkxweF53NHUVaOloRj8i0xAxjinx/02A9wRZmCBQZvlQ0lbRoF4pFJZn0Yvt5DdJlx11HEs+wG0ID4DY1TKlDjgFPWxHGFu5QY= 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:01 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 PATCH v5 06/12] iommu/amd: Adding GALOG interrupt handler Date: Mon, 25 Jul 2016 04:32:05 -0500 Message-ID: <1469439131-11308-7-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: 6a0f7827-ee2d-4fdc-7138-08d3b46eadec X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 2:CUBuztLrWXFuN2FHBttRLTtOs/ZEx/e1nvPxnifR/rR/XFVuhMApBM6LzMdEENv0t/KKWfs7/xwvoALj6cYj8vGyr+MB/vGIlA8uRGqEkF0ivi4ovQ6Yd+dGdbH3ToHr7FhYewY9kcz5XEYfxYk7gMZVXBw71Xkr58ECS/kDv+vUs3STmH8YihP3FbHQdRK3; 3:x43mjSKIjnslk8AHMDfrqElQq3s+Kegb83Wrro00NTcN+GEasAidB3fyiuMVrTgGbpPk9nP+/vc7/a9H5JZJsSlecvjwONk62x6DvlQO0ZFZvukNAnWSTlsZc5YYQZU3 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90SP4YgHVBdSSwibSxchvR4uW/PNpvxtNjGaOxl7akGX21VyQ2GH3TaARIm0OA==; 20:6/nfFXgfqms6IBE8mOXIV5wBtpzrWU15suyE2Dl/Gl4FCwJWrZOW4Y0WrZnVOdqvv+/IpaGvONPjIpb5uB3+avBvQPW4uqbUOHhTMbGrarmsTY94nxq2D1QtZRynUONKrjoML+UXsNdu0b6tmNqLbdUjMbdro1iacN9bZ1LptPeyQ1TlkVOMhj0G5QI2VeNPDINh+Y3Ch5s0gcwy8cj4EfjeJvey/Gt9f/6RfB1Ad6Y0gxWqrx+LynZ1/BpRKA8wJD41FU6UzjV2gXrypAhvnW/gp846EAnowwISTaNvYXy/C2ZWd7H3dHbq4nsN3GflJ20w3RjGWFOunn9maBvdSvaSMgbbl3g99+zQw4VudpE9qOrixpYfDeM0sLe/6gavI90ufUL4eIV+IYswvT6uF7YVPfNdvc/CF4PlV1u5Nd/OwsYj7pJyrZSXmQJC5wMG0x7QluQ0ck05EAjkf9RLXLFpxIQ9w6QSebeMWV2qotbl2bUuDjbkAIAlBHqrf7ZZ 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-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 4:MsNLX1FKkvRj8G55FrzWeyhpGdXoAFSjAeXDygtLF41M9r3qraK4HIp7BwAo6SUjICqt7W37PXRgEA+s1hXu4HHI0Gf6Cbx+bcRIUyuBApHfJhLwKjru11n8plkxikhfkcIdvsmaastNRcKzP6Masi5c/RErhQmmNut1bVq4TYO1KQlhsJIF++WfKq09K+84VuQxYb/A3E9qE5ycKwvy+Kc+kp0skIJul0GnfXscWx8bK3DYb6eKI+dOcodFh8qQgJfOSx7INNzM1vK1np6UYRT+9Lxs3O+gUeE4Z6anuudilEPRAYaA3h1SejDxahqFekCuirBPG3S161PI0mraT4Iazj2jxPTlt5vF0A20yrY4yzVP7JgPocQ1WTTYQd008wRWdrHeWX0G2BFD9yKtnq7Z4xNbzvBGPz+z1dDNc0KXL9SxapVGThOWm9A2ntUp 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:lTcXtXMAWiIR6gwpBXkbEOD8yPXsgztXBkrVWk5PO?= =?us-ascii?Q?erBdCS6jwiBGLbcY6l6jNrBNsP0rtGcfEMQPE5wi7Ia66uXNwJ6Uv/jJFbqP?= =?us-ascii?Q?VY1NRqvWNIfbp/eXuj2nxuxxnwPEI+k5dVSOQVXhtlN52qW+hrAOH8bdJ9wv?= =?us-ascii?Q?wwIb9eLfJESFGqBgRdSb7FLLHhGHwD3keXC1yJzoAEgmBdTcue/tPiTvZZEW?= =?us-ascii?Q?hz6j3lzZgJWEkpuimiFNTrBTScYudepi6kygkK+dME8OJzecgggekKsRevAo?= =?us-ascii?Q?BZaCTCXTjm63dVJOS+u7FqTP2VH73L2ermYyP+SJskWg8iS0ymj8fumQyw6H?= =?us-ascii?Q?cH6nf+N9pywRp1K33PZ4Udj+fBSbXD2fYP/lc1q6E9XKqSNDn3jeTAL/BhRl?= =?us-ascii?Q?nkLckCJQl6YBXJjjDoHhtGKVu6JJXxKQS5hMMS4EP7BhWuPUj+CWMIz8Qh/4?= =?us-ascii?Q?xnveEqQCJt+/dRFz87UTXYfeTxOqhWSw5Jgijb5wmmIcgP0FrV3ap93c1YNn?= =?us-ascii?Q?I5126mDPmgquAONNSJ6N4SAF22om6rfCPIcGmXD27lZRgx3esjvOblHlu51D?= =?us-ascii?Q?fqgJW+PatGRK/YOqNyJDLPcuVzWIg1m5RhnnOpDhtVSSCCseYpY3H0opzuM0?= =?us-ascii?Q?cbgJccVQjtMfUaqq315hwiN1w83mlOVIZWt8xsR8aH+XfSO6fsPQFfxAx94v?= =?us-ascii?Q?WumAq+sIBXbQsLzWMeufiIzpO+5k0kqiHZS0uKdpqKNIa7XbA/a5HW9eVvBV?= =?us-ascii?Q?0hA00GBHCFElerKjAAmcpxnfu1y/vzLKTJgcNWzGLSCEQqS9PZ9CXpCbsY6t?= =?us-ascii?Q?FK3HwpO0Szck9XeHiapK/6NKilOEbUfUoKeaddIBi52V2JrfUz/UI9N4X02G?= =?us-ascii?Q?GpdIepviLfp0k5MiRKh7hqKMAIVn8O49ZGlrt3hIkWGXjcMXBkg4zfiTuusL?= =?us-ascii?Q?iooHTlWkOo2J+xEkluPotARyEMd6q6Aek3jNp12OzFvvpeORs4EOg1F3OdYw?= =?us-ascii?Q?MwUZwRxwyFqHPnFNhM7c698RKB4q35sS3whhpCVD+MGQn9A4mWQXnSgD+X5t?= =?us-ascii?Q?n1J3NZahUOpkj5PYKdhNRKfa5C+Oqo9UGJMrnONjCTD0e2RHQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 6:y1iirYwCuDd2WqmS7F0E3y7z8Pm3UG8GlGydro1lwleaOGcIm995/QVI2utg0nhkUbuDTSyPFacfeOMOtKLNNTjRqhgmD0XtNLmVDaycinkG//0dWLLGbWBLdlmbod13QoYpyWiOfxj5NR29xP8ne+0bZVVYkedhL4fChBRVNYQTrQ75QkPrmcDEhAvCUCfamRk03HsTHU85xvOtD2TkbSlufC19Z1XP7NW2PYOtt3s1GgKkstg3eRLA9uWK5uKjaE2ZoJ2S4/QeYvBAOuL4Eie2UV3CSosnoJoPH39hk88cCwYeg1XGhZ5pecDIwMqjHTgfT4MQiIBXw8sOU+/QYg==; 5:yGWkIqY5HeQFwOMfFP9xW8a7uxum9xUDg7oxVDROy6s1QWDpiy2rbEJa4Vdg7VaUuRjrwN5N0r9MGa4S9WnI9fM0QLSe+kqAuP40sq+T+tHWose3Hs5dweZJhs0XNOU/PeJrChw3H1Hrzcf815MBag==; 24:lmTpvOW490PEDb+XOUcxK6uyZ6eP0UCxevv3sl6DMmfYvCIcfBTt9IvEj8ndPby2YEKAg/yDYigEzrDCn2z3CFAE2EquJH0wbGXYE3cXnls=; 7:8R6/Qe1gHS6eCP+u29iiDDQg520N5IpfOzG2lS2a9ucIrbqquYueyxeWK4fIt6YhyWJEnB0zQnotVYT/7TS85Z7pZOQSmv95XGj4hj9X3akibxFU4e/lUVVBL7PO7wKNFnhUfhQRXe8/qMtNyraDohO8l2vlwYNerfihSafgVllHo+6CDT1e5q7DlSZDLgyLktAgLQalsEgb25GSvIZVHWHjReNPlNnWWrZrjnCtHYDVSUeW0Dnd5zZ0b4R0+NFL SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 20:psveRXCw7LxOHLCDM1ZXIM2HFNATyWQc7wloA8hhF+50JdFcqnEoLL6RJNefl0b9QpNheIIuHuCTzQze0Q+PjVtbTot+MSjz4kLRAgnGcaVsT47ymBJHGwCk+m/8g8iy6QnXm64JlRHFML4/8MHPx9jyhxoW1bHIRVBi8Odenj0CcKHeo8Y8xxvoPWPVwP8KnocjJfA8eJhzk9OsYWFokYMQC05gY3gCO57Q5U2fVIA/91tH/4isNsNmW+niV3JC X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2016 09:33:01.8284 (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 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 | 77 +++++++++++++++++++++++++++++++++++++++++++++-- include/linux/amd-iommu.h | 20 ++++++++++-- 2 files changed, 91 insertions(+), 6 deletions(-) -- 1.9.1 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index abfb2b7..861d723 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -741,14 +741,78 @@ 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; + } + + /* Refresh ring-buffer information */ + head = readl(iommu->mmio_base + MMIO_GA_HEAD_OFFSET); + tail = readl(iommu->mmio_base + MMIO_GA_TAIL_OFFSET); + } +} +#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 +825,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 */