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

fix(driver): avoid kmod crash when a CPU gets enabled at runtime #2252

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Jan 22, 2025

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?
/area driver-kmod
/area tests

Does this PR require a change in the driver versions?

What this PR does / why we need it:

I also added tests for hotplug in the libscap_test suite.

Which issue(s) this PR fixes:

Fixes #2251

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

fix(driver): avoid kmod crash when a CPU gets enabled at runtime

@@ -1820,6 +1812,10 @@ static int record_event_consumer(struct ppm_consumer_t *consumer,
ASSERT(ring);

ring_info = ring->info;
if(!ring_info) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We won't send any event on the newly enabled CPU; ring_info will be NULL and we would panic.

driver/main.c Outdated
struct hotplug_st st;
st.sd_action = 1;
st.cpu = cpu;
return smp_call_on_cpu(0, do_cpu_callback, &st, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Run the do_cpu_callback on the CPU 0 to make sure that we are able to send the PPME_CPU_HOTPLUG_E event to userspace.
This is what we do in the bpf probes, since we are guaranteed that CPU 0 is always present.

Copy link

github-actions bot commented Jan 22, 2025

Perf diff from master - unit tests

    10.75%     -1.03%  [.] sinsp_parser::reset
     5.30%     +0.54%  [.] next_event_from_file
     8.17%     -0.43%  [.] sinsp_evt::get_type
     3.80%     -0.42%  [.] sinsp_evt::load_params
     1.14%     +0.30%  [.] libsinsp::sinsp_suppress::process_event
     0.88%     +0.30%  [.] sinsp_evt::get_syscall_return_value
     0.80%     +0.28%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release
     2.89%     -0.26%  [.] sinsp_parser::process_event
     3.05%     -0.25%  [.] sinsp_thread_manager::find_thread
     0.57%     +0.25%  [.] sinsp_fdtable::find

Heap diff from master - unit tests

peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Benchmarks diff from master

Comparing gbench_data.json to /root/actions-runner/_work/libs/libs/build/gbench_data.json
Benchmark                                                         Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------
BM_sinsp_split_mean                                            +0.0366         +0.0365           144           149           144           149
BM_sinsp_split_median                                          +0.0392         +0.0390           144           150           144           150
BM_sinsp_split_stddev                                          +1.2311         +1.2308             1             2             1             2
BM_sinsp_split_cv                                              +1.1522         +1.1522             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  -0.0009         -0.0010            57            57            57            57
BM_sinsp_concatenate_paths_relative_path_median                -0.0015         -0.0016            57            57            57            57
BM_sinsp_concatenate_paths_relative_path_stddev                -0.1838         -0.1835             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_cv                    -0.1831         -0.1826             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     -0.0260         -0.0261            25            24            25            24
BM_sinsp_concatenate_paths_empty_path_median                   -0.0271         -0.0272            25            24            25            24
BM_sinsp_concatenate_paths_empty_path_stddev                   +1.2357         +1.2339             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       +1.2954         +1.2938             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  -0.0042         -0.0043            56            56            56            56
BM_sinsp_concatenate_paths_absolute_path_median                -0.0027         -0.0028            56            56            56            56
BM_sinsp_concatenate_paths_absolute_path_stddev                -0.3322         -0.3324             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_cv                    -0.3294         -0.3295             0             0             0             0
BM_sinsp_split_container_image_mean                            -0.0111         -0.0112           389           384           389           384
BM_sinsp_split_container_image_median                          -0.0120         -0.0121           389           384           389           384
BM_sinsp_split_container_image_stddev                          -0.5330         -0.5328             3             1             3             1
BM_sinsp_split_container_image_cv                              -0.5278         -0.5275             0             0             0             0

@FedeDP
Copy link
Contributor Author

FedeDP commented Jan 22, 2025

Drivers CI Build / test-scap-arm64 😆 (bundled_deps) (pull_request) Failing after 2m

Need to make newly introduced tests a little bit less flaky.

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.16%. Comparing base (6c46ed3) to head (f121b29).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2252   +/-   ##
=======================================
  Coverage   75.16%   75.16%           
=======================================
  Files         278      278           
  Lines       34478    34478           
  Branches     5922     5922           
=======================================
+ Hits        25916    25917    +1     
+ Misses       8562     8561    -1     
Flag Coverage Δ
libsinsp 75.16% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link

github-actions bot commented Jan 22, 2025

X64 kernel testing matrix

KERNEL CMAKE-CONFIGURE KMOD BUILD KMOD SCAP-OPEN BPF-PROBE BUILD BPF-PROBE SCAP-OPEN MODERN-BPF SCAP-OPEN
amazonlinux2-4.19 🟢 🟢 🟢 🟢 🟢 🟡
amazonlinux2-5.10 🟢 🟢 🟢 🟢 🟢 🟢
amazonlinux2-5.15 🟢 🟢 🟢 🟢 🟢 🟢
amazonlinux2-5.4 🟢 🟢 🟢 🟢 🟢 🟡
amazonlinux2022-5.15 🟢 🟢 🟢 🟢 🟢 🟢
amazonlinux2023-6.1 🟢 🟢 🟢 🟢 🟢 🟢
archlinux-6.0 🟢 🟢 🟢 🟢 🟢 🟢
archlinux-6.7 🟢 🟢 🟢 🟢 🟢 🟢
centos-3.10 🟢 🟢 🟢 🟡 🟡 🟡
centos-4.18 🟢 🟢 🟢 🟢 🟢 🟢
centos-5.14 🟢 🟢 🟢 🟢 🟢 🟢
fedora-5.17 🟢 🟢 🟢 🟢 🟢 🟢
fedora-5.8 🟢 🟢 🟢 🟢 🟢 🟢
fedora-6.2 🟢 🟢 🟢 🟢 🟢 🟢
oraclelinux-3.10 🟢 🟢 🟢 🟡 🟡 🟡
oraclelinux-4.14 🟢 🟢 🟢 🟢 🟢 🟡
oraclelinux-5.15 🟢 🟢 🟢 🟢 🟢 🟢
oraclelinux-5.4 🟢 🟢 🟢 🟢 🟢 🟡
ubuntu-4.15 🟢 🟢 🟢 🟢 🟢 🟡
ubuntu-5.8 🟢 🟢 🟢 🟢 🟢 🟡
ubuntu-6.5 🟢 🟢 🟢 🟢 🟢 🟢

ARM64 kernel testing matrix

KERNEL CMAKE-CONFIGURE KMOD BUILD KMOD SCAP-OPEN BPF-PROBE BUILD BPF-PROBE SCAP-OPEN MODERN-BPF SCAP-OPEN
amazonlinux2-5.4 🟢 🟢 🟢 🟢 🟢 🟡
amazonlinux2022-5.15 🟢 🟢 🟢 🟢 🟢 🟢
fedora-6.2 🟢 🟢 🟢 🟢 🟢 🟢
oraclelinux-4.14 🟢 🟢 🟢 🟡 🟡 🟡
oraclelinux-5.15 🟢 🟢 🟢 🟢 🟢 🟢
ubuntu-6.5 🟢 🟢 🟢 🟢 🟢 🟢

@poiana poiana added size/XL and removed size/L labels Jan 23, 2025
@FedeDP FedeDP force-pushed the fix/hotplug_kmod branch 3 times, most recently from e5765a8 to 60cacc4 Compare January 23, 2025 08:09
Copy link

Please double check driver/SCHEMA_VERSION file. See versioning.

/hold

FedeDP and others added 2 commits January 23, 2025 10:03
… is hotplugged.

Signed-off-by: Federico Di Pierro <[email protected]>

Co-authored-by: Andrea Terzolo <[email protected]>
@poiana poiana added size/L and removed size/XL labels Jan 23, 2025
@FedeDP
Copy link
Contributor Author

FedeDP commented Jan 23, 2025

/milestone next-driver

@poiana poiana added this to the next-driver milestone Jan 23, 2025
@FedeDP
Copy link
Contributor Author

FedeDP commented Jan 23, 2025

/unhold

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Jan 23, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

NULL pointer dereference in kmod driver while hot plugging a CPU
3 participants