Skip to content

Instantly share code, notes, and snippets.

@cyyself
Created October 25, 2021 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyyself/be0e5ddc6e20ab90fa740779f47bcf34 to your computer and use it in GitHub Desktop.
Save cyyself/be0e5ddc6e20ab90fa740779f47bcf34 to your computer and use it in GitHub Desktop.
/*
Hello, I'm using d1-wip kernel from https://github.com/smaeul/linux/commits/riscv/d1-wip.
My rootfs is archriscv from https://mirrors.wsyu.edu.cn/archriscv/images/archriscv-20210601.tar.zst.
I found some programs running on this kernel will get SEGV, such as curl.
I delve into this problem and found the root cause is about pthread. It just trap at "amoswap.w.aq a5,a5,(s1)". And the value of register s1 is an address on the stack.
Here is a simple program with pthread. using gcc -lpthread to compile and run on D1-board with work in progress kernel is fine.
But if you comment the printf line in function main, you will get SEGV. And the cause is 0x7.
I guess this issue related to cache or TLB didn't flush properly. So I add some "sfence.vma x0,x0" to the kernel which I think should get TLB flush, but it doesn't work.
*/
#include <stdio.h>
#include <pthread.h>
void hello() {
printf("Hello from thread\n");
return;
}
int main() {
pthread_t t1;
printf("pthread create\n"); // try to comment this line, you will get segv
if ( pthread_create(&t1,NULL,hello,NULL) ) {
return 1;
}
pthread_join(t1,NULL);
return 0;
}
@victoryang00
Copy link

d1 kernel有各种问题,一不小心就重启。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment