Repository navigation
erasure_code/aarch64: limit SVE dot product table loads to 16 bytes - #479
Shakhtar-Sankur wants to merge 3 commits into
Conversation
gf_nvect_dot_prod_sve_unrolled() loads the two 16-byte halves of each 32-byte coefficient table with svptrue_b8(), so each load reads a full SVE vector. svtbl_u8() only indexes lanes 0-15, so the extra bytes are never used, but for the last coefficient the second load reads VL/8 - 16 bytes past the end of gftbls: 16 bytes at 256-bit VL (Neoverse V1), 48 at 512-bit (A64FX), up to 240 at 2048-bit. If the table ends at the end of a mapping, ec_encode_data() and gf_vect_dot_prod() fault. All of the gf_*vect_dot_prod_sve and _sve2 kernels are built from this function. Load the table halves with a 16-lane predicate instead. Inactive lanes are not read, and svtbl_u8() never uses them, so the results are unchanged. Add a check to erasure_code_test that runs ec_encode_data() and gf_vect_dot_prod() with a table of exactly 32 * k * rows bytes that ends at an inaccessible guard page, and compares the parity with ec_encode_data_base(). Fixes intel#476 Signed-off-by: Sankur Kundu <sankur.kundu.tw@gmail.com>
|
The kernel fix looks correct. Please fix two test issues before merging:
|
The guard page test used up to 42 of the shared test buffers, which breaks when TEST_SOURCES is set lower. Allocate its own buffers instead. Also check the reference against tables from ec_init_tables_base(), since ec_init_tables() produces a different format on GFNI capable CPUs, and overwrite the output before calling gf_vect_dot_prod() so the check cannot pass on the data written by ec_encode_data(). Signed-off-by: Sankur Kundu <sankur.kundu.tw@gmail.com>
|
Thanks @liuqinfei, both fixed in d0a142e:
While testing on an x86 CPU with GFNI I also found that the reference was computed with ec_encode_data_base() on tables from ec_init_tables(), which uses the GFNI table format there, so the test failed on GFNI machines. The reference now uses its own tables from ec_init_tables_base(). Under qemu, the test still segfaults on the guard page without the kernel fix at SVE vector lengths of 256, 512 and 2048 bits (and on neoverse-v1 and a64fx), and passes with it, including 128-bit SVE and NEON only. |
|
Thanks, d0a142e addresses both requested test fixes, and the separate base-format reference tables are correct. I rechecked One remaining test issue: the new source/output buffers use Please allocate |
With EC_ALIGNED_ADDR the encode functions use aligned loads and stores, so allocate the guard page test buffers with posix_memalign() like the rest of the test, and release them with aligned_free(). Signed-off-by: Sankur Kundu <sankur.kundu.tw@gmail.com>
|
Thanks @liuqinfei, done in 8c87417: the guard page test buffers are now allocated with posix_memalign(..., 64, len) and released with aligned_free(). With the library built with D="EC_ALIGNED_ADDR", the guard page test on its own segfaults with the previous malloc() buffers and passes now (x86-64 with AVX-512 and GFNI). The aarch64 SVE results are unchanged. For information: in the same EC_ALIGNED_ADDR build on that machine, erasure_code_test on master (af6a939) also segfaults, earlier, in the efence encode loop (vmovntdqa in the AVX-512 kernel on 16-byte aligned efence buffers). That is separate from this PR, so I haven't changed it here. |
Fixes #476
gf_nvect_dot_prod_sve_unrolled()loads the two 16-byte halves of each 32-byte coefficient table withsvptrue_b8(), so each load reads a full SVE vector.svtbl_u8()only indexes lanes 0-15, so the extra bytes are never used, but for the last coefficient the second load reads VL/8 - 16 bytes past the end ofgftbls: 16 bytes at 256-bit VL (Neoverse V1), 48 at 512-bit (A64FX), up to 240 at 2048-bit. When the table ends at the end of a mapping,ec_encode_data()andgf_vect_dot_prod()fault. All of thegf_*vect_dot_prod_sveand_sve2kernels are built from this function.The fix loads the table halves with a 16-lane predicate (
svwhilelt_b8_s32(0, 16)). Inactive lanes are not read andsvtbl_u8()never uses them, so the results are unchanged.As suggested in the issue,
erasure_code_testnow also runsec_encode_data()andgf_vect_dot_prod()with a table of exactly32 * k * rowsbytes that ends at an inaccessible guard page (k from 1 to 32, 1 to 10 rows), and compares the parity withec_encode_data_base(). It follows the guard-page test inmem/mem_zero_detect_test.c, including the Windows path.Testing: cross-compiled with GCC 14 for aarch64 and run under qemu-aarch64 8.2 user mode.
The reproducer from #476 gives the same pattern. With this PR,
erasure_code_test,erasure_code_update_test,gf_vect_mul_test,gf_inverse_testandgf_vect_dot_prod_testpass on all seven CPU configurations, and native x86-64make checkpasses (18/18). The changed files are clean with clang-format 18 (the repo's.clang-format).