From patchwork Wed Jul 30 12:13:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 34520 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 726DB20792 for ; Wed, 30 Jul 2014 12:45:34 +0000 (UTC) Received: by mail-oi0-f72.google.com with SMTP id a141sf5236358oig.7 for ; Wed, 30 Jul 2014 05:45:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=/jgw9K9pF59HL7IVhCDdjgPTCVrPvvR/EPpCbHq30FA=; b=Q4+snU33mvdllCzCOeaFTLsRZ/ZskjuJQiGuy77tmPjAcVVhAYV2siGVR8TfVoNi7y WldU8qpZdyWAwqXrELVwhA93Zr7A99zFKW/gEndKsKdqhmDqKnM3WoyB9KKJsKxa9Q4P 93PciyT1ssteB/ukH7RUifiDLtHS150Gvb3MUFALicNtrqGRybDtRt/MC4uF40rFOAU6 G18t+eBdercmPxceO9d6yjz7dvLCDw1mO1nlg7SqPOVmc8w82arP40S0WW+LkkWSDZRg 9BqwPn9cxs80iiz7AhAMHINzGsJ62L6KHnN04Q5BoX36nT5ebgdnIHRSJIvFrr72IphA 6CGw== X-Gm-Message-State: ALoCoQnhJ3qGhoAn+af74YeOpG/hzFRw0DgEFpbbhvjcTGqPa8PKdFAWnIVRxovOZCfuuMwlrae+ X-Received: by 10.50.73.168 with SMTP id m8mr16390692igv.7.1406724332860; Wed, 30 Jul 2014 05:45:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.35 with SMTP id k32ls475617qgd.73.gmail; Wed, 30 Jul 2014 05:45:32 -0700 (PDT) X-Received: by 10.220.190.134 with SMTP id di6mr2722888vcb.43.1406724332707; Wed, 30 Jul 2014 05:45:32 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id s10si1501038vei.45.2014.07.30.05.45.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Jul 2014 05:45:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hq11so1631626vcb.38 for ; Wed, 30 Jul 2014 05:45:32 -0700 (PDT) X-Received: by 10.220.15.8 with SMTP id i8mr3984814vca.45.1406724332633; Wed, 30 Jul 2014 05:45:32 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp24652vcb; Wed, 30 Jul 2014 05:45:32 -0700 (PDT) X-Received: by 10.66.226.100 with SMTP id rr4mr4440398pac.48.1406724331725; Wed, 30 Jul 2014 05:45:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mr10si1157783pdb.207.2014.07.30.05.45.31 for ; Wed, 30 Jul 2014 05:45:31 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755211AbaG3Mos (ORCPT + 26 others); Wed, 30 Jul 2014 08:44:48 -0400 Received: from ip4-83-240-18-248.cust.nbox.cz ([83.240.18.248]:36632 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752744AbaG3MPZ (ORCPT ); Wed, 30 Jul 2014 08:15:25 -0400 Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.83) (envelope-from ) id 1XCSmx-0003zZ-Tw; Wed, 30 Jul 2014 14:15:23 +0200 From: Jiri Slaby To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Catalin Marinas , Andrew Morton , Linus Torvalds , Jiri Slaby Subject: [PATCH 3.12 10/94] mm: kmemleak: avoid false negatives on vmalloc'ed objects Date: Wed, 30 Jul 2014 14:13:59 +0200 Message-Id: X-Mailer: git-send-email 2.0.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linux-kernel-owner@vger.kernel.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Catalin Marinas 3.12-stable review patch. If anyone has any objections, please let me know. =============== commit 7f88f88f83ed609650a01b18572e605ea50cd163 upstream. Commit 248ac0e1943a ("mm/vmalloc: remove guard page from between vmap blocks") had the side effect of making vmap_area.va_end member point to the next vmap_area.va_start. This was creating an artificial reference to vmalloc'ed objects and kmemleak was rarely reporting vmalloc() leaks. This patch marks the vmap_area containing pointers explicitly and reduces the min ref_count to 2 as vm_struct still contains a reference to the vmalloc'ed object. The kmemleak add_scan_area() function has been improved to allow a SIZE_MAX argument covering the rest of the object (for simpler calling sites). Signed-off-by: Catalin Marinas Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Jiri Slaby --- mm/kmemleak.c | 4 +++- mm/vmalloc.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index e126b0ef9ad2..31f01c5011e5 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -753,7 +753,9 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp) } spin_lock_irqsave(&object->lock, flags); - if (ptr + size > object->pointer + object->size) { + if (size == SIZE_MAX) { + size = object->pointer + object->size - ptr; + } else if (ptr + size > object->pointer + object->size) { kmemleak_warn("Scan area larger than object 0x%08lx\n", ptr); dump_object_info(object); kmem_cache_free(scan_area_cache, area); diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 107454312d5e..e2be0f802ccf 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -359,6 +359,12 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, if (unlikely(!va)) return ERR_PTR(-ENOMEM); + /* + * Only scan the relevant parts containing pointers to other objects + * to avoid false negatives. + */ + kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask & GFP_RECLAIM_MASK); + retry: spin_lock(&vmap_area_lock); /* @@ -1646,11 +1652,11 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, clear_vm_uninitialized_flag(area); /* - * A ref_count = 3 is needed because the vm_struct and vmap_area - * structures allocated in the __get_vm_area_node() function contain - * references to the virtual address of the vmalloc'ed block. + * A ref_count = 2 is needed because vm_struct allocated in + * __get_vm_area_node() contains a reference to the virtual address of + * the vmalloc'ed block. */ - kmemleak_alloc(addr, real_size, 3, gfp_mask); + kmemleak_alloc(addr, real_size, 2, gfp_mask); return addr;