Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp504085pxb; Thu, 25 Feb 2021 07:58:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/O8Tc875aDL5uQyvLN+8bMIWXCGhPKI01VBsSdECaRiELgh505mb4C6HI47WcGRoHS4Cq X-Received: by 2002:a17:906:1182:: with SMTP id n2mr3327929eja.234.1614268729554; Thu, 25 Feb 2021 07:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614268729; cv=none; d=google.com; s=arc-20160816; b=d2BlTzkVgnsPBnDDk/c78Ch7IUT+hG5gFqiYGAilHwK4L8ytgFFdmkhcDAW8JTQ073 RPgmAQUAQ5d/xwyPlxf1JR2nJhxAywMmt4xynB8jaSnN1uXsTFBxRmQY6qigWskynuN4 yLygaz+5AYxVi153syEidSgRmXJKcZliv43M0hDTyoEF9gYeixm/98wEQiG6x6mmJ2PP DOaGBEH+Htjcmi4RUKecI0F6xgvaoU/cS9F+4Megfjqq3nbRC4nCdvP2Ji9WSl078HPN q+PV9pilcB34owg+sjKTdesKuaopShMbaWsHY7dk5+hJ2oSEMs54O/ZE4y8wu0YrYnEg hRpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=IKK5Sk4xYKEQS6he6oFH14uzFoBWOsLEHulMdGPTh3s=; b=xNr/DHWgTqMsXz219tDUyYF5hgYslRbYFCtK3V1uVmGzEY6qGhXScHiPiiHY0tBQV3 AR5eJYM2vEu75ejYkSTRWbCX4SmvDe3Ow+SQiZXj6Pce88QTnZiz1D6vPg171t7qOFqK QKY/e3Uoa4zOehoa3+5eoeVY4xljTCknhSfyxFPHlQw7mURhA4O/5z6ElDh1bJoCc6ke 78Di3WgKHfrWo/anv+gXbkG/mf8Plxw5f1BzNBM9IbTSUwNDjRgjMyRlxhsSajb+T2yU u1fBYX3K5qPasqfIAswby6zOfJus7+rUdT7q/UPlSA6oZULw538M21JbHx1ai01T0jOT asog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rf7dYtwj; 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 pw12si3751753ejb.378.2021.02.25.07.58.25; Thu, 25 Feb 2021 07:58:49 -0800 (PST) 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=Rf7dYtwj; 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 S231960AbhBYP4y (ORCPT + 99 others); Thu, 25 Feb 2021 10:56:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231160AbhBYP4w (ORCPT ); Thu, 25 Feb 2021 10:56:52 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4C25C061574 for ; Thu, 25 Feb 2021 07:56:10 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id d11so5734754wrj.7 for ; Thu, 25 Feb 2021 07:56:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=IKK5Sk4xYKEQS6he6oFH14uzFoBWOsLEHulMdGPTh3s=; b=Rf7dYtwjQhhovLSRhQ++Yw2wPK4miSxmPQp+4AVUVIksnPY1j4FrbB90Gkfovz3njH Twrir59gr01W9OudUEgazdYm0MHK0yiyAid99ozreQuRf/KE6p2NWw/XfA7jRc01lDdW KY6kndFd/BSJQdsPnsmqW/2hDWF2/CpsmBnAN4d/Jf2x28RXxEJ79vBIqpGm4IwrVRrT Gw3nvPwZdSa6usNGKf3zlgozi6zfBt19Y/oPzakvwhCUPFt7goKzfLb+wuPMoBD4k1UZ LdeWizKmUC8988+3SKp5SR4SRVbK1pE3LNaA82fWqOSY9tXswNtu2Q8x59rLS6Kof26p x84w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=IKK5Sk4xYKEQS6he6oFH14uzFoBWOsLEHulMdGPTh3s=; b=mMxmI6FyV3TkTA44OGEvzF0/QZBnyvhyP8STyCYujyhPzxC0rzIjd/pYbkygy4Qunx sPuLTqKjNTVVLxABl4x0MhSl/OMto8DvtKtVctJRaUz/koEIvAb6AM1qv3bs4uwUPPtG mT+NJikUhuXsJ0j8LdW6aQ9HhwJzlJoNy9Sg+L7vgbPclx2AZFwBFfxPcNdoXkRlonJ4 y93wnnQPOm9CI1CZby1fCDy+6mgteQrbrhTDrJcXr9/ObbhaMYzm2DPMaLDlAUTZYj0/ rtF0EhX3R+1WqNlphS9X7DpoTzh3j3skn8+ymMTrHYBrcX5nqAhqLZs1+KqI4UrepFGZ /urg== X-Gm-Message-State: AOAM533lRF7D+q2UI9K4Q+gt2GkdyUX2sn0ArcAa5fWiAQhAVm+IlNp4 hqYZo2NTEgL+MWchvb4NxT51wPXsxWmmqRo1 X-Received: by 2002:adf:8104:: with SMTP id 4mr4193667wrm.265.1614268569651; Thu, 25 Feb 2021 07:56:09 -0800 (PST) Received: from maple.lan (cpc141216-aztw34-2-0-cust174.18-1.cable.virginm.net. [80.7.220.175]) by smtp.gmail.com with ESMTPSA id x18sm8702512wrs.16.2021.02.25.07.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 07:56:09 -0800 (PST) Date: Thu, 25 Feb 2021 15:56:07 +0000 From: Daniel Thompson To: Sumit Garg Cc: kgdb-bugreport@lists.sourceforge.net, akpm@linux-foundation.org, mhiramat@kernel.org, rostedt@goodmis.org, jason.wessel@windriver.com, dianders@chromium.org, peterz@infradead.org, stefan.saecherl@fau.de, qy15sije@cip.cs.fau.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kgdb: Fix to kill breakpoints on initmem after boot Message-ID: <20210225155607.634snzzq3w62kpkn@maple.lan> References: <20210224081652.587785-1-sumit.garg@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210224081652.587785-1-sumit.garg@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 24, 2021 at 01:46:52PM +0530, Sumit Garg wrote: > Currently breakpoints in kernel .init.text section are not handled > correctly while allowing to remove them even after corresponding pages > have been freed. > > Fix it via killing .init.text section breakpoints just prior to initmem > pages being freed. > > Suggested-by: Doug Anderson > Signed-off-by: Sumit Garg I saw Andrew has picked this one up. That's ok for me: Acked-by: Daniel Thompson I already enriched kgdbtest to cover this (and they pass) so I guess this is also: Tested-by: Daniel Thompson BTW this is not Cc:ed to stable and I do wonder if it crosses the threshold to be considered a fix rather than a feature. Normally I consider adding safety rails for kgdb to be a new feature but, in this case, the problem would easily ensnare an inexperienced developer who is doing nothing more than debugging their own driver (assuming they correctly marked their probe function as .init) so I think this weighs in favour of being a fix. Daniel. > --- > include/linux/kgdb.h | 2 ++ > init/main.c | 1 + > kernel/debug/debug_core.c | 11 +++++++++++ > 3 files changed, 14 insertions(+) > > diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h > index 57b8885708e5..3aa503ef06fc 100644 > --- a/include/linux/kgdb.h > +++ b/include/linux/kgdb.h > @@ -361,9 +361,11 @@ extern atomic_t kgdb_active; > extern bool dbg_is_early; > extern void __init dbg_late_init(void); > extern void kgdb_panic(const char *msg); > +extern void kgdb_free_init_mem(void); > #else /* ! CONFIG_KGDB */ > #define in_dbg_master() (0) > #define dbg_late_init() > static inline void kgdb_panic(const char *msg) {} > +static inline void kgdb_free_init_mem(void) { } > #endif /* ! CONFIG_KGDB */ > #endif /* _KGDB_H_ */ > diff --git a/init/main.c b/init/main.c > index c68d784376ca..a446ca3d334e 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -1417,6 +1417,7 @@ static int __ref kernel_init(void *unused) > async_synchronize_full(); > kprobe_free_init_mem(); > ftrace_free_init_mem(); > + kgdb_free_init_mem(); > free_initmem(); > mark_readonly(); > > diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c > index 229dd119f430..319381e95d1d 100644 > --- a/kernel/debug/debug_core.c > +++ b/kernel/debug/debug_core.c > @@ -465,6 +465,17 @@ int dbg_remove_all_break(void) > return 0; > } > > +void kgdb_free_init_mem(void) > +{ > + int i; > + > + /* Clear init memory breakpoints. */ > + for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { > + if (init_section_contains((void *)kgdb_break[i].bpt_addr, 0)) > + kgdb_break[i].state = BP_UNDEFINED; > + } > +} > + > #ifdef CONFIG_KGDB_KDB > void kdb_dump_stack_on_cpu(int cpu) > { > -- > 2.25.1