Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4310185ybz; Mon, 20 Apr 2020 20:53:06 -0700 (PDT) X-Google-Smtp-Source: APiQypJjKNNycnIHslhHC65ELEakCbeo2MU3pZfp2XejciKaKm5Zi1hrOACKZmYYRP6qjg0xHoMx X-Received: by 2002:a17:906:5e50:: with SMTP id b16mr19860892eju.331.1587441186536; Mon, 20 Apr 2020 20:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587441186; cv=none; d=google.com; s=arc-20160816; b=z20A53eAQ8IoLBq2pN4VOQwLrtGUwKqOeYkw1Zr79yCRd7MW+921LCVqJHh1YYFFen LcFFLsnrQqGbDnRAzAEdK1jVfcYqBxdW00wx2u+Xx7vYMElQNWv/1ZxGx5DG3vfjWRsV C3JBnSADGIiDrsPAAs5iN2FIhizMwM0OAqOXP6Aq+PSyFtRibKyllZqvCUJpJBaH4snG iqF7iplpd4NwlWqf2u0qGHJp0oWuElZtoRdTXO3aDlGDoozguAFBCOimY/eaonD7iT48 3VyfpDrWQ83zYmT5DXt2rerJoK7KQngFW/VdVGid0dDy8do4oXatRKq6ubrWjIoWRCU2 qmOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=jAl6zaKvi+5lW1/7o2BLtUtV7Gyv5Gw9FCFSeA0Ynj0=; b=Ort/s08qoIUUteXZXmB3YrfOp3Gs5gf8YuHKIdANswSPsB5qM0dF6+7GI2mNrxxVdN 4gstVFQfWW8g5CIhCFwKUBTmGOnJ1icOVJ5oQ6a2K8D6mi7ngd5Ljgo4eQTTYFFmymTS amTKvGGb0kBo1OXichmd1CvCpF+F6iQV2a11BH7GpKBtHLPOVGgEY9StWk1jreAi3St1 A6Li4hT+ZOFq0ciOH3bFLqzepOKpRtBeLhFEw4kM8b5vBMJn4LkvlymSmSv6Shpj58b8 kk8JUTYPouprK4t417XslRD1Q6ZGju98yDlRKKLMiBu7cRUpjbjpU9bxtG6009HlSgqy wTDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=MclvBTXX; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nj3si733672ejb.144.2020.04.20.20.52.43; Mon, 20 Apr 2020 20:53:06 -0700 (PDT) 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=fail header.i=@mg.codeaurora.org header.s=smtp header.b=MclvBTXX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728282AbgDUDtW (ORCPT + 99 others); Mon, 20 Apr 2020 23:49:22 -0400 Received: from mail26.static.mailgun.info ([104.130.122.26]:25861 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726793AbgDUDtW (ORCPT ); Mon, 20 Apr 2020 23:49:22 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1587440961; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=jAl6zaKvi+5lW1/7o2BLtUtV7Gyv5Gw9FCFSeA0Ynj0=; b=MclvBTXXSvrQdMjIMhDtSzcVut5AzRoGt2b6RivNfIl95hRUt49fMOFfJYnTqsHXv6Azt/Fp OqS42u+lKADFINVSnbwxlefIPMQ6fNHoGrDh9KXYBCPJvqy8A6gsIVJJuXae/TSclmOnz62H 8/JMCG2qa/LI7oyhKAzDffrzkkY= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e9e6d3a.7efc3f8a90d8-smtp-out-n04; Tue, 21 Apr 2020 03:49:14 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 83652C433BA; Tue, 21 Apr 2020 03:49:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: tingwei) by smtp.codeaurora.org (Postfix) with ESMTPSA id CF53FC432C2; Tue, 21 Apr 2020 03:49:11 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Tue, 21 Apr 2020 11:49:11 +0800 From: tingwei@codeaurora.org To: Will Deacon Cc: Mark Rutland , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: hw_breakpoint: don't clear debug registers in halt mode In-Reply-To: <20200331114502.GA29553@willie-the-truck> References: <20200328083209.21793-1-tingwei@codeaurora.org> <20200330123946.GH1309@C02TD0UTHF1T.local> <20200330134218.GB10633@willie-the-truck> <2f4d076b2b21de3908f0821126d0c61e@codeaurora.org> <20200331074147.GA25612@willie-the-truck> <518d9ca9652c23bfc0e1831306144418@codeaurora.org> <20200331114502.GA29553@willie-the-truck> Message-ID: <20b8c92a16db07978dfcb8cdf3b0e185@codeaurora.org> X-Sender: tingwei@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2020-03-31 19:45,Will Deacon 写道: > On Tue, Mar 31, 2020 at 07:33:38PM +0800, tingwei@codeaurora.org wrote: >> 在 2020-03-31 15:41,Will Deacon 写道: >> > On Tue, Mar 31, 2020 at 10:39:42AM +0800, tingwei@codeaurora.org wrote: >> > > 在 2020-03-30 21:42,Will Deacon 写道: >> > > > On Mon, Mar 30, 2020 at 01:39:46PM +0100, Mark Rutland wrote: >> > > > > On Sat, Mar 28, 2020 at 04:32:09PM +0800, Tingwei Zhang wrote: >> > > > > > If external debugger sets a breakpoint for one Kernel function >> > > > > > when device is in bootloader mode and loads Kernel, this >> > > > > > breakpoint >> > > > > > will be wiped out in hw_breakpoint_reset(). To fix this, check >> > > > > > MDSCR_EL1.HDE in hw_breakpoint_reset(). When MDSCR_EL1.HDE is >> > > > > > 0b1, halting debug is enabled. Don't reset debug registers in >> > > > > > this >> > > > case. >> > > > > >> > > > > I don't think this is sufficient, because the kernel can still >> > > > > subsequently mess with breakpoints, and the HW debugger might not >> > > > > be >> > > > > attached at this point in time anyhow. >> > > > > >> > > > > I reckon this should hang off the existing "nodebumon" command >> > > > > line >> > > > > option, and we shouldn't use HW breakpoints at all when that is >> > > > > passed. >> > > > > Then you can pass that to prevent the kernel stomping on the >> > > > > external >> > > > > debugger. >> > > > > >> > > > > Will, thoughts? >> > > > >> > > > I was going to suggest the same thing, although we will also need to >> > > > take >> > > > care to reset the registers if "nodebugmon" is toggled at runtime >> > > > via >> > > > the >> > > > "debug_enabled" file in debugfs. >> > > > >> > > Thanks for the suggestion, Mark and Will. It's a great idea to use >> > > "nodebugmon". When "nodebugmon" is set, Kernel won't change HW >> > > breakpoints. >> > > >> > > For reset the registers after "debug_enabled" is toggled, I'm >> > > thinking if >> > > we are adding unnecessary complexity here.If we take that approach, we >> > > will >> > > hook "debug_enabled" interface and use smp_call_function_single() to >> > > call >> > > hw_breakpoint_reset() on each CPU. Wait for all CPUs' execution done >> > > and >> > > change "debug_enabled". External debugger would clear the >> > > breakpoints when >> > > it detaches the device and restores its breakpoints when attaches the >> > > device. >> > > Assume debug_enabled is changed to one after external debugger >> > > detaches >> > > the >> > > device. Debugger would already clear the breakpoint registers. If >> > > debgger >> > > is >> > > still attached, there's nothing Kernel can do to stop it >> > > restores/programs >> > > the breakpoint registers. >> > > >> > > What do you think of this? >> > >> > It's all a bit of a mess. Looking at it some more, why can't the >> > external >> > debugger simply trap access to the debug registers using EDSCR.TDA? That >> > way, we don't have to change anything in the kernel. >> > >> >> External debugger has the function to trap access to debug registers >> now. >> What do we expect debugger to do after core is stopped? Skip that msr >> instruction and continue to run? > > The nicest thing to do would probably be to record all the accesses > made > by the OS so that it can emulate reads and replay writes when external > debugging is over. Given that you'd still be expecting to pass > "nodebugmon", > the emulation should be pretty straightforward, I think. > > Will Will, To provide an update on this, I've worked with external debugger vendor on this. Now external debugger can trap the write to debug registers and ignore the write. This is the first step. Thanks, Tingwei