From: Phil Carmody <ext-phil.2.carmody@nokia.com>
To: "Doyu Hiroshi (Nokia-D/Helsinki)" <hiroshi.doyu@nokia.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"catalin.marinas@arm.com" <catalin.marinas@arm.com>
Subject: Re: [PATCH 1/2] kmemleak: Fix some false positives with special scan
Date: Mon, 31 May 2010 19:41:21 +0300 [thread overview]
Message-ID: <20100531164121.GV17639@pcarmody-desktop> (raw)
In-Reply-To: <1273821401-26578-2-git-send-email-Hiroshi.DOYU@nokia.com>
One small comment below.
On 14/05/10 09:16 +0200, Doyu Hiroshi (Nokia-D/Helsinki) wrote:
> From: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
>
> There is the false positive that the pointer is calculated by other
> methods than the usual container_of macro. "kmemleak_ignore" can cover
> a false positive, but it would loose the advantage of kmemleak. This
> patch allows kmemleak to work with such false positives by introducing
> a new special memory block with a calculation formula. The client
> module can register the area with a function, which kmemleak scan and
> calculate the pointer with the function.
>
> The typical use case could be the IOMMU first level pagetable which
> stores the pointer to the second level of page table with
> modification, for example, a physical address with attribution bits.
>
> Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
> ---
> include/linux/kmemleak.h | 4 ++
> mm/kmemleak.c | 83 ++++++++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 84 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/kmemleak.h b/include/linux/kmemleak.h
> index 99d9a67..10be9ef 100644
> --- a/include/linux/kmemleak.h
> +++ b/include/linux/kmemleak.h
> @@ -35,6 +35,10 @@ extern void kmemleak_ignore(const void *ptr) __ref;
> extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
> extern void kmemleak_no_scan(const void *ptr) __ref;
>
> +extern int kmemleak_special_scan(const void *ptr, size_t size,
> + unsigned long (*fn)(unsigned long)) __ref;
> +extern void kmemleak_no_special(const void *ptr) __ref;
> +
> static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
> int min_count, unsigned long flags,
> gfp_t gfp)
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index 2c0d032..5166987 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -249,6 +249,67 @@ static struct early_log
> early_log[CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE] __initdata;
> static int crt_early_log __initdata;
>
> +/* scan area which requires special conversion */
> +struct special_block {
> + void *start;
> + void *end;
> + unsigned long (*fn)(unsigned long);
> +};
> +#define SPECIAL_MAX 5
> +static struct special_block special_block[SPECIAL_MAX];
> +static DEFINE_SPINLOCK(special_block_lock);
> +
> +int kmemleak_special_scan(const void *ptr, size_t size,
> + unsigned long (*fn)(unsigned long))
> +{
> + struct special_block *p;
> + int i, err = 0;
> +
> + if (!ptr || (size == 0) || !fn)
> + return -EINVAL;
> +
> + spin_lock(&special_block_lock);
> +
> + p = special_block;
> + for (i = 0; i < SPECIAL_MAX; i++, p++) {
> + if (!p->start)
> + break;
> + }
> +
> + if (i == SPECIAL_MAX) {
> + err = -ENOMEM;
> + goto out;
> + }
> + p->start = (void *)ptr;
> + p->end = (void *)ptr + size;
> + p->fn = fn;
> +out:
> + spin_unlock(&special_block_lock);
> +
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(kmemleak_special_scan);
> +
> +void kmemleak_no_special(const void *ptr)
> +{
> + int i;
> +
> + spin_lock(&special_block_lock);
> +
> + for (i = 0; i < SPECIAL_MAX; i++) {
> + struct special_block *p;
> +
> + p = &special_block[i];
> + if (p->start == ptr) {
> + memset(p, 0, sizeof(*p));
> + break;
> + }
> + }
> +
> + spin_unlock(&special_block_lock);
> +}
> +EXPORT_SYMBOL_GPL(kmemleak_no_special);
> +
> static void kmemleak_disable(void);
>
> /*
> @@ -983,8 +1044,9 @@ static int scan_should_stop(void)
> * Scan a memory block (exclusive range) for valid pointers and add those
> * found to the gray list.
> */
> -static void scan_block(void *_start, void *_end,
> - struct kmemleak_object *scanned, int allow_resched)
> +static void __scan_block(void *_start, void *_end,
> + struct kmemleak_object *scanned, int allow_resched,
> + unsigned long (*fn)(unsigned long))
> {
> unsigned long *ptr;
> unsigned long *start = PTR_ALIGN(_start, BYTES_PER_POINTER);
> @@ -1005,7 +1067,7 @@ static void scan_block(void *_start, void *_end,
> BYTES_PER_POINTER))
> continue;
>
> - pointer = *ptr;
> + pointer = fn ? fn(*ptr) : *ptr;
Tests on the real-world scenario where this special scan became
desirable indicate that the following micro-optimisation is useful,
as much of the scanning is over zero-initialised blocks:
- pointer = *ptr;
+ pointer = (fn && *ptr) ? fn(*ptr) : *ptr;
But that's itsy-bitsy.
As this patchset is already making itself useful, I'd like to add my
support for it:
Acked-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Cheers,
Phil
next prev parent reply other threads:[~2010-05-31 16:38 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-14 7:16 [RFC][PATCH 0/2] " Hiroshi DOYU
2010-05-14 7:16 ` [PATCH 1/2] " Hiroshi DOYU
2010-05-31 16:41 ` Phil Carmody [this message]
2010-06-01 10:25 ` [PATCH v2 0/3] kmemleak: Fix false positive " Hiroshi DOYU
2010-06-02 10:01 ` Catalin Marinas
2010-06-02 11:34 ` Hiroshi DOYU
2010-06-02 12:28 ` Hiroshi DOYU
2010-06-02 14:12 ` Catalin Marinas
2010-06-03 9:54 ` Hiroshi DOYU
2010-06-18 6:04 ` [RFC][PATCH 0/1] kmemleak: Fix false positive with alias Hiroshi DOYU
2010-06-22 15:36 ` Phil Carmody
2010-06-28 14:46 ` Catalin Marinas
2010-06-29 4:44 ` Hiroshi DOYU
2010-08-10 15:49 ` Hiroshi DOYU
2010-08-27 6:12 ` Hiroshi DOYU
2010-08-30 20:30 ` Paul E. McKenney
2010-09-17 13:14 ` Catalin Marinas
2010-09-17 16:18 ` Catalin Marinas
2010-09-17 17:06 ` Hiroshi DOYU
2010-09-17 17:28 ` Phil Carmody
2010-06-18 6:04 ` [PATCH 1/1] " Hiroshi DOYU
2010-06-01 10:25 ` [PATCH v2 1/3] kmemleak: Fix false positives with special scan Hiroshi DOYU
2010-06-01 10:25 ` [PATCH v2 2/3] kmemleak: Add special scan test case Hiroshi DOYU
2010-06-01 10:25 ` [PATCH v2 3/3] omap iommu: kmemleak: Fix false positive with special scan Hiroshi DOYU
2010-05-14 7:16 ` [PATCH 2/2] kmemleak: test: Add a special scan test case Hiroshi DOYU
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=20100531164121.GV17639@pcarmody-desktop \
--to=ext-phil.2.carmody@nokia.com \
--cc=catalin.marinas@arm.com \
--cc=hiroshi.doyu@nokia.com \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®