Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2096005ybe; Tue, 3 Sep 2019 07:58:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQrb9UllsiC10BcT22ttxrfXWdSnmRMb56tB0ahSdVfo7F2gg409ElNf1amHWMOHOywTlE X-Received: by 2002:a63:2c8:: with SMTP id 191mr30149835pgc.139.1567522685513; Tue, 03 Sep 2019 07:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567522685; cv=none; d=google.com; s=arc-20160816; b=ZrPkMpu5UqCyD4593mGJ2w8xU9j0CBN9cigia5lhB9wysnrqhiArpMoVsbHJXgp5LE 9BrdaTzgDogq0NQO+cmp97SyF7C2V+v9B6s5u5MN0ldJOF83ar3EvQsX05tAUDc7QZ/I dGJZjWDCYzk8amkMyrXe6gA8f7+XqJOrHqRFsikcg8xlUPFfEA6TbXOdnbZNxRc/GW5U WV5Z6DMueDadVtTvFS0ZEZCnvQ4OwyX9MJO3Uo6yH/Jh8DHE2xf4og+nwu0nNEm+9YFN Y3GGr2QAcgj0R2JDEIzRhcKyDo4L8j90hisu+5pyHnHd4GvKUIjCLxVrfl0Xm7qeEDFM +kpA== 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 :dkim-signature; bh=vF6m0g42G8C15Kjxq7JM+Zo7viFkQMObl5+b/f7Khts=; b=uoYlvfAUW6o8c67AVW5+H+Stl88GeomyIsm2q2WSU6EuwOLQSJo7GGGiH4t8q1all2 Msxr8odcF8iqpJzMVTXuTwSCrpNWYgWNKZVHrQLQjQYNnfTT77HB/h8I6lgaGcQb1utH DCZh1krHoj4MAtid2IJKLxptLaf/Lv29s9V3J2ewksscRUe9ISenE6DfzmeIzfc+bW+C NUpTobPvCrgzh4pYKtWfYxLXXr+Ykn3WIa4M/fzuMEsVXddW69+jr7FjokU98+EH9KY9 eKqeiXfc4pCSQzkfmwkTvRKJP6eakXe2JBTGXHzUYdYKPzCm1Be2xtNTD1nhm4xzFj5q N7fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@axtens.net header.s=google header.b=LXzNdZWa; 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 14si7374263pfj.37.2019.09.03.07.57.49; Tue, 03 Sep 2019 07:58:05 -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; dkim=pass header.i=@axtens.net header.s=google header.b=LXzNdZWa; 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 S1729706AbfICO4H (ORCPT + 99 others); Tue, 3 Sep 2019 10:56:07 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42195 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729690AbfICO4G (ORCPT ); Tue, 3 Sep 2019 10:56:06 -0400 Received: by mail-pg1-f193.google.com with SMTP id p3so9275300pgb.9 for ; Tue, 03 Sep 2019 07:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vF6m0g42G8C15Kjxq7JM+Zo7viFkQMObl5+b/f7Khts=; b=LXzNdZWazMK6zy0lx9YtBYbXF9X6k/ujNzvt18aBdOOv3v25BsWv4Wq/F1h+j/+f75 nBnFt6ymLCbGO1vy5RHkDwGov4Jjo0Cgc0ZoZ5V6PBdUG4JRxf84mM0915iQPHCfkFR0 cD+DOmuxV6yIJsG+RC2TZuWoJ/Y6it1TksSws= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vF6m0g42G8C15Kjxq7JM+Zo7viFkQMObl5+b/f7Khts=; b=IahpoWkryaBRgz6oIwUz70tZaSou7JWtru7eEkHZ2MoGg5nerUbxlTCZYhnq1YAk2F RcD7vH/5nPaduLeVRGrF4jOMMf+i0BqERjOC1AVhCtZO2WtbjD76NWKmAXe9iay2PYhd jm7Y/BBMZqesnY1QLlYR/rp8IwgABB53evuU66MK5Bw0jnWuKSzWsTSUE1KbQ9O5MfG5 rOPbMuHg8BhOsnK/QzFmP+dI2NnNnrzCxb+7S5AmtDWxvGGscqACyoTIdsCotB638Lu4 KlhVVMbDVuSldQp53WrnGWY3/aRT+DEtIdny+Wvml3mMcRKT4DfzODuV+nx7sMPR0MhD rB9w== X-Gm-Message-State: APjAAAWisYPi6GrqLfrlYywh4D2ENwyp039l/CN9dnoq4+/Io52Lzm84 vQh2CkcbR6yZEeUmFqI6qjTWyr60/vI= X-Received: by 2002:a63:194f:: with SMTP id 15mr31482111pgz.382.1567522565767; Tue, 03 Sep 2019 07:56:05 -0700 (PDT) Received: from localhost (ppp167-251-205.static.internode.on.net. [59.167.251.205]) by smtp.gmail.com with ESMTPSA id c1sm19943843pfd.117.2019.09.03.07.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 07:56:05 -0700 (PDT) From: Daniel Axtens To: kasan-dev@googlegroups.com, linux-mm@kvack.org, x86@kernel.org, aryabinin@virtuozzo.com, glider@google.com, luto@kernel.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, dvyukov@google.com, christophe.leroy@c-s.fr Cc: linuxppc-dev@lists.ozlabs.org, gor@linux.ibm.com, Daniel Axtens Subject: [PATCH v7 5/5] kasan debug: track pages allocated for vmalloc shadow Date: Wed, 4 Sep 2019 00:55:36 +1000 Message-Id: <20190903145536.3390-6-dja@axtens.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190903145536.3390-1-dja@axtens.net> References: <20190903145536.3390-1-dja@axtens.net> 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 Provide the current number of vmalloc shadow pages in /sys/kernel/debug/kasan_vmalloc/shadow_pages. Signed-off-by: Daniel Axtens --- Merging this is probably overkill, but I leave it to the discretion of the broader community. On v4 (no dynamic freeing), I saw the following approximate figures on my test VM: - fresh boot: 720 - after test_vmalloc: ~14000 With v5 (lazy dynamic freeing): - boot: ~490-500 - running modprobe test_vmalloc pushes the figures up to sometimes as high as ~14000, but they drop down to ~560 after the test ends. I'm not sure where the extra sixty pages are from, but running the test repeately doesn't cause the number to keep growing, so I don't think we're leaking. - with vmap_stack, spawning tasks pushes the figure up to ~4200, then some clearing kicks in and drops it down to previous levels again. --- mm/kasan/common.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index e33cbab83309..e40854512417 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -35,6 +35,7 @@ #include #include #include +#include #include @@ -750,6 +751,8 @@ core_initcall(kasan_memhotplug_init); #endif #ifdef CONFIG_KASAN_VMALLOC +static u64 vmalloc_shadow_pages; + static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr, void *unused) { @@ -776,6 +779,7 @@ static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr, if (likely(pte_none(*ptep))) { set_pte_at(&init_mm, addr, ptep, pte); page = 0; + vmalloc_shadow_pages++; } spin_unlock(&init_mm.page_table_lock); if (page) @@ -829,6 +833,7 @@ static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, if (likely(!pte_none(*ptep))) { pte_clear(&init_mm, addr, ptep); free_page(page); + vmalloc_shadow_pages--; } spin_unlock(&init_mm.page_table_lock); @@ -947,4 +952,25 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, (unsigned long)shadow_end); } } + +static __init int kasan_init_vmalloc_debugfs(void) +{ + struct dentry *root, *count; + + root = debugfs_create_dir("kasan_vmalloc", NULL); + if (IS_ERR(root)) { + if (PTR_ERR(root) == -ENODEV) + return 0; + return PTR_ERR(root); + } + + count = debugfs_create_u64("shadow_pages", 0444, root, + &vmalloc_shadow_pages); + + if (IS_ERR(count)) + return PTR_ERR(root); + + return 0; +} +late_initcall(kasan_init_vmalloc_debugfs); #endif -- 2.20.1