pci: fix corrupted pci conf index register by unaligned write
PATCH 1/1 pci: fix corrupted pci conf index register by unaligned write
Commit d0ed8076cbdc261 converted the PCI config access to the memory API, but also inadvertantly changed it to accept unaligned writes, and corrupt the index register in the process. This causes a regression booting NetBSD.
Fix by ignoring unaligned or non-dword writes.
https://bugs.launchpad.net/qemu/+bug/897771
---
hw/pci_host.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
hw/pci_host.c +3 -0
@@ -101,6 +101,9 @@ static void pci_host_config_write(void *opaque, target_phys_addr_t addr,PCI_DPRINTF ("%s addr " TARGET_FMT_plx" len %d val %" PRIx64"\n" , __func__, addr, len, val); +if (addr !=0 || len !=4 ) { +return ; + } s->config_reg = val; }
Signature · 1 line
1.7.7.1
Quoted 11 lines · Avi Kivity
Commit
d0ed8076cbdc261converted the PCI config access to the memory API, but also inadvertantly changed it to accept unaligned writes, and corrupt the index register in the process. This causes a regression booting NetBSD.Fix by ignoring unaligned or non-dword writes.
https://bugs.launchpad.net/qemu/+bug/897771
Reported-by Andreas Gustafsson <[email protected]>Signed-off-by Avi Kivity <[email protected]>
Quoted 21 lines
---
hw/pci_host.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)hw/pci_host.c +3
-0@@ -101,6 +101,9 @@ static void pci_host_config_write(void *opaque, target_phys_addr_t addr,PCI_DPRINTF ("%s addr " TARGET_FMT_plx" len %d val %" PRIx64"\n" , __func__, addr, len, val); +if (addr !=0 || len !=4 ) { +return ; + } s->config_reg = val; }Signature · 1 line
1.7.7.1
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Avi Kivity
Commit
d0ed8076cbdc261converted the PCI config access to the memory API, but also inadvertantly changed it to accept unaligned writes, and corrupt the index register in the process. This causes a regression booting NetBSD.
Quoted 8 lines
Quoted 6 lines
Fix by ignoring unaligned or non-dword writes.
https://bugs.launchpad.net/qemu/+bug/897771
Reported-by Andreas Gustafsson <[email protected]>Signed-off-by Avi Kivity <[email protected]>
CC'ing qemu-stable.
Alex
Quoted 23 lines
Quoted 22 lines
---
hw/pci_host.c| 3 +++1 files changed, 3 insertions(+), 0 deletions(-)hw/pci_host.c +3
-0@@ -101,6 +101,9 @@ static void pci_host_config_write(void *opaque, target_phys_addr_t addr,PCI_DPRINTF ("%s addr " TARGET_FMT_plx" len %d val %" PRIx64"\n" , __func__, addr, len, val); +if (addr !=0 || len !=4 ) { +return ; + } s->config_reg = val; }Signature · 1 line
1.7.7.1
Am 04.01.2012 15:47, schrieb Michael S. Tsirkin:
Quoted 35 lines · Avi Kivity
Quoted 11 lines
Commit
d0ed8076cbdc261converted the PCI config access to the memory API, but also inadvertantly changed it to accept unaligned writes, and corrupt the index register in the process. This causes a regression booting NetBSD.Fix by ignoring unaligned or non-dword writes.
https://bugs.launchpad.net/qemu/+bug/897771
Reported-by Andreas Gustafsson <[email protected]>Signed-off-by Avi Kivity <[email protected]>Quoted 20 lines
---
hw/pci_host.c| 3 +++1 files changed, 3 insertions(+), 0 deletions(-)hw/pci_host.c +3
-0@@ -101,6 +101,9 @@ static void pci_host_config_write(void *opaque, target_phys_addr_t addr, PCI_DPRINTF("%s addr " TARGET_FMT_plx " len %d val %"PRIx64"\n", __func__, addr, len, val); +if (addr !=0 || len !=4 ) { +return ; + } s->config_reg = val; }
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
1.7.7.1
Non dword writes are quite common. I get them with Linux kernels, too. Do you really want to ignore them?
And the check for unaligned writes is, well, unusual :-)
Regards,
Stefan
Quoted 36 lines · Stefan Weil
Am 04.01.2012 15:47, schrieb Michael S. Tsirkin:
Quoted 35 lines · Avi Kivity
Quoted 11 lines
Commit
d0ed8076cbdc261converted the PCI config access to the memory API, but also inadvertantly changed it to accept unaligned writes, and corrupt the index register in the process. This causes a regression booting NetBSD.Fix by ignoring unaligned or non-dword writes.
https://bugs.launchpad.net/qemu/+bug/897771
Reported-by Andreas Gustafsson <[email protected]>Signed-off-by Avi Kivity <[email protected]>Quoted 20 lines
---
hw/pci_host.c| 3 +++1 files changed, 3 insertions(+), 0 deletions(-)hw/pci_host.c +3
-0@@ -101,6 +101,9 @@ static void pci_host_config_write(void *opaque, target_phys_addr_t addr,PCI_DPRINTF ("%s addr " TARGET_FMT_plx" len %d val %" PRIx64"\n" , __func__, addr, len, val); +if (addr !=0 || len !=4 ) { +return ; + } s->config_reg = val; }
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
1.7.7.1Non dword writes are quite common. I get them with Linux kernels, too. Do you really want to ignore them?
Are you sure?
Note this is an io write at cf8. Not an unaligned config write.
Quoted 1 line
And the check for unaligned writes is, well, unusual :-)
This seems to be how memory API behaves ... right, Avi? Maybe this should be documented somewhere.
Quoted 2 lines
Regards,
Stefan
Quoted 37 lines · Michael S. Tsirkin
Quoted 36 lines · Stefan Weil
Am 04.01.2012 15:47, schrieb Michael S. Tsirkin:
Quoted 35 lines · Avi Kivity
Quoted 11 lines
Commit
d0ed8076cbdc261converted the PCI config access to the memory API, but also inadvertantly changed it to accept unaligned writes, and corrupt the index register in the process. This causes a regression booting NetBSD.Fix by ignoring unaligned or non-dword writes.
https://bugs.launchpad.net/qemu/+bug/897771
Reported-by Andreas Gustafsson <[email protected]>Signed-off-by Avi Kivity <[email protected]>Quoted 20 lines
---
hw/pci_host.c| 3 +++1 files changed, 3 insertions(+), 0 deletions(-)hw/pci_host.c +3
-0@@ -101,6 +101,9 @@ static void pci_host_config_write(void *opaque, target_phys_addr_t addr,PCI_DPRINTF ("%s addr " TARGET_FMT_plx" len %d val %" PRIx64"\n" , __func__, addr, len, val); +if (addr !=0 || len !=4 ) { +return ; + } s->config_reg = val; }
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
1.7.7.1Non dword writes are quite common. I get them with Linux kernels, too. Do you really want to ignore them?
Are you sure?
Note this is an io write at cf8. Not an unaligned config write.Quoted 1 line
And the check for unaligned writes is, well, unusual :-)
What's unusual?
Quoted 2 lines
This seems to be how memory API behaves ... right, Avi? Maybe this should be documented somewhere.
Document what?
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 49 lines · Avi Kivity
Quoted 37 lines · Michael S. Tsirkin
Quoted 36 lines · Stefan Weil
Am 04.01.2012 15:47, schrieb Michael S. Tsirkin:
Quoted 35 lines · Avi Kivity
Quoted 11 lines
Commit
d0ed8076cbdc261converted the PCI config access to the memory API, but also inadvertantly changed it to accept unaligned writes, and corrupt the index register in the process. This causes a regression booting NetBSD.Fix by ignoring unaligned or non-dword writes.
https://bugs.launchpad.net/qemu/+bug/897771
Reported-by Andreas Gustafsson <[email protected]>Signed-off-by Avi Kivity <[email protected]>Quoted 20 lines
---
hw/pci_host.c| 3 +++1 files changed, 3 insertions(+), 0 deletions(-)hw/pci_host.c +3
-0@@ -101,6 +101,9 @@ static void pci_host_config_write(void *opaque, target_phys_addr_t addr,PCI_DPRINTF ("%s addr " TARGET_FMT_plx" len %d val %" PRIx64"\n" , __func__, addr, len, val); +if (addr !=0 || len !=4 ) { +return ; + } s->config_reg = val; }Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
1.7.7.1Non dword writes are quite common. I get them with Linux kernels, too. Do you really want to ignore them?
Are you sure?
Note this is an io write at cf8. Not an unaligned config write.Quoted 1 line
And the check for unaligned writes is, well, unusual :-)
Quoted 7 lines
What's unusual?
Quoted 2 lines
This seems to be how memory API behaves ... right, Avi? Maybe this should be documented somewhere.
Document what?
That address passed to callbacks is in fact an offset from start of the region.
Quoted 2 lines
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 6 lines · Michael S. Tsirkin
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
And the check for unaligned writes is, well, unusual :-)
What's unusual?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
This seems to be how memory API behaves ... right, Avi? Maybe this should be documented somewhere.
Document what?
That address passed to callbacks is in fact an offset from start of the region.
It's documented already (and it's not new - since 8da3ff18097, Dec 2008).
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Michael S. Tsirkin
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
And the check for unaligned writes is, well, unusual :-)
What's unusual?
Quoted 2 lines
This seems to be how memory API behaves ... right, Avi? Maybe this should be documented somewhere.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Document what?
That address passed to callbacks is in fact an offset from start of the region.
It's documented already (and it's not new - since
8da3ff18097, Dec 2008).
True, memory.h explicitly says:
@addr is relative to @mr
But now that's mentioned, I have a question:
we could also specify min access size and disable unaligned access in ops.valid structure. That would trigger machine checks on access errors instead of ignoring them as we do now. Anyone knows offhand what does real hardware do?
Quoted 2 lines
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 22 lines · Michael S. Tsirkin
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Michael S. Tsirkin
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
And the check for unaligned writes is, well, unusual :-)
What's unusual?
Quoted 2 lines
This seems to be how memory API behaves ... right, Avi? Maybe this should be documented somewhere.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Document what?
That address passed to callbacks is in fact an offset from start of the region.
It's documented already (and it's not new - since
8da3ff18097, Dec 2008).True,
memory.hexplicitly says:
@addr is relative to @mr
Quoted 6 lines
But now that's mentioned, I have a question:
we could also specify min access size and disable unaligned access in ops.valid structure. That would trigger machine checks on access errors instead of ignoring them as we do now. Anyone knows offhand what does real hardware do?
It depends on the actual hardware. qemu has some #ifdefs deep down that control this.
Ultimately this should be local to the bus rather than global; for example a bus can intercept unaligned writes and invoke some bus specific behaviour even though the cpu allows those accesses.
Signature · 1 line
error compiling committee.c: too many arguments to function