Martins3 / loongson-dune

:zap: Process virtualization based on KVM. More useable, stable and practical than Stanford Dune.
20 stars 3 forks source link

getpid failed when glibc dynamic linked #47

Closed Martins3 closed 3 years ago

Martins3 commented 3 years ago
Martins3 commented 3 years ago

这个是和 vdso 有关的,getpid 和 getuid 会走 vdso,而 vdso 中实现 getpid 需要利用到 timerid:

  1. disable 系统的 vdso : 重新编译内核
  2. disable 这个程序的 vdso
  3. 修改 kvm 代码,当 vcpu_load 的时候刷新 timerid
  4. 让 glibc 静态链接
    • [ ] 为什么让 glibc 静态链接可以阻止 vdso
Martins3 commented 3 years ago
Martins3 commented 3 years ago

ltp 结果分析:

Martins3 commented 3 years ago
Martins3 commented 3 years ago
diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c
index fd93cbea93fe..d5af832d7e33 100644
+++ b/arch/loongarch/kvm/mmu.c
@@ -1200,11 +1200,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
                 */
                kvm_loongarch_migrate_count(vcpu);
        }
+       write_gcsr_timerid(cpu);
+       kvm_restore_gcsr_timerid(vcpu->arch.csr);

        /* restore guest state to registers */
        kvm_cpu_cb->vcpu_load(vcpu, cpu);
        local_irq_restore(flags);
 }
Martins3 commented 3 years ago