linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] mm/page_counter: annotate an intentional data race
@ 2020-01-29 13:12 Qian Cai
  2020-01-29 13:29 ` Michal Hocko
  0 siblings, 1 reply; 3+ messages in thread
From: Qian Cai @ 2020-01-29 13:12 UTC (permalink / raw)
  To: akpm
  Cc: penguin-kernel, hannes, elver, linux-mm, linux-kernel, Qian Cai,
	syzbot+f36cfe60b1006a94f9dc

The commit 3e32cb2e0a12 ("mm: memcontrol: lockless page counters") could
had memcg->memsw->failcnt been accessed concurrently as reported by
KCSAN,

BUG: KCSAN: data-race in page_counter_try_charge / page_counter_try_charge

write to 0xffff88809bbf2158 of 8 bytes by task 11782 on cpu 0:
 page_counter_try_charge+0x100/0x170 mm/page_counter.c:129
 try_charge+0x185/0xbf0 mm/memcontrol.c:2405
 __memcg_kmem_charge_memcg+0x4a/0xe0 mm/memcontrol.c:2837
 __memcg_kmem_charge+0xcf/0x1b0 mm/memcontrol.c:2877
 __alloc_pages_nodemask+0x26c/0x310 mm/page_alloc.c:4780

read to 0xffff88809bbf2158 of 8 bytes by task 11814 on cpu 1:
 page_counter_try_charge+0xef/0x170 mm/page_counter.c:129
 try_charge+0x185/0xbf0 mm/memcontrol.c:2405
 __memcg_kmem_charge_memcg+0x4a/0xe0 mm/memcontrol.c:2837
 __memcg_kmem_charge+0xcf/0x1b0 mm/memcontrol.c:2877
 __alloc_pages_nodemask+0x26c/0x310 mm/page_alloc.c:4780

Since the "failcnt" counter is tolerant of some degree of inaccuracy and
is only used to report stats, a data race will not be harmful, thus mark
it as an intentional data races with the data_race() macro.

Reported-by: syzbot+f36cfe60b1006a94f9dc@syzkaller.appspotmail.com
Signed-off-by: Qian Cai <cai@lca.pw>
---
 mm/page_counter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/page_counter.c b/mm/page_counter.c
index a17841150906..7c82072cda25 100644
--- a/mm/page_counter.c
+++ b/mm/page_counter.c
@@ -126,7 +126,7 @@ bool page_counter_try_charge(struct page_counter *counter,
 			 * This is racy, but we can live with some
 			 * inaccuracy in the failcnt.
 			 */
-			c->failcnt++;
+			data_race(c->failcnt++);
 			*fail = c;
 			goto failed;
 		}
-- 
2.21.0 (Apple Git-122.2)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH -next] mm/page_counter: annotate an intentional data race
  2020-01-29 13:12 [PATCH -next] mm/page_counter: annotate an intentional data race Qian Cai
@ 2020-01-29 13:29 ` Michal Hocko
  2020-02-11 12:16   ` Qian Cai
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Hocko @ 2020-01-29 13:29 UTC (permalink / raw)
  To: Qian Cai
  Cc: akpm, penguin-kernel, hannes, elver, linux-mm, linux-kernel,
	syzbot+f36cfe60b1006a94f9dc

On Wed 29-01-20 08:12:42, Qian Cai wrote:
> The commit 3e32cb2e0a12 ("mm: memcontrol: lockless page counters") could
> had memcg->memsw->failcnt been accessed concurrently as reported by
> KCSAN,
> 
> BUG: KCSAN: data-race in page_counter_try_charge / page_counter_try_charge
> 
> write to 0xffff88809bbf2158 of 8 bytes by task 11782 on cpu 0:
>  page_counter_try_charge+0x100/0x170 mm/page_counter.c:129
>  try_charge+0x185/0xbf0 mm/memcontrol.c:2405
>  __memcg_kmem_charge_memcg+0x4a/0xe0 mm/memcontrol.c:2837
>  __memcg_kmem_charge+0xcf/0x1b0 mm/memcontrol.c:2877
>  __alloc_pages_nodemask+0x26c/0x310 mm/page_alloc.c:4780
> 
> read to 0xffff88809bbf2158 of 8 bytes by task 11814 on cpu 1:
>  page_counter_try_charge+0xef/0x170 mm/page_counter.c:129
>  try_charge+0x185/0xbf0 mm/memcontrol.c:2405
>  __memcg_kmem_charge_memcg+0x4a/0xe0 mm/memcontrol.c:2837
>  __memcg_kmem_charge+0xcf/0x1b0 mm/memcontrol.c:2877
>  __alloc_pages_nodemask+0x26c/0x310 mm/page_alloc.c:4780
> 
> Since the "failcnt" counter is tolerant of some degree of inaccuracy and
> is only used to report stats, a data race will not be harmful, thus mark
> it as an intentional data races with the data_race() macro.
> 
> Reported-by: syzbot+f36cfe60b1006a94f9dc@syzkaller.appspotmail.com
> Signed-off-by: Qian Cai <cai@lca.pw>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/page_counter.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/page_counter.c b/mm/page_counter.c
> index a17841150906..7c82072cda25 100644
> --- a/mm/page_counter.c
> +++ b/mm/page_counter.c
> @@ -126,7 +126,7 @@ bool page_counter_try_charge(struct page_counter *counter,
>  			 * This is racy, but we can live with some
>  			 * inaccuracy in the failcnt.
>  			 */
> -			c->failcnt++;
> +			data_race(c->failcnt++);
>  			*fail = c;
>  			goto failed;
>  		}
> -- 
> 2.21.0 (Apple Git-122.2)

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH -next] mm/page_counter: annotate an intentional data race
  2020-01-29 13:29 ` Michal Hocko
@ 2020-02-11 12:16   ` Qian Cai
  0 siblings, 0 replies; 3+ messages in thread
From: Qian Cai @ 2020-02-11 12:16 UTC (permalink / raw)
  To: Michal Hocko
  Cc: akpm, penguin-kernel, hannes, elver, linux-mm, linux-kernel,
	syzbot+f36cfe60b1006a94f9dc



> On Jan 29, 2020, at 8:29 AM, Michal Hocko <mhocko@kernel.org> wrote:
> 
> Acked-by: Michal Hocko <mhocko@suse.com>

Andrew, you might forget about picking this up too?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-11 12:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-29 13:12 [PATCH -next] mm/page_counter: annotate an intentional data race Qian Cai
2020-01-29 13:29 ` Michal Hocko
2020-02-11 12:16   ` Qian Cai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).