From patchwork Wed Oct 25 09:57:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie Yisheng X-Patchwork-Id: 10026377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D350960375 for ; Wed, 25 Oct 2017 10:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC69726E4A for ; Wed, 25 Oct 2017 10:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C15A127BA5; Wed, 25 Oct 2017 10:09:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F0B126E4A for ; Wed, 25 Oct 2017 10:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932507AbdJYKF3 (ORCPT ); Wed, 25 Oct 2017 06:05:29 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:9497 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932427AbdJYKF0 (ORCPT ); Wed, 25 Oct 2017 06:05:26 -0400 Received: from 172.30.72.60 (EHLO DGGEMS409-HUB.china.huawei.com) ([172.30.72.60]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DJX33004; Wed, 25 Oct 2017 18:05:09 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.361.1; Wed, 25 Oct 2017 18:04:59 +0800 From: Yisheng Xie To: , , , , CC: , , , Yisheng Xie , , Shu Wang Subject: [PATCH 2/2] scsi: megaraid: Track the page allocations for struct fusion_context Date: Wed, 25 Oct 2017 17:57:08 +0800 Message-ID: <1508925428-51660-2-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1508925428-51660-1-git-send-email-xieyisheng1@huawei.com> References: <1508925428-51660-1-git-send-email-xieyisheng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.59F061D6.0111, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 1b7079aaa65311f5faee27e131d51923 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I have get many kmemleak reports just similar to commit 70c54e210ee9 (scsi: megaraid_sas: fix memleak in megasas_alloc_cmdlist_fusion) on v4.14-rc6, however it seems have a different stroy: unreferenced object 0xffff8b5139d9d2c0 (size 192): comm "kworker/0:0", pid 3, jiffies 4294689182 (age 11347.731s) hex dump (first 32 bytes): 00 33 84 7b 41 8b ff ff 00 33 84 7b 00 00 00 00 .3.{A....3.{.... 00 30 8c 7b 41 8b ff ff 00 30 8c 7b 00 00 00 00 .0.{A....0.{.... backtrace: [] kmemleak_alloc+0x4a/0xa0 [] kmem_cache_alloc_trace+0xce/0x1d0 [] megasas_alloc_cmdlist_fusion+0xd4/0x180 [megaraid_sas] [] megasas_alloc_cmds_fusion+0x25/0x410 [megaraid_sas] [] megasas_init_adapter_fusion+0x21d/0x6e0 [megaraid_sas] [] megasas_init_fw+0x338/0xd00 [megaraid_sas] [] megasas_probe_one.part.34+0x5be/0x1040 [megaraid_sas] [] megasas_probe_one+0x46/0xc0 [megaraid_sas] [] local_pci_probe+0x45/0xa0 [] work_for_cpu_fn+0x14/0x20 [] process_one_work+0x149/0x360 [] worker_thread+0x1d8/0x3c0 [] kthread+0x109/0x140 [] ret_from_fork+0x25/0x30 [] 0xffffffffffffffff Struct fusion_context may alloc by get_free_pages, which contain pointers to other slab allocations(via megasas_alloc_cmdlist_fusion). Since kmemleak does not track/scan page allocations, the slab objects will be reported as leaks(false positives). This patch adds kmemleak callbacks to allow tracking of such pages. Cc: linux-mm@kvack.org Cc: Shu Wang Signed-off-by: Yisheng Xie --- drivers/scsi/megaraid/megaraid_sas_fusion.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index 11bd2e6..9a1be45 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -4512,6 +4513,14 @@ void megasas_fusion_ocr_wq(struct work_struct *work) dev_err(&instance->pdev->dev, "Failed from %s %d\n", __func__, __LINE__); return -ENOMEM; } + } else { + /* + * Allow kmemleak to scan these pages as they contain pointers + * to additional allocations via megasas_alloc_cmdlist_fusion. + */ + size_t size = (size_t)PAGE_SIZE << instance->ctrl_context_pages; + + kmemleak_alloc(instance->ctrl_context, size, 1, GFP_KERNEL); } fusion = instance->ctrl_context; @@ -4548,9 +4557,15 @@ void megasas_fusion_ocr_wq(struct work_struct *work) if (is_vmalloc_addr(fusion)) vfree(fusion); - else + else { + /* + * Remove kmemleak object previously allocated in + * megasas_alloc_fusion_context. + */ + kmemleak_free(fusion); free_pages((ulong)fusion, instance->ctrl_context_pages); + } } }