Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9848018imu; Wed, 5 Dec 2018 11:16:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vb/+NS8lw3JFilPslcvTdcqHiGwBJlF0J62I8cOt4dB3fmNn5AaXWkhr445fPKKEyChFfb X-Received: by 2002:a17:902:5ac7:: with SMTP id g7mr25718943plm.212.1544037391388; Wed, 05 Dec 2018 11:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544037391; cv=none; d=google.com; s=arc-20160816; b=P6/c2C+k1pn2n6FrsMCfXJOhv647Qn5NbWraxecFmCt60AjFM5lVjCyalTcsNM/sI8 aerD/V+vJ3PqqxfFkmQ0CN/H5cj0pBgc1Y1MggpL4Mtdf7/DZFcyW4R5sqWm4r52oOSR tRotRWWlqxudWHc3MzIxi+25jLTV1ovrK4U6gK5HMQscw937sCK+vVO2MDN4ZhFsoFzh IDgI7xoNamUx2t7FwbFKmqSwe5NFbXZPIElgphs0VFnYN4Lh1Or2z1/w5+UYAPLWGqMe vKIU+GsP1F7jzUiTIz7ngdrNWkc2tzVzbolCpEv1D3nkz223NYZ/JeCQOLpR3i2T+aeM 4bjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=x+bJpO98gM8zAnfIspgOlfpDJ0F102BwqGYpQSP7Nj0=; b=Ng4mQcJNDTO5DGJP/c/gGLHk9F1X9SiyDoI9VeRlHNhA1hSoi9Q87Dt8twPGuFq0ZD JG0zqX0RFhtAuPo3sN33IqdoWRZ5xQiCHCvtOChg0J8uKycAQxpAdgJvXZIOHDxOJ0h9 2aBZLEx0kbCtnb2+nvH2i27i+CQJDDQ3rfXvvkgs/Y1nnsSAyeGiV7+ToWLWEiOq3zux OUMEFfptIt668SlxsPXN6tu8fzQflaOM6Wg8aFghKKTSfwmefz4HPReCkfNOkNTbRVaa +jYmy7aRudJAOuEdj4hA3GOUIWdLlDiSIhSI8icndwo1ZCRlNEEn8TkXSnaQrm4xW3N8 ngjw== 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 x15si18761368pgq.378.2018.12.05.11.16.14; Wed, 05 Dec 2018 11:16:31 -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; 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 S1728269AbeLETOL convert rfc822-to-8bit (ORCPT + 99 others); Wed, 5 Dec 2018 14:14:11 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:49712 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727436AbeLETOK (ORCPT ); Wed, 5 Dec 2018 14:14:10 -0500 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1gUccT-0000sm-4o; Wed, 05 Dec 2018 20:14:01 +0100 Date: Wed, 5 Dec 2018 20:14:01 +0100 From: Sebastian Andrzej Siewior To: He Zhe Cc: catalin.marinas@arm.com, tglx@linutronix.de, rostedt@goodmis.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org Subject: Re: [PATCH v2] kmemleak: Turn kmemleak_lock to raw spinlock on RT Message-ID: <20181205191400.qrhim3m3ak5hcsuh@linutronix.de> References: <1542877459-144382-1-git-send-email-zhe.he@windriver.com> <20181123095314.hervxkxtqoixovro@linutronix.de> <40a63aa5-edb6-4673-b4cc-1bc10e7b3953@windriver.com> <20181130181956.eewrlaabtceekzyu@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-12-05 21:53:37 [+0800], He Zhe wrote: > For call trace 1: … > Since kmemleak would most likely be used to debug in environments where > we would not expect as great performance as without it, and kfree() has raw locks > in its main path and other debug function paths, I suppose it wouldn't hurt that > we change to raw locks. okay. > >> >From what I reached above, this is RT-only and happens on v4.18 and v4.19. > >> > >> The call trace above is caused by grabbing kmemleak_lock and then getting > >> scheduled and then re-grabbing kmemleak_lock. Using raw lock can also solve > >> this problem. > > But this is a reader / writer lock. And if I understand the other part > > of the thread then it needs multiple readers. > > For call trace 2: > > I don't get what "it needs multiple readers" exactly means here. > > In this call trace, the kmemleak_lock is grabbed as write lock, and then scheduled > away, and then grabbed again as write lock from another path. It's a > write->write locking, compared to the discussion in the other part of the thread. > > This is essentially because kmemleak hooks on the very low level memory > allocation and free operations. After scheduled away, it can easily re-enter itself. > We need raw locks to prevent this from happening. With raw locks you wouldn't have multiple readers at the same time. Maybe you wouldn't have recursion but since you can't have multiple readers you would add lock contention where was none (because you could have two readers at the same time). > > Couldn't we just get rid of that kfree() or move it somewhere else? > > I mean if the free() memory on CPU-down and allocate it again CPU-up > > then we could skip that, rigth? Just allocate it and don't free it > > because the CPU will likely get up again. > > For call trace 1: > > I went through the CPU hotplug code and found that the allocation of the > problematic data, cpuc->shared_regs, is done in intel_pmu_cpu_prepare. And > the free is done in intel_pmu_cpu_dying. They are handlers triggered by two > different perf events. > > It seems we can hardly form a convincing method that holds the data while > CPUs are off and then uses it again. raw locks would be easy and good enough. Why not allocate the memory in intel_pmu_cpu_prepare() if it is not already there (otherwise skip the allocation) and in intel_pmu_cpu_dying() not free it. It looks easy. > Thanks, > Zhe Sebastian