Module Name:    src
Committed By:   bouyer
Date:           Sun Jan 16 13:06:49 UTC 2011

Modified Files:
        src/sys/dev/ic [netbsd-5]: ahcisata_core.c

Log Message:
Pull up following revision(s) (requested by tsutsui in ticket #1530):
        sys/dev/ic/ahcisata_core.c: revision 1.31
Don't call bus_dmamap_load(9) and bus_dmamap_sync(9) on command xfers
if (AT_READ|AT_WRITE) in ata_c->flags is set but ata_c->bcount is zero.
Someone actually tries to put such a command and it causes
DIAGNOSTIC panic in x86/bus_dma.c:_bus_dmamap_sync().
I think bus_dma(9) API itself may allow calls with mapsize==0
but there are many MD code that asserts offset>=mapsize or len==0.
The problem is reported and fix is confirmed by Takuro KUBOTA
with XEN DOM0 kernel (which has options DIAGNOSTIC).


To generate a diff of this commit:
cvs rdiff -u -r1.18.4.4 -r1.18.4.5 src/sys/dev/ic/ahcisata_core.c

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

Modified files:

Index: src/sys/dev/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.18.4.4 src/sys/dev/ic/ahcisata_core.c:1.18.4.5
--- src/sys/dev/ic/ahcisata_core.c:1.18.4.4	Sun Mar 28 16:21:18 2010
+++ src/sys/dev/ic/ahcisata_core.c	Sun Jan 16 13:06:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.18.4.4 2010/03/28 16:21:18 snj Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.18.4.5 2011/01/16 13:06:49 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.18.4.4 2010/03/28 16:21:18 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.18.4.5 2011/01/16 13:06:49 bouyer Exp $");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -729,7 +729,8 @@
 	AHCIDEBUG_PRINT(("%s port %d header %p\n", AHCINAME(sc),
 	    chp->ch_channel, cmd_h), DEBUG_XFERS);
 	if (ahci_dma_setup(chp, slot,
-	    (ata_c->flags & (AT_READ|AT_WRITE)) ? ata_c->data : NULL,
+	    (ata_c->flags & (AT_READ|AT_WRITE) && ata_c->bcount > 0) ?
+	    ata_c->data : NULL,
 	    ata_c->bcount,
 	    (ata_c->flags & AT_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) {
 		ata_c->flags |= AT_DF;
@@ -862,7 +863,7 @@
 	/* this comamnd is not active any more */
 	achp->ahcic_cmds_active &= ~(1 << slot);
 
-	if (ata_c->flags & (AT_READ|AT_WRITE)) {
+	if (ata_c->flags & (AT_READ|AT_WRITE) && ata_c->bcount > 0) {
 		bus_dmamap_sync(sc->sc_dmat, achp->ahcic_datad[slot], 0,
 		    achp->ahcic_datad[slot]->dm_mapsize,
 		    (ata_c->flags & AT_READ) ? BUS_DMASYNC_POSTREAD :

Reply via email to