forked from linuxkerneltravel/lmp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kvm_watcher:优化代码,更新目录结构 (linuxkerneltravel#790)
* 修改makefile * 更新目录结构 * 添加用户态帮助函数 * 更新目录结构,添加用户态帮助函数 * update * 更新目录结构,添加用户态帮助函数 * update
- Loading branch information
1 parent
8ba3acf
commit 439159c
Showing
16 changed files
with
1,693 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,26 +118,33 @@ Report bugs to <[email protected]>. | |
## 四、代码结构 | ||
|
||
``` | ||
├── docs //功能模块说明文档 | ||
├── docs //功能模块说明文档 | ||
│ ├── kvm_exit.md | ||
│ ├── kvm_hypercall.md | ||
│ ├── kvm_irq.md | ||
│ ├── kvm_mmu.md | ||
│ └── kvm_vcpu.md | ||
├── include //内核态bpf程序 | ||
│ ├── kvm_exits.h | ||
│ ├── kvm_hypercall.h | ||
│ ├── kvm_ioctl.h | ||
│ ├── kvm_irq.h | ||
│ ├── kvm_mmu.h | ||
│ ├── kvm_vcpu.h | ||
│ └── kvm_watcher.h //公共头文件 | ||
├── include | ||
│ ├── bpf //内核态bpf程序 | ||
│ │ ├── kvm_exits.h | ||
│ │ ├── kvm_hypercall.h | ||
│ │ ├── kvm_ioctl.h | ||
│ │ ├── kvm_irq.h | ||
│ │ ├── kvm_mmu.h | ||
│ │ └── kvm_vcpu.h | ||
│ ├── common.h //内核态和用户态公共头文件 | ||
│ └── helpers //用户态帮助函数 | ||
│ ├── trace_helpers.h | ||
│ └── uprobe_helpers.h | ||
├── Makefile //编译脚本 | ||
├── README.md | ||
├── src | ||
│ ├── kvm_watcher.bpf.c //内核态bpf程序入口 | ||
│ └── kvm_watcher.c //用户态bpf程序 | ||
└── temp //临时文件目录 | ||
├── src | ||
│ ├── helpers //用户态帮助函数 | ||
│ │ ├── trace_helpers.c | ||
│ │ └── uprobe_helpers.c | ||
│ ├── kvm_watcher.bpf.c //内核态bpf程序入口 | ||
│ └── kvm_watcher.c //用户态bpf程序 | ||
└── temp //临时文件目录 | ||
``` | ||
|
||
## 五、测试 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
eBPF_Supermarket/kvm_watcher/include/helpers/trace_helpers.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ | ||
#ifndef __TRACE_HELPERS_H | ||
#define __TRACE_HELPERS_H | ||
|
||
#include <stdbool.h> | ||
|
||
#define NSEC_PER_SEC 1000000000ULL | ||
|
||
struct ksym { | ||
const char *name; | ||
unsigned long addr; | ||
}; | ||
|
||
struct ksyms; | ||
|
||
struct ksyms *ksyms__load(void); | ||
void ksyms__free(struct ksyms *ksyms); | ||
const struct ksym *ksyms__map_addr(const struct ksyms *ksyms, | ||
unsigned long addr); | ||
const struct ksym *ksyms__get_symbol(const struct ksyms *ksyms, | ||
const char *name); | ||
|
||
struct sym { | ||
const char *name; | ||
unsigned long start; | ||
unsigned long size; | ||
unsigned long offset; | ||
}; | ||
|
||
struct syms; | ||
|
||
struct syms *syms__load_pid(int tgid); | ||
struct syms *syms__load_file(const char *fname); | ||
void syms__free(struct syms *syms); | ||
const struct sym *syms__map_addr(const struct syms *syms, unsigned long addr); | ||
const struct sym *syms__map_addr_dso(const struct syms *syms, | ||
unsigned long addr, char **dso_name, | ||
unsigned long *dso_offset); | ||
|
||
struct syms_cache; | ||
|
||
struct syms_cache *syms_cache__new(int nr); | ||
struct syms *syms_cache__get_syms(struct syms_cache *syms_cache, int tgid); | ||
void syms_cache__free(struct syms_cache *syms_cache); | ||
|
||
struct partition { | ||
char *name; | ||
unsigned int dev; | ||
}; | ||
|
||
struct partitions; | ||
|
||
struct partitions *partitions__load(void); | ||
void partitions__free(struct partitions *partitions); | ||
const struct partition *partitions__get_by_dev( | ||
const struct partitions *partitions, unsigned int dev); | ||
const struct partition *partitions__get_by_name( | ||
const struct partitions *partitions, const char *name); | ||
|
||
void print_log2_hist(unsigned int *vals, int vals_size, const char *val_type); | ||
void print_linear_hist(unsigned int *vals, int vals_size, unsigned int base, | ||
unsigned int step, const char *val_type); | ||
|
||
unsigned long long get_ktime_ns(void); | ||
|
||
bool is_kernel_module(const char *name); | ||
|
||
/* | ||
* When attempting to use kprobe/kretprobe, please check out new fentry/fexit | ||
* probes, as they provide better performance and usability. But in some | ||
* situations we have to fallback to kprobe/kretprobe probes. This helper | ||
* is used to detect fentry/fexit support for the specified kernel function. | ||
* | ||
* 1. A gap between kernel versions, kernel BTF is exposed | ||
* starting from 5.4 kernel. but fentry/fexit is actually | ||
* supported starting from 5.5. | ||
* 2. Whether kernel supports module BTF or not | ||
* | ||
* *name* is the name of a kernel function to be attached to, which can be | ||
* from vmlinux or a kernel module. | ||
* *mod* is a hint that indicates the *name* may reside in module BTF, | ||
* if NULL, it means *name* belongs to vmlinux. | ||
*/ | ||
bool fentry_can_attach(const char *name, const char *mod); | ||
|
||
/* | ||
* The name of a kernel function to be attached to may be changed between | ||
* kernel releases. This helper is used to confirm whether the target kernel | ||
* uses a certain function name before attaching. | ||
* | ||
* It is achieved by scaning | ||
* /sys/kernel/debug/tracing/available_filter_functions | ||
* If this file does not exist, it fallbacks to parse /proc/kallsyms, | ||
* which is slower. | ||
*/ | ||
bool kprobe_exists(const char *name); | ||
bool tracepoint_exists(const char *category, const char *event); | ||
|
||
bool vmlinux_btf_exists(void); | ||
bool module_btf_exists(const char *mod); | ||
|
||
bool probe_tp_btf(const char *name); | ||
bool probe_ringbuf(); | ||
|
||
#endif /* __TRACE_HELPERS_H */ |
19 changes: 19 additions & 0 deletions
19
eBPF_Supermarket/kvm_watcher/include/helpers/uprobe_helpers.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ | ||
/* Copyright (c) 2021 Google LLC. */ | ||
#ifndef __UPROBE_HELPERS_H | ||
#define __UPROBE_HELPERS_H | ||
|
||
#include <sys/types.h> | ||
#include <unistd.h> | ||
#include <gelf.h> | ||
|
||
int get_pid_binary_path(pid_t pid, char *path, size_t path_sz); | ||
int get_pid_lib_path(pid_t pid, const char *lib, char *path, size_t path_sz); | ||
int resolve_binary_path(const char *binary, pid_t pid, char *path, | ||
size_t path_sz); | ||
off_t get_elf_func_offset(const char *path, const char *func); | ||
Elf *open_elf(const char *path, int *fd_close); | ||
Elf *open_elf_by_fd(int fd); | ||
void close_elf(Elf *e, int fd_close); | ||
|
||
#endif /* __UPROBE_HELPERS_H */ |
Oops, something went wrong.