Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1510580ybl; Tue, 3 Dec 2019 08:16:04 -0800 (PST) X-Google-Smtp-Source: APXvYqyfr3ZcSOnkEvLaadQ/rEJAyRQ+yEwRylDQG51f0qAgGjvRBPjL0M5/Brc9xMMLJn48xAUN X-Received: by 2002:aca:55cc:: with SMTP id j195mr4441479oib.22.1575389762724; Tue, 03 Dec 2019 08:16:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575389762; cv=none; d=google.com; s=arc-20160816; b=pS8xuhhWOZGsvum1ty39n4EkhHkiRxVEhH6C9tDLpaYXgGo8I4qEIdrQcJ82O0VxB4 KwnK41CJkRyfzhIWSYpteGufVQynjjAf2+ei+3uprzv7ewOgaMVbEgLF2lp7NB8vUo8Q /WDIzjHM0tq99Pdlsw+AOvcwue6qUN1fn/bHk2NpgzdFtUiYJTKeanMAXHVoDqoaToA0 QYtbx5Zp/8/vlIuWtpYcg03NwZFRyeSmF6jmHmuJk910bV4+U22BBZjWNrndVfpzEW4q NlbXZW/HOM3UmVkyD1SEZmsvdCe1EgHpHfkqCxI2UX+nKlKAyiR5gH3kp2TAHxKP4ZTr FHaw== 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:cc:from:date:content-transfer-encoding:mime-version :subject:to; bh=sDOLAFNdNPRqiaelMM0PSlHOFWOALfbm+h/Eq6382r0=; b=lraJNji4XMZIMgxKLtAaLUoFMkCncUVvzoljcipcfloxPtjHZfk6X8+NaWN+AoxeJc mvbhnPooqX7N6+7Le8VcwvGoxrhLO9n5MMXBuwl362MX9Gw2qyQxbazhjmBh+Stq9jxC QkHUDons3MT8Zr300xtWj5c0BX2ydBuavQmGhuR4tNt+8zMYEJfAdYLuShFDfAY93dZw De+tzoHi3IRP6TLA/6jd0akFQ6eeXcygJgorsK5ZpnAMGYe4l5fGERwoYLAn5V9pqYVf Kt1egmW2kp9jaMor5CmxisRHv9cA7akFSTrKlgijXUFqdmBIiaTmFZB0tqD1GAghmgR3 uesg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j15si1455105oij.52.2019.12.03.08.15.46; Tue, 03 Dec 2019 08:16:02 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbfLCP6y (ORCPT + 99 others); Tue, 3 Dec 2019 10:58:54 -0500 Received: from inca-roads.misterjones.org ([213.251.177.50]:53916 "EHLO inca-roads.misterjones.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726796AbfLCP6w (ORCPT ); Tue, 3 Dec 2019 10:58:52 -0500 Received: from www-data by cheepnis.misterjones.org with local (Exim 4.80) (envelope-from ) id 1icAZc-00084G-W2; Tue, 03 Dec 2019 16:58:49 +0100 To: Yao HongBo Subject: Re: ITS restore/save state when HCC =?UTF-8?Q?=3D=3D=20=30?= X-PHP-Originating-Script: 0:main.inc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 03 Dec 2019 15:58:48 +0000 From: Marc Zyngier Cc: "Guohanjun (Hanjun Guo)" , Yangyingliang , Linuxarm , , In-Reply-To: References: Message-ID: X-Sender: maz@kernel.org User-Agent: Roundcube Webmail/0.7.2 X-SA-Exim-Connect-IP: X-SA-Exim-Rcpt-To: yaohongbo@huawei.com, guohanjun@huawei.com, yangyingliang@huawei.com, linuxarm@huawei.com, linux-kernel@vger.kernel.org, james.morse@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on cheepnis.misterjones.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + James, who wrote most (if not all) of the arm64 hibernate code On 2019-12-03 02:23, Yao HongBo wrote: > On 12/2/2019 9:22 PM, Marc Zyngier wrote: >> Hi Yaohongbo, >> >> In the future, please refrain from sending HTML emails, they >> don't render very well and force me to reformat your email >> by hand. > > Sorry. I'll pay attention to this next time. > >> On 2019-12-02 12:52, yaohongbo wrote: >>> Hi, marc. >>> >>> I met a problem with GIC ITS when I try to power off gic logic in >>> suspend. >>> >>> In hisilicon hip08, the value of GIC_TYPER.HCC is zero, so that >>> ITS_FLAGS_SAVE_SUSPEND_STATE will have no chance to be set to 1. >> >> And that's a good thing. HCC indicates that you have collections >> that >> are backed by registers, and not memory. Which means that once the >> GIC >> is powered off, the state is lost. >> >>> It goes well for s4, when I simply remove the condition judgement >>> in >>> the code. >> >> What is "s4"? Doing so means you are reprogramming the ITS with >> mappings >> that already exist in the tables, and that is UNPRED territory. > > Sorry, I didn't describe it clearly. > S4 means "suspend to disk". > In s4, The its will reinit and malloc an new its address. Huh, hibernate... Yeah, this is not expected to work, I'm afraid. > My expectation is to reprogram the ITS with original mappings. If > ITS_FLAGS_SAVE_SUSPEND_STATE > is not set, i'll have no chance to use the original its table > mappings. > > What should i do if i want to restore its state with hcc == 0? HCC is the least of the problems, and there are plenty more issues: - I'm not sure what guarantees that the tables are at the same address in the booting kernel and the the resumed kernel. That covers all the ITS tables and as well as the RDs'. - It could well be that restoring the ITS base addresses is enough for everything to resume correctly, but this needs some serious investigation. Worse case, we will need to replay the whole of the ITS programming. - This is going to interact more or less badly with the normal suspend to RAM code... - The ITS is only the tip of the iceberg. The whole of the SMMU setup needs to be replayed, or devices won't resume correctly (I just tried on a D05). Anyway, with the hack below, I've been able to get D05 to resume up to the point where devices try to do DMA, and then it was dead. There is definitely some work to be done there... M. diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 4ba31de4a875..a05fc6bac203 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,7 @@ #define ITS_FLAGS_WORKAROUND_CAVIUM_22375 (1ULL << 1) #define ITS_FLAGS_WORKAROUND_CAVIUM_23144 (1ULL << 2) #define ITS_FLAGS_SAVE_SUSPEND_STATE (1ULL << 3) +#define ITS_FLAGS_SAVE_HIBERNATE_STATE (1ULL << 4) #define RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING (1 << 0) #define RDIST_FLAGS_RD_TABLES_PREALLOCATED (1 << 1) @@ -3517,8 +3519,16 @@ static int its_save_disable(void) raw_spin_lock(&its_lock); list_for_each_entry(its, &its_nodes, entry) { void __iomem *base; + u64 flags; - if (!(its->flags & ITS_FLAGS_SAVE_SUSPEND_STATE)) + if (system_entering_hibernation()) + its->flags |= ITS_FLAGS_SAVE_HIBERNATE_STATE; + + flags = its->flags; + flags &= (ITS_FLAGS_SAVE_SUSPEND_STATE | + ITS_FLAGS_SAVE_HIBERNATE_STATE); + + if (!flags) continue; base = its->base; @@ -3559,11 +3569,17 @@ static void its_restore_enable(void) raw_spin_lock(&its_lock); list_for_each_entry(its, &its_nodes, entry) { void __iomem *base; + u64 flags; int i; - if (!(its->flags & ITS_FLAGS_SAVE_SUSPEND_STATE)) + flags = its->flags; + flags &= (ITS_FLAGS_SAVE_SUSPEND_STATE | + ITS_FLAGS_SAVE_HIBERNATE_STATE); + if (!flags) continue; + its->flags &= ~ITS_FLAGS_SAVE_HIBERNATE_STATE; + base = its->base; /* -- Jazz is not dead. It just smells funny...