From dgilbert@daveg.ca  Sun Sep  7 13:02:58 2003
Return-Path: <dgilbert@daveg.ca>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0748616A4BF
	for <freebsd-gnats-submit@freebsd.org>; Sun,  7 Sep 2003 13:02:58 -0700 (PDT)
Received: from sizone.org (mortar.sizone.org [65.126.154.242])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 7197F43FB1
	for <freebsd-gnats-submit@freebsd.org>; Sun,  7 Sep 2003 13:02:57 -0700 (PDT)
	(envelope-from dgilbert@daveg.ca)
Received: by sizone.org (Postfix, from userid 66)
	id C61722FEE2; Sun,  7 Sep 2003 16:02:56 -0400 (EDT)
Received: by canoe.dclg.ca (Postfix, from userid 101)
	id F3CCE1D1C42; Sun,  7 Sep 2003 16:02:26 -0400 (EDT)
Message-Id: <20030907200226.F3CCE1D1C42@canoe.dclg.ca>
Date: Sun,  7 Sep 2003 16:02:26 -0400 (EDT)
From: David Gilbert <freebsd-submit@daveg.ca>
Reply-To: David Gilbert <freebsd-submit@daveg.ca>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ATAng sees zero sized disk... causes div-by-zero
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         56572
>Category:       kern
>Synopsis:       ATAng sees zero sized disk... causes div-by-zero
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    sos
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 07 13:10:12 PDT 2003
>Closed-Date:    Sat Oct 25 12:26:22 PDT 2003
>Last-Modified:  Sat Oct 25 12:26:22 PDT 2003
>Originator:     David Gilbert
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
daveg.ca
>Environment:
System: FreeBSD canoe.dclg.ca 5.1-CURRENT FreeBSD 5.1-CURRENT #1: Sun Sep 7 15:46:19 EDT 2003 dgilbert@canoe.dclg.ca:/usr/src/sys/i386/compile/CANOE i386


Dell D800 laptop.  Centrino processor, 1G RAM.
>Description:
The Dell has a two channel IDE controller.  Channel 0 is the hard drive
and channel 1 is the DVD+R drive.  For some reason, ATAng sees a phanotm
ad3 when the DVD+R is inserted (it is not seen when the DVD+R is removed.)
This happens both when the DVD+R is hot-swapped in and when it is in at
boot.

I get a divide-by-zero panic in ad_print in ata-disk.c without the
included patch.  The dmesg now says:

ata1: resetting devices ..
acd0: CDRW <PHILIPS DVD+RW SDVD6004> at ata1-master WDMA2
ad3: FAILURE - total sectors 0

>How-To-Repeat:

Boot with -CURRENT on my laptop.
>Fix:

This fix protects against zero length ata devices ... and should likely
be left in regardless (malicious devices hot-swapped in shouldn't
panic the kernel).

This fix does not address why ATAng is detecting a phantom ad3.
The ATA code previous to ATAng did not detect the phantom drive.

--- /sys/dev/ata/ata-disk.orig	Sun Sep  7 15:41:06 2003
+++ /sys/dev/ata/ata-disk.c	Sun Sep  7 15:53:10 2003
@@ -96,6 +96,16 @@
     adp->heads = atadev->param->heads;
     adp->sectors = atadev->param->sectors;
     adp->total_secs = atadev->param->cylinders * adp->heads * adp->sectors;	
+    /* if the total sectors is zero, the size of the disk is zero
+     * and there's little good in attaching it (besides the fact
+     * that this would generate divide by zero errors later.
+     */
+    if (adp->total_secs == 0) {
+	ata_prtdev(atadev, "FAILURE - total sectors 0\n");
+	free(adp, M_AD);
+	atadev->attach = NULL;
+	return;
+    }
     if (adp->device->channel->flags & ATA_USE_PC98GEOM &&
 	adp->total_secs < 17 * 8 * 65536) {
 	adp->sectors = 17;
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->sos 
Responsible-Changed-By: simon 
Responsible-Changed-When: Mon Sep 8 06:56:29 PDT 2003 
Responsible-Changed-Why:  
Over to the ATA maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=56572 
State-Changed-From-To: open->feedback 
State-Changed-By: sos 
State-Changed-When: Mon Sep 8 06:57:46 PDT 2003 
State-Changed-Why:  
Could you try to upgrade to the latest current (> 14:00 CET sept 8) 
and see if that fixes the problem by not finding ghost disks ? 


http://www.freebsd.org/cgi/query-pr.cgi?pr=56572 
State-Changed-From-To: feedback->closed 
State-Changed-By: sos 
State-Changed-When: Sat Oct 25 12:25:42 PDT 2003 
State-Changed-Why:  
Feedback timeout (and the proplem is belived to be fixed) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=56572 
>Unformatted:
