Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp355678pxj; Wed, 16 Jun 2021 04:08:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlEpDzTkgiSGk9YYtdRefKDAH/GYr6dZ5BI7s5J9PFe9zjJ6ugeMYokNl12DPL+t2yJtsc X-Received: by 2002:aa7:dd43:: with SMTP id o3mr2015461edw.302.1623841701175; Wed, 16 Jun 2021 04:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623841701; cv=none; d=google.com; s=arc-20160816; b=AGetH5bXlTA1xmcxyETV588xHX2rVst1fUhMvZmVQp91C18apRn29KrZ1ZH5mD2o5m wYtTvJp2UhgN33SkyTFoOV+9dUtEpbh1Iclsg6Aw7PdlfDT7YYXufGrGNS47I+PbwP6y UZPQ1XzxGBvTaCKjHjrUZ5ahgN+yzYN1HOKPR0f6FBBaH7etE4zf5Pg7BpH76CtX6WrM PrgJxfgLp1yiL7/H16iufOQHGJ2/pHhacnJEyTNedXLY/zYKKj9b+Z9XqI72D4JvLSdX AtAZj+J0HOkOK2eGLdBsJ+8kUI1IX/V53fSdt+PkUn+Wb3DqVkW+U8ZaRWAlxzX7pfc4 W4OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=hcnqgYV1OHaJr0sq4rpPF6e//e/o64rPvF0s7j9YdWo=; b=zjCHbASxrVYGh1HEM/x88u5PImW0xvGOYe729brnSinQ4MjpcL4rpEs4bQGP2hayQt Riwwuh6RFMl3tv9WnTEfS9u+5xy7P3kSJAmQ2YJ3Ds8RVBsmhUtIJNrqX7gzPZAWb8zc DrPpaL+gPaOpJD17gwpGT1iuMPut6qjEkuqVUKHPlrHV6aVJ1xslrqMRUxx0+73LEZhQ aMHliXf0p0XIx+CnlAAyo7xxwsNU+/H2o0Vb+dNnjyzdSJi4BAxtYI4LxBgYAE/pIfBH N887rilIzAMcCdV8aLurS06uzujxGzIImcKGexWfe8F2ybB+uEt6tVaeigxSnM4uvR++ hg1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=lHUFofQk; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=lHUFofQk; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=OPJCzz5n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t7si1941859ejx.540.2021.06.16.04.07.57; Wed, 16 Jun 2021 04:08:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=lHUFofQk; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=lHUFofQk; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=OPJCzz5n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231303AbhFPLHw (ORCPT + 99 others); Wed, 16 Jun 2021 07:07:52 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:41080 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230409AbhFPLHw (ORCPT ); Wed, 16 Jun 2021 07:07:52 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 93E20219D6; Wed, 16 Jun 2021 11:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623841545; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hcnqgYV1OHaJr0sq4rpPF6e//e/o64rPvF0s7j9YdWo=; b=lHUFofQkBTtr5npeN6gBLNXp4eETFhqp4qQHwOICibnfQTXZH6php5fyMCiYGgIQieQXFX EpwGmSEmbym19oxSrxL0LgUR+0c7dqOMss1oQozuCDivp2GDzN1u2iRJNYncxwSDHH6/j4 5dbCDJgs7WirXvLfeOQDhmxPq7J+Oag= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623841545; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hcnqgYV1OHaJr0sq4rpPF6e//e/o64rPvF0s7j9YdWo=; b=OPJCzz5nh9hmVzow8cUb64+csDdolPJFKZYD24Z8N/xvAkA8HEvSonlpWmcUOYggqUVed1 d07OTbm8iBqpfbBA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 68ADB118DD; Wed, 16 Jun 2021 11:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623841545; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hcnqgYV1OHaJr0sq4rpPF6e//e/o64rPvF0s7j9YdWo=; b=lHUFofQkBTtr5npeN6gBLNXp4eETFhqp4qQHwOICibnfQTXZH6php5fyMCiYGgIQieQXFX EpwGmSEmbym19oxSrxL0LgUR+0c7dqOMss1oQozuCDivp2GDzN1u2iRJNYncxwSDHH6/j4 5dbCDJgs7WirXvLfeOQDhmxPq7J+Oag= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623841545; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hcnqgYV1OHaJr0sq4rpPF6e//e/o64rPvF0s7j9YdWo=; b=OPJCzz5nh9hmVzow8cUb64+csDdolPJFKZYD24Z8N/xvAkA8HEvSonlpWmcUOYggqUVed1 d07OTbm8iBqpfbBA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id QtwCGQnbyWDBYgAALh3uQQ (envelope-from ); Wed, 16 Jun 2021 11:05:45 +0000 To: Qian Cai , Faiyaz Mohammed , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, greg@kroah.com, glittao@gmail.com, andy.shevchenko@gmail.com Cc: vinmenon@codeaurora.org, Catalin Marinas References: <1623438200-19361-1-git-send-email-faiyazm@codeaurora.org> <8c821abf-8fa6-b78b-cea4-b7d3b3b74a69@quicinc.com> From: Vlastimil Babka Subject: Re: [PATCH v12] mm: slub: move sysfs slab alloc/free interfaces to debugfs Message-ID: Date: Wed, 16 Jun 2021 13:05:45 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <8c821abf-8fa6-b78b-cea4-b7d3b3b74a69@quicinc.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/15/21 5:58 PM, Qian Cai wrote: > > > On 6/11/2021 3:03 PM, Faiyaz Mohammed wrote: >> alloc_calls and free_calls implementation in sysfs have two issues, >> one is PAGE_SIZE limitation of sysfs and other is it does not adhere >> to "one value per file" rule. >> >> To overcome this issues, move the alloc_calls and free_calls >> implementation to debugfs. >> >> Debugfs cache will be created if SLAB_STORE_USER flag is set. >> >> Rename the alloc_calls/free_calls to alloc_traces/free_traces, >> to be inline with what it does. >> >> Reviewed-by: Vlastimil Babka >> Reviewed-by: Greg Kroah-Hartman >> Signed-off-by: Faiyaz Mohammed > > Reverting this commit on today's linux-next fixed all leaks (hundreds) reported by kmemleak like below, > > unreferenced object 0xffff00091ae1b540 (size 64): > comm "lsbug", pid 1607, jiffies 4294958291 (age 1476.340s) > hex dump (first 32 bytes): > 02 00 00 00 00 00 00 00 6b 6b 6b 6b 6b 6b 6b 6b ........kkkkkkkk > 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk > backtrace: > [] slab_post_alloc_hook+0xa0/0x418 > [] kmem_cache_alloc_trace+0x1e4/0x378 > [] slab_debugfs_start+0x30/0x50 > slab_debugfs_start at /usr/src/linux-next/mm/slub.c:5831 > [] seq_read_iter+0x214/0xd50 > [] seq_read+0x28c/0x418 > [] full_proxy_read+0xdc/0x148 > [] vfs_read+0x104/0x340 > [] ksys_read+0xf8/0x1e0 > [] __arm64_sys_read+0x74/0xa8 > [] invoke_syscall.constprop.0+0xdc/0x1d8 > [] do_el0_svc+0xe4/0x298 > [] el0_svc+0x20/0x30 > [] el0t_64_sync_handler+0xb0/0xb8 > [] el0t_64_sync+0x178/0x17c > I think the problem is here: >> +static void slab_debugfs_stop(struct seq_file *seq, void *v) >> +{ >> + kfree(v); >> +} >> + >> +static void *slab_debugfs_next(struct seq_file *seq, void *v, loff_t *ppos) >> +{ >> + loff_t *spos = v; >> + struct loc_track *t = seq->private; >> + >> + if (*ppos < t->count) { >> + *ppos = ++*spos; >> + return spos; >> + } >> + *ppos = ++*spos; >> + return NULL; >> +} If we return NULL, then NULL is passed to slab_debugfs_stop and thus we don't kfree ppos. kfree(NULL) is silently ignored. I think as we have private struct loc_track, we can add a pos field there and avoid the kmaloc/kfree altogether.