Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1046916ybv; Wed, 5 Feb 2020 19:58:09 -0800 (PST) X-Google-Smtp-Source: APXvYqwPea9I9EtEmELCVpd8HnBtzTCwQIh1sE7iKnv0+waQya9Rfb0rnLfer4fXz04wcReI5nWh X-Received: by 2002:a05:6830:2102:: with SMTP id i2mr28463122otc.123.1580961489232; Wed, 05 Feb 2020 19:58:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580961489; cv=none; d=google.com; s=arc-20160816; b=I3Nx+8iM4YrhlpEWjh74ZhmkKx3+nF2ojP0zyUX4mbKvbnvTVFSMLK8holo/dUyoHB jp8uuMAUEyKsHb8/3A8ldwkD/noOTEE4yDzktkbaITHhSpbZXuRIqZ7MM/h5H4OCqdeJ TNlEoT0S7k73Ctf76yIyOs5idEvz4VWZTprZoBAYmNjdVN9QqK34NEbYe+RZG01hB/EL QP0WdKsqJvr5/wdjlRbkcu05+PxInZdoeokEqumBRaFjAj7orMIUmO6HKhkzvA10yX+7 DSsc6EvjQ+SSukHCCdG8qu59fwwTV0Bf1NS//QOo0hDINPz+zechTqMYgxeUCVaGjk9x U9uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=OzLzAKpVYvs92/D3iPQiHFL/UjwHdH2pu9eS92fC1ys=; b=fzDziAP18XdfQUEtzBzTtLuIlr4gpev7OoVA5O85LBDanzEh0HENIWMQeqBVIVbnoU kG3zye5biK1BxkLMC7S4yZW4CFOe6DBmY4FPKZkw1pMSDnNrkVcOmxJbfyrjUFY1KWpk rrgeKZq6g6RCXuGgmG7LeDIzOkIC7CbV8eA1fK+rBYpN3uosnpJjmgSRGO+dZgEjGTWn /mE5FuXBQg9e1X9lJY3yGR4FAkhGLHf/U1QJiH2cEPJXf3SzN28tQigdWvG4/OQKx61U ETQxoVREtnRv0UVnly6IJN88F+EraiAnKUyxayjYb4p1FpyalVpt3sT/C04dn/x481bI yILQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=kAyoMBvW; 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 s128si1369072oig.204.2020.02.05.19.57.56; Wed, 05 Feb 2020 19:58:09 -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=kAyoMBvW; 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 S1727698AbgBFDz3 (ORCPT + 99 others); Wed, 5 Feb 2020 22:55:29 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:35872 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbgBFDz3 (ORCPT ); Wed, 5 Feb 2020 22:55:29 -0500 Received: by mail-qt1-f193.google.com with SMTP id t13so3485401qto.3 for ; Wed, 05 Feb 2020 19:55:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OzLzAKpVYvs92/D3iPQiHFL/UjwHdH2pu9eS92fC1ys=; b=kAyoMBvWMTfqSO3rTdtl0FwCYUWk5X+h1kI3inkaU9Sggqx0Ixe6G8oXAz0KMgChcj CyonJNS9OBKiWuhLEfa7ROeeLTPGUD4FSFGyxrlkNVb/AZhq80yeQISV8ShE4prW73mC 2eMu581c0PmXYblIF88ZmSaXdfxet1ZK8Z5VnI7tBxDiJtC5P7l3HVo2OtEqxfWVMsGq EAD272Xv8rh+48YKzRwzAWLcreYy1/6+LOKKBDx7vcnxxTIMSSbC+v8LWVVfuIdH3mTZ kTMnOW+U2XK92MEReaJvXtX5lge2qE+w2PE0Q5Xw0DvxeuAbAzuF7lok7ag3O7KjKZUX 30zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OzLzAKpVYvs92/D3iPQiHFL/UjwHdH2pu9eS92fC1ys=; b=FuwKfyRMNtMCnld6hY/pCEt5mT46NOogIOOS1oc748JywHcIBrnSceHEwKsU0EMdOs M4gCfto+pVy5Ozeh4ZTub1c4ZXLChcZDTTSpXzZ59JAkp5zLdApj0CbxLdU4zrz4CBP8 SiACnuehfRXVEMWIAvpLBQyviNoa5CgVho3aUU/6KV1k0xxxvrw/hYUIVWNWFjheozss HEGCg6NWAwMTEbaC4k7KyUCXYx8+MIVSUlNGzXDEVAM6EwCIG0cGS1UvQzDlf+Ben/Pq kZzrsGVLgaMMeCND9u7Pm7RG+kxLh9r2HPE2q8qplun7bhH3EIS2XZV3uOrgmbzh+FgL mrDw== X-Gm-Message-State: APjAAAXMZDHjfChXCRTnZ3Uu8imYZlHT0uyF1KoKPyX9RsqyUYBf+upJ HEhVzVYNt/X1s8mpvqRWzi7J7HRReAF18A== X-Received: by 2002:aed:3f77:: with SMTP id q52mr951873qtf.248.1580961321687; Wed, 05 Feb 2020 19:55:21 -0800 (PST) Received: from ovpn-120-236.rdu2.redhat.com (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id p19sm1024733qte.81.2020.02.05.19.55.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Feb 2020 19:55:21 -0800 (PST) From: Qian Cai To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next] mm/swap_state: mark an intentional data race Date: Wed, 5 Feb 2020 22:55:16 -0500 Message-Id: <20200206035516.2593-1-cai@lca.pw> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org swap_cache_info.find_total could be accessed concurrently as noticed by KCSAN, BUG: KCSAN: data-race in lookup_swap_cache / lookup_swap_cache 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 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 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 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. While at it, fix a checkpatch.pl warning, WARNING: Single statement macros should not use a do {} while (0) loop Signed-off-by: Qian Cai --- mm/swap_state.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 = true; #define GET_SWAP_RA_VAL(vma) \ (atomic_long_read(&(vma)->swap_readahead_info) ? : 4) -#define INC_CACHE_INFO(x) do { swap_cache_info.x++; } while (0) -#define ADD_CACHE_INFO(x, nr) do { swap_cache_info.x += (nr); } while (0) +#define INC_CACHE_INFO(x) data_race(swap_cache_info.x++) +#define ADD_CACHE_INFO(x, nr) (swap_cache_info.x += (nr)) static struct { unsigned long add_total; -- 2.21.0 (Apple Git-122.2)