From patchwork Mon Aug 26 22:33:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 172223 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp4965533ily; Mon, 26 Aug 2019 15:33:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUdcqtrt0oyhQYGFV0R7Ante8Iywo5yKGY1JeBhvXkzsIqPPvIuJvX2cGvfC0sxmbjyj9W X-Received: by 2002:a17:902:aa08:: with SMTP id be8mr21693964plb.144.1566858817000; Mon, 26 Aug 2019 15:33:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566858816; cv=none; d=google.com; s=arc-20160816; b=ylMp3C432o5uDL+bhxtoYz+w6HqnuklOFlI3RkDiRY3oAWOdZ4aUNX7MHZermFnG7j LrZ166sxgBAfuCfSIX5+lAwCE7FpxHWznTHdEh+HFvHMy5PF+6oRfnLhUl5a5XWOblTA kwMXath485rcXGNZ8XZl8mCh5DpuksYcnmzbk09sFKKxvGIqxLyOHqWeERh+wlc8umX1 MaYxBbpXrNR+IP2duIk7FIiLgTZ8wLmGqbrv6gR1ufJaVNNWn26bGtwT8w2610BQf5Bp B4s29iTivrD9akOD1u8nJAyAB4s5ESkeUEBBz2HedPwuK9aWVn7zuUtSeA3jIkELTh6C k0Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=GrEXLb6Hh5yOEX7s1V+xWWMWoJzfBuaS5gIDUHFkFQ0=; b=sNjbW385sHdCY2IJoRiHNd31LJB7G6JLZWv8BOzX7BD9tRElbfUpik0piWaG+qqJj9 H4jFECzBlMdgoY7Roa+HUPZ2lmap8iWT14IMgU4vdVkEnDqruAHGqGKvJ9XB/G9r3ToJ qNWqooWY8U5HAj0MNrWjBWsi3A+91doYV4CFWLqYTkbEeg4K5thpAAuubeFNUdgrTlsn 5FyktbUJVL8QO3aShc7JPFOCW2SaZK9M/8MkW7UVrMUzCAUx/nN+/G+V+L4ZzM6WNvd9 CywBXu5kvwBe02i6kiF93fyLiXACe+U5se6q7alCgb7MzpgKhC7PIXLyLngKU8nXpJEE CJ2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id x13si10342096pgr.210.2019.08.26.15.33.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Aug 2019 15:33:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C73E66E319; Mon, 26 Aug 2019 22:33:35 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi1-f196.google.com (mail-oi1-f196.google.com [209.85.167.196]) by gabe.freedesktop.org (Postfix) with ESMTPS id E56A589CA8 for ; Mon, 26 Aug 2019 22:33:23 +0000 (UTC) Received: by mail-oi1-f196.google.com with SMTP id l2so13443235oil.0 for ; Mon, 26 Aug 2019 15:33:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JVt+vCDKgXVtdo0ejAqvuaCusDRsMqZBJphe0loOVVg=; b=gfor43rpXTHMYOqOc0q6zLwf8IYFSrgzyuLD6i7sOkr0PZwhESVk1yeT3hz5mDkpFZ n69lBsHVJIamB/ENcZMkAAHINscse6sJd56hIylhWhFAmy3v48qljBYuMZ4SLN281XQC ngcQS3KUfAWYktDXviaX2eFaOFN11Z3aHKUv97xwHloHhdB+IDcRoiMtHa7LjIM3utgG tdRH6sQKWKW1+Wkg8OyDWQb2u9czlgl3pkFgYF6l5rlA8u6hSIJDDXJn6I9++qtB32BY 77PUzvrnTmriPuX0lNlf08rnytSTn7dBePPY3RnRJ2BgdEifCXLsuxFJnFQvVkY3xNdQ 2QIw== X-Gm-Message-State: APjAAAWR788b08SnNJegNZdriJ8cqM8rJaM76jb7eeGlldE7EPy5MiBm 4OsG7OmFctE4msxejLoI7cGlll8= X-Received: by 2002:aca:4994:: with SMTP id w142mr13682915oia.132.1566858802745; Mon, 26 Aug 2019 15:33:22 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id e22sm3668959oii.7.2019.08.26.15.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2019 15:33:22 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 4/8] drm/panfrost: Rework page table flushing and runtime PM interaction Date: Mon, 26 Aug 2019 17:33:13 -0500 Message-Id: <20190826223317.28509-5-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190826223317.28509-1-robh@kernel.org> References: <20190826223317.28509-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , David Airlie , Steven Price , Alyssa Rosenzweig , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There is no point in resuming the h/w just to do flush operations and doing so takes several locks which cause lockdep issues with the shrinker. Rework the flush operations to only happen when the h/w is already awake. This avoids taking any locks associated with resuming which trigger lockdep warnings. Fixes: 013b65101315 ("drm/panfrost: Add madvise and shrinker support") Cc: Tomeu Vizoso Cc: Steven Price Cc: Alyssa Rosenzweig Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring Reviewed-by: Robin Murphy Reviewed-by: Steven Price --- v3: - Use pm_runtime_get_noresume() and pm_runtime_active() instead of pm_runtime_get_if_not_used(). The problem is pm_runtime_get_if_not_used() returns 0 (no get) if in the period between the last put() and before the autosuspend timeout when the h/w is still active. drivers/gpu/drm/panfrost/panfrost_mmu.c | 38 ++++++++++++------------- 1 file changed, 18 insertions(+), 20 deletions(-) -- 2.20.1 diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c index 3a8bcfa7e7b6..2204e60f7808 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c @@ -220,6 +220,22 @@ static size_t get_pgsize(u64 addr, size_t size) return SZ_2M; } +void panfrost_mmu_flush_range(struct panfrost_device *pfdev, + struct panfrost_mmu *mmu, + u64 iova, size_t size) +{ + if (mmu->as < 0) + return; + + pm_runtime_get_noresume(pfdev->dev); + + /* Flush the PTs only if we're already awake */ + if (pm_runtime_active(pfdev->dev)) + mmu_hw_do_operation(pfdev, mmu, iova, size, AS_COMMAND_FLUSH_PT); + + pm_runtime_put_sync_autosuspend(pfdev->dev); +} + static int mmu_map_sg(struct panfrost_device *pfdev, struct panfrost_mmu *mmu, u64 iova, int prot, struct sg_table *sgt) { @@ -244,8 +260,7 @@ static int mmu_map_sg(struct panfrost_device *pfdev, struct panfrost_mmu *mmu, } } - mmu_hw_do_operation(pfdev, mmu, start_iova, iova - start_iova, - AS_COMMAND_FLUSH_PT); + panfrost_mmu_flush_range(pfdev, mmu, start_iova, iova - start_iova); return 0; } @@ -255,7 +270,6 @@ int panfrost_mmu_map(struct panfrost_gem_object *bo) struct drm_gem_object *obj = &bo->base.base; struct panfrost_device *pfdev = to_panfrost_device(obj->dev); struct sg_table *sgt; - int ret; int prot = IOMMU_READ | IOMMU_WRITE; if (WARN_ON(bo->is_mapped)) @@ -268,14 +282,7 @@ int panfrost_mmu_map(struct panfrost_gem_object *bo) if (WARN_ON(IS_ERR(sgt))) return PTR_ERR(sgt); - ret = pm_runtime_get_sync(pfdev->dev); - if (ret < 0) - return ret; - mmu_map_sg(pfdev, bo->mmu, bo->node.start << PAGE_SHIFT, prot, sgt); - - pm_runtime_mark_last_busy(pfdev->dev); - pm_runtime_put_autosuspend(pfdev->dev); bo->is_mapped = true; return 0; @@ -289,17 +296,12 @@ void panfrost_mmu_unmap(struct panfrost_gem_object *bo) u64 iova = bo->node.start << PAGE_SHIFT; size_t len = bo->node.size << PAGE_SHIFT; size_t unmapped_len = 0; - int ret; if (WARN_ON(!bo->is_mapped)) return; dev_dbg(pfdev->dev, "unmap: as=%d, iova=%llx, len=%zx", bo->mmu->as, iova, len); - ret = pm_runtime_get_sync(pfdev->dev); - if (ret < 0) - return; - while (unmapped_len < len) { size_t unmapped_page; size_t pgsize = get_pgsize(iova, len - unmapped_len); @@ -312,11 +314,7 @@ void panfrost_mmu_unmap(struct panfrost_gem_object *bo) unmapped_len += pgsize; } - mmu_hw_do_operation(pfdev, bo->mmu, bo->node.start << PAGE_SHIFT, - bo->node.size << PAGE_SHIFT, AS_COMMAND_FLUSH_PT); - - pm_runtime_mark_last_busy(pfdev->dev); - pm_runtime_put_autosuspend(pfdev->dev); + panfrost_mmu_flush_range(pfdev, bo->mmu, bo->node.start << PAGE_SHIFT, len); bo->is_mapped = false; }