1  version:
    valgrind-3.20.0
    4.19.25-200.el7.bclinux.x86_64
    gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) 
2  Problem description:
-- source code:   mmap a mdev device

static int test_mmap_bar(void)
{
    const char *path="/sys/class/mdev_bus/0000:06:00.0/resource4";
    ...
    flags = O_RDWR;
    prot = PROT_READ | PROT_WRITE;
    unsigned long len = 4096;
    unsigned long offset = 0x320000;
    fd = open(path, flags | O_SYNC);
&nbsp; &nbsp; if (fd < 0) {
&nbsp; &nbsp; &nbsp; &nbsp; printf("[ERROR] open device err\n");
&nbsp; &nbsp; &nbsp; &nbsp; return -1;
&nbsp; &nbsp; }
&nbsp; &nbsp; addr = mmap(0, len, prot, MAP_SHARED, fd, offset);
&nbsp; &nbsp; if (addr == P_FAILED) {
&nbsp; &nbsp; &nbsp; &nbsp; printf("[ERROR] mmap faild\n");
&nbsp; &nbsp; }
...
}


--run with valgrind : 
&nbsp; &nbsp; &nbsp;valgrind --leak-check=full --show-leak-kinds=all -v 
--log-file=valgrind.log ./build/valgrind-test --base-virtaddr=0x4000000000
-- The valgrind log reported the following error with mmap??
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;valgrind: m_debuginfo/image.c:587 
(set_CEnt): Assertion '! sr_isError(sr)' failed.
--strace valgrind:
&nbsp; &nbsp; 
&nbsp; &nbsp; open("/sys/class/mdev_bus/0000:06:00.0/resource4", O_RDWR|O_SYNC) 
= 94&nbsp; &nbsp; rt_sigprocmask(SIG_SETMASK, ~[ILL TRAP BUS FPE KILL SEGV STOP 
SYS], NULL, 8) = 0
&nbsp; &nbsp; gettid()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 13758
&nbsp; &nbsp; read(1028, "Y", 1)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; mmap(0x4033000, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 
94, 0x320000) = 0x4033000
&nbsp; &nbsp; syscall_332(0x5e, 0x58246543, 0x1000, 0xfff, 0x1003633aa0, 0) = 0
&nbsp; &nbsp; readlink("/proc/self/fd/94", 
"/sys/devices/pci0000:00/0000:00:"..., 4096) = 59
&nbsp; &nbsp; syscall_332(0xffffffffffffff9c, 0x597789da, 0, 0xfff, 
0x10036346d0, 0) = 0
&nbsp; &nbsp; syscall_332(0x5e, 0x58246543, 0x1000, 0xfff, 0x1003634560, 0) = 0
&nbsp; &nbsp; pread64(94, 0x100299acd0, 8192, 0)&nbsp; &nbsp; &nbsp; = -1 EIO 
(Input/output error)
&nbsp; 
valgrind will do pread64&nbsp; after mmap ??




4&nbsp; run directly:
-- There is no problem with mmap
-- use pread64(..)&nbsp; will cause io error


5&nbsp; Quesions:
&nbsp; &nbsp; &nbsp; &nbsp;How can I use valgrind in this case

Attachment: valgrind.log
Description: Binary data

_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to