Received: by 10.223.185.116 with SMTP id b49csp5958470wrg; Wed, 7 Mar 2018 22:39:32 -0800 (PST) X-Google-Smtp-Source: AG47ELs6a5CHNWiXiiQYwgGkxu2/DY3DyFO0pGEcHzLvXtPa6dt+0EIEV3AxkjeEO8Sv72iuNu+O X-Received: by 10.99.97.7 with SMTP id v7mr20730355pgb.239.1520491172450; Wed, 07 Mar 2018 22:39:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520491172; cv=none; d=google.com; s=arc-20160816; b=jQ4K0WAfsf6RZqmA+/AHSUop5WVORn7GDNWHXI10Xvspft2XuYBYDSdmcb98iouCpa Kv2aLmZ6gh+phOoal7vQp64zLCbuLYs7rSSXTaZsJuDMTCO+z9QWoTnDECpHp2sFRhD3 0PigMlllznsio+HNfExgviKTqJkB1rk9hUdcVyubp9oklwMAhXjw12fTyISeFEZf2r+o OSq9ti12LEt4U9bCDqs55Vqp5yPDCuk/giOlGKzG81cecqUZVx1HOpkEhomKjyt3+jLu eAaHTtnSecXs/JtxsE9XlMfzZ/HiCLPOhnrHXYHcrERlp9wgptAudvc2MgzN6ysRfUCN ms8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=qqhIMuW55xgZvMIvTtFD1tXcIao1PIXr92Jj87WUO0g=; b=J5ArYdTuDnIcfxOn0qIGl9XuoALID2hurqgOLgzdbT9ChjxU8v0o0wlmFsEsa0L+cw H8rZYmzzIWVT2sF9ds3xmM7OvfVvnQ8qLb1zqZorjBmV9uu4gW+1PRrg57+qqwIgu/30 /j6YiC/kmCmewmtbzNwSuR9CLiNXySw7g53EilLDl7/0YkjaYlJ6Qru8elm0iVGT2pHv W5dcfnv2JlbSnga61fKt7gbG9XQ8/pFVzd4XQrCYkbbu8UD9W1t97kuBe6FFtDZY7RRj HCw0xTqxHW9TPVFBB03FHVARb9ecmBhgpadbYhzLsISQ538WNRHnKiVjZFErIQm8Pz2t huLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=AEZP3jQ4; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 14si15179248pfk.412.2018.03.07.22.39.18; Wed, 07 Mar 2018 22:39:32 -0800 (PST) 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=@microsoft.com header.s=selector1 header.b=AEZP3jQ4; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965447AbeCHGiR (ORCPT + 99 others); Thu, 8 Mar 2018 01:38:17 -0500 Received: from mail-sn1nam01on0106.outbound.protection.outlook.com ([104.47.32.106]:14491 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935357AbeCHE7M (ORCPT ); Wed, 7 Mar 2018 23:59:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=qqhIMuW55xgZvMIvTtFD1tXcIao1PIXr92Jj87WUO0g=; b=AEZP3jQ4iJCT2NfwdQjehpqSH6V3/Fw+b2rAz/efvO5BcO0A1fPzxkOYE6wplZtahZULKlaUsVaqb33I1Emz3Z2YzFR7kVZ5iB49oi1K0Y1NX2F1a+p32vwHGD8+tSJ9KNLs7lrwFPjUnkNU8vJZhgi8GAqfbgnY4+sfWsE2k4I= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.588.3; Thu, 8 Mar 2018 04:59:09 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446%2]) with mapi id 15.20.0588.008; Thu, 8 Mar 2018 04:59:08 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Jerry Snitselaar , Alex Williamson , Joerg Roedel , Ashok Raj , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 52/67] iommu/vt-d: clean up pr_irq if request_threaded_irq fails Thread-Topic: [PATCH AUTOSEL for 4.14 52/67] iommu/vt-d: clean up pr_irq if request_threaded_irq fails Thread-Index: AQHTtpoEjILtS77DcU2dgvbfBxltEA== Date: Thu, 8 Mar 2018 04:57:54 +0000 Message-ID: <20180308045641.7814-52-alexander.levin@microsoft.com> References: <20180308045641.7814-1-alexander.levin@microsoft.com> In-Reply-To: <20180308045641.7814-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1015;7:HDfUi94sWBzELsmJWCJqCrpG6P0edg+AXXg2NIpfxPXAYtpsWeF/5FcDQSWn/+EN1cvOc9/yAdb9+2IGoJ97yQCMs0e7dZEW1J+iRuGVn6vmCNr3ClO2EeVicOldrg69WGa4hHU22EHdtBdTTJAqUalbSZ21nWAZybQ0SzwbTowBbzkwlF/A5pY4sELqRWFRvuBe2tYGsyAdqOr32qGhU2gWc5S8LX+NZwenjhREqudbo7N418+RuxncvcKOJ4y5;20:gHzD9IMVugdni5Tt36d21JrWMNuVoMhl9psAp/EpM4RBrhI3F5XE96Au17IN8ocIAzm484+R7ue+Iu3QW3Kku88m6Z/lj3pqFZPqIK98JPXaLUeko1jzPeDi9/PQ/6DqqVcJbL8k89xu/EjV95xgrtOlGAauVs4p5E9FDb3V/ok= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: f98b3c8e-0369-41d8-43e3-08d584b153a0 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231220)(944501244)(52105095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 060503E79B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(396003)(366004)(39860400002)(39380400002)(346002)(189003)(199004)(6116002)(53936002)(1076002)(107886003)(3846002)(3660700001)(10090500001)(6666003)(2950100002)(2906002)(6512007)(99286004)(8936002)(6486002)(76176011)(6506007)(68736007)(59450400001)(316002)(110136005)(81156014)(81166006)(8676002)(54906003)(3280700002)(2900100001)(6436002)(97736004)(72206003)(25786009)(10290500003)(86612001)(4326008)(305945005)(7736002)(66066001)(22452003)(478600001)(5660300001)(86362001)(575784001)(14454004)(106356001)(36756003)(102836004)(5250100002)(105586002)(26005)(2501003)(186003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: LrSudLxFXIGF0t20HOOpwYbfH4WcpQiYlJ9OVM2iAzkeLU/glwr05VE/2dH9Jh5Sll4EWtbpnXptIjVBoint+Y7gjD9VN8sJorhGUp58lKF8Saxzdz7SbjzkQDGqfiXMmOy46mB3TxBVstNemCZVELilsLBwWlak2CzomJDMQdZzwRCiQi6VE6XiXFo8SHkIYmz5RMOcNRt6j5fpWWfRosVsjYPHF9inRooqhj2VlVnwpDEK3LhP8bIqo+mCOrfSdiGwq+Z/TKQmgl6iHg8rDstI958mGJKld75mN2ezpnhMWUhvHbfb2W6I0XWP5HSXsiPDf13GlKaOpQtdO6eZoA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f98b3c8e-0369-41d8-43e3-08d584b153a0 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2018 04:57:54.2967 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jerry Snitselaar [ Upstream commit 72d548113881dd32bf7f0b221d031e6586468437 ] It is unlikely request_threaded_irq will fail, but if it does for some reason we should clear iommu->pr_irq in the error path. Also intel_svm_finish_prq shouldn't try to clean up the page request interrupt if pr_irq is 0. Without these, if request_threaded_irq were to fail the following occurs: fail with no fixes: [ 0.683147] ------------[ cut here ]------------ [ 0.683148] NULL pointer, cannot free irq [ 0.683158] WARNING: CPU: 1 PID: 1 at kernel/irq/irqdomain.c:1632 irq_do= main_free_irqs+0x126/0x140 [ 0.683160] Modules linked in: [ 0.683163] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.15.0-rc2 #3 [ 0.683165] Hardware name: /NUC7i3BNB, BIOS BNKBL357.86= A.0036.2017.0105.1112 01/05/2017 [ 0.683168] RIP: 0010:irq_domain_free_irqs+0x126/0x140 [ 0.683169] RSP: 0000:ffffc90000037ce8 EFLAGS: 00010292 [ 0.683171] RAX: 000000000000001d RBX: ffff880276283c00 RCX: ffffffff81c= 5e5e8 [ 0.683172] RDX: 0000000000000001 RSI: 0000000000000096 RDI: 00000000000= 00246 [ 0.683174] RBP: ffff880276283c00 R08: 0000000000000000 R09: 00000000000= 0023c [ 0.683175] R10: 0000000000000007 R11: 0000000000000000 R12: 00000000000= 0007a [ 0.683176] R13: 0000000000000001 R14: 0000000000000000 R15: 00000100100= 00000 [ 0.683178] FS: 0000000000000000(0000) GS:ffff88027ec80000(0000) knlGS:= 0000000000000000 [ 0.683180] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.683181] CR2: 0000000000000000 CR3: 0000000001c09001 CR4: 00000000003= 606e0 [ 0.683182] Call Trace: [ 0.683189] intel_svm_finish_prq+0x3c/0x60 [ 0.683191] free_dmar_iommu+0x1ac/0x1b0 [ 0.683195] init_dmars+0xaaa/0xaea [ 0.683200] ? klist_next+0x19/0xc0 [ 0.683203] ? pci_do_find_bus+0x50/0x50 [ 0.683205] ? pci_get_dev_by_id+0x52/0x70 [ 0.683208] intel_iommu_init+0x498/0x5c7 [ 0.683211] pci_iommu_init+0x13/0x3c [ 0.683214] ? e820__memblock_setup+0x61/0x61 [ 0.683217] do_one_initcall+0x4d/0x1a0 [ 0.683220] kernel_init_freeable+0x186/0x20e [ 0.683222] ? set_debug_rodata+0x11/0x11 [ 0.683225] ? rest_init+0xb0/0xb0 [ 0.683226] kernel_init+0xa/0xff [ 0.683229] ret_from_fork+0x1f/0x30 [ 0.683259] Code: 89 ee 44 89 e7 e8 3b e8 ff ff 5b 5d 44 89 e7 44 89 ee = 41 5c 41 5d 41 5e e9 a8 84 ff ff 48 c7 c7 a8 71 a7 81 31 c0 e8 6a d3 f9 ff = <0f> ff 5b 5d 41 5c 41 5d 41 5 e c3 0f 1f 44 00 00 66 2e 0f 1f 84 [ 0.683285] ---[ end trace f7650e42792627ca ]--- with iommu->pr_irq =3D 0, but no check in intel_svm_finish_prq: [ 0.669561] ------------[ cut here ]------------ [ 0.669563] Trying to free already-free IRQ 0 [ 0.669573] WARNING: CPU: 3 PID: 1 at kernel/irq/manage.c:1546 __free_ir= q+0xa4/0x2c0 [ 0.669574] Modules linked in: [ 0.669577] CPU: 3 PID: 1 Comm: swapper/0 Not tainted 4.15.0-rc2 #4 [ 0.669579] Hardware name: /NUC7i3BNB, BIOS BNKBL357.86= A.0036.2017.0105.1112 01/05/2017 [ 0.669581] RIP: 0010:__free_irq+0xa4/0x2c0 [ 0.669582] RSP: 0000:ffffc90000037cc0 EFLAGS: 00010082 [ 0.669584] RAX: 0000000000000021 RBX: 0000000000000000 RCX: ffffffff81c= 5e5e8 [ 0.669585] RDX: 0000000000000001 RSI: 0000000000000086 RDI: 00000000000= 00046 [ 0.669587] RBP: 0000000000000000 R08: 0000000000000000 R09: 00000000000= 0023c [ 0.669588] R10: 0000000000000007 R11: 0000000000000000 R12: ffff8802762= 53960 [ 0.669589] R13: ffff8802762538a4 R14: ffff880276253800 R15: ffff8802762= 83600 [ 0.669593] FS: 0000000000000000(0000) GS:ffff88027ed80000(0000) knlGS:= 0000000000000000 [ 0.669594] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.669596] CR2: 0000000000000000 CR3: 0000000001c09001 CR4: 00000000003= 606e0 [ 0.669602] Call Trace: [ 0.669616] free_irq+0x30/0x60 [ 0.669620] intel_svm_finish_prq+0x34/0x60 [ 0.669623] free_dmar_iommu+0x1ac/0x1b0 [ 0.669627] init_dmars+0xaaa/0xaea [ 0.669631] ? klist_next+0x19/0xc0 [ 0.669634] ? pci_do_find_bus+0x50/0x50 [ 0.669637] ? pci_get_dev_by_id+0x52/0x70 [ 0.669639] intel_iommu_init+0x498/0x5c7 [ 0.669642] pci_iommu_init+0x13/0x3c [ 0.669645] ? e820__memblock_setup+0x61/0x61 [ 0.669648] do_one_initcall+0x4d/0x1a0 [ 0.669651] kernel_init_freeable+0x186/0x20e [ 0.669653] ? set_debug_rodata+0x11/0x11 [ 0.669656] ? rest_init+0xb0/0xb0 [ 0.669658] kernel_init+0xa/0xff [ 0.669661] ret_from_fork+0x1f/0x30 [ 0.669662] Code: 7a 08 75 0e e9 c3 01 00 00 4c 39 7b 08 74 57 48 89 da = 48 8b 5a 18 48 85 db 75 ee 89 ee 48 c7 c7 78 67 a7 81 31 c0 e8 4c 37 fa ff = <0f> ff 48 8b 34 24 4c 89 ef e 8 0e 4c 68 00 49 8b 46 40 48 8b 80 [ 0.669688] ---[ end trace 58a470248700f2fc ]--- Cc: Alex Williamson Cc: Joerg Roedel Cc: Ashok Raj Signed-off-by: Jerry Snitselaar Reviewed-by: Ashok Raj Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/iommu/intel-svm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c index f6697e55c2d4..003b4a4d4b78 100644 --- a/drivers/iommu/intel-svm.c +++ b/drivers/iommu/intel-svm.c @@ -129,6 +129,7 @@ int intel_svm_enable_prq(struct intel_iommu *iommu) pr_err("IOMMU: %s: Failed to request IRQ for page request queue\n", iommu->name); dmar_free_hwirq(irq); + iommu->pr_irq =3D 0; goto err; } dmar_writeq(iommu->reg + DMAR_PQH_REG, 0ULL); @@ -144,9 +145,11 @@ int intel_svm_finish_prq(struct intel_iommu *iommu) dmar_writeq(iommu->reg + DMAR_PQT_REG, 0ULL); dmar_writeq(iommu->reg + DMAR_PQA_REG, 0ULL); =20 - free_irq(iommu->pr_irq, iommu); - dmar_free_hwirq(iommu->pr_irq); - iommu->pr_irq =3D 0; + if (iommu->pr_irq) { + free_irq(iommu->pr_irq, iommu); + dmar_free_hwirq(iommu->pr_irq); + iommu->pr_irq =3D 0; + } =20 free_pages((unsigned long)iommu->prq, PRQ_ORDER); iommu->prq =3D NULL; --=20 2.14.1