From patchwork Wed Sep 16 19:26:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kirjanov X-Patchwork-Id: 518541 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A4AC0140D9F for ; Thu, 17 Sep 2015 06:05:59 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 8556C1A2EAD for ; Thu, 17 Sep 2015 06:05:59 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com [209.85.217.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 0409D1A035C for ; Thu, 17 Sep 2015 06:04:57 +1000 (AEST) Received: by lbbvu2 with SMTP id vu2so37823460lbb.0 for ; Wed, 16 Sep 2015 13:04:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6wvVcXUGHBSda81RUuwa08ZNGpjej6bAl0hp3N/J+4U=; b=PiqWg9tjLSf4iP0tK3psJx7e7JkRPG5hrmic8fa8pIM87NBEPiuCzxb+i8q10Ykejn 9YAMWwIvP1ulaOQTRJmMlMrAc2za1mWUhSNsjEVnl3lBh7nwoIR5O3UHXEg4B0lBMJuW SG04Roo5AXThCBho/pmblRblZh2O6FzRhwO7QzzJvwceFkAIvKlgIjsUVAkhH/lBnX/F fMOa3+Cw1Hj2QJIWosVf4Zz+A0SRD4DfCMECmaYmBrqapEePg/AD7spDfDD4BfKPmpXV 3Bkf0BjGfYhbTZACdNQOFUkdZ9ezKp0ho7yPX1ustu1JeXLtoWLb5xbka/wLK3UtYyCD gfXw== X-Gm-Message-State: ALoCoQl590sIzZKyks33BL1AC5sgRV4cdux7lvSC5XQfuKxr6c5HorUTUNM1FXziH7W7MvuLTh7e X-Received: by 10.112.36.196 with SMTP id s4mr32049343lbj.59.1442433893566; Wed, 16 Sep 2015 13:04:53 -0700 (PDT) Received: from hydra.kdaintranet ([5.35.73.89]) by smtp.gmail.com with ESMTPSA id nv3sm4328060lbb.24.2015.09.16.13.04.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Sep 2015 13:04:52 -0700 (PDT) From: Denis Kirjanov To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v3] powerpc: msi: mark bitmap with kmemleak_not_leak() Date: Wed, 16 Sep 2015 22:26:14 +0300 Message-Id: <1442431574-4575-1-git-send-email-kda@linux-powerpc.org> X-Mailer: git-send-email 2.4.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Denis Kirjanov , Catalin Marinas MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" During the MSI bitmap test on boot kmemleak spews the following trace: unreferenced object 0xc00000016e86c900 (size 64): comm "swapper/0", pid 1, jiffies 4294893173 (age 518.024s) hex dump (first 32 bytes): 00 00 01 ff 7f ff 7f 37 00 00 00 00 00 00 00 00 .......7........ ff ff ff ff ff ff ff ff 01 ff ff ff ff ff ff ff ................ backtrace: [] .zalloc_maybe_bootmem+0x3c/0x380 [] .msi_bitmap_alloc+0x3c/0xb0 [] .msi_bitmap_selftest+0x30/0x2b4 [] .do_one_initcall+0xd4/0x270 [] .kernel_init_freeable+0x1a0/0x280 [] .kernel_init+0x1c/0x120 [] .ret_from_kernel_thread+0x58/0x9c Added a flag to msi_bitmap for tracking allocations from slab and memblock so we can properly free/handle memory in msi_bitmap_free(). Signed-off-by: Denis Kirjanov Changes vor v2: - added a flag to msi_bitmap - kmemleak annotaion moved under CONFIG_MSI_BITMAP_SELFTEST Changes vor v3: - correctly initialize bitmap_from_slab - put kmemleak_not_leak annotation right after the allocation Reviewed-by: Catalin Marinas --- arch/powerpc/include/asm/msi_bitmap.h | 1 + arch/powerpc/sysdev/msi_bitmap.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/include/asm/msi_bitmap.h b/arch/powerpc/include/asm/msi_bitmap.h index 97ac3f4..47a8ebc 100644 --- a/arch/powerpc/include/asm/msi_bitmap.h +++ b/arch/powerpc/include/asm/msi_bitmap.h @@ -19,6 +19,7 @@ struct msi_bitmap { unsigned long *bitmap; spinlock_t lock; unsigned int irq_count; + bool bitmap_from_slab; }; int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num); diff --git a/arch/powerpc/sysdev/msi_bitmap.c b/arch/powerpc/sysdev/msi_bitmap.c index 73b64c7..6f2f3d6 100644 --- a/arch/powerpc/sysdev/msi_bitmap.c +++ b/arch/powerpc/sysdev/msi_bitmap.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -122,7 +123,16 @@ int msi_bitmap_alloc(struct msi_bitmap *bmp, unsigned int irq_count, size = BITS_TO_LONGS(irq_count) * sizeof(long); pr_debug("msi_bitmap: allocator bitmap size is 0x%x bytes\n", size); - bmp->bitmap = zalloc_maybe_bootmem(size, GFP_KERNEL); + if (slab_is_available()) { + bmp->bitmap = kzalloc(size, GFP_KERNEL); + bmp->bitmap_from_slab = true; + } else { + bmp->bitmap = memblock_virt_alloc(size, 0); + bmp->bitmap_from_slab = false; + /* the bitmap won't be freed from memblock allocator */ + kmemleak_not_leak(bmp->bitmap); + } + if (!bmp->bitmap) { pr_debug("msi_bitmap: ENOMEM allocating allocator bitmap!\n"); return -ENOMEM; @@ -138,7 +148,8 @@ int msi_bitmap_alloc(struct msi_bitmap *bmp, unsigned int irq_count, void msi_bitmap_free(struct msi_bitmap *bmp) { - /* we can't free the bitmap we don't know if it's bootmem etc. */ + if (bmp->bitmap_from_slab) + kfree(bmp->bitmap); of_node_put(bmp->of_node); bmp->bitmap = NULL; } @@ -203,8 +214,6 @@ static void __init test_basics(void) /* Clients may WARN_ON bitmap == NULL for "not-allocated" */ WARN_ON(bmp.bitmap != NULL); - - kfree(bmp.bitmap); } static void __init test_of_node(void)