Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1047569ybv; Wed, 5 Feb 2020 19:59:09 -0800 (PST) X-Google-Smtp-Source: APXvYqzI+0sZdTZoZ0Dn249CQNtrVRI7nJkfDlv10vDwxz0WZsngWXqaR/Hosy8jgO9hmFAUoywE X-Received: by 2002:a9d:63d6:: with SMTP id e22mr28802492otl.72.1580961549054; Wed, 05 Feb 2020 19:59:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580961549; cv=none; d=google.com; s=arc-20160816; b=Vn/ZtdsAoequOA72+4YrFcnmr+9CagmfM1tkYWsVP2g8NPiy/sRvv2CPe+VGhm3Uq0 jSCwNP6X+dBuirYz+N4GRpOO6MTB7vnqIaD6T4LSrEVGZ7WXchJ/VhxLK3VJeYZBP36g hbogM+leKBrIJ4QkR4n2Ana2I9VexXYD66176r7P577hsaVZ69aQ4k8hl8PNO4Aa21fJ ajU4bNRQyBRx0Oil7AD4XKFCa4syb287tRrDCb4WncwsdyX2i+Cc2CI1LXI0fh8BIOo3 4wleD54VbZhpTjl+fg/Vlw35vzUkYL/FMjOJPfsTJZzu38Q6mhQHZsBFzw+LULEvBpq4 ivcQ== 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=10h8LQaszZB8kto067/5O+pOylX9gdI2ZGKY//hP60E=; b=p4ma/yC7n7BvFRpqj8j9AU3sbxY9+EzWjDZ6yf8TfSLGHDJUmxvjkcJMwM/QOjjSGp 6zSLKZ9DlksU44Lz9YCfXI7iJqjcup/texnPBa0T8V9ZWVKpNaXoh1rtyLTEZWq5nir9 ReoWRFJhLP2YXoV2848jwfvz6HLpzkhVcadWGy49dH+3b43EAH6WnaRMechASY0DG+B9 Kk5whm7u0Wgo/VS/Rbm72ONRMfR8E2u0YDtEDBx1ctUCqh/j9prZJDUbfYlSpe794HnH 2oZAqnacDjf/8OxfPgu/MMTPaEA4v+e86Vui+2Ju9WaMBT+BopnnvWvoroFctZqRwNip WCOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b="qZj/hBcH"; 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.58.56; Wed, 05 Feb 2020 19:59: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="qZj/hBcH"; 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 S1727675AbgBFD52 (ORCPT + 99 others); Wed, 5 Feb 2020 22:57:28 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:40520 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726687AbgBFD52 (ORCPT ); Wed, 5 Feb 2020 22:57:28 -0500 Received: by mail-qt1-f194.google.com with SMTP id v25so3466014qto.7 for ; Wed, 05 Feb 2020 19:57:27 -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=10h8LQaszZB8kto067/5O+pOylX9gdI2ZGKY//hP60E=; b=qZj/hBcH6OWOuaGct5p6Y2Notbh9zBt7vVs3FVwzP3j+2Z9bLfgWmQCKCYwR4BbAiv dLIux0vXieJvfkWXeys8zi32OPYVJAXGljHpxuh4N+scc8wKvUuskr/s6VcXor+JZIUw 7RvIgKfFpUyaU2wY0cWk4dEwGwp9u8I5p9bbLT5Ls4Jug/b+WRfWSWqBECtBrjTW4E10 GoenGwm3uEUiYdCDfrehN6OXEeSUg0TJPEFf7g4foLx263gBdWQvDFjPpIKB4MbL63NX k3kHyTs5aG2tpFR8/oNkvsqGTHjuazMAAoRFXSdgS0CX3cOvFAPRRG72qLGHTfICnA7q 4TmA== 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=10h8LQaszZB8kto067/5O+pOylX9gdI2ZGKY//hP60E=; b=mWaSOgz5KnsjPRsVFF8KP0HgYMryefNDbr+fo5qCJCe2Fp3NFQ42Pf8slkraw46Nt5 EcQdR+7QH2EFME1EkJhi45G7x5/hSkO+urfMjltfDV7vqYZuS89Y19y39Vci8pYopzUi EZ24EFhKCmGo+Tt0tBmUw2Qw/WQYyoskfTIbbYVHDLngtBwrdf4j1hGxRQiwSax/uvkx zkcXQDfe8XXhqMghTmYqrvgh2co0JPL7J/ptyHnLITMCM+I16vmqKWf1M9PLusB+wcAf Usla7yfdrRzSmAgZUYIlY8V+/41ZSGdf1XixbRHRB773LUjD+110cnZ9zHQsgX/qIPwe fLiA== X-Gm-Message-State: APjAAAWfQX4xuj8m//LF1WGYN0gaNPM1u0SEmM+WHgmN/ng2gHO0/2+T 3OFZqm7FVMwhnjR2ezyzv2MeFQ== X-Received: by 2002:aed:2510:: with SMTP id v16mr963492qtc.306.1580961447045; Wed, 05 Feb 2020 19:57:27 -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 i13sm837545qkk.78.2020.02.05.19.57.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Feb 2020 19:57:26 -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/page_io: mark an intentional data race Date: Wed, 5 Feb 2020 22:56:54 -0500 Message-Id: <20200206035654.2647-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 struct swap_info_struct si.flags could be accessed concurrently as noticed by KCSAN, BUG: KCSAN: data-race in scan_swap_map_slots / swap_readpage write to 0xffff9c77b80ac400 of 8 bytes by task 91325 on cpu 16: scan_swap_map_slots+0x6fe/0xb50 scan_swap_map_slots at mm/swapfile.c:887 get_swap_pages+0x39d/0x5c0 get_swap_page+0x377/0x524 add_to_swap+0xe4/0x1c0 shrink_page_list+0x1740/0x2820 shrink_inactive_list+0x316/0x8b0 shrink_lruvec+0x8dc/0x1380 shrink_node+0x317/0xd80 do_try_to_free_pages+0x1f7/0xa10 try_to_free_pages+0x26c/0x5e0 __alloc_pages_slowpath+0x458/0x1290 __alloc_pages_nodemask+0x3bb/0x450 alloc_pages_vma+0x8a/0x2c0 do_anonymous_page+0x170/0x700 __handle_mm_fault+0xc9f/0xd00 handle_mm_fault+0xfc/0x2f0 do_page_fault+0x263/0x6f9 page_fault+0x34/0x40 read to 0xffff9c77b80ac400 of 8 bytes by task 5422 on cpu 7: swap_readpage+0x204/0x6a0 swap_readpage at mm/page_io.c:380 read_swap_cache_async+0xa2/0xb0 swapin_readahead+0x6a0/0x890 do_swap_page+0x465/0xeb0 __handle_mm_fault+0xc7a/0xd00 handle_mm_fault+0xfc/0x2f0 do_page_fault+0x263/0x6f9 page_fault+0x34/0x40 Reported by Kernel Concurrency Sanitizer on: CPU: 7 PID: 5422 Comm: gmain 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 The write is under &si->lock, but the read is done as lockless. Since the read only check for a specific bit in the flag, it is harmless even if load tearing happens. Thus, just mark it as an intentional data race using the data_race() macro. Signed-off-by: Qian Cai --- mm/page_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_io.c b/mm/page_io.c index 76965be1d40e..e33925b9178c 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -377,7 +377,7 @@ int swap_readpage(struct page *page, bool synchronous) goto out; } - if (sis->flags & SWP_FS) { + if (data_race(sis->flags & SWP_FS)) { struct file *swap_file = sis->swap_file; struct address_space *mapping = swap_file->f_mapping; -- 2.21.0 (Apple Git-122.2)