Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp551968ybl; Wed, 29 Jan 2020 05:32:07 -0800 (PST) X-Google-Smtp-Source: APXvYqwed3XwaU5hS9iszglGgf3B1cXixD+eFSn0VN1F1yomkTtsUS3KNk/axeog/fVO7QoomUi+ X-Received: by 2002:a05:6808:a8e:: with SMTP id q14mr6157247oij.173.1580304727650; Wed, 29 Jan 2020 05:32:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580304727; cv=none; d=google.com; s=arc-20160816; b=VrbELVy5EBfsZgqAKUKqNqTTS9NHFHzOsvW54GuZinSIZEY3c+IgiBFNdh8+qfxaRA JQytEgUP+PWi6DCAg4Z+quZity6u4W3SsVKc5CdxhPW4RX0bYGvE3NDf7MP3hwXsdB6R Yo4G4RIdjFsxwzFDPyjc+RdvFje9oEO70+tliCqNDFSyMLG2HvnEUgm3gIWG0cgMxQ4E 7lA8UaMJI+sfY8fXiz7ySTWaH+rAPPDJRS8a2FQbodWxIpD/aDPpecfR4oTY9aQS2nI1 L2p+MTZw5CGX30yqqTb9/Gc6WTbmxOhMZVOT8SK0AYhXaUujBJq07uC0C72gxVUkWGSu zUAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=prpS7rraPt/GjCivc8V6REqwcGP4nAyD1IPQ65+5P0g=; b=BeY4vuFbvC8nJUV3CI4rtW8jysLrBOcS5i1mImJ0tty28Mqd+t4w8gi/FHywL5nGMN pqJo4a4+18xxH/Ebf2ti51SVOIgy4uBwqMZUpn8QlUqDhjVmLsHza9D/G+DNu4Al15ym CjMy7xQsB5CnV7JZUnBtQ9VCxdQf9Q+WVhHe2dVPm1cmgDzRfEWvrzG6D6ObrMyppR5s uPNZFJPtwdGHO3ra6Nkw928SpGOvzxUeDwS2f92MYx7Yzk1kLvrpX6FHhzfbElUSXbCw QyBUn84cG/9OwlRA7A//xHp+EbwvdWd3HVKtLQiyM9Wc2tszbuCM5K5WSQrlhS3I8vXC QH9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c20si983928oic.113.2020.01.29.05.31.55; Wed, 29 Jan 2020 05:32:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726528AbgA2N3z (ORCPT + 99 others); Wed, 29 Jan 2020 08:29:55 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43041 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbgA2N3y (ORCPT ); Wed, 29 Jan 2020 08:29:54 -0500 Received: by mail-wr1-f65.google.com with SMTP id d16so20185245wre.10 for ; Wed, 29 Jan 2020 05:29:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=prpS7rraPt/GjCivc8V6REqwcGP4nAyD1IPQ65+5P0g=; b=H3x1RDTwWkfTVU+QVGVfvJyiyRyR7hsr2qppvopieE5eq7yk1sz6nk245NneIF4MMY Ic+xPF8StU5BRphRNmiFbDnfMrj8x1kPVksxCTJyNjJcF0jPUUeH2Bny7L+6LmVNw1U5 Qhq+ooZxh+GLxILQe5TIC7p6s7K50Scb6aIDWd9v3wGEURqn43DAQ21JFk9rV/ZcPgkl Ak/bmMXccHG49OhKt+rC5hZCYmhaUiGszE56083jj7kpyKobYBy7f//pb82PVS5P6x/a yU2yn4ggp0U4XNuSGzm2oo/y6YLBoL60w8K2AnI0emyEcy/2zKplqIu1f5McllgummkG jQvw== X-Gm-Message-State: APjAAAXrg7UTfuQY0YySsGc8R9APTRDoJOk2ciBgZg3SdtRAwi5dicTu /Z56VgIZDWAt4g7VjtifF8Q= X-Received: by 2002:a5d:540f:: with SMTP id g15mr33967169wrv.86.1580304592326; Wed, 29 Jan 2020 05:29:52 -0800 (PST) Received: from localhost (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id y20sm2334628wmi.23.2020.01.29.05.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 05:29:51 -0800 (PST) Date: Wed, 29 Jan 2020 14:29:50 +0100 From: Michal Hocko To: Qian Cai Cc: akpm@linux-foundation.org, penguin-kernel@i-love.sakura.ne.jp, hannes@cmpxchg.org, elver@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, syzbot+f36cfe60b1006a94f9dc@syzkaller.appspotmail.com Subject: Re: [PATCH -next] mm/page_counter: annotate an intentional data race Message-ID: <20200129132950.GL24244@dhcp22.suse.cz> References: <20200129131242.4329-1-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200129131242.4329-1-cai@lca.pw> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michal Hocko > --- > 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