From patchwork Thu Aug 18 19:42:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 74202 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp71592qga; Thu, 18 Aug 2016 18:22:40 -0700 (PDT) X-Received: by 10.66.181.16 with SMTP id ds16mr8943331pac.102.1471569760072; Thu, 18 Aug 2016 18:22:40 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s24si2114728pfd.86.2016.08.18.18.22.39; Thu, 18 Aug 2016 18:22:40 -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 S932234AbcHSBWF (ORCPT + 27 others); Thu, 18 Aug 2016 21:22:05 -0400 Received: from mail-bl2nam02on0047.outbound.protection.outlook.com ([104.47.38.47]:32310 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754727AbcHSBVl (ORCPT ); Thu, 18 Aug 2016 21:21:41 -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=O0YmOm5nrzu3c1IKEHCBaQ7bt50EGcYy0bmzODvQ02E=; b=zQsyZd0HvUlOK8CbEoLQe7ak0rSibRHoMYfPCKS9PN/WA/rvlEk3o2mycBwleQn7poaz0WpGXAOmDMLfaPcHCuGyZjjAdhzVvLGT/x5kjGQUsUlfe7FFMqTeHgkQO9dTFa0CwphSMOjURBroLm2PiwgC80trRNApZfn/CkiLovs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (114.109.128.54) by MWHPR12MB1453.namprd12.prod.outlook.com (10.172.55.22) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Thu, 18 Aug 2016 19:43:43 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 PATCH v6 06/12] iommu/amd: Adding GALOG interrupt handler Date: Thu, 18 Aug 2016 14:42:38 -0500 Message-ID: <1471549364-6672-7-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471549364-6672-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1471549364-6672-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [114.109.128.54] X-ClientProxiedBy: KL1PR0201CA0016.apcprd02.prod.outlook.com (10.167.53.154) To MWHPR12MB1453.namprd12.prod.outlook.com (10.172.55.22) X-MS-Office365-Filtering-Correlation-Id: d6edeb64-c232-421d-a2f4-08d3c79ff786 X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 2:LNL97XgLOwJyF/l2tqT3io2rEnvPHFsOumUdTxEY5Ut4RICCU/dc6Ja7ZQJvPgqmR9tUKLlG+N8mBGOtDbweU6Cv0ZGjAL7xa3/rbHEuC9BweuPfh1zDmk4nNs0+8HuNsU9qlqru6w3jcczVCk2dmAigflavUbCsNjChEemM11CUlLHDhrxLWvKKFUMqWFZk; 3:CHO0Qavk7FUeUlU/n6GpohpoO457mYir1tEohkCKtrascVctnE0r/4dJRcsXdeg2bzRTetPoL0YyCrBpQE2Imq0fEyRCbI33shVW/nqcZT5ltLbGLpzljtXyXt8yVjWA X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:MWHPR12MB1453; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 25:jK5hhum4n0hlYSGUXFBD3CDdo5MeS7pOdWPw5t6eEWruDZOePJPrbUPTg2h7oaGFFT2pP5XCSmnkfDQiKNYdzoT/rhZB2aaht5LL19hSNAJkPaPhPv+KwBHrRjgbX8YwVReT+AJvlqdk5QrjHShgXecQaYgOlEGW7CjarTn0QNyyHMTrstEwH9d+gOEnzK7jTYwg2kGMBCX4DXglBPIN5FGlE7XIUw94vOErpzv1NbZU4qXAAiUIoasI8n4sjwGj/mhldukyomnHV7bhu4sstBSay8uetQONLypGuU0nGN4rUgNeVNcvLc+znx2mBQDzDNGHjgktgqVmXCVmp005ymEXhcNgiWrz49GhrDRnV2edCbsB8jEr/g/A1shJ+jFXDAK0xOc+cQPc/yZ0wfyzdQiSFV61jpH3bVr4FRwUh9N+b89Xm4VjOx72sP3anrAj8wQLz5LZhLk8PpmQWg3JtUcW5zscBzRbioKfIXhs6QD95siOQd9Um8B0kzV1VvjyHJ9v5Q2I0RylEmuHtAxS22QltPejkV56cUDKCRUaxtl1TZpBv+aADLiH7kPVK/IKUfm2M7JaLsrqe4vQNYJTouiGxHc056I2Jrx/wMY+IIKiAz1WCzKEbqwq2k0PH0oqYVOuINZAEYcQNWMD4fP4PRKN1kFvVhhT4laRD+lErgSG7IPaVcPnSlUTAirYTWc6buEplfVPQRhcEkWCH4FPYFAL4WCKKZw/izCr/8futcjQTxp96txzzgmDaWgsbe7DX8pyGHQuDSs8k3WMFnJb4Q== X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 31:3n3zmnLYhAxNnAsaxOJLJJAtrfaza7lNP/7nZpgzt3E/ODq+MJbb6GhLKAU7K7iXdeW4JOFlfBqMyFsYLBNaCzZlUpDD0Q3Tu9xiNpLVYbYTc2N31VmgqjLhLVted2rU9+lRD/aTXFE5HY/QOApopJk4WcJmXyd36IvYkS5hrRtRBkpnz5tPDTy4O13m7toWergb/8vbmPNEmIEHz1QkUnrRU3Z8yIIAHMBFkkZN1Hk=; 20:1+e7/hUnrzXF9hLPo5UX8iunJ+UVqO0lHpEgSyO0h+sudIzjppBDNNbcLkzFYy2UF7bFORpXfi697EaDeTj/0ZR8v5sLBz/ia71cZ+/OcZL7wfW8QopEI1MuUY0od65lErEYXmR2LP2rGQbJUqT4dRPOZxcHLrIAwB9GO8lj1lYQ0h6Ys94t7b5UWeMzBSVJYEdBcESeKNZ4LfbXVBaRJ/ODGk0oHirLjvPVf6dVtNnG5s3mHCoEY9VpQN5NAGI4g/UK+Atn2vKt7q3pi+Of7JSib924Is3Ny1v3zySXf2KfyfD2GkLLcmpjwYFfg7QwU8X914wUhqEXM5ysIrI0W45Mn/DLPY4eSSYoI7OofLODihMzd39/WRfg3z0R7mRwk+cNOGOVz0ft2SQnj2YqiXlIFKWU3d5ApMYaQLkNoS6mu1jbtMbe3bm/H26Qw60z8+HTM2OQel9eiCMVycMfSiZBayxBqv1kioshTzXPdWlOPIYidgvu1CipEiaVPtn9 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)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:MWHPR12MB1453; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1453; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 4:v/recOlSVpGPDUWgNJ8UOMVWhNZ4bIoEAxwXV99xXAm2scnTkcWIuvqNdGLRWL0QGM4QHrp9KzhOSlOwZgCNyt9HPY9uV8Rvj9iri/WI6K7RmzEkFEX6R32hkQVBJSSvb7X9jr79J4E9MlclcEQk3r5cM8KqgKFXhNerkBixbaYuVpZHBWuNlPgr5nMXqnmNhzHIucAri9ZEXalIZtco17rxWyzlj2Fpx/Xni9w/JY/daYohZNkjrU4fv9vmfCXFYvzzSXUCMTJYzUT6fJgamZVdODuHpwFslcN9UeiUakwLxcX6sZ3C6+EEzj8CZM2bQswvt7K18wN7x14cc+vXq8EGxg/7y64BdIQrvX5N9wcr1DI1vzddvtA+G+gamzQFIBCElB0z6vsOlyXbkwEUQZCgRKQuSTvcDgJVcAPJMLkU4/ayJrZALv5xo/Xn4/Ew X-Forefront-PRVS: 0038DE95A2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(189002)(199003)(86362001)(42186005)(50226002)(19580395003)(586003)(68736007)(92566002)(3846002)(6116002)(189998001)(105586002)(8676002)(81156014)(81166006)(5003940100001)(47776003)(5001770100001)(2950100001)(97736004)(48376002)(77096005)(50986999)(50466002)(106356001)(36756003)(2201001)(305945005)(19580405001)(76176999)(7846002)(7736002)(4326007)(2906002)(66066001)(229853001)(101416001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1453; 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; MWHPR12MB1453; 23:R14pGw9bGHHqiXO58/lIsG4NVfMAff4y0bq09pD/f?= =?us-ascii?Q?kVSaPf+QWA75j4jqyET/RGiLTYh9FogN6Lb6F1cVoAjfk03WpyfAtkYw6fyT?= =?us-ascii?Q?HeI4W9bgfAuuVtjUFH4DEJXo7u07VGd+w8CxFLT1Zn7cC/BpwjmDAHzndeei?= =?us-ascii?Q?wSHUhhMDbLkqT+HTl+dW7kOj1o4KRjfy6h7VVno2zsUoxBI1YwRwFFliYK8S?= =?us-ascii?Q?tsWhz2ieUC88DD/V3f/px85Fi/bbgG/jGkTBb+90Aen4kFIitI/y9juEJzGl?= =?us-ascii?Q?0ehGqsZmCsPd2+yj13TRnWUzw9o9pHTqp03UhCwAqfwsubdfCmFjM69vvLVv?= =?us-ascii?Q?hqaeSR9JgmRNXF7M79zYEb3goQIplt9YS0rJ81eRGjY1YxgUs+vFV3mhyfH5?= =?us-ascii?Q?Nx7XTptu1uY1wJBBPycD3/NJmkRyEWuVFeb6uJ/o15MoKOrV+stcFobX+X+u?= =?us-ascii?Q?9kJObj7ddDGegRG0Rg907QxA8BzhJg2uFe0qByzOfRG8DNyBcLStpaFnljyt?= =?us-ascii?Q?nqpNUZ0YMOwArMV+p94JnzWztXy8rOV9/LoOMcFA48L41qCYOCmzV2q2PGQz?= =?us-ascii?Q?ZA4j8qUGi6G/8XlTKv/yp8C7oH2AFeq8toXQc6xCK5b4Degq2mJiVPGun9DQ?= =?us-ascii?Q?HTYGWObiipvlIJUHiUD+9dTEfD3jbAAq7FrKbqyVGKOO1WM0kwXKobadh9Pr?= =?us-ascii?Q?fK642qzhiY/fs3ldguP8XnspZXc244C7IyR7f8InTuMrLHfO2gPK58FEqs5C?= =?us-ascii?Q?eTzobtVK7fERtRnG6TlVdnWaizhrtQyi3Oop6hP/QXxfBBQ/HHpIkSGajlr7?= =?us-ascii?Q?tXK0MayIIFZZflZTXrh0aNxAZQ6yToyUNkYE/AqccQe0zCqj1qM7Bnjjwmxy?= =?us-ascii?Q?NtWtOsJV2YUy8sefm4Fqyk2RnDMujp14E0eXtN8+QUqces+CC2tsxh0Ibj69?= =?us-ascii?Q?sjK8lnbMK3YWBFgHZIpNCT57+bYxy4aHCj9jc4entm24ELLNZunZRe/19fH6?= =?us-ascii?Q?aGH4En0ztj8bF1ift7nLgboEbaJwogsluhebX7c0nkcfxj88CVFMTCMkVTE6?= =?us-ascii?Q?harq3z1vENIB8KeGmA1Z7SNVTMa?= X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 6:xt+mUy4bPEnipq0URp7+somyc/ToNZfHHAcvDeoxxRqbfH7f9DMEGRctQp63TYMJmkaVZXevJoQED2hs4Tl/PAgtT8CT/CVJJlgGhi5yzUf/cJ015JCUX8bidjvJUJb6L8zwbXz1xs8YK1uCUjEVIAu3sxOgv9aastP1+dZBHGYdHdFfd3fFwawv01PvIH5ZFz+yrBYB6v99L6nzJ1+dMP+0kcPYlSTwNLozT0Qyu8kv7okM4gO3J6ddmQdpad7J8e+dG7KLxSqwYth+ngC8OQUxsTMd+yeDiGBFe23dAKSzaY/9a5fuOksB5QNGpkA6kT00YVPmBy+okeEjz7+aPQ==; 5:5CLHmt4xFfNNbUfDdJutc5mNx70ZHbG2L/yp5RBBQAD9A9SiZez9mwMnB3Eu9pD6Me9jVRP/GdecDZGs1wAQVRhn0JXUgMoZGktOGddmcrc1jZjviWcqO4w1HMA+s4DL3aPYGgtyqIX7MHDXkfRxpw==; 24:IorfCIINgixVmphcKEJJ1suXRwgLvefmEXwct957Jl0S5CzFyklmRLmQ3+hNGrfJM1LzGpvNKfpAv7oKD1+3SyTUaA0VISK52x9FWQCxtC8=; 7:qa3cv6208eFpV6DdaKen3AhE8qi3385Xzsj18qu7TC8ZeKqyuKBLGCij3qv1mMIfaXolHLUFjg4wffNs0Vd+E4Hf000OpyqIjKn7z6oHmKGjllUicYv6c1Uv+wcOa2ljc+YQSDxtUZtA66eq+sWBXJYHnf8B7KBs3+IL1UCyIXPGoNO9iAVtxKfYk/ECW2XJLgZZNhLJuPX1zb24Yuv+FwHWgAVUDoBkYgSCtnHTYc6RHmpLI0cc7W73lVfdxs1G SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 20:xhXhnraMG1gDMu5tQ8gP7TuhQTyvC16ozuphzLaLF86RgITeuOzczfYfgH09qqzIG8g8wi/WRvg4rziYTXN1PCiJZK0bO5D4shG9oKGvcdD/XohUHM7f+GEyDOs5bpuvC88PMeo20lsL+X1YOBdB1nrWPgby1zRg7unbTSzNDMhkKr4HAxjgOdQz7pMVnIZ76w8fAskPEbNReYPIpwHIg9EUUbxVlc23e9hDh0NE+qOkRQMPnFT6xZ0HGNwQR3LP X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2016 19:43:43.1254 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1453 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 abfb2b7..fd5ceff 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 */