Skip to contentSkip to conversation

Initialisation bug in IDE patch

PATCH Andrew Pam 2 participants 9 messages May 22, 2002

lore
Share & tools
lore

Andrew Pam

author
#0 lore raw

In the latest available kernel 2.2 IDE patch "ide-2.2.20.01102002.patch" there is a bug that prevents ide_setup in drivers/block/ide.c from accepting kernel parameters selecting special IDE hardware.

The ide_init_default_hwifs() function in include/asm-*/ide.h fails to initialise the "hw_regs_t hw" variable, thus leaving uninitialised data in some fields. Specifically, the "chipset" field is uninitialised which causes the "if (hwif->chipset != ide_unknown)" test in drivers/block/ide.c to always fail with the error message " -- BAD OPTION".

Cheers,
Andrew Pam

Patch follows:

include/asm-alpha/ide.h +5 -0
diff -Nurd linux-2.2.20+ide-orig/include/asm-alpha/ide.h linux-2.2.20+ide/include/asm-alpha/ide.h
@@ -74,6 +74,11 @@
 	hw_regs_t hw;
 	int index;
 
+	/*
+	 * Initialise before use!
+	 * memset added 2002/05/22 by Andrew Pam <[email protected]>
+	 */
+	memset(&hw, 0, sizeof(hw_regs_t));
 	for (index = 0; index < MAX_HWIFS; index++) {
 		ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, NULL);
 		hw.irq = ide_default_irq(ide_default_io_base(index));
include/asm-i386/ide.h +5 -0
diff -Nurd linux-2.2.20+ide-orig/include/asm-i386/ide.h linux-2.2.20+ide/include/asm-i386/ide.h
@@ -77,6 +77,11 @@
 	hw_regs_t hw;
 	int index;
 
+	/*
+	 * Initialise before use!
+	 * memset added 2002/05/22 by Andrew Pam <[email protected]>
+	 */
+	memset(&hw, 0, sizeof(hw_regs_t));
 	for(index = 0; index < MAX_HWIFS; index++) {
 		ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, NULL);
 		hw.irq = ide_default_irq(ide_default_io_base(index));
include/asm-mips/ide.h +5 -0
diff -Nurd linux-2.2.20+ide-orig/include/asm-mips/ide.h linux-2.2.20+ide/include/asm-mips/ide.h
@@ -70,6 +70,11 @@
 	hw_regs_t hw;
 	int index;
 
+	/*
+	 * Initialise before use!
+	 * memset added 2002/05/22 by Andrew Pam <[email protected]>
+	 */
+	memset(&hw, 0, sizeof(hw_regs_t));
 	for (index = 0; index < MAX_HWIFS; index++) {
 		ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, 0);
 		hw.irq = ide_default_irq(ide_default_io_base(index));
include/asm-ppc/ide.h +5 -0
diff -Nurd linux-2.2.20+ide-orig/include/asm-ppc/ide.h linux-2.2.20+ide/include/asm-ppc/ide.h
@@ -89,6 +89,11 @@
 	hw_regs_t hw;
 	int index;
 
+	/*
+	 * Initialise before use!
+	 * memset added 2002/05/22 by Andrew Pam <[email protected]>
+	 */
+	memset(&hw, 0, sizeof(hw_regs_t));
 	for(index = 0; index < MAX_HWIFS; index++) {
 		base = ide_default_io_base(index);
 		if (base == 0)
include/asm-sparc64/ide.h +5 -0
diff -Nurd linux-2.2.20+ide-orig/include/asm-sparc64/ide.h linux-2.2.20+ide/include/asm-sparc64/ide.h
@@ -57,6 +57,11 @@
 	hw_regs_t hw;
 	int index;
 
+	/*
+	 * Initialise before use!
+	 * memset added 2002/05/22 by Andrew Pam <[email protected]>
+	 */
+	memset(&hw, 0, sizeof(hw_regs_t));
 	for (index = 0; index < MAX_HWIFS; index++) {
 		ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, 0);
 		hw.irq = ide_default_irq(ide_default_io_base(index));
Signature · 6 lines
mailto:[email protected]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Technology Manager, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics
http://two-cents-worth.com/?105347&EG		Donate two cents to our work!
P.O. Box 477, Blackburn VIC 3130 Australia	Phone +61 401 258 915
author
#1 lore raw
Quoted 9 lines · Andrew Pam

In the latest available kernel 2.2 IDE patch "ide-2.2.20.01102002.patch" there is a bug that prevents ide_setup in drivers/block/ide.c from accepting kernel parameters selecting special IDE hardware.

The ide_init_default_hwifs() function in include/asm-*/ide.h fails to initialise the "hw_regs_t hw" variable, thus leaving uninitialised data in some fields. Specifically, the "chipset" field is uninitialised which causes the "if (hwif->chipset != ide_unknown)" test in drivers/block/ide.c to always fail with the error message " -- BAD OPTION".

This bug also appears to be present in the mainline 2.4 kernel IDE code. I haven't checked the 2.5 code yet.

Regards,
Andrew Pam

Signature · 6 lines
mailto:[email protected]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Technology Manager, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics
http://two-cents-worth.com/?105347&EG		Donate two cents to our work!
P.O. Box 477, Blackburn VIC 3130 Australia	Phone +61 401 258 915
#2 lore raw

Please check the function in the top of ide.c

linux-2.4.19-p7 ide.c

static void init_hwif_data (unsigned int index)

{
        unsigned int unit;
        hw_regs_t hw;
        ide_hwif_t *hwif = &ide_hwifs[index];

        /* bulk initialize hwif & drive info with zeros */
        memset(hwif, 0, sizeof(ide_hwif_t));
        memset(&hw, 0, sizeof(hw_regs_t));

        /* fill in any non-zero initial values */
        hwif->index     = index;
        ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
        memcpy(&hwif->hw, &hw, sizeof(hw));
        memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
        hwif->noprobe   = !hwif->io_ports[IDE_DATA_OFFSET];

Obviously you are calling things outside of the normal usage of the driver.

2.2.19 ide.c

/*
* Do not even *think* about calling this!
*/
static void init_hwif_data (unsigned int index)

{
        unsigned int unit;
        hw_regs_t hw;
        ide_hwif_t *hwif = &ide_hwifs[index];

        /* bulk initialize hwif & drive info with zeros */
        memset(hwif, 0, sizeof(ide_hwif_t));
        memset(&hw, 0, sizeof(hw_regs_t));

        /* fill in any non-zero initial values */
        hwif->index     = index;
        ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
        memcpy(&hwif->hw, &hw, sizeof(hw));
        memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
        hwif->noprobe   = !hwif->io_ports[IDE_DATA_OFFSET];
#ifdef CONFIG_BLK_DEV_HD
        if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)

If you are attempting to introduce a hw.chipset which is unknown to the driver please submit a patch to register it or the enum index will barf.

Cheers,

Quoted 11 lines · Andrew Pam
Quoted 9 lines · Andrew Pam

In the latest available kernel 2.2 IDE patch "ide-2.2.20.01102002.patch" there is a bug that prevents ide_setup in drivers/block/ide.c from accepting kernel parameters selecting special IDE hardware.

The ide_init_default_hwifs() function in include/asm-*/ide.h fails to initialise the "hw_regs_t hw" variable, thus leaving uninitialised data in some fields. Specifically, the "chipset" field is uninitialised which causes the "if (hwif->chipset != ide_unknown)" test in drivers/block/ide.c to always fail with the error message " -- BAD OPTION".

Quoted 13 lines

This bug also appears to be present in the mainline 2.4 kernel IDE code. I haven't checked the 2.5 code yet.

Regards,
Andrew Pam

Signature · 6 lines
mailto:[email protected]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Technology Manager, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics
http://two-cents-worth.com/?105347&EG		Donate two cents to our work!
P.O. Box 477, Blackburn VIC 3130 Australia	Phone +61 401 258 915

Andre Hedrick
LAD Storage Consulting Group

author
#3 lore raw
In reply to Andrew Pam
Quoted 22 lines · Andre Hedrick

Please check the function in the top of ide.c

linux-2.4.19-p7 ide.c

static void init_hwif_data (unsigned int index)

{
        unsigned int unit;
        hw_regs_t hw;
        ide_hwif_t *hwif = &ide_hwifs[index];

        /* bulk initialize hwif & drive info with zeros */
        memset(hwif, 0, sizeof(ide_hwif_t));
        memset(&hw, 0, sizeof(hw_regs_t));

        /* fill in any non-zero initial values */
        hwif->index     = index;
        ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
        memcpy(&hwif->hw, &hw, sizeof(hw));
        memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
        hwif->noprobe   = !hwif->io_ports[IDE_DATA_OFFSET];
Quoted 2 lines

Obviously you are calling things outside of the normal usage of the driver.

No, this is the existing driver as shipped; I have not modified the code. The init_hwif_data roiutine has not yet been called while the ide_setup() routine is parsing the kernel parameters, hence the bug.

Quoted 24 lines

2.2.19 ide.c

/*
* Do not even *think* about calling this!
*/
static void init_hwif_data (unsigned int index)

{
        unsigned int unit;
        hw_regs_t hw;
        ide_hwif_t *hwif = &ide_hwifs[index];

        /* bulk initialize hwif & drive info with zeros */
        memset(hwif, 0, sizeof(ide_hwif_t));
        memset(&hw, 0, sizeof(hw_regs_t));

        /* fill in any non-zero initial values */
        hwif->index     = index;
        ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
        memcpy(&hwif->hw, &hw, sizeof(hw));
        memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
        hwif->noprobe   = !hwif->io_ports[IDE_DATA_OFFSET];
#ifdef CONFIG_BLK_DEV_HD
        if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
Quoted 2 lines

If you are attempting to introduce a hw.chipset which is unknown to the driver please submit a patch to register it or the enum index will barf.

No, I have a qd6580 which is already supported. This bug is in existing kernel code; I am not adding any new code, but spent some hours debugging the problem with printk statements.

Regards,
Andrew Pam

Signature · 6 lines
mailto:[email protected]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Technology Manager, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics
http://two-cents-worth.com/?105347&EG		Donate two cents to our work!
P.O. Box 477, Blackburn VIC 3130 Australia	Phone +61 401 258 915
#4 lore raw

from ide.c

*/
int __init ide_setup (char *s)

{
        int i, vals[3];
<snip>
        printk("ide_setup: %s", s);
        init_ide_data ();

#define MAGIC_COOKIE 0x12345678
static void __init init_ide_data (void)

{
        unsigned int index;
        static unsigned long magic_cookie = MAGIC_COOKIE;

        if (magic_cookie != MAGIC_COOKIE)
                return;         /* already initialized */
        magic_cookie = 0;

        /* Initialise all interface structures */
        for (index = 0; index < MAX_HWIFS; ++index)
                init_hwif_data(index);

        /* Add default hw interfaces */
        ide_init_default_hwifs();

        idebus_parameter = 0;
        system_bus_speed = 0;
}

Now you have me puzzled........
If "ide_setup" which parses the passed settings calls "init_ide_data" which initalizes all "hwif" groups and sets a cookie to prevent "ide_init" from re-initalizing thus purging the contents place in by "ide_setup", how are you getting a "BAD -- OPTION"?

Would please post what you are attempting to pass ?

Quoted 57 lines · Andrew Pam
Quoted 22 lines · Andre Hedrick

Please check the function in the top of ide.c

linux-2.4.19-p7 ide.c

static void init_hwif_data (unsigned int index)

{
        unsigned int unit;
        hw_regs_t hw;
        ide_hwif_t *hwif = &ide_hwifs[index];

        /* bulk initialize hwif & drive info with zeros */
        memset(hwif, 0, sizeof(ide_hwif_t));
        memset(&hw, 0, sizeof(hw_regs_t));

        /* fill in any non-zero initial values */
        hwif->index     = index;
        ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
        memcpy(&hwif->hw, &hw, sizeof(hw));
        memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
        hwif->noprobe   = !hwif->io_ports[IDE_DATA_OFFSET];
Quoted 2 lines

Obviously you are calling things outside of the normal usage of the driver.

No, this is the existing driver as shipped; I have not modified the code. The init_hwif_data roiutine has not yet been called while the ide_setup() routine is parsing the kernel parameters, hence the bug.

Quoted 24 lines

2.2.19 ide.c

/*
* Do not even *think* about calling this!
*/
static void init_hwif_data (unsigned int index)

{
        unsigned int unit;
        hw_regs_t hw;
        ide_hwif_t *hwif = &ide_hwifs[index];

        /* bulk initialize hwif & drive info with zeros */
        memset(hwif, 0, sizeof(ide_hwif_t));
        memset(&hw, 0, sizeof(hw_regs_t));

        /* fill in any non-zero initial values */
        hwif->index     = index;
        ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
        memcpy(&hwif->hw, &hw, sizeof(hw));
        memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
        hwif->noprobe   = !hwif->io_ports[IDE_DATA_OFFSET];
#ifdef CONFIG_BLK_DEV_HD
        if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
Quoted 2 lines

If you are attempting to introduce a hw.chipset which is unknown to the driver please submit a patch to register it or the enum index will barf.

Quoted 14 lines

No, I have a qd6580 which is already supported. This bug is in existing kernel code; I am not adding any new code, but spent some hours debugging the problem with printk statements.

Regards,
Andrew Pam

Signature · 6 lines
mailto:[email protected]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Technology Manager, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics
http://two-cents-worth.com/?105347&EG		Donate two cents to our work!
P.O. Box 477, Blackburn VIC 3130 Australia	Phone +61 401 258 915

Andre Hedrick
LAD Storage Consulting Group

author
#5 lore raw
In reply to Andrew Pam
Quoted 7 lines · Andre Hedrick

Now you have me puzzled........
If "ide_setup" which parses the passed settings calls "init_ide_data" which initalizes all "hwif" groups and sets a cookie to prevent "ide_init" from re-initalizing thus purging the contents place in by "ide_setup", how are you getting a "BAD -- OPTION"?

Would please post what you are attempting to pass ?

"ide0=qd6580"

Don't tell me, you're going to want me to put all my printk debugging back in and show exactly where the data remains uninitialised...

Cheers,
Andrew Pam

Signature · 6 lines
mailto:[email protected]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Technology Manager, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics
http://two-cents-worth.com/?105347&EG		Donate two cents to our work!
P.O. Box 477, Blackburn VIC 3130 Australia	Phone +61 401 258 915
author
#6 lore raw
In reply to Andrew Pam
Quoted 5 lines · Andre Hedrick

Now you have me puzzled........
If "ide_setup" which parses the passed settings calls "init_ide_data" which initalizes all "hwif" groups and sets a cookie to prevent "ide_init" from re-initalizing thus purging the contents place in by "ide_setup", how are you getting a "BAD -- OPTION"?

Off the top of my head, it looks like ide_init_default_hwifs creates an uninitialised "hw_regs_t hw;" variable, fills in some fields, then calls "ide_register_hw(&hw, NULL);" which does "memcpy(&hwif->hw, hw, sizeof(*hw));" thus copying the unitialised fields (such as "chipset") right over the area zeroed by init_ide_data().

Am I on the right track?

Cheers,
Andrew Pam

Signature · 6 lines
mailto:[email protected]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Technology Manager, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics
http://two-cents-worth.com/?105347&EG		Donate two cents to our work!
P.O. Box 477, Blackburn VIC 3130 Australia	Phone +61 401 258 915
#7 lore raw

First question for 2.2.X, in your .config is "CONFIG_BLK_DEV_QD6580" set ? If not then ide0=qd6580 will yield "-- BAD OPTION"

Second question for 2.4.X in your .config is "CONFIG_BLK_DEV_QD65XX" set ? If not then ide0=qd65xx will yield "-- BAD OPTION"

Please check those first.

Cheers,

Quoted 13 lines · Andrew Pam
Quoted 5 lines · Andre Hedrick

Now you have me puzzled........
If "ide_setup" which parses the passed settings calls "init_ide_data" which initalizes all "hwif" groups and sets a cookie to prevent "ide_init" from re-initalizing thus purging the contents place in by "ide_setup", how are you getting a "BAD -- OPTION"?

Off the top of my head, it looks like ide_init_default_hwifs creates an uninitialised "hw_regs_t hw;" variable, fills in some fields, then calls "ide_register_hw(&hw, NULL);" which does "memcpy(&hwif->hw, hw, sizeof(*hw));" thus copying the unitialised fields (such as "chipset") right over the area zeroed by init_ide_data().

Quoted 12 lines

Am I on the right track?

Cheers,
Andrew Pam

Signature · 6 lines
mailto:[email protected]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Technology Manager, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics
http://two-cents-worth.com/?105347&EG		Donate two cents to our work!
P.O. Box 477, Blackburn VIC 3130 Australia	Phone +61 401 258 915

Andre Hedrick
LAD Storage Consulting Group

author
#8 lore raw
In reply to Andrew Pam
Quoted 8 lines · Andre Hedrick

First question for 2.2.X, in your .config is "CONFIG_BLK_DEV_QD6580" set ? If not then ide0=qd6580 will yield "-- BAD OPTION"

Second question for 2.4.X in your .config is "CONFIG_BLK_DEV_QD65XX" set ? If not then ide0=qd65xx will yield "-- BAD OPTION"

Please check those first.

Yes, they are set.

Regards,
Andrew Pam

Signature · 6 lines
mailto:[email protected]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Technology Manager, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics
http://two-cents-worth.com/?105347&EG		Donate two cents to our work!
P.O. Box 477, Blackburn VIC 3130 Australia	Phone +61 401 258 915