From nobody Thu Jan 1 11:01:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48417C25B46 for ; Mon, 23 Oct 2023 20:18:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231213AbjJWUSQ (ORCPT ); Mon, 23 Oct 2023 16:18:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230202AbjJWUSK (ORCPT ); Mon, 23 Oct 2023 16:18:10 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB4E210E for ; Mon, 23 Oct 2023 13:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698092241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dl1QUMiwke7YPVfNkVdbN9szUlQ85JjU5x5y/2sjjXc=; b=GDg+lg6QrU4WOBjKRs8T25qntJOweqYN0gzlApIBoj+6UiYxQdVH6S0i4Y0fOrNcenypiG gRAWy+IoisSSk+bykcQHTQYm+DO2Zyafi1dSZy1qqIWaW2mhzCMSB+HwHTTeOUmVhpef2o Epq9gerGbuhgJ+aubimUZLa/nVPag7c= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-HlNR1yMXNMWrgjlPUNTgNA-1; Mon, 23 Oct 2023 16:17:09 -0400 X-MC-Unique: HlNR1yMXNMWrgjlPUNTgNA-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-5079630993dso3643166e87.1 for ; Mon, 23 Oct 2023 13:17:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698092228; x=1698697028; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dl1QUMiwke7YPVfNkVdbN9szUlQ85JjU5x5y/2sjjXc=; b=xUyxmNeXoiN7P7vOuO/to43HBmeEM6vX3JZswIH3DWd8UI/y2IBEjQy/Ovm0a4+MoE Q4OX/QflsLkRfbEkF0YTRH5Dx/bIEiI1hvqqm8VXxgj0eLizZz1g1UudzMpHulD9RVMc YQJy/1qZoawxJpDgeRTxE0MLWYjuiLz+W5lOqB8mG5rLoXAsx1ai2v7j1HgUp+M0xUmV PH7jFBiq5I/a2G5TAqlB0EW7I9kVAoQCcPCekM3yDErTickx5X/cV7v96LYd00HbL1k9 FI8VJ2g55JGoSfM24se+FZMwui2oMounbVbxmvcF3G/IEbho8BP2J6LeY1NofBeNTjWd jgGQ== X-Gm-Message-State: AOJu0YxuaFbwVQG1yAu7pPe+XCrwUlef1UcBqGpU71yOz98Og2cVJk9j 0czYxyfgcSyqaVVyDurRsbIhKb52CMXqvTR1n2O3gLW4l0q7chgZtTp0nRkUqNAJuq3xco8KenW r87QvuvwIyripfmDH0nqAEPjq X-Received: by 2002:ac2:4113:0:b0:503:95b:db0a with SMTP id b19-20020ac24113000000b00503095bdb0amr7241726lfi.12.1698092228042; Mon, 23 Oct 2023 13:17:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHc8IaarDdkL02rtXTnQFw/nUBILwsxuD1DzIExz/OJTQMf7p6tTc0LZCr3oYiKFVJCnadRfA== X-Received: by 2002:ac2:4113:0:b0:503:95b:db0a with SMTP id b19-20020ac24113000000b00503095bdb0amr7241717lfi.12.1698092227628; Mon, 23 Oct 2023 13:17:07 -0700 (PDT) Received: from cassiopeiae.. ([2a02:810d:4b3f:de9c:642:1aff:fe31:a19f]) by smtp.gmail.com with ESMTPSA id i7-20020a50fc07000000b00534e791296bsm6734384edr.37.2023.10.23.13.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 13:17:07 -0700 (PDT) From: Danilo Krummrich To: airlied@gmail.com, daniel@ffwll.ch, matthew.brost@intel.com, thomas.hellstrom@linux.intel.com, sarah.walker@imgtec.com, donald.robson@imgtec.com, boris.brezillon@collabora.com, christian.koenig@amd.com, faith@gfxstrand.net Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH drm-misc-next v7 1/7] drm/gpuvm: convert WARN() to drm_WARN() variants Date: Mon, 23 Oct 2023 22:16:47 +0200 Message-ID: <20231023201659.25332-2-dakr@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023201659.25332-1-dakr@redhat.com> References: <20231023201659.25332-1-dakr@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use drm_WARN() and drm_WARN_ON() variants to indicate drivers the context the failing VM resides in. Signed-off-by: Danilo Krummrich Reviewed-by: Thomas Hellstr=C3=B6m --- drivers/gpu/drm/drm_gpuvm.c | 32 ++++++++++++++------------ drivers/gpu/drm/nouveau/nouveau_uvmm.c | 3 ++- include/drm/drm_gpuvm.h | 7 ++++++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/drm_gpuvm.c b/drivers/gpu/drm/drm_gpuvm.c index 08c088319652..d7367a202fee 100644 --- a/drivers/gpu/drm/drm_gpuvm.c +++ b/drivers/gpu/drm/drm_gpuvm.c @@ -614,12 +614,12 @@ static int __drm_gpuva_insert(struct drm_gpuvm *gpuvm, static void __drm_gpuva_remove(struct drm_gpuva *va); =20 static bool -drm_gpuvm_check_overflow(u64 addr, u64 range) +drm_gpuvm_check_overflow(struct drm_gpuvm *gpuvm, u64 addr, u64 range) { u64 end; =20 - return WARN(check_add_overflow(addr, range, &end), - "GPUVA address limited to %zu bytes.\n", sizeof(end)); + return drm_WARN(gpuvm->drm, check_add_overflow(addr, range, &end), + "GPUVA address limited to %zu bytes.\n", sizeof(end)); } =20 static bool @@ -647,7 +647,7 @@ static bool drm_gpuvm_range_valid(struct drm_gpuvm *gpuvm, u64 addr, u64 range) { - return !drm_gpuvm_check_overflow(addr, range) && + return !drm_gpuvm_check_overflow(gpuvm, addr, range) && drm_gpuvm_in_mm_range(gpuvm, addr, range) && !drm_gpuvm_in_kernel_node(gpuvm, addr, range); } @@ -656,6 +656,7 @@ drm_gpuvm_range_valid(struct drm_gpuvm *gpuvm, * drm_gpuvm_init() - initialize a &drm_gpuvm * @gpuvm: pointer to the &drm_gpuvm to initialize * @name: the name of the GPU VA space + * @drm: the &drm_device this VM resides in * @start_offset: the start offset of the GPU VA space * @range: the size of the GPU VA space * @reserve_offset: the start of the kernel reserved GPU VA area @@ -668,8 +669,8 @@ drm_gpuvm_range_valid(struct drm_gpuvm *gpuvm, * &name is expected to be managed by the surrounding driver structures. */ void -drm_gpuvm_init(struct drm_gpuvm *gpuvm, - const char *name, +drm_gpuvm_init(struct drm_gpuvm *gpuvm, const char *name, + struct drm_device *drm, u64 start_offset, u64 range, u64 reserve_offset, u64 reserve_range, const struct drm_gpuvm_ops *ops) @@ -677,20 +678,20 @@ drm_gpuvm_init(struct drm_gpuvm *gpuvm, gpuvm->rb.tree =3D RB_ROOT_CACHED; INIT_LIST_HEAD(&gpuvm->rb.list); =20 - drm_gpuvm_check_overflow(start_offset, range); - gpuvm->mm_start =3D start_offset; - gpuvm->mm_range =3D range; - gpuvm->name =3D name ? name : "unknown"; gpuvm->ops =3D ops; + gpuvm->drm =3D drm; =20 - memset(&gpuvm->kernel_alloc_node, 0, sizeof(struct drm_gpuva)); + drm_gpuvm_check_overflow(gpuvm, start_offset, range); + gpuvm->mm_start =3D start_offset; + gpuvm->mm_range =3D range; =20 + memset(&gpuvm->kernel_alloc_node, 0, sizeof(struct drm_gpuva)); if (reserve_range) { gpuvm->kernel_alloc_node.va.addr =3D reserve_offset; gpuvm->kernel_alloc_node.va.range =3D reserve_range; =20 - if (likely(!drm_gpuvm_check_overflow(reserve_offset, + if (likely(!drm_gpuvm_check_overflow(gpuvm, reserve_offset, reserve_range))) __drm_gpuva_insert(gpuvm, &gpuvm->kernel_alloc_node); } @@ -712,8 +713,8 @@ drm_gpuvm_destroy(struct drm_gpuvm *gpuvm) if (gpuvm->kernel_alloc_node.va.range) __drm_gpuva_remove(&gpuvm->kernel_alloc_node); =20 - WARN(!RB_EMPTY_ROOT(&gpuvm->rb.tree.rb_root), - "GPUVA tree is not empty, potentially leaking memory."); + drm_WARN(gpuvm->drm, !RB_EMPTY_ROOT(&gpuvm->rb.tree.rb_root), + "GPUVA tree is not empty, potentially leaking memory.\n"); } EXPORT_SYMBOL_GPL(drm_gpuvm_destroy); =20 @@ -795,7 +796,8 @@ drm_gpuva_remove(struct drm_gpuva *va) struct drm_gpuvm *gpuvm =3D va->vm; =20 if (unlikely(va =3D=3D &gpuvm->kernel_alloc_node)) { - WARN(1, "Can't destroy kernel reserved node.\n"); + drm_WARN(gpuvm->drm, 1, + "Can't destroy kernel reserved node.\n"); return; } =20 diff --git a/drivers/gpu/drm/nouveau/nouveau_uvmm.c b/drivers/gpu/drm/nouve= au/nouveau_uvmm.c index 5cf892c50f43..aaf5d28bd587 100644 --- a/drivers/gpu/drm/nouveau/nouveau_uvmm.c +++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.c @@ -1808,6 +1808,7 @@ int nouveau_uvmm_init(struct nouveau_uvmm *uvmm, struct nouveau_cli *cli, u64 kernel_managed_addr, u64 kernel_managed_size) { + struct drm_device *drm =3D cli->drm->dev; int ret; u64 kernel_managed_end =3D kernel_managed_addr + kernel_managed_size; =20 @@ -1836,7 +1837,7 @@ nouveau_uvmm_init(struct nouveau_uvmm *uvmm, struct n= ouveau_cli *cli, uvmm->kernel_managed_addr =3D kernel_managed_addr; uvmm->kernel_managed_size =3D kernel_managed_size; =20 - drm_gpuvm_init(&uvmm->base, cli->name, + drm_gpuvm_init(&uvmm->base, cli->name, drm, NOUVEAU_VA_SPACE_START, NOUVEAU_VA_SPACE_END, kernel_managed_addr, kernel_managed_size, diff --git a/include/drm/drm_gpuvm.h b/include/drm/drm_gpuvm.h index bdfafc4a7705..687fd5893624 100644 --- a/include/drm/drm_gpuvm.h +++ b/include/drm/drm_gpuvm.h @@ -29,6 +29,7 @@ #include #include =20 +#include #include =20 struct drm_gpuvm; @@ -201,6 +202,11 @@ struct drm_gpuvm { */ const char *name; =20 + /** + * @drm: the &drm_device this VM lives in + */ + struct drm_device *drm; + /** * @mm_start: start of the VA space */ @@ -241,6 +247,7 @@ struct drm_gpuvm { }; =20 void drm_gpuvm_init(struct drm_gpuvm *gpuvm, const char *name, + struct drm_device *drm, u64 start_offset, u64 range, u64 reserve_offset, u64 reserve_range, const struct drm_gpuvm_ops *ops); --=20 2.41.0