Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Sep 2005 00:20:21 GMT
From:      "Andrew Watkins" <awatkins@ejungle.us>
To:        freebsd-i386@FreeBSD.org
Subject:   Re: i386/78929: atapicam prevents boot, system hangs
Message-ID:  <200509200020.j8K0KLj1031884@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR i386/78929; it has been noted by GNATS.

From: "Andrew Watkins" <awatkins@ejungle.us>
To: <bug-followup@FreeBSD.org>,
	<harrycoin@quietfountain.com>
Cc:  
Subject: Re: i386/78929: atapicam prevents boot, system hangs
Date: Mon, 19 Sep 2005 17:19:08 -0700

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_0185_01C5BD3E.3F2AF8D0
 Content-Type: text/plain;
 	charset="us-ascii"
 Content-Transfer-Encoding: 7bit
 
 This happened on both i386 for me and amd64 with 5.4, both using SMP and not
 for dual processor support (dell sc1425) with a QSI-DVD burner.  Dump of the
 kernel provided this:
 
  
 
 _mtx_lock_sleep+0x77 (kern_mutex.c, 521)
 
 Get_softc+0x80 (atapi-cam.c, 776)
 
 Atapi_cam_reinit_bus+0x16 (atapi-cam.c, 195)
 
  
 
 I read through the code to see where the mutex is initialized and found that
 the only place it is done is atapi_cam_attach_bus.  I guess its possible for
 the code to reach the atapi_cam_reinit_bus which calls get_softc before the
 bus is attached?  Anyway, I changed get_softc to look to see if the mutex is
 initialized before locking and that did the trick.  Below is my modified
 code:
 
  
 
 static struct atapi_xpt_softc *
 
 get_softc(struct ata_channel *ata_ch) {
 
     struct atapi_xpt_softc *scp = NULL;
 
  
 
     /* There could be a race condition where the atapi mtx has not been
 initialized */
 
  
 
     if (mtx_initialized(&atapicam_softc_mtx) == 0)
 
         mtx_init(&atapicam_softc_mtx, "ATAPI/CAM softc mutex", NULL,
 MTX_DEF);
 
  
 
  
 
     mtx_lock(&atapicam_softc_mtx);
 
     LIST_FOREACH(scp, &all_buses, chain) {
 
             if (scp->ata_ch == ata_ch)
 
                 break;
 
     }
 
     mtx_unlock(&atapicam_softc_mtx);
 
     return scp;
 
 }
 
  
 
 After that it booted no problem and burned a DVD like a champ.
 
 I don't think this change can impact the rest of the system, but can someone
 let me know as this is going to be a production box.  Let me know if you
 need anymore information as I have trace and the kernel.debug (burned on a
 dvd as my trophy).
 
  
 
 Andrew
 
 
 ------=_NextPart_000_0185_01C5BD3E.3F2AF8D0
 Content-Type: text/html;
 	charset="us-ascii"
 Content-Transfer-Encoding: quoted-printable
 
 <html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
 xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
 xmlns=3D"http://www.w3.org/TR/REC-html40">;
 
 <head>
 <meta http-equiv=3DContent-Type content=3D"text/html; =
 charset=3Dus-ascii">
 <meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
 <style>
 <!--
  /* Style Definitions */
  p.MsoNormal, li.MsoNormal, div.MsoNormal
 	{margin:0in;
 	margin-bottom:.0001pt;
 	font-size:12.0pt;
 	font-family:"Times New Roman";}
 a:link, span.MsoHyperlink
 	{color:blue;
 	text-decoration:underline;}
 a:visited, span.MsoHyperlinkFollowed
 	{color:purple;
 	text-decoration:underline;}
 span.EmailStyle17
 	{mso-style-type:personal-compose;
 	font-family:Arial;
 	color:windowtext;}
 @page Section1
 	{size:8.5in 11.0in;
 	margin:1.0in 1.25in 1.0in 1.25in;}
 div.Section1
 	{page:Section1;}
 -->
 </style>
 
 </head>
 
 <body lang=3DEN-US link=3Dblue vlink=3Dpurple>
 
 <div class=3DSection1>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>This happened on both i386 for me and amd64 with 5.4, =
 both
 using SMP and not for dual processor support (dell sc1425) with a =
 QSI-DVD
 burner.&nbsp; Dump of the kernel provided =
 this:<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>_<i><span =
 style=3D'font-style:italic'>mtx</span></i>_lock_sleep+0x77
 (kern_mutex.c, 521)<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>Get_softc+0x80 (atapi-cam.c, =
 776)<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>Atapi_cam_reinit_bus+0x16 (atapi-cam.c, =
 195)<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>I read through the code to see where the mutex is
 initialized and found that the only place it is done is =
 atapi_cam_attach_bus.&nbsp;
 I guess its possible for the code to reach the atapi_cam_reinit_bus =
 which calls
 get_softc before the bus is attached?&nbsp; Anyway, I changed get_softc =
 to look
 to see if the mutex is initialized before locking and that did the =
 trick.&nbsp;
 Below is my modified code:<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>static struct atapi_xpt_softc =
 *<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>get_softc(struct ata_channel *ata_ch) =
 {<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp; struct atapi_xpt_softc *scp =3D =
 NULL;<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp; /* There could be a race condition =
 where
 the atapi mtx has not been initialized */<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp; if
 (mtx_initialized(&amp;atapicam_softc_mtx) =3D=3D =
 0)<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 mtx_init(&amp;atapicam_softc_mtx, &quot;ATAPI/CAM softc mutex&quot;, =
 NULL,
 MTX_DEF);<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp; =
 mtx_lock(&amp;atapicam_softc_mtx);<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp; LIST_FOREACH(scp, &amp;all_buses, =
 chain)
 {<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp; if
 (scp-&gt;ata_ch =3D=3D ata_ch)<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 break;<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp; =
 mtx_unlock(&amp;atapicam_softc_mtx);<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>&nbsp;&nbsp;&nbsp; return =
 scp;<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>}<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>After that it booted no problem and burned a DVD like =
 a
 champ.<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>I don&#8217;t think this change can impact the rest =
 of the
 system, but can someone let me know as this is going to be a production =
 box.&nbsp;
 Let me know if you need anymore information as I have trace and the
 kernel.debug (burned on a dvd as my =
 trophy).<o:p></o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>
 
 <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
 style=3D'font-size:10.0pt;
 font-family:Arial'>Andrew<o:p></o:p></span></font></p>
 
 </div>
 
 </body>
 
 </html>
 
 ------=_NextPart_000_0185_01C5BD3E.3F2AF8D0--
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200509200020.j8K0KLj1031884>