Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp159228ybl; Wed, 4 Dec 2019 00:04:27 -0800 (PST) X-Google-Smtp-Source: APXvYqwfLZ1QrDdRiiQOG5D7rjI3J//ttjM8y48Q0qHue4HpXDrb1xqnMGvWIvb6Gyh7R9E8sGS2 X-Received: by 2002:aca:a896:: with SMTP id r144mr1569070oie.142.1575446667309; Wed, 04 Dec 2019 00:04:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575446667; cv=none; d=google.com; s=arc-20160816; b=IfrS6WASU5Lk6J0bKbWO1ns6QDgT4JTgr7RvBEmLbhID0rQ8BcQP5g8u/pONNbea8u LA0OUJ+mV7gatPIm9iUxNIr/c8EyTJdA4bR2vwIL+/Yhyx0Ma91QhVkbmIy3ovISuB+L /HIwivhFr+N4EY8Y9hNYbHBXPLXqRwRMEsPJ/amg2PIwCoVG3emyU+XRE9fwu+xTZ5ps uggaNJBhSF2w8sXpUkr/dyMmuutg3fh7z8UpwRrlFSz8wmY/6dsqy3oNUFGC73KC/Qvp edqf+ct2tUhv1JorU7e461bozBz7BF7TvWyE38CMQ8rPHuIW9gQ/DK3e2dCW4LHHjYxc biGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=PZD9L+JDrVtK0kLEJKyy0Oct/r/GuX58mQ1pB5/8LSA=; b=yNgLBhdL9gjI2GyaUf0QF9BBnVAc/J+lcAnqT93j+qQJO+uj7gJXBuS/mJFw2+p5gb Kb4BtJ/jEVeX96jSlohB+KgbUKfXfdd7b2J3/h74dz5M5GQ080PjD6XlA50mjvubtWli LoK2HGkK+ciT36QfFhmLiF93+qaWxqhOhF7m8AL/U1czLkJ/vOOh/7Dzv70QL3xki1+I iuM4VMgr4n9JBbbUeS4tLYiBqZpgMf12GOAs6LPn5VOKhNLRYwn/NK0xF0c1gLIyiYig Oo1IAfr4aELxB5DHG7ECm1M7ojqcNtpps1JjwpzhmdrDcteiIDABGeluRBwG+mTDidOq WXbw== 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 i10si2813224otk.195.2019.12.04.00.04.13; Wed, 04 Dec 2019 00:04:27 -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 S1726899AbfLDIDi (ORCPT + 99 others); Wed, 4 Dec 2019 03:03:38 -0500 Received: from inca-roads.misterjones.org ([213.251.177.50]:43648 "EHLO inca-roads.misterjones.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725839AbfLDIDi (ORCPT ); Wed, 4 Dec 2019 03:03:38 -0500 Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=big-swifty.misterjones.org) by cheepnis.misterjones.org with esmtpsa (TLSv1.2:AES256-GCM-SHA384:256) (Exim 4.80) (envelope-from ) id 1icPdH-0005rb-4E; Wed, 04 Dec 2019 09:03:35 +0100 Date: Wed, 04 Dec 2019 08:03:33 +0000 Message-ID: <86lfrszfe2.wl-maz@kernel.org> From: Marc Zyngier To: Ivid Suvarna Cc: Yao HongBo , "Guohanjun (Hanjun Guo)" , Yangyingliang , Linuxarm , Kernel development list , james.morse@arm.com Subject: Re: ITS restore/save state when HCC == 0 In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/26 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: ivid.suvarna@gmail.com, 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 On Wed, 04 Dec 2019 06:13:23 +0000, Ivid Suvarna wrote: > > On Tue, Dec 3, 2019 at 9:46 PM Marc Zyngier wrote: > > > > + 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; > > > > /* > > How about this one to reinit GIC for restore: > - https://source.codeaurora.org/quic/la/kernel/msm-4.14/commit/drivers/irqchip/irq-gic-v3.c?h=msm-4.14&id=b0079fb73c08e195498ba2b2ea9623b0cc0f5fed That's not what we're concerned with at the moment, as there is much more state that is currently missing. Save/restoring registers is the easy part. What needs to be fixed is the way RD memory tables potentially get moved around (and how they can then survive a kexec). Once we've solved these issues, we'll look at the register state which is likely to already be correct anyway. M. -- Jazz is not dead, it just smells funny.