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=-10.7 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 autolearn=unavailable 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 BF59AC433DF for ; Thu, 27 Aug 2020 18:14:48 +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 8CB5E22B4B for ; Thu, 27 Aug 2020 18:14:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fN/7zG3x"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jN9Jy05o" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CB5E22B4B 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: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=w7x8KH+BjNxv+y0SoqGuf59O1uEQFqyJt4gvmITDUOQ=; b=fN/7zG3xEaN/QIIuMppycpleh t4DzwhvSMPeBYaZHgpYRD/pvWEeXehr/f6HAvLd4wqcNV5Hv/T8tk9KkF+y4wlyom+z7zjvpARRcU Ow85Su8bt0MT6/aOnD6X0+hfZDJqMUH+MfGyL7Fy0a5jvtsP3vWhCkkQ3AvOoX3xMPlJuDi/UDHtS HGVCH4AQ7qNbzXkPLwlghrVybZhnP1IT9ThfQXQc8m7v9mgdTnGAcPUFdOTxqLF9vS+WKM6oWuFqH T6/hzPLZsmcsISiOcf0DTLV8WQLRHGzh+UFJOq10cUU7gpRA7DQh/sGppShyy9Fq2cQpQSvqzQ8T+ OySitLHTw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBMOV-0005NZ-0z; Thu, 27 Aug 2020 18:13:03 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBMOS-0005Mx-2H for linux-arm-kernel@lists.infradead.org; Thu, 27 Aug 2020 18:13:01 +0000 Received: by mail-pg1-x544.google.com with SMTP id o13so3944268pgf.0 for ; Thu, 27 Aug 2020 11:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fuSolVX8LC0jNf2qxLZlltK9x50zFghAwQwSG3ActBE=; b=jN9Jy05oArX3fILCpW2YF5bax0+prmwFcTaiTGl3kfL6GLn0ogGB5uN/as6dxdux2R eTM8MVBzJsrtp2jpT3HPVXETSxCTXN5BwlZ3IZ0I1/7f3u0BRuIz3piQxIXgVmUtFddt SNXBbJS5KUpPY2LyxzGTgNtlVdmaZgjdyOXuXZcvj1q927cUKSkis1lsyJ91E4q3KmQJ pd6LW8kx9SU9c5hA6Cbpydo2m51wg/+n2/vduAXNy3w6VKVcGB0rae7ECka+TL/G03CD cPRvoSmjese8NEvcaYViHzgZTBnIY+yPrVnTvTIL0YM9wCEsjnTlonwQv4hYkrWxdP1R 6RoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fuSolVX8LC0jNf2qxLZlltK9x50zFghAwQwSG3ActBE=; b=qW7jp/PRmlCurYB1g2nB0s5FmQ4tqw6pttZ/ZxXmh7YDEw0+kXW8Gvjrg0ApRU8fU9 LM4eJxLijTVjcQFKpoAssJ0cqZVPIKB4bytxPRWhCF/v+0unZ40IiblSsCcY06fzhsB/ KbX12kpjQnVaXa4ydB3EXDQUctqqSG4zyMqfYvMgctg9JjaiKM0OLFV8Wfoy12JDvI/I rsZrX3CIgsyOa69Pg8WNAQRZMJIrjcsTGd7/zlDrLNGnnOpVQoosGz88k682QIW7SiJp 5m90b8hoqRnqhXrdjH5khzvxszfHMN437DbffSSA//UP8P1fA+8C8+/UtatFm0BMjXfg OgAw== X-Gm-Message-State: AOAM530VrE3EO3r1bHanhpKc4Y182XGsqCQFCIBgOJ5vK3GwEiNeKGYw OFw/6VXS/cqE+edUV5BeUmPxew== X-Google-Smtp-Source: ABdhPJyK3jeEl5e2q3GRKnl/94jGpsxoReBVWtVdwZ5LhZzKVkT3aB6f6DazSXG/QVS8TwHN0xY2uw== X-Received: by 2002:a17:902:aa4c:: with SMTP id c12mr10625344plr.37.1598551976043; Thu, 27 Aug 2020 11:12:56 -0700 (PDT) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j1sm2587382pgp.93.2020.08.27.11.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 11:12:55 -0700 (PDT) Date: Thu, 27 Aug 2020 12:12:53 -0600 From: Mathieu Poirier To: Tingwei Zhang Subject: Re: [PATCH] coresight: cti: write regsiters directly in cti_enable_hw() Message-ID: <20200827181253.GA22307@xps15> References: <20200818111057.19755-1-tingwei@codeaurora.org> <20200818111057.19755-3-tingwei@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200818111057.19755-3-tingwei@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200827_141300_162736_32DA8216 X-CRM114-Status: GOOD ( 27.16 ) 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: tsoni@codeaurora.org, Sai Prakash Ranjan , Suzuki K Poulose , Alexander Shishkin , Greg Kroah-Hartman , coresight@lists.linaro.org, Mao Jinlong , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mike Leach 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 Tingwei, On Tue, Aug 18, 2020 at 07:10:57PM +0800, Tingwei Zhang wrote: > Deadlock as below is triggered by one CPU holds drvdata->spinlock > and calls cti_enable_hw(). Smp_call_function_single() is called > in cti_enable_hw() and tries to let another CPU write CTI registers. > That CPU is trying to get drvdata->spinlock in cti_cpu_pm_notify() > and doesn't response to IPI from smp_call_function_single(). > > [ 988.335937] CPU: 6 PID: 10258 Comm: sh Tainted: G W L > 5.8.0-rc6-mainline-16783-gc38daa79b26b-dirty #1 > [ 988.346364] Hardware name: Thundercomm Dragonboard 845c (DT) > [ 988.352073] pstate: 20400005 (nzCv daif +PAN -UAO BTYPE=--) > [ 988.357689] pc : smp_call_function_single+0x158/0x1b8 > [ 988.362782] lr : smp_call_function_single+0x124/0x1b8 > ... > [ 988.451638] Call trace: > [ 988.454119] smp_call_function_single+0x158/0x1b8 > [ 988.458866] cti_enable+0xb4/0xf8 [coresight_cti] > [ 988.463618] coresight_control_assoc_ectdev+0x6c/0x128 [coresight] > [ 988.469855] coresight_enable+0x1f0/0x364 [coresight] > [ 988.474957] enable_source_store+0x5c/0x9c [coresight] > [ 988.480140] dev_attr_store+0x14/0x28 > [ 988.483839] sysfs_kf_write+0x38/0x4c > [ 988.487532] kernfs_fop_write+0x1c0/0x2b0 > [ 988.491585] vfs_write+0xfc/0x300 > [ 988.494931] ksys_write+0x78/0xe0 > [ 988.498283] __arm64_sys_write+0x18/0x20 > [ 988.502240] el0_svc_common+0x98/0x160 > [ 988.506024] do_el0_svc+0x78/0x80 > [ 988.509377] el0_sync_handler+0xd4/0x270 > [ 988.513337] el0_sync+0x164/0x180 > Was this the full log or you did cut some of it? > This change write CTI registers directly in cti_enable_hw(). > Config->hw_powered has been checked to be true with spinlock holded. > CTI is powered and can be programmed until spinlock is released. > >From your explanation above it seems that cti_enable_hw() was called from, say CPUy, to enable the CTI associated to CPUx. CTIx's drvdata->spinlock was taken and smp_call_function_single() called right after. That woke up CPUx and cti_cpu_pm_notify() was executed on CPUx in interrupt context, trying to take CTIx's drvdata->spinlock. That hung CPUx and the kernel got angry. Is my assessment correct? If so I don't think the fix suggested in this patch will work. The same condition will happen whenever cti_enable_hw() is called on a CPU to enable a CTI that belongs to another CPU and that cti_cpu_pm_notify() is called on latter CPU at the same time. I think a better solution is to grab the lock in cti_enable_hw() and check the value of ->ctidev.cpu. If not a global CPU, i.e >= 0, then release the lock and call smp_call_function_single(). In cti_enable_hw_smp_call() take the lock again and move forward from there. I have applied the other two patches in this set so no need to send them again. Thanks, Mathieu > Fixes: 6a0953ce7de9 ("coresight: cti: Add CPU idle pm notifer to CTI devices") > Signed-off-by: Tingwei Zhang > --- > drivers/hwtracing/coresight/coresight-cti.c | 17 +---------------- > 1 file changed, 1 insertion(+), 16 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c > index 3ccc703dc940..869569eb8c7f 100644 > --- a/drivers/hwtracing/coresight/coresight-cti.c > +++ b/drivers/hwtracing/coresight/coresight-cti.c > @@ -86,13 +86,6 @@ void cti_write_all_hw_regs(struct cti_drvdata *drvdata) > CS_LOCK(drvdata->base); > } > > -static void cti_enable_hw_smp_call(void *info) > -{ > - struct cti_drvdata *drvdata = info; > - > - cti_write_all_hw_regs(drvdata); > -} > - > /* write regs to hardware and enable */ > static int cti_enable_hw(struct cti_drvdata *drvdata) > { > @@ -112,15 +105,7 @@ static int cti_enable_hw(struct cti_drvdata *drvdata) > if (rc) > goto cti_err_not_enabled; > > - if (drvdata->ctidev.cpu >= 0) { > - rc = smp_call_function_single(drvdata->ctidev.cpu, > - cti_enable_hw_smp_call, > - drvdata, 1); > - if (rc) > - goto cti_err_not_enabled; > - } else { > - cti_write_all_hw_regs(drvdata); > - } > + cti_write_all_hw_regs(drvdata); > > config->hw_enabled = true; > atomic_inc(&drvdata->config.enable_req_count); > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel