From patchwork Fri May 6 14:24:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9033691 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C3B19BF29F for ; Fri, 6 May 2016 14:26:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CEE0F20218 for ; Fri, 6 May 2016 14:26:54 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C55BE200F0 for ; Fri, 6 May 2016 14:26:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayggD-0003oH-LF; Fri, 06 May 2016 14:24:33 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayggC-0003oA-34 for xen-devel@lists.xenproject.org; Fri, 06 May 2016 14:24:32 +0000 Received: from [193.109.254.147] by server-4.bemta-14.messagelabs.com id 12/59-03277-F19AC275; Fri, 06 May 2016 14:24:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCIsWRWlGSWpSXmKPExsXS6fjDS1dupU6 4QcM3VYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPz3FXMBfuNKt7vqm1g/KzZxcjJISSQJ7Hz 0UY2EJtXwE5i07WNzCC2hIChxL75q8DiLAKqEgu3NoHF2QTUJdqebWftYuTgEBEwkDh3NAkkz CygLHFx6mqwEmEBM4m9LUuYQEp4BQQl/u4Qhiixk5i+8iDjBEauWQiZWUgyELaWxMNft1ggbG 2JZQtfM4OUMwtISyz/xwERtpJYP7mXEVUJiO0qMWvNUrYFjByrGDWKU4vKUot0DY31kooy0zN KchMzc3QNDU30clOLixPTU3MSk4r1kvNzNzECQ6+egYFxB+Ou7Z6HGCU5mJREeb8X6IQL8SXl p1RmJBZnxBeV5qQWH2KU4eBQkuB9vhwoJ1iUmp5akZaZA4wCmLQEB4+SCK/hCqA0b3FBYm5xZ jpE6hSjopQ47yaQPgGQREZpHlwbLPIuMcpKCfMyMjAwCPEUpBblZpagyr9iFOdgVBLm9QEZz5 OZVwI3/RXQYiagxe/naoIsLklESEk1ME7wrp5q/3zV8qSCv9V20aHPpkdrLb2sYlXycyqviei OGbrc6e3fa449OMG05OQDuc2XT/7cqXjv1CNNEaekqndTT2coGzA4+M7++aXSXvLzyaWs4bZW V2u/5z69FWvUp+zwMkDvt6vOIdHH70SuHNhWdT3XJfCs/xljweI1vhkLNj/o2HEpdZ8SS3FGo qEWc1FxIgBsKjJKtwIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1462544668!40006847!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 53213 invoked from network); 6 May 2016 14:24:30 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-10.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 May 2016 14:24:30 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Fri, 06 May 2016 08:24:28 -0600 Message-Id: <572CC53C02000078000E9182@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Fri, 06 May 2016 08:24:28 -0600 From: "Jan Beulich" To: "xen-devel" Mime-Version: 1.0 Cc: Wei Liu Subject: [Xen-devel] [PATCH] IOMMU: don't BUG() on exotic hardware X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On x86, iommu_get_ops() BUG()s when running on non-Intel, non-AMD hardware. While, with our current code, that's a correct prerequisite assumption for IOMMU presence, this is wrong on systems without IOMMU. Hence iommu_enabled (and alike) checks should be done prior to calling that function, not after. Also move iommu_suspend() next to iommu_resume() - it escapes me why iommu_do_domctl() had got put between the two. Signed-off-by: Jan Beulich IOMMU: don't BUG() on exotic hardware On x86, iommu_get_ops() BUG()s when running on non-Intel, non-AMD hardware. While, with our current code, that's a correct prerequisite assumption for IOMMU presence, this is wrong on systems without IOMMU. Hence iommu_enabled (and alike) checks should be done prior to calling that function, not after. Also move iommu_suspend() next to iommu_resume() - it escapes me why iommu_do_domctl() had got put between the two. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -337,11 +337,16 @@ int __init iommu_setup(void) return rc; } +void iommu_suspend() +{ + if ( iommu_enabled ) + iommu_get_ops()->suspend(); +} + void iommu_resume() { - const struct iommu_ops *ops = iommu_get_ops(); if ( iommu_enabled ) - ops->resume(); + iommu_get_ops()->resume(); } int iommu_do_domctl( @@ -365,34 +370,28 @@ int iommu_do_domctl( return ret; } -void iommu_suspend() -{ - const struct iommu_ops *ops = iommu_get_ops(); - if ( iommu_enabled ) - ops->suspend(); -} - void iommu_share_p2m_table(struct domain* d) { - const struct iommu_ops *ops = iommu_get_ops(); - if ( iommu_enabled && iommu_use_hap_pt(d) ) - ops->share_p2m(d); + iommu_get_ops()->share_p2m(d); } void iommu_crash_shutdown(void) { - const struct iommu_ops *ops = iommu_get_ops(); if ( iommu_enabled ) - ops->crash_shutdown(); + iommu_get_ops()->crash_shutdown(); iommu_enabled = iommu_intremap = iommu_intpost = 0; } int iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt) { - const struct iommu_ops *ops = iommu_get_ops(); + const struct iommu_ops *ops; + + if ( !iommu_enabled ) + return 0; - if ( !iommu_enabled || !ops->get_reserved_device_memory ) + ops = iommu_get_ops(); + if ( !ops->get_reserved_device_memory ) return 0; return ops->get_reserved_device_memory(func, ctxt); --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1241,16 +1241,15 @@ __initcall(setup_dump_pcidevs); int iommu_update_ire_from_msi( struct msi_desc *msi_desc, struct msi_msg *msg) { - const struct iommu_ops *ops = iommu_get_ops(); - return iommu_intremap ? ops->update_ire_from_msi(msi_desc, msg) : 0; + return iommu_intremap + ? iommu_get_ops()->update_ire_from_msi(msi_desc, msg) : 0; } void iommu_read_msi_from_ire( struct msi_desc *msi_desc, struct msi_msg *msg) { - const struct iommu_ops *ops = iommu_get_ops(); if ( iommu_intremap ) - ops->read_msi_from_ire(msi_desc, msg); + iommu_get_ops()->read_msi_from_ire(msi_desc, msg); } int iommu_add_device(struct pci_dev *pdev) Reviewed-by: Dario Faggioli --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -337,11 +337,16 @@ int __init iommu_setup(void) return rc; } +void iommu_suspend() +{ + if ( iommu_enabled ) + iommu_get_ops()->suspend(); +} + void iommu_resume() { - const struct iommu_ops *ops = iommu_get_ops(); if ( iommu_enabled ) - ops->resume(); + iommu_get_ops()->resume(); } int iommu_do_domctl( @@ -365,34 +370,28 @@ int iommu_do_domctl( return ret; } -void iommu_suspend() -{ - const struct iommu_ops *ops = iommu_get_ops(); - if ( iommu_enabled ) - ops->suspend(); -} - void iommu_share_p2m_table(struct domain* d) { - const struct iommu_ops *ops = iommu_get_ops(); - if ( iommu_enabled && iommu_use_hap_pt(d) ) - ops->share_p2m(d); + iommu_get_ops()->share_p2m(d); } void iommu_crash_shutdown(void) { - const struct iommu_ops *ops = iommu_get_ops(); if ( iommu_enabled ) - ops->crash_shutdown(); + iommu_get_ops()->crash_shutdown(); iommu_enabled = iommu_intremap = iommu_intpost = 0; } int iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt) { - const struct iommu_ops *ops = iommu_get_ops(); + const struct iommu_ops *ops; + + if ( !iommu_enabled ) + return 0; - if ( !iommu_enabled || !ops->get_reserved_device_memory ) + ops = iommu_get_ops(); + if ( !ops->get_reserved_device_memory ) return 0; return ops->get_reserved_device_memory(func, ctxt); --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1241,16 +1241,15 @@ __initcall(setup_dump_pcidevs); int iommu_update_ire_from_msi( struct msi_desc *msi_desc, struct msi_msg *msg) { - const struct iommu_ops *ops = iommu_get_ops(); - return iommu_intremap ? ops->update_ire_from_msi(msi_desc, msg) : 0; + return iommu_intremap + ? iommu_get_ops()->update_ire_from_msi(msi_desc, msg) : 0; } void iommu_read_msi_from_ire( struct msi_desc *msi_desc, struct msi_msg *msg) { - const struct iommu_ops *ops = iommu_get_ops(); if ( iommu_intremap ) - ops->read_msi_from_ire(msi_desc, msg); + iommu_get_ops()->read_msi_from_ire(msi_desc, msg); } int iommu_add_device(struct pci_dev *pdev)