Make sure not to overrun the internal data buffer.
PATCH 1/1 Make sure not to overrun the internal data buffer.
It did happen that the internal data buffer was overrun leading to a Qemu crash (in particular while emulating the i.MX6 sabrelite board).
This patch makes sure the data array would not be overrun and allow the sabrelite emulation to run without crash.
--- hw/block/m25p80.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/m25p80.c +1 -1
@@ -1117,7 +1117,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) s->data[s->len] = (uint8_t )tx; s->len++; -if (s->len == s->needed_bytes) { +if ((s->len >= s->needed_bytes) || (s->len >=sizeof (s->data))) {complete_collecting_data (s); }break ;
Signature · 1 line
2.9.3
Hello,
W dniu 24.12.2016 o 16:11, Jean-Christophe Dubois pisze:
Quoted 16 lines
It did happen that the internal data buffer was overrun leading to a Qemu crash (in particular while emulating the i.MX6 sabrelite board).
This patch makes sure the data array would not be overrun and allow the sabrelite emulation to run without crash.
Signed-off-by Jean-Christophe Dubois <[email protected]>--- hw/block/m25p80.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/block/m25p80.c +0
-0
hw/block/m25p80.c static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) · line 1123
Quoted 8 lines
hw/block/m25p80.c +1
-1@@ -1117,7 +1117,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) s->data[s->len] = (uint8_t )tx; s->len++; -if (s->len == s->needed_bytes) { +if ((s->len >= s->needed_bytes) || (s->len >=sizeof (s->data))) {complete_collecting_data (s); }break ;
Do you have exact scenario that caused the problem? Generally it should not happen.
Thanks,
Marcin
Quoted 14 lines · mar.krzeminski
Hello,
W dniu 24.12.2016 o 16:11, Jean-Christophe Dubois pisze:
Quoted 11 lines
It did happen that the internal data buffer was overrun leading to a Qemu crash (in particular while emulating the i.MX6 sabrelite board).
This patch makes sure the data array would not be overrun and allow the sabrelite emulation to run without crash.
Signed-off-by Jean-Christophe Dubois <[email protected]>--- hw/block/m25p80.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 5 lines
hw/block/m25p80.c +0
-0hw/block/m25p80.c static uint32_t m25p80_transfer8(SSISlave *ss, · line 1123
Quoted 9 lines
hw/block/m25p80.c +1
-0@@ -1117,7 +1117,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) s->data[s->len] = (uint8_t)tx; s->len++; - if (s->len == s->needed_bytes) { +if ((s->len >= s->needed_bytes) || (s->len >=sizeof (s->data))) {complete_collecting_data (s); }break ;Do you have exact scenario that caused the problem?
When booting Xvisor (http://xhypervisor.org/) on top of Qemu emulated Sabrelite.
During the boot Qemu would segfault while writing to the SPI flash.
Quoted 1 line
Generally it should not happen.
The fact is that there is no protection to make sure the data array is not overrun.
May be it should not happen but it did happen in this case ....
JC
Quoted 5 lines
Thanks,
Marcin
W dniu 24.12.2016 o 18:41, Jean-Christophe DUBOIS pisze:
Quoted 31 lines · mar.krzeminski
Quoted 14 lines
Hello,
W dniu 24.12.2016 o 16:11, Jean-Christophe Dubois pisze:
Quoted 11 lines
It did happen that the internal data buffer was overrun leading to a Qemu crash (in particular while emulating the i.MX6 sabrelite board).
This patch makes sure the data array would not be overrun and allow the sabrelite emulation to run without crash.
Signed-off-by Jean-Christophe Dubois <[email protected]>--- hw/block/m25p80.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 15 lines
Quoted 5 lines
hw/block/m25p80.c +0
-0hw/block/m25p80.c static uint32_t m25p80_transfer8(SSISlave *ss, · line 1123
Quoted 9 lines
hw/block/m25p80.c +1
-0@@ -1117,7 +1117,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) s->data[s->len] = (uint8_t)tx; s->len++; - if (s->len == s->needed_bytes) { +if ((s->len >= s->needed_bytes) || (s->len >=sizeof (s->data))) {complete_collecting_data (s); }break ;Do you have exact scenario that caused the problem?
Quoted 3 lines
When booting Xvisor (http://xhypervisor.org/) on top of Qemu emulated Sabrelite.
During the boot Qemu would segfault while writing to the SPI flash.
Thanks, I'll try to take I look.
Quoted 4 lines
Quoted 2 lines
Generally it should not happen.
The fact is that there is no protection to make sure the data array is not overrun.
Yes. IMHO it could be nice to log some error here and reset state machine instead of going to next state.
Quoted 2 lines
May be it should not happen but it did happen in this case ....
Yeap, but this mean m25p80's state machine goes nuts. Overflow is just a symptom that something wrong is going on.
Thanks,
Marcin
Quoted 11 lines
JC
Quoted 5 lines
Thanks,
Marcin
Quoted 34 lines · mar.krzeminski
W dniu 24.12.2016 o 18:41, Jean-Christophe DUBOIS pisze:
Quoted 31 lines · mar.krzeminski
Quoted 29 lines
Hello,
W dniu 24.12.2016 o 16:11, Jean-Christophe Dubois pisze:
Quoted 16 lines
It did happen that the internal data buffer was overrun leading to a Qemu crash (in particular while emulating the i.MX6 sabrelite board).
This patch makes sure the data array would not be overrun and allow the sabrelite emulation to run without crash.
Signed-off-by Jean-Christophe Dubois <[email protected]>--- hw/block/m25p80.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/block/m25p80.c +0
-0hw/block/m25p80.c static uint32_t m25p80_transfer8(SSISlave · line 1123
Quoted 9 lines
hw/block/m25p80.c +1
-0@@ -1117,7 +1117,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) s->data[s->len] = (uint8_t )tx; s->len++; - if (s->len == s->needed_bytes) { +if ((s->len >= s->needed_bytes) || (s->len >=sizeof (s->data))) {complete_collecting_data (s); }break ;Do you have exact scenario that caused the problem?
Quoted 4 lines
Quoted 3 lines
When booting Xvisor (http://xhypervisor.org/) on top of Qemu emulated Sabrelite.
During the boot Qemu would segfault while writing to the SPI flash.
Thanks, I'll try to take I look.
Once you have built Xvisor for "generic ARMv7" you can run the following command.
qemu-system-arm -M sabrelite -display none -serial null -serial stdio -kernel ./build/vmm.bin -initrd ./build/vmm.bin -dtb ./build/arch/arm/board/generic/dts/imx6/sabrelite-a9/one_guest_sabrelite-a9.dtb
You can also run Qemu under valgrind that will pinpoint the problem.
JC
Quoted 26 lines
Quoted 4 lines
Quoted 2 lines
Generally it should not happen.
The fact is that there is no protection to make sure the data array is not overrun.
Yes. IMHO it could be nice to log some error here and reset state machine instead of going to next state.
Quoted 2 lines
May be it should not happen but it did happen in this case ....
Yeap, but this mean m25p80's state machine goes nuts. Overflow is just a symptom that something wrong is going on.
Thanks,
MarcinQuoted 11 lines
JC
Quoted 5 lines
Thanks,
Marcin
You can have a more detailed procedure on how to run Xvisor on Qemu Sabrelite (with Linux guests if you wish) at the following URL.
https://github.com/avpatel/xvisor-next/blob/master/docs/arm/imx6-sabrelite.txt
You don't need to start the guest to see the crash. Just boot Xvisor ...
JC
Quoted 79 lines · Jean-Christophe DUBOIS
Quoted 34 lines · mar.krzeminski
W dniu 24.12.2016 o 18:41, Jean-Christophe DUBOIS pisze:
Quoted 31 lines · mar.krzeminski
Quoted 29 lines
Hello,
W dniu 24.12.2016 o 16:11, Jean-Christophe Dubois pisze:
Quoted 16 lines
It did happen that the internal data buffer was overrun leading to a Qemu crash (in particular while emulating the i.MX6 sabrelite board).
This patch makes sure the data array would not be overrun and allow the sabrelite emulation to run without crash.
Signed-off-by Jean-Christophe Dubois <[email protected]>--- hw/block/m25p80.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/block/m25p80.c +0
-0hw/block/m25p80.c static uint32_t m25p80_transfer8(SSISlave · line 1123
Quoted 9 lines
hw/block/m25p80.c +1
-0@@ -1117,7 +1117,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) s->data[s->len] = (uint8_t )tx; s->len++; - if (s->len == s->needed_bytes) { +if ((s->len >= s->needed_bytes) || (s->len >=sizeof (s->data))) {complete_collecting_data (s); }break ;Do you have exact scenario that caused the problem?
Quoted 4 lines
Quoted 3 lines
When booting Xvisor (http://xhypervisor.org/) on top of Qemu emulated Sabrelite.
During the boot Qemu would segfault while writing to the SPI flash.
Thanks, I'll try to take I look.
Once you have built Xvisor for "generic ARMv7" you can run the following command.
qemu-system-arm -M sabrelite -display none -serial null -serial stdio -kernel ./build/vmm.bin -initrd ./build/vmm.bin -dtb ./build/arch/arm/board/generic/dts/imx6/sabrelite-a9/one_guest_sabrelite-a9.dtb
You can also run Qemu under valgrind that will pinpoint the problem.
JC
Quoted 26 lines
Quoted 4 lines
Quoted 2 lines
Generally it should not happen.
The fact is that there is no protection to make sure the data array is not overrun.
Yes. IMHO it could be nice to log some error here and reset state machine instead of going to next state.
Quoted 2 lines
May be it should not happen but it did happen in this case ....
Yeap, but this mean m25p80's state machine goes nuts. Overflow is just a symptom that something wrong is going on.
Thanks,
MarcinQuoted 11 lines
JC
Quoted 5 lines
Thanks,
Marcin
W dniu 27.12.2016 o 18:08, Jean-Christophe DUBOIS pisze:
Quoted 56 lines
You can have a more detailed procedure on how to run Xvisor on Qemu Sabrelite (with Linux guests if you wish) at the following URL.
https://github.com/avpatel/xvisor-next/blob/master/docs/arm/imx6-sabrelite.txt
You don't need to start the guest to see the crash. Just boot Xvisor ...
JC
Quoted 46 lines · Jean-Christophe DUBOIS
Quoted 34 lines · mar.krzeminski
W dniu 24.12.2016 o 18:41, Jean-Christophe DUBOIS pisze:
Quoted 31 lines · mar.krzeminski
Quoted 29 lines
Hello,
W dniu 24.12.2016 o 16:11, Jean-Christophe Dubois pisze:
Quoted 16 lines
It did happen that the internal data buffer was overrun leading to a Qemu crash (in particular while emulating the i.MX6 sabrelite board).
This patch makes sure the data array would not be overrun and allow the sabrelite emulation to run without crash.
Signed-off-by Jean-Christophe Dubois <[email protected]>--- hw/block/m25p80.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/block/m25p80.c +0
-0hw/block/m25p80.c static uint32_t m25p80_transfer8(SSISlave · line 1123
Quoted 9 lines
hw/block/m25p80.c +1
-0@@ -1117,7 +1117,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) s->data[s->len] = (uint8_t )tx; s->len++; - if (s->len == s->needed_bytes) { +if ((s->len >= s->needed_bytes) || (s->len >=sizeof (s->data))) {complete_collecting_data (s); }break ;Do you have exact scenario that caused the problem?
Quoted 4 lines
Quoted 3 lines
When booting Xvisor (http://xhypervisor.org/) on top of Qemu emulated Sabrelite.
During the boot Qemu would segfault while writing to the SPI flash.
Thanks, I'll try to take I look.
Once you have built Xvisor for "generic ARMv7" you can run the following command.
qemu-system-arm -M sabrelite -display none -serial null -serial stdio -kernel ./build/vmm.bin -initrd ./build/vmm.bin -dtb ./build/arch/arm/board/generic/dts/imx6/sabrelite-a9/one_guest_sabrelite-a9.dtb
I got some time, and reproduced the problem. Here are some logs with m25p80 debugs:
: decode_new_cmd: decoded new command:9f
: decode_new_cmd: populated jedec code
: decode_new_cmd: decoded new command:0
: decode_new_cmd: decoded new command:0 //Getting flash Id in above 4 lines -> OK (but missing CS) Found sst25vf016b compatible flash device
: decode_new_cmd: decoded new command:6 //Write enable, command without payload, so it is ok : decode_new_cmd: decoded new command:1 //Write to status register, guest sends data
INFO: spi0.0: sst25vf016b (2048 Kbytes)
INFO: spi0.0: mtd
.name = spi0.0,
.size = 0x200000 (2MiB)
.erasesize = 0x00001000 (4KiB)
.numeraseregions = 0
Segmentation fault (core dumped) //Here probably guest try to send some data
The root cause why m25p80 enter strange state is that CS line is not selected/deselected at all- there is missing debug from m25p80_cs. In spi transfer CS line (here qemu_irq) should be 0 before begin of every message, and set after end of transmission. In case of simple WREN command you should see something like this:
: m25p80_cs: deselect
: decode_new_cmd: decoded new command:6
: m25p80_cs: select
Can you check spi controller model code?
Thanks,
Marcin
Quoted 35 lines
Quoted 33 lines
You can also run Qemu under valgrind that will pinpoint the problem.
JC
Quoted 26 lines
Quoted 4 lines
Quoted 2 lines
Generally it should not happen.
The fact is that there is no protection to make sure the data array is not overrun.
Yes. IMHO it could be nice to log some error here and reset state machine instead of going to next state.
Quoted 2 lines
May be it should not happen but it did happen in this case ....
Yeap, but this mean m25p80's state machine goes nuts. Overflow is just a symptom that something wrong is going on.
Thanks,
MarcinQuoted 11 lines
JC
Quoted 5 lines
Thanks,
Marcin
Quoted 16 lines · mar.krzeminski
I got some time, and reproduced the problem. Here are some logs with m25p80 debugs:
:decode_new_cmd: decoded new command:9f
:decode_new_cmd: populated jedec code
:decode_new_cmd: decoded new command:0
:decode_new_cmd: decoded new command:0 //Getting flash Id in above 4 lines -> OK (but missing CS) Found sst25vf016b compatible flash device
:decode_new_cmd: decoded new command:6 //Write enable, command without payload, so it is ok :decode_new_cmd: decoded new command:1 //Write to status register, guest sends data
INFO: spi0.0: sst25vf016b (2048 Kbytes)
INFO: spi0.0: mtd
.name = spi0.0,
.size =0x200000(2MiB)
.erasesize =0x00001000(4KiB)
.numeraseregions = 0
Segmentation fault (core dumped) //Here probably guest try to send some data
Quoted 8 lines
The root cause why m25p80 enter strange state is that CS line is not selected/deselected at all- there is missing debug from
m25p80_cs. In spi transfer CS line (hereqemu_irq) should be 0 before begin of every message, and set after end of transmission. In case of simple WREN command you should see something like this:
:m25p80_cs: deselect
:decode_new_cmd: decoded new command:6
:m25p80_cs: selectCan you check spi controller model code?
I'll double check.
But why is the SPI memory/device even responding if CS is not set ?
Quoted 5 lines
Thanks,
Marcin
W dniu 30.12.2016 o 18:14, Jean-Christophe DUBOIS pisze:
Quoted 24 lines · mar.krzeminski
Quoted 23 lines
I got some time, and reproduced the problem. Here are some logs with m25p80 debugs:
:decode_new_cmd: decoded new command:9f
:decode_new_cmd: populated jedec code
:decode_new_cmd: decoded new command:0
:decode_new_cmd: decoded new command:0 //Getting flash Id in above 4 lines -> OK (but missing CS) Found sst25vf016b compatible flash device
:decode_new_cmd: decoded new command:6 //Write enable, command without payload, so it is ok :decode_new_cmd: decoded new command:1 //Write to status register, guest sends data
INFO: spi0.0: sst25vf016b (2048 Kbytes)
INFO: spi0.0: mtd
.name = spi0.0,
.size =0x200000(2MiB)
.erasesize =0x00001000(4KiB)
.numeraseregions = 0
Segmentation fault (core dumped) //Here probably guest try to send some dataThe root cause why m25p80 enter strange state is that CS line is not selected/deselected at all- there is missing debug from
m25p80_cs. In spi transfer CS line (hereqemu_irq) should be 0 before begin of every message, and set after end of transmission. In case of simple WREN command you should see something like this:
:m25p80_cs: deselect
:decode_new_cmd: decoded new command:6
:m25p80_cs: select
Quoted 5 lines
Quoted 1 line
Can you check spi controller model code?
I'll double check.
But why is the SPI memory/device even responding if CS is not set ?
Looking at ssi code it should not.
Flash (so the m25p80) is responding when CS line is low and it seem that this is default.
Thanks,
Marcin
Quoted 8 lines
Quoted 6 lines
Thanks,
Marcin
Quoted 7 lines · mar.krzeminski
Quoted 5 lines
Quoted 1 line
Can you check spi controller model code?
I'll double check.
But why is the SPI memory/device even responding if CS is not set ?
Looking at ssi code it should not.
Flash (so the m25p80) is responding when CS line is low and it seem that this is default.
So I fixed the CS handling in the i.MX SPI device emulator and I don't experience crashes anymore. Thanks for your help.
You may still want to harden the m25p80 code to make sure it doesn't overrun its internal buffer.
Quoted 14 lines
Thanks,
MarcinQuoted 8 lines
Quoted 6 lines
Thanks,
Marcin
W dniu 02.01.2017 o 22:24, Jean-Christophe DUBOIS pisze:
Quoted 10 lines · mar.krzeminski
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Can you check spi controller model code?
I'll double check.
But why is the SPI memory/device even responding if CS is not set ?
Looking at ssi code it should not.
Flash (so the m25p80) is responding when CS line is low and it seem that this is default.So I fixed the CS handling in the i.MX SPI device emulator and I don't experience crashes anymore. Thanks for your help.
Cool!
Quoted 2 lines
You may still want to harden the m25p80 code to make sure it doesn't overrun its internal buffer.
Yeap, for me it is a bug.
I understand you will not finish this patch, won't you ?:)
Thanks,
Marcin
Quoted 17 lines
Quoted 15 lines
Thanks,
MarcinQuoted 8 lines
Quoted 6 lines
Thanks,
Marcin
Quoted 5 lines · mar.krzeminski
Quoted 2 lines
You may still want to harden the m25p80 code to make sure it doesn't overrun its internal buffer.
Yeap, for me it is a bug.
I understand you will not finish this patch, won't you ?:)
I could give it a shot.
JC