adi_v5_jtag: avoid RAM exhaustion by limiting jtag queue size
authorBohdan Tymkiv <bhdt@cypress.com>
Tue, 26 Feb 2019 09:45:40 +0000 (11:45 +0200)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Fri, 18 Oct 2019 08:20:49 +0000 (09:20 +0100)
commit5f42124a40e8ccbc1b5db3a8898d24408be22c62
tree8d87a2bb7739a93ea42ef7790de1dda9a7458e77
parent03beb01239a8ca02787cb99d19401b1974fe41c4
adi_v5_jtag: avoid RAM exhaustion by limiting jtag queue size

Issue has been found when I tried to read 64 MiB QSPI flash bank.
Bank is memory mapped, default_flash_read() is used for 'flash read_bank'
command. OpenOCD consumed as much as 6.8 GiB of RAM during this
process. Investigation showed that this happens because JTAG queue
is not limited in any way. OpenOCD queues 16 millions of AP reads
allocating all corresponding data structures.

Most of this memory is allocated in:
cmd_queue_alloc (commands.c) - 4.2 GiB
dap_cmd_new (adi_v5_jtag.c) - 2.25GiB

This patch implements a pool of "struct dap_cmd" objects using
linked list. Objects are taken from a pool in "dap_cmd_new()" and
returned to the pool when they are not needed. Size of the pool
is limited to 64K of objects, JTAG queue is forcibly executed
when this limit is reached.

Checked with Valgrind and Clang analyzer - no new warnings.

Change-Id: I5aaaecce5ed71414f7965a2598f49742f6a6b2b5
Signed-off-by: Bohdan Tymkiv <bhdt@cypress.com>
Reviewed-on: http://openocd.zylin.com/4948
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
src/target/adi_v5_jtag.c
src/target/arm_adi_v5.h
src/target/arm_dap.c