Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp457659pxj; Thu, 17 Jun 2021 06:41:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgWirYC4nFBvkmh0JuHTU6WzwV56uSYSfjhEHhN6sF093bpIaZWOk688OVYnETA3KJd9bN X-Received: by 2002:a05:6402:908:: with SMTP id g8mr3817353edz.240.1623937298987; Thu, 17 Jun 2021 06:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623937298; cv=none; d=google.com; s=arc-20160816; b=oe1P8jGCO/823dN0kGKeINUOBCKqYVBcU8/30Z+XJ2/jpyE/AgNbL7wJmZf+cNu8Fa TW2h9hBWtIdxBYXbYypckTN9kiMaYpIoxI0I3R2fY4Mtl3nte7CQqmfsv2rIw1hdj/Du 0v5BJKFJagp22nmdzSv6mthVnT8S89zBA2hMozQC6NcL+WUh37vFqVbpg22cWKMiu+Pd tl7L4lOeyc7hcmsGQEu9Gpz3dOILAZeLoiTLcStK4W4BFksohlvMgBjdW3OxDg8KNvd7 cfCNkjSmanIlyN7ib5vsoJ399nlj2VyoINCy6Z1FmxCBqyi8g9f5bLH+71xGrL+1hbIk CDjQ== 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=PAQVkmDM9ks63fpAXt6D/ILvK6PyLHBYSS0DZBxRCs0=; b=UMJN8l2GuJBunN/Z2eEazd6XbpN4ET3XpcZC/W2n6RydtaKAEgbUENuBhponnq3PVb ufbPckG8HCqRwboyuFJpQoULvifNEOKjcwyZKhosnSKNJASjEJMYVmpLS5lEvTLKz6mx WRP+FHd0B0JFx4DWGVLxdy/P9Qi/15RrYIL5c3moEIofCfpzQCeUXJ65Fnzb3zUVyn3m 4l7tAccG0yAvk3znxP/v8QUULybj4mmx6F/i7HZPa4QQHZ39ZveRvKQYNeYgQKONOtxN 7VPOFrEGTLYdq1GlEz6qGOrPds4J3IYf4eVvWDj5+phMVLdyv1mh+sgsI1V/lZHjZT9b JNqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G1n2nMMg; 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 4si5341394ejr.444.2021.06.17.06.41.16; Thu, 17 Jun 2021 06:41:38 -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=G1n2nMMg; 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 S232618AbhFQLxg (ORCPT + 99 others); Thu, 17 Jun 2021 07:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230269AbhFQLxf (ORCPT ); Thu, 17 Jun 2021 07:53:35 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D489C061574 for ; Thu, 17 Jun 2021 04:51:26 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id q20so10060482lfo.2 for ; Thu, 17 Jun 2021 04:51:26 -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=PAQVkmDM9ks63fpAXt6D/ILvK6PyLHBYSS0DZBxRCs0=; b=G1n2nMMgdFMZmLdYpzf8ADnIx5QYjQJK5kMpIwzOyf95zQbz0lsEdME2FrnRnzlrU7 8ULRSEL/JSqomxeu3dJwFcjct8zaRnneogXxgiI7D+vSno8dxIvV3/6N00udo2IBz0j1 WpXzzb6CH0AfEtK8kAA5rNVeYJI5FCJsQY2lAPuH4SBEKCFV2MvsQPiboITpD920IWXO NrRsV5cirP/a0BOsJ0vi8Yvw24BOhxL9lkssRH1d/Q5AeZKPvBfLjwGIr+QY/3cG1tTc 0wEJZ5HXK+F9jerOqBc6+0bYL7o90olY4KWm8XQ+rnz+uCDu2NJbisnoYsBvNOXBu0bz VqdA== 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=PAQVkmDM9ks63fpAXt6D/ILvK6PyLHBYSS0DZBxRCs0=; b=Rjlecvx92T8SmInUKNVtamGcXwJwwPIpGxNtSE9GkDzzDOmFm/fG3TC1p+haHJRk2Y IAN+z3wPB99v64I/mOK08QlAuRpEQyLq9XFfE2dYc5wqAFmEj0SEHF9N8BL+BFCAhM3K NxNTNp9dwniC/raizsjOAmuTVYW2WWx3jmwgG3zvJ6HkIaRIoLf3fx743AwNifd+lHF7 caqHeR8lV17LyAj6HkIRwOssUNxX7mz642aD15/OJA4h2byqqqpsFEKJsEzVoDcCJzxq i73ant8iSEug6JXqh5NSYI0UY9kLDcmQtrMUo3+shPoMpqg1hnlf8J2F2dtaUFDueiTK feeA== X-Gm-Message-State: AOAM5339UPqDXwMoKLojPhxlNM6+10PJ75LbFxTk3nxze8NhgiclNlBg KsET9QiHFwN5g1hKFUovqu6o2zW+dBa6jr/iZcWqvQ== X-Received: by 2002:ac2:5396:: with SMTP id g22mr3701413lfh.84.1623930683579; Thu, 17 Jun 2021 04:51:23 -0700 (PDT) MIME-Version: 1.0 References: <20210323065519.821062-1-sumit.garg@linaro.org> <20210617112527.nganuruifprwhv3h@maple.lan> In-Reply-To: <20210617112527.nganuruifprwhv3h@maple.lan> From: Sumit Garg Date: Thu, 17 Jun 2021 17:21:12 +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 Thu, 17 Jun 2021 at 16:55, Daniel Thompson wrote: > > On Tue, Mar 23, 2021 at 12:25:19PM +0530, Sumit Garg wrote: > > Currently the only user for debug heap is kdbnearsym() which can be > > modified to rather use statically allocated buffer for symbol name as > > per it's current usage. So do that and hence remove custom debug heap > > allocator. > > > > Note that this change puts a restriction on kdbnearsym() callers to > > carefully use shared namebuf such that a caller should consume the symbol > > returned immediately prior to another call to fetch a different symbol. > > > > This change has been tested using kgdbtest on arm64 which doesn't show > > any regressions. > > > > Suggested-by: Daniel Thompson > > Signed-off-by: Sumit Garg > > I'm afraid the passage of time (mostly due to my dropping the ball) > means this no longer applies cleanly to latest kernel and `git am > -3way` tells me that "sha1 information is lacking or useless". > Please can you rebase this on v5.13-rc4 and repost? > Sure. > Also... > > > > diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h > > index b857a84de3b5..ec91d7e02334 100644 > > diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c > > index b59aad1f0b55..e131d74abb8d 100644 > > --- a/kernel/debug/kdb/kdb_support.c > > +++ b/kernel/debug/kdb/kdb_support.c > > @@ -57,35 +57,26 @@ 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'. > > + * kdbnearsym() - Return the name of the symbol with the nearest address > > + * less than @addr. > > + * @addr: Address to check for near symbol > > + * @symtab: Structure to receive results > > * > > - * Parameters: > > - * addr Address to check for symbol near > > - * symtab Structure to receive results > > - * Returns: > > - * 0 No sections contain this address, symtab zero filled > > - * 1 Address mapped to module/symbol/section, data in symtab > > - * Remarks: > > - * 2.6 kallsyms has a "feature" where it unpacks the name into a > > - * string. If that string is reused before the caller expects it > > - * then the caller sees its string change without warning. To > > - * avoid cluttering up the main kdb code with lots of kdb_strdup, > > - * tests and kfree calls, kdbnearsym maintains an LRU list of the > > - * last few unique strings. The list is sized large enough to > > - * hold active strings, no kdb caller of kdbnearsym makes more > > - * than ~20 later calls before using a saved value. > > + * Note here that only single statically allocated namebuf is used for every > > + * symbol, so the caller should consume it immediately prior to another call > > + * to fetch a different symbol. > > This still looks like it will confused experienced kernel devs who > aren't aware of kdb's calling context. Nor does it help future kdb > developers understand some of the subtlty of interactions here. > > Can you enlarge this to the following (editing anything below that you > don't want git to blame you for ;-) ): > > ~~~ > WARNING: This function may return a pointer to a single statically > allocated buffer (namebuf). kdb's unusual calling context (single > threaded, all other CPUs halted) provides us sufficient locking for > this to be safe. The only constraint imposed by the static buffer is > that the caller must consume any previous reply prior to another call > to lookup a new symbol. > > Note that, strictly speaking, some architectures may re-enter the kdb > trap if the system turns out to be very badly damaged and this breaks > the single-threaded assumption above. In these circumstances successful > continuation and exit from the inner trap is unlikely to work and any > user attempting this receives a prominent warning before being allowed > to progress. In these circumstances we remain memory safe because > namebuf[KSYM_NAME_LEN-1] will never change from '\0' although we do > tolerate the possibility of garbled symbol display from the outer kdb > trap. > ~~~ > Okay I will use this comment instead. -Sumit > Thanks > > > Daniel.