workaround for cmd646 bmdma register access while no dma is active
PATCH 1/1 workaround for cmd646 bmdma register access while no dma is active
From: Igor V. Kovalenko <[email protected]>
This is a workaround only, and is a partial revert of a few changes to BMDMAState which removed pci_dev field on the way.
- cmd646 pci_from_bm() expects bm->unit value to correspond with bm data being passed to callback as opaque pointer. This breaks when write to dma control register of second channel happens when no dma operation is in progress, so bm->unit is zero for second channel, and pci_from_bm() returns garbage pointer. Crash happens shortly after that while dereferencing that pointer.
--- hw/ide/cmd646.c | 2 ++ hw/ide/internal.h | 1 + hw/ide/piix.c | 1 + 3 files changed, 4 insertions(+), 0 deletions(-)
hw/ide/cmd646.c +2 -0
@@ -70,6 +70,7 @@ static void ide_map(PCIDevice *pci_dev, int region_num,static PCIIDEState *pci_from_bm (BMDMAState *bm) { +return bm->pci_dev;if (bm->unit ==0 ) {return container_of (bm, PCIIDEState, bmdma[0 ]); }else {
@@ -145,6 +146,7 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,BMDMAState *bm = &d->bmdma[i]; d->bus[i].bmdma = bm; bm->bus = d->bus+i; + bm->pci_dev = d;qemu_add_vm_change_state_handler (ide_dma_restart_cb, bm);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
hw/ide/internal.h +1 -0
@@ -474,6 +474,7 @@ struct BMDMAState {uint8_t status;uint32_t addr; +struct PCIIDEState *pci_dev;IDEBus *bus;/* current transfer state */ uint32_t cur_addr;
hw/ide/piix.c +1 -0
@@ -78,6 +78,7 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,BMDMAState *bm = &d->bmdma[i]; d->bus[i].bmdma = bm; bm->bus = d->bus+i; + bm->pci_dev = d;qemu_add_vm_change_state_handler (ide_dma_restart_cb, bm);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
Quoted 15 lines · Igor V. Kovalenko
From: Igor V. Kovalenko <[email protected]>
This is a workaround only, and is a partial revert of a few changes to BMDMAState which removed
pci_devfield on the way.- cmd646
pci_from_bm()expectsbm->unitvalue to correspond with bm data being passed to callback as opaque pointer. This breaks when write to dma control register of second channel happens when no dma operation is in progress, sobm->unitis zero for second channel, andpci_from_bm()returns garbage pointer. Crash happens shortly after that while dereferencing that pointer.
Quoted 6 lines
static PCIIDEState *pci_from_bm(BMDMAState *bm) {
+ returnbm->pci_dev;
if (bm->unit== 0) {
returncontainer_of(bm, PCIIDEState, bmdma[0]); } else {
I think you should delete the rest of the function, unused code is useless and if someone decides to fix and restore the old code, they can fetch it from git.
Quoted 24 lines · Blue Swirl
Quoted 15 lines · Igor V. Kovalenko
From: Igor V. Kovalenko <[email protected]>
This is a workaround only, and is a partial revert of a few changes to BMDMAState which removed
pci_devfield on the way.- cmd646
pci_from_bm()expectsbm->unitvalue to correspond with bm data being passed to callback as opaque pointer. This breaks when write to dma control register of second channel happens when no dma operation is in progress, sobm->unitis zero for second channel, andpci_from_bm()returns garbage pointer. Crash happens shortly after that while dereferencing that pointer.Quoted 6 lines
static PCIIDEState *pci_from_bm(BMDMAState *bm) {
+ returnbm->pci_dev;
if (bm->unit== 0) {
returncontainer_of(bm, PCIIDEState, bmdma[0]); } else {
Quoted 3 lines
I think you should delete the rest of the function, unused code is useless and if someone decides to fix and restore the old code, they can fetch it from git.
Thanks, resent with this change.
Signature · 2 lines
Kind regards, Igor V. Kovalenko