Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3961562ybl; Mon, 12 Aug 2019 09:08:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/fasCHHz8d9aOoTe4NMVgqvLhdNhOMXVw7jSAiGa76/2cesP+QrK4D6UZwiAP9H+R9IwW X-Received: by 2002:a63:c008:: with SMTP id h8mr31755106pgg.427.1565626091897; Mon, 12 Aug 2019 09:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565626091; cv=none; d=google.com; s=arc-20160816; b=tIKzMAtuVuCm+ITCrsc078e4RiKl+So9b2atP+a/+qxr6RAzRxy5uNB3CKWCejMzSO 0Z6HY0iCTBtx+I0dQguyC2kdEJTRsirLyLNibXJ+MzN/4L40dZofM+IQFNHqwgA+xXau bfGiLz3BbDD71Q4lF8Yzwi12JtoI+cZM97NjCI7Ps4Y7Ek6sXh9elSRfuXPeENUNftRw Jy/Dk450BtCuEk08Po6ul2zxQtAPBQgn+6xKDNXDyQMC9k92qWFl81MijrczhXkv93Vt eKIhm8aIL085jtcbMYh87c7cSiYuoThPgOwO8JhfMC8LTXTWo6kXoK5tEW2xl8eHk4E7 kf7w== 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 l14si61595494pgh.205.2019.08.12.09.07.56; Mon, 12 Aug 2019 09:08:11 -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 S1726683AbfHLQGt (ORCPT + 99 others); Mon, 12 Aug 2019 12:06:49 -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 Content-Transfer-Encoding: 8bit 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;