Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2404883pxb; Tue, 23 Feb 2021 06:25:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDzweHKs9WOV2eEcV7b7gzVxa89H9zybdwEGX0KPQkFDolEkzoDqg7jl+dEUN3dzAaVKZz X-Received: by 2002:a17:906:4102:: with SMTP id j2mr17463557ejk.460.1614090322102; Tue, 23 Feb 2021 06:25:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614090322; cv=none; d=google.com; s=arc-20160816; b=wtnZTuuM4srG3Qmf03Sd5BE5FJElHxAPbeJCUUm7gweQIXAvE8jldvusT5u8/6ruPs GP3nar6x0Soi4mM2hOXUa0azuTYkjjV2I0aD1jkNESt7Po8aWcZMKsp3IF4C2ure+ljY 9B8ilHL2WVtsrS67HWF8B5MS0VTgnHeiX9PPLY+pNUZoPY8nb+uoSAGUuXhCCSFjlUfX HB4eMs8RLW4ZulJPvxRxXR8RKhePlrkCA6TQrDXbQBSklOxs0T+c+j0CWqki1UQtdV0n b2WvzsjyEir0I46Pf46KwlQQ3R3fsqGKPPiOORJyBuy6NEFqAVcKWmmMzvlKiSN8uyzs hoKA== 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=vbdKltIhts0axs04YJ9CyEwqeT/nW8/5+MCqaVe0TFs=; b=RD1n1ZGKAN5LUN1djU8ZZIfMiGVqOli2lmDV2JWaQSE5BEliKNKM7MNFphj9WFeaNw 3mt/iVy8eNU7xzHEVeN+eDyLD555wQcj2htPXQIC7AyB/1Zm2JRyrT9tOM1eRiwR2/Zw 7SL+ThR992/RdoV8ThIVJQxFDLAiQX7oudShF4L2/04ws0etPPJYK0ZgYL6+02KtcUgw EcY04VES/t665ExbDYD+6iaI2LSFdwzQFxlHhVcSoT1mDHAy0wmXqhFdHgiY9/ipQEWZ xlmDPqa2BR/Ev1CGWYRA3IJkSOkrXchE0MTVeAY6yc80Rxdah6zJ3h/FzmJ5aGN6nmx6 rJgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hi2QVr3G; 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 w15si14031442edx.158.2021.02.23.06.24.56; Tue, 23 Feb 2021 06:25:22 -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=hi2QVr3G; 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 S232539AbhBWMzf (ORCPT + 99 others); Tue, 23 Feb 2021 07:55:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232519AbhBWMzb (ORCPT ); Tue, 23 Feb 2021 07:55:31 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FC01C061574 for ; Tue, 23 Feb 2021 04:54:51 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id v1so22464840wrd.6 for ; Tue, 23 Feb 2021 04:54:51 -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=vbdKltIhts0axs04YJ9CyEwqeT/nW8/5+MCqaVe0TFs=; b=hi2QVr3GmBlp8a2HbGiRh3SUPtZz5nr6+oD8MZzDNjFHEfWayB7cxB0mlc1jD+wj5V 3v4cO1xGluyMynbmjLCUSZBvsmeNG5yBZGJZOTWVs8iG+gydyCS9Ge6d1U95q/y7qKOw F0BYpY6lpM114H/vDqCKhJWMn6lBVX492HJ/HYvnN9S65dIW0GW1Zyv6oqmXC5QP28fr btx8vqeNm9RtXSYJzKkuseVk03ZM7lIq8bxs1A+UtKnYOA6tdErmpcFvhLorJfI6blNh uNfhp8lJN/WPTOMMmJJDxHc/lTx0NvQxkGcOXKte5gJy7x4dmy/hTBkplKtNEhJdPB+6 mqEA== 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=vbdKltIhts0axs04YJ9CyEwqeT/nW8/5+MCqaVe0TFs=; b=RE0uJkU91c2YuUd0wf67WWskjv0J5l21UOV50orGfhIIungws3wci9VfZ7FCLj30gc S+Mc6OzY/cWnX+HXPuaGheXBnfSg5x6xTq/lxJ60+lpalwp79UFVYNMlbV6Ho7sJ8BN6 a3N9Hphf6DlrS6/3iWKM8m9sNTt7R3myqfb6zpZEna3ysXQh8WjWhfAtAQFWxNcMVfNy 3EQPyDfig7H/qsBLYbNOA5R/e8CAJ2pT9iuk+hYdw4P05tpaSLXZxVasgPK3j99421f8 bKvgj17Pm8OiNiuwCEFdkgb2hR6H2Ql2is4JBS2qcflI7esA9Qb+qTH8T1WKwawBF3Zn Gwjw== X-Gm-Message-State: AOAM533jom9BfdDG3PXp4+nOTkCOf3+BZqVmsoneXegEOrFY7GKjQFEv N7uknuvTYCptREWxMoRDkZLROAnw6EPmri0A X-Received: by 2002:a5d:4842:: with SMTP id n2mr14699171wrs.181.1614084890338; Tue, 23 Feb 2021 04:54:50 -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 k1sm31919995wrx.77.2021.02.23.04.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Feb 2021 04:54:49 -0800 (PST) Date: Tue, 23 Feb 2021 12:54:47 +0000 From: Daniel Thompson To: Sumit Garg Cc: Doug Anderson , kgdb-bugreport@lists.sourceforge.net, Jason Wessel , Peter Zijlstra , stefan.saecherl@fau.de, qy15sije@cip.cs.fau.de, LKML Subject: Re: [PATCH] kernel: debug: Handle breakpoints in kernel .init.text section Message-ID: <20210223125447.7penkj42hd6ito4i@maple.lan> References: <1613721694-16418-1-git-send-email-sumit.garg@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 23, 2021 at 02:33:50PM +0530, Sumit Garg wrote: > Thanks Doug for your comments. > > On Tue, 23 Feb 2021 at 05:28, Doug Anderson wrote: > > > To be clear there is still a very small window between call to > > > free_initmem() and system_state = SYSTEM_RUNNING which can lead to > > > removal of freed .init.text section breakpoints but I think we can live > > > with that. > > > > I know kdb / kgdb tries to keep out of the way of the rest of the > > system and so there's a bias to just try to infer the state of the > > rest of the system, but this feels like a halfway solution when really > > a cleaner solution really wouldn't intrude much on the main kernel. > > It seems like it's at least worth asking if we can just add a call > > like kgdb_drop_init_breakpoints() into main.c. Then we don't have to > > try to guess the state... Just for the record, +1. This would be a better approach. > Sounds reasonable, will post RFC for this. I think we should call such > function as kgdb_free_init_mem() in similar way as: > - kprobe_free_init_mem() > - ftrace_free_init_mem() As is matching the names... > @@ -378,8 +382,13 @@ int dbg_deactivate_sw_breakpoints(void) > int i; > > for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { > - if (kgdb_break[i].state != BP_ACTIVE) > + if (kgdb_break[i].state < BP_ACTIVE_INIT) > + continue; > + if (system_state >= SYSTEM_RUNNING && > + kgdb_break[i].state == BP_ACTIVE_INIT) { > + kgdb_break[i].state = BP_UNDEFINED; > continue; > + } > error = kgdb_arch_remove_breakpoint(&kgdb_break[i]); > if (error) { > pr_info("BP remove failed: %lx\n", > > > > > > + kgdb_break[i].state = BP_ACTIVE; > > > + else > > > + kgdb_break[i].state = BP_ACTIVE_INIT; > > > > I don't really see what the "BP_ACTIVE_INIT" state gets you. Why not > > just leave it as "BP_ACTIVE" and put all the logic fully in > > dbg_deactivate_sw_breakpoints()? > > Please see my response above. > > [which was] > > "BP_ACTIVE_INIT" state is added specifically to handle this scenario > > as to keep track of breakpoints that actually belong to the .init.text > > section. And we should be able to again set breakpoints after free > > since below change in this patch would mark them as "BP_UNDEFINED": This answer does not say whether the BP_ACTIVE_INIT state needs to be per-breakpoint state or whether we can infer it from the global state. Changing the state of breakpoints in .init is a one-shot activity whether it is triggered explicitly (e.g. kgdb_free_init_mem) or implicitly (run the first time dbg_deactivate_sw_breakpoints is called with the system state >= running). As Doug has suggested it is quite possible to unify all the logic to handle .init within a single function by running that function when the state changes globally. Daniel.