From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 ABB60C56202 for ; Wed, 25 Nov 2020 16:10:34 +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 248C8207BC for ; Wed, 25 Nov 2020 16:10:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="m6mOC6DS"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="asxI4TIX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 248C8207BC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.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:References:In-Reply-To:Message-Id: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TMYUU8/mhkpRG1rxg99TiU3jyFe2y94LlbiaaMAQtUI=; b=m6mOC6DSb/tpz0L9kucVl4h7K HbupdNwWCUdX2WaQyJu4qHihEHr/pK3rwq8KTCLNtOrvmbMo56y/4egot7ijm5Fmei8I/0nvxHKHM bFqZCChs7+jek8g5rHpUtOTPuc/y9XVUr2Ty/Jv2CYb2nQKwluWXG0hnzFNQ7OehvGrCRD2fnBzt8 mvOqmMW/Bru/RA5N8zAUfdLSZWz7smKzLEtrk5JAAlzDusQT4dQypZT/4u/Zrg1n8Ua5gpjeNoBr/ ObP0W92WjCxPHNLwVYa0lh/xMGCKdoRGye0X0AJnquohxLY16TIwOgUVJgjmvdrwcVrJ2Js/5hyJz SbUwYC9Ow==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khxM2-00070x-Iy; Wed, 25 Nov 2020 16:09:14 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khxM0-00070J-1t for linux-arm-kernel@lists.infradead.org; Wed, 25 Nov 2020 16:09:13 +0000 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 21F29206F7; Wed, 25 Nov 2020 16:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606320550; bh=xpkI6LpHrLiS62QEivgXMyvg/0xYoWFot0s0dB+Tm80=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=asxI4TIXifUqgSWa8hcRH6m2v5iz7vbmdUP5Yrnf3onixU8sn6TFidLt0Sq3dn27o jVAa//hTW/fz9MvvhHwYmco2kpHc7D8rC6CiPvHnb4J5i587RSBVuOmBMQ5OP9IZRl cwNi6M3F1XYIe6Ye1/nVW3xpr051oC/niR4a1PIg= Date: Thu, 26 Nov 2020 01:09:06 +0900 From: Masami Hiramatsu To: Will Deacon Subject: Re: [PATCH] arm64: Fix early single-stepping Message-Id: <20201126010906.dd56ca668e30de6be9380028@kernel.org> In-Reply-To: <20201028083643.GA27678@willie-the-truck> References: <20201026172907.1468294-1-jean-philippe@linaro.org> <20201027191318.aba935f7ccf00af9acd89388@kernel.org> <20201027194258.43b157ac0bbccd918fc8756a@kernel.org> <20201027115909.GB1514990@myrica> <20201027123317.GA26351@willie-the-truck> <20201027224922.7b032857d53bbfdc4484f768@kernel.org> <20201028082820.GA2328726@myrica> <20201028083643.GA27678@willie-the-truck> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201125_110912_267847_64C15356 X-CRM114-Status: GOOD ( 38.94 ) 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 , catalin.marinas@arm.com, dianders@chromium.org, Steven Rostedt , Masami Hiramatsu , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Will, On Wed, 28 Oct 2020 08:36:44 +0000 Will Deacon wrote: > On Wed, Oct 28, 2020 at 09:28:20AM +0100, Jean-Philippe Brucker wrote: > > On Tue, Oct 27, 2020 at 10:49:22PM +0900, Masami Hiramatsu wrote: > > > On Tue, 27 Oct 2020 12:33:18 +0000 > > > Will Deacon wrote: > > > > > > > On Tue, Oct 27, 2020 at 12:59:09PM +0100, Jean-Philippe Brucker wrote: > > > > > On Tue, Oct 27, 2020 at 07:42:58PM +0900, Masami Hiramatsu wrote: > > > > > > On Tue, 27 Oct 2020 19:13:18 +0900 > > > > > > Masami Hiramatsu wrote: > > > > > > > > > > > > > On Mon, 26 Oct 2020 18:29:09 +0100 > > > > > > > Jean-Philippe Brucker wrote: > > > > > > > > > > > > > > > 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 > > > > > > > > > > > > > > Hi Jean, > > > > > > > > > > > > > > How have you confirmed this fixes the issue? > > > > > > > On my environment, this doesn't fix the issue. > > > > > > > > > > > > Oops, it was my mistake. I missed to boot up with Xen. (so I find another bug...) > > > > > > Anyway this works for me too. > > > > > > > > > > No worries :) Although now I've been wondering whether it would be better > > > > > to just disable the OS lock lazily, on the first call to > > > > > enable_debug_monitors(). It might add a tiny performance penalty but would > > > > > avoid this problem reappearing if one of the debugger needs to start even > > > > > earlier in the future. > > > > > > > > I'm still uneasy about enabling KDE with the watchpoint registers in an > > > > unknown state, so I think this needs more work. > > > > > > Hmm, how we reset it in the early stage? reset watchpoint registers first? > > > > Yes, I think so. Same order problem as the OS lock, they need to be reset > > before enable_debug_monitors(). On CPU0 that would be before > > early_initcall and for secondaries the hotplug notifier needs to be > > installed earlier as well. I'll send a v2. > > Cheers. An alternative (which I think would be better in the long run > anyway) would be to avoid using hardware step in kprobes and instead rely > on a BRK instruction to trap after running the trampoline. We started working on using the BRK instead of hardware step in kprobes in other threads. However, there still be a bug in the kernel. I would like to fix or at least mitigate this issue until this is released (since it's a bug) Would you think we can push the BRK only kprobes until it or in stable kernel? Or, we should add a mitigation patch for this bug? For the mitigation, I think we can introduce a kconfig flag which indicates the arch doesn't support early kprobes, in that case we defer the kprobe and boot-time trace later stage. This flag will be removed after we introduce the BRK-only kprobes. Thank you, -- Masami Hiramatsu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel