iommu/arm-smmu: adreno-smmu page fault handling
Subsystems (7)
v4 cover iommu/arm-smmu: adreno-smmu page fault handling
From: Rob Clark <[email protected]>
(Resend, first attempt seems to not have entirely shown up in patchwork and had a random already merged patch tagging along because 00*patch picks up things I forgot to delete)
This picks up an earlier series[1] from Jordan, and adds additional support needed to generate GPU devcore dumps on iova faults. Original description:
This is a stack to add an Adreno GPU specific handler for pagefaults. The first patch starts by wiring up report_iommu_fault for arm-smmu. The next patch adds a adreno-smmu-priv function hook to capture a handful of important debugging registers such as TTBR0, CONTEXTIDR, FSYNR0 and others. This is used by the third patch to print more detailed information on page fault such as the TTBR0 for the pagetable that caused the fault and the source of the fault as determined by a combination of the FSYNR1 register and an internal GPU register.
This code provides a solid base that we can expand on later for even more extensive GPU side page fault debugging capabilities.
v4: [Rob] Add support to stall SMMU on fault, and let the GPU driver
resume translation after it has had a chance to snapshot the GPUs state
v3: Always clear FSR even if the target driver is going to handle resume
v2: Fix comment wording and function pointer check per Rob Clark
[1] https://lore.kernel.org/dri-devel/[email protected]/
Jordan Crouse (3):
iommu/arm-smmu: Add support for driver IOMMU fault handlers iommu/arm-smmu-qcom: Add an adreno-smmu-priv callback to get pagefault
info
drm/msm: Improve the a6xx page fault handler
Rob Clark (3):
iommu/arm-smmu-qcom: Add stall support
drm/msm: Add crashdump support for stalled SMMU
drm/msm: devcoredump iommu fault support
drivers/gpu/drm/msm/adreno/a2xx_gpu.c | 2 +- drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 2 +- drivers/gpu/drm/msm/adreno/a4xx_gpu.c | 2 +- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 9 +- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 101 +++++++++++++++++++- drivers/gpu/drm/msm/adreno/a6xx_gpu.h | 2 +- drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c | 43 +++++++-- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 15 +++ drivers/gpu/drm/msm/msm_debugfs.c | 2 +- drivers/gpu/drm/msm/msm_gem.h | 1 + drivers/gpu/drm/msm/msm_gem_submit.c | 1 + drivers/gpu/drm/msm/msm_gpu.c | 55 ++++++++++- drivers/gpu/drm/msm/msm_gpu.h | 19 +++- drivers/gpu/drm/msm/msm_gpummu.c | 5 + drivers/gpu/drm/msm/msm_iommu.c | 22 ++++- drivers/gpu/drm/msm/msm_mmu.h | 5 +- drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 50 ++++++++++ drivers/iommu/arm/arm-smmu/arm-smmu.c | 9 +- drivers/iommu/arm/arm-smmu/arm-smmu.h | 2 + include/linux/adreno-smmu-priv.h | 38 +++++++- 20 files changed, 354 insertions(+), 31 deletions(-)
Signature · 1 line
2.31.1
PATCH RESEND v4 1/6 iommu/arm-smmu: Add support for driver IOMMU fault handlers
From: Jordan Crouse <[email protected]>
Call report_iommu_fault() to allow upper-level drivers to register their own fault handlers.
--- drivers/iommu/arm/arm-smmu/arm-smmu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/iommu/arm/arm-smmu/arm-smmu.c +7 -2
@@ -408,6 +408,7 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev)struct arm_smmu_domain *smmu_domain =to_smmu_domain (domain);struct arm_smmu_device *smmu = smmu_domain->smmu;int idx = smmu_domain->cfg.cbndx; +int ret; fsr =arm_smmu_cb_read (smmu, idx,ARM_SMMU_CB_FSR );if (!(fsr &ARM_SMMU_FSR_FAULT ))
@@ -417,8 +418,12 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev) iova =arm_smmu_cb_readq (smmu, idx,ARM_SMMU_CB_FAR ); cbfrsynra =arm_smmu_gr1_read (smmu,ARM_SMMU_GR1_CBFRSYNRA (idx)); -dev_err_ratelimited (smmu->dev, -"Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cbfrsynra=0x%x, cb=%d\n" , + ret =report_iommu_fault (domain,NULL , iova, + fsynr &ARM_SMMU_FSYNR0_WNR ?IOMMU_FAULT_WRITE :IOMMU_FAULT_READ ); + +if (ret == -ENOSYS ) +dev_err_ratelimited (smmu->dev, +"Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cbfrsynra=0x%x, cb=%d\n" , fsr, iova, fsynr, cbfrsynra, idx);arm_smmu_cb_write (smmu, idx,ARM_SMMU_CB_FSR , fsr);
Signature · 1 line
2.31.1
PATCH RESEND v4 2/6 iommu/arm-smmu-qcom: Add an adreno-smmu-priv callback to get pagefault info
In reply to Rob ClarkFrom: Jordan Crouse <[email protected]>
Add a callback in adreno-smmu-priv to read interesting SMMU registers to provide an opportunity for a richer debug experience in the GPU driver.
--- drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 17 ++++++++++++ drivers/iommu/arm/arm-smmu/arm-smmu.h | 2 ++ include/linux/adreno-smmu-priv.h | 31 +++++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +17 -0
@@ -32,6 +32,22 @@ static void qcom_adreno_smmu_write_sctlr(struct arm_smmu_device *smmu, int idx,arm_smmu_cb_write (smmu, idx,ARM_SMMU_CB_SCTLR , reg); } +static void qcom_adreno_smmu_get_fault_info (const void *cookie, +struct adreno_smmu_fault_info *info) +{ +struct arm_smmu_domain *smmu_domain = (void *)cookie; +struct arm_smmu_cfg *cfg = &smmu_domain->cfg; +struct arm_smmu_device *smmu = smmu_domain->smmu; + + info->fsr =arm_smmu_cb_read (smmu, cfg->cbndx,ARM_SMMU_CB_FSR ); + info->fsynr0 =arm_smmu_cb_read (smmu, cfg->cbndx,ARM_SMMU_CB_FSYNR0 ); + info->fsynr1 =arm_smmu_cb_read (smmu, cfg->cbndx,ARM_SMMU_CB_FSYNR1 ); + info->far =arm_smmu_cb_readq (smmu, cfg->cbndx,ARM_SMMU_CB_FAR ); + info->cbfrsynra =arm_smmu_gr1_read (smmu,ARM_SMMU_GR1_CBFRSYNRA (cfg->cbndx)); + info->ttbr0 =arm_smmu_cb_read (smmu, cfg->cbndx,ARM_SMMU_CB_TTBR0 ); + info->contextidr =arm_smmu_cb_read (smmu, cfg->cbndx,ARM_SMMU_CB_CONTEXTIDR ); +} +#define QCOM_ADRENO_SMMU_GPU_SID 0static bool qcom_adreno_smmu_is_gpu_device (struct device *dev)
@@ -156,6 +172,7 @@ static int qcom_adreno_smmu_init_context(struct arm_smmu_domain *smmu_domain, priv->cookie = smmu_domain; priv->get_ttbr1_cfg = qcom_adreno_smmu_get_ttbr1_cfg; priv->set_ttbr0_cfg = qcom_adreno_smmu_set_ttbr0_cfg; + priv->get_fault_info = qcom_adreno_smmu_get_fault_info;return 0 ; }
drivers/iommu/arm/arm-smmu/arm-smmu.h +2 -0
@@ -224,6 +224,8 @@ enum arm_smmu_cbar_type {#define ARM_SMMU_CB_FSYNR0 0x68#define ARM_SMMU_FSYNR0_WNR BIT(4) +#define ARM_SMMU_CB_FSYNR1 0x6c +#define ARM_SMMU_CB_S1_TLBIVA 0x600#define ARM_SMMU_CB_S1_TLBIASID 0x610#define ARM_SMMU_CB_S1_TLBIVAL 0x620
include/linux/adreno-smmu-priv.h +30 -1
@@ -8,6 +8,32 @@#include <linux/io-pgtable.h> +/** +* struct adreno_smmu_fault_info - container for key fault information +* +* @far: The faulting IOVA from ARM_SMMU_CB_FAR +* @ttbr0: The current TTBR0 pagetable from ARM_SMMU_CB_TTBR0 +* @contextidr: The value of ARM_SMMU_CB_CONTEXTIDR +* @fsr: The fault status from ARM_SMMU_CB_FSR +* @fsynr0: The value of FSYNR0 from ARM_SMMU_CB_FSYNR0 +* @fsynr1: The value of FSYNR1 from ARM_SMMU_CB_FSYNR0 +* @cbfrsynra: The value of CBFRSYNRA from ARM_SMMU_GR1_CBFRSYNRA(idx) +* +* This struct passes back key page fault information to the GPU driver +* through the get_fault_info function pointer. +* The GPU driver can use this information to print informative +* log messages and provide deeper GPU specific insight into the fault. +*/ +struct adreno_smmu_fault_info { +u64 far; +u64 ttbr0; +u32 contextidr; +u32 fsr; +u32 fsynr0; +u32 fsynr1; +u32 cbfrsynra; +}; +/** * struct adreno_smmu_priv - private interface between adreno-smmu and GPU *
@@ -17,6 +43,8 @@* @set_ttbr0_cfg: Set the TTBR0 config for the GPUs context bank. A * NULL config disables TTBR0 translation, otherwise * TTBR0 translation is enabled with the specified cfg +* @get_fault_info: Called by the GPU fault handler to get information about +* the fault * * The GPU driver (drm/msm) and adreno-smmu work together for controlling * the GPU's SMMU instance. This is by necessity, as the GPU is directly
@@ -31,6 +59,7 @@ struct adreno_smmu_priv {const void *cookie;const struct io_pgtable_cfg *(*get_ttbr1_cfg)(const void *cookie);int (*set_ttbr0_cfg)(const void *cookie,const struct io_pgtable_cfg *cfg); + void (*get_fault_info)(const void *cookie, struct adreno_smmu_fault_info *info); }; -#endif /* __ADRENO_SMMU_PRIV_H */ +#endif /* __ADRENO_SMMU_PRIV_H */
Signature · 1 line
2.31.1
PATCH RESEND v4 3/6 drm/msm: Improve the a6xx page fault handler
In reply to Rob ClarkFrom: Jordan Crouse <[email protected]>
Use the new adreno-smmu-priv fault info function to get more SMMU debug registers and print the current TTBR0 to debug per-instance pagetables and figure out which GPU block generated the request.
--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 4 +- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 76 +++++++++++++++++++++++++-- drivers/gpu/drm/msm/msm_iommu.c | 11 +++- drivers/gpu/drm/msm/msm_mmu.h | 4 +- 4 files changed, 87 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +2 -2
@@ -1075,7 +1075,7 @@ bool a5xx_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring)return true; } -static int a5xx_fault_handler (void *arg,unsigned long iova,int flags) +static int a5xx_fault_handler (void *arg,unsigned long iova,int flags,void *data) {struct msm_gpu *gpu = arg; pr_warn_ratelimited("*** gpu fault: iova=%08lx, flags=%d (%u,%u,%u,%u)\n",
@@ -1085,7 +1085,7 @@ static int a5xx_fault_handler(void *arg, unsigned long iova, int flags)gpu_read (gpu,REG_A5XX_CP_SCRATCH_REG (6 )), gpu_read(gpu, REG_A5XX_CP_SCRATCH_REG(7))); -return -EFAULT ; +return 0 ; }static void a5xx_cp_err_irq (struct msm_gpu *gpu)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +73 -3
91 lines not on this page · raw message
drivers/gpu/drm/msm/msm_iommu.c +10 -1
@@ -211,8 +211,17 @@ static int msm_fault_handler(struct iommu_domain *domain, struct device *dev, unsigned long iova, int flags, void *arg) { struct msm_iommu *iommu = arg; +struct adreno_smmu_priv *adreno_smmu =dev_get_drvdata (iommu->base.dev); +struct adreno_smmu_fault_info info, *ptr =NULL ; + +if (adreno_smmu->get_fault_info) { + adreno_smmu->get_fault_info (adreno_smmu->cookie, &info); + ptr = &info; + } +if (iommu->base.handler) -return iommu->base.handler (iommu->base.arg, iova, flags); +return iommu->base.handler (iommu->base.arg, iova, flags, ptr); +pr_warn_ratelimited ("*** fault: iova=%16lx, flags=%d\n" , iova, flags);return 0 ; }
drivers/gpu/drm/msm/msm_mmu.h +2 -2
@@ -26,7 +26,7 @@ enum msm_mmu_type {struct msm_mmu {const struct msm_mmu_funcs *funcs;struct device *dev; -int (*handler)(void *arg,unsigned long iova,int flags); +int (*handler)(void *arg,unsigned long iova,int flags,void *data);void *arg;enum msm_mmu_type type; };
@@ -43,7 +43,7 @@ struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain);struct msm_mmu *msm_gpummu_new (struct device *dev,struct msm_gpu *gpu);static inline void msm_mmu_set_fault_handler (struct msm_mmu *mmu,void *arg, -int (*handler)(void *arg,unsigned long iova,int flags)) +int (*handler)(void *arg,unsigned long iova,int flags,void *data)) { mmu->arg = arg; mmu->handler = handler;
Signature · 1 line
2.31.1
PATCH RESEND v4 4/6 iommu/arm-smmu-qcom: Add stall support
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
Add, via the adreno-smmu-priv interface, a way for the GPU to request the SMMU to stall translation on faults, and then later resume the translation, either retrying or terminating the current translation.
This will be used on the GPU side to "freeze" the GPU while we snapshot useful state for devcoredump.
--- drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 33 ++++++++++++++++++++++ include/linux/adreno-smmu-priv.h | 7 +++++ 2 files changed, 40 insertions(+)
drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +33 -0
@@ -13,6 +13,7 @@ struct qcom_smmu {struct arm_smmu_device smmu;bool bypass_quirk;u8 bypass_cbndx; +u32 stall_enabled; };static struct qcom_smmu *to_qcom_smmu (struct arm_smmu_device *smmu)
@@ -23,12 +24,17 @@ static struct qcom_smmu *to_qcom_smmu(struct arm_smmu_device *smmu)static void qcom_adreno_smmu_write_sctlr (struct arm_smmu_device *smmu,int idx,u32 reg) { +struct qcom_smmu *qsmmu =to_qcom_smmu (smmu); +/* * On the GPU device we want to process subsequent transactions after a * fault to keep the GPU from hanging */ reg |=ARM_SMMU_SCTLR_HUPCF ; +if (qsmmu->stall_enabled &BIT (idx)) + reg |=ARM_SMMU_SCTLR_CFCFG ; +arm_smmu_cb_write (smmu, idx,ARM_SMMU_CB_SCTLR , reg); }
@@ -48,6 +54,31 @@ static void qcom_adreno_smmu_get_fault_info(const void *cookie, info->contextidr =arm_smmu_cb_read (smmu, cfg->cbndx,ARM_SMMU_CB_CONTEXTIDR ); } +static void qcom_adreno_smmu_set_stall (const void *cookie,bool enabled) +{ +struct arm_smmu_domain *smmu_domain = (void *)cookie; +struct arm_smmu_cfg *cfg = &smmu_domain->cfg; +struct qcom_smmu *qsmmu =to_qcom_smmu (smmu_domain->smmu); + +if (enabled) + qsmmu->stall_enabled |=BIT (cfg->cbndx); +else + qsmmu->stall_enabled &= ~BIT (cfg->cbndx); +} + +static void qcom_adreno_smmu_resume_translation (const void *cookie,bool terminate) +{ +struct arm_smmu_domain *smmu_domain = (void *)cookie; +struct arm_smmu_cfg *cfg = &smmu_domain->cfg; +struct arm_smmu_device *smmu = smmu_domain->smmu; +u32 reg =0 ; + +if (terminate) + reg |=ARM_SMMU_RESUME_TERMINATE ; + +arm_smmu_cb_write (smmu, cfg->cbndx,ARM_SMMU_CB_RESUME , reg); +} +#define QCOM_ADRENO_SMMU_GPU_SID 0static bool qcom_adreno_smmu_is_gpu_device (struct device *dev)
@@ -173,6 +204,8 @@ static int qcom_adreno_smmu_init_context(struct arm_smmu_domain *smmu_domain, priv->get_ttbr1_cfg = qcom_adreno_smmu_get_ttbr1_cfg; priv->set_ttbr0_cfg = qcom_adreno_smmu_set_ttbr0_cfg; priv->get_fault_info = qcom_adreno_smmu_get_fault_info; + priv->set_stall = qcom_adreno_smmu_set_stall; + priv->resume_translation = qcom_adreno_smmu_resume_translation;return 0 ; }
include/linux/adreno-smmu-priv.h +7 -0
@@ -45,6 +45,11 @@ struct adreno_smmu_fault_info {* TTBR0 translation is enabled with the specified cfg * @get_fault_info: Called by the GPU fault handler to get information about * the fault +* @set_stall: Configure whether stall on fault (CFCFG) is enabled. Call +* before set_ttbr0_cfg(). If stalling on fault is enabled, +* the GPU driver must call resume_translation() +* @resume_translation: Resume translation after a fault +* * * The GPU driver (drm/msm) and adreno-smmu work together for controlling * the GPU's SMMU instance. This is by necessity, as the GPU is directly
@@ -60,6 +65,8 @@ struct adreno_smmu_priv {const struct io_pgtable_cfg *(*get_ttbr1_cfg)(const void *cookie);int (*set_ttbr0_cfg)(const void *cookie,const struct io_pgtable_cfg *cfg);void (*get_fault_info)(const void *cookie,struct adreno_smmu_fault_info *info); +void (*set_stall)(const void *cookie,bool enabled); + void (*resume_translation)(const void *cookie, bool terminate); };#endif /* __ADRENO_SMMU_PRIV_H */
Signature · 6 lines
2.31.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND v4 5/6 drm/msm: Add crashdump support for stalled SMMU
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
For collecting devcoredumps with the SMMU stalled after an iova fault, we need to skip the parts of the GPU state which are normally collected with the hw crashdumper, since with the SMMU stalled the hw would be unable to write out the requested state to memory.
--- drivers/gpu/drm/msm/adreno/a2xx_gpu.c | 2 +- drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 2 +- drivers/gpu/drm/msm/adreno/a4xx_gpu.c | 2 +- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 5 ++- drivers/gpu/drm/msm/adreno/a6xx_gpu.h | 2 +- drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c | 43 ++++++++++++++++----- drivers/gpu/drm/msm/msm_debugfs.c | 2 +- drivers/gpu/drm/msm/msm_gpu.c | 7 ++-- drivers/gpu/drm/msm/msm_gpu.h | 2 +- 9 files changed, 47 insertions(+), 20 deletions(-)
drivers/gpu/drm/msm/adreno/a2xx_gpu.c +1 -1
@@ -434,7 +434,7 @@ static void a2xx_dump(struct msm_gpu *gpu)adreno_dump (gpu); } -static struct msm_gpu_state *a2xx_gpu_state_get (struct msm_gpu *gpu) +static struct msm_gpu_state *a2xx_gpu_state_get (struct msm_gpu *gpu,bool stalled) {struct msm_gpu_state *state =kzalloc (sizeof (*state),GFP_KERNEL );
drivers/gpu/drm/msm/adreno/a3xx_gpu.c +1 -1
@@ -464,7 +464,7 @@ static void a3xx_dump(struct msm_gpu *gpu)adreno_dump (gpu); } -static struct msm_gpu_state *a3xx_gpu_state_get (struct msm_gpu *gpu) +static struct msm_gpu_state *a3xx_gpu_state_get (struct msm_gpu *gpu,bool stalled) {struct msm_gpu_state *state =kzalloc (sizeof (*state),GFP_KERNEL );
drivers/gpu/drm/msm/adreno/a4xx_gpu.c +1 -1
@@ -549,7 +549,7 @@ static const unsigned int a405_registers[] = { ~0 /* sentinel */ }; -static struct msm_gpu_state *a4xx_gpu_state_get (struct msm_gpu *gpu) +static struct msm_gpu_state *a4xx_gpu_state_get (struct msm_gpu *gpu,bool stalled) {struct msm_gpu_state *state =kzalloc (sizeof (*state),GFP_KERNEL );
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +3 -2
@@ -1519,7 +1519,7 @@ static void a5xx_gpu_state_get_hlsq_regs(struct msm_gpu *gpu,msm_gem_kernel_put (dumper.bo, gpu->aspace, true); } -static struct msm_gpu_state *a5xx_gpu_state_get (struct msm_gpu *gpu) +static struct msm_gpu_state *a5xx_gpu_state_get (struct msm_gpu *gpu,bool stalled) {struct a5xx_gpu_state *a5xx_state =kzalloc (sizeof (*a5xx_state),GFP_KERNEL );
@@ -1536,7 +1536,8 @@ static struct msm_gpu_state *a5xx_gpu_state_get(struct msm_gpu *gpu) a5xx_state->base.rbbm_status =gpu_read (gpu,REG_A5XX_RBBM_STATUS );/* Get the HLSQ regs with the help of the crashdumper */ -a5xx_gpu_state_get_hlsq_regs (gpu, a5xx_state); +if (!stalled) +a5xx_gpu_state_get_hlsq_regs (gpu, a5xx_state);a5xx_set_hwcg (gpu, true);
drivers/gpu/drm/msm/adreno/a6xx_gpu.h +1 -1
@@ -86,7 +86,7 @@ unsigned long a6xx_gmu_get_freq(struct msm_gpu *gpu);void a6xx_show (struct msm_gpu *gpu,struct msm_gpu_state *state,struct drm_printer *p); -struct msm_gpu_state *a6xx_gpu_state_get (struct msm_gpu *gpu); +struct msm_gpu_state *a6xx_gpu_state_get (struct msm_gpu *gpu,bool stalled);int a6xx_gpu_state_put (struct msm_gpu_state *state);#endif /* __A6XX_GPU_H__ */
drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c +34 -9
63 lines not on this page · raw message
drivers/gpu/drm/msm/msm_debugfs.c +1 -1
@@ -77,7 +77,7 @@ static int msm_gpu_open(struct inode *inode, struct file *file) goto free_priv;pm_runtime_get_sync (&gpu->pdev->dev); - show_priv->state = gpu->funcs->gpu_state_get (gpu); + show_priv->state = gpu->funcs->gpu_state_get (gpu, false);pm_runtime_put_sync (&gpu->pdev->dev);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/msm/msm_gpu.c +4 -3
@@ -381,7 +381,8 @@ static void msm_gpu_crashstate_get_bo(struct msm_gpu_state *state, }static void msm_gpu_crashstate_capture (struct msm_gpu *gpu, -struct msm_gem_submit *submit,char *comm,char *cmd) +struct msm_gem_submit *submit,char *comm,char *cmd, +bool stalled) {struct msm_gpu_state *state;
@@ -393,7 +394,7 @@ static void msm_gpu_crashstate_capture(struct msm_gpu *gpu,if (gpu->crashstate)return ; - state = gpu->funcs->gpu_state_get (gpu); + state = gpu->funcs->gpu_state_get (gpu, stalled);if (IS_ERR_OR_NULL (state))return ;
@@ -519,7 +520,7 @@ static void recover_worker(struct kthread_work *work)/* Record the crash state */ pm_runtime_get_sync (&gpu->pdev->dev); -msm_gpu_crashstate_capture (gpu, submit, comm, cmd); +msm_gpu_crashstate_capture (gpu, submit, comm, cmd, false);pm_runtime_put_sync (&gpu->pdev->dev);kfree (cmd);
drivers/gpu/drm/msm/msm_gpu.h +1 -1
@@ -60,7 +60,7 @@ struct msm_gpu_funcs {void (*debugfs_init)(struct msm_gpu *gpu,struct drm_minor *minor);#endif unsigned long (*gpu_busy)(struct msm_gpu *gpu); -struct msm_gpu_state *(*gpu_state_get)(struct msm_gpu *gpu); +struct msm_gpu_state *(*gpu_state_get)(struct msm_gpu *gpu,bool stalled);int (*gpu_state_put)(struct msm_gpu_state *state);unsigned long (*gpu_get_freq)(struct msm_gpu *gpu);void (*gpu_set_freq)(struct msm_gpu *gpu,struct dev_pm_opp *opp);
Signature · 1 line
2.31.1
PATCH RESEND v4 6/6 drm/msm: devcoredump iommu fault support
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
Wire up support to stall the SMMU on iova fault, and collect a devcore- dump snapshot for easier debugging of faults.
Currently this is a6xx-only, but mostly only because so far it is the only one using adreno-smmu-priv.
--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 29 +++++++++++++-- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 15 ++++++++ drivers/gpu/drm/msm/msm_gem.h | 1 + drivers/gpu/drm/msm/msm_gem_submit.c | 1 + drivers/gpu/drm/msm/msm_gpu.c | 48 +++++++++++++++++++++++++ drivers/gpu/drm/msm/msm_gpu.h | 17 +++++++++ drivers/gpu/drm/msm/msm_gpummu.c | 5 +++ drivers/gpu/drm/msm/msm_iommu.c | 11 ++++++ drivers/gpu/drm/msm/msm_mmu.h | 1 + 9 files changed, 126 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +27 -2
@@ -1008,6 +1008,16 @@ static int a6xx_fault_handler(void *arg, unsigned long iova, int flags, void *dastruct msm_gpu *gpu = arg;struct adreno_smmu_fault_info *info = data;const char *type ="UNKNOWN" ; +const char *block; +bool do_devcoredump = info && !READ_ONCE (gpu->crashstate); + +/* +* If we aren't going to be resuming later from fault_worker, then do +* it now. +*/ +if (!do_devcoredump) { + gpu->aspace->mmu->funcs->resume_translation (gpu->aspace->mmu); + }/* * Print a default message if we couldn't get the data from the
@@ -1031,15 +1041,30 @@ static int a6xx_fault_handler(void *arg, unsigned long iova, int flags, void *daelse if (info->fsr &ARM_SMMU_FSR_EF ) type ="EXTERNAL" ; + block =a6xx_fault_block (gpu, info->fsynr1 &0xff ); +pr_warn_ratelimited ("*** gpu fault: ttbr0=%.16llx iova=%.16lx dir=%s type=%s source=%s (%u,%u,%u,%u)\n" , info->ttbr0, iova, - flags &IOMMU_FAULT_WRITE ?"WRITE" :"READ" , type, -a6xx_fault_block (gpu, info->fsynr1 &0xff ), + flags &IOMMU_FAULT_WRITE ?"WRITE" :"READ" , + type, block,gpu_read (gpu,REG_A6XX_CP_SCRATCH_REG (4 )),gpu_read (gpu,REG_A6XX_CP_SCRATCH_REG (5 )),gpu_read (gpu,REG_A6XX_CP_SCRATCH_REG (6 )),gpu_read (gpu,REG_A6XX_CP_SCRATCH_REG (7 ))); +if (do_devcoredump) { +/* Turn off the hangcheck timer to keep it from bothering us */ +del_timer (&gpu->hangcheck_timer); + + gpu->fault_info.ttbr0 = info->ttbr0; + gpu->fault_info.iova = iova; + gpu->fault_info.flags = flags; + gpu->fault_info.type = type; + gpu->fault_info.block = block; + +kthread_queue_work (gpu->worker, &gpu->fault_work); + } +return 0 ; }
drivers/gpu/drm/msm/adreno/adreno_gpu.c +15 -0
@@ -684,6 +684,21 @@ void adreno_show(struct msm_gpu *gpu, struct msm_gpu_state *state, adreno_gpu->info->revn, adreno_gpu->rev.core, adreno_gpu->rev.major, adreno_gpu->rev.minor, adreno_gpu->rev.patchid); +/* +* If this is state collected due to iova fault, so fault related info +* +* TTBR0 would not be zero, so this is a good way to distinguish +*/ +if (state->fault_info.ttbr0) { +const struct msm_gpu_fault_info *info = &state->fault_info; + +drm_puts (p,"fault-info:\n" ); +drm_printf (p," - ttbr0=%.16llx\n" , info->ttbr0); +drm_printf (p," - iova=%.16lx\n" , info->iova); +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); + }drm_printf (p,"rbbm-status: 0x%08x\n" , state->rbbm_status);
drivers/gpu/drm/msm/msm_gem.h +1 -0
@@ -328,6 +328,7 @@ struct msm_gem_submit {struct dma_fence *fence;struct msm_gpu_submitqueue *queue;struct pid *pid;/* submitting process */ +bool fault_dumped;/* Limit devcoredump dumping to one per submit */ bool valid;/* true if no cmdstream patching needed */ bool in_rb;/* "sudo" mode, copy cmds into RB */ struct msm_ringbuffer *ring;
drivers/gpu/drm/msm/msm_gem_submit.c +1 -0
@@ -50,6 +50,7 @@ static struct msm_gem_submit *submit_create(struct drm_device *dev, submit->cmd = (void *)&submit->bos[nr_bos]; submit->queue = queue; submit->ring = gpu->rb[queue->prio]; + submit->fault_dumped = false;/* initially, until copy_from_user() and bo lookup succeeds: */ submit->nr_bos =0 ;
drivers/gpu/drm/msm/msm_gpu.c +48 -0
66 lines not on this page · raw message
drivers/gpu/drm/msm/msm_gpu.h +17 -0
@@ -71,6 +71,15 @@ struct msm_gpu_funcs {uint32_t (*get_rptr)(struct msm_gpu *gpu,struct msm_ringbuffer *ring); }; +/* Additional state for iommu faults: */ +struct msm_gpu_fault_info { +u64 ttbr0; +unsigned long iova; +int flags; +const char *type; +const char *block; +}; +struct msm_gpu {const char *name;struct drm_device *dev;
@@ -135,6 +144,12 @@ struct msm_gpu {#define DRM_MSM_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_MSM_HANGCHECK_PERIOD)struct timer_list hangcheck_timer; +/* Fault info for most recent iova fault: */ +struct msm_gpu_fault_info fault_info; + +/* work for handling GPU ioval faults: */ +struct kthread_work fault_work; +/* work for handling GPU recovery: */ struct kthread_work recover_work;
@@ -243,6 +258,8 @@ struct msm_gpu_state {char *comm;char *cmd; +struct msm_gpu_fault_info fault_info; +int nr_bos;struct msm_gpu_state_bo *bos; };
drivers/gpu/drm/msm/msm_gpummu.c +5 -0
@@ -68,6 +68,10 @@ static int msm_gpummu_unmap(struct msm_mmu *mmu, uint64_t iova, size_t len)return 0 ; } +static void msm_gpummu_resume_translation (struct msm_mmu *mmu) +{ +} +static void msm_gpummu_destroy (struct msm_mmu *mmu) {struct msm_gpummu *gpummu =to_msm_gpummu (mmu);
@@ -83,6 +87,7 @@ static const struct msm_mmu_funcs funcs = { .map = msm_gpummu_map, .unmap = msm_gpummu_unmap, .destroy = msm_gpummu_destroy, + .resume_translation = msm_gpummu_resume_translation, };struct msm_mmu *msm_gpummu_new (struct device *dev,struct msm_gpu *gpu)
drivers/gpu/drm/msm/msm_iommu.c +11 -0
@@ -184,6 +184,9 @@ struct msm_mmu *msm_iommu_pagetable_create(struct msm_mmu *parent)* the arm-smmu driver as a trigger to set up TTBR0 */ if (atomic_inc_return (&iommu->pagetables) ==1 ) { +/* Enable stall on iommu fault: */ + adreno_smmu->set_stall (adreno_smmu->cookie, true); + ret = adreno_smmu->set_ttbr0_cfg (adreno_smmu->cookie, &ttbr0_cfg);if (ret) {free_io_pgtable_ops (pagetable->pgtbl_ops);
@@ -226,6 +229,13 @@ static int msm_fault_handler(struct iommu_domain *domain, struct device *dev,return 0 ; } +static void msm_iommu_resume_translation (struct msm_mmu *mmu) +{ +struct adreno_smmu_priv *adreno_smmu =dev_get_drvdata (mmu->dev); + + adreno_smmu->resume_translation (adreno_smmu->cookie, true); +} +static void msm_iommu_detach (struct msm_mmu *mmu) {struct msm_iommu *iommu =to_msm_iommu (mmu);
@@ -273,6 +283,7 @@ static const struct msm_mmu_funcs funcs = { .map = msm_iommu_map, .unmap = msm_iommu_unmap, .destroy = msm_iommu_destroy, + .resume_translation = msm_iommu_resume_translation, };struct msm_mmu *msm_iommu_new (struct device *dev,struct iommu_domain *domain)
drivers/gpu/drm/msm/msm_mmu.h +1 -0
@@ -15,6 +15,7 @@ struct msm_mmu_funcs { size_t len, int prot);int (*unmap)(struct msm_mmu *mmu,uint64_t iova,size_t len);void (*destroy)(struct msm_mmu *mmu); +void (*resume_translation)(struct msm_mmu *mmu); };enum msm_mmu_type {
Signature · 1 line
2.31.1
kernel test robot
build botRe: [RESEND PATCH v4 5/6] drm/msm: Add crashdump support for stalled SMMU
In reply to Rob ClarkI love your patch! Yet something to improve:
Hi Rob,
I love your patch! Yet something to improve:
[auto build test ERROR on iommu/next]
[also build test ERROR on drm-intel/for-linux-next drm-tip/drm-tip drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next linus/master v5.13-rc4 next-20210603] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Rob-Clark/iommu-arm-smmu-adreno-smmu-page-fault-handling/20210603-005246 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: arm64-randconfig-r001-20210603 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project d8e0ae9a76a62bdc6117630d59bf9967ac9bb4ea)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/cdbd07b471b955a50c15ea2a86f73c39bea6dfa5
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Rob-Clark/iommu-arm-smmu-adreno-smmu-page-fault-handling/20210603-005246 git checkout cdbd07b471b955a50c15ea2a86f73c39bea6dfa5
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/gpu/drm/msm/msm_gpu.c:510:53: error: too many arguments to function call, expected 4, have 5
msm_gpu_crashstate_capture(gpu, submit, comm, cmd, false);
~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~
drivers/gpu/drm/msm/msm_gpu.c:432:13: note: 'msm_gpu_crashstate_capture' declared here
static void msm_gpu_crashstate_capture(struct msm_gpu *gpu,
^1 error generated.
vim +510 drivers/gpu/drm/msm/msm_gpu.c
460
461 static void recover_worker(struct kthread_work *work)
462 {
463 struct msm_gpu *gpu = container_of(work, struct msm_gpu, recover_work);
464 struct drm_device *dev = gpu->dev;
465 struct msm_drm_private *priv = dev->dev_private;
466 struct msm_gem_submit *submit;
467 struct msm_ringbuffer *cur_ring = gpu->funcs->active_ring(gpu);
468 char *comm = NULL, *cmd = NULL;
469 int i;
470
471 mutex_lock(&dev->struct_mutex);
472
473 DRM_DEV_ERROR(dev->dev, "%s: hangcheck recover!\n", gpu->name);
474
475 submit = find_submit(cur_ring, cur_ring->memptrs->fence + 1);
476 if (submit) {
477 struct task_struct *task;
478
479 /* Increment the fault counts */
480 gpu->global_faults++;
481 submit->queue->faults++;
482
483 task = get_pid_task(submit->pid, PIDTYPE_PID);
484 if (task) {
485 comm = kstrdup(task->comm, GFP_KERNEL);
486 cmd = kstrdup_quotable_cmdline(task, GFP_KERNEL);
487 put_task_struct(task);
488 }
489
490 /* msm_rd_dump_submit() needs bo locked to dump: */
491 for (i = 0; i < submit->nr_bos; i++)
492 msm_gem_lock(&submit->bos[i].obj->base);
493
494 if (comm && cmd) {
495 DRM_DEV_ERROR(dev->dev, "%s: offending task: %s (%s)\n",
496 gpu->name, comm, cmd);
497
498 msm_rd_dump_submit(priv->hangrd, submit,
499 "offending task: %s (%s)", comm, cmd);
500 } else {
501 msm_rd_dump_submit(priv->hangrd, submit, NULL);
502 }
503
504 for (i = 0; i < submit->nr_bos; i++)
505 msm_gem_unlock(&submit->bos[i].obj->base);
506 }
507
508 /* Record the crash state */
509 pm_runtime_get_sync(&gpu->pdev->dev);
> 510 msm_gpu_crashstate_capture(gpu, submit, comm, cmd, false);
511 pm_runtime_put_sync(&gpu->pdev->dev);
512
513 kfree(cmd);
514 kfree(comm);
515
516 /*
517 * Update all the rings with the latest and greatest fence.. this
518 * needs to happen after msm_rd_dump_submit() to ensure that the
519 * bo's referenced by the offending submit are still around.
520 */
521 for (i = 0; i < gpu->nr_rings; i++) {
522 struct msm_ringbuffer *ring = gpu->rb[i];
523
524 uint32_t fence = ring->memptrs->fence;
525
526 /*
527 * For the current (faulting?) ring/submit advance the fence by
528 * one more to clear the faulting submit
529 */
530 if (ring == cur_ring)
531 fence++;
532
533 update_fences(gpu, ring, fence);
534 }
535
536 if (msm_gpu_active(gpu)) {
537 /* retire completed submits, plus the one that hung: */
538 retire_submits(gpu);
539
540 pm_runtime_get_sync(&gpu->pdev->dev);
541 gpu->funcs->recover(gpu);
542 pm_runtime_put_sync(&gpu->pdev->dev);
543
544 /*
545 * Replay all remaining submits starting with highest priority
546 * ring
547 */
548 for (i = 0; i < gpu->nr_rings; i++) {
549 struct msm_ringbuffer *ring = gpu->rb[i];
550
551 spin_lock(&ring->submit_lock);
552 list_for_each_entry(submit, &ring->submits, node)
553 gpu->funcs->submit(gpu, submit);
554 spin_unlock(&ring->submit_lock);
555 }
556 }
557
558 mutex_unlock(&dev->struct_mutex);
559
560 msm_gpu_retire(gpu);
561 }
562
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [RESEND PATCH v4 1/6] iommu/arm-smmu: Add support for driver IOMMU fault handlers
In reply to Rob ClarkQuoted 26 lines · Rob Clark
From: Jordan Crouse <[email protected]>
Call
report_iommu_fault()to allow upper-level drivers to register their own fault handlers.Signed-off-by Jordan Crouse <[email protected]>Signed-off-by Rob Clark <[email protected]>--- drivers/iommu/arm/arm-smmu/arm-smmu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/iommu/arm/arm-smmu/arm-smmu.c +1
-0@@ -408,6 +408,7 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev)struct arm_smmu_domain *smmu_domain =to_smmu_domain (domain);struct arm_smmu_device *smmu = smmu_domain->smmu;int idx = smmu_domain->cfg.cbndx; +int ret; fsr =arm_smmu_cb_read (smmu, idx,ARM_SMMU_CB_FSR );if (!(fsr &ARM_SMMU_FSR_FAULT ))@@ -417,8 +418,12 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev) iova =arm_smmu_cb_readq (smmu, idx,ARM_SMMU_CB_FAR ); cbfrsynra =arm_smmu_gr1_read (smmu,ARM_SMMU_GR1_CBFRSYNRA (idx));
drivers/iommu/arm/arm-smmu/arm-smmu.c static irqreturn_t arm_smmu_context_fault(int irq, void *dev) · line 427
Quoted 10 lines
drivers/iommu/arm/arm-smmu/arm-smmu.c +6
-2-dev_err_ratelimited (smmu->dev, -"Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cbfrsynra=0x%x, cb=%d\n" , + ret =report_iommu_fault (domain,NULL , iova, + fsynr &ARM_SMMU_FSYNR0_WNR ?IOMMU_FAULT_WRITE :IOMMU_FAULT_READ ); + +if (ret == -ENOSYS ) +dev_err_ratelimited (smmu->dev, +"Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cbfrsynra=0x%x, cb=%d\n" , fsr, iova, fsynr, cbfrsynra, idx);
Will