自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(29)
  • 资源 (1)
  • 收藏
  • 关注

原创 KVM 调试(一) 使用qemu使能kvm.

qemu调试真的非常方便,内建gdb server。在虚拟机上运行虚拟机。链接: https://pan.baidu.com/s/1q54YFhFUYldKRjMWsLJ4-g 提取码: 3h24。这样创建的虚拟机,有/dev/kvm 节点,可以使用kvm。在虚拟机上运行、调试虚拟机。只要把虚拟机的eth0 和Host的tap0 设置同网段ip。root 目录下,有个简单的使用kvm程序。rootfs.ext2 用ssh 的配置。rootfs.ext2 下载。这个虚拟机是nvhe。

2024-06-30 09:47:07 144

原创 vmlinux的调整,方便linux kernel 打开mmu之前的调试

如何调试符号表。

2024-04-17 13:50:53 538

原创 kasan bug 已经相应log

kasan bug log

2024-02-20 09:44:49 799

原创 this_cpu_cmpxchg_double

#define this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) \ __pcpu_double_call_return_bool(this_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2)#define __pcpu_double_call_return_bool(stem, pcp1, pcp2, ...) \({ ...

2024-02-20 09:41:26 418

原创 struct unknown 一个有趣的c编译器特性

发现一个有趣的c编译器特性:struct unknown *my_t1;my_t1 = (struct unknown *)0xffff111;struct unknown 在任何地方都没有声名,但以上语句,c编译器不会报错。因为只是一个指针的赋值,不需要具体类型。但如果这样 : *my_t1 = 1就会报一下错误。src/cc.c:169:2: error: dereferencing pointer to incomplete type 'struct unknown'因为这

2022-03-10 16:21:17 233

原创 libunwind 中的宏

有些宏真的很绕:static inline intcommon_init (struct cursor *c, unsigned use_prev_instr){int ret;c->dwarf.loc[RAX] = REG_INIT_LOC(c, rax, RAX);-># define REG_INIT_LOC(c, rlc, ruc) \ DWARF_REG_LOC (&c->dwarf, UNW_X86_64_ ## ruc)-&gt..

2022-01-29 10:49:49 808

原创 Linux 内核 由fd获得文件名

fd 不是唯一的,只是进程打开文件的index. 利用current->files + fd 可获得文件名{struct file *ftmp = NULL;struct fdtable *fdt = NULL;fdt = (struct fdtable *)files_fdtable(current->files);ftmp = fdt->fd[fd];if ((ftmp->f_path.dentry != NULL) &&(ft

2021-12-29 20:03:23 1611

原创 warning: implicit declaration of function ‘xxxxx‘ 导致的严重后果

一个简单的函数,返回一个全局的指针:_Uint64t *xxxxx(){ return 全局指针;}但运行时发现xxxxx的返回值的高32位被清空。函数的汇编没有问题0000000000003a0c <xxxxx>: 3a0c: f0000080 adrp x0, 16000 <__dso_handle> 3a10: 91018000 add x0, x0, #0x60 3a14: d65...

2021-12-03 16:10:02 721

原创 audit2allow 的 -p 参数

网络上大量资料都是说audit2allow 要这样用audit2allow -i avc.log其实这样是用ubuntu 上的sepolicy去检测avc.log 中的avc会报一些莫名其妙的问题:libsepol.context_from_record: user u is not definedlibsepol.context_from_record: could not create context structurelibsepol.context_from_string:...

2021-10-13 19:43:39 1211

原创 Linux Kernel –系统调用(ARM 64)

用户进程有用户态和内核态两种执行状态,用户进程可以通过系统调用陷入内核态,陷入内核态就意味着可以访问内核的资源。那么如何陷入内核态呢?一般通过同步异常操作来实现。ARM64专门定义了svc指令,用于进入同步异常,也就是说,一旦执行了svc指令,cpu立即跳转到同步异常入口地址处,从这个地址进入内核态。当程序调用了open,read,write,sleep,mutex等等,就做了系统调用 。系统调用就是程序如何进入内核执行任务。程序使用系统调用执行一系列的操作诸如:创建进程,网络和文件IO等等。你.

2021-09-07 19:42:47 717

原创 在Trace 32中找查看per_cup 变量

比如说我们要找runqueues, 先运行v.v runqueues 找到基地址再找per_cpu offset , v.vper_cpu offset如果找cpu0 的runqueuesv.v (struct rq *)(0x FFFFFF8008F629C0 + 0x00000041F6C7D000) 基地址 cup0 offset , __per_cpu_off...

2021-08-23 19:25:49 566

原创 Arm64 Linux : DECLARE_PER_CPU DEFINE_PER_CPU 区别

#define DECLARE_PER_CPU(type, name) \DECLARE_PER_CPU_SECTION(type, name, "")#define DEFINE_PER_CPU(type, name) \DEFINE_PER_CPU_SECTION(type, name, "")看看具体定义:/** Normal declaration and definition macros.*/#define DECLARE_PER_CPU_SECTION.

2021-08-05 15:44:32 369

原创 Arm 64 Linux per_cpu 变量读取

比如我们读取或者写入一个per cpu变量cnten_val = per_cpu(cntenset_val, cpu);其实就是求这个per cpu 变量的地址#define per_cpu(var, cpu) (*per_cpu_ptr(&(var), cpu))#define per_cpu_ptr(ptr, cpu) \({ \ __verify_p...

2021-07-30 16:33:22 567

原创 内存屏障 与 volatile

编译器代码优化加了mb 后,编译器优化没有了但我们无法看到mb 禁止了cpu的乱序执行volatile volatile关键字可以解决编译器的乱序问题 处理器乱序执行的避免就需要用到一组内存屏障函数(barrier)了...

2021-07-27 11:10:47 88

原创 devm_ioremap_resource devm_ioremap 区别

从源代码看devm_ioremap_resource多了 if (!devm_request_mem_region(dev, res->start, size, name)) { dev_err(dev, "can't request region for resource %pR\n", res); return IOMEM_ERR_PTR(-EBUSY); }从driver 代码中可以看到有时间用devm_ioremap_resource, 而有时直接用devm_iorema

2021-07-15 09:55:02 8845

原创 ARM64 Linux : thread_ground in struct task_struct

struct task_struct{… struct list_head tasks;… structlist_headthread_group;…}thread_group 会包含当前的task_struct证明如下: (struct task_struct *)(NSD:0xFFFFFF8009125890) = 0xFFFFFF8009125890 -> (... thread_group_= ( next = 0xFFFFFF800...

2021-07-14 18:31:16 168

原创 Arm64 KVM : 如何GPA到HPA的映射

如何获得fault_ipahva 请参卡一下文章:https://blog.csdn.net/weixin_46485500/article/details/118339827?spm=1001.2014.3001.5501static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,struct kvm_memory_slot *memslot, unsigned long hva,unsigned l..

2021-07-07 16:43:35 614

原创 Arm64 KVM : 如何判断Guest abort 是否为Instruction Abort

先看看Arm V8 ESR_EL2如何定义的:EC :Exception ClassInstruction Abort所以就是判断 ESR_EL2 的 EC 是否为0b100000看看Linux kernel 代码实现:static inline bool kvm_vcpu_trap_is_iabt(const struct kvm_vcpu *vcpu){ return kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_I...

2021-07-01 13:42:14 317

原创 ARM64 KVM User Space 和 Kernel 如何共享kvm_run数据

User Spacevcpu_fd = ioctl(vm_fd, KVM_CREATE_VCPU, 0);kvm_run = (struct kvm_run *)mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, vcpu_fd, 0);kvm_run 是经常要用到的数据,copy来copy去,效率不高。在这里User Space 是直接使用kernel 的vcpu->run我们看看是如何实现的,其实本质就是mmap.

2021-06-30 17:15:37 175

原创 ARM64 KVM io_mem_abort

此文档持续更新虚拟机发生mem abort, host是如何获得mem abort 信息:int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa){struct kvm_run *run = vcpu->run;unsigned long data;unsigned long rt;int ret;bool is_write;int len;u8 data_buf[8];/**

2021-06-29 17:21:20 588

原创 ARM64 KVM : KVM_SET_ONE_REG KVM_GET_ONE_REG

KVM_SET_ONE_REG 从名字上看就是设置一个寄存器的值。KVM_GET_ONE_REG从名字上看就是取一个寄存器值。我们一起看看吧。user space 和 kernel space 通用structstruct kvm_one_reg { __u64 id; __u64 addr;};User space#define AARCH64_CORE_REG(x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_AR...

2021-06-24 20:17:31 213

原创 ARM64 Linux KVM 常用结构

include/linux/kvm_host.hstruct kvm_vcpu {struct kvm *kvm;#ifdef CONFIG_PREEMPT_NOTIFIERSstruct preempt_notifier preempt_notifier;#endifint cpu;int vcpu_id; /* id given by userspace at creation */int vcpu_idx; /* index in kvm->vcpus array

2021-06-23 16:32:39 438 1

原创 readx_poll_timeout and readx_poll_timeout_atomic

op :op(addr) ,对addr 操作,通常为读操作 如 ioread32(addr)addr : 寄存器地址val : 读完成后保存变量cond :判断条件sleep_us : 休眠时间timeout_us : time out 时间使用实例readx_poll_timeout(LAN743X_CSR_READ_OP, PMT_CTL, data, (!(data & PMT_CTL_ETH_PHY_RST_) && (data &...

2021-06-23 13:42:42 1497

原创 树梅派4b+ubuntu-20.04.2-server ARM64 更换Linux 内核

HW :树梅派4b 4GOS :ubuntu-20.04.2-server ARM64下载树梅派 的linux kernelhttps://github.com/raspberrypi/linux$git clone --depth=1 -bVERSIONhttps://github.com/raspberrypi/linux.git其中VERSION替换为对应的版本号.加上--depth=1参数使得只会下载最新的一次commit. 查不到code 提交的历史。也可下...

2021-06-22 19:56:00 1062

原创 kernel log 输出某进程打开的文件

LINUX/android/kernel//fs/open.cstatic int stTemp = 0;long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode) { struct open_flags op; int fd = build_open_flags(flags, mode, &op); struct filename *tmp; if (fd) return fd; tm.

2021-06-21 13:31:43 154 1

原创 C中嵌入汇编获得CPU 寄存器 SP的值

char *isp;__asm volatile("mov %0, sp" :"=r"(isp): :);

2021-06-17 21:07:30 2165

原创 arm64 linux mmu表创建过程

__create_pgd_mapping ->alloc_init_pud ->alloc_init_cont_pmd ->init_pmd ->alloc_init_cont_pte ->init_pte ->set_pte(ptep, pfn_pte(__phys_to_pfn(phys), prot));

2021-06-15 19:53:28 251 1

原创 arm64 linux set_pte(ptep, pfn_pte(__phys_to_pfn(phys), prot));

pfn_pte(__phys_to_pfn(phys), prot)macro 只能一级一级的看#define __phys_to_pfn(paddr) PHYS_PFN(paddr)

2021-06-15 19:06:47 436

原创 arm64 kvm 常用 macro

__vcpu_sys_reg(vcpu, reg) = val;#define __vcpu_sys_reg(v,r) (ctxt_sys_reg(&(v)->arch.ctxt, (r)))#define ctxt_sys_reg(c,r) (*__ctxt_sys_reg(c,r))#define __ctxt_sys_reg(c,r) (&(c)->sys_regs[(r)])arch/arm64/include/asm/kvm_host....

2021-06-15 15:05:18 339

DDI0557A_b_armv8_1_supplement.pdf

ARM Architecture Reference Manual Supplement ARMv8.1, for ARMv8-A architecture profile

2021-05-22

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除