All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Efremov <efremov@linux.com>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6] coccinelle: api: add kvfree script
Date: Mon, 3 Aug 2020 14:33:45 +0300	[thread overview]
Message-ID: <a8d8eade-1d98-b8d9-7c66-bd05b22af751@linux.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2008022142550.2531@hadrien>



On 8/2/20 11:24 PM, Julia Lawall wrote:
>> +@initialize:python@
>> +@@
>> +# low-level memory api
>> +filter = frozenset(['__vmalloc_area_node'])
>> +
>> +def relevant(p):
>> +    return not (filter & {el.current_element for el in p})
> 
> Is this used?

I'll remove it in v8. Or do you want me to add iterate_dir_item() in the list?

> 
> Otherwise, I think it would be good to not warn about a use of kvfree
> if that use is reachable from a kvmalloc.  There seems to be such a false
> positive in fs/btrfs/send.c, on line 1118.

I don't know how to handle this case without position filter.
It's too complex. In iterate_dir_item() there is:
buf = kmalloc(buf_len, GFP_KERNEL);
while(...) {
	if (...) {
		if (is_vmalloc_addr(buf)) {
			vfree(buf);
			...
		} else {
			char *tmp = krealloc(buf, ...);

			if (!tmp)
				kfree(buf);
			...
		}
		if (!buf) {
			buf = kvmalloc(buf_len, GFP_KERNEL);
			...
		}
	}
}
kvfree(buf);

Adding "when != kvfree(E)" is not enough:
* E = \(kvmalloc\|kvzalloc\|kvcalloc\|kvzalloc_node\|kvmalloc_node\|
*       kvmalloc_array\)(...)@k
	... when != is_vmalloc_addr(E)
+	when != kvfree(E)
	when any
* \(kfree\|kzfree\|vfree\|vfree_atomic\)(E)@p

> 
> It also seems that when there are both a kmalloc and a vmalloc, there is
> no warning if kfree or vfree is used.  Is that intentional?
> 

No, I will try to address it in v8.

Regards,
Denis

WARNING: multiple messages have this Message-ID (diff)
From: Denis Efremov <efremov@linux.com>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org
Subject: Re: [Cocci] [PATCH v6] coccinelle: api: add kvfree script
Date: Mon, 3 Aug 2020 14:33:45 +0300	[thread overview]
Message-ID: <a8d8eade-1d98-b8d9-7c66-bd05b22af751@linux.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2008022142550.2531@hadrien>



On 8/2/20 11:24 PM, Julia Lawall wrote:
>> +@initialize:python@
>> +@@
>> +# low-level memory api
>> +filter = frozenset(['__vmalloc_area_node'])
>> +
>> +def relevant(p):
>> +    return not (filter & {el.current_element for el in p})
> 
> Is this used?

I'll remove it in v8. Or do you want me to add iterate_dir_item() in the list?

> 
> Otherwise, I think it would be good to not warn about a use of kvfree
> if that use is reachable from a kvmalloc.  There seems to be such a false
> positive in fs/btrfs/send.c, on line 1118.

I don't know how to handle this case without position filter.
It's too complex. In iterate_dir_item() there is:
buf = kmalloc(buf_len, GFP_KERNEL);
while(...) {
	if (...) {
		if (is_vmalloc_addr(buf)) {
			vfree(buf);
			...
		} else {
			char *tmp = krealloc(buf, ...);

			if (!tmp)
				kfree(buf);
			...
		}
		if (!buf) {
			buf = kvmalloc(buf_len, GFP_KERNEL);
			...
		}
	}
}
kvfree(buf);

Adding "when != kvfree(E)" is not enough:
* E = \(kvmalloc\|kvzalloc\|kvcalloc\|kvzalloc_node\|kvmalloc_node\|
*       kvmalloc_array\)(...)@k
	... when != is_vmalloc_addr(E)
+	when != kvfree(E)
	when any
* \(kfree\|kzfree\|vfree\|vfree_atomic\)(E)@p

> 
> It also seems that when there are both a kmalloc and a vmalloc, there is
> no warning if kfree or vfree is used.  Is that intentional?
> 

No, I will try to address it in v8.

Regards,
Denis
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  reply	other threads:[~2020-08-03 11:33 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05 20:42 [PATCH] coccinelle: api: add kvfree script Denis Efremov
2020-06-05 20:42 ` [Cocci] " Denis Efremov
2020-06-05 20:51 ` Julia Lawall
2020-06-05 20:51   ` Julia Lawall
2020-06-05 21:15   ` Denis Efremov
2020-06-05 21:15     ` Denis Efremov
2020-06-05 21:19     ` Julia Lawall
2020-06-05 21:19       ` Julia Lawall
2020-06-14  9:03   ` Denis Efremov
2020-06-14  9:03     ` Denis Efremov
2020-06-14  9:17     ` Julia Lawall
2020-06-14  9:17       ` Julia Lawall
2020-06-14  9:24       ` Denis Efremov
2020-06-14  9:24         ` Denis Efremov
2020-06-14 18:36 ` [PATCH v2] " Denis Efremov
2020-06-14 18:36   ` [Cocci] " Denis Efremov
2020-07-17 12:00   ` Denis Efremov
2020-07-17 12:00     ` [Cocci] " Denis Efremov
2020-07-30 14:01 ` [PATCH v3] " Denis Efremov
2020-07-30 14:01   ` [Cocci] " Denis Efremov
2020-07-30 14:05   ` Denis Efremov
2020-07-30 14:05     ` [Cocci] " Denis Efremov
2020-07-30 14:07 ` [PATCH v4] " Denis Efremov
2020-07-30 14:07   ` [Cocci] " Denis Efremov
2020-07-30 20:15   ` Julia Lawall
2020-07-30 20:15     ` [Cocci] " Julia Lawall
2020-07-30 20:38   ` Julia Lawall
2020-07-30 20:38     ` [Cocci] " Julia Lawall
2020-07-31  8:31     ` Denis Efremov
2020-07-31  8:31       ` [Cocci] " Denis Efremov
2020-07-31  8:48       ` Julia Lawall
2020-07-31  8:48         ` [Cocci] " Julia Lawall
2020-07-31 10:47 ` [PATCH v5] " Denis Efremov
2020-07-31 10:47   ` [Cocci] " Denis Efremov
2020-07-31 21:00 ` [PATCH v6] " Denis Efremov
2020-07-31 21:00   ` [Cocci] " Denis Efremov
2020-08-02 20:24   ` Julia Lawall
2020-08-02 20:24     ` [Cocci] " Julia Lawall
2020-08-03 11:33     ` Denis Efremov [this message]
2020-08-03 11:33       ` Denis Efremov
2020-08-03 12:18       ` Julia Lawall
2020-08-03 12:18         ` [Cocci] " Julia Lawall
2020-08-03 11:45   ` Denis Efremov
2020-08-03 11:45     ` [Cocci] " Denis Efremov
2020-08-03 12:12     ` Julia Lawall
2020-08-03 12:12       ` [Cocci] " Julia Lawall
2020-08-03 18:34 ` [PATCH v7] coccinelle: api: add kfree_mismatch script Denis Efremov
2020-08-03 18:34   ` [Cocci] " Denis Efremov
2020-09-21 17:15   ` Denis Efremov
2020-09-21 17:15     ` [Cocci] " Denis Efremov
2020-10-15 20:48   ` Julia Lawall
2020-10-15 20:48     ` [Cocci] " Julia Lawall
2020-10-16  8:54 ` [PATCH v8] " Denis Efremov
2020-10-16  8:54   ` [Cocci] " Denis Efremov
2020-10-17 21:17   ` Julia Lawall
2020-10-17 21:17     ` Julia Lawall
     [not found] <3aea12cf-68dc-e140-936f-cfefb2adbc8f@web.de>
2020-08-02  7:09 ` [PATCH v6] coccinelle: api: add kvfree script Julia Lawall
2020-08-02  7:09   ` Julia Lawall

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=a8d8eade-1d98-b8d9-7c66-bd05b22af751@linux.com \
    --to=efremov@linux.com \
    --cc=cocci@systeme.lip6.fr \
    --cc=julia.lawall@inria.fr \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.