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=-4.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 5DC74C433E0 for ; Mon, 11 Jan 2021 11:45:25 +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 B8B0F22510 for ; Mon, 11 Jan 2021 11:45:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8B0F22510 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com 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:In-Reply-To:MIME-Version:References: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=Duz/kdy+tmAUhaxsnE3V5uTrEKEgk0ZCiSbT8gPsh0Y=; b=UTEg0uly3TemL1WL0ZTxcsvFr oaLsQ6T46Koh6qQAH9GFuSL5Eg5Mz2yrG2zFJxkAXTzyGzoC1W4KOit/ryo5j7XPcsEDmlJR/p4pn 0VsVmwHyP8iOUSxIBomPGfS+gAydksFEY+nLwt5b2xhnvOPMyfcNA6QeHPULCQUi01CJs4/3pb1Lw XSfaHfUQKp6Gt6oRxxgJbAGdYZi/Vx22sERvHQfx2xJnF+Tu8NuIUAWkEbLnhgLwpvktE6EZocQ8T mZ0uAqqlbWAQR1qjyZUpnFPhNT9pHNOpbQl0/GOGXEw4yGaV3ObY6vQINWvgbIah8atmsorPVZcPH bxttLm3AA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyvcJ-0003tn-9V; Mon, 11 Jan 2021 11:44:11 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyvcE-0003rG-Dh for linux-arm-kernel@lists.infradead.org; Mon, 11 Jan 2021 11:44:07 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5236831B; Mon, 11 Jan 2021 03:44:04 -0800 (PST) Received: from C02TD0UTHF1T.local (unknown [10.57.41.172]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D73303F719; Mon, 11 Jan 2021 03:44:02 -0800 (PST) Date: Mon, 11 Jan 2021 11:44:00 +0000 From: Mark Rutland To: Tingwei Zhang Subject: Re: Set DBGCLAIM when self-host debug is enabled Message-ID: <20210111114400.GB49295@C02TD0UTHF1T.local> References: <512a30e6cc6877687c10c0f9ccc3c4c5@codeaurora.org> <20210106122356.GC26994@C02TD0UTHF1T.local> <20210108040055.GA11529@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210108040055.GA11529@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210111_064406_627179_60A4BF3B X-CRM114-Status: GOOD ( 30.84 ) 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: Will Deacon , linux-arm-kernel@lists.infradead.org, tingwei@codeaurora.org, linux-kernel@vger.kernel.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 On Fri, Jan 08, 2021 at 12:00:55PM +0800, Tingwei Zhang wrote: > On Wed, Jan 06, 2021 at 08:23:56PM +0800, Mark Rutland wrote: > > On Wed, Jan 06, 2021 at 06:29:53PM +0800, tingwei@codeaurora.org wrote: > > > Hi Will and Mark, > > > > Hi Tingwei, > > > > > In recent implementation of save/restore ARM debug registers in > > > EL2/EL3, we found it's necessary to know whether self-host debug is > > > enabled so EL2/EL3 can avoid saving/restoring debug registers but no > > > one is using debug. > > > > In what situation are you considering? I assume you mean idle sequences > > using CPU_SUSPEND? > > > > Generally our expectation for CPU_SUSPEND is: > > > > * Where StateType==0, the debug state is preserved with all other > > PE state. > > > > * Where StateType==1 and the PE returns "warm" without having entered a > > powerdown state, the debug state is preserved along with all other PE > > state. > > > > * Where StateType==1, and the PE returns "cold" after having entered a > > powerdown state (i.e. we return via the entry point address), the > > debug state is not preserved. > > > > ... and I'm missing where you could avoid saving the state. What > > situation(s) did you have in mind? > > > In StateType==1 case, EL2/EL3 can save debug registers before PE suspend > and restore them after PE resume. If EL2/EL3 doesn't know whether external > debugger or self-host debugger is using debug registers, it can save and > restore bindly everytime. However, if EL2/EL3 can get the information from > DBGCLAIM, it can only save/restore debug registers when debug is ongoing > which means DGBCLAIM[0] is set by external debugger or DGBCLAIM[1] is set > by self-host debugger. I think I'm missing something here. Are you tring to enable self-hosted debug over powerdown events, or are you trying to optimize the save/restore of debug state? Linux doesn't support self-hosted debug over powerdown events, since we lose context anyway, and we need to get through a reasonable portion of setup code before it's safe to take debug exceptions again. Linux saves and restores the debug state in this case (e.g. we call hw_breakpoint_restore(cpu) in __cpu_suspend_exit()). So AFAICT, Linux never needs to set DBGCLAIM[1]. For "cold" returns we already have the relevant save/restore in Linux, and for "warm" returns the debug state must be preserved by the firmware. > > I was under the impression that this was solely for the benefit of an > > external debugger, and should have no functional impact on the PSCI > > implementation from the kernel's PoV, so as above I think we need a > > better description of the case you're trying to address. > > If self-host debugger like gdb/kgdb is used for debug, Kernel can set > DBGCLAIM[1] to inform EL2/EL3. I think there's additional complexity there. KGDB relies on other CPU state (e.g. MMU, VBARs, TPIDRs, SP_EL0, DAIF.D) being configured, so there will always be a blackout period over a power-down events where this is restored. The kernel itself can save/restore the debug state during this blackout period. What benefit do you see there being if FW saves/restores this? I'm very concerned that there are FW implementations out there which do not save/restore when DBGCLAIM[1] is set, and the spec isn't entirely clear as to what "debug context" consists of, so I suspect we don't have reliable behaviour in this area. Thanks, Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel