From patchwork Mon Oct 26 17:29:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 11857925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFBECC4363A for ; Mon, 26 Oct 2020 17:34:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 63EA221D42 for ; Mon, 26 Oct 2020 17:34:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="obEGU0nl"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="acjUNJUb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63EA221D42 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=WAXJPqwkv2kDlfxJabCdLTSmlLr7GgdtjMmKYed4zV4=; b=obEGU0nlcHBF0S/VZZqZaYHDuW YhzsfacbKCVmRWy7/E1yvi1o5yzGMQzgEfXBiSN8Rahtgx+btcyWuL8bdJ6AJNAPBPkH2s53rH1fj liqukTh0bNnaaknW3M7b6OrKcS7Q7WQ9OepaMBagkLXuaNr8mKb8art+Kib+GqakjlF9cxBdIKf+h A/l3xrE9QPCYR9b0Ajak78xt6GH4nsuk8yzicLRF7Hc3I89ZHLTDlZK/I8g3TY3i5Pa2G5Rs1Gr2u 9IT7V9Ye9G4oc7DaMVnbE04NGeYLsnr4F1RMUNzF69dcjdYZgV2zU0JcYnttf7We/+OwNHbWXlEXc pNh7icNg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kX6MZ-0003j4-0s; Mon, 26 Oct 2020 17:32:55 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kX6MW-0003id-R7 for linux-arm-kernel@lists.infradead.org; Mon, 26 Oct 2020 17:32:54 +0000 Received: by mail-ed1-x541.google.com with SMTP id l16so10300905eds.3 for ; Mon, 26 Oct 2020 10:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/8kVgnldmsVxlBtDPCP0MKJft+6jfqkkKHrhusxpgRI=; b=acjUNJUb5QNuLw79jeNUfUfo0FMNc0x3ykAI0BhUSIWyM2OIfYzLwE6x7A/DayJwBA DDw7a1RD2JpXX/PbIBCm1D0+9+BrjEluWQCY5bu5tc2rLyjj8k/NYuCMSawbbl/J2zoz s8FSBtBvzFPhYOScgJrkuMoC+RI9Fp6k5c9e/3r/nlrySSwH3qFDjAmp+chXk3ERN7QU F7UfvZYNgNaWOsHv/4G2eoH8EYvtUgBzrlqGztkBzZ5kIjnGJHMvdwt8sUuV+hwszuyN waKCaFzlx/xeL2SvsxQhZszEdiopXuWsD87kyKkhrycMAKFu+FqSBUa9Rt9+DRGav5dP kzqA== 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:mime-version :content-transfer-encoding; bh=/8kVgnldmsVxlBtDPCP0MKJft+6jfqkkKHrhusxpgRI=; b=ieYAK2AHHloeU60+IjSuUm8uHMFY+v0YZ6eQLVyiLGMCQqeyH1AwuoMEosTUUt2+oM DLVpoE+nY2HnY7E4MzOPrauHQz+ScthdDtV6DBZ2KeVXVEYGraOM9oxdOsqozXyPHiq1 m5qowzrS7+qm85PtcK9LKI6gKILoBdgYyV/OjcuR129Vay0+2FkVGvi0jj4Q0IDwV6qc htknTQaxmYOluuJY+eJ2WEpbcqnGPmaoGu3GsYyY5UHKfUyvEjbTqvyM5nf4llBuQAvs uDrOpg9pJl7WxaLbgb5LdorORy/8MFckzW4v1rtzqXcNWiBoB0sS57LdQSsaExYlJ8m3 sI2g== X-Gm-Message-State: AOAM530Q1Wd9hseLWL9s0aWMo594jtWFU84LPHFmVBxYR7LRByYOT7ex 5jZJxjSa/Wp1RR1IKBiKK+4wbQ== X-Google-Smtp-Source: ABdhPJzFoFRMKP8Glvq5NItEI550ZaPfjvUIkWosEnKab3Xh0fLDDlorU+u8dWMejRuDIfOjwwfyZw== X-Received: by 2002:a05:6402:1d13:: with SMTP id dg19mr17342715edb.217.1603733569405; Mon, 26 Oct 2020 10:32:49 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id r24sm5519044eds.67.2020.10.26.10.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 10:32:48 -0700 (PDT) From: Jean-Philippe Brucker To: catalin.marinas@arm.com, will@kernel.org Subject: [PATCH] arm64: Fix early single-stepping Date: Mon, 26 Oct 2020 18:29:09 +0100 Message-Id: <20201026172907.1468294-1-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201026_133253_167360_D10EFE0B X-CRM114-Status: GOOD ( 14.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , dianders@chromium.org, linux-arm-kernel@lists.infradead.org, mhiramat@kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org To use debug features such as single-step, the OS lock must be unlocked in the debug registers. Currently this is done in postcore_initcall which is now too late. Commit 36dadef23fcc ("kprobes: Init kprobes in early_initcall") enabled using kprobes from early_initcall, when OS lock is still locked. So when kprobe attempts to single-step a patched instruction, instead of trapping, execution continues until it throws an undef exception: [ 0.064233] Kprobe smoke test: started [ 0.151133] ------------[ cut here ]------------ [ 0.151458] kernel BUG at arch/arm64/kernel/traps.c:406! [ 0.151812] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ... [ 0.162689] Call trace: [ 0.163014] do_undefinstr+0x1d4/0x1f4 [ 0.163336] el1_sync_handler+0xbc/0x140 [ 0.163839] el1_sync+0x80/0x100 [ 0.164154] 0xffffffc01001d004 [ 0.164527] init_kprobes+0x13c/0x154 [ 0.164968] do_one_initcall+0x54/0x2e0 [ 0.165322] kernel_init_freeable+0xf4/0x258 [ 0.165783] kernel_init+0x20/0x12c [ 0.166117] ret_from_fork+0x10/0x30 [ 0.166595] Code: 97ffff53 a9425bf5 17ffff9b f9001bf7 (d4210000) [ 0.167084] ---[ end trace 36778fdf576e9a79 ]--- To fix this, unlock the OS lock as early as possible. Do it in traps_init() for CPU0, since KGDB wants to use single-step from that point on according to commit b322c65f8ca3 ("arm64: Call debug_traps_init() from trap_init() to help early kgdb"). For secondary CPUs, setup the CPU hotplug handler at early_initcall. Fixes: 36dadef23fcc ("kprobes: Init kprobes in early_initcall") Signed-off-by: Jean-Philippe Brucker Reviewed-by: Masami Hiramatsu Tested-by: Masami Hiramatsu --- arch/arm64/kernel/debug-monitors.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c index 75a423c3336a..80f082021234 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -135,7 +135,7 @@ static int __init debug_monitors_init(void) "arm64/debug_monitors:starting", clear_os_lock, NULL); } -postcore_initcall(debug_monitors_init); +early_initcall(debug_monitors_init); /* * Single step API and exception handling. @@ -380,6 +380,7 @@ NOKPROBE_SYMBOL(aarch32_break_handler); void __init debug_traps_init(void) { + clear_os_lock(0); hook_debug_fault_code(DBG_ESR_EVT_HWSS, single_step_handler, SIGTRAP, TRAP_TRACE, "single-step handler"); hook_debug_fault_code(DBG_ESR_EVT_BRK, brk_handler, SIGTRAP,