From patchwork Thu Feb 13 16:49:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qian Cai X-Patchwork-Id: 11380815 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 156351395 for ; Thu, 13 Feb 2020 16:49:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD78B24676 for ; Thu, 13 Feb 2020 16:49:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lca.pw header.i=@lca.pw header.b="Mbo6mH13" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD78B24676 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 0C1946B0573; Thu, 13 Feb 2020 11:49:56 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 04B4C6B0575; Thu, 13 Feb 2020 11:49:56 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E55376B0576; Thu, 13 Feb 2020 11:49:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id C91BC6B0573 for ; Thu, 13 Feb 2020 11:49:55 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 72779824556B for ; Thu, 13 Feb 2020 16:49:55 +0000 (UTC) X-FDA: 76485690750.20.can26_5692c8eef5040 X-Spam-Summary: 2,0,0,ab4aa1953c92030d,d41d8cd98f00b204,cai@lca.pw,:akpm@linux-foundation.org:elver@google.com::linux-kernel@vger.kernel.org:cai@lca.pw,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1345:1437:1535:1543:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2904:2918:3138:3139:3140:3141:3142:3354:3865:3866:3867:3870:3871:3872:4117:4321:4385:4605:5007:6261:6653:7903:7904:8784:8957:9163:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12740:12895:12986:13161:13208:13229:14018:14096:14104:14181:14394:14721:21067:21080:21444:21627:21990:30029:30054:30056:30070,0,RBL:209.85.222.193:@lca.pw:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:30,LUA_SUMMARY:none X-HE-Tag: can26_5692c8eef5040 X-Filterd-Recvd-Size: 6183 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Thu, 13 Feb 2020 16:49:54 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id w15so6306925qkf.6 for ; Thu, 13 Feb 2020 08:49:54 -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; bh=p0Q6hlzmT378e7z6l0VbudwtzHddZYb7fL48aFnyhQI=; b=Mbo6mH13hg4FUj125LjT49IpZfh5Dx6Clki2I0o1qK/+D9ig3+4zc4sKXV2vv6btj1 pILY/jvB9oMw042WivFSkyFuyi002K8QSBH8g7G5IYFhAeRkVFqn4K1IxSugQwloaDiE TDwi8Jm9mCp6b++s7AaBiVU12pFuzpog9T2YHNzfVJeBQTTkm39VSxXqyut0s1Y1Jdo1 RlYsOsvKmX+0OVACh5XYikOuQdz9FfQZVWicqP2kHfh6vFuInHRIS1t+w1i+0/49PlJi d6JQD+q5uRtv8xcQ76t3KY3p8jzI1MN9Jg3yG2tmFzjK0YabGL1iKjtmb+6KPqNTTJd9 bMPQ== 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; bh=p0Q6hlzmT378e7z6l0VbudwtzHddZYb7fL48aFnyhQI=; b=YyffFQcLaVrIuKDPM3HgJG031ecqYVN1tEz46Q9USD1rWpqVwwBTDy5VrUTrHyEvYZ tJaApD8ASWT5hccLaxmEHdw3VZzQIaPdx3jMPAkCzpEh8S2NJWkWHb0/UNvrzrnadYXP Obt3fJ3sdRY6b/ynsNKDpgQ0OR2MHqOMrjPEd7U2uk0SWagGOoyEbyBLuPWYb6xwhuAv aBrEGtikd9NoyhHVbaK+6jmY6uS3HQmpSDzMFFGDH6zajh54XADdi9p8cNADrc5AOFFx Wga7esNhzyUdRpALADVs2tDZRe45ag5D45fxD1CRE1hzVj9lMEQ3rS9EjRzNMHjXuc5K ga8Q== X-Gm-Message-State: APjAAAUtUcUHmVx4gWc2l6bZxwkvahgwuLEMoAxE/j4GnSGe7bs5y0FX d4kKp8qDjOSQwJ1+avOBi6ez5g== X-Google-Smtp-Source: APXvYqxToB0ZdUztLY2jCfM16G2vL2IzQ177XzC8UoL9bZJGCZ2p2bepzb7wDW94brCIeWaQ+NUXQA== X-Received: by 2002:a37:a116:: with SMTP id k22mr16169504qke.340.1581612594173; Thu, 13 Feb 2020 08:49:54 -0800 (PST) Received: from qcai.nay.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id c45sm1785126qtd.43.2020.02.13.08.49.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Feb 2020 08:49:53 -0800 (PST) From: Qian Cai To: akpm@linux-foundation.org Cc: elver@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next v2] mm/page_io: mark various intentional data races Date: Thu, 13 Feb 2020 11:49:45 -0500 Message-Id: <1581612585-5812-1-git-send-email-cai@lca.pw> X-Mailer: git-send-email 1.8.3.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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-20200204+ #6 Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 07/10/2019 Other reads, read to 0xffff91ea33eac400 of 8 bytes by task 11276 on cpu 120: __swap_writepage+0x140/0xc20 __swap_writepage at mm/page_io.c:289 read to 0xffff91ea33eac400 of 8 bytes by task 11264 on cpu 16: swap_set_page_dirty+0x44/0x1f4 swap_set_page_dirty at mm/page_io.c:442 read to 0xffff9095cbaa8400 of 8 bytes by interrupt on cpu 72: swap_slot_free_notify+0x121/0x2e0 swap_slot_free_notify at mm/page_io.c:89 The write is under &si->lock, but the reads are done as lockless. Since the reads only check for a specific bit in the flag, it is harmless even if a data race happens. Thus, just mark them as intentional data races using the data_race() macro. Signed-off-by: Qian Cai --- v2: add a missing annotation. mm/page_io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 76965be1d40e..26935db0676c 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -86,7 +86,7 @@ static void swap_slot_free_notify(struct page *page) return; sis = page_swap_info(page); - if (!(sis->flags & SWP_BLKDEV)) + if (data_race(!(sis->flags & SWP_BLKDEV))) return; /* @@ -286,7 +286,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, struct swap_info_struct *sis = page_swap_info(page); VM_BUG_ON_PAGE(!PageSwapCache(page), page); - if (sis->flags & SWP_FS) { + if (data_race(sis->flags & SWP_FS)) { struct kiocb kiocb; struct file *swap_file = sis->swap_file; struct address_space *mapping = swap_file->f_mapping; @@ -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; @@ -439,7 +439,7 @@ int swap_set_page_dirty(struct page *page) { struct swap_info_struct *sis = page_swap_info(page); - if (sis->flags & SWP_FS) { + if (data_race(sis->flags & SWP_FS)) { struct address_space *mapping = sis->swap_file->f_mapping; VM_BUG_ON_PAGE(!PageSwapCache(page), page);