From patchwork Mon Aug 12 16:06:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 171095 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3026022ily; Mon, 12 Aug 2019 09:06:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7/gEoffI6oG0zwFGhvKe3Vr1oSAQ+BADcvdzrr4sAibPxob7kLtmr657vozl/flDtE3bk X-Received: by 2002:a65:5c4b:: with SMTP id v11mr31108005pgr.62.1565626017586; Mon, 12 Aug 2019 09:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565626017; cv=none; d=google.com; s=arc-20160816; b=vLIKf4XF+QrDPDtllcgYLJmUQIc7cT0XAfhv+ok+HT5PK5zZXfYi01Ftb7fSbIUwzE qtuKByh647tNSxQy1aaSBbUsBVwekSRbs7XIEclW2Re3Oxw41Y3Yiaxl/8mnMHyhZx7k 7Kz2O6UFBLWTyWL28SA1K/9fSbOzwLio8mkRUVADaYyUxuIzR/tLtIVlDt3gzNf/H3ND yLhOzSgCFMSKPQkYqaVyQ3ykF4FskbQojVculGJk2cChAW/V2TssH6+pD2tDzsgvhXOA z0ZbT0f1NXoYtgFP1FysrsthhU7pvjlvcmkQxE7Tz9FLLs7flqsq/uyHb+EJJNYN1Qtx yYww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ocDMmshQjuPKnAf7DQtgku75UKkRp9ouJddFnfWFt8A=; b=pVzo9Te7WabVcihS7gkkSaGnqN+UDmZ9xSZEKAWkfAeAO5D/En3ld7VEP9YcwqnY7s +wOLD3Mph1cwQDg+BKuRhEUtfu8bhZ1SiDUvv6ZmuXnBG/Wnk6TzOKre7yMT/F6Z0lbR 9gyKbb2kMC0sbbjVJ1Xezs4cUsE33hthJk/0CslymusZ/JLwvef4BC/mwQak4ZhFqkRP NP+OvMNOcmZoYsbAkcQ5Tm2+ueNGTx50Vvxq8fs6zGAgs6kUIDs2drHA2YkZ2HbUyZxX SyJsRWn32QmvCNomTe3Agf1L0gQ3a6JYt5+zWlU6t6w6MKkyb6tyvNVlGcCpHYxrVOb/ jKkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si65739627pgb.245.2019.08.12.09.06.57; Mon, 12 Aug 2019 09:06:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726693AbfHLQGu (ORCPT + 28 others); Mon, 12 Aug 2019 12:06:50 -0400 Received: from foss.arm.com ([217.140.110.172]:52304 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725923AbfHLQGs (ORCPT ); Mon, 12 Aug 2019 12:06:48 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2D24F1715; Mon, 12 Aug 2019 09:06:48 -0700 (PDT) Received: from arrakis.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 29A6B3F718; Mon, 12 Aug 2019 09:06:47 -0700 (PDT) From: Catalin Marinas To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Michal Hocko , Matthew Wilcox , Qian Cai Subject: [PATCH v3 1/3] mm: kmemleak: Make the tool tolerant to struct scan_area allocation failures Date: Mon, 12 Aug 2019 17:06:40 +0100 Message-Id: <20190812160642.52134-2-catalin.marinas@arm.com> X-Mailer: git-send-email 2.23.0.rc0 In-Reply-To: <20190812160642.52134-1-catalin.marinas@arm.com> References: <20190812160642.52134-1-catalin.marinas@arm.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Object scan areas are an optimisation aimed to decrease the false positives and slightly improve the scanning time of large objects known to only have a few specific pointers. If a struct scan_area fails to allocate, kmemleak can still function normally by scanning the full object. Introduce an OBJECT_FULL_SCAN flag and mark objects as such when scan_area allocation fails. Signed-off-by: Catalin Marinas --- mm/kmemleak.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index f6e602918dac..5ba7fad00fda 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -168,6 +168,8 @@ struct kmemleak_object { #define OBJECT_REPORTED (1 << 1) /* flag set to not scan the object */ #define OBJECT_NO_SCAN (1 << 2) +/* flag set to fully scan the object when scan_area allocation failed */ +#define OBJECT_FULL_SCAN (1 << 3) #define HEX_PREFIX " " /* number of bytes to print per line; must be 16 or 32 */ @@ -773,12 +775,14 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp) } area = kmem_cache_alloc(scan_area_cache, gfp_kmemleak_mask(gfp)); - if (!area) { - pr_warn("Cannot allocate a scan area\n"); - goto out; - } spin_lock_irqsave(&object->lock, flags); + if (!area) { + pr_warn_once("Cannot allocate a scan area, scanning the full object\n"); + /* mark the object for full scan to avoid false positives */ + object->flags |= OBJECT_FULL_SCAN; + goto out_unlock; + } if (size == SIZE_MAX) { size = object->pointer + object->size - ptr; } else if (ptr + size > object->pointer + object->size) { @@ -795,7 +799,6 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp) hlist_add_head(&area->node, &object->area_list); out_unlock: spin_unlock_irqrestore(&object->lock, flags); -out: put_object(object); } @@ -1408,7 +1411,8 @@ static void scan_object(struct kmemleak_object *object) if (!(object->flags & OBJECT_ALLOCATED)) /* already freed object */ goto out; - if (hlist_empty(&object->area_list)) { + if (hlist_empty(&object->area_list) || + object->flags & OBJECT_FULL_SCAN) { void *start = (void *)object->pointer; void *end = (void *)(object->pointer + object->size); void *next;