-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Bpftrace fixes for s390x #1241
Bpftrace fixes for s390x #1241
Conversation
Please review and request to merge into master. Thank you. |
Hello @fbs , @brendangregg @yonghong-song, The last commit Fix variable assignment of 32 bit integers causes failure in tools-parsing-test.sh. Other commits passes the tests. Few questions:
Any suggestions would be great. Thank you. Best Regards |
Hi @sumanthkorikkar , thanks for the PR. I'm skimming it and it seems reasonable (will look more closely next on monday) .
It looks like it's hitting some kind of assertion. Do you think you can figure out what's going on? If you wanna do partial merges of s390x support we can also go with a build flag that's off by default and fix the abort in another PR.
Usually we do it all in one PR, especially if the commits depend on each other. But see above if you wanna get most of the code in first so you don't have to keep fixing merge conflicts. Other stuff:
|
Hi @danobi
Ok. thank you.
Sure. I will give it a try.
Ok. I will separate s390 support and I will fix the abort in another PR
Ok. Sure I will conform it to clang-format and send. Thanks
Ok. |
Thanks for working on this! :) Haven't look closely either yet, but just some remarks: As for the helpers. Having both a 'short/i16' and 'long/i32' versions is a bit different from the way most helpers currently work, which usually look at the input argument and derive stuff from it. Instead of having 4 helpers, cant we have one that just flips the byte order? Looking at the change that seems possible to do. We're not 1.0 yet, but I'd rather not add any helpers that we don't need. If a good use case pops up we can always add more helpers (calls). Re the current compiler issue: bpftrace is not as strict with LLVM typing as LLVM wants us to be. While it "mostly works" you can run into weird issues like the crashes you're seeing now. A simple way to test that is running In this case it is caused by:
Which compiles down to
Doing a i64 store in a i16* causes the issue in this case. As a fix:
Lately I've been fixing most of these (e.g #1189) with #1231 and #1194 still open but there probably still are some left. In this case the issue is mostly with the semantic analyser however. Your newly added functions have call.type set to i64 which appearently doesn't get checked properly during variable assignment as it only appears to check the type:
I want to start working on improving on this (#878) once the current codegen issues are fixed but that will take a while. For now it will probably work if you make the return type of your new helpers match the input type, instead of casting it to i64. Can you add codegen tests for the new helpers (after we've decided what to do with them, see fisrt part of comment). What are your thoughts about testing this and making sure it keeps working? Are there any CI platforms that do s390. At least being able to do semi-regular (daily, weekly) builds would be a huge help. |
As for splitting up, I having the first 4 or 5 commits going in first would be easier. |
Hi @fbs, Thanks for reviewing.
something like bswap() instead of hton*(). ?. Based on input type, Let me try that.
Ok. Thanks for mentioning this.
Ok. I will check.
I will add this. But this is specific to little endian. [ llvm/*] datalayout is different for big endian. I will think about this and see how we improve codegen tests for both arch.
Ok. I need to check with my colleagues, if there is CI platforms for s390. Thank you |
Hi @fbs,
I have added bpftrace runtime-tests to our internal CI environment as of now. So, we run daily builds and runtime-tests. |
add486f
to
61e3d0d
Compare
@@ -3,6 +3,11 @@ | |||
#include <algorithm> | |||
#include <array> | |||
|
|||
// For little endian 64 bit, sp + 32 + 8 regs save area + argX | |||
#define ARG0_STACK_LE 96 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to find where in the spec LE and BE are different for stack frame setup. Can you point me to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Powerpc64, little endian, See Power Architecture 64-Bit ELF V2 ABI Specification
https://members.openpowerfoundation.org/document/dl/576
- See parameter save area
- When the caller allocates the Parameter Save Area, it will always be automatically quadword aligned because it must always start at SP + 32. It shall be at least 8 doublewords in length. If a function needs to pass more than 8 doublewords of arguments, the Parameter Save Area shall be large enough to spill all register-based parameters and to contain the arguments that the caller stores in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I'm a little confused. Seems like the ABI changed starting at power ISA 2.07B. So why is only LE using the new ABI?
Won't block this PR on these questions. Realizing the sarg
issue is a big win already.
Sounds good. If you can find a way to set it up in the open source CI it would help us prevent future breakages at merge time. Not sure if it would be less work on the long run (depends on how much of our stuff implicitly depends on endianness, I guess). |
yes. that would be great for community. One of my colleague, referred me to this, So it should be possible. I can try this. But I would need some input from you people about the requirements - (os requirements, services, scripts) to run this.?
Ok. I will have a look at build scripts which are available here. Thanks |
I don't know if we have any hard requirements other than it functioning as expected. I don't think any of us are too picky on how tests get run, just that they run somehow. We have github actions and travis ci at our disposal.
This seems like a pain. We also have github actions set up. I looked around and I found this: https://github.com/marketplace/actions/run-on-architecture . Looks much easier to get set up than lxd. Seems like it's powered by https://github.com/multiarch/qemu-user-static which looks quite powerful. |
Looks mostly good to me. I'm not that sure about "bpftrace: Fix type conversion in printf() builtin". Using I think that the better way to fix this is to get rid of that resize the semantic analyser does and instead make sure everything is properly stored. Which is what I want to do with #1231. I think the best we can do is to accept for now and revert it later (e.g. in #1231). |
Hi @danobi, My findings:
-Related issue : multiarch/qemu-user-static#17. Tried this, but same error message.
|
Add s390x specific registers. This is needed for bpftrace builtins like argX, regs(), retval etc. This commit provides various functions to perform proper offset calculation from the pt_regs context. The builtin functions of bpftrace uses these offset functions to generate the proper bytecode for s390x Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com> Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Introduce arg_stack_offset() function and define it for each architecture. When the number of arguments passed to a function is greater than the number of available argument registers, then the additonal parameters are stored on the stack. This function calculates the argument stack offset for each architecture. This should fix the sarg builtin support for s390x/powerpc64/aarch64. It should also be noted that only 64 bit architecture is supported. Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com> Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
LLVM might change the size used to store the print arguements in the stack according to BPF alignment requirements. This resulted in bpftrace printf() builtin interpreting the values not correctly. To avoid these, in commit df51b11 ("promote scalar printf args to 64-bits"), all the printf integer args were promoted to 64 bits. But however this causes issues when performing type conversion in big endian systems. In Big endian systems: 1. Current state: bpftrace -e 'BEGIN { printf("%d", (uint16)0x1234); exit() }' Returns 0 Expected result: 0x1234 2. Current state: In Big endian machines, this is interpreted as: Address: Value 0x0 : 12 0x1 : 34 --------- 0x2 : 00 0x3 : 00 0x4 : 00 0x5 : 00 0x6 : 00 0x7 : 00 format() will intepret it from 0x6-0x7 and print the result as 0. Hence the result is always zero. Expected state: In Big endian machines: Address: Value 0x0 : 00 0x1 : 00 0x2 : 00 0x3 : 00 0x4 : 00 0x5 : 00 0x6 : 00 0x7 : 12 0x8 : 34 format() will print 0x1234. Now let's see the bytecode: 0: (bf) r6 = r1 1: (b7) r1 = 0 2: (7b) *(u64 *)(r10 -8) = r1 last_idx 2 first_idx 0 regs=2 stack=0 before 1: (b7) r1 = 0 3: (b7) r2 = 4660 4: (6b) *(u16 *)(r10 -8) = r2 <<<<<<< The upper most 0x0-0x1 will be set to 0x1234, Which is OK for Little endian, but for big endian NOT OK. 5: (7b) *(u64 *)(r10 -16) = r1 6: (18) r7 = 0xab6d0c00 8: (85) call bpf_get_smp_processor_id#8 9: (bf) r4 = r10 10: (07) r4 += -16 <<<< arg_data.offset for calls + arg_data args. 11: (bf) r1 = r6 12: (bf) r2 = r7 13: (bf) r3 = r0 14: (b7) r5 = 16 15: (85) call bpf_perf_event_output#25 last_idx 15 first_idx 0 regs=20 stack=0 before 14: (b7) r5 = 16 16: (b7) r0 = 0 17: (95) exit 4. bpftrace also maintains arg.type.cast_type information. Utilize this information to correctly print the arguments for bigendian architectures. Test result: ./bpftrace -e 'BEGIN { printf("%x", (uint8)-1); exit() }' Attaching 1 probe... ff Fixes: bpftrace#47 Fixes: df51b11 ("promote scalar printf args to 64-bits") Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com> Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
1. bpftrace -e 'kretprobe:vfs_read { @=hist(512); exit(); }' 2. bpftrace histogram adds the 512 value into the wrong bucket - For big endian systems, the output value is always added to the 0th bucket instead of (log 512 base 2) bucket. The output could be wrong even for little endian systems, when the bucket number goes beyond 255. Avoid this by properly reading 8 bytes data instead of 1 byte char. - Also avoid 32 bit overflow of sum. All histogram, stats related testcases are now OK. Test result: ./bpftrace -e 'kretprobe:vfs_read { @[1]=hist(512); @[1]=hist(512); @[1]=hist(1024); exit(); }' Attaching 1 probe... @[1]: [512, 1K) 2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@| [1K, 2K) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@| Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com> Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
- Add ARCH support for the test tool - Fix architecture specific testcases Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
61e3d0d
to
c90cec2
Compare
Ok. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep the CI conversation going in parallel. I think this is good to merge. I'll merge tomorrow if there aren't any new comments.
+1. Lets get the 0.10 release out first and merge it first thing after |
The patch series provides register support for s390x. This also solves various issues that can occur in big-endian architectures.