Received: by 10.223.185.116 with SMTP id b49csp3570425wrg; Mon, 19 Feb 2018 02:14:07 -0800 (PST) X-Google-Smtp-Source: AH8x227WVqslD74KJhAyOCAYOjZkLx2Sboela2KnhhClQ5lBapmSk1Op5EBOcf/Wko1n39i9FdwU X-Received: by 10.99.116.18 with SMTP id p18mr11773039pgc.77.1519035247336; Mon, 19 Feb 2018 02:14:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519035247; cv=none; d=google.com; s=arc-20160816; b=GHFHGlOkcvHdQZ+C4Lk2he1aftQX1N8G38B1Rqw9BhnBXMJyhXvtd1FsXWtMHNMF9c pVM0O4/9cFKbgmglh76FatkFh7luhgrvzeNkwXY3FYj0u6AhK+12/xLU+LmAoPRPV9Jz hH9N1Yf6iU2s8khXvtTTu5btOjBf36eSozXAKXJoyUWmretm+9t15PzS9wx+2hZTVu7i dD/jVP5IakcEgitUqbt1b6uaQ3eb3h8uebHE/1K+Ehhn4x7Uzw4Y9LRt0+pVeivFqzY5 7BSjutJSiDld06DCUNczww5G03LF1O0au7mzPkX3iXii2+1feDiVEBx+MpVyQ/v/F54o +qJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=NwcOINqa+KNht9bM3QDUX/rCembXt6Q8M+nwoP/kwCE=; b=DCcpz4qhA7zErPBQ3aS1uSA7QmUSBRh/btJVx0kUNVvVDOp/863nQ+Xg0a7wGBsuRa v7hO0B8WRYQiqDhwVB6QqgEtVAjmD3XZ6C5OFuIvi/OBKkJnm1vI+N1JagUyVSdqlstE jrFE5xenGFiQzeZ0ZCyhNkPEgQkxWHkHoF3M8i1KtxkBmR508v5/xNJodP5ZYmR2qrqx LwtVbWwmpnQa7DWTBnNx1mVE9+HkbvZoEmiU1GkAm0yV/LxsoHd7JTSjFAa4I0Pw4r6D /ZRBIimcq1fl+372kUyse/uwO9Md8+coMba6Igy+kMYeDnvRgGwa0dTz6oR4O/TQPn46 gDsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t199si5011325pgb.105.2018.02.19.02.13.52; Mon, 19 Feb 2018 02:14:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752309AbeBSKNO (ORCPT + 99 others); Mon, 19 Feb 2018 05:13:14 -0500 Received: from 9pmail.ess.barracuda.com ([64.235.150.224]:51418 "EHLO 9pmail.ess.barracuda.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752219AbeBSKNN (ORCPT ); Mon, 19 Feb 2018 05:13:13 -0500 Received: from MIPSMAIL01.mipstec.com (mailrelay.mips.com [12.201.5.28]) by mx4.ess.sfj.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Mon, 19 Feb 2018 10:12:55 +0000 Received: from mredfearn-linux.mipstec.com (10.150.130.83) by MIPSMAIL01.mipstec.com (10.20.43.31) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 19 Feb 2018 02:11:43 -0800 From: Matt Redfearn To: James Hogan , Ralf Baechle CC: , Paul Burton , Ed Blake , Matt Redfearn , "Bryan O'Donoghue" , Dengcheng Zhu , , Mark Rutland Subject: [PATCH v2] MIPS: pm-cps: Block system suspend when a JTAG probe is present Date: Mon, 19 Feb 2018 10:11:09 +0000 Message-ID: <1519035069-31012-1-git-send-email-matt.redfearn@mips.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518706759-9890-1-git-send-email-matt.redfearn@mips.com> References: <1518706759-9890-1-git-send-email-matt.redfearn@mips.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.150.130.83] X-BESS-ID: 1519035173-298555-1632-143268-11 X-BESS-VER: 2018.2-r1802152108 X-BESS-Apparent-Source-IP: 12.201.5.28 X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.190183 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a JTAG probe is connected to a MIPS cluster, then the CPC detects it and latches the CPC.STAT_CONF.EJTAG_PROBE bit to 1. While set, attempting to send a power-down command to a core will be blocked, and the CPC will instead send the core to clock-off state. This can interfere with systems fully entering a low power state where all cores, CM, GIC, etc are powered down. Detect that a JTAG probe is / has been connected to the cluster and block the suspend attempt. Attempting to suspend the system while a JTAG probe is connected now yields: # echo mem > /sys/power/state [ 11.654000] PM: Syncing filesystems ... done. [ 11.658000] JTAG probe is connected - abort suspend -sh: echo: write error: Operation not permitted # To restore suspend, the JTAG probe should be disconnected or put into quiescent state. Platform code can then clear the CPC.STAT_CONF.EJTAG_PROBE bit. Signed-off-by: Matt Redfearn --- Changes in v2: Fixed CPC_Cx_STAT_CONF_EJTAG_PROBE_MSK -> CPC_Cx_STAT_CONF_EJTAG_PROBE - thanks kbuild test robot! arch/mips/kernel/pm-cps.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c index 421e06dfee72..a17d85d51576 100644 --- a/arch/mips/kernel/pm-cps.c +++ b/arch/mips/kernel/pm-cps.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -670,6 +671,36 @@ static int cps_pm_online_cpu(unsigned int cpu) return 0; } +#if defined(CONFIG_PM_SLEEP) +static int cps_pm_power_notifier(struct notifier_block *this, + unsigned long event, void *ptr) +{ + unsigned int stat; + + switch (event) { + case PM_SUSPEND_PREPARE: + stat = read_cpc_cl_stat_conf(); + /* + * If we're attempting to suspend the system and power down all + * of the cores, the JTAG detect bit indicates that the CPC will + * instead put the cores into clock-off state. In this state + * a connected debugger can cause the CPU to attempt + * interactions with the powered down system. At best this will + * fail. At worst, it can hang the NoC, requiring a hard reset. + * To avoid this, just block system suspend if a JTAG probe + * is detected. + */ + if (stat & CPC_Cx_STAT_CONF_EJTAG_PROBE) { + pr_warn("JTAG probe is connected - abort suspend\n"); + return NOTIFY_BAD; + } + return NOTIFY_DONE; + default: + return NOTIFY_DONE; + } +} +#endif /* CONFIG_PM_SLEEP */ + static int __init cps_pm_init(void) { /* A CM is required for all non-coherent states */ @@ -705,6 +736,8 @@ static int __init cps_pm_init(void) pr_warn("pm-cps: no CPC, clock & power gating unavailable\n"); } + pm_notifier(cps_pm_power_notifier, 0); + return cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mips/cps_pm:online", cps_pm_online_cpu, NULL); } -- 2.7.4