NetBSD Problem Report #56648

From manu@netbsd.org  Fri Jan 21 02:10:54 2022
Return-Path: <manu@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id BD6411A9239
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 21 Jan 2022 02:10:54 +0000 (UTC)
Message-Id: <20220121021054.381EC84E73@mail.netbsd.org>
Date: Fri, 21 Jan 2022 02:10:54 +0000 (UTC)
From: manu@netbsd.org
Reply-To: manu@netbsd.org
To: gnats-bugs@NetBSD.org
Subject: i915drmkms fails to detect output
X-Send-Pr-Version: 3.95

>Number:         56648
>Category:       kern
>Synopsis:       i915drmkms fails to detect output
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 21 02:15:01 +0000 2022
>Closed-Date:    Sat Aug 05 16:35:57 +0000 2023
>Last-Modified:  Sat Aug 05 16:35:57 +0000 2023
>Originator:     Emmanuel Dreyfus
>Release:        NetBSD-current/amd64
>Organization:
NetBSD
>Environment:
System: NetBSD basalte 9.99.93 NetBSD 9.99.93 (GENERIC) #94: Fri Jan  7 03:55:44 CET 2022  manu@basalte:/home2/manu/netbsd-src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
The machine is a notebook with Intel UHD Graphis 615. It features an internal dispay (eDP1) and an external HDMI output.

Since the recent DRM update, the integrated dispaly now works with i195drmkms, but it fails to detect a display conenced on the external HDMI output. xrandr says:
# xrandr -d :0
Screen 0: minimum 8 x 8, current 1920 x 1200, maximum 32767 x 32767
eDP1 connected primary 1920x1200+0+0 left (normal left inverted right x axis y axis) 90mm x 150mm
   1200x1920     55.00*+
   DP1 disconnected (normal left inverted right x axis y axis)
   HDMI1 disconnected (normal left inverted right x axis y axis)
   HDMI2 disconnected (normal left inverted right x axis y axis)
   VIRTUAL1 disconnected (normal left inverted right x axis y axis)

   When booting (UEFI mode) the external display works and automatically mirrors the integrated display. It gets blank when i915drmkms takes over the display during boot time.
>How-To-Repeat:
 Use the machine :-/
>Fix:
 Not known yet

>Release-Note:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/56648: i915drmkms fails to detect output
Date: Fri, 21 Jan 2022 11:19:45 +0100

 Duplicate of kern/56608 ?

From: Emmanuel Dreyfus <manu@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/56648: i915drmkms fails to detect output
Date: Fri, 21 Jan 2022 13:33:50 +0000

 On Fri, Jan 21, 2022 at 10:20:01AM +0000, Martin Husemann wrote:
 >  Duplicate of kern/56608 ?

 Note quite: in my case it finds the display connected to eDP1.

 -- 
 Emmanuel Dreyfus
 manu@netbsd.org

From: Emmanuel Dreyfus <manu@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/56648: i915drmkms fails to detect output
Date: Sat, 22 Jan 2022 02:19:38 +0000

 On Fri, Jan 21, 2022 at 01:33:50PM +0000, Emmanuel Dreyfus wrote:
 > On Fri, Jan 21, 2022 at 10:20:01AM +0000, Martin Husemann wrote:
 > >  Duplicate of kern/56608 ?
 > 
 > Note quite: in my case it finds the display connected to eDP1.

 I made some progress!

 The external HDMI1 actually works, it is just unable to probe the 
 output for a connected screen. Configuring the mode manually using cvt
 and xrandr produces a working HDMI1 output for X11. 

 Mode data obtained using cvt 1920 1080

 xrandr --output HDMI1 --newmode "1920x1080_60.00"  \
         173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
 xrandr --output HDMI1 --addmode HDMI1 "1920x1080_60.00" 
 xrandr --output HDMI1 --mode "1920x1080_60.00" 

 This produces a mirrored output. xrandr --output HDMI1 --left-of eDP1
 caused a panic:
 panic: kernel diagnostic assertion "!(vma->ggtt_view.type)" failed: file "/home2/manu/netbsd-src/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c", line 1769

 -- 
 Emmanuel Dreyfus
 manu@netbsd.org

State-Changed-From-To: open->feedback
State-Changed-By: maya@NetBSD.org
State-Changed-When: Sun, 22 May 2022 22:25:32 +0000
State-Changed-Why:
Is the monitor detected correctly with the latest GMBUS changes? also, are you seeing this panic still?


From: Emmanuel Dreyfus <manu@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/56648 (i915drmkms fails to detect output)
Date: Tue, 24 May 2022 15:31:30 +0000

 On Sun, May 22, 2022 at 10:25:32PM +0000, maya@NetBSD.org wrote:
 > Is the monitor detected correctly with the latest GMBUS changes? also, are you seeing this panic still?

 I was not able to get a panic, and the modes are now properly detected.
 However, I had a hard to to convince HDMI1 to actually output something.
 It hapenend once by luck, but most of the time it reamins black. eDP1
 works fine.


 -- 
 Emmanuel Dreyfus
 manu@netbsd.org

State-Changed-From-To: feedback->open
State-Changed-By: maya@NetBSD.org
State-Changed-When: Fri, 27 May 2022 01:15:16 +0000
State-Changed-Why:
some issues remain


State-Changed-From-To: open->feedback
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sun, 09 Jul 2023 20:01:22 +0000
State-Changed-Why:
Can you get dmesg with `boot -v -x'?

Can you boot normally, set `sysctl -w hw.drm2.__drm_debug=6', and
unplug/replug the HDMI display, and share dmesg?


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56648 CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gt
Date: Sun, 9 Jul 2023 20:24:06 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sun Jul  9 20:24:06 UTC 2023

 Modified Files:
 	src/sys/external/bsd/drm2/dist/drm/i915/gt: intel_ggtt.c

 Log Message:
 i915: Fail gracefully, don't panic, with unsupported ggtt views.

 Workaround for part of PR kern/56648.

 XXX pullup-10


 To generate a diff of this commit:
 cvs rdiff -u -r1.15 -r1.16 \
     src/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Taylor R Campbell <riastradh@NetBSD.org>
To: manu@NetBSD.org
Cc: gnats-bugs@NetBSD.org
Subject: Re: kern/56648: i915drmkms fails to detect output
Date: Sun, 9 Jul 2023 22:02:36 +0000

 This is a multi-part message in MIME format.
 --=_3GH/d8a4GiEuk6sY511/abKYWvHzDwXu

 For the panic on xrandr:

 1. Can you verify that with HEAD (intel_ggtt.c 1.16), the panic is
    gone?  It won't work -- but we shouldn't panic, at least.

 2. Can you see whether the attached patch on top of HEAD makes the
    functionality work?

 --=_3GH/d8a4GiEuk6sY511/abKYWvHzDwXu
 Content-Type: text/plain; charset="ISO-8859-1"; name="i915rotateremap"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename="i915rotateremap.patch"

 From cdc07f918cec0d2bed86f0ac8d2c1848e9f9dceb Mon Sep 17 00:00:00 2001
 From: Taylor R Campbell <riastradh@NetBSD.org>
 Date: Sun, 9 Jul 2023 22:00:18 +0000
 Subject: [PATCH] WIP: i915: Implement rotate and remap views.

 ---
  .../bsd/drm2/dist/drm/i915/gt/intel_ggtt.c    | 186 ++++++++++++------
  1 file changed, 126 insertions(+), 60 deletions(-)

 diff --git a/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c b/sys/exte=
 rnal/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c
 index 4da9f00317c4..044d632a80cb 100644
 --- a/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c
 +++ b/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c
 @@ -1433,7 +1433,30 @@ void i915_gem_restore_gtt_mappings(struct drm_i915_p=
 rivate *i915)
  		setup_private_pat(ggtt->vm.gt->uncore);
  }
 =20
 -#ifndef __NetBSD__
 +#ifdef __NetBSD__
 +static int
 +ensure_view_dmamap(struct drm_i915_gem_object *obj, struct sg_table *st)
 +{
 +	int ret;
 +
 +	/* XXX KASSERT?  */
 +	if (obj->mm.pages->sgl->sg_dmamap =3D=3D NULL)
 +		return 0;
 +
 +	/* XXX errno NetBSD->Linux */
 +	ret =3D -bus_dmamap_create(obj->base.dev->dmat,
 +	    (bus_size_t)st->nents << PAGE_SHIFT,
 +	    st->nents, PAGE_SIZE, 0, BUS_DMA_NOWAIT,
 +	    &st->sgl->sg_dmamap);
 +	if (ret) {
 +		st->sgl->sg_dmamap =3D NULL;
 +		return ret;
 +	}
 +
 +	st->sgl->sg_dmat =3D obj->base.dev->dmat;
 +	return 0;
 +}
 +#endif
 =20
  static struct scatterlist *
  rotate_pages(struct drm_i915_gem_object *obj, unsigned int offset,
 @@ -1447,18 +1470,43 @@ rotate_pages(struct drm_i915_gem_object *obj, unsig=
 ned int offset,
  	for (column =3D 0; column < width; column++) {
  		src_idx =3D stride * (height - 1) + column + offset;
  		for (row =3D 0; row < height; row++) {
 +#ifdef __NetBSD__
 +			/*
 +			 * XXX Do we need to handle >1-page segments
 +			 * here?
 +			 */
 +			CTASSERT(PAGE_SIZE =3D=3D I915_GTT_PAGE_SIZE);
 +			KASSERTMSG(src_idx <=3D obj->mm.pages->sgl->sg_npgs,
 +			    "src_idx=3D%u npgs=3D%u",
 +			    src_idx, obj->mm.pages->sgl->sg_npgs);
 +			sg->sg_pgs[st->nents] =3D
 +			    obj->mm.pages->sgl->sg_pgs[src_idx / PAGE_SIZE];
 +			if (obj->mm.pages->sgl->sg_dmamap) {
 +				bus_dmamap_t m =3D obj->mm.pages->sgl->sg_dmamap;
 +
 +				KASSERTMSG(src_idx <=3D m->dm_nsegs,
 +				    "src_idx=3D%u dm_nsegs=3D%d",
 +				    src_idx, m->dm_nsegs);
 +				sg->sg_dmamap->dm_segs[st->nents].ds_addr =3D
 +				    m->dm_segs[src_idx / PAGE_SIZE].ds_addr;
 +				sg->sg_dmamap->dm_segs[st->nents].ds_len =3D
 +				    PAGE_SIZE;
 +			}
 +#endif
  			st->nents++;
  			/*
  			 * We don't need the pages, but need to initialize
  			 * the entries so the sg list can be happily traversed.
  			 * The only thing we need are DMA addresses.
  			 */
 +#ifndef __NetBSD__
  			sg_set_page(sg, NULL, I915_GTT_PAGE_SIZE, 0);
  			sg_dma_address(sg) =3D
  				i915_gem_object_get_dma_address(obj, src_idx);
  			sg_dma_len(sg) =3D I915_GTT_PAGE_SIZE;
  			sg =3D sg_next(sg);
  			src_idx -=3D stride;
 +#endif
  		}
  	}
 =20
 @@ -1484,6 +1532,14 @@ intel_rotate_pages(struct intel_rotation_info *rot_i=
 nfo,
  	if (ret)
  		goto err_sg_alloc;
 =20
 +#ifdef __NetBSD__
 +	ret =3D ensure_view_dmamap(obj, st);
 +	if (ret) {
 +		sg_free_table(st);
 +		goto err_sg_alloc;
 +	}
 +#endif
 +
  	st->nents =3D 0;
  	sg =3D st->sgl;
 =20
 @@ -1493,6 +1549,10 @@ intel_rotate_pages(struct intel_rotation_info *rot_i=
 nfo,
  				  rot_info->plane[i].stride, st, sg);
  	}
 =20
 +#ifdef __NetBSD__
 +	KASSERTMSG(st->nents =3D=3D size, "nents=3D%u size=3D%u", st->nents, size=
 );
 +#endif
 +
  	return st;
 =20
  err_sg_alloc:
 @@ -1513,6 +1573,7 @@ remap_pages(struct drm_i915_gem_object *obj, unsigned=
  int offset,
  {
  	unsigned int row;
 =20
 +	/* height pages */
  	for (row =3D 0; row < height; row++) {
  		unsigned int left =3D width * I915_GTT_PAGE_SIZE;
 =20
 @@ -1530,12 +1591,38 @@ remap_pages(struct drm_i915_gem_object *obj, unsign=
 ed int offset,
 =20
  			length =3D min(left, length);
 =20
 +#ifdef __NetBSD__
 +			/*
 +			 * XXX Do we need to handle >1-page segments
 +			 * here?
 +			 */
 +			KASSERTMSG(length <=3D PAGE_SIZE, "length=3D%u", length);
 +			KASSERTMSG(offset <=3D obj->mm.pages->sgl->sg_npgs,
 +			    "offset=3D%u npgs=3D%u",
 +			    offset, obj->mm.pages->sgl->sg_npgs);
 +			sg->sg_pgs[st->nents] =3D
 +			    obj->mm.pages->sgl->sg_pgs[offset / PAGE_SIZE];
 +			if (obj->mm.pages->sgl->sg_dmamap) {
 +				bus_dmamap_t m =3D obj->mm.pages->sgl->sg_dmamap;
 +
 +				KASSERTMSG(offset <=3D m->dm_nsegs,
 +				    "offset=3D%u dm_nsegs=3D%d",
 +				    offset, m->dm_nsegs);
 +				sg->sg_dmamap->dm_segs[st->nents].ds_addr =3D
 +				    addr;
 +				sg->sg_dmamap->dm_segs[st->nents].ds_len =3D
 +				    length;
 +			}
 +#endif
 +
  			st->nents++;
 =20
 +#ifndef __NetBSD__
  			sg_set_page(sg, NULL, length, 0);
  			sg_dma_address(sg) =3D addr;
  			sg_dma_len(sg) =3D length;
  			sg =3D sg_next(sg);
 +#endif
 =20
  			offset +=3D length / I915_GTT_PAGE_SIZE;
  			left -=3D length;
 @@ -1566,6 +1653,14 @@ intel_remap_pages(struct intel_remapped_info *rem_in=
 fo,
  	if (ret)
  		goto err_sg_alloc;
 =20
 +#ifdef __NetBSD__
 +	ret =3D ensure_view_dmamap(obj, st);
 +	if (ret) {
 +		sg_free_table(st);
 +		goto err_sg_alloc;
 +	}
 +#endif
 +
  	st->nents =3D 0;
  	sg =3D st->sgl;
 =20
 @@ -1575,6 +1670,10 @@ intel_remap_pages(struct intel_remapped_info *rem_in=
 fo,
  				 rem_info->plane[i].stride, st, sg);
  	}
 =20
 +#ifdef __NetBSD__
 +	KASSERTMSG(st->nents =3D=3D size, "nents=3D%u size=3D%u", st->nents, size=
 );
 +#endif
 +
  	i915_sg_trim(st);
 =20
  	return st;
 @@ -1589,15 +1688,36 @@ err_st_alloc:
  	return ERR_PTR(ret);
  }
 =20
 -#endif	/* __NetBSD__ */
 -
  static noinline struct sg_table *
  intel_partial_pages(const struct i915_ggtt_view *view,
  		    struct drm_i915_gem_object *obj)
  {
 +	struct sg_table *st;
 +	struct scatterlist *sg, *iter;
 +	unsigned int count =3D view->partial.size;
 +	unsigned int offset;
 +	int ret;
 +
 +	st =3D kmalloc(sizeof(*st), GFP_KERNEL);
 +	if (!st) {
 +		ret =3D -ENOMEM;
 +		goto err_st_alloc;
 +	}
 +
 +	ret =3D sg_alloc_table(st, count, GFP_KERNEL);
 +	if (ret)
 +		goto err_sg_alloc;
 +
  #ifdef __NetBSD__
 -	struct sg_table *st =3D NULL;
 -	int ret =3D -ENOMEM;
 +	__USE(sg);
 +	__USE(iter);
 +	__USE(offset);
 +
 +	ret =3D ensure_view_dmamap(obj, st);
 +	if (ret) {
 +		sg_free_table(st);
 +		goto err_sg_alloc;
 +	}
 =20
  	KASSERTMSG(view->partial.offset <=3D obj->base.size >> PAGE_SHIFT,
  	    "obj=3D%p size=3D0x%zx; view offset=3D0x%zx size=3D0x%zx",
 @@ -1615,29 +1735,6 @@ intel_partial_pages(const struct i915_ggtt_view *vie=
 w,
  	KASSERTMSG(view->partial.size <=3D INT_MAX, "view size=3D0x%zx",
  	    (size_t)view->partial.size);
 =20
 -	st =3D kmalloc(sizeof(*st), GFP_KERNEL);
 -	if (st =3D=3D NULL)
 -		goto fail;
 -	ret =3D sg_alloc_table(st, view->partial.size, GFP_KERNEL);
 -	if (ret) {
 -		kfree(st);
 -		st =3D NULL;
 -		goto fail;
 -	}
 -
 -	/* XXX errno NetBSD->Linux */
 -	if (obj->mm.pages->sgl->sg_dmamap) { /* XXX KASSERT?  */
 -		ret =3D -bus_dmamap_create(obj->base.dev->dmat,
 -		    (bus_size_t)view->partial.size << PAGE_SHIFT,
 -		    view->partial.size, PAGE_SIZE, 0, BUS_DMA_NOWAIT,
 -		    &st->sgl->sg_dmamap);
 -		if (ret) {
 -			st->sgl->sg_dmamap =3D NULL;
 -			goto fail;
 -		}
 -		st->sgl->sg_dmat =3D obj->base.dev->dmat;
 -	}
 -
  	/*
  	 * Copy over the pages.  The view's offset and size are in
  	 * units of pages already.
 @@ -1690,31 +1787,8 @@ intel_partial_pages(const struct i915_ggtt_view *vie=
 w,
  		}
  	}
 =20
 -	/* Success!  */
  	return st;
 -
 -fail:	if (st) {
 -		sg_free_table(st);
 -		kfree(st);
 -	}
 -	return ERR_PTR(ret);
  #else
 -	struct sg_table *st;
 -	struct scatterlist *sg, *iter;
 -	unsigned int count =3D view->partial.size;
 -	unsigned int offset;
 -	int ret;
 -
 -	st =3D kmalloc(sizeof(*st), GFP_KERNEL);
 -	if (!st) {
 -		ret =3D -ENOMEM;
 -		goto err_st_alloc;
 -	}
 -
 -	ret =3D sg_alloc_table(st, count, GFP_KERNEL);
 -	if (ret)
 -		goto err_sg_alloc;
 -
  	iter =3D i915_gem_object_get_sg(obj, view->partial.offset, &offset);
  	GEM_BUG_ON(!iter);
 =20
 @@ -1743,12 +1817,12 @@ fail:	if (st) {
  		iter =3D __sg_next(iter);
  		offset =3D 0;
  	} while (1);
 +#endif
 =20
  err_sg_alloc:
  	kfree(st);
  err_st_alloc:
  	return ERR_PTR(ret);
 -#endif	/* __NetBSD__ */
  }
 =20
  static int
 @@ -1773,21 +1847,13 @@ i915_get_ggtt_vma_pages(struct i915_vma *vma)
  		return 0;
 =20
  	case I915_GGTT_VIEW_ROTATED:
 -#ifdef __NetBSD__
 -		vma->pages =3D ERR_PTR(-ENODEV);
 -#else
  		vma->pages =3D
  			intel_rotate_pages(&vma->ggtt_view.rotated, vma->obj);
 -#endif
  		break;
 =20
  	case I915_GGTT_VIEW_REMAPPED:
 -#ifdef __NetBSD__
 -		vma->pages =3D ERR_PTR(-ENODEV);
 -#else
  		vma->pages =3D
  			intel_remap_pages(&vma->ggtt_view.remapped, vma->obj);
 -#endif
  		break;
 =20
  	case I915_GGTT_VIEW_PARTIAL:

 --=_3GH/d8a4GiEuk6sY511/abKYWvHzDwXu--

State-Changed-From-To: feedback->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 18 Jul 2023 21:28:07 +0000
State-Changed-Why:
submitter reports fixed with patch that was committed

not yet confident the other patch has been tested adequately, let's
wait a bit for that, but I think it's for performance and not
correctness or functionality


State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Wed, 02 Aug 2023 14:48:10 +0000
State-Changed-Why:
pullup-10 #307: https://releng.netbsd.org/cgi-bin/req-10.cgi?show=307


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56648 CVS commit: [netbsd-10] src/sys/external/bsd/drm2/dist/drm/i915/gt
Date: Fri, 4 Aug 2023 13:30:57 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Fri Aug  4 13:30:57 UTC 2023

 Modified Files:
 	src/sys/external/bsd/drm2/dist/drm/i915/gt [netbsd-10]: intel_ggtt.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #307):

 	sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c: revision 1.16

 i915: Fail gracefully, don't panic, with unsupported ggtt views.

 Workaround for part of PR kern/56648.


 To generate a diff of this commit:
 cvs rdiff -u -r1.15 -r1.15.4.1 \
     src/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 05 Aug 2023 16:35:57 +0000
State-Changed-Why:
fixed in HEAD, pulled up to 10, not relevant to 9 or 8


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.