Received: by 10.223.185.116 with SMTP id b49csp845135wrg; Fri, 23 Feb 2018 07:42:08 -0800 (PST) X-Google-Smtp-Source: AH8x225W6i82YhHOFtGnHNpTPjXADmXBJVcGNadaQpHGRP/xYTV1hqeSlDbh8zOZj862FCFxLU29 X-Received: by 2002:a17:902:3281:: with SMTP id z1-v6mr2099050plb.431.1519400528413; Fri, 23 Feb 2018 07:42:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519400528; cv=none; d=google.com; s=arc-20160816; b=iU8Cg+dQIaPfKOFQmCbdUGifByvvuOmJzuQ+JbEr+kDBsp9jufKAuZTREFJnkqjWGL mO98OCuCesa74iqgswqa49DJ5rO6BB0b1HEE1F8DhFJx8i+EaPS6WRwJTUd462BtUnfp c4mD5CUbaskAdIArKEOnSrTyo1icIzedseDjimvr2Ycyya9AgfISodyL4WJJGJAhDMo/ Xua20HrEOFAy//OTiMn8juUGyaXua4po89tnQnTFD9XEs6VV3obuTeJIpHTJzXoHQM+8 5oPM56NBmuv2eW760Xy85H38qDc4eK3tF48pbBZ8NCbVrsFi7xlAEkEqWY0xzwuDGE7q FhTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dmarc-filter:dkim-signature :dkim-signature:arc-authentication-results; bh=iA+sFJwwFJKAXGH5SU+TPqn2/5UlnrJPa7vdsjMvW7c=; b=f2Njg6ulIpO9HmjlLnVcH7rsV3eF4TArvVeXuvZQK3VYGZVceogSr4e8urQuCdVeW3 chX4aAD3w6wOuub8UhhLQItLnlMyBTOIIIGX9AE3Y/aElc86uZ/TowfAo20PKeQIwIw8 HLXYpCi5UmP3JmKA1il4cBshFxEJYqLltwY0orOtGVjhCRuEyz5UUOrhN2HB/VnP61/b qMaekMMRocRu1qP1Q+XnfWPUz9mVXoKtS5E20WJYi/Wf2yz3YroC0bmoBGwWp+qprFDZ Tjc3tfbmMSzOYLN9sIcaqBlH5KF0MBMe+f6w79By3y5nvay5fg6WS9oeIfbgr9+GsgfA QEhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=iM0TNga3; dkim=pass header.i=@codeaurora.org header.s=default header.b=DfijPrXQ; 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 a1-v6si1921564plt.549.2018.02.23.07.41.45; Fri, 23 Feb 2018 07:42:08 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=iM0TNga3; dkim=pass header.i=@codeaurora.org header.s=default header.b=DfijPrXQ; 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 S1751656AbeBWPk4 (ORCPT + 99 others); Fri, 23 Feb 2018 10:40:56 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:39372 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751406AbeBWPky (ORCPT ); Fri, 23 Feb 2018 10:40:54 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 75C8760F6E; Fri, 23 Feb 2018 15:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519400453; bh=JF08fQ1f0GSCHk/3b8bnLr1Vp+uPsUVYJsU3NhUI9u0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iM0TNga3fY5Z+kN2Mzy5bGUNEQ9fdtOCjONPpn5Anu5w4vgJHHspw9jQ4EltAS7Vh dnW53MZRzN902P0y1AeHdna//8lrG5btpFWzRoK1kk3p17btNEPCCLcMAB71EEuhgT dbpERNgecrHW37jye4mNName5IsaDiQaSzbgm8tc= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from jcrouse-lnx.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: jcrouse@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id A33526030F; Fri, 23 Feb 2018 15:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519400452; bh=JF08fQ1f0GSCHk/3b8bnLr1Vp+uPsUVYJsU3NhUI9u0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DfijPrXQuoIZP/Q14ehYH7p61ttYRa0rs0/h1hKA3H1e6s2EJv2kM2YjzV3XcPvAf QLncHBDlnvHQYudo00bJvFMjmiSPZ/rCs2QJFvnAjVvdVLSgoYmZaqDjtTw80CXWqW O46idi32R2n2PS3SedJEwTakwv4/ESWbZ/o8P+cg= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A33526030F Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=jcrouse@codeaurora.org Date: Fri, 23 Feb 2018 08:40:48 -0700 From: Jordan Crouse To: Vivek Gautam Cc: "list@263.net:IOMMU DRIVERS , Joerg Roedel , " , robh+dt , Mark Rutland , "Rafael J. Wysocki" , Robin Murphy , Will Deacon , Rob Clark , "list@263.net:IOMMU DRIVERS , Joerg Roedel , " , devicetree@vger.kernel.org, open list , Linux PM , dri-devel , freedreno , David Airlie , Greg KH , Stephen Boyd , linux-arm-msm Subject: Re: [Freedreno] [PATCH v7 3/6] iommu/arm-smmu: Invoke pm_runtime during probe, add/remove device Message-ID: <20180223154048.GB18743@jcrouse-lnx.qualcomm.com> Mail-Followup-To: Vivek Gautam , "list@263.net:IOMMU DRIVERS , Joerg Roedel , " , robh+dt , Mark Rutland , "Rafael J. Wysocki" , Robin Murphy , Will Deacon , Rob Clark , "list@263.net:IOMMU DRIVERS , Joerg Roedel , " , devicetree@vger.kernel.org, open list , Linux PM , dri-devel , freedreno , David Airlie , Greg KH , Stephen Boyd , linux-arm-msm References: <1517999482-17317-1-git-send-email-vivek.gautam@codeaurora.org> <1517999482-17317-4-git-send-email-vivek.gautam@codeaurora.org> <20180222235200.GA18743@jcrouse-lnx.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 23, 2018 at 04:06:39PM +0530, Vivek Gautam wrote: > On Fri, Feb 23, 2018 at 5:22 AM, Jordan Crouse wrote: > > On Wed, Feb 07, 2018 at 04:01:19PM +0530, Vivek Gautam wrote: > >> From: Sricharan R > >> > >> The smmu device probe/remove and add/remove master device callbacks > >> gets called when the smmu is not linked to its master, that is without > >> the context of the master device. So calling runtime apis in those places > >> separately. > >> > >> Signed-off-by: Sricharan R > >> [vivek: Cleanup pm runtime calls] > >> Signed-off-by: Vivek Gautam > >> --- > >> drivers/iommu/arm-smmu.c | 42 ++++++++++++++++++++++++++++++++++++++---- > >> 1 file changed, 38 insertions(+), 4 deletions(-) > >> > >> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c > >> index 9e2f917e16c2..c024f69c1682 100644 > >> --- a/drivers/iommu/arm-smmu.c > >> +++ b/drivers/iommu/arm-smmu.c > >> @@ -913,11 +913,15 @@ static void arm_smmu_destroy_domain_context(struct iommu_domain *domain) > >> struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); > >> struct arm_smmu_device *smmu = smmu_domain->smmu; > >> struct arm_smmu_cfg *cfg = &smmu_domain->cfg; > >> - int irq; > >> + int ret, irq; > >> > >> if (!smmu || domain->type == IOMMU_DOMAIN_IDENTITY) > >> return; > >> > >> + ret = pm_runtime_get_sync(smmu->dev); > >> + if (ret) > >> + return; > >> + > >> /* > >> * Disable the context bank and free the page tables before freeing > >> * it. > >> @@ -932,6 +936,8 @@ static void arm_smmu_destroy_domain_context(struct iommu_domain *domain) > >> > >> free_io_pgtable_ops(smmu_domain->pgtbl_ops); > >> __arm_smmu_free_bitmap(smmu->context_map, cfg->cbndx); > >> + > >> + pm_runtime_put_sync(smmu->dev); > >> } > >> > >> static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) > >> @@ -1407,14 +1413,22 @@ static int arm_smmu_add_device(struct device *dev) > >> while (i--) > >> cfg->smendx[i] = INVALID_SMENDX; > >> > >> - ret = arm_smmu_master_alloc_smes(dev); > >> + ret = pm_runtime_get_sync(smmu->dev); > >> if (ret) > >> goto out_cfg_free; > > > > Hey Vivek, I just hit a problem with this on sdm845. It turns out that > > pm_runtime_get_sync() returns a positive 1 if the device is already active. > > > > I hit this in the GPU code. The a6xx has two platform devices that each use a > > different sid on the iommu. The GPU is probed normally from a platform driver > > and it in turn initializes the GMU device by way of a phandle. > > > > Because the GMU isn't probed with a platform driver we need to call > > of_dma_configure() on the device to set up the IOMMU for the device which ends > > up calling through this path and we discover that the smmu->dev is already > > powered (pm_runtime_get_sync returns 1). > > > > I'm not immediately sure if this is a bug on sdm845 or not because a cursory > > inspection says that the SMMU device shouldn't be powered at this time but there > > might be a connection that I'm not seeing. Obviously if the SMMU was left > > powered thats a bad thing. But putting that aside it is obvious that this > > code should be accommodating of the possibility that the device is already > > powered, and so this should be > > > > if (ret < 0) > > goto out_cfg_free; > > Right, as Tomasz also pointed, we should surely check the negative value of > pm_runtime_get_sync(). Sorry, I didn't notice that Tomasz had pointed it out as well. I wanted to quickly get it on the mailing list so you could catch it in your time zone. > From your description, it may be that the GPU has turned on the smmu, and > then once if goes and probes the GMU, the GMU device also wants to turn-on > the same smmu device. But that's already active. So pm_runtime_get_sync() > returns 1. > Am i making sense? My concern is that this is happening during the probe and we shouldn't be energizing the GPU at this point. But it is entirely possible that the bus is on for other reasons. I'll do a bit of digging today and see exactly which device is at fault. Jordan -- The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project