Skip to content

Add some kfd ioctl decoding - #236

Open
ZenithalHourlyRate wants to merge 4 commits into
strace:masterfrom
ZenithalHourlyRate:kfd
Open

ZenithalHourlyRate wants to merge 4 commits into
strace:masterfrom
ZenithalHourlyRate:kfd

Conversation

@ZenithalHourlyRate

Copy link
Copy Markdown

kfd (/dev/kfd) is an interface exposed by amdgpu kernel driver for user space drivers (e.g. ROCm)

FIXME

KD and KFD both use the 'K' base. Fortunately they currently do not overlap and can be distinguished from NR. However, as KFD is gradually adding ioctls, one day they may overlap.

More generously, how do we decode ioctls arg with the same base? We already have ioctl_next_match for displaying ioctls with the same code, do we have similar mechanisms?

Note

TODOs in code will not be addressed in this patchset. They could be implemented later when I get the time.

Also, the variable length array handling for struct kfd_ioctl_svm_attribute attrs[]; could be generalized to e.g. defs.h then print_field.h. I think tfetch_obj after the end of the struct is quite unsafe. If kernel returned an invalid nattr, e.g. -1, then we will access the whole memory. What's your opinion on this.

TODO

  • The FIXME mentioned above
  • Tests

Comment thread src/ioctl.c
case 'K':
return kd_ioctl(tcp, code, arg);
/* FIXME: this is ugly, and wont work forever */
if (_IOC_NR(code) >= _IOC_NR(KIOCSOUND)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I didn't finish revising after reviewing, the patch I proposed in https://lists.strace.io/pipermail/strace-devel/2022-March/010996.html adds the ability to distinguish the type of file descriptors to strace. Just comment.

@ldv-alt

ldv-alt commented Feb 10, 2023 via email

Copy link
Copy Markdown
Member

@masatake

Copy link
Copy Markdown
Contributor

By the way, do you have any plans revisiting that series?

Yes, I'm revising now. I'm also interested in kfd. So I would like to make my patches working well with this pull request.

@masatake

Copy link
Copy Markdown
Contributor

@ZenithalHourlyRate @ldv-alt
My original patchset for resolving ioctl command overwrapping comes from two parts:
A. getting file descriptor-related information from printdev(),
B. use the information to resolve the command overwrapping between TTY and SND devices.

However, the development of the patchset was staneeded morenot find enough timestrafe'srstand strace's printing routines and TTY layers of Linux.

So I will split the patchset into two, and I will focus on the A part.
However, submitting A. without a real use case is a bad idea.
So I'm interested in this pull request.

Could you see https://github.com/masatake/strace/commits/finfo-v0 especially
masatake@58922f6
?

@ldv-alt

ldv-alt commented Feb 12, 2023

Copy link
Copy Markdown
Member

The main problem with this PR is the absence of tests for the new ioctl decoder.

@ldv-alt

ldv-alt commented Feb 13, 2023

Copy link
Copy Markdown
Member

@ZenithalHourlyRate @ldv-alt My original patchset for resolving ioctl command overwrapping comes from two parts: A. getting file descriptor-related information from printdev(), B. use the information to resolve the command overwrapping between TTY and SND devices.

However, the development of the patchset was staneeded morenot find enough timestrafe'srstand strace's printing routines and TTY layers of Linux.

So I will split the patchset into two, and I will focus on the A part. However, submitting A. without a real use case is a bad idea. So I'm interested in this pull request.

To be honest, I think your original patchset was closer to be merged because, unlike this PR, it contained tests.

* NEWS: mention this change
* bundled/Makefile.am: include new file
* bundled/linux/include/uapi/linux/kfd_ioctl.h: new file from Linux 6.1
* src/Makefile.am: include new file
* src/defs.h: declare kfd ioctl
* src/ioctl.c: redirect ioctl decoding to kfd_ioctl
* src/kfd_ioctl.c: new file
* src/xlat/kfd_alloc_mem_flags.in: flags from header
* src/xlat/kfd_cache_policy.in: likewise
* src/xlat/kfd_event_type.in: likewise
* src/xlat/kfd_queue_type.in: likewise

TODOs in this patch will not be addressed in this patchset.
They could be implemented later when I get the time.

Signed-off-by: Hongren (Zenithal) Zheng <i@zenithal.me>
Signed-off-by: Hongren (Zenithal) Zheng <i@zenithal.me>
@ZenithalHourlyRate

Copy link
Copy Markdown
Author

unlike this PR, it contained tests.

I have added tests now. The data in the tests are collected from my GPU program and I used a script to generate the test functions.

ioctls that my GPU program does not call are now deleted and wont be addressed in this patchset due to a limited time budget. They have beed splitted to kfd-dev branch and anyone interested could add tests for them and get them upstreamed.

Could you see https://github.com/masatake/strace/commits/finfo-v0 especially
masatake@58922f6

I've tested this branch on my machine and it worked.

I am marking this PR as ready for review now. The FIXME mentioned above could be addressed if masatake's patchset get merged first, but I'll leave it for now.

@ZenithalHourlyRate ZenithalHourlyRate changed the title [WIP][RFC] Add kfd ioctl decoding Add some kfd ioctl decoding Feb 17, 2023
@ZenithalHourlyRate
ZenithalHourlyRate marked this pull request as ready for review February 17, 2023 13:43
* bundled/Makefile.am: include new file
* bundled/linux/include/uapi/drm/drm.h: new file from Linux 6.1, stripped __user
* bundled/linux/include/uapi/drm/drm_mode.h: new file from Linux 6.1
@codecov

codecov Bot commented Feb 19, 2023 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.23%. Comparing base (46a9270) to head (fe971b0).
⚠️ Report is 1193 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #236      +/-   ##
==========================================
+ Coverage   90.09%   90.23%   +0.13%     
==========================================
  Files         289      290       +1     
  Lines       24877    25225     +348     
==========================================
+ Hits        22414    22761     +347     
- Misses       2463     2464       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@masatake

masatake commented Feb 21, 2023 •

Copy link
Copy Markdown
Contributor

I have added tests now. The data in the tests are collected from my GPU program and I used a script to generate the test functions.

Can I see the script?
I found /dev/kfd in my machine but I have no knowledge about it. So your script helps me.

ioctls that my GPU program does not call are now deleted and wont be addressed in this patchset due to a limited time budget. They have beed splitted to kfd-dev branch and anyone interested could add tests for them and get them upstreamed.

I would like to try to push your efforts to the upstream.

The parts of my patches were merged into the master ldv/next branch.
However, the patches are a subset of what the kfd ioctl decoder needs.
Linux kernel assigns the major number of kfd dynamically. The merged patches provide only major numbers to ioctl decoders.

These two patches are needed:

masatake@2aa88bd
masatake@6bd09fe

@ldv-alt Should I use strace-list to get your review? or can I use this GitHub interface?

@ZenithalHourlyRate

Copy link
Copy Markdown
Author

@masatake

Copy link
Copy Markdown
Contributor

@ZenithalHourlyRate Thanks.

@ldv-alt

ldv-alt commented Feb 21, 2023

Copy link
Copy Markdown
Member

These two patches are needed:

masatake@2aa88bd masatake@6bd09fe

@ldv-alt Should I use strace-list to get your review? or can I use this GitHub interface?

I prefer the mailing list, but I can cope with the github interface, too.

@ZenithalHourlyRate

Copy link
Copy Markdown
Author

I've gone through the new finfo interface, there are some questions regarding how it can be used for kfd ioctl decoding

In ioctl_decode, finfo is NULL when it is leaving or the fd is not valid

  • kfd and kd still needs distinguishing when in leaving stages
  • in tests we are always using fd = -1

The leaving stage problem can be resolved by changing the logic in SYS_FUNC(ioctl), but for the tests there are no way to provide finfo.

In summary, there must be some fallback ways to distinguish kfd and kd, and the code looks like this

if (finfo) {
  // call kfd_ioctl or kd_ioctl accoring to the finfo
} else {
  if (_IOC_NR(code) >= _IOC_NR(KIOCSOUND))
  // ...
}

And the current ugly hack can not be avoided.

Since we always need a fallback way, and there is actualy no overlap for now, I think kfd/kd distinguish can just use the hacky way for now to reduce the complexity. In the future when there are overlaps, finfo could be used.

@masatake

masatake commented Mar 11, 2023 •

Copy link
Copy Markdown
Contributor

See the last three commits at https://github.com/masatake/strace/commits/kfd.

Since we always need a fallback way, and there is actualy no overlap for now, I think kfd/kd distinguish can just use the hacky way for now to reduce the complexity. In the future when there are overlaps, finfo could be used.

Basically, I agree with you.
Even the last commit () my branch uses your original fallback.
Without the hacky way, strace cannot decode the arguments when -1 is passed as the fd (as you wrote).

But I would like to evaluate the last three commits.
But I would like you to evaluate the last three commits. (added in Mar 12 2023)
They solve the "leaving stages" issue you wrote.

@ZenithalHourlyRate

Copy link
Copy Markdown
Author

Even the last commit () my branch uses your original fallback.

@ldv-alt How do you think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants