From patchwork Mon Nov 29 19:19:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 12645513 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3BABC433F5 for ; Mon, 29 Nov 2021 19:21:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239585AbhK2TZP (ORCPT ); Mon, 29 Nov 2021 14:25:15 -0500 Received: from mail-co1nam11on2135.outbound.protection.outlook.com ([40.107.220.135]:11648 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229452AbhK2TXP (ORCPT ); Mon, 29 Nov 2021 14:23:15 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FkXrNwnpsTECUbQg1WtmxnEJtq7ivuvpwWpN4GngPk8QCMSvdLt/vMjO6lNq4NXPsFg68O1RzISok2Eel+eKPwjjZ6+HhxMSZiE4wxUIW5KlkgKobu694mnTGd2rvhJSxzhZ876F/R+WzeuVMuTMl3DfGhSPmuublmydtE5HgWKglnomBqJSM2O/aWGnJf6wnf/A3h6ln8EdgImf9LGj8X50vWjPu+4bT9byzujnEq65nSrxRp0/hK/qnM64IDxmaIHi2S7ogsp2zGN4ryNl4EGQQL01J8FBBdKDHv/T677Dfs+yVkoNap+Uq4uApVuF+YQsm3fR0L9E8q495BELIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pfK0T8V/t4iWM4h9LV9bI31NKRkqOmzwxf1eV/KhBEM=; b=JPR+kr0cjFfOWeIZKUMvFD5JvFgt0BbRdUDlxIwivQKwRp6Ju5y6g+0tEfzqx0jmls72xpXB9VRl5H+TfTpwbGmA5cZyvsnqEPO+8BUEfwxsFhHbxKtZsiXlXCQffCrdAzDTs2ErqypA9o0CfsZOngYooApDrDlTSADklpCb4ieQRRzIM7xGha4VeIqG0yR8rbaFYPKZHA8JPwPg4GnoUaxe70gyOfYSj9HhTTEpzZhYZCpPyOpnue+jS4gTfGjr+QtQ6y6L7wNoLIh6Oynhd7TRMftAHKHOoXy1e8afoD2sN/3F0lFr9zFIEoP/6fHPOtVCFc1t3puMYPilPUyWHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=cornelisnetworks.com smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pfK0T8V/t4iWM4h9LV9bI31NKRkqOmzwxf1eV/KhBEM=; b=RR3C76FVc5yUo/TomyVNOw05E5mkqxCL/0Q2I6yQLK3iSfTORxzAx8/yJKeNrsq2MeMOVEr4aRuXpMLp4sqvcTqZNSNUikbrACuH0QQ+t1nvrHgk2O5vqTFD1FM7nGnszUwHg1nNx0GiBrYL8uLDh6yx8nv75dbsZ4mVMjY8p2Kjx8InZWWujfoDwdTRRhtqwHGN5GR3sT54R9dC5lPZdO9go1TG+TdzfFx8oDJmJ/HBqs3Lz0iP2E17PDKPpqN/lFRI0NFbJlxSkgE0UIKYWT34OaGAbeiXbjHIMmOEK2pZfnt/HKACTknoocq2n4rCd7lCNZIfNX6ZS+s2kea+SQ== Received: from MWHPR18CA0032.namprd18.prod.outlook.com (2603:10b6:320:31::18) by BY5PR01MB5939.prod.exchangelabs.com (2603:10b6:a03:1cb::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22; Mon, 29 Nov 2021 19:19:54 +0000 Received: from CO1NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:320:31:cafe::58) by MWHPR18CA0032.outlook.office365.com (2603:10b6:320:31::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23 via Frontend Transport; Mon, 29 Nov 2021 19:19:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-01.cornelisnetworks.com; Received: from awfm-01.cornelisnetworks.com (208.255.156.42) by CO1NAM11FT055.mail.protection.outlook.com (10.13.175.129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22 via Frontend Transport; Mon, 29 Nov 2021 19:19:53 +0000 Received: from awfm-01.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-01.cornelisnetworks.com (8.14.7/8.14.7) with ESMTP id 1ATJJqHF117689; Mon, 29 Nov 2021 14:19:52 -0500 Subject: [PATCH for-rc 1/4] IB/hfi1: Correct guard on eager buffer deallocation From: Dennis Dalessandro To: jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, Mike Marciniszyn Date: Mon, 29 Nov 2021 14:19:52 -0500 Message-ID: <20211129191952.101968.17137.stgit@awfm-01.cornelisnetworks.com> In-Reply-To: <20211129191510.101968.6259.stgit@awfm-01.cornelisnetworks.com> References: <20211129191510.101968.6259.stgit@awfm-01.cornelisnetworks.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6de52d1f-d3fd-4773-0eab-08d9b36d390e X-MS-TrafficTypeDiagnostic: BY5PR01MB5939: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UFJxVTOzckBLMqZFJaMlkKCDFoPF7UjnaouQkC1qEG1CileMVPeFeaNp2S67QT8EnFljiy/XJnX8sKaN4v+2/gu/br7IMUoxUKY4PDPd8rZXhiP2iKeVdPXPnJIV0rHP4SfQTAVoMwTJw0YlVc/2A/D9F5ThOWpJ+0aCCKE4b27UBS5tZ0H33Kk4/rVKagIKWerzSR6GgI6dQ/nE0/Qd/G6O9XyWtjg59yVD9k15BGGp82m07X9Skp31UphqzIpSpv/cK7K91MO0PrmC0Y6ini1X6TeEuuaFP1/aNx02mg915YDsD+EfT3qMkeUss+x65PBJkF6MBkZoUesyywS8IBxnQzDI0Azr+b0RVvEIpd1FFyJBSaHA+0OO+sP/scKmMvYfy+crXRmUD5N47eLPNSu9x1UeZXL9/Ck0VP188tGrSKqZehe0PWR44+gQXCW6T2uJ0eeCqWUD3eSmDliIoAnJ5emhNcgTHBKT9vZF5FwcNlnr4AbKFLnEmnBGBu1yhzkp4mqnrOZx2D5j5IH2yx/whYrFlDFDhVSX3a1stpyEFcZBiHDEkl1rgwl+5bWsHs7Re5KkIFSqTc/W8B9hhL36UdGsHhWzWmT4gG9wpxue56wuRzhFKpYDud4ULdoCne9tzAIrtyw1JSM7tRkk+8L4q4sMPetAV305gm38QCexYprqt+GhhCLRvbU3taDUnw55Vrp5wwcNc4XAenvO69Gbcf6M+k6VevaSpcknCpk= X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-01.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(26005)(83380400001)(336012)(1076003)(316002)(44832011)(2906002)(5660300002)(7696005)(186003)(36860700001)(55016003)(4326008)(426003)(70206006)(70586007)(508600001)(8676002)(8936002)(6916009)(81166007)(356005)(82310400004)(107886003)(86362001)(103116003)(47076005)(7126003)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2021 19:19:53.8098 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6de52d1f-d3fd-4773-0eab-08d9b36d390e X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-01.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR01MB5939 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Mike Marciniszyn The code tests the dma address which legitimately can be 0. The code should test the kernel logical address to avoid leaking eager buffer allocations that happen to map to a dma address of 0. Fixes: 60368186fd85 ("IB/hfi1: Fix user-space buffers mapping with IOMMU enabled") Signed-off-by: Mike Marciniszyn Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hfi1/init.c b/drivers/infiniband/hw/hfi1/init.c index dbd1c31..8e1236b 100644 --- a/drivers/infiniband/hw/hfi1/init.c +++ b/drivers/infiniband/hw/hfi1/init.c @@ -1120,7 +1120,7 @@ void hfi1_free_ctxtdata(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd) rcd->egrbufs.rcvtids = NULL; for (e = 0; e < rcd->egrbufs.alloced; e++) { - if (rcd->egrbufs.buffers[e].dma) + if (rcd->egrbufs.buffers[e].addr) dma_free_coherent(&dd->pcidev->dev, rcd->egrbufs.buffers[e].len, rcd->egrbufs.buffers[e].addr, From patchwork Mon Nov 29 19:19:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 12645515 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8646FC433FE for ; Mon, 29 Nov 2021 19:22:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241151AbhK2TZT (ORCPT ); Mon, 29 Nov 2021 14:25:19 -0500 Received: from mail-bn8nam08on2110.outbound.protection.outlook.com ([40.107.100.110]:44353 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234229AbhK2TXT (ORCPT ); Mon, 29 Nov 2021 14:23:19 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NKzeizBFpuEa7LdrdqL88vlCtA5jaf4wCbzKVv0/uaUcgTYeN2ju/lwGX8AmXdW9kusaRKxShJYP1DW++/lXb0xW8qKxrVzZJjaQhc+cOnszQ68SRyuA5HdUu1fHbUqByFC1n9B5HkjcoP6iA3Cint5R3XctHI/6nx+vZ2wwpUsGhyZB69zqqDLijhSaXZXA+V8jem7RXTYHZKSANlVJD5Bd+y5ceAui7p68jcThVt1M79s0S6LrbAv2+rkLR2oxAWFHp6UweLuEo7i7hhxMV43m0pjG1FEM44aIArkC7VqJKTFUZxou1GPq45kTMR+ptg3+h6lFXtnEEvDTbnvVpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DOjuqqS32unn6C3gC6erHofd5sIdxCsdtG2rJBfwjns=; b=Dh2N0f5ajkN5eWitTi6pzhKHK8pmsRb46iCtA5dMCaYu/HNofHk0vLo96TZLbbK682E+4GLGL4ocAEsdAPQRtz/VFekUvpcDcyYvDjgLtoK7g1sjHkeOP7vGtw1hd57Y7pF6m0apFd24eQ1fB9XmCvt4tYu8/1JkT5rOe3f2vrdm4cPRWyYEcnDeeGTahQz982wlp5UuVqFaH3vPzyE1l1mzOBC6YCpz/YyenPV4hWqpA7Os69aIjrPVY5SD2LFgU/FTVc+mpEIx0e5PdHimT97KnZi/kJHubybZ4rwagW/QGYkBaBybI6a+KLblD9FfpCc7ms3XNaMG9Xa+xnP6TA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DOjuqqS32unn6C3gC6erHofd5sIdxCsdtG2rJBfwjns=; b=mA8qsbmva4HrRadFkUqY3ap72/GtIeU2zzjmtJpsuXx1xoo05NeMRzYsU22EzpKvn5r/hp9vUWvymR5LAk1Lk8EDKb92GAHWQbOd6ZstlbacAkGlNpGXegbdhZIQIVp+H4asY36hRpaTmKfZzp/g2UFYAZ/26tz3Jeg42lFPpX+d7KULtr0QHSViaGxbTX5nxMxPJ83byP1JaVV7so9Z4WV2aXqKmY1vX60VfFA2/Lgn/+OZp/HGcNlAhFTYBDAj0NbVadFBK6Nz+xYiFfhV7Yl5CdrbcpFOE2rZh1bKuzHM90yNjs9HTkS7zLprKgrco3AZ+UUL8aKbLutJJCq7FA== Received: from DM3PR14CA0134.namprd14.prod.outlook.com (2603:10b6:0:53::18) by DM5PR0101MB2906.prod.exchangelabs.com (2603:10b6:4:2b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.21; Mon, 29 Nov 2021 19:19:59 +0000 Received: from DM6NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:0:53:cafe::9) by DM3PR14CA0134.outlook.office365.com (2603:10b6:0:53::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.24 via Frontend Transport; Mon, 29 Nov 2021 19:19:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-01.cornelisnetworks.com; Received: from awfm-01.cornelisnetworks.com (208.255.156.42) by DM6NAM11FT035.mail.protection.outlook.com (10.13.172.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22 via Frontend Transport; Mon, 29 Nov 2021 19:19:58 +0000 Received: from awfm-01.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-01.cornelisnetworks.com (8.14.7/8.14.7) with ESMTP id 1ATJJwNN118013; Mon, 29 Nov 2021 14:19:58 -0500 Subject: [PATCH for-rc 2/4] IB/hfi1: Insure use of smp_processor_id() is preempt disabled From: Dennis Dalessandro To: jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, Mike Marciniszyn , stable@vger.kernel.org Date: Mon, 29 Nov 2021 14:19:58 -0500 Message-ID: <20211129191958.101968.87329.stgit@awfm-01.cornelisnetworks.com> In-Reply-To: <20211129191510.101968.6259.stgit@awfm-01.cornelisnetworks.com> References: <20211129191510.101968.6259.stgit@awfm-01.cornelisnetworks.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: de915734-8b16-444a-9474-08d9b36d3c13 X-MS-TrafficTypeDiagnostic: DM5PR0101MB2906: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VzY1d31azzxtzOH1xlrOnbF75BQc0zYJMECr30SK7/+fiOl14aICDHiAVfDZHzOOVpd/kcQ56ZcgySbvHCt0XE3RoU2xn3eOOHyPXV/r1Ya+0vkiP5BZLfvZkddQ1y51lahjNPaR6ZMMjoHHrwPJUKgJ0wd4Vy/9zF+LlWpqFnPPqpjVyvsHEJ6A+91GojYJh4DIH9XTybcy46FPeEtrZCYCAEGefo18j/R8H2cynRvh5B6reqLH2kA2dpihQeojMNARu/c/LJJ5bNBIyWT73kW4FBu5ucUR1PTJUEPsHA1yBM7jdTcRHjhb6zoLM80kSTlGfgg0J0Los8xg84yg4P997h6BIE3PYm5+TzfZMCasrBmrwkY2LpMj+P7AZ9zFY94gRmr3S/5gTibfUkrhTwfLkE0KvgvjzwGBtsMpmtnWNSfI2YB+j5QwAgtmssPMAkXEgSGjh2s+ntys3coPePDbqO6zaqQL3xnUxjatNJlPFRjLNAj3Zn+pM5QGw4Ja9MEcFSmnnJrkCn3OQpH5j2KBDDnYd327LGTIc2jG6X8ZN857G07ByYZ82NnGqhptp05srcnEQza5vLydRIikiO8jXZlgK99ENMHGAPKOcFSUFDp++4UdIrekuSmUV1y8P28iDtA69qc4AcB8YyWw/ySeOW27a+3Yr0vG+sEKYbU7Vy55XeMLC6HIVcA+mitArEM4jjh5tj4roNnBX67I//yPQf6rD0RXBTQrU1hjkNI= X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-01.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(136003)(346002)(376002)(396003)(39840400004)(46966006)(36840700001)(7696005)(86362001)(8936002)(5660300002)(426003)(356005)(82310400004)(103116003)(8676002)(47076005)(70586007)(55016003)(508600001)(36860700001)(7126003)(81166007)(2906002)(4326008)(44832011)(26005)(1076003)(70206006)(83380400001)(6916009)(186003)(316002)(336012)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2021 19:19:58.8969 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: de915734-8b16-444a-9474-08d9b36d3c13 X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-01.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0101MB2906 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Mike Marciniszyn The following BUG has just surfaced with our 5.16 testing: [27140.581296] BUG: using smp_processor_id() in preemptible [00000000] code: mpicheck/1581081 [27140.590987] caller is sdma_select_user_engine+0x72/0x210 [hfi1] [27140.597999] CPU: 0 PID: 1581081 Comm: mpicheck Tainted: G S 5.16.0-rc1+ #1 [27140.607454] Hardware name: Intel Corporation S2600WT2R/S2600WT2R, BIOS SE5C610.86B.01.01.0016.033120161139 03/31/2016 [27140.619628] Call Trace: [27140.622682] [27140.625350] dump_stack_lvl+0x33/0x42 [27140.629760] check_preemption_disabled+0xbf/0xe0 [27140.635222] sdma_select_user_engine+0x72/0x210 [hfi1] [27140.641299] ? _raw_spin_unlock_irqrestore+0x1f/0x31 [27140.647140] ? hfi1_mmu_rb_insert+0x6b/0x200 [hfi1] [27140.652909] hfi1_user_sdma_process_request+0xa02/0x1120 [hfi1] [27140.659857] ? hfi1_write_iter+0xb8/0x200 [hfi1] [27140.665348] hfi1_write_iter+0xb8/0x200 [hfi1] [27140.670650] do_iter_readv_writev+0x163/0x1c0 [27140.675827] do_iter_write+0x80/0x1c0 [27140.680214] vfs_writev+0x88/0x1a0 [27140.684315] ? recalibrate_cpu_khz+0x10/0x10 [27140.689388] ? ktime_get+0x3e/0xa0 [27140.693473] ? __fget_files+0x66/0xa0 [27140.697853] do_writev+0x65/0x100 [27140.701842] do_syscall_64+0x3a/0x80 Fix this long standing bug by moving the smp_processor_id() to after the rcu_read_lock(). The rcu_read_lock() implicitly disables preemption. Cc: stable@vger.kernel.org Fixes: 0cb2aa690c7e ("IB/hfi1: Add sysfs interface for affinity setup") Signed-off-by: Mike Marciniszyn Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/sdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hfi1/sdma.c b/drivers/infiniband/hw/hfi1/sdma.c index 2b6c24b..f07d328 100644 --- a/drivers/infiniband/hw/hfi1/sdma.c +++ b/drivers/infiniband/hw/hfi1/sdma.c @@ -838,8 +838,8 @@ struct sdma_engine *sdma_select_user_engine(struct hfi1_devdata *dd, if (current->nr_cpus_allowed != 1) goto out; - cpu_id = smp_processor_id(); rcu_read_lock(); + cpu_id = smp_processor_id(); rht_node = rhashtable_lookup(dd->sdma_rht, &cpu_id, sdma_rht_params); From patchwork Mon Nov 29 19:20:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 12645517 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39F4EC433FE for ; Mon, 29 Nov 2021 19:22:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351060AbhK2TZ0 (ORCPT ); Mon, 29 Nov 2021 14:25:26 -0500 Received: from mail-bn1nam07on2107.outbound.protection.outlook.com ([40.107.212.107]:50149 "EHLO NAM02-BN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235981AbhK2TXZ (ORCPT ); Mon, 29 Nov 2021 14:23:25 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KOGp9AkF53oua5/zG7t4aoyCLYu2xJKRXQkWgFP4IfTX+w8PNAtBstHmCM+BosJri8vt/UDehkuwCqetwELLTYhZWsjaQrmSu2YEHYUYGEGQjbA38lOO+60ucpXul+dq9ZCWl9Jxde2aaPeI0OTMx5mmp7rKDZ3PZsZYcJPDb65Ub4s+fFXSg5CfEs2Sq6eg4FWs1NUZ7gF+2JnI/f0DZm9URj/gbRF//fsRHOoZa6UnCicKrdik8ubLDcMu5j+BQxQM9o9ElYiY7oZdAwTAqCUVgQoSHCwXdlPMOLZlbHqTMsylTfhijD/H/281mHX06Ty0D3aD3ExMlVUVtPghXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yBdNusOiFvUVppXFtGgvFYMvx1bUKIN7+urXkQa9CgY=; b=Iz6QTI7f/luuGUqqK960SIdlvvMaNySlS0Xz7NiZkE5Nzsu2Fka+BxakhjYUAXgLe8B55BbBYKf+Fhc++12nxk9pcgE6ZtyrQUzxPQFzY+bC8YL9HX32f6zHtAQERC6fUPYttOJo1yVCNXRqdJZx9SEvvE+UusNAYJGqsU3O+QHOyPWRfnNBUChALXiVM9chOchbktOKPH78mizzOjb1wwZsF7kE1x9rrxB2tYTGgWD8UUKpVOwOD8KJ8eBf5BIXqdt2o03YgfcehZUGHnmWwJPd/ES0DKKToLvOuvccrdTVwlgf0rd7hOGTI4mEnZnsH0HP2hTfodqGEaboW0BVOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yBdNusOiFvUVppXFtGgvFYMvx1bUKIN7+urXkQa9CgY=; b=EJNjE404pVzuX+aKJuvoEr4LupEHmlgve8D7cNAT8D6Ds1bt01P4maZhGH8LjKs73m86p590fODxrzplzx5bBiTcaQj/E4YL9jvGZ6WVLkmgEYjBiyCT/jWdyRGbHL7POvv2G40Vxj+wvmnNQwoHjmOpSDAELxIqTafZQhJU6JLaWSaK96dBxU2olopOePXQHpKYRVPWsbTqsCLuWO8XApm6K38+S1F0UJ5OozGnI9J8mCRwdrdLZ/9xiDEPUMlRzL6rYBvDCV47+Ck54fYwjJi2ycD0TAhf5VKq2wynQK43JENx4tNTvL8qXyeqPZYAJk4ZxWvo8d2UVz7V5VsB/A== Received: from DM5PR21CA0006.namprd21.prod.outlook.com (2603:10b6:3:ac::16) by BYAPR01MB5558.prod.exchangelabs.com (2603:10b6:a03:123::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Mon, 29 Nov 2021 19:20:04 +0000 Received: from DM6NAM11FT067.eop-nam11.prod.protection.outlook.com (2603:10b6:3:ac:cafe::9f) by DM5PR21CA0006.outlook.office365.com (2603:10b6:3:ac::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.2 via Frontend Transport; Mon, 29 Nov 2021 19:20:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-01.cornelisnetworks.com; Received: from awfm-01.cornelisnetworks.com (208.255.156.42) by DM6NAM11FT067.mail.protection.outlook.com (10.13.172.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22 via Frontend Transport; Mon, 29 Nov 2021 19:20:03 +0000 Received: from awfm-01.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-01.cornelisnetworks.com (8.14.7/8.14.7) with ESMTP id 1ATJK3H2118300; Mon, 29 Nov 2021 14:20:03 -0500 Subject: [PATCH for-rc 3/4] IB/hfi1: Fix early init panic From: Dennis Dalessandro To: jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, Mike Marciniszyn , stable@vger.kernel.org Date: Mon, 29 Nov 2021 14:20:03 -0500 Message-ID: <20211129192003.101968.33612.stgit@awfm-01.cornelisnetworks.com> In-Reply-To: <20211129191510.101968.6259.stgit@awfm-01.cornelisnetworks.com> References: <20211129191510.101968.6259.stgit@awfm-01.cornelisnetworks.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31d154c0-da1a-4aa8-3883-08d9b36d3f15 X-MS-TrafficTypeDiagnostic: BYAPR01MB5558: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wpaqRpHOEEvtNLO/x3njTsRHE1sTpLUTL4xaHTSx84aq45bk+UYF30X1eD/nslBJCps9RbUIcek+MRYpFQV6AaItdYe9e8zyjpEjD9nDOUFg5W2GpkT5oClC5EFAP7SkXeJkwaAm86y/+lvpD5GunpIYJpXK0GPXrF4CsXoPTRqalmki+b42ikDgmiPb6rukRVPXUKEL6uC7uieq3qyemm5X0wTngStN6nrdNs3W+TYX6/PdxOurVN7A+LMNmEK9QG7/jrAQuEPenDm3pn72bhqsCtI+Xjy9kzE4t7Vb7V9MtKClWHjxgVKNUNqvm4+T0rjbIAABecusbHcUmLTD0ooy86xHz2smFTtCdSsCFZs51c+ky/8A4ozcep2b/tbctzrEu+YHan4NHQYEzLlMvde6AkusMQvCbq9ySASVuHjsyHtSeMSrU4+hy5FQ5F1zS2aqU4lvBlkCvuW9A4JV4OzEPpjNCWTqTbUeiqaIJfivLeuu0VhC/WUmTRKTjAx+MxGUdc9P0fvZO640W9eTKQ27NgF74lkLtabweAg7PUTR7nH7kyNv6EKCcngC/z6zidpurq1Fst3H+4gu2xsUL0BGrzWYOSIpZMTmW34V0aTig/Dzf2Vr2lFlx9BDqTxMHz8jyLRJ25O4pQnerrWhEkNK2fmpGVKJnCohfLnfsPcNQ4rosOeSRwUp2S99YMkB23qKwgOt26kYm0lm0Kxg7ennYOiZk8mI9hdlmYyKvNA= X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-01.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(396003)(39840400004)(346002)(376002)(136003)(46966006)(36840700001)(44832011)(186003)(336012)(8676002)(8936002)(1076003)(103116003)(81166007)(86362001)(36860700001)(70586007)(426003)(26005)(7126003)(83380400001)(82310400004)(4326008)(5660300002)(508600001)(7696005)(2906002)(356005)(316002)(47076005)(70206006)(6916009)(55016003)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2021 19:20:03.9988 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31d154c0-da1a-4aa8-3883-08d9b36d3f15 X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-01.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT067.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR01MB5558 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Mike Marciniszyn The following trace can be observed with an init failure such as firmware load failures: [ 18.421033] BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 [ 18.430189] PGD 0 P4D 0 [ 18.433435] Oops: 0010 [#1] SMP PTI [ 18.437715] CPU: 0 PID: 537 Comm: kworker/0:3 Tainted: G OE --------- - - 4.18.0-240.el8.x86_64 #1 [ 18.461788] Workqueue: events work_for_cpu_fn [ 18.467104] RIP: 0010:0x0 [ 18.470493] Code: Bad RIP value. [ 18.474549] RSP: 0000:ffffae5f878a3c98 EFLAGS: 00010046 [ 18.480819] RAX: 0000000000000000 RBX: ffff95e48e025c00 RCX: 0000000000000000 [ 18.489243] RDX: 0000000000000001 RSI: 0000000000000000 RDI: ffff95e48e025c00 [ 18.497655] RBP: ffff95e4bf3660a4 R08: 0000000000000000 R09: ffffffff86d5e100 [ 18.506069] R10: ffff95e49e1de600 R11: 0000000000000001 R12: ffff95e4bf366180 [ 18.514478] R13: ffff95e48e025c00 R14: ffff95e4bf366028 R15: ffff95e4bf366000 [ 18.522869] FS: 0000000000000000(0000) GS:ffff95e4df200000(0000) knlGS:0000000000000000 [ 18.532369] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 18.539238] CR2: ffffffffffffffd6 CR3: 0000000f86a0a003 CR4: 00000000001606f0 [ 18.547660] Call Trace: [ 18.550862] receive_context_interrupt+0x1f/0x40 [hfi1] [ 18.557165] __free_irq+0x201/0x300 [ 18.561528] free_irq+0x2e/0x60 [ 18.565497] pci_free_irq+0x18/0x30 [ 18.569846] msix_free_irq.part.2+0x46/0x80 [hfi1] [ 18.575662] msix_clean_up_interrupts+0x2b/0x70 [hfi1] [ 18.581846] hfi1_init_dd+0x640/0x1a90 [hfi1] [ 18.587170] do_init_one.isra.19+0x34d/0x680 [hfi1] [ 18.593058] local_pci_probe+0x41/0x90 [ 18.597684] work_for_cpu_fn+0x16/0x20 [ 18.602332] process_one_work+0x1a7/0x360 [ 18.607256] worker_thread+0x1cf/0x390 [ 18.611872] ? create_worker+0x1a0/0x1a0 [ 18.616694] kthread+0x112/0x130 [ 18.620737] ? kthread_flush_work_fn+0x10/0x10 [ 18.626147] ret_from_fork+0x35/0x40 [ 18.655466] CR2: 0000000000000000 [ 18.659703] ---[ end trace 40218ba9776cac37 ]--- The free_irq() results in a callback to the registered interrupt handler, and rcd->do_interrupt is NULL because the receive context data structures are not fully initialized. Fix by ensuring that the do_interrupt is always assigned and adding a guards in the slow path handler to detect and handle a partially initialized receive context and noop the receive. Cc: stable@vger.kernel.org Fixes: b0ba3c18d6bf ("IB/hfi1: Move normal functions from hfi1_devdata to const array") Signed-off-by: Mike Marciniszyn Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/chip.c | 2 ++ drivers/infiniband/hw/hfi1/driver.c | 2 ++ drivers/infiniband/hw/hfi1/init.c | 5 ++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/chip.c b/drivers/infiniband/hw/hfi1/chip.c index ec37f4f..f1245c9 100644 --- a/drivers/infiniband/hw/hfi1/chip.c +++ b/drivers/infiniband/hw/hfi1/chip.c @@ -8415,6 +8415,8 @@ static void receive_interrupt_common(struct hfi1_ctxtdata *rcd) */ static void __hfi1_rcd_eoi_intr(struct hfi1_ctxtdata *rcd) { + if (!rcd->rcvhdrq) + return; clear_recv_intr(rcd); if (check_packet_present(rcd)) force_recv_intr(rcd); diff --git a/drivers/infiniband/hw/hfi1/driver.c b/drivers/infiniband/hw/hfi1/driver.c index 61f341c..e2c634a 100644 --- a/drivers/infiniband/hw/hfi1/driver.c +++ b/drivers/infiniband/hw/hfi1/driver.c @@ -1012,6 +1012,8 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread) struct hfi1_packet packet; int skip_pkt = 0; + if (!rcd->rcvhdrq) + return RCV_PKT_OK; /* Control context will always use the slow path interrupt handler */ needset = (rcd->ctxt == HFI1_CTRL_CTXT) ? 0 : 1; diff --git a/drivers/infiniband/hw/hfi1/init.c b/drivers/infiniband/hw/hfi1/init.c index 8e1236b..6422dd6 100644 --- a/drivers/infiniband/hw/hfi1/init.c +++ b/drivers/infiniband/hw/hfi1/init.c @@ -113,7 +113,6 @@ static int hfi1_create_kctxt(struct hfi1_devdata *dd, rcd->fast_handler = get_dma_rtail_setting(rcd) ? handle_receive_interrupt_dma_rtail : handle_receive_interrupt_nodma_rtail; - rcd->slow_handler = handle_receive_interrupt; hfi1_set_seq_cnt(rcd, 1); @@ -334,6 +333,8 @@ int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa, rcd->numa_id = numa; rcd->rcv_array_groups = dd->rcv_entries.ngroups; rcd->rhf_rcv_function_map = normal_rhf_rcv_functions; + rcd->slow_handler = handle_receive_interrupt; + rcd->do_interrupt = rcd->slow_handler; rcd->msix_intr = CCE_NUM_MSIX_VECTORS; mutex_init(&rcd->exp_mutex); @@ -898,8 +899,6 @@ int hfi1_init(struct hfi1_devdata *dd, int reinit) if (!rcd) continue; - rcd->do_interrupt = &handle_receive_interrupt; - lastfail = hfi1_create_rcvhdrq(dd, rcd); if (!lastfail) lastfail = hfi1_setup_eagerbufs(rcd); From patchwork Mon Nov 29 19:20:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 12645519 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDBFEC433FE for ; Mon, 29 Nov 2021 19:22:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232378AbhK2TZi (ORCPT ); Mon, 29 Nov 2021 14:25:38 -0500 Received: from mail-mw2nam12on2133.outbound.protection.outlook.com ([40.107.244.133]:6881 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232541AbhK2TXi (ORCPT ); Mon, 29 Nov 2021 14:23:38 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nI4DBlUSlM91x6lGnHrBwZgk1Pw7Zqa/9lnxO1qADTh5d9MsKFZvvVAkU+jE1b/XdNZ7VGorsSgLKogqNJ3pC0BYxbi1HokNDyW7Jq7ZeE9ryMETykBIUA+afZ/4NlTodt0e51zejEaAiltW470OvapJXCB9CU9rbjC2hL+G8X+0BW+rG5boDgG+fw5u44tgJVJjMEsPhDGTW0JS5Sg2R5YVZHJpMpBbCGC3/00TJFKvKmNpB94l1eFCdZiJxz3ZewXKxfm/2XupJSQYQsKgKSCfR21vqQrby+jCvPgAcSn6fJVX+0QZduMGHk8M+nMZ5svpbehjT0DDY/b7fsnTeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UEndnqqNi2+RhoADBT7S6ymHqxxV13lLD39Uk4IwrzE=; b=ToSBcZKhsCaoHqsXT5g+hyNz+VMe8h1xpChwOZs6rqz5WpvieSdfQaUcDkMv6W9U6ckXETxpvByVyO6T4peDtQEE4ljlS6iTpowQMeD41EOFPC7KMAfxzpZl+yuTAUyQgnOr8dWmuwy2iDOseFt31g/H4VSiR8uC93A02WTFtaAR0IWHGntfceFOiiMzGWTuc9PUxfPhAq8xWb+IS9QFdUj8JY2kKEnSkZQqTCl8r/aZzGP2c6Fmzb7esHdPMuJoHX2D+7O/KmC7ZbWh5afebV0pi5pBdlk8e0D2wliA6i9uW/ZeXy7tEECjoea4PPBTZYVGQ3rt431bVuFw3FvBMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UEndnqqNi2+RhoADBT7S6ymHqxxV13lLD39Uk4IwrzE=; b=WHQzg5A6MLWCsYSeXf6hI2ejY5cZprWYLdJKc3FxvLCFkmm3/FAeoWGLYAmkX497t5aU2YxjHrSLXJRd6KeTG0wO5yCYNee2QwzQg5N3oSZmyGtg1Xhe2CIIg6TsbKUcHgfUd41T3fv5cVngeaowBbf6um4Q9yVmllmvR7zXH5qAFrrYB0ufCmtSauh6R0vI8RG1/ikKzmwmHAAO6MQD4+7DyI9j1U9XAPawES/mqpG5ZiSF2GhkzZd0hjdRBAvI8btRxAn4H8LnUSa/Am5O8XapaWWIkgVk6ewtJfAsNiPAvUxfGQ8rC3RjURjH4/myc958NXloQ4hWCoQLYM5tbw== Received: from DM3PR14CA0137.namprd14.prod.outlook.com (2603:10b6:0:53::21) by BL0PR01MB4546.prod.exchangelabs.com (2603:10b6:208:82::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.21; Mon, 29 Nov 2021 19:20:17 +0000 Received: from DM6NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:0:53:cafe::81) by DM3PR14CA0137.outlook.office365.com (2603:10b6:0:53::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23 via Frontend Transport; Mon, 29 Nov 2021 19:20:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-01.cornelisnetworks.com; Received: from awfm-01.cornelisnetworks.com (208.255.156.42) by DM6NAM11FT035.mail.protection.outlook.com (10.13.172.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22 via Frontend Transport; Mon, 29 Nov 2021 19:20:17 +0000 Received: from awfm-01.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-01.cornelisnetworks.com (8.14.7/8.14.7) with ESMTP id 1ATJK87Q118589; Mon, 29 Nov 2021 14:20:08 -0500 Subject: [PATCH for-rc 4/4] IB/hfi1: Fix leak of rcvhdrtail_dummy_kvaddr From: Dennis Dalessandro To: jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, Mike Marciniszyn , stable@vger.kernel.org Date: Mon, 29 Nov 2021 14:20:08 -0500 Message-ID: <20211129192008.101968.91302.stgit@awfm-01.cornelisnetworks.com> In-Reply-To: <20211129191510.101968.6259.stgit@awfm-01.cornelisnetworks.com> References: <20211129191510.101968.6259.stgit@awfm-01.cornelisnetworks.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14986a21-fde8-41dc-a280-08d9b36d4727 X-MS-TrafficTypeDiagnostic: BL0PR01MB4546: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SRCGl0Q2lcag1B48a2M/Jp667PADkxGIbp8iEsYC7rPCi5w4Lkhbb8lgtxbPGVkO0gEsPnMpw02Q7FeyPBLap7I5RWlA0LBCPwD8wSRtdJtvPXPCtFXmz3A6WXyWGbizr90/JmqFvcBkDFESLZqUo7AVHNfUfCp7ItknNQtN2pAzMlSGOzotGwfwSsyWWMrczcWzN8vWuvrdXPuEP0Jt6EnJAS1EflplwTKDxP6jEs1Jyp2+e7NlzVrc7LEGrxUNMR9A14mXpoIoc/RIBd4ikR25IAim25Xd6T2xn59ZFM77vZOq2KurHVvw28Wk/UXKaR609gPN+z1a7l5qQEYWnmetaT5N7YVxm6dFfRNTG/GQihWJV7jZQmEGSH7lw1mLJBTfIY6M5G7gnkeEeVfVVZdGzk86ZbNP7DYQC2+hg/4ZVeZOgfxEb7A9SG0zWqUdYiaGcJdjSztPHHtNEXINCclker1D7XGqGg26K6NDb1pKsh5bhgo/yzDMXRwj5QU9h/GHK7panpAhRwe7iJZFv7xE+mEjDHj2Qc4WCA7q0VhKOpubKe09KxGsrb/onzmWV4djD0FRhYMWTiZUk3UNpeJdzgZ28mNEP/2UOUuEBCkcPLYFS3GD0ocyNt6JHyF7aXFflYH9Fw/syYs/BAxcydHzGX36amfNX7ZaWGxLyLLBCcJhidQP0rB3OvOz9VUI+Gr4oF1bZVHbF119dRnDD3LT4W5DnLhYI18Vb7I5y5U= X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-01.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(136003)(376002)(39840400004)(396003)(346002)(36840700001)(46966006)(4326008)(2906002)(44832011)(7126003)(55016003)(81166007)(186003)(316002)(83380400001)(6916009)(336012)(26005)(70206006)(1076003)(426003)(103116003)(82310400004)(356005)(86362001)(7696005)(5660300002)(8936002)(36860700001)(508600001)(47076005)(8676002)(70586007)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2021 19:20:17.5373 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 14986a21-fde8-41dc-a280-08d9b36d4727 X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-01.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR01MB4546 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Mike Marciniszyn This buffer is currently allocated in hfi1_init(): if (reinit) ret = init_after_reset(dd); else ret = loadtime_init(dd); if (ret) goto done; /* allocate dummy tail memory for all receive contexts */ dd->rcvhdrtail_dummy_kvaddr = dma_alloc_coherent(&dd->pcidev->dev, sizeof(u64), &dd->rcvhdrtail_dummy_dma, GFP_KERNEL); if (!dd->rcvhdrtail_dummy_kvaddr) { dd_dev_err(dd, "cannot allocate dummy tail memory\n"); ret = -ENOMEM; goto done; } The reinit triggered path will overwrite the old allocation and leak it. Fix by moving the allocation to hfi1_alloc_devdata() and the deallocation to hfi1_free_devdata(). Cc: stable@vger.kernel.org Fixes: 46b010d3eeb8 ("staging/rdma/hfi1: Workaround to prevent corruption during packet delivery") Signed-off-by: Mike Marciniszyn Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/init.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/init.c b/drivers/infiniband/hw/hfi1/init.c index 6422dd6..4436ed4 100644 --- a/drivers/infiniband/hw/hfi1/init.c +++ b/drivers/infiniband/hw/hfi1/init.c @@ -875,18 +875,6 @@ int hfi1_init(struct hfi1_devdata *dd, int reinit) if (ret) goto done; - /* allocate dummy tail memory for all receive contexts */ - dd->rcvhdrtail_dummy_kvaddr = dma_alloc_coherent(&dd->pcidev->dev, - sizeof(u64), - &dd->rcvhdrtail_dummy_dma, - GFP_KERNEL); - - if (!dd->rcvhdrtail_dummy_kvaddr) { - dd_dev_err(dd, "cannot allocate dummy tail memory\n"); - ret = -ENOMEM; - goto done; - } - /* dd->rcd can be NULL if early initialization failed */ for (i = 0; dd->rcd && i < dd->first_dyn_alloc_ctxt; ++i) { /* @@ -1200,6 +1188,11 @@ void hfi1_free_devdata(struct hfi1_devdata *dd) dd->tx_opstats = NULL; kfree(dd->comp_vect); dd->comp_vect = NULL; + if (dd->rcvhdrtail_dummy_kvaddr) + dma_free_coherent(&dd->pcidev->dev, sizeof(u64), + (void *)dd->rcvhdrtail_dummy_kvaddr, + dd->rcvhdrtail_dummy_dma); + dd->rcvhdrtail_dummy_kvaddr = NULL; sdma_clean(dd, dd->num_sdma); rvt_dealloc_device(&dd->verbs_dev.rdi); } @@ -1297,6 +1290,15 @@ static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, goto bail; } + /* allocate dummy tail memory for all receive contexts */ + dd->rcvhdrtail_dummy_kvaddr = + dma_alloc_coherent(&dd->pcidev->dev, sizeof(u64), + &dd->rcvhdrtail_dummy_dma, GFP_KERNEL); + if (!dd->rcvhdrtail_dummy_kvaddr) { + ret = -ENOMEM; + goto bail; + } + atomic_set(&dd->ipoib_rsm_usr_num, 0); return dd; @@ -1504,13 +1506,6 @@ static void cleanup_device_data(struct hfi1_devdata *dd) free_credit_return(dd); - if (dd->rcvhdrtail_dummy_kvaddr) { - dma_free_coherent(&dd->pcidev->dev, sizeof(u64), - (void *)dd->rcvhdrtail_dummy_kvaddr, - dd->rcvhdrtail_dummy_dma); - dd->rcvhdrtail_dummy_kvaddr = NULL; - } - /* * Free any resources still in use (usually just kernel contexts) * at unload; we do for ctxtcnt, because that's what we allocate.