Skip to contentSkip to conversation

fix the SEGBUS signal error

PATCH In review Zhouping Liu 3 participants 3 messages Nov 25, 2010 1 message not in the archive

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 fix the SEGBUS signal error

In reply to a message not in the archive

Hi,all
when I run this test program :
#./hugemmap04 -I 3600 -H /var/hugetlbfs
I found it returned quickly.
I used gdb tool to debug it, it returned error with the 'SEGBUS' signal error, and the error occurred in the 178 lines '*(int*)addr = 0;'.
it's okay when I add this line
write(fildes, "write some words to the TEMPFILE file\n",40);
you can run this c program to find this error.
$cat test.c

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
char * TEMPFILE="mmapfile";
int freepages = 0;
int main()
{
long *addr;
int fd;
long long mapsize;
if ((fd = open(TEMPFILE, O_RDWR | O_CREAT | O_TRUNC,0666)) < 0) { printf("open error\n");
return -2;
}
freepages = 100;
mapsize = (long long)freepages * 2048 * 1024;
printf("mapsize is %lld \n",mapsize);
addr = (long *)mmap(NULL,mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd,0); if (addr == MAP_FAILED) {
printf("mmap error\n");
return -1;
}
/* if you enable this line,there will be no error. */ //write(fd,"I don't know\n",20);
*(int *)addr = 0;
sleep(10);
close(fd);
return 0;
}

$./test
mapsize is 209715200
Bus error (core dumped)
$

Signed-off-by Zhouping Liu < zliu@ redhat >
testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c +0 -0
index 485b465..cc7b249 100644 
@@ -174,6 +174,8 @@ main(int ac, char **av) 

continue;
} else {
tst_resm(TPASS, "Succeeded mapping file using %d pages",freepages);
+ /* the write function just do initalization */
+ write(fildes, "write some words to the TEMPFILE file\n",40); /* force to allocate page and change HugePages_Free */ *(int*)addr = 0;
}

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw

your patch seems to be horribly mangled. please use git send-email or something like that.
-mike

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw
In reply to Zhouping Liu
Quoted 60 lines · Zhouping Liu

Hi,all
when I run this test program :
#./hugemmap04 -I 3600 -H /var/hugetlbfs
I found it returned quickly.
I used gdb  tool to debug it, it returned error with the 'SEGBUS' signal error,
and the error occurred in the 178 lines '*(int*)addr = 0;'. it's okay when I add this line
write(fildes, "write some words to the TEMPFILE file\n",40); you can run this c program to find this error.
$cat test.c

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
char * TEMPFILE="mmapfile";
int freepages = 0;
int main()
{
    long *addr;
    int fd;
    long long mapsize;
    if ((fd = open(TEMPFILE, O_RDWR | O_CREAT | O_TRUNC,0666)) < 0) { printf("open error\n");
        return -2;
    }
    freepages = 100;
    mapsize = (long long)freepages * 2048 * 1024; printf("mapsize is %lld \n",mapsize);
    addr = (long *)mmap(NULL,mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd,0);
    if (addr == MAP_FAILED) {
        printf("mmap error\n");
        return -1;
    }
     /*  if you enable this line,there will be no error. */ //write(fd,"I don't know\n",20);
    *(int *)addr = 0;
    sleep(10);
    close(fd);
    return 0;
}

$./test
mapsize is 209715200
Bus error (core dumped)
$

testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c +0 -0
index 485b465..cc7b249 100644
@@ -174,6 +174,8 @@ main(int ac, char **av)
                         continue;
                 } else {

                        tst_resm(TPASS, "Succeeded mapping file using %d

Quoted 8 lines

pages",freepages);
+                       /* the write function just do initalization */ +                       write(fildes, "write some words to the TEMPFILE file\n",40);
                        /* force to allocate page and change HugePages_Free */
                        *(int*)addr = 0;
                }

That doesn't make sense (this test is junk in its current form
anyhow, but your conclusion doesn't make sense regardless), in particular because this logic has worked on a number of other platforms and OSes before this.
Please dig deeper to figure out what the real error is.
Thanks,
-Garrett

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list