From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22A1BC2D0B1 for ; Thu, 6 Feb 2020 03:57:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D190920661 for ; Thu, 6 Feb 2020 03:57:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=lca.pw header.i=@lca.pw header.b="qZj/hBcH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D190920661 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lca.pw Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6E9AD6B0003; Wed, 5 Feb 2020 22:57:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 69CA96B0006; Wed, 5 Feb 2020 22:57:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58A276B0007; Wed, 5 Feb 2020 22:57:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 41ADB6B0003 for ; Wed, 5 Feb 2020 22:57:28 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E86648248047 for ; Thu, 6 Feb 2020 03:57:27 +0000 (UTC) X-FDA: 76458342534.25.hate36_412383990bb11 X-HE-Tag: hate36_412383990bb11 X-Filterd-Recvd-Size: 4937 Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Feb 2020 03:57:27 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id c5so3472922qtj.6 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=MPO7Pw1X0KC4ZtGKfpAdDh/emR0OLIM8gv3FwYU4/HbD3yFZERctHdihbkdhHeekSS 9yOfKtuXlvyKplLoEi2RJJVU/ICI5VcwqfUI4segZ176JQJK8GlPFKJwv86LOv9j7Ykx b812qoEj/4Ms4uR0u1o+nnsbuG6xZ5qDZF8ceMxayp6zAzi7eJNmy8qaPX1fuYrN5ED0 1AFAPXLuQSO58QKG4UGehHWvBshvDCQuyftoLVBDcSwR1OwsEHG5v3XG3cC/cDhkId96 TWEGe130nqs3Yq7wmR/OrWXfM82e46wxqfnrp7ertZa34s8Eh36LNVjjbqfLsIcftnBD Jeeg== X-Gm-Message-State: APjAAAXsxZ/+sDZu09NA4mRUe9HC+Tj4RVWK2RUisysF1gw1vhOg1726 0VrYsWOLjHC937KuL17awOV+eA== X-Google-Smtp-Source: APXvYqxX2KBwvRMGi4GbDdPvkhD/vtXv0C6Yr0n5rcNCNWMyAEjX/JOzWnup5AhhrzNCzv0UdKROGw== 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: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000957, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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-2020020= 4+ #6 Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 0= 7/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; } =20 - if (sis->flags & SWP_FS) { + if (data_race(sis->flags & SWP_FS)) { struct file *swap_file =3D sis->swap_file; struct address_space *mapping =3D swap_file->f_mapping; =20 --=20 2.21.0 (Apple Git-122.2)