From patchwork Wed Feb 23 19:12:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Souza, Jose" X-Patchwork-Id: 12757356 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 7AA26C433EF for ; Wed, 23 Feb 2022 19:10:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C4A5410E122; Wed, 23 Feb 2022 19:10:45 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id B2FE410E122 for ; Wed, 23 Feb 2022 19:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645643444; x=1677179444; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BkHxn6KZ1p3+RHhfVvUFevDfrZ9u/330lO2tvg9osjA=; b=MXGOsCbiNo+McQG9O02N6vxQo5NNJjCSUDveUYGe/DYJyaUQ0SVtDuNH i0Ryw+bAlSgOKn4J0HCc5Ip+A1TLs3S/7MsJ2UQSfgnfD9nYf9OyzO+6N n0hW8O+fwl5/uQPW87T2NvLPwcEMu0eCFzDpMURotBI4Z2nt4HuYRPZi0 C0qfphQAbn350mTCpJj9i3z4u2F2MgWgTcCucaH8hUSXIfT7j9upX+6h1 RRIIgocziI6IIYKCtl071WbpP7qIaYips5mYp+QuwYZMH1XY2UQU8CXAI fDf3fIQEzddD1p1kCuvZJJ9ChFYKvzeQ0RRWBSGd7h9Vqt8QYhp5OVCAP Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10267"; a="250887341" X-IronPort-AV: E=Sophos;i="5.88,391,1635231600"; d="scan'208";a="250887341" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2022 11:10:44 -0800 X-IronPort-AV: E=Sophos;i="5.88,391,1635231600"; d="scan'208";a="684012808" Received: from zhixinxi-mobl2.amr.corp.intel.com (HELO josouza-mobl2.amr.corp.intel.com) ([10.212.48.190]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2022 11:10:42 -0800 From: =?utf-8?q?Jos=C3=A9_Roberto_de_Souza?= To: intel-gfx@lists.freedesktop.org Date: Wed, 23 Feb 2022 11:12:56 -0800 Message-Id: <20220223191256.698239-1-jose.souza@intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] drm/i915: Check stolen memory size before calling drm_mm_init 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: , Cc: Steve Carbonari , Lucas De Marchi Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add check for zero usable stolen memory before calling drm_mm_init to support configurations where stolen memory exists but is fully reserved. Also skip memory test in such case. Cc: Ville Syrjälä Cc: Daniele Ceraolo Spurio Cc: Lucas De Marchi Signed-off-by: José Roberto de Souza Signed-off-by: Steve Carbonari --- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 9 ++++++--- drivers/gpu/drm/i915/intel_memory_region.c | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c index b9c3196b91cab..636cdf8a73b0a 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c @@ -497,13 +497,16 @@ static int i915_gem_init_stolen(struct intel_memory_region *mem) * memory, so just consider the start. */ reserved_total = stolen_top - reserved_base; + i915->stolen_usable_size = + resource_size(&i915->dsm) - reserved_total; + drm_dbg(&i915->drm, "Memory reserved for graphics device: %lluK, usable: %lluK\n", (u64)resource_size(&i915->dsm) >> 10, - ((u64)resource_size(&i915->dsm) - reserved_total) >> 10); + (u64)i915->stolen_usable_size >> 10); - i915->stolen_usable_size = - resource_size(&i915->dsm) - reserved_total; + if (i915->stolen_usable_size == 0) + return 0; /* Basic memrange allocator for stolen space. */ drm_mm_init(&i915->mm.stolen, 0, i915->stolen_usable_size); diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c index c70d7e286a512..1cbe194e01f6b 100644 --- a/drivers/gpu/drm/i915/intel_memory_region.c +++ b/drivers/gpu/drm/i915/intel_memory_region.c @@ -97,10 +97,14 @@ static int iomemtest(struct intel_memory_region *mem, bool test_all, const void *caller) { - resource_size_t last = resource_size(&mem->region) - PAGE_SIZE; - resource_size_t page; + resource_size_t last, page; int err; + if (resource_size(&mem->region) == 0) + return 0; + + last = resource_size(&mem->region) - PAGE_SIZE; + /* * Quick test to check read/write access to the iomap (backing store). *