Pull Request已成功合入, 合并人@CANN-robot
(感谢 huanghaihong 的贡献)变更摘要
该 PR 主要修复 rms_norm_quant_v2 内核在 arch35 架构下因全局内存(GM)复制时使用对齐尺寸(xGammaBetaAlign、scalesAlign、zeroPointsAlign)而非实际元素数量计算 blockLen,导致 DataCopyPad 读取越界的问题。同时顺带清理了 rms_norm_quant_v3 中一个多余的 #include。
主要改动
rms_norm_quant_v2_regbase_full_load.h中 gamma 复制长度修正:将copyInParamsGamma.blockLen从xGammaBetaAlign * sizeof(T_X)改为numR * sizeof(T_X),避免因对齐值大于实际行数numR导致从 gamma 全局内存读取越界。rms_norm_quant_v2_regbase_full_load.h中 scales 复制长度修正:引入numQ == 1条件分支,当量化组数为 1 时blockLen设为sizeof(T_SCALES)(仅一个元素),否则使用numR * sizeof(T_SCALES),替代原先可能偏大的scalesAlign * sizeof(T_SCALES)。rms_norm_quant_v2_regbase_full_load.h中 zeroPoints 复制长度修正:同样引入numQ == 1条件分支逻辑,替换原先zeroPointsAlign * sizeof(T_ZEROPOINTS)的计算方式,防止 zeroPoints 全局内存越界读取。aclnn_rms_norm_quant_v3.cpp移除冗余头文件:删除了#include "op_api/op_api_def.h",属于无关的代码清理。


代码审查
审查总结
审查结果
| 文件 | 结果 |
|---|---|
norm/rms_norm_quant_v2/op_kernel/arch35/rms_norm_quant_v2_regbase_full_load.h |
2 个 P0 发现 |
norm/rms_norm_quant_v3/op_api/aclnn_rms_norm_quant_v3.cpp |
无问题 |
发现统计
- P0: 2 个
- P1: 0 个
- P2: 0 个
- P3: 0 个
总体风险评估
高风险。rms_norm_quant_v2_regbase_full_load.h 中第 387–391 行的复制粘贴错误是一个严重的正确性缺陷:zeroPoints 段的 blockLen 被错误地赋值到了 copyInParamsScales.blockLen(且使用了错误的类型 T_SCALES),导致:
copyInParamszeroPoints.blockLen保持未初始化状态,当hasZeroPoints1或hasZeroPoints2为 true 时,DataCopyPad使用栈上的脏数据作为拷贝长度,必然引发 GM 越界读写;- 同时
copyInParamsScales.blockLen被意外覆盖,如果hasScales2也为 true,scales2 的拷贝也会使用错误的数据量。
此缺陷与 PR 标题「fix rmsnormquantv2/3 gm memory out-of-bounds」的目标直接矛盾——它引入了一个新的、确定性的 GM 越界问题。建议在合入前必须修复。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 2 |
| 🟡 建议 | 0 |
⛔ 需要修改


Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| norm | ✅ 苏跃明, 任如海 (2/2) | ✅ 苏跃明 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
huanghaihong, thanks for your pull request. All authors of the commits have signed the CLA. 👍


🔴 Critical
第 385 行声明 DataCopyExtParams copyInParamszeroPoints;,随后第 386 行仅设置了 blockCount = 1,blockLen 字段从未被赋值。
由于第 387–391 行的复制粘贴错误将 blockLen 错误地写到了 copyInParamsScales.blockLen(参见上一条 P0 报告),copyInParamszeroPoints.blockLen 实际保持未初始化状态。
第 392–393 行设置了 srcStride 和 dstStride,但 blockLen 仍然是栈上的脏数据。
随后在第 406 行(hasZeroPoints1 路径)和第 413 行(hasZeroPoints2 路径),DataCopyPad 使用这个未初始化的 copyInParamszeroPoints 进行 GM→UB 数据搬移,导致:
- 拷贝数据量不可预测(栈上的随机值)
- 可能从 GM 越界读取,触发内存访问错误
- 可能向 UB 越界写入,破坏其他 LocalTensor 数据
触发条件:hasZeroPoints1 == true 或 hasZeroPoints2 == true 时必然触发。
建议:与上一条合并修复:将第 387–391 行的赋值目标从 copyInParamsScales 改为 copyInParamszeroPoints,类型从 T_SCALES 改为 T_ZEROPOINTS。修复后 copyInParamszeroPoints.blockLen 即被正确初始化。
|
391 | + if (numQ == 1) { |
|
392 | + copyInParamszeroPoints.blockLen = sizeof(T_ZEROPOINTS); |
|
393 | + } else { |
|
394 | + copyInParamszeroPoints.blockLen = numR * sizeof(T_ZEROPOINTS); |
| 391
| - } |
|
395 | + } |


🔴 Critical
在 CopyInOhters 函数中,第 387–391 行(zeroPoints 段)的 blockLen 赋值存在明显的复制粘贴错误:
这段代码是从第 370–374 行(scales 段)复制过来但未修改目标变量和类型。它导致了两个独立的缺陷:
-
copyInParamszeroPoints.blockLen未初始化:第 385 行声明DataCopyExtParams copyInParamszeroPoints后仅设置了blockCount=1,blockLen从未被赋值,保持栈上的脏数据。第 406 行、413 行调用DataCopyPad(... copyInParamszeroPoints ...)时使用未初始化的blockLen,导致未定义行为——可能拷贝错误数量的数据或越界。 -
copyInParamsScales.blockLen被意外覆盖:如果hasScales2为 true(第 395 行),第 399 行会复用copyInParamsScales做 scales2 拷贝,此时 blockLen 已被覆盖为 zeroPoints 段错误写入的值(sizeof(T_SCALES)或numR * sizeof(T_SCALES),但语义上应是 zeroPoints 的 size),导致 scales2 拷贝数据量可能不正确。
触发条件:当 hasZeroPoints1 或 hasZeroPoints2 为 true 时触发未初始化 blockLen 的问题;当 hasScales2 && (hasZeroPoints1 || hasZeroPoints2) 时还会触发 scales2 拷贝错误。
建议:将第 388 行的 copyInParamsScales 改为 copyInParamszeroPoints,将 T_SCALES 改为 T_ZEROPOINTS;第 390 行同理。修正后的代码如上。
|
391 | + if (numQ == 1) { |
|
392 | + copyInParamszeroPoints.blockLen = sizeof(T_ZEROPOINTS); |
|
393 | + } else { |
|
394 | + copyInParamszeroPoints.blockLen = numR * sizeof(T_ZEROPOINTS); |
| 391
| - } |
|
395 | + } |


compile


流水线任务触发成功
任务链接 [27f2a9f2981b4936903805e1d3a14c8a][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_harmony-infer-chs-nn | ✅ SUCCESS | >>>>> | |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_report_lcov | ✅ SUCCESS | >>>>> |
[2026-07-10 17:18:54] CI执行结束


流水线任务触发成功
任务链接 [edcc43d5a68e4491a7fd9611ea3e40e3][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_style | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> |
[2026-07-10 17:02:58] CI执行结束


/lgtm
/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


/approve


描述
修复
rmsnormquantv2/3中 GM 内存越界问题。norm/rms_norm_quant_v2/op_kernel/arch35/rms_norm_quant_v2_regbase_full_load.h中,CopyInOhters函数通过DataCopyPad复制gamma、scales、zeroPoints时,原先使用了对齐后的长度(xGammaBetaAlign、scalesAlign、zeroPointsAlign)作为blockLen。当实际数据元素数numR小于对齐长度时,会读取超出 GM 实际数据范围的内存,造成越界。本次改动将gamma的blockLen改为numR * sizeof(T_X),并将scales和zeroPoints改为根据numQ分支:当numQ == 1时按单个元素复制,否则按numR * sizeof(...)复制,确保仅复制有效数据。norm/rms_norm_quant_v3/op_api/aclnn_rms_norm_quant_v3.cpp中移除未使用的头文件op_api/op_api_def.h,避免冗余依赖。关联的Issue
测试
文档更新
无
类型标签
AI/Agent生成声明