Skip to content

fix log cannot print in kernel 5.10 by bpf_trace_printk #1363

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

Merged
merged 1 commit into from
May 8, 2025

Conversation

lec-bit
Copy link
Contributor

@lec-bit lec-bit commented May 7, 2025

bpf_trace_printk cannot print two %s, need to fix

What type of PR is this?
/kind bug

What this PR does / why we need it:
bpf_trace_printk cannot print two %s, need to fix

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@kmesh-bot kmesh-bot added the kind/bug Something isn't working label May 7, 2025
Copy link

codecov bot commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.26%. Comparing base (44d5b2b) to head (e4ee237).
Report is 158 commits behind head on main.

see 23 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fc5794...e4ee237. Read the comment docs.

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

@hzxuzhonghu
Copy link
Member

@nlgwcy can you please give some suggestion

bpf_trace_printk cannot print two %s, need to fix
remove redundant function definitions 'xdp_deny_packet'

Signed-off-by: lec-bit <[email protected]>
ip2str(&sock_addr->ipv4, 1),
bpf_ntohs(sock_addr->port));
// Since bpf_trace_printk cannot print two %s, the name and ipv4 are printed separately.
BPF_LOG(INFO, CLUSTER, "cluster=\"%s\"\n", name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
BPF_LOG(INFO, CLUSTER, "cluster=\"%s\"\n", name);
BPF_LOG(INFO, CLUSTER, "cluster=\"%s\",", name);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BPF logs are printed on a new line each time in bpf_trace_printk. Adding \n here will not affect whether the log is continuous.

@nlgwcy
Copy link
Contributor

nlgwcy commented May 7, 2025

@nlgwcy can you please give some suggestion

The restriction is fixed in this PR: torvalds/linux@d9c9e4db186ab

@hzxuzhonghu
Copy link
Member

Ok, so in 5.10 kernel we must fix it. Is this the right way?

@hzxuzhonghu
Copy link
Member

Can you also fix bpf/kmesh/workload/xdp.c

@hzxuzhonghu
Copy link
Member

Seems xdp_deny_packet is not used anymore

@lec-bit
Copy link
Contributor Author

lec-bit commented May 8, 2025

Can you also fix bpf/kmesh/workload/xdp.c

I don't know if this place can be repaired simply by taking it apart.
`

        BPF_LOG(
        INFO,
        XDP,
        "auth denied, src ip: %s, dst ip %s, dst port: %u\n",
        ip2str(&tuple_info->ipv4.saddr, true),
        ip2str(&tuple_info->ipv4.daddr, true),
        bpf_ntohs(tuple_info->ipv4.dport)); 

`

    BPF_LOG(INFO, XDP, "auth denied, src ip: %s",ip2str(&tuple_info->ipv4.saddr, true), false))
    BPF_LOG(
        INFO,
        XDP,
        "auth denied, dst ip %s, dst port: %u\n",
        ip2str(&tuple_info->ipv4.daddr, true),
        bpf_ntohs(tuple_info->ipv4.dport));`

@hzxuzhonghu
Copy link
Member

I think this function can be removed now

@lec-bit
Copy link
Contributor Author

lec-bit commented May 8, 2025

I think this function can be removed now

ok
I see that there is only empty definition and no usage.

@lec-bit
Copy link
Contributor Author

lec-bit commented May 8, 2025

/retest

@LiZhenCheng9527
Copy link
Contributor

/lgtm
/approve

@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: LiZhenCheng9527

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

@kmesh-bot kmesh-bot merged commit 15a8137 into kmesh-net:main May 8, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants