From patchwork Fri Apr 4 12:02:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038366 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 CB8A51E1DE7; Fri, 4 Apr 2025 12:02:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768150; cv=none; b=iZ9LmD1VACpnQrC62UXHOJ5H0Jpi8nbGwM9T9lCvr4tWlI4uxgbWMsQC/WR/EBFrmXDGzlZ1hRL1mIXFK+NsV4bQR87habeywB5aFljPkwnYPpp0adZX1coXbs+i8KkTTNL0abCTTozZ1XhGsQRCIDDXcUyAMk6ofMWPZcucWdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768150; c=relaxed/simple; bh=Dt6RyjDkbtfECZNsTctiSSADXgGcZPflEasijEWIUQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YIukme3thPileMCVxX603J8xZWaJVcBbl/Pug44cSg7V2VDj1RDCC4fbpo4aibSYR3BkCHDYHRY8ffXCr0/ypbqfYHSfT1H5dnZ+0Q/2nyinfmQj+3XWeQozY/SRsKrnLPzrDR9sLiDwJD7CoXMKHTOZJSfjDX2nXaooNED77kw= 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=wlxXMvXd; arc=none smtp.client-ip=115.124.30.97 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="wlxXMvXd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768140; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=E63D3a4UUFyXm/wG8nOV+rzvBCPd3HiIjLHhpke82hY=; b=wlxXMvXd30XglQrMHA/XZn/BsP8Ok9oono9s0VNeqJsCCbSzb1BsimpmtcWu51+3rSypoOXd74feouSy7pCbnimBNXpH4Bs7gjjaRXD4tI9xaR5jyt9oruds38lt1JrPAKfPCaNw9qEfftEm9cDMelpAIxA3y8kgt4xuRbKuJkY= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld3p_1743768139 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:19 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/9] dmaengine: idxd: fix memory leak in error handling path of idxd_setup_wqs Date: Fri, 4 Apr 2025 20:02:09 +0800 Message-ID: <20250404120217.48772-2-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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: 7c5dd23e57c1 ("dmaengine: idxd: fix wq conf_dev 'struct device' lifetime") Fixes: 700af3a0a26c ("dmaengine: idxd: add 'struct idxd_dev' as wrapper for conf_dev") Fixes: de5819b99489 ("dmaengine: idxd: track enabled workqueues in bitmap") Fixes: b0325aefd398 ("dmaengine: idxd: add WQ operation cap restriction support") Cc: stable@vger.kernel.org Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang Reviewed-by: Fenghua Yu --- drivers/dma/idxd/init.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index fca1d2924999..80fb189c9624 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++) { @@ -189,10 +189,8 @@ static int idxd_setup_wqs(struct idxd_device *idxd) conf_dev->bus = &dsa_bus_type; conf_dev->type = &idxd_wq_device_type; rc = dev_set_name(conf_dev, "wq%d.%d", idxd->id, wq->id); - if (rc < 0) { - put_device(conf_dev); + if (rc < 0) goto err; - } mutex_init(&wq->wq_lock); init_waitqueue_head(&wq->err_queue); @@ -203,7 +201,6 @@ static int idxd_setup_wqs(struct idxd_device *idxd) wq->enqcmds_retries = IDXD_ENQCMDS_RETRIES; wq->wqcfg = kzalloc_node(idxd->wqcfg_size, GFP_KERNEL, dev_to_node(dev)); if (!wq->wqcfg) { - put_device(conf_dev); rc = -ENOMEM; goto err; } @@ -211,9 +208,8 @@ 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) { - put_device(conf_dev); rc = -ENOMEM; - goto err; + goto err_opcap_bmap; } bitmap_copy(wq->opcap_bmap, idxd->opcap_bmap, IDXD_MAX_OPCAP_BITS); } @@ -224,12 +220,28 @@ static int idxd_setup_wqs(struct idxd_device *idxd) return 0; - err: +err_opcap_bmap: + kfree(wq->wqcfg); + +err: + put_device(conf_dev); + kfree(wq); + 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 Fri Apr 4 12:02:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038367 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (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 3333E1E1020; Fri, 4 Apr 2025 12:02:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768152; cv=none; b=Jk8Xcdf4OKWPTcdkxsw8Uxm6xAJYe7AjKRnOtIe3koRxOzFG3kZNK2wVvWLhnwdXwM2sKWrgp1sEcfeRoUuYIpQESVrt5em8RBqVNer+TcXYxQc0yLdVxvDPLXdeC21Jrqh1eNc2Oom7HiBATo2jxIYx2TgetpESC/sXGWY6uz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768152; c=relaxed/simple; bh=KAyEV8BTleWW1dzXEcTbbOThEjffpdF7ikqrRRQ/Nzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FOGnEHJNLVpEWk5ICbQIvNKr2LLUiscPG+QFeRMSxswt6Jo1m0h3VaoNDbHs4W+aIbdx1zJClhclp7NZam8oiBK6LBY1RA+4Vq7/s0EvFFfBLjGLOYN1fVX0wOfdQ8A8fWbkLr+uSlMwC00fBt1nSiKWQ+5N2QeEl1Op4j26OSA= 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=cZBPEYzU; arc=none smtp.client-ip=115.124.30.132 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="cZBPEYzU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768140; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=bHrE7lpbUgz12wfwjxk2eHqBwsJF0K53E2iCqsP2ONE=; b=cZBPEYzU5FKBfy6Xc6OQzR+vNIItc/+6D2QKJ1WwRafS+t3vegUsIHkMPVl9+k5Sn0UtEbOqrVE52k9OF7wT78DUsnEl2ugKlVqyAzZoGrjAGVBGCK0j5dOLyGffk6Qrly8Z3sC5/sTLvU1F/cq12wSg9NkX9Yk4Ho2Ol7+u0/0= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld47_1743768140 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:20 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/9] dmaengine: idxd: fix memory leak in error handling path of idxd_setup_engines Date: Fri, 4 Apr 2025 20:02:10 +0800 Message-ID: <20250404120217.48772-3-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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") Cc: stable@vger.kernel.org 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 80fb189c9624..ff6ec3c0f604 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -275,6 +275,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; } @@ -288,7 +289,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 Fri Apr 4 12:02:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038369 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 01F391EFF90; Fri, 4 Apr 2025 12:02:30 +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=1743768154; cv=none; b=Uwt2XxrBntChqtNrulMLguU6VaZWCUiYvAEY4G6/EbaODJ4oW92LBV5EdPYCb7AzVjbu+PFPh9PNei/p9sq20E0ULK+/LqpRCAdv3PO9pJOi4XC7STYwzRKc7/SARr8feHagFaEOOUiKdmBrwqGnUGTH1cuHi9X5Fb8glh4p1Jk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768154; c=relaxed/simple; bh=d+jJYEEXvfxCfqpIfgEm+Tabi8hXYp5Fahd6eIu8Upw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kQCnW1tnyR7faE7b+EIeZHgGIrWPltmGEDkA4AJUj8tgTIRh5HpHATE1TeqjgmuEmnO6w4JFfuIUDB6dJ78u5M0mYjK3F+lj6AE1WnsG0Ly+TAeS2h5p9tmm/y7Xet2k1da/CJgY8jvKwmtKwrEZ33NHCCHKHPPDn0W31pdYhzg= 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=mElQKUG2; 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="mElQKUG2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768141; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=XJ01F+rqnhGV29oO2n8+5TyMDaDIvW//7qhuHE1yXcc=; b=mElQKUG2TjN7SyihbaU+/s1lK4AgDGxfrCQxuE5psxWTtW/uxa8qcNo4aauN8xZ99gTPERWgDPJuUszk8BFXW8Bl7PExk3KNEZm6JHVhmz+FU/nu95Nj4LpygJizRvp6TTm0RfrjkaXKsZShjNptWcLmWRVqbHFkIBpJfjQfMpg= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld4S_1743768140 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:20 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/9] dmaengine: idxd: fix memory leak in error handling path of idxd_setup_groups Date: Fri, 4 Apr 2025 20:02:11 +0800 Message-ID: <20250404120217.48772-4-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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") Cc: stable@vger.kernel.org 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 ff6ec3c0f604..7f0a26e2e0a5 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -326,6 +326,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; } @@ -350,7 +351,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 Fri Apr 4 12:02:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038364 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 96FAB191F98; Fri, 4 Apr 2025 12:02:25 +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=1743768148; cv=none; b=Ujme440KScpP9Nd9CHkrtsMS07YlAg4y0xz2FXfDmrZZtQ5FqcEIN4638mLoWiMoJbjuCQlrVYQfGf53h+hQWaiYM5iec9Oq+hcisRXH01lv+fJ3zAM2K5EKJ2WIexRiaenftWHLABbfpK3rhQYkRiubJWYjIEAxemR/athox4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768148; c=relaxed/simple; bh=J9dgHiVoUeDehzGhiMKQsLqo/lrePUAYwnsmDH/a2V8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DK/Lo2XejDM4PwXwNtFhC4JvNefcIU+WHg9ibVeFTpaPKRH13fuXh65CPMkUR7+XSfJz94p9nK9j95J8DuY2bdZWlRtBVBDd7GiG/0/tocG/E4vR+VV7SDybUqQhZi1HgDYppz+9L8LAef9LWcFU3uN9kSANhnPhlyq+VcmUrOg= 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=e90dXDhj; 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="e90dXDhj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768143; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=X1wSzaMsYxcrm8YLnnJlfkvlBMimjzDbk7WoYmqzepA=; b=e90dXDhjxQIAvK23GFafkWk+YkJMVJl+AhlW2iHqncH2jwA58C6z6157FfuV84WxomSr6ceJd5I7yprITGlcVzTZjKVIPq/C8QdUzhydrY+cqqyMX4DzDYcjjAejRiwqGsHV8YWgDYU8ECLBCj15EK3NNhcP5XDmg5Hg+LudhyM= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld4u_1743768141 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:21 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/9] dmaengine: idxd: Add missing cleanup for early error out in idxd_setup_internals Date: Fri, 4 Apr 2025 20:02:12 +0800 Message-ID: <20250404120217.48772-5-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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_setup_internals() is missing some cleanup when things fail in the middle. Add the appropriate cleanup routines: - cleanup groups - cleanup enginces - cleanup wqs to make sure it exits gracefully. Fixes: defe49f96012 ("dmaengine: idxd: fix group conf_dev lifetime") Cc: stable@vger.kernel.org Suggested-by: Fenghua Yu Signed-off-by: Shuai Xue Reviewed-by: Fenghua Yu --- drivers/dma/idxd/init.c | 58 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 7f0a26e2e0a5..a40fb2fd5006 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -155,6 +155,25 @@ static void idxd_cleanup_interrupts(struct idxd_device *idxd) pci_free_irq_vectors(pdev); } +static void idxd_clean_wqs(struct idxd_device *idxd) +{ + struct idxd_wq *wq; + struct device *conf_dev; + int i; + + for (i = 0; i < idxd->max_wqs; i++) { + 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); + kfree(idxd->wqs); +} + static int idxd_setup_wqs(struct idxd_device *idxd) { struct device *dev = &idxd->pdev->dev; @@ -245,6 +264,21 @@ static int idxd_setup_wqs(struct idxd_device *idxd) return rc; } +static void idxd_clean_engines(struct idxd_device *idxd) +{ + struct idxd_engine *engine; + struct device *conf_dev; + int i; + + for (i = 0; i < idxd->max_engines; i++) { + engine = idxd->engines[i]; + conf_dev = engine_confdev(engine); + put_device(conf_dev); + kfree(engine); + } + kfree(idxd->engines); +} + static int idxd_setup_engines(struct idxd_device *idxd) { struct idxd_engine *engine; @@ -296,6 +330,19 @@ static int idxd_setup_engines(struct idxd_device *idxd) return rc; } +static void idxd_clean_groups(struct idxd_device *idxd) +{ + struct idxd_group *group; + int i; + + for (i = 0; i < idxd->max_groups; i++) { + group = idxd->groups[i]; + put_device(group_confdev(group)); + kfree(group); + } + kfree(idxd->groups); +} + static int idxd_setup_groups(struct idxd_device *idxd) { struct device *dev = &idxd->pdev->dev; @@ -410,7 +457,7 @@ static int idxd_init_evl(struct idxd_device *idxd) static int idxd_setup_internals(struct idxd_device *idxd) { struct device *dev = &idxd->pdev->dev; - int rc, i; + int rc; init_waitqueue_head(&idxd->cmd_waitq); @@ -441,14 +488,11 @@ static int idxd_setup_internals(struct idxd_device *idxd) err_evl: destroy_workqueue(idxd->wq); err_wkq_create: - for (i = 0; i < idxd->max_groups; i++) - put_device(group_confdev(idxd->groups[i])); + idxd_clean_groups(idxd); err_group: - for (i = 0; i < idxd->max_engines; i++) - put_device(engine_confdev(idxd->engines[i])); + idxd_clean_engines(idxd); err_engine: - for (i = 0; i < idxd->max_wqs; i++) - put_device(wq_confdev(idxd->wqs[i])); + idxd_clean_wqs(idxd); err_wqs: return rc; } From patchwork Fri Apr 4 12:02:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038368 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 F026A191F98; Fri, 4 Apr 2025 12:02:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768153; cv=none; b=fkV5yS0HiN9hLdVPdDMA6PiKVntDOdjjNuz/lO1UGo1CkPzvjcz1MVMl+D9OlkxUcYQKc44VhpGa4c3tEWd//9oF+UG1mJotg6KDkjoxCzIk3TjqGtt0/+l5xtLT9HTiOisyarPmXS9Sijz8L/dm2TNoQc+BDlrqqc1k/TcVvK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768153; c=relaxed/simple; bh=dqDu8WL4h4bZfWHM69QQlCAdoWMi8cbOaNG41oLCUw0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ILI7TYHfO74gGww+L+TSzo2Gax/dubltsygcRTvGRwYKModTQQ4gOjVtCWNxdj1Xns5Ln91PyZDRng9iSzAogetlQSq51hlxgocfErP/qrWNMYhi63+e2VKfgCCOW+J/d7KZ+byctfQdS1DssdaMOI9ycTNmRcQsP5dNRApKCVA= 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=yKmuO7x4; arc=none smtp.client-ip=115.124.30.97 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="yKmuO7x4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768144; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=BF0hRp/spta9T2HH0txDA+euJMfdcZjxuSjIy5hZh2U=; b=yKmuO7x4uDWBRtVFiav3k9/+m09KF8/7pSJj988XW0N4GmOijoqFWGq2heLZXhfYeQsGD+caJTwmdwpPeYITRcu4lpJOs3fxBQsCOfXtPNEIdvba1zvQPguGimlogDPP514cjCuOqOO1vhJVzPGZBUxPdpysbe8YwWdhpymAy6s= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld5F_1743768141 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:21 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 5/9] dmaengine: idxd: Add missing cleanups in cleanup internals Date: Fri, 4 Apr 2025 20:02:13 +0800 Message-ID: <20250404120217.48772-6-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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_internals() function only decreases the reference count of groups, engines, and wqs but is missing the step to release memory resources. To fix this, use the cleanup helper to properly release the memory resources. Fixes: ddf742d4f3f1 ("dmaengine: idxd: Add missing cleanup for early error out in probe call") Cc: stable@vger.kernel.org Signed-off-by: Shuai Xue Reviewed-by: Fenghua Yu --- drivers/dma/idxd/init.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index a40fb2fd5006..f8129d2d53f1 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -407,14 +407,9 @@ static int idxd_setup_groups(struct idxd_device *idxd) static void idxd_cleanup_internals(struct idxd_device *idxd) { - int i; - - for (i = 0; i < idxd->max_groups; i++) - put_device(group_confdev(idxd->groups[i])); - for (i = 0; i < idxd->max_engines; i++) - put_device(engine_confdev(idxd->engines[i])); - for (i = 0; i < idxd->max_wqs; i++) - put_device(wq_confdev(idxd->wqs[i])); + idxd_clean_groups(idxd); + idxd_clean_engines(idxd); + idxd_clean_wqs(idxd); destroy_workqueue(idxd->wq); } From patchwork Fri Apr 4 12:02:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038363 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 526991DDC12; Fri, 4 Apr 2025 12:02:25 +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=1743768148; cv=none; b=b3infqNIdTe2UYET5FdfRd1i4ttpMCsUW34vVuLf5THHcvfkryjlPsmk8P8tEhYIs/CPyfETD/K490xW0kY4rFqzQlz2PE/HLWOowmZed23i31/I56fbfdAoDge+wTWGVUc/KG85oU4NgIOWdpoXcwbcsIgqgjdyTjmwYzn63Nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768148; c=relaxed/simple; bh=yopQBOAQYTJhqtWMuYQAu77gkqRAiHoHaU/seYM4l8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oTEaDeWPJnP12GlrKAyi8AWZ4kTcAcIRW2Ugt/azG84XLM4ZEyYvYOPnK3GpOe/lSGszQ5Rm00MvjKtkBA3Vax57B0DeziQvDtrWAXQ9yAdSBwKXAJ2FZJt3mm7PpGE29mKcRKVgUz9PKr/lpbp26/AsS/CvTDmQDIYTQ7nAJf8= 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=Zs3jvSw0; 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="Zs3jvSw0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768143; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=RR4Rew323Ji6zCDvSypFNWCsteupqKtVTFUYw8jlo9M=; b=Zs3jvSw0zw0evr4DCsrzGrwDOyNDvMDLrc7LFKmIPUKRVuOziNOPr0DSWwIlVDibYnC5Z30EH9Hsl4bjtqRbBUnOrUrJuD3GpKwjAH5aMpc2BqYTW0jTAy4eX9CcaVfoUTCRBsAgo93AjDh37avgucyDB+j4kK/zhi5yajDhFHY= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld5X_1743768142 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:22 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 6/9] dmaengine: idxd: fix memory leak in error handling path of idxd_alloc Date: Fri, 4 Apr 2025 20:02:14 +0800 Message-ID: <20250404120217.48772-7-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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") Cc: stable@vger.kernel.org Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang Reviewed-by: Fenghua Yu --- 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 f8129d2d53f1..302d8983ed8c 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -604,28 +604,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 Fri Apr 4 12:02:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038365 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 526EE1DE2A1; Fri, 4 Apr 2025 12:02:25 +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=1743768149; cv=none; b=BN6C9rjNIT8tOv7mGR5mtVN6YKqas84WSEFFurh3bOw8iFReFMfaqBbNAzRPFDndWHW9DM9y32ihgR2l60K1+u3tlfUlRNdF+TpPH5gC4+zGZiT3oE1pHU+l0qMbhsv//MzE9pU/szzTfgpJFanc2pCIxwrLEBRhiFn/++DEsl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768149; c=relaxed/simple; bh=SHZwFqeIre1l+vXt4R2dOG0+l9d01xd1QFM7+k8cqRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=anTe2T1aevN6UlY7m/D8BvG4P58w/R7AAmysJBrbUGMHn8azfTZVxxcCbezhuPXn8X4cbgPCuEJkhSuEmKeuGvkGzOqnhy/BFBko2L35n3iqJXk3t0F0pk0DvfbctcQ5HrTe11ub8AC2wLz7cSYBSho3vfsn0+846jTnRS1TW0A= 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=a1sPR0BN; 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="a1sPR0BN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768143; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=/cQyfBM4ou0asWHVRISENFgpbvJOOzovwlkHeg81JOI=; b=a1sPR0BNo1UmKQIXDFGGp9N0epItIAZFIBMROcLz2j1FauzIdUtZujLmholW4Wmavm5fOWWMYALDS+r0/RuHQVYYvCK4NXsc2x26YjW6+TDPIaWKHi82cDecp6hlPvcs1oRQQnTyCWZyVWCwAtJZroNwD9MC4YjnHS/pVdG1SG8= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld5x_1743768142 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:23 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 7/9] dmaengine: idxd: fix memory leak in error handling path of idxd_pci_probe Date: Fri, 4 Apr 2025 20:02:15 +0800 Message-ID: <20250404120217.48772-8-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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") Cc: stable@vger.kernel.org Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang Reviewed-by: Fenghua Yu --- drivers/dma/idxd/init.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 302d8983ed8c..f2b5b17538c0 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -587,6 +587,17 @@ 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) +{ + if (!idxd) + return; + + 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; @@ -1255,7 +1266,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 Fri Apr 4 12:02:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038371 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 D23C61F12E7; Fri, 4 Apr 2025 12:02:33 +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=1743768156; cv=none; b=s54s/v5enkyxpIHtlm0x8FC1w8qu11c9xEAYyc7I8c+K1Cc3IXpc4H1XsiZLpPCZxYtuuujEJt0PZ8CgKQtYv9JSs62hU7QPVESpoETCJ3ASH5mPjBI0Ss+Lcfh70JXYOs3SFXNtKdc0BubEzcMtIpIMBySc2jb8g0bISmrkNc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768156; c=relaxed/simple; bh=uSowLlD33f0Ns4kT3FjfvxpSLud2PBaZhfUCcZeFwP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AbzAbLN2Cdg+IAlgmMQ5F8jkvbYbVFSPUGRLXcWO6STdUAFEPKfKqELIk1Pn9FVDxw/793+aBnUga14ZIn56svWfEHcaKRxWhxFBFOUs98iZhPvAfCxU0F2UgapctCN3g2zjnAk+hN1mDMhpJRoukzAPozW437XTZNn0ADUjIlY= 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=ikH13drN; 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="ikH13drN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768144; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=SxvMUKx0UtmHnSPEXCBgkqeFgDKfDwGQVwbLp687BM0=; b=ikH13drNsa6iNSqOBf3vIqBUIXpdDaGuN8aD+oO45dSKe4UReJMkmUEZ/P2drRtUiWKXNyGSIqyFh2hqI5hf3GSe+MhfZv9Jp9CqiZJ9w+a56NzvhSzPS426JJx+CGY5+s7NpAnBC898ZD7MC9bgyMsp0MDNZK/m858iKWdkjA4= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld6F_1743768143 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:23 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 8/9] dmaengine: idxd: Add missing idxd cleanup to fix memory leak in remove call Date: Fri, 4 Apr 2025 20:02:16 +0800 Message-ID: <20250404120217.48772-9-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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") Cc: stable@vger.kernel.org Suggested-by: Vinicius Costa Gomes Signed-off-by: Shuai Xue Reviewed-by: Fenghua Yu --- drivers/dma/idxd/init.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index f2b5b17538c0..974b926bd930 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -1335,6 +1335,7 @@ static void idxd_remove(struct pci_dev *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 Fri Apr 4 12:02:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038370 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (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 177EA1F0E33; Fri, 4 Apr 2025 12:02:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768156; cv=none; b=H1mCE72yu4/D5j7HdzcbPgagOTr5gpZwx9aN3SQTjG9HP9TCmhKvG4tZ0psmkuX9UJZi1oqCx9Cyh/lWOvCd9o90V5vzDplwOAelP7uBiwXwpNNZcblaPxCJVEUblXmWQ7fURA0ZZemOxKA79E8PJAd0JTILn+QxMWEUhaLSlJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768156; c=relaxed/simple; bh=t20dnQbl8Sv6KyVku6tQirwcP+wWaCcCuhQMzFuA4qw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aFDq6Z+/YwDhzfoY4EpEb6c4J8LvS2ENixfG5JNKl+/FnpMvmXRWpsl5XM0HX6N49IemMMWQsVmstNXOrri5CBhT9Fl5GBAMMHKIkP8pIBQIll9zppCbDZdbom6WeWugPJgZQKHa9lSRXBu6ljDgk9EFAan0WGPyfvWm/HoNLg4= 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=wbZUWnls; arc=none smtp.client-ip=115.124.30.132 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="wbZUWnls" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768144; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Tmy+ZorzD11pKLZvBB/hJhvgTc4giBS+7kJVYCpQrMA=; b=wbZUWnlswoVsmdHJwptNcxx4fQi+W2ruWvqd/d4RGCjj7Y8Ra/3ekVCZkF0Qykm078YzRuOiXWK/Q3eScPF0NNEvoeXFBKASW+3iZUCdZovWycL8Pf5tW70D/9UVtQvyEHg8aQXZRjTAKzrs6VGfJZaKUdgOGADggQp4jUyisz8= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld6R_1743768143 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:24 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 9/9] dmaengine: idxd: Refactor remove call with idxd_cleanup() helper Date: Fri, 4 Apr 2025 20:02:17 +0800 Message-ID: <20250404120217.48772-10-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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 cleans up perfmon, interrupts, internals and so on. Refactor remove call with the 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") Cc: stable@vger.kernel.org Suggested-by: Vinicius Costa Gomes Signed-off-by: Shuai Xue Reviewed-by: Fenghua Yu --- drivers/dma/idxd/init.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 974b926bd930..760b7d81fcd8 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -1308,7 +1308,6 @@ static void idxd_shutdown(struct pci_dev *pdev) static void idxd_remove(struct pci_dev *pdev) { struct idxd_device *idxd = pci_get_drvdata(pdev); - struct idxd_irq_entry *irq_entry; idxd_unregister_devices(idxd); /* @@ -1321,21 +1320,12 @@ 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); put_device(idxd_confdev(idxd)); idxd_free(idxd); + pci_disable_device(pdev); } static struct pci_driver idxd_pci_driver = {