This is an automated email from the ASF dual-hosted git repository.
liuhan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-rover.git
The following commit(s) were added to refs/heads/main by this push:
new 14af438 Fix the unaligned memory accesses for (#163)
14af438 is described below
commit 14af438ca2937c80223a24b4349144730deea9d8
Author: david <[email protected]>
AuthorDate: Sat Dec 7 14:10:59 2024 +0800
Fix the unaligned memory accesses for (#163)
---
CHANGES.md | 1 +
bpf/include/socket_data.h | 14 ++++++++------
bpf/include/socket_opts.h | 2 +-
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index eb7e90c..db16ffa 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -10,6 +10,7 @@ Release Notes.
* Fix context structs parameters for tracepoint programs.
* Improve the build of skywalking-rover by adding some options.
* Decode the BPF data by self instant `binary.Read` to reduce CPU usage.
+* Fix the unaligned memory accesses for `upload_socket_data_buf`.
#### Bug Fixes
* Fix the base image cannot run in the arm64.
diff --git a/bpf/include/socket_data.h b/bpf/include/socket_data.h
index 0e62675..cae2622 100644
--- a/bpf/include/socket_data.h
+++ b/bpf/include/socket_data.h
@@ -35,7 +35,7 @@ struct socket_data_upload_event {
__u64 randomid;
__u64 data_id;
__u64 total_size;
- char buffer[MAX_TRANSMIT_SOCKET_READ_LENGTH + 1];
+ char buffer[MAX_TRANSMIT_SOCKET_READ_LENGTH];
};
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
@@ -107,15 +107,17 @@ static __always_inline struct upload_data_args*
generate_socket_upload_args() {
}
static __always_inline void __upload_socket_data_with_buffer(void *ctx, __u8
index, char* buf, size_t size, __u32 is_finished, __u8 have_reduce_after_chunk,
struct socket_data_upload_event *event) {
+ if (size <= 0) {
+ return;
+ }
+ if (size > sizeof(event->buffer)) {
+ size = sizeof(event->buffer);
+ }
event->sequence = index;
event->data_len = size;
event->finished = is_finished;
event->have_reduce_after_chunk = have_reduce_after_chunk;
- if (size <= 0) {
- return;
- }
- asm volatile("%[size] &= 0x7ff;\n" ::[size] "+r"(size) :);
- bpf_probe_read(&event->buffer, size & 0x7ff, buf);
+ bpf_probe_read(&event->buffer, size, buf);
bpf_perf_event_output(ctx, &socket_data_upload_event_queue,
BPF_F_CURRENT_CPU, event, sizeof(*event));
}
diff --git a/bpf/include/socket_opts.h b/bpf/include/socket_opts.h
index 8aeafca..d506302 100644
--- a/bpf/include/socket_opts.h
+++ b/bpf/include/socket_opts.h
@@ -43,7 +43,7 @@
// for protocol analyze need to read
#define MAX_PROTOCOL_SOCKET_READ_LENGTH 31
// for transmit to the user space
-#define MAX_TRANSMIT_SOCKET_READ_LENGTH 2047
+#define MAX_TRANSMIT_SOCKET_READ_LENGTH 2048
// unknown the connection type, not trigger the syscall connect,accept
#define AF_UNKNOWN 0xff