From patchwork Tue Dec 10 16:51:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13901783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5EB5EE7717F for ; Tue, 10 Dec 2024 16:52:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D2D0710E5D0; Tue, 10 Dec 2024 16:52:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="j+fFC0Pl"; dkim-atps=neutral Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1061410E5D0; Tue, 10 Dec 2024 16:52:03 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2166022c5caso17968725ad.2; Tue, 10 Dec 2024 08:52:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733849522; x=1734454322; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qh7p2d7+E2GMmgZFCCSWmo87bNDM3/nkgcYOWm/PC60=; b=j+fFC0PlitkQYKRG4ktvezOZ7S7rljwGC2U4cFOKhapSwxCB8wspvY/P/Y6OHHgLJB 4CrTtSlZAC6d/GQSasgXMTxYsrbICfNo5lnhGrH0Sl6xZRBsj+nYoOD41xaW1aYUK97a jWWXNs19ejvN1zadckTlQ9UsOIwY6m6LQWsj+xVV3n+uFastnM0y4s0oG2+HsUUhX+88 rHeAybeBZnLZBSS9wFmZSe+5Awk8jEczA6bGj2taAFId6Lqpr+G3HiqemNyO8TehQaSK A9OMD+85uKUalQflqGmU+J9tQ9nhw07N1bBEsSRxaTqghzxRv2v5z+QwZzyn/i2fzTne yKdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733849522; x=1734454322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qh7p2d7+E2GMmgZFCCSWmo87bNDM3/nkgcYOWm/PC60=; b=vafYIQZYMPA9Z/5aFHxa0qTtMGfT9EzjgcDcQP0+a/wGNSaxzg/LjywUItEfhLWbhw KBfDIBqOAxg2RKZVi+2pT5+HSzPYEFIj3LPEHknVlFUgmoNyDDnJ7TpvY0S80siTGanA UTsHsoDxeyCazEaUcUbB+XQBcmkpxRTNzCMLMRkDSG5H/PBxhOLx1qjhkCRBK/cbTecn xD9t3M9X+WjJgTq/5k6SmlPGO5q36XbuWS4sRw4GZEm9sFLdp57YItGBWXjKpsG2lMOj CNLoizC2VxCCwijKj/no0gx1P4SsgzzT/ascaW1n8kAFkMYsgGbZtnFBclDFOPgkQBhT 8E4g== X-Forwarded-Encrypted: i=1; AJvYcCWZ+BeEPw21bCcTUq5k6f6FWh9yH2uyMOAN6HlA6AV7ItRkkUFRd0ZP49IBa+judK5xrOco4KFzJVyU@lists.freedesktop.org, AJvYcCXkGR/VgAjK8oJRD3iQy3gD+efTr926KKIYSVOINP6jkKBg2NjZEJPQXXB9JL9Vp9j+wc6mKGfWOko=@lists.freedesktop.org X-Gm-Message-State: AOJu0Yweb5KTK0W4hS+T1HjxzYABeFdzlTmcNsnhj/P6f9uffQTf8umF rMvPnGpew24SCoAq3h+HG85751+ICXa0XkM5S8kY6VQ2NLoQz4LG X-Gm-Gg: ASbGncsX0t2nWQQ7W761eE1Mu4osIDO+x/EBbh68+gBBC1M4v0XUg9rmC8gpXo94w+F G4PjaezY0qauD6AoWUtxQTcEYYp3OEY5Wuc4qsN/jWZpOk4L2KRrWcGY5ozp+LYaFwdQfvoftLa dsWN1oFsKfmTFPoIbSzZDdhEqH7taqtCBkMD5ZiHRRbsF+bAcLYmSq9EI40k4zA4lXYcL14y9CT 7cbGL+aWjYRkvreKKH+2U7OVOxXUcy2i1hEtVbT5mXajeLuGvhfvSOjjKs+X/0CSwcS3SqWPOMw 5kCRhgR8Ito2XvPTngtP4PDoFV1O X-Google-Smtp-Source: AGHT+IGyppZ/XUmktj28oKiZ+5yOlPQdJYESYN99eWYi54gnG85QRxp2tq+GL1giES6A+moTdOjNmQ== X-Received: by 2002:a17:902:f684:b0:216:386e:dbc with SMTP id d9443c01a7336-216386e1127mr132673815ad.13.1733849522435; Tue, 10 Dec 2024 08:52:02 -0800 (PST) Received: from localhost ([2a00:79e1:2e00:1301:12e9:d196:a1e9:ab67]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21632c4fd4dsm55201575ad.232.2024.12.10.08.52.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 08:52:01 -0800 (PST) From: Rob Clark To: iommu@lists.linux.dev Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Mostafa Saleh , Will Deacon , Rob Clark , Rob Clark , Sean Paul , Konrad Dybcio , Abhinav Kumar , Dmitry Baryshkov , Marijn Suijten , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org (open list:DRM DRIVER for Qualcomm Adreno GPUs), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v11 4/4] drm/msm: Extend gpu devcore dumps with pgtbl info Date: Tue, 10 Dec 2024 08:51:22 -0800 Message-ID: <20241210165127.600817-5-robdclark@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241210165127.600817-1-robdclark@gmail.com> References: <20241210165127.600817-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Rob Clark In the case of iova fault triggered devcore dumps, include additional debug information based on what we think is the current page tables, including the TTBR0 value (which should match what we have in adreno_smmu_fault_info unless things have gone horribly wrong), and the pagetable entries traversed in the process of resolving the faulting iova. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 10 ++++++++++ drivers/gpu/drm/msm/msm_gpu.c | 9 +++++++++ drivers/gpu/drm/msm/msm_gpu.h | 8 ++++++++ drivers/gpu/drm/msm/msm_iommu.c | 22 ++++++++++++++++++++++ drivers/gpu/drm/msm/msm_mmu.h | 3 ++- 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c index 076be0473eb5..f1d6e6665c30 100644 --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c @@ -868,6 +868,16 @@ void adreno_show(struct msm_gpu *gpu, struct msm_gpu_state *state, drm_printf(p, " - dir=%s\n", info->flags & IOMMU_FAULT_WRITE ? "WRITE" : "READ"); drm_printf(p, " - type=%s\n", info->type); drm_printf(p, " - source=%s\n", info->block); + + /* Information extracted from what we think are the current + * pgtables. Hopefully the TTBR0 matches what we've extracted + * from the SMMU registers in smmu_info! + */ + drm_puts(p, "pgtable-fault-info:\n"); + drm_printf(p, " - ttbr0: %.16llx\n", (u64)info->pgtbl_ttbr0); + drm_printf(p, " - asid: %d\n", info->asid); + drm_printf(p, " - ptes: %.16llx %.16llx %.16llx %.16llx\n", + info->ptes[0], info->ptes[1], info->ptes[2], info->ptes[3]); } drm_printf(p, "rbbm-status: 0x%08x\n", state->rbbm_status); diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index 0d4a3744cfcb..82f204f3bb8f 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -281,6 +281,15 @@ static void msm_gpu_crashstate_capture(struct msm_gpu *gpu, if (submit) { int i; + if (state->fault_info.ttbr0) { + struct msm_gpu_fault_info *info = &state->fault_info; + struct msm_mmu *mmu = submit->aspace->mmu; + + msm_iommu_pagetable_params(mmu, &info->pgtbl_ttbr0, + &info->asid); + msm_iommu_pagetable_walk(mmu, info->iova, info->ptes); + } + state->bos = kcalloc(submit->nr_bos, sizeof(struct msm_gpu_state_bo), GFP_KERNEL); diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h index 7cabc8480d7c..e25009150579 100644 --- a/drivers/gpu/drm/msm/msm_gpu.h +++ b/drivers/gpu/drm/msm/msm_gpu.h @@ -101,6 +101,14 @@ struct msm_gpu_fault_info { int flags; const char *type; const char *block; + + /* Information about what we think/expect is the current SMMU state, + * for example expected_ttbr0 should match smmu_info.ttbr0 which + * was read back from SMMU registers. + */ + phys_addr_t pgtbl_ttbr0; + u64 ptes[4]; + int asid; }; /** diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c index 2a94e82316f9..3e692818ba1f 100644 --- a/drivers/gpu/drm/msm/msm_iommu.c +++ b/drivers/gpu/drm/msm/msm_iommu.c @@ -195,6 +195,28 @@ struct iommu_domain_geometry *msm_iommu_get_geometry(struct msm_mmu *mmu) return &iommu->domain->geometry; } +int +msm_iommu_pagetable_walk(struct msm_mmu *mmu, unsigned long iova, uint64_t ptes[4]) +{ + struct msm_iommu_pagetable *pagetable; + struct arm_lpae_io_pgtable_walk_data wd = {}; + + if (mmu->type != MSM_MMU_IOMMU_PAGETABLE) + return -EINVAL; + + pagetable = to_pagetable(mmu); + + if (!pagetable->pgtbl_ops->pgtable_walk) + return -EINVAL; + + pagetable->pgtbl_ops->pgtable_walk(pagetable->pgtbl_ops, iova, &wd); + + for (int i = 0; i < ARRAY_SIZE(wd.ptes); i++) + ptes[i] = wd.ptes[i]; + + return 0; +} + static const struct msm_mmu_funcs pagetable_funcs = { .map = msm_iommu_pagetable_map, .unmap = msm_iommu_pagetable_unmap, diff --git a/drivers/gpu/drm/msm/msm_mmu.h b/drivers/gpu/drm/msm/msm_mmu.h index 88af4f490881..96e509bd96a6 100644 --- a/drivers/gpu/drm/msm/msm_mmu.h +++ b/drivers/gpu/drm/msm/msm_mmu.h @@ -53,7 +53,8 @@ static inline void msm_mmu_set_fault_handler(struct msm_mmu *mmu, void *arg, struct msm_mmu *msm_iommu_pagetable_create(struct msm_mmu *parent); int msm_iommu_pagetable_params(struct msm_mmu *mmu, phys_addr_t *ttbr, - int *asid); + int *asid); +int msm_iommu_pagetable_walk(struct msm_mmu *mmu, unsigned long iova, uint64_t ptes[4]); struct iommu_domain_geometry *msm_iommu_get_geometry(struct msm_mmu *mmu); #endif /* __MSM_MMU_H__ */