Message ID | 20231105172718.18673-1-pazz@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2232695vqu; Sun, 5 Nov 2023 09:32:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIuCD3tk3y0H0u4kPJFR87Nb3ZCmYOu7PvDQs3omvRyjuEWPwAbs4mVc+gMx4x8zgKuMAJ X-Received: by 2002:a05:6e02:1846:b0:357:3d32:bf76 with SMTP id b6-20020a056e02184600b003573d32bf76mr43294433ilv.1.1699205524161; Sun, 05 Nov 2023 09:32:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699205524; cv=none; d=google.com; s=arc-20160816; b=ovc81fOj5kJE+J6UD5S4zaZqbwjGd3DJltMOSQpD+dOZEuOy9sXb7gkrXIbh9BlYb9 MNIhrL2We36WhVSFiBlIlFNKskskEEjbpiW6i5kzrmxa4dNRJI/Tpd+l9ZThNXMDHCxs gzJjbaFYQ4KsfLzkqmD8QS09BntA9mWEthSzc7O+2qJOEzcYyJPdSBMK+emIznROfeTh 2J/10R1kqAjLzi4LDSmtl3D9InM+9MO0Z6cvqjZXRJp5La/JyG0Jg1ZpmLEiRB3UuxRz 3hqnahOcgesw1M75IOb1cKTirnvHW/PLPNKgirrC8G+JYlD7lA/zMelZossNbt6E9sdQ GdSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=27FuzK5ZhNIAiarJZJb+WVFq6M3PPP0ewVP4DAogA48=; fh=aZttrWTsUHQcGbSn6Z1IHnI1nAUeij+60iLvM/AzvmU=; b=ufcl9kTwJfOnN7HE3Lv1zJHDn5OGc9z8k4cGltmcA0GDyB2b27GqP1MICsVfKhzTL0 aj/vp0D2Vm6wFqFZcDdFtew8j0f1CEO8eu1tG/nulKQpGZwjuaUYv5SrunNoWbp4DDR8 t2I9FGqa4Ys5yuxLKSTwxpNldgmlL7LL1QwIAoASPoQYnODtCd/LlkqHfhzTswfdVrRE 2dpDXLTNDKW+kFVu6gX+efzDYhjbqxz/L5nu77/gOEPoKfrS41ds4gZKEHglUrga1r2i iDjq3AneP0Agi0ttt+GC/EP9aFFMWbDtAkKElIt8CAQnqZvc0pvWLumu388ul20v40UL ukxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NY0oaXz5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l25-20020a656819000000b005acba4c9bf4si6162119pgt.2.2023.11.05.09.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 09:32:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NY0oaXz5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 134FD80A5F77; Sun, 5 Nov 2023 09:32:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229569AbjKER1a (ORCPT <rfc822;heyuhang3455@gmail.com> + 34 others); Sun, 5 Nov 2023 12:27:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbjKER13 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 5 Nov 2023 12:27:29 -0500 Received: from mail-ua1-x935.google.com (mail-ua1-x935.google.com [IPv6:2607:f8b0:4864:20::935]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E433C5 for <linux-kernel@vger.kernel.org>; Sun, 5 Nov 2023 09:27:27 -0800 (PST) Received: by mail-ua1-x935.google.com with SMTP id a1e0cc1a2514c-7b9ff2b6f9bso1616454241.3 for <linux-kernel@vger.kernel.org>; Sun, 05 Nov 2023 09:27:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1699205246; x=1699810046; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=27FuzK5ZhNIAiarJZJb+WVFq6M3PPP0ewVP4DAogA48=; b=NY0oaXz5lpbFVBBWPTazZnaAAs9DRbsKiAyXHz7e6uldu9QEbAqOV6X76meR/zSEnZ 72MWc4qQqAAcqLBlnAxfjX+gDQDZlXImiDKKRnT2HVh02CfMhALW6yyM0oejG2IGLpXl uJFuSOt0uQK5rfnPO5Ik6ZmW5+6Ro3Zji107M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699205246; x=1699810046; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=27FuzK5ZhNIAiarJZJb+WVFq6M3PPP0ewVP4DAogA48=; b=vcspi5BwmLp9GhB0NLvJJL07m6Y9fBSRMykSP03mswv3QBeQ+l8b0Azq5KPzR13tFA r5zKzrnl/Pvtsea4I8e7DceL2JH27yufw/rIcbXvSm4J+oZbrFne8stGQoeZQoFvagAE aUVT6Em5vhRfojXpGuEq8xslPlW61xJvHbs3v03OBQopLxL/n9SXq+EN9GNEDgI+igz4 3oE63Hzc0pCSoaRfek7JS/siaAaiFiSRHtBgWqsapHNaM0BZS83QiZJPO69fa2uYnVPp RAAxe+aQAoV0Uhvnv8+YYcg4h2Gjl+IR9o28G7OYuEVwiVLbJb2tDIrihfrzny2EvLx9 Bwwg== X-Gm-Message-State: AOJu0YzMIjRFbz/pD2l7SmpTYeIK3Lq/fqjMfpmGeTew0lI4e+2algWy tXRqIE+E1W3KlWRgrgxEYFjVXg== X-Received: by 2002:a05:6102:1085:b0:45d:8660:b91 with SMTP id s5-20020a056102108500b0045d86600b91mr7395347vsr.9.1699205246307; Sun, 05 Nov 2023 09:27:26 -0800 (PST) Received: from pazz.c.googlers.com.com (129.177.85.34.bc.googleusercontent.com. [34.85.177.129]) by smtp.gmail.com with ESMTPSA id h5-20020ac846c5000000b0041cbf113c28sm2635106qto.40.2023.11.05.09.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 09:27:25 -0800 (PST) From: Paz Zcharya <pazz@chromium.org> To: matthew.auld@intel.com, Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Sean Paul <seanpaul@chromium.org>, Subrata Banik <subratabanik@google.com>, Manasi Navare <navaremanasi@chromium.org>, Marcin Wojtas <mwojtas@chromium.org>, Drew Davenport <ddavenport@chromium.org>, Paz Zcharya <pazz@chromium.org>, Andrzej Hajda <andrzej.hajda@intel.com>, Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@gmail.com>, Jani Nikula <jani.nikula@linux.intel.com>, Joonas Lahtinen <joonas.lahtinen@linux.intel.com>, =?utf-8?q?Jouni_H=C3=B6g?= =?utf-8?q?ander?= <jouni.hogander@intel.com>, Nirmoy Das <nirmoy.das@intel.com>, Rodrigo Vivi <rodrigo.vivi@intel.com>, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>, =?utf-8?b?VmlsbGUgU3lyasOk?= =?utf-8?b?bMOk?= <ville.syrjala@linux.intel.com>, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/i915/display: Fix phys_base to be relative not absolute Date: Sun, 5 Nov 2023 17:27:03 +0000 Message-ID: <20231105172718.18673-1-pazz@chromium.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 05 Nov 2023 09:32:01 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781746131704910627 X-GMAIL-MSGID: 1781746131704910627 |
Series |
drm/i915/display: Fix phys_base to be relative not absolute
|
|
Commit Message
Paz Zcharya
Nov. 5, 2023, 5:27 p.m. UTC
Fix the value of variable `phys_base` to be the relative offset in
stolen memory, and not the absolute offset of the GSM.
Currently, the value of `phys_base` is set to "Surface Base Address,"
which in the case of Meter Lake is 0xfc00_0000. This causes the
function `i915_gem_object_create_region_at` to fail in line 128, when
it attempts to verify that the range does not overflow:
if (range_overflows(offset, size, resource_size(&mem->region)))
return ERR_PTR(-EINVAL);
where:
offset = 0xfc000000
size = 0x8ca000
mem->region.end + 1 = 0x4400000
mem->region.start = 0x800000
resource_size(&mem->region) = 0x3c00000
call stack:
i915_gem_object_create_region_at
initial_plane_vma
intel_alloc_initial_plane_obj
intel_find_initial_plane_obj
intel_crtc_initial_plane_config
Looking at the flow coming next, we see that `phys_base` is only used
once, in function `_i915_gem_object_stolen_init`, in the context of
the offset *in* the stolen memory. Combining that with an
examinination of the history of the file seems to indicate the
current value set is invalid.
call stack (functions using `phys_base`)
_i915_gem_object_stolen_init
__i915_gem_object_create_region
i915_gem_object_create_region_at
initial_plane_vma
intel_alloc_initial_plane_obj
intel_find_initial_plane_obj
intel_crtc_initial_plane_config
[drm:_i915_gem_object_stolen_init] creating preallocated stolen
object: stolen_offset=0x0000000000000000, size=0x00000000008ca000
Signed-off-by: Paz Zcharya <pazz@chromium.org>
---
drivers/gpu/drm/i915/display/intel_plane_initial.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Sun, Nov 05, 2023 at 05:27:03PM +0000, Paz Zcharya wrote: > Fix the value of variable `phys_base` to be the relative offset in > stolen memory, and not the absolute offset of the GSM. to me it looks like the other way around. phys_base is the physical base address for the frame_buffer. Setting it to zero doesn't seem to make that relative. And also doesn't look right. > > Currently, the value of `phys_base` is set to "Surface Base Address," > which in the case of Meter Lake is 0xfc00_0000. I don't believe this is a fixed value. IIRC this comes from the register set by video bios, where the idea is to reuse the fb that was used so far. With this in mind I don't understand how that could overflow. Maybe the size of the stolen is not right? maybe the size? maybe different memory region? > This causes the > function `i915_gem_object_create_region_at` to fail in line 128, when > it attempts to verify that the range does not overflow: > > if (range_overflows(offset, size, resource_size(&mem->region))) > return ERR_PTR(-EINVAL); > > where: > offset = 0xfc000000 > size = 0x8ca000 > mem->region.end + 1 = 0x4400000 > mem->region.start = 0x800000 > resource_size(&mem->region) = 0x3c00000 > > call stack: > i915_gem_object_create_region_at > initial_plane_vma > intel_alloc_initial_plane_obj > intel_find_initial_plane_obj > intel_crtc_initial_plane_config > > Looking at the flow coming next, we see that `phys_base` is only used > once, in function `_i915_gem_object_stolen_init`, in the context of > the offset *in* the stolen memory. Combining that with an > examinination of the history of the file seems to indicate the > current value set is invalid. > > call stack (functions using `phys_base`) > _i915_gem_object_stolen_init > __i915_gem_object_create_region > i915_gem_object_create_region_at > initial_plane_vma > intel_alloc_initial_plane_obj > intel_find_initial_plane_obj > intel_crtc_initial_plane_config > > [drm:_i915_gem_object_stolen_init] creating preallocated stolen > object: stolen_offset=0x0000000000000000, size=0x00000000008ca000 > > Signed-off-by: Paz Zcharya <pazz@chromium.org> > --- > > drivers/gpu/drm/i915/display/intel_plane_initial.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/i915/display/intel_plane_initial.c b/drivers/gpu/drm/i915/display/intel_plane_initial.c > index a55c09cbd0e4..e696cb13756a 100644 > --- a/drivers/gpu/drm/i915/display/intel_plane_initial.c > +++ b/drivers/gpu/drm/i915/display/intel_plane_initial.c > @@ -90,7 +90,7 @@ initial_plane_vma(struct drm_i915_private *i915, > "Using phys_base=%pa, based on initial plane programming\n", > &phys_base); > } else { > - phys_base = base; > + phys_base = 0; > mem = i915->mm.stolen_region; > } > > -- > 2.42.0.869.gea05f2083d-goog >
On Tue, Nov 14, 2023 at 10:13:59PM -0500, Rodrigo Vivi wrote: > On Sun, Nov 05, 2023 at 05:27:03PM +0000, Paz Zcharya wrote: > > Fix the value of variable `phys_base` to be the relative offset in > > stolen memory, and not the absolute offset of the GSM. > > to me it looks like the other way around. phys_base is the physical > base address for the frame_buffer. Setting it to zero doesn't seem > to make that relative. And also doesn't look right. > > > > > Currently, the value of `phys_base` is set to "Surface Base Address," > > which in the case of Meter Lake is 0xfc00_0000. > > I don't believe this is a fixed value. IIRC this comes from the register > set by video bios, where the idea is to reuse the fb that was used so > far. > > With this in mind I don't understand how that could overflow. Maybe > the size of the stolen is not right? maybe the size? maybe different > memory region? > Hi Rodrigo, thanks for the great comments. Apologies for using a wrong/confusing terminology. I think 'phys_base' is supposed to be the offset in the GEM BO, where base (or "Surface Base Address") is supposed to be the GTT offset. Other than what I wrote before, I noticed that the function 'i915_vma_pin' which calls to 'i915_gem_gtt_reserve' is the one that binds the right address space in the GTT for that stolen region. I see that in the function 'i915_vma_insert' (full call stack below), where if (flags & PIN_OFFSET_FIXED), then when calling 'i915_gem_gtt_reserve' we add an offset. Specifically in MeteorLake, and specifically when using GOP driver, this offset is equal to 0xfc00_0000. But as you mentioned, this is not strict. The if statement always renders true because in the function 'initial_plane_vma' we always set pinctl = PIN_GLOBAL | PIN_OFFSET_FIXED | base; where pinctl == flags (see file 'intel_plane_initial.c' line 145). Call stack: drm_mm_reserve_node i915_gem_gtt_reserve i915_vma_insert i915_vma_pin_ww i915_vma_pin initial_plane_vma intel_alloc_initial_plane_obj intel_find_initial_plane_obj Therefore, I believe the variable 'phys_base' in the function 'initial_plane_vma,' should be the the offset in the GEM BO and not the GTT offset, and because the base is added later on in the function 'i915_gem_gtt_reserve', this value should not be equal to base and be 0. Hope it makes more sense. > > This causes the > > function `i915_gem_object_create_region_at` to fail in line 128, when > > it attempts to verify that the range does not overflow: > > > > if (range_overflows(offset, size, resource_size(&mem->region))) > > return ERR_PTR(-EINVAL); > > > > where: > > offset = 0xfc000000 > > size = 0x8ca000 > > mem->region.end + 1 = 0x4400000 > > mem->region.start = 0x800000 > > resource_size(&mem->region) = 0x3c00000 > > > > call stack: > > i915_gem_object_create_region_at > > initial_plane_vma > > intel_alloc_initial_plane_obj > > intel_find_initial_plane_obj > > intel_crtc_initial_plane_config > > > > Looking at the flow coming next, we see that `phys_base` is only used > > once, in function `_i915_gem_object_stolen_init`, in the context of > > the offset *in* the stolen memory. Combining that with an > > examinination of the history of the file seems to indicate the > > current value set is invalid. > > > > call stack (functions using `phys_base`) > > _i915_gem_object_stolen_init > > __i915_gem_object_create_region > > i915_gem_object_create_region_at > > initial_plane_vma > > intel_alloc_initial_plane_obj > > intel_find_initial_plane_obj > > intel_crtc_initial_plane_config > > > > [drm:_i915_gem_object_stolen_init] creating preallocated stolen > > object: stolen_offset=0x0000000000000000, size=0x00000000008ca000 > > > > Signed-off-by: Paz Zcharya <pazz@chromium.org> > > --- > > > > drivers/gpu/drm/i915/display/intel_plane_initial.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/gpu/drm/i915/display/intel_plane_initial.c b/drivers/gpu/drm/i915/display/intel_plane_initial.c > > index a55c09cbd0e4..e696cb13756a 100644 > > --- a/drivers/gpu/drm/i915/display/intel_plane_initial.c > > +++ b/drivers/gpu/drm/i915/display/intel_plane_initial.c > > @@ -90,7 +90,7 @@ initial_plane_vma(struct drm_i915_private *i915, > > "Using phys_base=%pa, based on initial plane programming\n", > > &phys_base); > > } else { > > - phys_base = base; > > + phys_base = 0; > > mem = i915->mm.stolen_region; > > } > > > > -- > > 2.42.0.869.gea05f2083d-goog > >
On 18.11.2023 00:01, Paz Zcharya wrote: > On Tue, Nov 14, 2023 at 10:13:59PM -0500, Rodrigo Vivi wrote: >> On Sun, Nov 05, 2023 at 05:27:03PM +0000, Paz Zcharya wrote: >>> Fix the value of variable `phys_base` to be the relative offset in >>> stolen memory, and not the absolute offset of the GSM. >> >> to me it looks like the other way around. phys_base is the physical >> base address for the frame_buffer. Setting it to zero doesn't seem >> to make that relative. And also doesn't look right. >> >>> >>> Currently, the value of `phys_base` is set to "Surface Base Address," >>> which in the case of Meter Lake is 0xfc00_0000. >> >> I don't believe this is a fixed value. IIRC this comes from the register >> set by video bios, where the idea is to reuse the fb that was used so >> far. >> >> With this in mind I don't understand how that could overflow. Maybe >> the size of the stolen is not right? maybe the size? maybe different >> memory region? >> > > Hi Rodrigo, thanks for the great comments. > > Apologies for using a wrong/confusing terminology. I think 'phys_base' > is supposed to be the offset in the GEM BO, where base (or > "Surface Base Address") is supposed to be the GTT offset. Since base is taken from PLANE_SURF register it should be resolvable via GGTT to physical address pointing to actual framebuffer. I couldn't find anything in the specs. The simplest approach would be then do the same as in case of DGFX: gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; gen8_pte_t pte; gte += base / I915_GTT_PAGE_SIZE; pte = ioread64(gte); phys_base = pte & I915_GTT_PAGE_MASK; Regards Andrzej > > Other than what I wrote before, I noticed that the function 'i915_vma_pin' > which calls to 'i915_gem_gtt_reserve' is the one that binds the right > address space in the GTT for that stolen region. > > I see that in the function 'i915_vma_insert' (full call stack below), > where if (flags & PIN_OFFSET_FIXED), then when calling 'i915_gem_gtt_reserve' > we add an offset. > > Specifically in MeteorLake, and specifically when using GOP driver, this > offset is equal to 0xfc00_0000. But as you mentioned, this is not strict. > > The if statement always renders true because in the function > 'initial_plane_vma' we always set > pinctl = PIN_GLOBAL | PIN_OFFSET_FIXED | base; > where pinctl == flags (see file 'intel_plane_initial.c' line 145). > > Call stack: > drm_mm_reserve_node > i915_gem_gtt_reserve > i915_vma_insert > i915_vma_pin_ww > i915_vma_pin > initial_plane_vma > intel_alloc_initial_plane_obj > intel_find_initial_plane_obj > > Therefore, I believe the variable 'phys_base' in the > function 'initial_plane_vma,' should be the the offset in the GEM BO > and not the GTT offset, and because the base is added later on > in the function 'i915_gem_gtt_reserve', this value should not be > equal to base and be 0. > > Hope it makes more sense. > >>> This causes the >>> function `i915_gem_object_create_region_at` to fail in line 128, when >>> it attempts to verify that the range does not overflow: >>> >>> if (range_overflows(offset, size, resource_size(&mem->region))) >>> return ERR_PTR(-EINVAL); >>> >>> where: >>> offset = 0xfc000000 >>> size = 0x8ca000 >>> mem->region.end + 1 = 0x4400000 >>> mem->region.start = 0x800000 >>> resource_size(&mem->region) = 0x3c00000 >>> >>> call stack: >>> i915_gem_object_create_region_at >>> initial_plane_vma >>> intel_alloc_initial_plane_obj >>> intel_find_initial_plane_obj >>> intel_crtc_initial_plane_config >>> >>> Looking at the flow coming next, we see that `phys_base` is only used >>> once, in function `_i915_gem_object_stolen_init`, in the context of >>> the offset *in* the stolen memory. Combining that with an >>> examinination of the history of the file seems to indicate the >>> current value set is invalid. >>> >>> call stack (functions using `phys_base`) >>> _i915_gem_object_stolen_init >>> __i915_gem_object_create_region >>> i915_gem_object_create_region_at >>> initial_plane_vma >>> intel_alloc_initial_plane_obj >>> intel_find_initial_plane_obj >>> intel_crtc_initial_plane_config >>> >>> [drm:_i915_gem_object_stolen_init] creating preallocated stolen >>> object: stolen_offset=0x0000000000000000, size=0x00000000008ca000 >>> >>> Signed-off-by: Paz Zcharya <pazz@chromium.org> >>> --- >>> >>> drivers/gpu/drm/i915/display/intel_plane_initial.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/gpu/drm/i915/display/intel_plane_initial.c b/drivers/gpu/drm/i915/display/intel_plane_initial.c >>> index a55c09cbd0e4..e696cb13756a 100644 >>> --- a/drivers/gpu/drm/i915/display/intel_plane_initial.c >>> +++ b/drivers/gpu/drm/i915/display/intel_plane_initial.c >>> @@ -90,7 +90,7 @@ initial_plane_vma(struct drm_i915_private *i915, >>> "Using phys_base=%pa, based on initial plane programming\n", >>> &phys_base); >>> } else { >>> - phys_base = base; >>> + phys_base = 0; >>> mem = i915->mm.stolen_region; >>> } >>> >>> -- >>> 2.42.0.869.gea05f2083d-goog >>>
On 21.11.2023 13:06, Andrzej Hajda wrote: > On 18.11.2023 00:01, Paz Zcharya wrote: >> On Tue, Nov 14, 2023 at 10:13:59PM -0500, Rodrigo Vivi wrote: >>> On Sun, Nov 05, 2023 at 05:27:03PM +0000, Paz Zcharya wrote: >>>> Fix the value of variable `phys_base` to be the relative offset in >>>> stolen memory, and not the absolute offset of the GSM. >>> >>> to me it looks like the other way around. phys_base is the physical >>> base address for the frame_buffer. Setting it to zero doesn't seem >>> to make that relative. And also doesn't look right. >>> >>>> >>>> Currently, the value of `phys_base` is set to "Surface Base Address," >>>> which in the case of Meter Lake is 0xfc00_0000. >>> >>> I don't believe this is a fixed value. IIRC this comes from the register >>> set by video bios, where the idea is to reuse the fb that was used so >>> far. >>> >>> With this in mind I don't understand how that could overflow. Maybe >>> the size of the stolen is not right? maybe the size? maybe different >>> memory region? >>> >> >> Hi Rodrigo, thanks for the great comments. >> >> Apologies for using a wrong/confusing terminology. I think 'phys_base' >> is supposed to be the offset in the GEM BO, where base (or >> "Surface Base Address") is supposed to be the GTT offset. > > Since base is taken from PLANE_SURF register it should be resolvable via > GGTT to physical address pointing to actual framebuffer. > I couldn't find anything in the specs. It was quite cryptic. I meant I have not found anything about assumption from commit history that for iGPU there should be 1:1 mapping, this is why there was an assignment "phys_base = base". Possibly the assumption is not valid anymore for MTL(?). Without the assumption we need to check GGTT to determine phys address. > The simplest approach would be then do the same as in case of DGFX: > gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; > gen8_pte_t pte; > > gte += base / I915_GTT_PAGE_SIZE; > > pte = ioread64(gte); > phys_base = pte & I915_GTT_PAGE_MASK; > > Regards > Andrzej > > >> >> Other than what I wrote before, I noticed that the function >> 'i915_vma_pin' >> which calls to 'i915_gem_gtt_reserve' is the one that binds the right >> address space in the GTT for that stolen region. >> >> I see that in the function 'i915_vma_insert' (full call stack below), >> where if (flags & PIN_OFFSET_FIXED), then when calling >> 'i915_gem_gtt_reserve' >> we add an offset. >> >> Specifically in MeteorLake, and specifically when using GOP driver, this >> offset is equal to 0xfc00_0000. But as you mentioned, this is not strict. >> >> The if statement always renders true because in the function >> 'initial_plane_vma' we always set >> pinctl = PIN_GLOBAL | PIN_OFFSET_FIXED | base; >> where pinctl == flags (see file 'intel_plane_initial.c' line 145). >> >> Call stack: >> drm_mm_reserve_node >> i915_gem_gtt_reserve >> i915_vma_insert >> i915_vma_pin_ww >> i915_vma_pin >> initial_plane_vma >> intel_alloc_initial_plane_obj >> intel_find_initial_plane_obj >> >> Therefore, I believe the variable 'phys_base' in the >> function 'initial_plane_vma,' should be the the offset in the GEM BO >> and not the GTT offset, and because the base is added later on >> in the function 'i915_gem_gtt_reserve', this value should not be >> equal to base and be 0. >> >> Hope it makes more sense. >> >>>> This causes the >>>> function `i915_gem_object_create_region_at` to fail in line 128, when >>>> it attempts to verify that the range does not overflow: >>>> >>>> if (range_overflows(offset, size, resource_size(&mem->region))) >>>> return ERR_PTR(-EINVAL); >>>> >>>> where: >>>> offset = 0xfc000000 >>>> size = 0x8ca000 >>>> mem->region.end + 1 = 0x4400000 >>>> mem->region.start = 0x800000 >>>> resource_size(&mem->region) = 0x3c00000 >>>> >>>> call stack: >>>> i915_gem_object_create_region_at >>>> initial_plane_vma >>>> intel_alloc_initial_plane_obj >>>> intel_find_initial_plane_obj >>>> intel_crtc_initial_plane_config >>>> >>>> Looking at the flow coming next, we see that `phys_base` is only used >>>> once, in function `_i915_gem_object_stolen_init`, in the context of >>>> the offset *in* the stolen memory. Combining that with an >>>> examinination of the history of the file seems to indicate the >>>> current value set is invalid. >>>> >>>> call stack (functions using `phys_base`) >>>> _i915_gem_object_stolen_init >>>> __i915_gem_object_create_region >>>> i915_gem_object_create_region_at >>>> initial_plane_vma >>>> intel_alloc_initial_plane_obj >>>> intel_find_initial_plane_obj >>>> intel_crtc_initial_plane_config >>>> >>>> [drm:_i915_gem_object_stolen_init] creating preallocated stolen >>>> object: stolen_offset=0x0000000000000000, size=0x00000000008ca000 >>>> >>>> Signed-off-by: Paz Zcharya <pazz@chromium.org> >>>> --- >>>> >>>> drivers/gpu/drm/i915/display/intel_plane_initial.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/gpu/drm/i915/display/intel_plane_initial.c >>>> b/drivers/gpu/drm/i915/display/intel_plane_initial.c >>>> index a55c09cbd0e4..e696cb13756a 100644 >>>> --- a/drivers/gpu/drm/i915/display/intel_plane_initial.c >>>> +++ b/drivers/gpu/drm/i915/display/intel_plane_initial.c >>>> @@ -90,7 +90,7 @@ initial_plane_vma(struct drm_i915_private *i915, >>>> "Using phys_base=%pa, based on initial plane >>>> programming\n", >>>> &phys_base); >>>> } else { >>>> - phys_base = base; >>>> + phys_base = 0; >>>> mem = i915->mm.stolen_region; >>>> } >>>> -- >>>> 2.42.0.869.gea05f2083d-goog >>>> >
On Wed, Nov 22, 2023 at 02:26:55PM +0100, Andrzej Hajda wrote: > > > On 21.11.2023 13:06, Andrzej Hajda wrote: > > On 18.11.2023 00:01, Paz Zcharya wrote: > > > On Tue, Nov 14, 2023 at 10:13:59PM -0500, Rodrigo Vivi wrote: > > > > On Sun, Nov 05, 2023 at 05:27:03PM +0000, Paz Zcharya wrote: > > > > > > Hi Rodrigo, thanks for the great comments. > > > > > > Apologies for using a wrong/confusing terminology. I think 'phys_base' > > > is supposed to be the offset in the GEM BO, where base (or > > > "Surface Base Address") is supposed to be the GTT offset. > > > > Since base is taken from PLANE_SURF register it should be resolvable via > > GGTT to physical address pointing to actual framebuffer. > > I couldn't find anything in the specs. > > It was quite cryptic. I meant I have not found anything about assumption > from commit history that for iGPU there should be 1:1 mapping, this is why > there was an assignment "phys_base = base". Possibly the assumption is not > valid anymore for MTL(?). > Without the assumption we need to check GGTT to determine phys address. > > > The simplest approach would be then do the same as in case of DGFX: > > gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; > > gen8_pte_t pte; > > > > gte += base / I915_GTT_PAGE_SIZE; > > > > pte = ioread64(gte); > > phys_base = pte & I915_GTT_PAGE_MASK; > > > > Regards > > Andrzej Hey Andrzej, Sorry for the late response. I was OOO :) I tried using the code you mentioned. It translates (in the very specific case of MTL + GOP driver) to phys_base == 0080_0000h. Unfortunately, it results in a corrupted screen -- the framebuffer is filled with zeros. It seems like `i915_vma_pin_ww` already reserves and binds the GEM BO to the correct address space independently of the value of `phys_base`. The only thing `phys_base` affects is the value of `stolen->start` https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/i915/gem/i915_gem_stolen.c#L747 So it seems to me that the maybe `phys_base` is named incorrectly and that it does not reflect the physical address, but the start offset of i915->mm.stolen_region. I'm happy to run more tests / debug further. Do you have more ideas of things to try? Many thanks, Paz
On Mon, Nov 27, 2023 at 8:20 PM Paz Zcharya <pazz@chromium.org> wrote: > > On 21.11.2023 13:06, Andrzej Hajda wrote: > > On 18.11.2023 00:01, Paz Zcharya wrote: > > > On Tue, Nov 14, 2023 at 10:13:59PM -0500, Rodrigo Vivi wrote: > > > > On Sun, Nov 05, 2023 at 05:27:03PM +0000, Paz Zcharya wrote: > > > > > > Hi Rodrigo, thanks for the great comments. > > > > > > Apologies for using a wrong/confusing terminology. I think 'phys_base' > > > is supposed to be the offset in the GEM BO, where base (or > > > "Surface Base Address") is supposed to be the GTT offset. > > > > Since base is taken from PLANE_SURF register it should be resolvable via > > GGTT to physical address pointing to actual framebuffer. > > I couldn't find anything in the specs. > > It was quite cryptic. I meant I have not found anything about assumption > from commit history that for iGPU there should be 1:1 mapping, this is why > there was an assignment "phys_base = base". Possibly the assumption is not > valid anymore for MTL(?). > Without the assumption we need to check GGTT to determine phys address. > > > The simplest approach would be then do the same as in case of DGFX: > > gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; > > gen8_pte_t pte; > > > > gte += base / I915_GTT_PAGE_SIZE; > > > > pte = ioread64(gte); > > phys_base = pte & I915_GTT_PAGE_MASK; > > > > Regards > > Andrzej Hey Andrzej, On a second thought, what do you think about something like + gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; + gen8_pte_t pte; + gte += base / I915_GTT_PAGE_SIZE; + pte = ioread64(gte); + pte = pte & I915_GTT_PAGE_MASK; + phys_base = pte - i915->mm.stolen_region->region.start; The only difference is the last line. Based on what I wrote before, I think `phys_base` is named incorrectly and that it does not reflect the physical address, but the start offset of i915->mm.stolen_region. So if we offset the start value of the stolen region, this code looks correct to me (and it also works on my MeteorLake device). What do you think? Many thanks, Paz
On 28.11.2023 04:47, Paz Zcharya wrote: > > On Mon, Nov 27, 2023 at 8:20 PM Paz Zcharya <pazz@chromium.org> wrote: >> >> On 21.11.2023 13:06, Andrzej Hajda wrote: >>> On 18.11.2023 00:01, Paz Zcharya wrote: >>>> On Tue, Nov 14, 2023 at 10:13:59PM -0500, Rodrigo Vivi wrote: >>>>> On Sun, Nov 05, 2023 at 05:27:03PM +0000, Paz Zcharya wrote: >>>> >>>> Hi Rodrigo, thanks for the great comments. >>>> >>>> Apologies for using a wrong/confusing terminology. I think 'phys_base' >>>> is supposed to be the offset in the GEM BO, where base (or >>>> "Surface Base Address") is supposed to be the GTT offset. >>> >>> Since base is taken from PLANE_SURF register it should be resolvable via >>> GGTT to physical address pointing to actual framebuffer. >>> I couldn't find anything in the specs. >> >> It was quite cryptic. I meant I have not found anything about assumption >> from commit history that for iGPU there should be 1:1 mapping, this is why >> there was an assignment "phys_base = base". Possibly the assumption is not >> valid anymore for MTL(?). >> Without the assumption we need to check GGTT to determine phys address. >> >>> The simplest approach would be then do the same as in case of DGFX: >>> gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; >>> gen8_pte_t pte; >>> >>> gte += base / I915_GTT_PAGE_SIZE; >>> >>> pte = ioread64(gte); >>> phys_base = pte & I915_GTT_PAGE_MASK; >>> >>> Regards >>> Andrzej > > Hey Andrzej, > > On a second thought, what do you think about something like > > + gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; > + gen8_pte_t pte; > + gte += base / I915_GTT_PAGE_SIZE; > + pte = ioread64(gte); > + pte = pte & I915_GTT_PAGE_MASK; > + phys_base = pte - i915->mm.stolen_region->region.start; > > The only difference is the last line. Bingo :) It seems to be generic algorithm to get phys_base for all platforms: - on older platforms stolen_region points to system memory which starts at 0, - on DG2 it uses lmem region which starts at 0 as well, - on MTL stolen_region points to stolen-local which starts at 0x800000. So this whole "if (IS_DGFX(i915)) {...} else {...}" could be replaced with sth generic. 1. Find pte. 2. if(IS_DGFX(i915) && pte & GEN12_GGTT_PTE_LM) mem = i915->mm.regions[INTEL_REGION_LMEM_0] else mem = i915->mm.stolen_region 3. phys_base = (pte & I915_GTT_PAGE_MASK) - mem->region.start; Regards Andrzej > > Based on what I wrote before, I think `phys_base` is named incorrectly and > that it does not reflect the physical address, but the start offset of > i915->mm.stolen_region. So if we offset the start value of the stolen > region, this code looks correct to me (and it also works on my > MeteorLake device). > > What do you think? > > > Many thanks, > Paz >
On Tue, Nov 28, 2023 at 12:12:08PM +0100, Andrzej Hajda wrote: > On 28.11.2023 04:47, Paz Zcharya wrote: > > > > On Mon, Nov 27, 2023 at 8:20 PM Paz Zcharya <pazz@chromium.org> wrote: > > > > Hey Andrzej, > > > > On a second thought, what do you think about something like > > > > + gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; > > + gen8_pte_t pte; > > + gte += base / I915_GTT_PAGE_SIZE; > > + pte = ioread64(gte); > > + pte = pte & I915_GTT_PAGE_MASK; > > + phys_base = pte - i915->mm.stolen_region->region.start; > > > > The only difference is the last line. > > Bingo :) It seems to be generic algorithm to get phys_base for all > platforms: > - on older platforms stolen_region points to system memory which starts at > 0, > - on DG2 it uses lmem region which starts at 0 as well, > - on MTL stolen_region points to stolen-local which starts at 0x800000. > > So this whole "if (IS_DGFX(i915)) {...} else {...}" could be replaced > with sth generic. > 1. Find pte. > 2. if(IS_DGFX(i915) && pte & GEN12_GGTT_PTE_LM) mem = > i915->mm.regions[INTEL_REGION_LMEM_0] else mem = i915->mm.stolen_region > 3. phys_base = (pte & I915_GTT_PAGE_MASK) - mem->region.start; > > Regards > Andrzej > > Good stuff!! I'll work on this revision and resubmit. Thank you so much Andrzej!
On Tue, Nov 28, 2023 at 12:12:08PM +0100, Andrzej Hajda wrote: > On 28.11.2023 04:47, Paz Zcharya wrote: > > > > On Mon, Nov 27, 2023 at 8:20 PM Paz Zcharya <pazz@chromium.org> wrote: > > > > > > On 21.11.2023 13:06, Andrzej Hajda wrote: > > > > > > > The simplest approach would be then do the same as in case of DGFX: > > > > gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; > > > > gen8_pte_t pte; > > > > > > > > gte += base / I915_GTT_PAGE_SIZE; > > > > > > > > pte = ioread64(gte); > > > > phys_base = pte & I915_GTT_PAGE_MASK; > > > > > > > > Regards > > > > Andrzej > > > > Hey Andrzej, > > > > On a second thought, what do you think about something like > > > > + gen8_pte_t __iomem *gte = to_gt(i915)->ggtt->gsm; > > + gen8_pte_t pte; > > + gte += base / I915_GTT_PAGE_SIZE; > > + pte = ioread64(gte); > > + pte = pte & I915_GTT_PAGE_MASK; > > + phys_base = pte - i915->mm.stolen_region->region.start; > > > > The only difference is the last line. > > Bingo :) It seems to be generic algorithm to get phys_base for all > platforms: > - on older platforms stolen_region points to system memory which starts at > 0, > - on DG2 it uses lmem region which starts at 0 as well, > - on MTL stolen_region points to stolen-local which starts at 0x800000. > > So this whole "if (IS_DGFX(i915)) {...} else {...}" could be replaced > with sth generic. > 1. Find pte. > 2. if(IS_DGFX(i915) && pte & GEN12_GGTT_PTE_LM) mem = > i915->mm.regions[INTEL_REGION_LMEM_0] else mem = i915->mm.stolen_region > 3. phys_base = (pte & I915_GTT_PAGE_MASK) - mem->region.start; > > Regards > Andrzej > > Hey Andrzej, I uploaded https://patchwork.freedesktop.org/series/127130/ based on algorithm. Please take a look and let me know if you'd like me to change anything. Really appreciate all of your help! Best, Paz
diff --git a/drivers/gpu/drm/i915/display/intel_plane_initial.c b/drivers/gpu/drm/i915/display/intel_plane_initial.c index a55c09cbd0e4..e696cb13756a 100644 --- a/drivers/gpu/drm/i915/display/intel_plane_initial.c +++ b/drivers/gpu/drm/i915/display/intel_plane_initial.c @@ -90,7 +90,7 @@ initial_plane_vma(struct drm_i915_private *i915, "Using phys_base=%pa, based on initial plane programming\n", &phys_base); } else { - phys_base = base; + phys_base = 0; mem = i915->mm.stolen_region; }