Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp662037rdb; Thu, 18 Jan 2024 15:14:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDdiuh5aO/58RPtMsKgeNBvt8aHB7lj905ax/nV82yNLLJ35XRtR6UykxSvW16Mbetib3o X-Received: by 2002:a05:6a20:4285:b0:19a:f071:6ba5 with SMTP id o5-20020a056a20428500b0019af0716ba5mr1737619pzj.36.1705619672619; Thu, 18 Jan 2024 15:14:32 -0800 (PST) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l24-20020a63ba58000000b005c624eec079si2222624pgu.724.2024.01.18.15.14.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 15:14:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30626-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@cornelisnetworks.com header.s=selector1 header.b=JxjcJWIk; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-30626-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30626-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3E603288751 for ; Thu, 18 Jan 2024 23:14:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC6331E488; Thu, 18 Jan 2024 23:14:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cornelisnetworks.com header.i=@cornelisnetworks.com header.b="JxjcJWIk" Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2130.outbound.protection.outlook.com [40.107.100.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0724728DA1; Thu, 18 Jan 2024 23:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.130 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705619660; cv=fail; b=IQfbVW6YaOTK7M8EbHqA6ERTLh4UL/MD82FHE3CElJFS/2lzCpyZFIC1hNrta3KN29EGnGON+2rV5qtN5x2PkObT0FYB+ZklMQuM1xoduoYdVpQ0ukUxzHkMbyMDXRYkSInssvBf4h5wZB8UiTwxtWv12e/08jVIg1kP+oLwCSI= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705619660; c=relaxed/simple; bh=IwLKRfz35/0Ixzh7L8Ae13vAaNZRfFGbshN6K3U0eEc=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=R9euo6hqY0xi15dyZzNxAZtb+URxRuRKPeuyY7s+Ir5IKvp7KaSDckYeW563PAwPcPrGc9vSHUT/geU29CE/jvf0pejrkSFtZ2D3tJOEKrGD/Vh2bAMDAMyzQMQ4vURk2KWxvkb9bRGgLbPGudU0rvySNXtSvNkNQzzM6gnstSA= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cornelisnetworks.com; spf=pass smtp.mailfrom=cornelisnetworks.com; dkim=pass (2048-bit key) header.d=cornelisnetworks.com header.i=@cornelisnetworks.com header.b=JxjcJWIk; arc=fail smtp.client-ip=40.107.100.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cornelisnetworks.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cornelisnetworks.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tziyl2CrdNJ9c1PLK1Lx2IPAPWHWklXyY5nIZtnmrjBb84EHsr2Vhi6vNL6S+CwHwy0fWL/BErORtvm9Qbxtm8JnxIwX15cSySmlAtO8Q/+zM5ocM73bwGau2DHDGU90uPO3D/xiKa6aXMzyYbBlAJ8+KZp/FyHjwarCwY70f9lihYzHfL1HfowACRkzPLtwL31v1/WYY1WYmuLFUAp1nBOk78SDkUt8SuVgN5rkE9kuoIcwGlqgOCCLyF8PnagtyhcrZAaK0lyP3pc5a8nilekH+f30F0E0gMgiWyaKy/idNnmyTyp4q0P34yCEQiZyC+jgxZBtruC553/HBHuTTQ== 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=Qmlhdvq7cAbrOwTdAy3Pjvqf9jLoh4z52NGx23VBvnM=; b=aQUEl929y/m2OlrzI6ML9DNOTXZ9X7aa8n6fGzjE+WxjQ2uO0OEdNejGWNlBiaOnHaQ2k9KyE/tKS6y387H8Su92XppWnbPR46KslZVMMBASR7T+Lmkr8NYuTmc6Aq2cZKYhJYjnlKzbCwXl3LVi+3hlP378Bzm9kDtjq0vTy/okdiXr3K6qG4T5MpkV4ZKWuhPdntFzOvuU1DdokFgItbtAXXolzU2FkOxPI4hBqmSDOi1nAyZiQCnZa9vrSETAzNthu8B78lymdhVBWnYoEHaOm2/7XcpKG/MSUSNMRZ0ELCktKxkWt0nmm9FqOL7X5orU4Z7wvprLTPWISBCqdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornelisnetworks.com; dmarc=pass action=none header.from=cornelisnetworks.com; dkim=pass header.d=cornelisnetworks.com; 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=Qmlhdvq7cAbrOwTdAy3Pjvqf9jLoh4z52NGx23VBvnM=; b=JxjcJWIk1oJXE+olF9E/Gu43x7Ak2o2j0lnpmoxzlm6wUkZWCkOSLo5QwKXSC/8w1mlabqteSL/tDTSU/EHZ1ssZGdkblmUz6Y09X0XZx9UARINzyW8VjQKVEJ0CGecnIAlGl2SWtSfZ570NZ3Q03jBo2Kah2q4JFk81fAqZJlfrYzntPui1zRw8ppBPc0ItCpvqxbV9LLfJu0bNXDbDKqrFQjPIC2BSFjoW6Itr/O9DGlmu4zH1cpSEmXAdXa1wOXueQCjKOahxtssmfVpVuMYNc6gDUx+iHBiHs8tTBwM7hirPyEiWLz1pPPR7CA7xMPao7DToxKqpjMlHpGqNDQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cornelisnetworks.com; Received: from BL0PR01MB4099.prod.exchangelabs.com (2603:10b6:208:42::12) by CH0PR01MB7020.prod.exchangelabs.com (2603:10b6:610:109::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.24; Thu, 18 Jan 2024 23:14:14 +0000 Received: from BL0PR01MB4099.prod.exchangelabs.com ([fe80::1840:13fa:59b2:40c5]) by BL0PR01MB4099.prod.exchangelabs.com ([fe80::1840:13fa:59b2:40c5%7]) with mapi id 15.20.7202.024; Thu, 18 Jan 2024 23:14:14 +0000 Message-ID: <28aeb877-c0b4-4236-87d5-0bbaeb185656@cornelisnetworks.com> Date: Thu, 18 Jan 2024 18:14:11 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] IB/hfi1: fix a memleak in init_credit_return Content-Language: en-US To: Leon Romanovsky , Zhipeng Lu Cc: Jason Gunthorpe , Ravi Krishnaswamy , Harish Chegondi , Brendan Cunningham , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240112085523.3731720-1-alexious@zju.edu.cn> <20240114090434.GD6404@unreal> From: Dennis Dalessandro In-Reply-To: <20240114090434.GD6404@unreal> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BLAPR03CA0091.namprd03.prod.outlook.com (2603:10b6:208:32a::6) To BL0PR01MB4099.prod.exchangelabs.com (2603:10b6:208:42::12) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR01MB4099:EE_|CH0PR01MB7020:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c9f4a11-d5e0-4ac5-1bf6-08dc187b2f64 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G6Z/HPsaENPhWlNqAsmeERQUsFY+fRKi7Y+oYIuNXpy7q+5HS5/pU+MOIWoaXsCUbnRownwmSluO1PFMagEl3Bxc10qCSJWYFjruiXcTA02If9I6vYqjLBK74XRsPefwknAZ2ySNYRjWFoFhD1mtJ51ATNP0kmXL3K/QTdZ5iDt1zg1qGfcnn7sRmUVOVO0HuEn3bvwPnlP+3S3n5UoT4b0HxGuL+HJ/SoA6+eQ3FVL1mytHB4qiMW0z5fCs/UqtDyMBiE4jgHBrzw9t+JjH/nDNVVBNXzWPyCPeSEe6jSx5BW0ERdDWhAfUdneTRQlDbmqt4n7vcUIPZTrlf4nt0EGzZE0dokyftVgYRjTHo1EXFPUhJBSTv+Zx58TdPS96drGLXgCoP7HM1vve9m90QfBZKhtzCD40cSYpPZ9sq60r0J2988yXNf5Vy+sa/zLkHO3rSiMbQoLEYmxsDqrVWlELmIGxv27ezuR3IQodTd1cp3b4k5zaNHphTrbFoRrN8qB6KxaqLT90Zbe8IbculDfM1/51nkCKeJd9UJZktbdcNDhZ0qLKh9jmSLndJmT5IBQ7Sr7TPNP3802pcbCH+u6c7VfivId5V8nbwTF//dmBho5i4WeYyso7HdHXc8qa4ileDkAFl6ez8bPddaaTFA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR01MB4099.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(346002)(396003)(366004)(39840400004)(136003)(1800799012)(64100799003)(451199024)(186009)(6506007)(66899024)(38100700002)(86362001)(36756003)(41300700001)(31696002)(38350700005)(2906002)(110136005)(66556008)(54906003)(66476007)(66946007)(53546011)(52116002)(316002)(478600001)(6512007)(6666004)(6486002)(2616005)(8936002)(4326008)(8676002)(5660300002)(83380400001)(26005)(44832011)(31686004)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aDhLaEVMNHBCaFhMMUtWMWVSTllicHhJZ0UxbWtpbTg0U0VWSVVVWDZPYndr?= =?utf-8?B?MFgrWGozaS9UbGdVc2JpVmVNUDMwa1o5M1JlL0RZT3A0dHZyaEZFY1ZvZGMx?= =?utf-8?B?WlR3RGVGT1hNNVJXT1UrNVl3djdnVWVzdDVOam5QNld0Q2wwczRHNjRvc09D?= =?utf-8?B?WGNpTnpvNUhPNlAyQmdSVXMrNHF3aEFhaU55bHYveHVZWmlwZUdSZDRaV3Za?= =?utf-8?B?QjljQU9UK2NoU0RQSGJzME5iSWkydVdsYWx1Tmo0dWg0eStyNTRmWjhRZWlQ?= =?utf-8?B?V3FsOGdINzdUa00zOVNYNlBwcEdnTG8rcTRFZCtLa3hWYjgwbll5VXE4dzZ2?= =?utf-8?B?Z2E2cUoybkRPby9KNjFaQ00wM09YUHA1ZWdBWUIvVmliaStrdH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3H1QV0UfP2mu0ME=3D?= X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c9f4a11-d5e0-4ac5-1bf6-08dc187b2f64 X-MS-Exchange-CrossTenant-AuthSource: BL0PR01MB4099.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2024 23:14:14.1827 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qR1YBePYYciK9md0bZO2iOD/S33SLRrEnd117ywx9ApSG7nomDI8kLs/iYfgZ+rDpo70mIe72SooszryAAgGsMzjKpH0CT3JBeiqma7RvdGnrV2KE9n/GgK44uFgPSjv X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR01MB7020 On 1/14/24 4:04 AM, Leon Romanovsky wrote: > On Fri, Jan 12, 2024 at 04:55:23PM +0800, Zhipeng Lu wrote: >> When dma_alloc_coherent fails to allocate dd->cr_base[i].va, >> init_credit_return should deallocate dd->cr_base and >> dd->cr_base[i] that allocated before. Or those resources >> would be never freed and a memleak is triggered. >> >> Fixes: 7724105686e7 ("IB/hfi1: add driver files") >> Signed-off-by: Zhipeng Lu >> --- >> drivers/infiniband/hw/hfi1/pio.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/infiniband/hw/hfi1/pio.c b/drivers/infiniband/hw/hfi1/pio.c >> index 68c621ff59d0..5a91cbda4aee 100644 >> --- a/drivers/infiniband/hw/hfi1/pio.c >> +++ b/drivers/infiniband/hw/hfi1/pio.c >> @@ -2086,7 +2086,7 @@ int init_credit_return(struct hfi1_devdata *dd) >> "Unable to allocate credit return DMA range for NUMA %d\n", >> i); >> ret = -ENOMEM; >> - goto done; >> + goto free_cr_base; >> } >> } >> set_dev_node(&dd->pcidev->dev, dd->node); >> @@ -2094,6 +2094,10 @@ int init_credit_return(struct hfi1_devdata *dd) >> ret = 0; >> done: >> return ret; >> + >> +free_cr_base: >> + free_credit_return(dd); > > Dennis, > > The idea of this patch is right, but it made me wonder, if > free_credit_return() is correct. Yes, I've double checked the call path and if init_credit_return() fails we do not call the free_credit_return(). So this patch: Acked-by: Dennis Dalessandro > > init_credit_return() iterates with help of for_each_node_with_cpus(): > > 2062 int init_credit_return(struct hfi1_devdata *dd) > 2063 { > ... > 2075 for_each_node_with_cpus(i) { > 2076 int bytes = TXE_NUM_CONTEXTS * sizeof(struct credit_return); > 2077 > > But free_credit_return uses something else: > 2099 void free_credit_return(struct hfi1_devdata *dd) > 2100 { > ... > 2105 for (i = 0; i < node_affinity.num_possible_nodes; i++) { > 2106 if (dd->cr_base[i].va) { > > Thanks > >> + goto done; >> } >> >> void free_credit_return(struct hfi1_devdata *dd) I think we are OK because the allocation uses node_affinity.num_possible_nodes and in free_credit_return() we walk that entire array and if something is allocated we free it. Now why do we use for_each_node_with_cpus() at all? I believe that is because it produces a subset of what is represented by num_possible_nodes(), which is OK and doesn't leak anything. -Denny