From: Jeff Dike <jdike@addtoit.com>
To: "D. Bahi" <dbahi@enterasys.com>
Cc: Nicholas Nethercote <njn25@cam.ac.uk>,
user-mode-linux-devel@lists.sourceforge.net,
valgrind-users@lists.sourceforge.net
Subject: Re: [Valgrind-users] Re: [uml-devel] Re: UML and valgrind
Date: Tue, 03 Aug 2004 15:40:32 -0400 [thread overview]
Message-ID: <200408031940.i73JeWvv003385@ccure.user-mode-linux.org> (raw)
In-Reply-To: Your message of "Tue, 03 Aug 2004 13:33:36 EDT." <410FCC70.1050902@enterasys.com>
If you get past the clone and repe problems in valgrind, there was another
where V was confused by UML's stack switching. I didn't see a patch for that
in my email, but someone special-cased longjmp in the stack overflow detection
to get around that.
IIRC, that got UML booting. Now, it produced almost no useful information
because V doesn't understand the kernel memory allocators. So, below are
my attempts to make it do so. These apply to UML, and describe the kernel
to V.
I don't guarantee that they are correct, but they should at least give you
an idea what needs to happen.
Jeff
V doesn't see that PTRACE_FAULTINFO initializes the fault struct given to it:
diff -Naur um/arch/um/kernel/skas/process.c v/arch/um/kernel/skas/process.c
--- um/arch/um/kernel/skas/process.c Tue Jan 14 21:09:16 2003
+++ v/arch/um/kernel/skas/process.c Mon Dec 23 11:42:39 2002
@@ -25,6 +25,8 @@
#include "proc_mm.h"
#include "skas_ptrace.h"
+#include "memcheck.h"
+
unsigned long exec_regs[FRAME_SIZE];
unsigned long exec_fp_regs[HOST_FP_SIZE];
unsigned long exec_fpx_regs[HOST_XFP_SIZE];
@@ -40,6 +42,7 @@
panic("handle_segv - PTRACE_FAULTINFO failed, errno = %d\n",
errno);
+ VALGRIND_MAKE_READABLE(&fault, sizeof(fault));
segv(fault.addr, 0, FAULT_WRITE(fault.is_write), 1, NULL);
}
This makes buffers writeable according to V when they are handed out by
the slab allocator, and no-access when they are freed:
diff -Naur um/mm/slab.c v/mm/slab.c
--- um/mm/slab.c Fri Dec 20 18:42:53 2002
+++ v/mm/slab.c Mon Dec 23 11:15:31 2002
@@ -76,6 +76,8 @@
#include <linux/seq_file.h>
#include <asm/uaccess.h>
+#include "memcheck.h"
+
/*
* DEBUG - 1 for kmem_cache_create() to honour; SLAB_DEBUG_INITIAL,
* SLAB_RED_ZONE & SLAB_POISON.
@@ -500,6 +502,11 @@
* it is a named-page or buffer-page. The members it tests are
* of no interest here.....
*/
+
+ if(addr != NULL)
+ VALGRIND_MAKE_WRITABLE(addr,
+ (1 << cachep->gfporder) * PAGE_SIZE);
+
return addr;
}
@@ -1076,8 +1083,11 @@
* the same cache which they are a constructor for.
* Otherwise, deadlock. They must also be threaded.
*/
- if (cachep->ctor)
+ if (cachep->ctor){
+ VALGRIND_MAKE_WRITABLE(objp, cachep->objsize);
cachep->ctor(objp, cachep, ctor_flags);
+ VALGRIND_MAKE_NOACCESS(objp, cachep->objsize);
+ }
#if DEBUG
if (cachep->flags & SLAB_RED_ZONE)
objp -= BYTES_PER_WORD;
@@ -1528,7 +1538,11 @@
*/
void * kmem_cache_alloc (kmem_cache_t *cachep, int flags)
{
- return __kmem_cache_alloc(cachep, flags);
+ void *ptr = __kmem_cache_alloc(cachep, flags);
+
+ if(ptr != NULL)
+ VALGRIND_MAKE_READABLE(ptr, cachep->objsize);
+ return ptr;
}
/**
@@ -1557,10 +1571,16 @@
cache_sizes_t *csizep = cache_sizes;
for (; csizep->cs_size; csizep++) {
+ void *ptr;
if (size > csizep->cs_size)
continue;
- return __kmem_cache_alloc(flags & GFP_DMA ?
- csizep->cs_dmacachep : csizep->cs_cachep, flags);
+ ptr = __kmem_cache_alloc(flags & GFP_DMA ?
+ csizep->cs_dmacachep :
+ csizep->cs_cachep, flags);
+ if(ptr != NULL)
+ VALGRIND_MAKE_WRITABLE(ptr, size);
+
+ return ptr;
}
return NULL;
}
Ditto for vmalloc/vfree:
diff -Naur um/mm/vmalloc.c v/mm/vmalloc.c
--- um/mm/vmalloc.c Mon Feb 25 12:50:45 2002
+++ v/mm/vmalloc.c Mon Dec 23 11:30:26 2002
@@ -16,6 +16,8 @@
#include <asm/uaccess.h>
#include <asm/pgalloc.h>
+#include "memcheck.h"
+
rwlock_t vmlist_lock = RW_LOCK_UNLOCKED;
struct vm_struct * vmlist;
@@ -212,11 +214,14 @@
printk(KERN_ERR "Trying to vfree() bad address (%p)\n", addr);
return;
}
+
write_lock(&vmlist_lock);
for (p = &vmlist ; (tmp = *p) ; p = &tmp->next) {
if (tmp->addr == addr) {
*p = tmp->next;
vmfree_area_pages(VMALLOC_VMADDR(tmp->addr), tmp->size);
+ VALGRIND_MAKE_NOACCESS(VMALLOC_VMADDR(tmp->addr),
+ tmp->size);
write_unlock(&vmlist_lock);
kfree(tmp);
return;
@@ -244,6 +249,8 @@
vfree(addr);
return NULL;
}
+
+ VALGRIND_MAKE_WRITABLE(addr, size);
return addr;
}
-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
next prev parent reply other threads:[~2004-08-03 18:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-08 4:13 [uml-devel] UML and valgrind Bahi, David
2004-08-03 2:47 ` [uml-devel] " D. Bahi
2004-08-03 5:17 ` Jeff Dike
2004-08-03 9:31 ` [Valgrind-users] " Nicholas Nethercote
2004-08-03 14:50 ` Jeff Dike
2004-08-03 14:31 ` Nicholas Nethercote
2004-08-03 17:50 ` Jeff Dike
2004-08-03 17:33 ` D. Bahi
2004-08-03 19:31 ` Jeff Dike
2004-08-03 20:12 ` D. Bahi
2004-08-04 7:47 ` Tom Hughes
2004-08-03 22:04 ` Nicholas Nethercote
2004-08-04 7:52 ` Tom Hughes
2004-08-04 15:10 ` Jeff Dike
2004-08-04 15:35 ` Jeff Dike
2004-08-04 14:58 ` Tom Hughes
2004-08-04 18:00 ` Jeff Dike
2004-08-04 17:57 ` Tom Hughes
2004-08-04 21:02 ` Jeff Dike
2004-08-05 9:28 ` Nicholas Nethercote
2004-08-05 13:15 ` D. Bahi
2004-08-05 15:24 ` Jeff Dike
2004-08-03 19:40 ` Jeff Dike [this message]
2004-08-04 1:09 ` Nuno Silva
2004-08-04 2:47 ` D. Bahi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200408031940.i73JeWvv003385@ccure.user-mode-linux.org \
--to=jdike@addtoit.com \
--cc=dbahi@enterasys.com \
--cc=njn25@cam.ac.uk \
--cc=user-mode-linux-devel@lists.sourceforge.net \
--cc=valgrind-users@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox