Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7843483pxb; Fri, 19 Feb 2021 00:07:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZt1pafjnor1crZ02Pj7mZMT+2mFB59hzZGjeDOGkjMyegleqq5N/5xFWp5j05/XsFrQ2U X-Received: by 2002:a17:906:2991:: with SMTP id x17mr54627eje.367.1613722056887; Fri, 19 Feb 2021 00:07:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613722056; cv=none; d=google.com; s=arc-20160816; b=qv48mL2wQK28QtMfRJiPaVKVcX4OdGQWGbVuYQmvmhl1XKsWMTHpADFMyhMgXUYtSr CbeIB4SAda+nB2vuQFnwoWt8cdbK6QwTBtO6Qq2Wwnim417KZVLRtJ0FzRAPFMIeAsAb WnB6wHicrWk8LJHnNRJCNkbvc1x+5KzsGQV2lFV957CqBds+H58vx8f88wUIiqHDF8JK QYFRzueaJsYp4MSpiWvlkRKK37Apy/c0Y9DVc7eGciofXPuO6OQcf3aYC//ESUR72eqy Gn9ZVSKcc2ofJB99FdmMGpby7aDl57c4fUIHKXV16Oh87jzVhrdyPx56QdJZslx9oWz0 HubQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=MhXeuyvm8uTbmAfHrQDEaA0duTq/sCZgbklnifZ5wLY=; b=NthaAJzeThUhX9BEZ9vHulBep4HuazNyRRBZleHcIbjFbLGHVoyCd1BAmiUNFR46fZ eOQikfJcWaSnd1D3XJ+OHdEIm3SsN+6waYmheBptga/74MX10zM0MviWHaYNf/trL8bn ENk3Vr5BOQI398nvbzGVtRxuNIGITlhpj2K9C4D93xicPhTger8pnyRnKj+dQr78u5gg g5iBWBfoHka6JcxMf2IYdO9MNtM3oBJ+ZYOE0pAZ1nsZiGMa2EZXOp833zq2G0qp2Hsv 7SebssCjVzqyciIScVF6c0WDnxExLIcexjNJD5sRlLqoVti8IOnq97Bpi72TArIceWWC uBPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GFVxB4gP; 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 u8si5137757edv.94.2021.02.19.00.07.07; Fri, 19 Feb 2021 00:07:36 -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=GFVxB4gP; 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 S229708AbhBSIEW (ORCPT + 99 others); Fri, 19 Feb 2021 03:04:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbhBSIEA (ORCPT ); Fri, 19 Feb 2021 03:04:00 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8A2AC061756 for ; Fri, 19 Feb 2021 00:03:19 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id kr16so3253983pjb.2 for ; Fri, 19 Feb 2021 00:03:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=MhXeuyvm8uTbmAfHrQDEaA0duTq/sCZgbklnifZ5wLY=; b=GFVxB4gPy6Btk4zFDDPDn5D3LXG90FLWsBVtQwCmbJaiYdKyZIKqm6DQsLao47vdF8 1RpTVKi8igHur6XMuj7/FmWf2NygjffsaC6uDb9mXX0K7SHU/tARUkaKyyfcCQ1Eg4OC SCW1ZTgnyHZvqG90WZWkW0SAFKYSxAYzou8fY8wKeDYHoHL401TLk6laNtL/lTInUpkO nh8sW5ZEYzn8t+TGhV7RC43O4o8BSlsNH6wOiKZzrzDxfg2iIYiKvPBZVjkZEW0p1h38 Rf/qY2EUsJQG2CAuLNHrFpMS2qQYX52VL08RNwfLJSAxjK8V++MhrzeCrImrEqXrSs2v kfRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MhXeuyvm8uTbmAfHrQDEaA0duTq/sCZgbklnifZ5wLY=; b=EPLJ/O62/c+Zbs+4HzpkiEZhU20Oxit0msNBfKt6I0tdNrlWqZtlLmAS24dK0pgdtR 1vE/zPu29Rz/IdAB45PPwmDcM1Z0M6PO8h4j6Ro/3+Y9uNqCTv8TYUoKj3EEapOyB+vb PBKXxC/ePW0gzlxhhTEuxahxr+4Rfb4zoVLeOI+AryI9XuZoBizGoBpQFNXC94jgxb5u byuJ0LYgttfqD0YEnSQORKxA4ul16Z9VhxKYGyEIVi5YIyziFY8NdvR7XWgmWndmOdaC dTB3347+bQXR07J51UM+MDG/0zjG2hS1zESGvV6M5o6RP4AsSZlnF+NFtfnqlqNB1DMA mhqw== X-Gm-Message-State: AOAM531/1IpsytSKYbH1EeDBBwffdviXiGaQVnTx+Km6eTfKlYRWU9oT gP8eib381VF5ZPpismAp9RUclg== X-Received: by 2002:a17:90b:1a8b:: with SMTP id ng11mr8455843pjb.160.1613721799493; Fri, 19 Feb 2021 00:03:19 -0800 (PST) Received: from localhost.localdomain ([122.173.196.104]) by smtp.gmail.com with ESMTPSA id lj11sm7463845pjb.2.2021.02.19.00.03.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Feb 2021 00:03:18 -0800 (PST) From: Sumit Garg To: kgdb-bugreport@lists.sourceforge.net Cc: daniel.thompson@linaro.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, Sumit Garg Subject: [PATCH] kernel: debug: Handle breakpoints in kernel .init.text section Date: Fri, 19 Feb 2021 13:31:34 +0530 Message-Id: <1613721694-16418-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently breakpoints in kernel .init.text section are not handled correctly while allowing to remove them even after corresponding pages have been freed. In order to keep track of .init.text section breakpoints, add another breakpoint state as BP_ACTIVE_INIT and don't try to free these breakpoints once the system is in running state. 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. Suggested-by: Peter Zijlstra Signed-off-by: Sumit Garg --- include/linux/kgdb.h | 3 ++- kernel/debug/debug_core.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h index 0d6cf64..57b8885 100644 --- a/include/linux/kgdb.h +++ b/include/linux/kgdb.h @@ -71,7 +71,8 @@ enum kgdb_bpstate { BP_UNDEFINED = 0, BP_REMOVED, BP_SET, - BP_ACTIVE + BP_ACTIVE_INIT, + BP_ACTIVE, }; struct kgdb_bkpt { diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index af6e8b4f..229dd11 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -324,7 +324,11 @@ int dbg_activate_sw_breakpoints(void) } kgdb_flush_swbreak_addr(kgdb_break[i].bpt_addr); - kgdb_break[i].state = BP_ACTIVE; + if (system_state >= SYSTEM_RUNNING || + !init_section_contains((void *)kgdb_break[i].bpt_addr, 0)) + kgdb_break[i].state = BP_ACTIVE; + else + kgdb_break[i].state = BP_ACTIVE_INIT; } return ret; } @@ -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", @@ -425,7 +434,7 @@ int kgdb_has_hit_break(unsigned long addr) 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 && kgdb_break[i].bpt_addr == addr) return 1; } @@ -439,7 +448,7 @@ int dbg_remove_all_break(void) /* Clear memory breakpoints. */ for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { - if (kgdb_break[i].state != BP_ACTIVE) + if (kgdb_break[i].state < BP_ACTIVE_INIT) goto setundefined; error = kgdb_arch_remove_breakpoint(&kgdb_break[i]); if (error) -- 2.7.4