Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751184AbdGMHBP (ORCPT ); Thu, 13 Jul 2017 03:01:15 -0400 Received: from mail-ve1eur01on0083.outbound.protection.outlook.com ([104.47.1.83]:12224 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751036AbdGMHBN (ORCPT ); Thu, 13 Jul 2017 03:01:13 -0400 From: =?iso-8859-2?Q?Horia_Geant=E3?= To: Xulin Sun , Dan Douglass , "herbert@gondor.apana.org.au" , "davem@davemloft.net" CC: "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "xulinsun@gmail.com" Subject: Re: [PATCH] crypto: caam - free qman_fq after kill_fq Thread-Topic: [PATCH] crypto: caam - free qman_fq after kill_fq Thread-Index: AQHS+g3r3aeErXtq5U2dPIrnBYk0ng== Date: Thu, 13 Jul 2017 07:01:05 +0000 Message-ID: References: <20170711062107.182889-1-xulin.sun@windriver.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: windriver.com; dkim=none (message not signed) header.d=none;windriver.com; dmarc=none action=none header.from=nxp.com; x-originating-ip: [192.88.146.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR0401MB2621;7:gv3AApj9HeH18KG0JTj6QSZaZwHjIaFkkl5lU2O5wWomLPmg0JPemvHZ+zblL0rynF11G7MvNNGD38ZIqpdMreJMt+xKMUFcRhJ5diNai5FJSWfQMRurbExuWTreB+yPOq5qhEIwjzk8273CUqIqMXT+12HLhZcH/iFXHYKbbAuIqj6CcFH8rgxqDlRPL9q9N895hjaib+GcrUj5dJEPTNmRVGd3YL9aN7bo0kaf/Slw92YIPMW1S4aZnAViG1P2SZRo/z4vvfdwl/5I1emiQPk6mwK+ZNuoOORgqSYs+SKAb4uV9zd0Kxi0lYdc/VQGegpEtQY+UJ+rRM9LFToQwbmo4OeSkSmT3VIOWZe64AHVO6R0cj+pM7HGADyNcb5FUgV2QawDq5TTO58vcgqqVR81Jvdx77sFdPNRjbCITktoVICVPXayUmO9ieFmJLfCA9YbMxjxFJaJG/x0JdFXDIod1dRfTiAYtxCpWOOKPOWcUkia0ooZ+1nOd6K14UPNPMrtAQu8QWvQGxSXugOYGT0CcCWdF4IicHBQ3BEvP8+qdOSn8T4MgE4/fGLJVW6P1gOdXts3FVJkP3FllHbcpQGznaiABME+7cQcsNRvvDnXhOTjPi4tcULBpfzfS+Aw6/reG9rA6mdJwgKfDj5x6Ub2uq2ZQDGnzHrGiqY3zqbAN4j3klSwfar0ghSUHez3qpAAY3As8edppqhQx3HPnqzhBE6hLuSoZ8R4qXqhHCptnK3vWaT+UMeemMnszf/di2HEefqoYRl1PBYooxNAFLpPm13Rk7eXtovXDfHOoE4= x-forefront-antispam-report: SFV:SKI;SCL:-1SFV:NSPM;SFS:(10009020)(6009001)(39450400003)(39850400002)(39400400002)(39840400002)(39410400002)(39860400002)(24454002)(377454003)(86362001)(478600001)(25786009)(53936002)(53546010)(4326008)(2201001)(189998001)(2501003)(39060400002)(5250100002)(74316002)(3660700001)(33656002)(8936002)(6116002)(66066001)(68736007)(81166006)(5660300001)(3846002)(38730400002)(102836003)(55016002)(3280700002)(6246003)(9686003)(6506006)(8676002)(54356999)(6436002)(2900100001)(99286003)(229853002)(76176999)(7736002)(305945005)(50986999)(54906002)(7696004)(14454004)(2906002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0401MB2621;H:VI1PR0401MB2591.eurprd04.prod.outlook.com;FPR:;SPF:None;MLV:ovrnspm;PTR:InfoNoRecords;LANG:en; x-ms-office365-filtering-correlation-id: 54235d51-ada3-44bd-7304-08d4c9bceea4 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:VI1PR0401MB2621; x-ms-traffictypediagnostic: VI1PR0401MB2621: x-exchange-antispam-report-test: UriScan:(236129657087228)(148574349560750); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(2017060910075)(5005006)(8121501046)(3002001)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123560025)(20161123564025)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:VI1PR0401MB2621;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:VI1PR0401MB2621; x-forefront-prvs: 0367A50BB1 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-2" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jul 2017 07:01:05.9465 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2621 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v6D71YWU031570 Content-Length: 2479 Lines: 69 On 7/11/2017 9:21 AM, Xulin Sun wrote: > kill_fq removes a complete frame queue, it needs to free the qman_fq > in the last. Else kmemleak will report the below warning: > > unreferenced object 0xffff800073085c80 (size 128): > comm "cryptomgr_test", pid 199, jiffies 4294937850 (age 67.840s) > hex dump (first 32 bytes): > 00 00 00 00 00 00 00 00 a0 80 7e 00 00 80 ff ff > 00 00 00 00 00 00 00 00 04 00 04 00 5c 01 00 00 > backtrace: > [] create_object+0xf8/0x258 > [] kmemleak_alloc+0x58/0xa0 > [] kmem_cache_alloc_trace+0x2c8/0x358 > [] create_caam_req_fq+0x40/0x170 > [] caam_drv_ctx_update+0x54/0x248 > [] aead_setkey+0x154/0x300 > [] setkey+0x50/0xf0 > [] __test_aead+0x5ec/0x1028 > [] test_aead+0x44/0xc8 > [] alg_test_aead+0x58/0xd0 > [] alg_test+0x14c/0x308 > [] cryptomgr_test+0x50/0x58 > [] kthread+0xdc/0xf0 > [] ret_from_fork+0x10/0x50 > > And check where the function kill_fq() is called to remove > the additional kfree to qman_fq. > > Signed-off-by: Xulin Sun > --- > drivers/crypto/caam/qi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/crypto/caam/qi.c b/drivers/crypto/caam/qi.c > index 1990ed4..c4b9173 100644 > --- a/drivers/crypto/caam/qi.c > +++ b/drivers/crypto/caam/qi.c > @@ -277,6 +277,7 @@ static int kill_fq(struct device *qidev, struct qman_fq *fq) > dev_err(qidev, "OOS of FQID: %u failed\n", fq->fqid); > > qman_destroy_fq(fq); > + kfree(fq); There is a case where kfree(fq) is executed and kill_fq() returns != 0 - that is when qman_oos_fq() returns != 0. Thus please make sure there is no reference to "fq" after kill_fq(..., fq) is called, even if kill_fq() return code is != 0. For e.g.: if (kill_fq(qidev, new_fq)) dev_warn(qidev, "New CAAM FQ: %u kill failed\n", new_fq->fqid); ^^^^^^ already kfree-ed Thanks, Horia > > return ret; > } > @@ -511,7 +512,6 @@ int caam_qi_shutdown(struct device *qidev) > > if (kill_fq(qidev, per_cpu(pcpu_qipriv.rsp_fq, i))) > dev_err(qidev, "Rsp FQ kill failed, cpu: %d\n", i); > - kfree(per_cpu(pcpu_qipriv.rsp_fq, i)); > } > > /* >