Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp377466pxb; Wed, 24 Feb 2021 04:49:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYMqtLPp0tOOtDIJTks210E5Z5lyG+O4YR0DAWi+8Sndvr0zXiVYEKJgQqGj8TSEr5yktK X-Received: by 2002:a17:906:4acf:: with SMTP id u15mr28811654ejt.497.1614170945859; Wed, 24 Feb 2021 04:49:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614170945; cv=none; d=google.com; s=arc-20160816; b=GBgpXkJuC1hkS1Mn644wSWu5zu9r7whIxHKeorK0WDqujzAH9+MaeACU77u/W07gDJ H+uo2ju4MVUeg9oWHSqUaFg73aotFQ8Tp/QQtU6y7V1kyz/JzeDX9LxQBzHyGrRApL5a Jghq8ts8hUAbRT7mBGzdpIS3yz/yGLYLPY7PnEnEddjq8jj5WzbvfR3vdfeN5Xm6Xpcw BKOk1Yyx9gjKz2C8aEpVzu1A4zGhfD03iOrqmMsCzvAtd5kx+xxBam/geG8WGSKSwDOS bPKeIQaLaYMVUusXsZDUpO/ERXMr/nMTIfzJlWQvb8b2QEtKhIp/0PYAWwogr6r6NGjY T5Sw== 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=g/ihSCYjkGq0mVDgKW7XRfTj3HFK99zD03o5XQ3n2So=; b=X0+sfLTPx5wvbMECyfMfKTdm4BhZLckeQh0vmLDYCX6cjFHKNDR95oAwXl8RSvdBUJ MPWmBNH0hPPVgUqtjUhLMbqksIkDCIGEZMSMtXRS7aCU3K7fp2ExgQaUl60tJIJgQErJ QMP5Wiw0yWELhh/OJmc/oWqjUImF0yT2SFAeuh1gGXmFMLH+yU0xL+rmr/ILV4lQ8AO/ 1jSdz3s7gCVzEpf1vSZ6HRi0CFqB4MFSUImRG0zw/7KEAGaThT32oV4TRC8ZUZKvzWDg ALFu02Dt83JjvSOjhIulFoFHTWjMrySrgYC0rlH3YAGgPgzWYgKKpHUydnDO5Eosk7Bi XG8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OVVAlme8; 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 m19si1067512edr.329.2021.02.24.04.48.42; Wed, 24 Feb 2021 04:49:05 -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=OVVAlme8; 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 S233860AbhBXFaP (ORCPT + 99 others); Wed, 24 Feb 2021 00:30:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233105AbhBXFaO (ORCPT ); Wed, 24 Feb 2021 00:30:14 -0500 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30039C061574 for ; Tue, 23 Feb 2021 21:29:34 -0800 (PST) Received: by mail-lj1-x234.google.com with SMTP id v17so983018ljj.9 for ; Tue, 23 Feb 2021 21:29:34 -0800 (PST) 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=g/ihSCYjkGq0mVDgKW7XRfTj3HFK99zD03o5XQ3n2So=; b=OVVAlme8EN5RSBhZYiTwJnY7D3RqoRKvhT8/weafREU78rdsK2RV2qvpeU0De8lemE n3dyapfBvveZpqbutJnF5uA/el7Z0hs4Yarj4gR9am0EbYqgqLG6/i5c3iWFjXPPHn08 FbBe0KJKGXr3yMDoIRk4lXbnDsZc7oI4Mmcbgu5ZCaqFVmQSvHCWCsGseOKisFTYeog5 L/Q7ibaiyK0Cpojx87l8lqqlEuV+ux77D2Qrx/WkqKxADFX1QT8kIXzbNgt345u5zlL8 JhtXlUnLZtW+0UJk2o9LGuqIURvbpxdbB2I+EFJzaDpIyYMRJSQloJPlOL3Y3iEidBdi bLOA== 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=g/ihSCYjkGq0mVDgKW7XRfTj3HFK99zD03o5XQ3n2So=; b=bLbqFHWYcC6eeEh37Z17iydmYTKC3dqFjg8mgMg8hni2tG+ZTmZgaRtK2tPgxoSvSL HrGVYaMy0eWxI2S6S/cC28VCRwgD3s0Zze+hyVi5hPb6lEWDDpJdFnWUpIkU7nDbC2AA HeEy/iTT1iuM2V6q6kHN6bDLFsU8ODBoYicrmWpFPvkJD3+8U7fqU5vmb7r3apo8xYPe YkOSxsurswHSl0YOz+A3Xqjum4D6XSawXLEz2GdSpAK0PB8e5eLqCCek0D3a0lzcKBbt o9ZDSPrIbwvl7EfPOnT9QFNSibONELUvC2ZDQc2C9nQU+zg5QOLIjOogxOkdys0vnv0D dRIQ== X-Gm-Message-State: AOAM533vHIm37V3+jgtudHHMYoAZSxWnM/aUhrtQs4ZXKO/mdKWs2ce5 gkysoLOI+3UtmM+TXRPP08zgE4I9qu42EU927jFFcRaZ5Jxd2A== X-Received: by 2002:a2e:99cb:: with SMTP id l11mr9838399ljj.343.1614144572582; Tue, 23 Feb 2021 21:29:32 -0800 (PST) MIME-Version: 1.0 References: <1613721694-16418-1-git-send-email-sumit.garg@linaro.org> <20210223125447.7penkj42hd6ito4i@maple.lan> In-Reply-To: <20210223125447.7penkj42hd6ito4i@maple.lan> From: Sumit Garg Date: Wed, 24 Feb 2021 10:59:20 +0530 Message-ID: Subject: Re: [PATCH] kernel: debug: Handle breakpoints in kernel .init.text section To: Daniel Thompson Cc: Doug Anderson , kgdb-bugreport@lists.sourceforge.net, Jason Wessel , Peter Zijlstra , stefan.saecherl@fau.de, qy15sije@cip.cs.fau.de, LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 23 Feb 2021 at 18:24, Daniel Thompson wrote: > > 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. > Ah, I see. Thanks for further clarification. Will get rid of BP_ACTIVE_INIT state. -Sumit > > Daniel.