From 1f3ed97947a406a555a3efea05cab67da94172e7 Mon Sep 17 00:00:00 2001 From: Danilo Krummrich Date: Wed, 8 Nov 2023 03:26:07 +0100 Subject: [PATCH] drm/sched: fix potential page fault in drm_sched_job_init() Commit 56e449603f0a ("drm/sched: Convert the GPU scheduler to variable number of run-queues") introduces drm_err() in drm_sched_job_init(), in order to indicate that the given entity has no runq, however at this time job->sched is not yet set, likely to be NULL initialized, and hence shouldn't be used. Replace the corresponding drm_err() call with pr_err() to avoid a potential page fault. While at it, extend the documentation of drm_sched_job_init() to indicate that job->sched is not a valid pointer until drm_sched_job_arm() has been called. v2: Add pr_fmt to drm_printk.h. Add "*ERROR*" to this pr_err() message. (Luben) Fixes: 56e449603f0a ("drm/sched: Convert the GPU scheduler to variable number of run-queues") Signed-off-by: Danilo Krummrich Link: https://patchwork.freedesktop.org/patch/msgid/20231108022716.15250-1-dakr@redhat.com Signed-off-by: Luben Tuikov --- drivers/gpu/drm/scheduler/sched_main.c | 5 ++++- include/drm/drm_print.h | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index cd0dc3f81d05f0..bd13d4c8c385a8 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -680,6 +680,9 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs); * This function returns -ENOENT in this case (which probably should be -EIO as * a more meanigful return value). * + * Note that job->sched is not a valid pointer until drm_sched_job_arm() has + * been called. + * * Returns 0 for success, negative error code otherwise. */ int drm_sched_job_init(struct drm_sched_job *job, @@ -691,7 +694,7 @@ int drm_sched_job_init(struct drm_sched_job *job, * or worse--a blank screen--leave a trail in the * logs, so this can be debugged easier. */ - drm_err(job->sched, "%s: entity has no rq!\n", __func__); + pr_err("*ERROR* %s: entity has no rq!\n", __func__); return -ENOENT; } diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h index a93a387f8a1a15..0132d563c8cfb9 100644 --- a/include/drm/drm_print.h +++ b/include/drm/drm_print.h @@ -26,6 +26,15 @@ #ifndef DRM_PRINT_H_ #define DRM_PRINT_H_ +/* Define this before including linux/printk.h, so that the format + * string in pr_*() macros is correctly set for DRM. If a file wants + * to define this to something else, it should do so before including + * this header file. + */ +#ifndef pr_fmt +#define pr_fmt(fmt) "[drm] " fmt +#endif + #include #include #include base-commit: 8d88e4cdce4f5c56de55174a4d32ea9c06f7fa66 -- 2.42.1