Skip to content
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

Add linux kernel module helpers #411

Merged
merged 1 commit into from
Jul 13, 2024
Merged

Add linux kernel module helpers #411

merged 1 commit into from
Jul 13, 2024

Conversation

brenns10
Copy link
Contributor

@brenns10 brenns10 commented Jul 3, 2024

There are a few common use cases that I find myself re-writing: iterating over the list of modules, looking up a module by name, and getting memory addresses related to modules (or vice versa). Add helpers for each.


I know there is the drgn module API which is upcoming, and I don't necessarily want to confuse or overlap with that. So maybe it's possible this will duplicate that API in some form, but I find myself needing to access kernel modules or look them up by name/address rather frequently. So here's some code and tests (tested on 6.9 and 4.19, hoping to let CI take a look at the rest 😉 ).

@brenns10 brenns10 linked an issue Jul 3, 2024 that may be closed by this pull request
@brenns10
Copy link
Contributor Author

brenns10 commented Jul 3, 2024

So, I'm not sure how the module API issue 332 got linked to this pull request... I did not mention it by number? I mentioned the title though. Is that enough to accidentally link issues and pull requests? If so... booo.

@osandov osandov removed a link to an issue Jul 11, 2024
Copy link
Owner

@osandov osandov left a comment

Choose a reason for hiding this comment

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

Thanks, I agree that this still makes sense even with the module API. Some minor comments. (I unlinked the issue, maybe it was because your branch had the same name as the branch I had previously linked to it? That's weird.)

drgn/helpers/linux/module.py Show resolved Hide resolved
drgn/helpers/linux/module.py Outdated Show resolved Hide resolved
drgn/helpers/linux/module.py Outdated Show resolved Hide resolved
drgn/helpers/linux/module.py Outdated Show resolved Hide resolved
drgn/helpers/linux/module.py Show resolved Hide resolved
drgn/helpers/linux/module.py Outdated Show resolved Hide resolved
@osandov
Copy link
Owner

osandov commented Jul 11, 2024

One more thing, the test case is failing for me with !SMP:

$ python3 setup.py test -k '*tiny'
...
======================================================================
FAIL: test_module_percpu_region (tests.linux_kernel.helpers.test_module.TestModules.test_module_percpu_region)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/osandov/repos/drgn3/tests/linux_kernel/helpers/test_module.py", line 32, in test_module_percpu_region
    self.assertTrue(start <= pcpu_addr <= start + size)
AssertionError: False is not true

@brenns10
Copy link
Contributor Author

Huh, I guess I was getting too clever about that test. On !SMP the start should be 0, i.e. NULL, so I will probably only conditionally assert if start != 0. Since it's still a nice test of functionality for SMP kernels.

There are a few common use cases that I find myself re-writing:
iterating over the list of modules, looking up a module by name, and
getting memory addresses related to modules (or vice versa). Add helpers
for each.

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
@osandov osandov merged commit de8ba22 into osandov:main Jul 13, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants