Skip to contentSkip to conversation

tests/qtest/aspeed-acry: Allocate SRAM buffers on the heap

PATCH In review Jamin Lin 2 participants 2 messages Sep 10 – Sep 15 Arm/Aspeed machine support

lore
Share & tools
lore

Jamin Lin

author
#0 lore raw

PATCH 1/1 tests/qtest/aspeed-acry: Allocate SRAM buffers on the heap

The ACRY RSA qtest allocates two ACRY_SRAM_SIZE buffers on the stack. Since each buffer is nearly 9 KiB, this unnecessarily increases the stack usage of test_modexp_rsa() and may cause unexpected failures on environments with a limited stack size.

This reduces the stack usage while preserving the existing test behavior.

---
 tests/qtest/aspeed-acry-test.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/qtest/aspeed-acry-test.c +4 -4
index ec348c2206..51048d697c 100644
@@ -327,8 +327,8 @@ static void test_modexp_rsa(const void *opaque)
         .alg = QCRYPTO_AK_CIPHER_ALGO_RSA,
         .u.rsa.padding_alg = QCRYPTO_RSA_PADDING_ALGO_RAW,
     };
-    uint8_t dram_buf[ACRY_SRAM_SIZE] = { 0 };
-    uint8_t sram_buf[ACRY_SRAM_SIZE] = { 0 };
+    g_autofree uint8_t *dram_buf = g_malloc0(ACRY_SRAM_SIZE);
+    g_autofree uint8_t *sram_buf = g_malloc0(ACRY_SRAM_SIZE);
     uint8_t result[ACRY_MAX_BYTES] = { 0 };
     QTestState *qts;
 
@@ -345,7 +345,7 @@ static void test_modexp_rsa(const void *opaque)
     put_bignum_be_bytes(dram_buf, ACRY_MOD_OFFSET, t->n, t->n_len);
     put_bignum_be_bytes(dram_buf, ACRY_DATA_OFFSET, t->m, t->m_len);
 
-    qtest_memwrite(qts, c->dram_addr, dram_buf, sizeof(dram_buf));
+    qtest_memwrite(qts, c->dram_addr, dram_buf, ACRY_SRAM_SIZE);
 
     qtest_writel(qts, c->acry_addr + ACRY_DMA_CMD, ACRY_DMA_CMD_DMEM_AHB);
     qtest_writel(qts, c->acry_addr + ACRY_DMA_SRC, c->dram_addr);
@@ -362,7 +362,7 @@ static void test_modexp_rsa(const void *opaque)
     g_assert_cmphex(qtest_readl(qts, c->acry_addr + ACRY_STATUS), ==,
                     ACRY_STATUS_RSA_DONE);
 
-    qtest_memread(qts, c->sram_addr, sram_buf, sizeof(sram_buf));
+    qtest_memread(qts, c->sram_addr, sram_buf, ACRY_SRAM_SIZE);
     get_bignum_be_bytes(sram_buf, ACRY_DATA_OFFSET, result, t->c_len);
     g_assert_cmpmem(result, t->c_len, t->c, t->c_len);
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 38 lines · Jamin Lin

The ACRY RSA qtest allocates two ACRY_SRAM_SIZE buffers on the stack. Since each buffer is nearly 9 KiB, this unnecessarily increases the stack usage of test_modexp_rsa() and may cause unexpected failures on environments with a limited stack size.

This reduces the stack usage while preserving the existing test behavior.

---
  tests/qtest/aspeed-acry-test.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
tests/qtest/aspeed-acry-test.c +3 -3
index ec348c2206..51048d697c 100644
@@ -327,8 +327,8 @@ static void test_modexp_rsa(const void *opaque)
          .alg = QCRYPTO_AK_CIPHER_ALGO_RSA,
          .u.rsa.padding_alg = QCRYPTO_RSA_PADDING_ALGO_RAW,
      };
-    uint8_t dram_buf[ACRY_SRAM_SIZE] = { 0 };
-    uint8_t sram_buf[ACRY_SRAM_SIZE] = { 0 };
+    g_autofree uint8_t *dram_buf = g_malloc0(ACRY_SRAM_SIZE);
+    g_autofree uint8_t *sram_buf = g_malloc0(ACRY_SRAM_SIZE);
      uint8_t result[ACRY_MAX_BYTES] = { 0 };
      QTestState *qts;
 
@@ -345,7 +345,7 @@ static void test_modexp_rsa(const void *opaque)
      put_bignum_be_bytes(dram_buf, ACRY_MOD_OFFSET, t->n, t->n_len);
      put_bignum_be_bytes(dram_buf, ACRY_DATA_OFFSET, t->m, t->m_len);
 
-    qtest_memwrite(qts, c->dram_addr, dram_buf, sizeof(dram_buf));
+    qtest_memwrite(qts, c->dram_addr, dram_buf, ACRY_SRAM_SIZE);
 
      qtest_writel(qts, c->acry_addr + ACRY_DMA_CMD, ACRY_DMA_CMD_DMEM_AHB);
      qtest_writel(qts, c->acry_addr + ACRY_DMA_SRC, c->dram_addr);

tests/qtest/aspeed-acry-test.c static void test_modexp_rsa(const void *opaque) · line 368

Quoted 8 lines
tests/qtest/aspeed-acry-test.c +1 -1
@@ -362,7 +362,7 @@ static void test_modexp_rsa(const void *opaque)
      g_assert_cmphex(qtest_readl(qts, c->acry_addr + ACRY_STATUS), ==,
                      ACRY_STATUS_RSA_DONE);
 
-    qtest_memread(qts, c->sram_addr, sram_buf, sizeof(sram_buf));
+    qtest_memread(qts, c->sram_addr, sram_buf, ACRY_SRAM_SIZE);
      get_bignum_be_bytes(sram_buf, ACRY_DATA_OFFSET, result, t->c_len);
      g_assert_cmpmem(result, t->c_len, t->c, t->c_len);
 

Thanks,

C.