Skip to content

Commit

Permalink
drm/tests: Alloc drm_device on drm_exec tests
Browse files Browse the repository at this point in the history
The drm_exec tests where crashing[0] because of a null dereference. This
is caused by a new access of the `driver` attribute of `struct
drm_driver` on drm_gem_private_object_init(). Alloc the drm_device to
fix that.

[0]
[15:05:24] ================== drm_exec (6 subtests) ===================
[15:05:24] [PASSED] sanitycheck
^CERROR:root:Build interruption occurred. Cleaning console.
[15:05:50] [ERROR] Test: drm_exec: missing expected subtest!
[15:05:50] BUG: kernel NULL pointer dereference, address: 00000000000000b0
[15:05:50] #PF: supervisor read access in kernel mode
[15:05:50] #PF: error_code(0x0000) - not-present page
[15:05:50] PGD 0 P4D 0
[15:05:50] Oops: 0000 [#1] PREEMPT NOPTI
[15:05:50] CPU: 0 PID: 23 Comm: kunit_try_catch Tainted: G                 N 6.4.0-rc7-02032-ge6303f323b1a torvalds#69
[15:05:50] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.fc37 04/01/2014
[15:05:50] RIP: 0010:drm_gem_private_object_init+0x60/0xc0

Fixes: e6303f3 ("drm: manager to keep track of GPUs VA mappings")
Signed-off-by: Arthur Grillo <[email protected]>
Tested-by: Danilo Krummrich <[email protected]>
Acked-by: Danilo Krummrich <[email protected]>
Reviewed-by: Maíra Canal <[email protected]>
Signed-off-by: Maxime Ripard <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
Grillo-0 authored and jdpanderson committed Oct 8, 2023
1 parent cd576ab commit 13e33dc
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions drivers/gpu/drm/tests/drm_exec_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,35 @@

#include <drm/drm_exec.h>
#include <drm/drm_device.h>
#include <drm/drm_drv.h>
#include <drm/drm_gem.h>
#include <drm/drm_kunit_helpers.h>

#include "../lib/drm_random.h"

static struct drm_device dev;
struct drm_exec_priv {
struct device *dev;
struct drm_device *drm;
};

static int drm_exec_test_init(struct kunit *test)
{
struct drm_exec_priv *priv;

priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);

test->priv = priv;

priv->dev = drm_kunit_helper_alloc_device(test);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev);

priv->drm = __drm_kunit_helper_alloc_drm_device(test, priv->dev, sizeof(*priv->drm), 0,
DRIVER_MODESET);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->drm);

return 0;
}

static void sanitycheck(struct kunit *test)
{
Expand All @@ -29,11 +53,12 @@ static void sanitycheck(struct kunit *test)

static void test_lock(struct kunit *test)
{
struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj = { };
struct drm_exec exec;
int ret;

drm_gem_private_object_init(&dev, &gobj, PAGE_SIZE);
drm_gem_private_object_init(priv->drm, &gobj, PAGE_SIZE);

drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
drm_exec_until_all_locked(&exec) {
Expand All @@ -48,11 +73,12 @@ static void test_lock(struct kunit *test)

static void test_lock_unlock(struct kunit *test)
{
struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj = { };
struct drm_exec exec;
int ret;

drm_gem_private_object_init(&dev, &gobj, PAGE_SIZE);
drm_gem_private_object_init(priv->drm, &gobj, PAGE_SIZE);

drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
drm_exec_until_all_locked(&exec) {
Expand All @@ -74,11 +100,12 @@ static void test_lock_unlock(struct kunit *test)

static void test_duplicates(struct kunit *test)
{
struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj = { };
struct drm_exec exec;
int ret;

drm_gem_private_object_init(&dev, &gobj, PAGE_SIZE);
drm_gem_private_object_init(priv->drm, &gobj, PAGE_SIZE);

drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES);
drm_exec_until_all_locked(&exec) {
Expand All @@ -102,11 +129,12 @@ static void test_duplicates(struct kunit *test)

static void test_prepare(struct kunit *test)
{
struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj = { };
struct drm_exec exec;
int ret;

drm_gem_private_object_init(&dev, &gobj, PAGE_SIZE);
drm_gem_private_object_init(priv->drm, &gobj, PAGE_SIZE);

drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
drm_exec_until_all_locked(&exec) {
Expand All @@ -121,14 +149,15 @@ static void test_prepare(struct kunit *test)

static void test_prepare_array(struct kunit *test)
{
struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj1 = { };
struct drm_gem_object gobj2 = { };
struct drm_gem_object *array[] = { &gobj1, &gobj2 };
struct drm_exec exec;
int ret;

drm_gem_private_object_init(&dev, &gobj1, PAGE_SIZE);
drm_gem_private_object_init(&dev, &gobj2, PAGE_SIZE);
drm_gem_private_object_init(priv->drm, &gobj1, PAGE_SIZE);
drm_gem_private_object_init(priv->drm, &gobj2, PAGE_SIZE);

drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
drm_exec_until_all_locked(&exec)
Expand All @@ -150,6 +179,7 @@ static struct kunit_case drm_exec_tests[] = {

static struct kunit_suite drm_exec_test_suite = {
.name = "drm_exec",
.init = drm_exec_test_init,
.test_cases = drm_exec_tests,
};

Expand Down

0 comments on commit 13e33dc

Please sign in to comment.