From patchwork Sat Feb 15 05:44:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13975950 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (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 A8AF61624D9; Sat, 15 Feb 2025 05:44:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598281; cv=none; b=OJpDwxNOvbz76A5tQSReQkSzUTkbWFHct3x0ZDEYMGuPQzNDD0o0yzft7jX/uf5/hSukaIzVm2W2675k2SmcFhMThYmU4S6fP53SwzPt/X1dUUXqdmIMYWmchxojW8tV0yjUxWeWQbWSCVPAZHav4ABrJKwrpMrp9hYSXfMPsYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598281; c=relaxed/simple; bh=jBt7+vnJjRgzyW+ey5C4tsfMOJ85XpSkNkkXKzASRZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iCjGTbsFKxIb+3YGm5ZJCYhovzJJF7EzPFcI4DH09Zh6MIZxgJ45PDFwCXMqpQ/NjBEdsqWdU9I6Q1I1T+YcPXbC33rbFmJQilkSOrFnsr9WLADXyovrOeuUEU3JOskWU2xu4YsP86XEgSWyj1ToaPNGrXuuTia7cVKbWiBWmEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=g16/x57e; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="g16/x57e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739598274; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=6mzodyOusN1fygK0BoeX0n09AD6gHWxROo2RlbkTXbE=; b=g16/x57erEKylUg/onc05qSlbJb7zU4YEGD+dVj2csSvkN5dDOlYR46f1wbcN68Nu2ICV0SEw8pXsWXSpa+Uqp5EZg2EYKh09dp8jSDrgsZRlhSkCwsIbZRpFLor+7WHDJipQWcQr1mzXAuEiMgOn6aB2psTaWNLC6Y2sWHitUw= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPSysNU_1739598273 cluster:ay36) by smtp.aliyun-inc.com; Sat, 15 Feb 2025 13:44:33 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, vkoul@kernel.org Cc: nikhil.rao@intel.com, xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/7] dmaengine: idxd: fix memory leak in error handling path of idxd_setup_wqs Date: Sat, 15 Feb 2025 13:44:25 +0800 Message-ID: <20250215054431.55747-2-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250215054431.55747-1-xueshuai@linux.alibaba.com> References: <20250215054431.55747-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Memory allocated for wqs is not freed if an error occurs during idxd_setup_wqs(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: a8563a33a5e2 ("dmanegine: idxd: reformat opcap output to match bitmap_parse() input") Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang --- drivers/dma/idxd/init.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index b946f78f85e1..b85736fd25bd 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -169,8 +169,8 @@ static int idxd_setup_wqs(struct idxd_device *idxd) idxd->wq_enable_map = bitmap_zalloc_node(idxd->max_wqs, GFP_KERNEL, dev_to_node(dev)); if (!idxd->wq_enable_map) { - kfree(idxd->wqs); - return -ENOMEM; + rc = -ENOMEM; + goto err_bitmap; } for (i = 0; i < idxd->max_wqs; i++) { @@ -191,6 +191,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd) rc = dev_set_name(conf_dev, "wq%d.%d", idxd->id, wq->id); if (rc < 0) { put_device(conf_dev); + kfree(wq); goto err; } @@ -204,6 +205,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd) wq->wqcfg = kzalloc_node(idxd->wqcfg_size, GFP_KERNEL, dev_to_node(dev)); if (!wq->wqcfg) { put_device(conf_dev); + kfree(wq); rc = -ENOMEM; goto err; } @@ -211,7 +213,9 @@ static int idxd_setup_wqs(struct idxd_device *idxd) if (idxd->hw.wq_cap.op_config) { wq->opcap_bmap = bitmap_zalloc(IDXD_MAX_OPCAP_BITS, GFP_KERNEL); if (!wq->opcap_bmap) { + kfree(wq->wqcfg); put_device(conf_dev); + kfree(wq); rc = -ENOMEM; goto err; } @@ -225,11 +229,21 @@ static int idxd_setup_wqs(struct idxd_device *idxd) return 0; err: - while (--i >= 0) { + while (i-- > 0) { wq = idxd->wqs[i]; + if (idxd->hw.wq_cap.op_config) + bitmap_free(wq->opcap_bmap); + kfree(wq->wqcfg); conf_dev = wq_confdev(wq); put_device(conf_dev); + kfree(wq); + } + bitmap_free(idxd->wq_enable_map); + +err_bitmap: + kfree(idxd->wqs); + return rc; } From patchwork Sat Feb 15 05:44:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13975952 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 1960C1714CF; Sat, 15 Feb 2025 05:44:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598282; cv=none; b=cRLb7fEZE2RqXIbBbvJ9N3njg1fuBjQOfLtrDpYqbaHEJo+Fxsh2eFnF9RdvYh9MdxxEY0x4dqaQF5Dd3loeqR9BBSHNYsiciAJFKA9xOuL0wH+biy0QGqGFTeDouatYgcWs6bgx6JM4zOb97a7hWZTRni4kux9o9//w2SFhikY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598282; c=relaxed/simple; bh=sXaN64ej2EoMki/lxw2I/rnnLCL7roUqvV1Jzzq6lSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EdsbE0zVfPBj5P0UZLFC+TVz26l77dLEUaZfFGrY7OaMpJ7ubrtfo0pIsnLmzrXC3BI7kWg5Co8kEBDMU5r9sfhXyKakaax3tXpg4Hzax6h3OfJz1muVdsAsLMV23rdNJI2Y80kMMeMyzq6w8LWMrHuESXtD3BbV4ZCJ8SXuIvk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=hDcqs8xo; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="hDcqs8xo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739598275; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=wethGuIidRNpnCkYM6wgAu5bx2tackfeipFWL5/OdMA=; b=hDcqs8xo3nTjgGU+hj7O0rSyqW7utssDB1kcIhxBrML90jGCUDN3ROWgzSTO8eX34qr32AgVGbsOxK3lVbYgtgqXU+nazCaAKfIT5FrPSDw8B4zTjfsoSVkBXMFfopXOpGM7ZKaEyfUyXcY7433QYQ+2ss1iG+qKtD1rjilU5ZE= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPSysNm_1739598274 cluster:ay36) by smtp.aliyun-inc.com; Sat, 15 Feb 2025 13:44:34 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, vkoul@kernel.org Cc: nikhil.rao@intel.com, xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/7] dmaengine: idxd: fix memory leak in error handling path of idxd_setup_engines Date: Sat, 15 Feb 2025 13:44:26 +0800 Message-ID: <20250215054431.55747-3-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250215054431.55747-1-xueshuai@linux.alibaba.com> References: <20250215054431.55747-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Memory allocated for engines is not freed if an error occurs during idxd_setup_engines(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: 75b911309060 ("dmaengine: idxd: fix engine conf_dev lifetime") Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang Reviewed-by: Fenghua Yu --- drivers/dma/idxd/init.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index b85736fd25bd..4e47075c5bef 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -277,6 +277,7 @@ static int idxd_setup_engines(struct idxd_device *idxd) rc = dev_set_name(conf_dev, "engine%d.%d", idxd->id, engine->id); if (rc < 0) { put_device(conf_dev); + kfree(engine); goto err; } @@ -290,7 +291,10 @@ static int idxd_setup_engines(struct idxd_device *idxd) engine = idxd->engines[i]; conf_dev = engine_confdev(engine); put_device(conf_dev); + kfree(engine); } + kfree(idxd->engines); + return rc; } From patchwork Sat Feb 15 05:44:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13975951 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (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 72134158D8B; Sat, 15 Feb 2025 05:44:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598281; cv=none; b=UjtR+2bx6KeSJQzOm0oPca/rYaSQT71f1qcSbYvsfBZIthqKacbOI5BKANa5MMKnxmhQWem5Fiw45PdQumHxXXvXbD7zLMXoE8d+9EWah53JczVeR75Z2s7sJNIN1tK78p3wQx/HiBaMrH2j2xCqT30TKvk2VJUYOWTK1Clmvt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598281; c=relaxed/simple; bh=kNrbFcj4cpsPTOptFX/x1HhuyqO99srfA6H4nXAHOMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JawrQf1WOzxM24LATKN771vJHWM5yVXgZAKHC58hz3/GongC8KhzU7SvH5VZ7F0hL0RC5CkF5Ck3XFr1bbO65gvhxARE/RvRxLNTs7hxbyJwx588k4ClCa0+XQLF4AMFli5lZIDSCgMlE6s7gJwnrxueEN7EH7X35xVLGuTSNiY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=On5Vxi8S; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="On5Vxi8S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739598275; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=+MVbKIezpcfCtllaZ2ooZF6RIq3YcQ+WJC5+YDPcqIk=; b=On5Vxi8SMCIYleTz0FfZHWSwRFxtKnewN1igt/YCFdi7if40hqfkMiXhEy15U89bZ88P7yv/ll7QOq3J2eWZf7/C11rEAHuCz70be+g5oOzZtobtwCJo+frT2p14ZJriNJgdYNXpeBKDSecfpWPIgvCKH3PY61qufi0jYDlQMAE= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPSysNs_1739598274 cluster:ay36) by smtp.aliyun-inc.com; Sat, 15 Feb 2025 13:44:34 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, vkoul@kernel.org Cc: nikhil.rao@intel.com, xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] dmaengine: idxd: fix memory leak in error handling path of idxd_setup_groups Date: Sat, 15 Feb 2025 13:44:27 +0800 Message-ID: <20250215054431.55747-4-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250215054431.55747-1-xueshuai@linux.alibaba.com> References: <20250215054431.55747-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Memory allocated for groups is not freed if an error occurs during idxd_setup_groups(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: defe49f96012 ("dmaengine: idxd: fix group conf_dev lifetime") Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang --- drivers/dma/idxd/init.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 4e47075c5bef..a2da68e6144d 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -328,6 +328,7 @@ static int idxd_setup_groups(struct idxd_device *idxd) rc = dev_set_name(conf_dev, "group%d.%d", idxd->id, group->id); if (rc < 0) { put_device(conf_dev); + kfree(group); goto err; } @@ -352,7 +353,10 @@ static int idxd_setup_groups(struct idxd_device *idxd) while (--i >= 0) { group = idxd->groups[i]; put_device(group_confdev(group)); + kfree(group); } + kfree(idxd->groups); + return rc; } From patchwork Sat Feb 15 05:44:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13975956 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 2CE7E19DF66; Sat, 15 Feb 2025 05:44:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598286; cv=none; b=fQq6YicQI9TU8IwDnRpmnMDoB8k24BDh6hbeLvcn5FWQXE70ef4qF5KIlaaCtqs50+wHMGi7dBBgU4MFl1bT9uA38O34rSQDkeASNb3uaMgSQdR1p8IaPQt7tamegisfv1MUeLGPSHV3Kh/OI6Pn+rcYcLxLGmdTCHtm6+GPzp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598286; c=relaxed/simple; bh=Gd3QuvVUwwaXOMTn22LJfR8ggxA+qsdsGFMiFuF6moU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oWclOIl9e8pYrtWiqbCD6Ue41S+KvJrTNQvisoIXyHzK3oQN4HV7488vtU/63YV804ByV3GgdNMHIeLAAZhRFK1Vq937JGcNGg5yjCOxPFWNAMkgK3rbDCugLyr89zhH9q311jmdbvetsvbT9YU8nJTO3np5g/valwvHRv50k/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=U1QanTi4; arc=none smtp.client-ip=115.124.30.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="U1QanTi4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739598276; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=TwIpPAeALoWFsS7S+cMv96y4UX2XGf68/jW3CZv7Zuw=; b=U1QanTi42mbeTm5XlxzaoRZHgehVx64MhqIH8HMGi0XNuz4sfg9LdXSSK4toHDfWEE6KTWyp3zQvOGh6bJwIc1Afh+/CFKsFfjQNAnPPFPspSOrJAxopWVrjtZB6r+Gwne3paoFFEWZXLtAcuYQo/0eAqabbYVdOgwK+ii1t9rc= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPSysO0_1739598275 cluster:ay36) by smtp.aliyun-inc.com; Sat, 15 Feb 2025 13:44:35 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, vkoul@kernel.org Cc: nikhil.rao@intel.com, xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] dmaengine: idxd: fix memory leak in error handling path of idxd_alloc Date: Sat, 15 Feb 2025 13:44:28 +0800 Message-ID: <20250215054431.55747-5-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250215054431.55747-1-xueshuai@linux.alibaba.com> References: <20250215054431.55747-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Memory allocated for idxd is not freed if an error occurs during idxd_alloc(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: a8563a33a5e2 ("dmanegine: idxd: reformat opcap output to match bitmap_parse() input") Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang --- drivers/dma/idxd/init.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index a2da68e6144d..dc34830fe7c3 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -567,28 +567,34 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d idxd_dev_set_type(&idxd->idxd_dev, idxd->data->type); idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL); if (idxd->id < 0) - return NULL; + goto err_ida; idxd->opcap_bmap = bitmap_zalloc_node(IDXD_MAX_OPCAP_BITS, GFP_KERNEL, dev_to_node(dev)); - if (!idxd->opcap_bmap) { - ida_free(&idxd_ida, idxd->id); - return NULL; - } + if (!idxd->opcap_bmap) + goto err_opcap; device_initialize(conf_dev); conf_dev->parent = dev; conf_dev->bus = &dsa_bus_type; conf_dev->type = idxd->data->dev_type; rc = dev_set_name(conf_dev, "%s%d", idxd->data->name_prefix, idxd->id); - if (rc < 0) { - put_device(conf_dev); - return NULL; - } + if (rc < 0) + goto err_name; spin_lock_init(&idxd->dev_lock); spin_lock_init(&idxd->cmd_lock); return idxd; + +err_name: + put_device(conf_dev); + bitmap_free(idxd->opcap_bmap); +err_opcap: + ida_free(&idxd_ida, idxd->id); +err_ida: + kfree(idxd); + + return NULL; } static int idxd_enable_system_pasid(struct idxd_device *idxd) From patchwork Sat Feb 15 05:44:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13975957 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 DED3819F419; Sat, 15 Feb 2025 05:44:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598286; cv=none; b=UMgEyJ+u+1MKNueQMWxL+BjaJkltu7cb19byzLD+MzSyEorYwib1T6bayKakGZ5lWOGxHezxEsCVGtdZC3hWAXCR+Kav5K1VYS0vgUStc+2o9talYLv58CFUo8J1cnDeBZ8PaP5ewQUdB1N4u7caUNTU4w4lvF2v27cDMZArypQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598286; c=relaxed/simple; bh=kHWOKaugnCugIRfbWHpMJb0nYUXoXLMBAwcA+g+xgrs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pN4OU+ZhBVSB61WpnXALeiBU1aHqjVpHfRysSOhElOlz+TJLgE9idPblQqgmJDsWUC2JSDXsNCcJNJmQI7/O/paGu+2ctPGBzzuD+W2ueB+tg/Cfpw2XRlGbP9pcHqW9PYi+sGWyjygiHIVqdRQDjlVU8J1sWu4pvgQe1ysCtS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=yXBp7FAj; arc=none smtp.client-ip=115.124.30.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="yXBp7FAj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739598276; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Ip3C2z8pFwpxrfoRX4KLEGAhWo1Y0wrskFEhejStJcE=; b=yXBp7FAj2/7kSggJ95Cr2ayM2Bls5y1CATV9iYuW8kF2OVLZqZO6O7dwx8p0gwPJIdN2BNtCuEMDn1I8gWyJM/Wn05ZCdlL7hKYsgEtSfMMKlFRqYlqD3L/I7W14x+t57Y67CHQj/GIypR2x7I/5j1VpPj2FFa2VX3ei1EqLR0I= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPSysO9_1739598275 cluster:ay36) by smtp.aliyun-inc.com; Sat, 15 Feb 2025 13:44:36 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, vkoul@kernel.org Cc: nikhil.rao@intel.com, xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] dmaengine: idxd: fix memory leak in error handling path of idxd_pci_probe Date: Sat, 15 Feb 2025 13:44:29 +0800 Message-ID: <20250215054431.55747-6-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250215054431.55747-1-xueshuai@linux.alibaba.com> References: <20250215054431.55747-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Memory allocated for idxd is not freed if an error occurs during idxd_pci_probe(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: bfe1d56091c1 ("dmaengine: idxd: Init and probe for Intel data accelerators") Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang --- drivers/dma/idxd/init.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index dc34830fe7c3..ac1cdc1d82bf 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -550,6 +550,14 @@ static void idxd_read_caps(struct idxd_device *idxd) idxd->hw.iaa_cap.bits = ioread64(idxd->reg_base + IDXD_IAACAP_OFFSET); } +static void idxd_free(struct idxd_device *idxd) +{ + put_device(idxd_confdev(idxd)); + bitmap_free(idxd->opcap_bmap); + ida_free(&idxd_ida, idxd->id); + kfree(idxd); +} + static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data) { struct device *dev = &pdev->dev; @@ -1219,7 +1227,7 @@ int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev, err: pci_iounmap(pdev, idxd->reg_base); err_iomap: - put_device(idxd_confdev(idxd)); + idxd_free(idxd); err_idxd_alloc: pci_disable_device(pdev); return rc; From patchwork Sat Feb 15 05:44:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13975953 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) (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 3C98217799F; Sat, 15 Feb 2025 05:44:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598283; cv=none; b=ZoTcBbbGh7KsKPMhNGRAmbN0oBvYtPmJEwmelIy1CIduixoqk97SE/Eri/1TNdPxtY6QSZgmhuzb+QadFXeUSZnNcV4APqqNLfjcUfXdfOs+OGMVmmQJvSxhNXmM6lip3XKukGhJhvGrdXzr44lJylo7gVo8dkpp/2ZCQ5eK6mU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598283; c=relaxed/simple; bh=yo7qlUaeF3xO9z4Scj60HtMY12AAzelde4yE32W+jFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mE2JPaaABfIAlwpvlVXUL5NDkP97ZTq9uNcTm2rwBzqRxLmptM/TBCOC/MY+X82794lCOC4LxvessdNfk+HgYO07PKh1Jm9+ANbceFEHAZqjqV3qAmkPYQRvdXUW5p8D0AlYWfPmr7RKrXjO06P9e6t1FC4Dk422PzZbXHIFxpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=d6ELRKUe; arc=none smtp.client-ip=115.124.30.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="d6ELRKUe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739598277; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Ca7xZlMAPEYMN9D4MiMu30TtHiCMTqjknr5SucAhlr8=; b=d6ELRKUecePhOPnkn/QCBeBJgispvx+uBu+JgDGxNtEnKx4cExanya43bR3DJfVjcBm9Y+p9UjYVAdf8H+4NZVkzEUnF6AKm031EQ3EFZhtv85v5XCuirxTrUgkqgiZugnpYRcNpPIP/durXAZsMRa4u+yxd+KbjekCt0jF4QGQ= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPSysOL_1739598276 cluster:ay36) by smtp.aliyun-inc.com; Sat, 15 Feb 2025 13:44:36 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, vkoul@kernel.org Cc: nikhil.rao@intel.com, xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] dmaengine: idxd: Add missing idxd cleanup to fix memory leak in remove call Date: Sat, 15 Feb 2025 13:44:30 +0800 Message-ID: <20250215054431.55747-7-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250215054431.55747-1-xueshuai@linux.alibaba.com> References: <20250215054431.55747-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The remove call stack is missing idxd cleanup to free bitmap, ida and the idxd_device. Call idxd_free() helper routines to make sure we exit gracefully. Fixes: bfe1d56091c1 ("dmaengine: idxd: Init and probe for Intel data accelerators") Suggested-by: Vinicius Costa Gomes Signed-off-by: Shuai Xue --- drivers/dma/idxd/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index ac1cdc1d82bf..f40f1c44a302 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -1295,7 +1295,7 @@ static void idxd_remove(struct pci_dev *pdev) pci_disable_device(pdev); destroy_workqueue(idxd->wq); perfmon_pmu_remove(idxd); - put_device(idxd_confdev(idxd)); + idxd_free(idxd); } static struct pci_driver idxd_pci_driver = { From patchwork Sat Feb 15 05:44:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13975954 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (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 4342F1885B8; Sat, 15 Feb 2025 05:44:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598283; cv=none; b=QkyxA9CMi25OU1+5DHvWmZ8wUBl+0pOLG38bpME7SMEBeavda7ZeRnmYwLnnDZLxtrEWIkEdYnlHvSsTrCbBi+YlKYMLBSqvRCBGjo62AoJIcgK998OVrhW6CCyY3xhUZr9V5XbGdPnfLvDVRkTE6lu65ZZAotNL+t6EiUYYXhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739598283; c=relaxed/simple; bh=cJA4KfJMcaxH+0TnGhLHjE1Vg4xal9BE0r8mnGst23Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rPF39FHX/z/wnmLoSHrbw3p9xcvoS945A6ZCZjqGMquKv++hGF6nFrKLJSU/PjzuNvtxGPlU6XkEH6Y9x1RTr7k54JhV5la91iCjGdEVsfRd2sCEsZC6N1DXc/iUqAZCDPCdXGfrSvU2jeCSXjm/D9Mgtps2iIRp3cxfQ/fiaho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=YPcFI704; arc=none smtp.client-ip=115.124.30.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="YPcFI704" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739598277; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=v12LeWPu6e0WL/LjRIaAjzQvV7k89DRLKSi3Y5y47eU=; b=YPcFI704tFD+2lpggMKaRd71IaPlPzjEBgGd6eb20HaCFJZTaz0HlCHYxc12jjFvKi02z/S3HdmT4IB3JooqMxRVcSBzryMTEEH8JJ1W964rUa9tzRZdXUngi6NEtG8WLy4Z/FHSBDTS4vHzzLGPtuI2imJ6uHd3wfyOdQgv5Fk= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPSysOT_1739598276 cluster:ay36) by smtp.aliyun-inc.com; Sat, 15 Feb 2025 13:44:37 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, vkoul@kernel.org Cc: nikhil.rao@intel.com, xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] dmaengine: idxd: Refactor remove call with idxd_cleanup() helper Date: Sat, 15 Feb 2025 13:44:31 +0800 Message-ID: <20250215054431.55747-8-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250215054431.55747-1-xueshuai@linux.alibaba.com> References: <20250215054431.55747-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The idxd_cleanup() helper clean up perfmon, interrupts, internals and so on. Refactor remove call with idxd_cleanup() helper to avoid code duplication. Note, this also fixes the missing put_device() for idxd groups, enginces and wqs. Fixes: bfe1d56091c1 ("dmaengine: idxd: Init and probe for Intel data accelerators") Suggested-by: Vinicius Costa Gomes Signed-off-by: Shuai Xue --- drivers/dma/idxd/init.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index f40f1c44a302..0fbfbe024c29 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -1282,20 +1282,11 @@ static void idxd_remove(struct pci_dev *pdev) get_device(idxd_confdev(idxd)); device_unregister(idxd_confdev(idxd)); idxd_shutdown(pdev); - if (device_pasid_enabled(idxd)) - idxd_disable_system_pasid(idxd); idxd_device_remove_debugfs(idxd); - - irq_entry = idxd_get_ie(idxd, 0); - free_irq(irq_entry->vector, irq_entry); - pci_free_irq_vectors(pdev); + idxd_cleanup(idxd); pci_iounmap(pdev, idxd->reg_base); - if (device_user_pasid_enabled(idxd)) - idxd_disable_sva(pdev); - pci_disable_device(pdev); - destroy_workqueue(idxd->wq); - perfmon_pmu_remove(idxd); idxd_free(idxd); + pci_disable_device(pdev); } static struct pci_driver idxd_pci_driver = {