[PATCH] drm/tests: Alloc drm_device on drm_exec tests

Maxime Ripard mripard at redhat.com
Fri Jul 28 14:33:57 UTC 2023


Hi,

On Thu, Jul 27, 2023 at 04:22:59PM -0300, Arthur Grillo wrote:
> 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 #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: e6303f323b1a ("drm: manager to keep track of GPUs VA mappings")
> Signed-off-by: Arthur Grillo <arthurgrillo at riseup.net>

You should Cc the list of people returned by scripts/get_maintainers.pl
for all your patches.

> ---
>  drivers/gpu/drm/tests/drm_exec_test.c | 36 +++++++++++++++++++++------
>  1 file changed, 29 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tests/drm_exec_test.c b/drivers/gpu/drm/tests/drm_exec_test.c
> index 727ac267682e..df31f89a7945 100644
> --- a/drivers/gpu/drm/tests/drm_exec_test.c
> +++ b/drivers/gpu/drm/tests/drm_exec_test.c
> @@ -12,11 +12,31 @@
>  
>  #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;
> +static struct device *dev;
> +static struct drm_device *drm;
> +
> +static int test_init(struct kunit *test)
> +{
> +	dev = drm_kunit_helper_alloc_device(test);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
> +
> +	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0,
> +						  DRIVER_MODESET);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
> +
> +	return 0;
> +}
> +
> +static void test_exit(struct kunit *test)
> +{
> +	drm_kunit_helper_free_device(test, dev);
> +}

You shouldn't be using a global variable here. test->priv is meant for
those kind of things.

Maxime
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20230728/3eec04b2/attachment.sig>


More information about the dri-devel mailing list