Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1933170ybv; Thu, 6 Feb 2020 12:32:56 -0800 (PST) X-Google-Smtp-Source: APXvYqwyDybJIa7FvmFMS0O9lWY3r6obSN/sDZWTcG8ryc+GbgOvsOPtIxHPLMcXDe5+rWeVvLNx X-Received: by 2002:a54:4f04:: with SMTP id e4mr7759470oiy.111.1581021176109; Thu, 06 Feb 2020 12:32:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581021176; cv=none; d=google.com; s=arc-20160816; b=k1PtFbE83b9ZolcnmQalmdV7GexHBQVyVTgm/PSbqeeKkIfwLPJOv7dPFA4s1EXOR0 fi7EbchxsLGGHBfTEERuKcLVNmppIr75gEHN8UU2tKXgM8QVyRzOD0AzlnZ9wMOIS2SW XpxLcaZSYv0feIOz8lA2SqpDKrhKt4Yj8uIau8RhRpzQX3dBl6vDYii9rtKqAsp8YZec sZQ4Vkg1i9GBqYUNj1v+5c4A1VgkFP77RbrHFc6+5BI4HJNWP2ySb6wrvB2Ya+xDxk6T xKHIOEixMTq+BkgUBj4Pp2IFEhFo7VIfvEN+icKlolTZS+sGkgPx1MDWNtpM5d7FAUd0 dv2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=3hepVKSvwAH2BCEpeqSROxuiNRdF8yu9qLYhzLxF5X0=; b=1EXZ+5EyGCy70f/nuyuEPLkIsHYMZNpoLZ9jqVL+Ay33RSu3hAK9BaRhiYN3mCyS5M wrTgrDNH/6XIU8wq2HJE9Zxhv0uAuw/99GDvhqOrXiS7a0/LrAZKiSI+FKoqeGJkDQiH DmOk9hnjf/5zdheHaHo/fIDGaz3Vv5OEOfx8Rsf6FRiq9pgvK6CskImzzmGIXhDP8bNp v8hUGi7lod/A7pnvsx6ZW1pzYrW/ODrLeyFXdPIjM2r4dtQv8bZbnZ40hx9mgNTiA+wu TPBGt6bLmQyGV/zx9VgfBMTc6g6KutMP14kwmsxKHl/8KiCoSq+rozXNIj7D42w4785f AeVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=mCUQ5rJx; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q126si2832921oia.8.2020.02.06.12.32.42; Thu, 06 Feb 2020 12:32:56 -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; dkim=pass header.i=@lca.pw header.s=google header.b=mCUQ5rJx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727851AbgBFUbl (ORCPT + 99 others); Thu, 6 Feb 2020 15:31:41 -0500 Received: from mail-qv1-f67.google.com ([209.85.219.67]:46793 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727698AbgBFUbk (ORCPT ); Thu, 6 Feb 2020 15:31:40 -0500 Received: by mail-qv1-f67.google.com with SMTP id y2so3481999qvu.13 for ; Thu, 06 Feb 2020 12:31:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=3hepVKSvwAH2BCEpeqSROxuiNRdF8yu9qLYhzLxF5X0=; b=mCUQ5rJxLZCg5QMWr6ZxXRplaT+23zazAIVOwZhHUYjIEMMmMhpgHApJx6nsUwaKFa dRf8/7xUI59q+iT3yH+SdQU/MWDG0Lb9rOU2AFhfukiIZ/WEsh4492SxbCZyY7ZGvbRI 3liEvywzAFrzOnjycn4el3PKJB4EVkdrXuz44gBulPJDiP+9LjZipnuf4J6MxU/QKk+E WyBWyf9Kc7n/t5O8D0tLyqfhZn69lVSjnUJtnKBemAMnwmj4WW8pakwC8L58pt/JbxQG n0Dl3m7eLoEc4yFrLfOrIj2uRwgtLc68YNoZjWhR/ctviVeRU+dPdM6FI4XMTnX+XGEp mJDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=3hepVKSvwAH2BCEpeqSROxuiNRdF8yu9qLYhzLxF5X0=; b=Sfa8rjvU9mii6QkUJYULQGwMBKpK7/DQZTF8UNAtGt6/Mlv8wz4clCTS2PU5wlwZ96 aB9l1nAsHKk7pnb9mQfwispEIH1R990GoBiSkoqUALVnYHUgpDrcGkshS1xoLEY23kVK lWJfBgUDzRN6FrSUBwt9eiZq6ETCJkbu1u2f6Ypma81j+Fpsp2KYF3/OjPAYr4gpQAyk BKiLdDWBTcfHk1hK1JHhBIWng49Ln+EAp++vjEAV/vtissfZio4Akipxj9asIpSgAauW XDAi7/e/ueJFw/hUT5XRXGi1DMEjy7D7r6QpJcpREo8dfcDhmS9pki3UoC1bJNn93Lmt 5CPQ== X-Gm-Message-State: APjAAAWskJ8v/bIYkCTylVViIoNJx6MoR1Y735HMSMuSYgPvSPKbjjDh NensWZ+sTmjguII6Y7pTsIyyjg== X-Received: by 2002:ad4:5349:: with SMTP id v9mr4060471qvs.177.1581021099930; Thu, 06 Feb 2020 12:31:39 -0800 (PST) Received: from [192.168.1.153] (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id b17sm212383qtr.36.2020.02.06.12.31.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Feb 2020 12:31:39 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: [PATCH -next] mm/swap_state: mark an intentional data race From: Qian Cai In-Reply-To: <20200206035516.2593-1-cai@lca.pw> Date: Thu, 6 Feb 2020 15:31:38 -0500 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <1BD7EB07-8E26-4AE4-8FEF-A05154D3F674@lca.pw> References: <20200206035516.2593-1-cai@lca.pw> To: Andrew Morton X-Mailer: Apple Mail (2.3608.60.0.2.5) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Please disregard this patch. I found more data races in this file, so = will send a new patch to have them at once. > On Feb 5, 2020, at 10:55 PM, Qian Cai wrote: >=20 > swap_cache_info.find_total could be accessed concurrently as noticed = by > KCSAN, >=20 > BUG: KCSAN: data-race in lookup_swap_cache / lookup_swap_cache >=20 > write to 0xffffffff85517318 of 8 bytes by task 94138 on cpu 101: > lookup_swap_cache+0x12e/0x460 > lookup_swap_cache at mm/swap_state.c:322 > do_swap_page+0x112/0xeb0 > __handle_mm_fault+0xc7a/0xd00 > handle_mm_fault+0xfc/0x2f0 > do_page_fault+0x263/0x6f9 > page_fault+0x34/0x40 >=20 > read to 0xffffffff85517318 of 8 bytes by task 91655 on cpu 100: > lookup_swap_cache+0x117/0x460 > lookup_swap_cache at mm/swap_state.c:322 > shmem_swapin_page+0xc7/0x9e0 > shmem_getpage_gfp+0x2ca/0x16c0 > shmem_fault+0xef/0x3c0 > __do_fault+0x9e/0x220 > do_fault+0x4a0/0x920 > __handle_mm_fault+0xc69/0xd00 > handle_mm_fault+0xfc/0x2f0 > do_page_fault+0x263/0x6f9 > page_fault+0x34/0x40 >=20 > Reported by Kernel Concurrency Sanitizer on: > CPU: 100 PID: 91655 Comm: systemd-journal Tainted: G W O L = 5.5.0-next-20200204+ #6 > Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 = 07/10/2019 >=20 > Both the read and write are done as lockless. Since INC_CACHE_INFO() = is > only used for swap_cache_info.find_total and > swap_cache_info.find_success which both are information counters, even > if any of them missed a few incremental due to data races, it will be > harmless, so just mark it as an intentional data race using the > data_race() macro. >=20 > While at it, fix a checkpatch.pl warning, >=20 > WARNING: Single statement macros should not use a do {} while (0) loop >=20 > Signed-off-by: Qian Cai > --- > mm/swap_state.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/mm/swap_state.c b/mm/swap_state.c > index 8e7ce9a9bc5e..b964c1391362 100644 > --- a/mm/swap_state.c > +++ b/mm/swap_state.c > @@ -58,8 +58,8 @@ static bool enable_vma_readahead __read_mostly =3D = true; > #define GET_SWAP_RA_VAL(vma) \ > (atomic_long_read(&(vma)->swap_readahead_info) ? : 4) >=20 > -#define INC_CACHE_INFO(x) do { swap_cache_info.x++; } while (0) > -#define ADD_CACHE_INFO(x, nr) do { swap_cache_info.x +=3D = (nr); } while (0) > +#define INC_CACHE_INFO(x) data_race(swap_cache_info.x++) > +#define ADD_CACHE_INFO(x, nr) (swap_cache_info.x +=3D (nr)) >=20 > static struct { > unsigned long add_total; > --=20 > 2.21.0 (Apple Git-122.2) >=20