Received: by 10.223.164.202 with SMTP id h10csp2731226wrb; Mon, 27 Nov 2017 23:52:27 -0800 (PST) X-Google-Smtp-Source: AGs4zMb2aJk7ko8htCiVDQiiko8B1GnFDjg5ko3k8SGZhTFpr3Ca1kuENUUN0wsQIYcO3ocSzG7O X-Received: by 10.98.196.155 with SMTP id h27mr39717775pfk.137.1511855547499; Mon, 27 Nov 2017 23:52:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511855547; cv=none; d=google.com; s=arc-20160816; b=OU34EpsHg99sa/Rt8fWRsgmizlGrh9+Q+f2Tyb3Bx9O9Rpp+C+RZiqrVCIRglNIdAo 1wTw3zXuB4WrbQrG8Qka/3UIZotQT7Rk9p4EM7GKDT2VmjLD58Huy6AZqGr9j/ksyjHR BrmM1ajvMSu0vgvA+Iq5HzTFt8rnoB80MqlfZHq7GYOGl4OfIj8rpeL4UcfuhSqcv2A6 AnfBlJYh9Z2rHKBvzR9Ieat+XflVKgwiYs4qRsr0m0XIE4da/4UPAif6D01auHPouTxU 9I6S+wAmgaf4B18hxB8e2K6/ir/qS2ASV5YkqmMfbDH8Yexjopf3C9f4+ePMb4At2DEY fOVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=kcjdolaT7bi3VK45hj8yly+KJm8BmY1UkuQV5r3/Jz8=; b=UJxbBo73ZnVxBNmrJQkPeF3cKVF2Ux59fV44At8u7l0Cn2iWVYPjbuj5UHTDl4Kt65 U5rpw4IHOXEi4++DG7vBeTJwO3hdwc2MNh+S1gI722l3MkqsbiERYU5kr/UWZB4jP4jT h6WYEoNL1cJp8PfRjHwfkte5c4vESBi6d0H/HW1z+9fOm0RCxAiomakYNCvz69N7vL+E WIb/G7PKR1OZQByH4ELAV6f50FhMEoqMmZpE5cEgCEIHlyWO6fb1bw7hUwUa4X5EHYf7 /tPKfM8udbuv3vX8zhaUDjct4XVsoFqa3Y8V4ehy1oWXp+v9FqcV2R/HDLHQeewClXLo Suwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mss6HapQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si23943650plo.815.2017.11.27.23.52.15; Mon, 27 Nov 2017 23:52:27 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=mss6HapQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752534AbdK1HvN (ORCPT + 78 others); Tue, 28 Nov 2017 02:51:13 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36363 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752386AbdK1HuH (ORCPT ); Tue, 28 Nov 2017 02:50:07 -0500 Received: by mail-pf0-f194.google.com with SMTP id i15so18610152pfa.3 for ; Mon, 27 Nov 2017 23:50:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kcjdolaT7bi3VK45hj8yly+KJm8BmY1UkuQV5r3/Jz8=; b=mss6HapQBIM7/Y2O6w7Tpe3xE8YNU+l6kdgba3DTD+iN2iXkq0OsIgcpRNm/jyVAAm X1C0EwFg8IHEp8EoebL+e++0IRpifHbBeHb7zb8GFFDZyZR84sRBAASM9hNObOGi8VrR JBa/bLzNNtkYxfBBM/amYQSqiCOq+bzbX6wtxrG9mGIEDzNBTfTRcip9BW3fuj1d4056 ZHhRnA7f0Uo7B3VLkcOoRjBkXI3GhBFLNraXizygN2YMSVGmSIDkwU6DBG+ZaQroexws +AIBeIa7/jjlqe/pW0YIfoYRQqcMFHjWYNMp118yB9R7dbpQKNTxNCsWCJi+c4ugL7za lYqw== 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; bh=kcjdolaT7bi3VK45hj8yly+KJm8BmY1UkuQV5r3/Jz8=; b=cCfiKqEff7RXoGX3KvmegFED8Inb6UZbdB4NQcF3haVn7yltVjacg0tFN1HYr47Ey6 1S8VVUEbT7GGYS1U045CwY3f1MKi7pCCzSzbdKJ9TLHGCWgFqKnfzUD264Xbd2XL56zD 86RjQ3AhX1DiBPwwgE6beRL5aaFDsW2uWcTOl/rfsHzGubdfjxQISrttOOoYv0WsPy40 ubixwQp2svoMZ/9tI/m7Qb2cohnXGZuODtjJxvjW1Zg2SJtmyV5U00xLvoZ/xCcN/5az clr9Kt06TLpyrT41GsL+7n5igWnfXE0zZwuI/6alJhCIJOG15p6/NklFFUvz8lMF3NvO v1KQ== X-Gm-Message-State: AJaThX5DZpDn4vu6rK/kWzRiMXwbWP9qhaewE/r2rpPuOYlR1IT27Jec hIpqVLVTH7cEVN7Tf7/Q/n8= X-Received: by 10.101.101.216 with SMTP id y24mr34974909pgv.236.1511855407308; Mon, 27 Nov 2017 23:50:07 -0800 (PST) Received: from localhost.localdomain ([124.56.155.17]) by smtp.gmail.com with ESMTPSA id 67sm39403946pfz.171.2017.11.27.23.50.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Nov 2017 23:50:06 -0800 (PST) From: js1304@gmail.com X-Google-Original-From: iamjoonsoo.kim@lge.com To: Andrew Morton Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Namhyung Kim , Wengang Wang , Joonsoo Kim Subject: [PATCH 14/18] mm/vchecker: make callstack depth configurable Date: Tue, 28 Nov 2017 16:48:49 +0900 Message-Id: <1511855333-3570-15-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511855333-3570-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1511855333-3570-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joonsoo Kim Getting full callstack is heavy job so it's sometimes better to reduce this overhead by limiting callstack depth. So, this patch makes the callstack depth configurable by using debugfs interface. Signed-off-by: Joonsoo Kim --- mm/kasan/vchecker.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/mm/kasan/vchecker.c b/mm/kasan/vchecker.c index acead62..4d140e7 100644 --- a/mm/kasan/vchecker.c +++ b/mm/kasan/vchecker.c @@ -27,6 +27,7 @@ struct vchecker { bool enabled; + unsigned int callstack_depth; struct list_head cb_list; }; @@ -309,13 +310,14 @@ static void filter_vchecker_stacks(struct stack_trace *trace, } static noinline depot_stack_handle_t save_stack(struct stackdepot *s, - unsigned long ret_ip, bool *is_new) + unsigned long ret_ip, unsigned int max_entries, + bool *is_new) { unsigned long entries[VCHECKER_STACK_DEPTH]; struct stack_trace trace = { .nr_entries = 0, .entries = entries, - .max_entries = VCHECKER_STACK_DEPTH, + .max_entries = max_entries, .skip = VCHECKER_SKIP_DEPTH, }; depot_stack_handle_t handle; @@ -489,6 +491,70 @@ static const struct file_operations enable_fops = { .release = single_release, }; +static int callstack_depth_show(struct seq_file *f, void *v) +{ + struct kmem_cache *s = f->private; + struct vchecker *checker = s->vchecker_cache.checker; + + mutex_lock(&vchecker_meta); + seq_printf(f, "%u\n", checker->callstack_depth); + mutex_unlock(&vchecker_meta); + + return 0; +} + +static int callstack_depth_open(struct inode *inode, struct file *file) +{ + return single_open(file, callstack_depth_show, inode->i_private); +} + +static ssize_t callstack_depth_write(struct file *filp, const char __user *ubuf, + size_t cnt, loff_t *ppos) +{ + char callstack_depth_chars[32]; + unsigned int callstack_depth; + struct kmem_cache *s = file_inode(filp)->i_private; + + if (cnt >= 32 || cnt == 0) + return -EINVAL; + + if (copy_from_user(&callstack_depth_chars, ubuf, cnt)) + return -EFAULT; + + if (isspace(callstack_depth_chars[0])) { + callstack_depth = VCHECKER_STACK_DEPTH; + goto setup; + } + + callstack_depth_chars[cnt - 1] = '\0'; + if (kstrtouint(callstack_depth_chars, 10, &callstack_depth)) + return -EINVAL; + + if (callstack_depth > VCHECKER_STACK_DEPTH) + callstack_depth = VCHECKER_STACK_DEPTH; + +setup: + mutex_lock(&vchecker_meta); + if (s->vchecker_cache.checker->enabled || + !list_empty(&s->vchecker_cache.checker->cb_list)) { + mutex_unlock(&vchecker_meta); + return -EINVAL; + } + + s->vchecker_cache.checker->callstack_depth = callstack_depth; + mutex_unlock(&vchecker_meta); + + return cnt; +} + +static const struct file_operations callstack_depth_fops = { + .open = callstack_depth_open, + .write = callstack_depth_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static int init_value(struct kmem_cache *s, struct vchecker_cb *cb, char *buf, size_t cnt) { @@ -571,7 +637,8 @@ static bool check_value(struct kmem_cache *s, struct vchecker_cb *cb, if (!write) goto check; - handle = save_stack(NULL, ret_ip, NULL); + handle = save_stack(NULL, ret_ip, + s->vchecker_cache.checker->callstack_depth, NULL); if (!handle) { pr_err("VCHECKER: %s: fail at addr %p\n", __func__, object); dump_stack(); @@ -715,7 +782,8 @@ static bool check_callstack(struct kmem_cache *s, struct vchecker_cb *cb, struct vchecker_callstack_arg *arg = cb->arg; int idx; - handle = save_stack(arg->s, ret_ip, &is_new); + handle = save_stack(arg->s, ret_ip, + s->vchecker_cache.checker->callstack_depth, &is_new); if (!is_new) return true; @@ -825,6 +893,7 @@ static int alloc_vchecker(struct kmem_cache *s) if (!checker) return -ENOMEM; + checker->callstack_depth = VCHECKER_STACK_DEPTH; INIT_LIST_HEAD(&checker->cb_list); s->vchecker_cache.checker = checker; @@ -848,6 +917,10 @@ static int register_debugfs(struct kmem_cache *s) if (!debugfs_create_file("enable", 0600, dir, s, &enable_fops)) return -ENOMEM; + if (!debugfs_create_file("callstack_depth", 0600, dir, s, + &callstack_depth_fops)) + return -ENOMEM; + for (i = 0; i < ARRAY_SIZE(vchecker_types); i++) { t = &vchecker_types[i]; if (!debugfs_create_file(t->name, 0600, dir, s, t->fops)) -- 2.7.4 From 1585297309672790298@xxx Tue Nov 28 08:22:08 +0000 2017 X-GM-THRID: 1584466607656225114 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread