-
Notifications
You must be signed in to change notification settings - Fork 15
-Wattribute-warning in drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c #1781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
"output" is always sized to one of these, depending on caller: MLXSW_SP2_BLOOM_KEY_LEN Both callers appears to bounds-check all of these using their respective chunk defines. I don't see anything that would be arch-specific, though. |
This is now visible in mainline: https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/4242664339/jobs/7376999640 I can reproduce this with just I am not sure this is related to #1687, as Nick's changes to LLVM do not resolve this for me (which makes sense, since KASAN is not enable for these configurations). |
The warning has slightly more detail with the inline tracking patch:
But this doesn't tell us anything new, as |
This shows |
If I grow the sp4 Is a loop unroller going too far? |
This makes the warning go away (?!) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c
index e2aced7ab454..0f4419343a17 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c
@@ -235,7 +235,7 @@ __mlxsw_sp_acl_bf_key_encode(struct mlxsw_sp_acl_atcam_region *aregion,
u8 key_offset, u8 chunk_key_len, u8 chunk_len)
{
struct mlxsw_afk_key_info *key_info = aregion->region->key_info;
- u8 chunk_index, chunk_count, block_count;
+ u8 chunk_index, chunk_count, block_count, chunk_start;
char *chunk = output;
__be16 erp_region_id;
@@ -243,7 +243,12 @@ __mlxsw_sp_acl_bf_key_encode(struct mlxsw_sp_acl_atcam_region *aregion,
chunk_count = 1 + ((block_count - 1) >> 2);
erp_region_id = cpu_to_be16(aentry->ht_key.erp_id |
(aregion->region->id << 4));
- for (chunk_index = max_chunks - chunk_count; chunk_index < max_chunks;
+
+ chunk_start = max_chunks - chunk_count;
+ if (WARN_ON_ONCE(chunk_start >= max_chunks))
+ chunk_start = 0;
+
+ for (chunk_index = chunk_start; chunk_index < max_chunks;
chunk_index++) {
memset(chunk, 0, pad_bytes);
memcpy(chunk + pad_bytes, &erp_region_id, If I make the |
If you want to test if it's the loop unroller, you might be able to add something like |
Ta-da! No warning. make CC=clang KCFLAGS="-mllvm -unroll-threshold=0" LLVM_IAS=1 LD=s390x-linux-gnu-ld O=clang-s390 ARCH=s390 drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.o
make[1]: Entering directory '/srv/code/clang-s390'
GEN Makefile
CALL ../scripts/checksyscalls.sh
CC [M] drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.o
make[1]: Leaving directory '/srv/code/clang-s390' |
BOO YEAH! :-) Okay, you could start fiddling with the threshold to see at what point it breaks. I believe the default for |
|
max_chunks is always 3, so the loop should never reach 3 loops. Is there some kind of off-by-one in the s390 loop unroller? |
It would be from s390's To get an IR file without optimizations applied, add this: |
I have no idea what I'm looking at now. :) Hopefully someone with more familiarity with this can debug it. |
@nathanchance what's the compilation command for that file? |
@bwendling This reproduces for me with this
|
Reduced a bit:
|
Quick note: From what I can see, the loop unroller determines that it loops by four, just like @kees thought would happen....I don't know why it's doing that. It doesn't appear to be architecture-specific, since it involves SCEV... |
I looked at the x86 code, and it seems like inlining isn't taking place at some level, so that might be why it's not generating this warning. |
Verified that even on x86 if all of the inlining is done then it will emit the same warning/error:
This makes me question whether the |
GCC complains about having to inline that function, but apparently does it. However, it (apparently) doesn't fully unroll the loop, so it doesn't leave the offending functions. |
Removing one of the |
@kees This doesn't solve the issue, but is there a reason why the |
Ooookaaay...So, I've been staring at this for a while now and my eyes have stopped bleeding enough for me to realize that this might not be a compiler issue but maybe the fortify check itself. The issue seems to be that the if-then statement with ANYWHO, if we could massage the code to omit that extra trip count the code compiles just fine. There's this comment below the offending code:
However, this same check for Thoughts?
|
And, no, I don't know what GCC doesn't have this issue. My guess is that their loop unrolling algorithm is different enough that it omits the extra loop unroll... |
Hmm, so I spent a little time looking at this. While the changes to the macro do make the warning go away, this isn't a workable solution because we need to be able to reject zero-sized destination buffers. Do you have a minimized test case for this, by any chance? |
This is because they don't (yet) call |
After commit f7cd05c76c70 ("fortify: Use __builtin_dynamic_object_size() when available") in -next, I see the following warning in
ARCH=s390 allmodconfig
:This appears to be the
memset()
andmemcpy()
calls in__mlxsw_sp_acl_bf_key_encode()
, as commenting them out makes the warning disappear.cc @kees
The text was updated successfully, but these errors were encountered: