From nobody@FreeBSD.org  Wed Jul 18 06:41:16 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id A8F1216A401
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 18 Jul 2007 06:41:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (groups.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 99EC913C4B7
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 18 Jul 2007 06:41:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.1/8.14.1) with ESMTP id l6I6fGo2022574
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 18 Jul 2007 06:41:16 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.1/8.14.1/Submit) id l6I6fG0T022558;
	Wed, 18 Jul 2007 06:41:16 GMT
	(envelope-from nobody)
Message-Id: <200707180641.l6I6fG0T022558@www.freebsd.org>
Date: Wed, 18 Jul 2007 06:41:16 GMT
From: vehemens <vehemens@verizon.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: RADEON/AIGLX/DRM Problem
X-Send-Pr-Version: www-3.0

>Number:         114688
>Category:       kern
>Synopsis:       [drm] RADEON/AIGLX/DRM Problem
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    remko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 18 06:50:01 GMT 2007
>Closed-Date:    Sun Feb 10 11:15:48 UTC 2008
>Last-Modified:  Sun Feb 10 11:20:00 UTC 2008
>Originator:     vehemens
>Release:        Current
>Organization:
>Environment:
FreeBSD hep.dsl-verizon.net 7.0-CURRENT FreeBSD 7.0-CURRENT #0: Sun Jul 15 22:20:10 PDT 2007     vehemens@hep.dsl-verizon.net:/usr/obj/usr/src/sys/HEP  i386

>Description:
The problem with the RADEON driver failing when run with the AIGLX extension 
appears to be a problem with the DRM piece (library and/or driver).

What is happening is that the RADEON driver initializes DRM and sets a lock 
using one file descriptor.  When the AIGLX extension loads, it probes via 
DRM using open/close calls on another file descriptor.

As both the RADEON driver and the AIGLX extension are part of the same 
process, the AIGLX probe close calls drm_close which removes the DRI lock 
causing the RADEON driver to fail during xserver initialization (i.e. system 
hang).

Just to complicate the issue, I've been told that this doesn't occur with 
linux with the suggestion that the BSD driver is broken or that the close 
semantics are different between the two operating systems.

I don't know what direction to go in a this point, as I don't have the
system knowledge to determine if the problem should be fixed in 1) the
DRM driver, 2) libdrm, 3) the xserver, 4) the video driver, or 5) the
AIGLX extension.
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: Thierry Thomas <thierry@FreeBSD.org>
To: vehemens <vehemens@verizon.net>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: kern/114688: RADEON/AIGLX/DRM Problem
Date: Wed, 18 Jul 2007 18:49:18 +0200

 On Wed 18 jul 07 at 8:41:16 +0200, vehemens <vehemens@verizon.net>
  wrote:
 > 
 > >Number:         114688
 > >Category:       kern
 > >Synopsis:       RADEON/AIGLX/DRM Problem
 
 Seems a duplicate of PR kern/89271 and PR kern/112984.
 
 Check <http://www.freebsd.org/cgi/query-pr.cgi?pr=89271>
 and <http://www.freebsd.org/cgi/query-pr.cgi?pr=112984>
 and let's know if this PR can be closed.
 
 Regards,
 -- 
 Th. Thomas.
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Wed Jul 18 17:50:08 UTC 2007 
State-Changed-Why:  
See kern/112984, which also has a patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114688 

From: vehemens <vehemens@verizon.net>
To: Thierry Thomas <thierry@freebsd.org>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: kern/114688: RADEON/AIGLX/DRM Problem
Date: Wed, 18 Jul 2007 20:14:19 -0700

 On Wednesday 18 July 2007 09:49:18 am Thierry Thomas wrote:
 > On Wed 18 jul 07 at 8:41:16 +0200, vehemens <vehemens@verizon.net>
 >
 >  wrote:
 > > >Number:         114688
 > > >Category:       kern
 > > >Synopsis:       RADEON/AIGLX/DRM Problem
 >
 > Seems a duplicate of PR kern/89271 and PR kern/112984.
 >
 > Check <http://www.freebsd.org/cgi/query-pr.cgi?pr=89271>
 > and <http://www.freebsd.org/cgi/query-pr.cgi?pr=112984>
 > and let's know if this PR can be closed.
 >
 > Regards,
 
 I don't believe that PR 89271 applies here as my PR attempts to address 
 breakage due to the AIGLX extension.
State-Changed-From-To: closed->open 
State-Changed-By: linimon 
State-Changed-When: Thu Jul 19 05:50:14 UTC 2007 
State-Changed-Why:  
Submitter disagrees that this PR is the same as the ones cited in the 
Audit-Trail. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114688 

From: Stefan Sperling <stsp@stsp.name>
To: bug-followup@FreeBSD.org, vehemens@verizon.net
Cc:  
Subject: Re: kern/114688: [drm] RADEON/AIGLX/DRM Problem
Date: Fri, 20 Jul 2007 12:17:05 +0200

 --qDbXVdCdHGoSgWSk
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 
 > Why:	Submitter disagrees that this PR is the same as the ones cited=20
 >       in the Audit-Trail.
 
 No, I believe vehemens said that only PR kern/89271 didn't apply,
 not that both didn't apply.
 
 PR kern/112984 is indeed about the very same bug, yet this PR
 (kern/114688) provides a much better analysis of the problem.
 
 It explains why the "fix" provided in kern/112984 is likely inadequate.
 Note that the "fix" supposed in kern/112984 is just patches by vehemens,
 who also opened this issue, ported blindly to FreeBSD 6.2 by myself
 hoping that it would work. But it didn't.
 
 So I'd favour this issue over kern/112984, because it has more
 valuable information. Maybe they should me merged? Is this possible
 at all with GNATS?
 
 I'd really like to see this fixed, but I have no clue about the
 subsystems involved either. Without knowing how these subsystems
 are supposed to interact by design it's almost impossible to come
 up with "the proper" fix.
 
 vehemens, are you still actively trying to find a fix for this issue?
 
 --=20
 stefan
 http://stsp.name                                         PGP Key: 0xF59D25F0
 
 --qDbXVdCdHGoSgWSk
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.7 (FreeBSD)
 
 iD8DBQFGoIuh5dMCc/WdJfARAkMmAJ4pJ92zE51RBn5NkaG4kQo+TMTsjQCgyIkp
 w5lBkXNO4eHntOkdpmCzEfw=
 =4tC5
 -----END PGP SIGNATURE-----
 
 --qDbXVdCdHGoSgWSk--

From: vehemens <vehemens@verizon.net>
To: Stefan Sperling <stsp@stsp.name>
Cc: bug-followup@freebsd.org
Subject: Re: kern/114688: [drm] RADEON/AIGLX/DRM Problem
Date: Fri, 20 Jul 2007 21:21:53 -0700

 On Friday 20 July 2007 03:17:05 am Stefan Sperling wrote:
 > > Why:	Submitter disagrees that this PR is the same as the ones cited
 > >       in the Audit-Trail.
 >
 > No, I believe vehemens said that only PR kern/89271 didn't apply,
 > not that both didn't apply.
 >
 > PR kern/112984 is indeed about the very same bug, yet this PR
 > (kern/114688) provides a much better analysis of the problem.
 PR kern/112984 and kern/114688 probably have the same root cause.  The cards 
 are different however.  Also the locking problem may impact other drivers.
 
 > It explains why the "fix" provided in kern/112984 is likely inadequate.
 > Note that the "fix" supposed in kern/112984 is just patches by vehemens,
 > who also opened this issue, ported blindly to FreeBSD 6.2 by myself
 > hoping that it would work. But it didn't.
 >
 > So I'd favour this issue over kern/112984, because it has more
 > valuable information. Maybe they should me merged? Is this possible
 > at all with GNATS?
 >
 > I'd really like to see this fixed, but I have no clue about the
 > subsystems involved either. Without knowing how these subsystems
 > are supposed to interact by design it's almost impossible to come
 > up with "the proper" fix.
 >
 > vehemens, are you still actively trying to find a fix for this issue?
 
 Still working it, but I think it's an architecture issue, and I don't have the 
 knowledge to know which piece to fix, hence the writing of the PR.
 
 Here's my list of possible approaches:
 
 1) The DRM driver counts open and closes, and only removes the lock on the 
 last close.  However it's not clear to me that the DRM driver would get the 
 multiple closes needed if the xserver process terminated abnormally.  Also 
 according to the close man page "However, the semantics of System V and IEEE 
 Std 1003.1-198 (``POSIX.1'') dictate that all fcntl(2) advisory record locks 
 associated with a file for a given process are removed when any file 
 descriptor for that file is closed by that process."
 
 2) Rewrite of libdrm to only probe once.
 
 3) Modify the xserver to reacquire the lock before drawing.

From: vehemens <vehemens@verizon.net>
To: bug-followup@freebsd.org, vehemens@verizon.net
Cc:  
Subject: Re: kern/114688: [drm] RADEON/AIGLX/DRM Problem
Date: Fri, 27 Jul 2007 23:16:45 -0700

 There is now a driver patch that provides a reasonable workaround for the drm 
 locking problem.
 
 It was provided by Kostik Belousov and appears below.  Refer to his email for 
 his comments on the patch.
  
 <http://docs.freebsd.org/cgi/getmsg.cgi?fetch=82619+0+archive/2007/freebsd-x11/20070722.freebsd-x11>
 
 I have verified that it works.  In addition, I no longer have xserver exit 
 hangs.
 
 Note 1) This patch was not the only change I made to get aiglx with beryl 
 running on my system.  I have updated my 7.0 current system with the 
 development branch of 1) xserver which required pixman as well as mesa, 
 inputproto, keyboard and mouse driver updates, 2) ati driver, 3) drm driver 
 with patches, and 4) misc xorg updates (both released and unreleased) not yet 
 in the ports.
 
 Note 2) I still get a white screen when I restart the xserver and beryl 
 without rebooting.  I do not know if this problem with drm core, drm radeon, 
 or something else.
 
 diff --git a/sys/dev/drm/drm_drv.c b/sys/dev/drm/drm_drv.c
 index dda03c1..b7c9ab9 100644
 --- a/sys/dev/drm/drm_drv.c
 +++ b/sys/dev/drm/drm_drv.c
 @@ -711,6 +711,15 @@ int drm_close(struct cdev *kdev, int flags, int fmt, 
 DRM_STRUCTPROC *p)
                 return EINVAL;
         }
 
 +       atomic_inc( &dev->counts[_DRM_STAT_CLOSES] );
 +#ifdef __FreeBSD__
 +       device_unbusy(dev->device);
 +#endif
 +       if (--dev->open_count != 0) {
 +               DRM_UNLOCK();
 +               return (0);
 +       }
 +
         if (dev->driver.preclose != NULL)
                 dev->driver.preclose(dev, filp);
 
 @@ -797,13 +806,8 @@ int drm_close(struct cdev *kdev, int flags, int fmt, 
 DRM_STRUCTPROC *p)
          * End inline drm_release
          */
 
 -       atomic_inc( &dev->counts[_DRM_STAT_CLOSES] );
 -#ifdef __FreeBSD__
 -       device_unbusy(dev->device);
 -#endif
 -       if (--dev->open_count == 0) {
 -               retcode = drm_lastclose(dev);
 -       }
 +
 +       retcode = drm_lastclose(dev);
 
           DRM_UNLOCK();

From: Stefan Sperling <stsp@stsp.name>
To: bug-followup@FreeBSD.org, vehemens@verizon.net
Cc:  
Subject: Re: kern/114688: [drm] RADEON/AIGLX/DRM Problem
Date: Sat, 11 Aug 2007 18:44:09 +0200

 --zYM0uCDKw75PZbzx
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On an otherwise unpatched 6.2 system, the above patch
 makes it possible for me to enable AIGLX and start and
 use beryl. Albeit only with --use-copy, so it's rather slow.
 
 But the patch breaks DRI if I restart the X server.
 
 DRI works after starting X the first time, but after
 that the radeon driver seems to pick up an empty PCI ID
 for the graphics card (the ID shows in the logs as ''),
 and then DRI initialisation fails in drmGetBusid with
 'permission denied'.
 
 I don't get white screens.
 
 --=20
 stefan
 http://stsp.name                                         PGP Key: 0xF59D25F0
 
 --zYM0uCDKw75PZbzx
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.7 (FreeBSD)
 
 iD4DBQFGvedY5dMCc/WdJfARArNNAJY1LhLm+0nUSN4bLuf8i/R+fVCDAKCmkXWH
 kgmkC7pDEh+qVMx570rwbQ==
 =NBDi
 -----END PGP SIGNATURE-----
 
 --zYM0uCDKw75PZbzx--

From: vehemens <vehemens@verizon.net>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: kern/114688: [drm] RADEON/AIGLX/DRM Problem
Date: Sun, 19 Aug 2007 14:24:46 -0700

 Tracking priv->refs seems to be a better approach.  With this change, I can 
 restart the xserver and run beryl.
 
 It has been tested using a slightly modified git drm driver.  The patch is for 
 the 7.0 driver code.
 
 --- drm_drv.c.orig	2006-09-07 16:04:47.000000000 -0700
 +++ drm_drv.c	2007-08-19 13:43:41.000000000 -0700
 @@ -711,6 +711,8 @@
  		return EINVAL;
  	}
  
 +//	if (--priv->refs == 0) {
 +
  	if (dev->driver.preclose != NULL)
  		dev->driver.preclose(dev, filp);
  
 @@ -786,7 +788,7 @@
  	dev->buf_pgid = 0;
  #endif /* __NetBSD__  || __OpenBSD__ */
  
 -	if (--priv->refs == 0) {
 +//	if (--priv->refs == 0) {
  		if (dev->driver.postclose != NULL)
  			dev->driver.postclose(dev, priv);
  		TAILQ_REMOVE(&dev->files, priv, link);

From: vehemens <vehemens@verizon.net>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: kern/114688: [drm] RADEON/AIGLX/DRM Problem
Date: Tue, 21 Aug 2007 23:50:07 -0700

 The previous code change was only tested in the git branch, and I fumbled 
 modifying it for the freebsd branch.
 
 This revised patch has been tested using the 7.0 driver code.
 
 --- drm_drv.c.orig	2006-09-07 16:04:47.000000000 -0700
 +++ drm_drv.c	2007-08-21 21:47:08.000000000 -0700
 @@ -711,6 +711,8 @@
  		return EINVAL;
  	}
  
 +if (--priv->refs == 0) {
 +
  	if (dev->driver.preclose != NULL)
  		dev->driver.preclose(dev, filp);
  
 @@ -786,7 +788,7 @@
  	dev->buf_pgid = 0;
  #endif /* __NetBSD__  || __OpenBSD__ */
  
 -	if (--priv->refs == 0) {
 +//	if (--priv->refs == 0) {
  		if (dev->driver.postclose != NULL)
  			dev->driver.postclose(dev, priv);
  		TAILQ_REMOVE(&dev->files, priv, link);

From: Stefan Sperling <stsp@stsp.name>
To: bug-followup@FreeBSD.org, vehemens@verizon.net
Cc:  
Subject: Re: kern/114688: [drm] RADEON/AIGLX/DRM Problem
Date: Thu, 30 Aug 2007 16:45:03 +0200

 --wRRV7LY7NUeQGEoC
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Great. Using only your revised patch on 7-CURRENT, it loads AIGLX
 and I can use beryl. And after restarting the X server both
 DRI and AIGLX still work :)
 
 Beryl only works with --use-copy though, otherwise the content
 of windows is no updated (such as the terminal pane in gnome-terminal
 or the main window of the file manager). It doesn't crash and I can
 still move windows around without --use-copy though.
 
 Could this be a driver issue? glxinfo shows GLX_EXT_texture_from_pixmap
 under "server glx extensions" and "client glx extensions", but neither
 under "GLX extensions" nor "OpenGL extensions".=20
 My card is reported in dmesg as "drm0: <ATI Radeon AS 9550> on vgapci0"
 and I use the r300 driver on 7-CURRENT as of 27th of August 2007.
 
 --=20
 stefan
 http://stsp.name                                         PGP Key: 0xF59D25F0
 
 --wRRV7LY7NUeQGEoC
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.7 (FreeBSD)
 
 iD8DBQFG1tfv5dMCc/WdJfARAl//AKDkaO19fYz+Gl+3wXToPvzizfhYfwCgpQ2w
 AJzhP5/auIljfw71aOowJmE=
 =BSUU
 -----END PGP SIGNATURE-----
 
 --wRRV7LY7NUeQGEoC--

From: vehemens <vehemens@verizon.net>
To: bug-followup@freebsd.org, vehemens@verizon.net
Cc:  
Subject: Re: kern/114688: [drm] RADEON/AIGLX/DRM Problem
Date: Thu, 20 Sep 2007 18:56:09 -0700

 Revised 7-current patch with Jung-uk Kim's style fixes.
 
 --- drm_drv.c.orig	2006-09-07 16:04:47.000000000 -0700
 +++ drm_drv.c	2007-09-20 12:20:24.000000000 -0700
 @@ -711,6 +711,9 @@
  		return EINVAL;
  	}
  
 +	if (--priv->refs != 0)
 +		goto done;
 +
  	if (dev->driver.preclose != NULL)
  		dev->driver.preclose(dev, filp);
  
 @@ -786,17 +789,17 @@
  	dev->buf_pgid = 0;
  #endif /* __NetBSD__  || __OpenBSD__ */
  
 -	if (--priv->refs == 0) {
 -		if (dev->driver.postclose != NULL)
 -			dev->driver.postclose(dev, priv);
 -		TAILQ_REMOVE(&dev->files, priv, link);
 -		free(priv, M_DRM);
 -	}
 +
 +	if (dev->driver.postclose != NULL)
 +		dev->driver.postclose(dev, priv);
 +	TAILQ_REMOVE(&dev->files, priv, link);
 +	free(priv, M_DRM);
  
  	/* ========================================================
  	 * End inline drm_release
  	 */
  
 +done:
  	atomic_inc( &dev->counts[_DRM_STAT_CLOSES] );
  #ifdef __FreeBSD__
  	device_unbusy(dev->device);
Responsible-Changed-From-To: freebsd-bugs->remko 
Responsible-Changed-By: remko 
Responsible-Changed-When: Fri Nov 9 07:07:20 UTC 2007 
Responsible-Changed-Why:  
I am currently testing the patch and I 'fixed' the patch since the web 
version is not applicable (patch-wise seen, the code itself looks OK) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114688 
State-Changed-From-To: open->patched 
State-Changed-By: remko 
State-Changed-When: Wed Jan 16 13:54:50 UTC 2008 
State-Changed-Why:  
Patched in -CURRENT, will MFC in a little 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114688 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/114688: commit references a PR
Date: Wed, 16 Jan 2008 13:54:47 +0000 (UTC)

 remko       2008-01-16 13:54:40 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/dev/drm          drm_drv.c 
   Log:
   Dont accidentally remove a filesocket which is still in use. This gives
   problems when the DRM driver is loaded and the AIXGL extension is loaded
   , the AIXGL driver requests a drm_close and this will cause the radeon
   driver to fail while starting X windows.
   
   PR:             kern/114688
   Submitted by:   vehemens <vehemens at verizon dot net>
   Prodded by:     Robert Noland
   Approved by:    imp (mentor, a while ago already), anholt
   MFC After:      1 week
   
   Revision  Changes    Path
   1.7       +9 -6      src/sys/dev/drm/drm_drv.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: remko 
State-Changed-When: Sun Feb 10 11:15:47 UTC 2008 
State-Changed-Why:  
MFC'ed to all relevant branches, thanks for the submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114688 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/114688: commit references a PR
Date: Sun, 10 Feb 2008 11:15:35 +0000 (UTC)

 remko       2008-02-10 11:15:27 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     sys/dev/drm          drm_drv.c 
   Log:
   MFC rev 1.7 drm_drv.c
   
     Dont accidentally remove a filesocket which is still in use. This gives
     problems when the DRM driver is loaded and the AIXGL extension is loaded
     , the AIXGL driver requests a drm_close and this will cause the radeon
     driver to fail while starting X windows.
   
     PR: kern/114688
     Submitted by: vehemens <vehemens at verizon dot net>
     Prodded by: Robert Noland
     Approved by: imp (mentor, a while ago already), anholt
   
   Approved by:    imp (mentor, implicit)
   
   Revision  Changes    Path
   1.1.2.4   +9 -6      src/sys/dev/drm/drm_drv.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
