Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5729583pxv; Wed, 21 Jul 2021 12:28:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyG+4IzwVbU7kqAn4FPcbiDthcXL/C5ag0kdVEULBIxUTnOgZFnQwdlsDpUjM7VxXRbIfVx X-Received: by 2002:a92:8e41:: with SMTP id k1mr14420706ilh.276.1626895723155; Wed, 21 Jul 2021 12:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626895723; cv=none; d=google.com; s=arc-20160816; b=1AEjBX2RllqXjxtCR0PFiFHrl2YhN85SMkm5Df0EKKrGOYThJvBvusJRqyUb/k30jz f3/vNuX6PDdXzMS0TDtkbl3o5JoRG0kGxRB9qB86kFdPNTsZhhrtXCVWNvKDP5NLhG65 WXtAPMMh5HEtkjLWQs0dC2WGMBv2y2XlYqAG6hQhfj8iO83fgOwCVaGSl+MB8NoAFEPV ptwZVfjmznAZw0HuSvSIUsjtFOuGgBuogn6Zr8KirTfhZuNJ94Ac4FWkuyC+gPmyguQB KGBDoDCtdnalQORUNFNVizcODtAgj+a48gndpwHcpS0qoVK8AMo3rmpZ41JPEVNzLIME 4VxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=x3hFsaOpPc4LTcHTfgxGa+49jrEL1HA/9LgMKGVmcxw=; b=JisRjSeesIyc7wXnJpI2C7b/xk/QQBle6w1agstm/CaWloRCtup+hlYiPbMo2wGLMz JnFfFTC8Db2OXm8puBG/pkV+9nAdd10hOHidYFx5Sn1m1DGwHhfMOAtD7yv7nzYx+Q5S x30CRFVxgiQqNIChEL5KWOF634GFInBJIZ7TN7vEqayTMig2+f+SfTxSeM44u9fYd4os xhDeYqCk6Cy/2Te+reS0meg335sGWQU1+PsvfoZ7ghpf4g+pVggHPiNzb0HBMugTSIfj +v4R5W7XMuIFxXjPhZ02t3VC29vP4PnfgV/x7qVHwyaa7AGjQJkdw/3GwWH4Du5Rm+Au AW3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t13si27985927ilg.9.2021.07.21.12.28.30; Wed, 21 Jul 2021 12:28:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239481AbhGUOXd (ORCPT + 99 others); Wed, 21 Jul 2021 10:23:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:56894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239491AbhGUOUu (ORCPT ); Wed, 21 Jul 2021 10:20:50 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2D6A16120E; Wed, 21 Jul 2021 15:01:27 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m6Div-0005Ox-3p; Wed, 21 Jul 2021 16:01:25 +0100 Date: Wed, 21 Jul 2021 16:01:24 +0100 Message-ID: <877dhj3e4b.wl-maz@kernel.org> From: Marc Zyngier To: Robin Murphy Cc: Bixuan Cui , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, will@kernel.org, weiyongjun1@huawei.com, john.wanghui@huawei.com, dingtianhong@huawei.com, thunder.leizhen@huawei.com, guohanjun@huawei.com, joro@8bytes.org, jean-philippe@linaro.org, Jonathan.Cameron@huawei.com, song.bao.hua@hisilicon.com, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH -next] iommu/arm-smmu-v3: Add suspend and resume support In-Reply-To: <848befb0-7a9a-0b2b-8be9-3dfa02919488@arm.com> References: <20210721013350.17664-1-cuibixuan@huawei.com> <4e506481-5f6c-9c5e-eda3-300861581080@arm.com> <878s1z3j68.wl-maz@kernel.org> <848befb0-7a9a-0b2b-8be9-3dfa02919488@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-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: 185.219.108.64 X-SA-Exim-Rcpt-To: robin.murphy@arm.com, cuibixuan@huawei.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, will@kernel.org, weiyongjun1@huawei.com, john.wanghui@huawei.com, dingtianhong@huawei.com, thunder.leizhen@huawei.com, guohanjun@huawei.com, joro@8bytes.org, jean-philippe@linaro.org, Jonathan.Cameron@huawei.com, song.bao.hua@hisilicon.com, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 21 Jul 2021 14:59:47 +0100, Robin Murphy wrote: > > On 2021-07-21 14:12, Marc Zyngier wrote: > > On Wed, 21 Jul 2021 12:42:14 +0100, > > Robin Murphy wrote: > >> > >> [ +Marc for MSI bits ] > >> > >> On 2021-07-21 02:33, Bixuan Cui wrote: > >>> Add suspend and resume support for arm-smmu-v3 by low-power mode. > >>> > >>> When the smmu is suspended, it is powered off and the registers are > >>> cleared. So saves the msi_msg context during msi interrupt initialization > >>> of smmu. When resume happens it calls arm_smmu_device_reset() to restore > >>> the registers. > >>> > >>> Signed-off-by: Bixuan Cui > >>> Reviewed-by: Wei Yongjun > >>> Reviewed-by: Zhen Lei > >>> Reviewed-by: Ding Tianhong > >>> Reviewed-by: Hanjun Guo > >>> --- > >>> > >>> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 72 ++++++++++++++++++--- > >>> 1 file changed, 64 insertions(+), 8 deletions(-) > >>> > >>> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > >>> index 235f9bdaeaf2..bf1163acbcb1 100644 > >>> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > >>> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > >>> @@ -40,6 +40,7 @@ MODULE_PARM_DESC(disable_bypass, > >>> static bool disable_msipolling; > >>> module_param(disable_msipolling, bool, 0444); > >>> +static bool bypass; > >>> MODULE_PARM_DESC(disable_msipolling, > >>> "Disable MSI-based polling for CMD_SYNC completion."); > >>> @@ -3129,11 +3130,37 @@ static void arm_smmu_write_msi_msg(struct > >>> msi_desc *desc, struct msi_msg *msg) > >>> doorbell = (((u64)msg->address_hi) << 32) | msg->address_lo; > >>> doorbell &= MSI_CFG0_ADDR_MASK; > >>> + /* Saves the msg context for resume if desc->msg is empty */ > >>> + if (desc->msg.address_lo == 0 && desc->msg.address_hi == 0) { > >>> + desc->msg.address_lo = msg->address_lo; > >>> + desc->msg.address_hi = msg->address_hi; > >>> + desc->msg.data = msg->data; > >>> + } > >> > >> My gut feeling is that this is something a device driver maybe > >> shouldn't be poking into, but I'm not entirely familiar with the area > >> :/ > > > > Certainly not. If you rely on the message being stored into the > > descriptors, then implement this in the core code, like we do for PCI. > > Ah, so it would be an acceptable compromise to *read* desc->msg (and > thus avoid having to store our own copy of the message) if the core > was guaranteed to cache it? That's good to know, thanks. Yeah, vfio, a couple of other weird drivers and (*surprise!*) ia64 are using this kind of trick. I don't see a reason not to implement that for platform-MSI (although level signalling may be interesting...), or even to move it into the core MSI code. > > >>> + > >>> writeq_relaxed(doorbell, smmu->base + cfg[0]); > >>> writel_relaxed(msg->data, smmu->base + cfg[1]); > >>> writel_relaxed(ARM_SMMU_MEMATTR_DEVICE_nGnRE, smmu->base + cfg[2]); > >>> } > >>> +static void arm_smmu_resume_msis(struct arm_smmu_device *smmu) > >>> +{ > >>> + struct msi_desc *desc; > >>> + struct device *dev = smmu->dev; > >>> + > >>> + for_each_msi_entry(desc, dev) { > >>> + switch (desc->platform.msi_index) { > >>> + case EVTQ_MSI_INDEX: > >>> + case GERROR_MSI_INDEX: > >>> + case PRIQ_MSI_INDEX: > >>> + arm_smmu_write_msi_msg(desc, &(desc->msg)); > > > > Consider using get_cached_msi_msg() instead of using the internals of > > the descriptor. > > Oh, there's even a proper API for it, marvellous! I hadn't managed to > dig that far myself :) It is a bit odd in the sense that it takes a copy of the message instead of returning a pointer, but at least this solves lifetime issues. Thanks, M. -- Without deviation from the norm, progress is not possible.