Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/msm: Add fault-injection support

Intended as a way to trigger error paths in mesa.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Patchwork: https://patchwork.freedesktop.org/patch/496710/
Link: https://lore.kernel.org/r/20220807172848.2432845-1-robdclark@gmail.com

+30
+8
drivers/gpu/drm/msm/msm_debugfs.c
··· 7 7 #ifdef CONFIG_DEBUG_FS 8 8 9 9 #include <linux/debugfs.h> 10 + #include <linux/fault-inject.h> 10 11 11 12 #include <drm/drm_debugfs.h> 12 13 #include <drm/drm_file.h> ··· 327 326 328 327 if (priv->kms && priv->kms->funcs->debugfs_init) 329 328 priv->kms->funcs->debugfs_init(priv->kms, minor); 329 + 330 + #ifdef CONFIG_FAULT_INJECTION 331 + fault_create_debugfs_attr("fail_gem_alloc", minor->debugfs_root, 332 + &fail_gem_alloc); 333 + fault_create_debugfs_attr("fail_gem_iova", minor->debugfs_root, 334 + &fail_gem_iova); 335 + #endif 330 336 } 331 337 #endif 332 338
+15
drivers/gpu/drm/msm/msm_drv.c
··· 6 6 */ 7 7 8 8 #include <linux/dma-mapping.h> 9 + #include <linux/fault-inject.h> 9 10 #include <linux/kthread.h> 10 11 #include <linux/sched/mm.h> 11 12 #include <linux/uaccess.h> ··· 78 77 static bool modeset = true; 79 78 MODULE_PARM_DESC(modeset, "Use kernel modesetting [KMS] (1=on (default), 0=disable)"); 80 79 module_param(modeset, bool, 0600); 80 + 81 + #ifdef CONFIG_FAULT_INJECTION 82 + DECLARE_FAULT_ATTR(fail_gem_alloc); 83 + DECLARE_FAULT_ATTR(fail_gem_iova); 84 + #endif 81 85 82 86 static irqreturn_t msm_irq(int irq, void *arg) 83 87 { ··· 707 701 flags |= MSM_BO_WC; 708 702 } 709 703 704 + if (should_fail(&fail_gem_alloc, args->size)) 705 + return -ENOMEM; 706 + 710 707 return msm_gem_new_handle(dev, file, args->size, 711 708 args->flags, &args->handle, NULL); 712 709 } ··· 771 762 if (!priv->gpu) 772 763 return -EINVAL; 773 764 765 + if (should_fail(&fail_gem_iova, obj->size)) 766 + return -ENOMEM; 767 + 774 768 /* 775 769 * Don't pin the memory here - just get an address so that userspace can 776 770 * be productive ··· 794 782 /* Only supported if per-process address space is supported: */ 795 783 if (priv->gpu->aspace == ctx->aspace) 796 784 return -EOPNOTSUPP; 785 + 786 + if (should_fail(&fail_gem_iova, obj->size)) 787 + return -ENOMEM; 797 788 798 789 return msm_gem_set_iova(obj, ctx->aspace, iova); 799 790 }
+7
drivers/gpu/drm/msm/msm_drv.h
··· 34 34 #include <drm/msm_drm.h> 35 35 #include <drm/drm_gem.h> 36 36 37 + #ifdef CONFIG_FAULT_INJECTION 38 + extern struct fault_attr fail_gem_alloc; 39 + extern struct fault_attr fail_gem_iova; 40 + #else 41 + # define should_fail(attr, size) 0 42 + #endif 43 + 37 44 struct msm_kms; 38 45 struct msm_gpu; 39 46 struct msm_mmu;