Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4007650pxf; Mon, 22 Mar 2021 23:30:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwv0X3mjyjqEqGdV5C27Q4NINtqXnW2sX3nT/2GQwkJd6S4M3iyS8lTB5QCEzIh3tf1WeIn X-Received: by 2002:a05:6402:35d3:: with SMTP id z19mr2943537edc.143.1616481022690; Mon, 22 Mar 2021 23:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616481022; cv=none; d=google.com; s=arc-20160816; b=I8RIG5Vupd8MHyRaMp+KR5dYDReP46053dTmCfRLSUfMT2gJIIuRQ2acEnq+R7jBCN xJpr0XFdflce1N4hT12NPn8u82YszJN7jQk4ZpaguzpxytSvcX3Vn2UkdqOv+fNYBZiD eAN0YOHxs2Wb6qSh+f49BJ/jxxv0HVfK63jXScl77RtMG5AdgAuDtErpNx70wVX+AhsC /RbvxuSfj+A88gQoVfYOESR5BJt+bEwnfgMw3vyZaJzXWexTAY82GZD62f73WWlVlHjG zDW1xBVWIfn4DR0dicmxJkpMhh38tydoelLrELvexhrBTVtdrnDeArlVEaRYZ7urqvJQ LS5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Tf3+ufm9CCQWVkrT07EmAz18ZuZ1xI3SfrYzdfNmVEs=; b=X62RySm1o6Unu4Xnluwe1oczhE+gYcLlAhDMflU1KoCydu5T0NfqvO9c1vHc00ehKs N0l1L4mswxTkTn2z/x1k3sElb17Y927G8sMWYA2RmT7FLHkOydlX0im7igMdN8V7iwOB sEwCyFyFAH7tTKVu2AnnE0OgRgfm5ph5FhsQpBn58PTMH1IWReANbtQJtt4EfDQYAzNx l1RDZIaPfnglTS2XhQ+JpJrAeR78QmLKPUZn9pX4hfLbHEw/9xy0qdWF0Utxt/oZMb5V NP+jxWHR0T2J6kmVEUnOjcgW1vq1yFbUFPor02IXlbwOOmg9nyFgFbSTozaNSy+8Jrma xptQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hKD863u5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si12359844edx.95.2021.03.22.23.29.59; Mon, 22 Mar 2021 23:30:22 -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=@linaro.org header.s=google header.b=hKD863u5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229437AbhCWG1f (ORCPT + 99 others); Tue, 23 Mar 2021 02:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbhCWG1L (ORCPT ); Tue, 23 Mar 2021 02:27:11 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3301DC061574 for ; Mon, 22 Mar 2021 23:27:11 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id n138so24959478lfa.3 for ; Mon, 22 Mar 2021 23:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Tf3+ufm9CCQWVkrT07EmAz18ZuZ1xI3SfrYzdfNmVEs=; b=hKD863u5GWp09THn+Fjpe3f27PjIOM2kUWsUcHLpFeMMvK4PACsFwnZaxfIvS9+WtO 8o8wE6nUgBWRjJIPYEuCHruJ0o9MrIciN17RvW0ipbGVgXeHP0JBIwuwtTjeBv2l3UTH ktzFiHIxm7igxMrAHr1G/P34mrU6h5kruu9efCUaS6I9dBgzOdsueuUlIgYeN7sFC0BK yFi1XNnhBsralnp0YyUG3YYxzINrbYTc3G+Nyk05o6EYffTmsxIgBkUK6uwfBiMTp3Ag WWtCwieB5CZEXXuJzB/cmsTVu5yCzROZTGh7gjImTDt14BnejgL8CioD5EZq3jPrgvmz 2//Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Tf3+ufm9CCQWVkrT07EmAz18ZuZ1xI3SfrYzdfNmVEs=; b=EMkz1VkzjBf5sL4K5w6TR2Ek/2GxC4h7+xr0pHdhTe/MEFDBAFOP2M1X0daf/YXUpu I4eWXHjQKoknxIGYYlflKsWJHOSOboeTqts4Z/RdmMsR3J++tdK+Lr7VJmcvSug2R2lf xz9STc8jZFawklnoT3BCnqziyThAaPhBYYjuFtGfRe1nrFYuctlw1KtuYFJQhGSgz6b8 M9ON0/OSdQsu/R1TL/IwwnmVh6apGdvdlQa9Ex5brEl3tM0+LUwYvg0YFSE7VVmcujlB 5NRvwfi4DL7D2F2RwtH1DarSQE/A/HOoCwABDQELKDCLhQjgEnllE2bbQo/jUP2WNJMl a79g== X-Gm-Message-State: AOAM5334YEkGSkL2CzhsHcXU4taYlQoXaPPbUgJJtxOf7HnAuF4206Uc 2hVLXwE9JOuG8b1CoN/g/SUL/0T+9llijdCoIDn/FQ== X-Received: by 2002:ac2:46db:: with SMTP id p27mr1720809lfo.396.1616480829596; Mon, 22 Mar 2021 23:27:09 -0700 (PDT) MIME-Version: 1.0 References: <20210226095306.1236539-1-sumit.garg@linaro.org> <20210226105934.gmppt6kubfadv4uf@maple.lan> <20210226173727.dqa5uytqwbll6omo@maple.lan> <20210319173525.m5uagzthzzmtuldy@maple.lan> In-Reply-To: <20210319173525.m5uagzthzzmtuldy@maple.lan> From: Sumit Garg Date: Tue, 23 Mar 2021 11:56:58 +0530 Message-ID: Subject: Re: [PATCH v2] kdb: Get rid of custom debug heap allocator To: Daniel Thompson Cc: kgdb-bugreport@lists.sourceforge.net, Jason Wessel , Douglas Anderson , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 19 Mar 2021 at 23:05, Daniel Thompson wrote: > > On Mon, Mar 01, 2021 at 11:33:00AM +0530, Sumit Garg wrote: > > On Fri, 26 Feb 2021 at 23:07, Daniel Thompson > > wrote: > > > > > > On Fri, Feb 26, 2021 at 06:12:13PM +0530, Sumit Garg wrote: > > > > On Fri, 26 Feb 2021 at 16:29, Daniel Thompson > > > > wrote: > > > > > > > > > > On Fri, Feb 26, 2021 at 03:23:06PM +0530, Sumit Garg wrote: > > > > > > Currently the only user for debug heap is kdbnearsym() which can be > > > > > > modified to rather ask the caller to supply a buffer for symbol name. > > > > > > So do that and modify kdbnearsym() callers to pass a symbol name buffer > > > > > > allocated statically and hence remove custom debug heap allocator. > > > > > > > > > > Why make the callers do this? > > > > > > > > > > The LRU buffers were managed inside kdbnearsym() why does switching to > > > > > an approach with a single buffer require us to push that buffer out to > > > > > the callers? > > > > > > > > > > > > > Earlier the LRU buffers managed namebuf uniqueness per caller (upto > > > > 100 callers) > > > > > > The uniqueness is per symbol, not per caller. > > > > > > > Agree. > > > > > > but if we switch to single entry in kdbnearsym() then all > > > > callers need to share common buffer which will lead to incorrect > > > > results from following simple sequence: > > > > > > > > kdbnearsym(word, &symtab1); > > > > kdbnearsym(word, &symtab2); > > > > kdb_symbol_print(word, &symtab1, 0); > > > > kdb_symbol_print(word, &symtab2, 0); > > > > > > > > But if we change to a unique static namebuf per caller then the > > > > following sequence will work: > > > > > > > > kdbnearsym(word, &symtab1, namebuf1); > > > > kdbnearsym(word, &symtab2, namebuf2); > > > > kdb_symbol_print(word, &symtab1, 0); > > > > kdb_symbol_print(word, &symtab2, 0); > > > > > > This is true but do any of the callers of kdbnearsym ever do this? > > > > No, but any of prospective callers may need this. > > > > > The > > > main reaason that heap stuck out as redundant was that I've only ever > > > seen the output of kdbnearsym() consumed almost immediately by a print. > > > > > > > Yeah but I think the alternative proposed in this patch isn't as > > burdensome as the heap and tries to somewhat match existing > > functionality. > > > > > I wrote an early version of a patch like this that just shrunk the LRU > > > cache down to 2 and avoided any heap usage... but I threw it away > > > when I realized we never carry cached values outside the function > > > that obtained them. > > > > > > > Okay, so if you still think that having a single static buffer inside > > kdbnearsym() is an appropriate approach for time being then I will > > switch to use that instead. > > Sorry to drop this thread for so long. > > On reflection I still have a few concerns about the current code. > To be clear this is not really about wasting 128 bytes of RAM (your > patch saves 256K after all). > > It's more that the current static buffers "look weird". They are static > so any competent OS programmer reads them and thinks "but what about > concurrency/reentrancy"). With the static buffers scattered through the > code they don't have a single place to find the answer. > > I originally proposed handling this by the static buffer horror in > kdbnearsym() and describing how it all works in the header comment! > As much as anything this was to centralize the commentary in the > contract for calling kdbnearsym(). Hence nobody should write the > theoretic bug you describe because they read the contract! > > You are welcome to counter propose but you must ensure that there are > equivalent comments so our "competent OS programmer" from the paragraph > above can figure out how the static buffer works without having to run > git blame` and digging out the patch history. > Okay, I understand your point here. Let me go ahead with a single static buffer in kdbnearsym() with a proper header comment. -Sumit > > Daniel. > > > > > > > -Sumit > > > > > > > > > > > @@ -526,6 +526,7 @@ int kdbgetaddrarg(int argc, const char **argv, int *nextarg, > > > > > > > > > > > > > > > diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c > > > > > > index 9d69169582c6..6efe9ec53906 100644 > > > > > > --- a/kernel/debug/kdb/kdb_main.c > > > > > > +++ b/kernel/debug/kdb/kdb_main.c > > > > > > @@ -526,6 +526,7 @@ int kdbgetaddrarg(int argc, const char **argv, int *nextarg, > > > > > > > > > > The documentation comment for this function has not been updated to > > > > > describe the new contract on callers of this function (e.g. if they > > > > > consume the symbol name they must do so before calling kdbgetaddrarg() > > > > > (and maybe kdbnearsym() again). > > > > > > > > > > > > > I am not sure if I follow you here. If we have a unique static buffer > > > > per caller then why do we need this new contract? > > > > > > I traced the code wrong. I thought it shared symtab->sym_name with its > > > own caller... but it doesn't it shares synname with its caller and > > > that's totally different... > > > > > > > > > Daniel. > > > > > > > > > > > > > > > > > > char symbol = '\0'; > > > > > > char *cp; > > > > > > kdb_symtab_t symtab; > > > > > > + static char namebuf[KSYM_NAME_LEN]; > > > > > > > > > > > > /* > > > > > > * If the enable flags prohibit both arbitrary memory access > > > > > > diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c > > > > > > index b59aad1f0b55..9b907a84f2db 100644 > > > > > > --- a/kernel/debug/kdb/kdb_support.c > > > > > > +++ b/kernel/debug/kdb/kdb_support.c > > > > > > @@ -57,8 +57,6 @@ int kdbgetsymval(const char *symname, kdb_symtab_t *symtab) > > > > > > } > > > > > > EXPORT_SYMBOL(kdbgetsymval); > > > > > > > > > > > > -static char *kdb_name_table[100]; /* arbitrary size */ > > > > > > - > > > > > > /* > > > > > > * kdbnearsym - Return the name of the symbol with the nearest address > > > > > > * less than 'addr'. > > > > > > > > > > Again the documentation comment has not been updated and, in this case, > > > > > is now misleading. > > > > > > > > Okay, I will fix it. > > > > > > > > > > > > > > If we move the static buffer here then the remarks section on this > > > > > function is a really good place to describe what the callers must do to > > > > > manage the static buffer safely as well as a convenient place to mention > > > > > that we tolerate the reuse of the static buffer if kdb is re-entered > > > > > becase a) kdb is broken if that happens and b) we are crash resilient > > > > > if if does. > > > > > > > > > > > > > > > > @@ -79,13 +77,11 @@ static char *kdb_name_table[100]; /* arbitrary size */ > > > > > > * hold active strings, no kdb caller of kdbnearsym makes more > > > > > > * than ~20 later calls before using a saved value. > > > > > > */ > > > > > > -int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab) > > > > > > +int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab, char *namebuf) > > > > > > > > > > As above, I don't understand why we need to add namebuf here. I think > > > > > the prototype can remain the same. > > > > > > > > > > Think of it simple that we have reduce the cache from having 100 entries > > > > > to having just 1 ;-) . > > > > > > > > Please see my response above. > > > > > > > > -Sumit > > > > > > > > > > > > > > > > > > > Daniel.