From patchwork Sun Jun 16 07:03:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 13699441 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54818C27C6E for ; Sun, 16 Jun 2024 07:04:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E159710E14B; Sun, 16 Jun 2024 07:04:18 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="VtxqNsuT"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 355D310E14B; Sun, 16 Jun 2024 07:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718521457; x=1750057457; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3yzp8HPJZs3AbDjyqABYx/hljOmgtItfu+wrI/YE590=; b=VtxqNsuTEMifbqEbQh6w5s3e98uwFBagEFbFtxKZRlfomq9yQSOequRS j/uUFpc7VO4Vz8sTSzUhLmA7kyTGB0f8pwSwUoA1OkiXEnMrS3lUThOcf VT8DeOzS94v0GRhN0rrLPluyOSaHgc8AxL5GDNiAJq6f2EMHBUcMak/+u ueF/thuYk8Xw7IB7x3tNbpldES4ai+9lPIjCVxZJhH8mYHmTx87tHKRgp NGN3gURE8YQuzKq35Y3QJ2rmYBceLabH2UdpfeZHKFCERP/KdL4mgnBU1 7WKmFrvAJXKHRZ8L2fSzBGGbQdpie2Ye3wKShPAABfZ5/rVVqWEC+yQeT Q==; X-CSE-ConnectionGUID: d0fvoxoXTt+7AQ8IYILmBg== X-CSE-MsgGUID: c8U1GJCyQBe+A4DbG5v79w== X-IronPort-AV: E=McAfee;i="6700,10204,11104"; a="15504756" X-IronPort-AV: E=Sophos;i="6.08,241,1712646000"; d="scan'208";a="15504756" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2024 00:04:17 -0700 X-CSE-ConnectionGUID: 2Cl4e7pqQZWpBOuZGC96cQ== X-CSE-MsgGUID: e/tfwd75TFGhO9feD6y6jg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,241,1712646000"; d="scan'208";a="78379889" Received: from lfiedoro-mobl.ger.corp.intel.com (HELO intel.com) ([10.245.246.42]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2024 00:04:15 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Andi Shyti , Jonathan Cavitt Subject: [PATCH 1/2] drm/i915/gem: Return -EINVAL instead of '0' Date: Sun, 16 Jun 2024 09:03:48 +0200 Message-ID: <20240616070349.250899-2-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240616070349.250899-1-andi.shyti@linux.intel.com> References: <20240616070349.250899-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Commit 05da7d9f717b ("drm/i915/gem: Downgrade stolen lmem setup warning") returns '0' from i915_gem_stolen_lmem_setup(), but it's supposed to return a pointer to the intel_memory_region structure. Sparse complains with the following message: >> drivers/gpu/drm/i915/gem/i915_gem_stolen.c:943:32: sparse: sparse: Using plain integer as NULL pointer The caller checks for errors, and if no error is returned, it stores the address of the stolen memory. Therefore, we can't return NULL. Since we are handling a case of out-of-bounds, it's appropriate to treat the "lmem_size < dsm_base" case as an error. Return -EINVAL embedded in a pointer instead of '0' (or NULL). This way, we avoid a potential NULL pointer dereference. Since we are returning an error, it makes sense to print an error message with drm_err() instead of a debug message using drm_dbg(). Fixes: 05da7d9f717b ("drm/i915/gem: Downgrade stolen lmem setup warning") Signed-off-by: Andi Shyti Cc: Jonathan Cavitt --- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c index 004471f60117..bd774ce713cf 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c @@ -937,10 +937,10 @@ i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type, /* Use DSM base address instead for stolen memory */ dsm_base = intel_uncore_read64(uncore, GEN6_DSMBASE) & GEN11_BDSM_MASK; if (lmem_size < dsm_base) { - drm_dbg(&i915->drm, + drm_err(&i915->drm, "Disabling stolen memory support due to OOB placement: lmem_size = %lli vs dsm_base = %lli\n", lmem_size, dsm_base); - return 0; + return ERR_PTR(-EINVAL); } dsm_size = ALIGN_DOWN(lmem_size - dsm_base, SZ_1M); } From patchwork Sun Jun 16 07:03:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 13699442 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9DE69C27C6E for ; Sun, 16 Jun 2024 07:04:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A56E610E164; Sun, 16 Jun 2024 07:04:25 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="cfu/5EXM"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id BDE7F10E164; Sun, 16 Jun 2024 07:04:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718521463; x=1750057463; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z+Y0gvIoMUjU1pMDYQnweJSrbpXtsBroGjE0fuBTLqM=; b=cfu/5EXMvUE6lRo9HSEEMpAMm9anEzqj9Un4qgIq+COMiQitULEu6aVd pMxmscwf6kKS1VM/GMiWi84it1O6iyzvmwvYZIzdWeGvRUiwLm7TnO/ih RF2n6k50wIuhUQmGQOdEgJCD0CWPrEW0UHPEkjAFKXAu0k2Nkk7lHnKdU 5t8ELwzfOwGWKprVqln6nf0SvKY9CHvCLuWrNSWFxZKm1ARJ6WffVKjLl MeYqUVIL9j7PPBm76/xfCQbCIKRO+lNdvTNZQjU+PrFpJkxcGQHOYQLmY WG8yKORz9e7DydCOV5SUv3Su4Xfltg/mie03yDVSQpXJiIiYjsnFjY56w w==; X-CSE-ConnectionGUID: Tb0fiLwuTcGf7BbV43nG/w== X-CSE-MsgGUID: fRmrzEBVQj2GJwk09J8z/w== X-IronPort-AV: E=McAfee;i="6700,10204,11104"; a="15504766" X-IronPort-AV: E=Sophos;i="6.08,241,1712646000"; d="scan'208";a="15504766" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2024 00:04:23 -0700 X-CSE-ConnectionGUID: uzGyd0WdT0GFJxwsa6sbFQ== X-CSE-MsgGUID: 6cPC8UbBQyCtKJ2XY+xucw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,241,1712646000"; d="scan'208";a="78379930" Received: from lfiedoro-mobl.ger.corp.intel.com (HELO intel.com) ([10.245.246.42]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2024 00:04:22 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Andi Shyti , Jonathan Cavitt Subject: [PATCH 2/2] drm/i915/gem: Use the correct format specifier for resource_size_t Date: Sun, 16 Jun 2024 09:03:49 +0200 Message-ID: <20240616070349.250899-3-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240616070349.250899-1-andi.shyti@linux.intel.com> References: <20240616070349.250899-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Commit 05da7d9f717b ("drm/i915/gem: Downgrade stolen lmem setup warning") adds a debug message where the "lmem_size" and "dsm_base" variables are printed using the %lli identifier. However, these variables are defined as resource_size_t, which are unsigned long for 32-bit machines and unsigned long long for 64-bit machines. The documentation (core-api/printk-formats.rst) recommends using the %pa specifier for printing addresses and sizes of resources. Replace %lli with %pa. This patch also mutes the following sparse warning when compiling with: make W=1 ARCH=i386 drivers/gpu/drm/i915 >> drivers/gpu/drm/i915/gem/i915_gem_stolen.c:941:5: error: format '%lli' expects argument of type 'long long int', but argument 5 has type 'resource_size_t' {aka 'unsigned int'} [-Werror=format=] Signed-off-by: Andi Shyti Cc: Jonathan Cavitt --- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c index bd774ce713cf..d78afdcbe0fe 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c @@ -938,8 +938,8 @@ i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type, dsm_base = intel_uncore_read64(uncore, GEN6_DSMBASE) & GEN11_BDSM_MASK; if (lmem_size < dsm_base) { drm_err(&i915->drm, - "Disabling stolen memory support due to OOB placement: lmem_size = %lli vs dsm_base = %lli\n", - lmem_size, dsm_base); + "Disabling stolen memory support due to OOB placement: lmem_size = %pa vs dsm_base = %pa\n", + &lmem_size, &dsm_base); return ERR_PTR(-EINVAL); } dsm_size = ALIGN_DOWN(lmem_size - dsm_base, SZ_1M);