From patchwork Thu Feb 6 18:30:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qian Cai X-Patchwork-Id: 11369021 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 42713924 for ; Thu, 6 Feb 2020 18:30:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0E2EC21775 for ; Thu, 6 Feb 2020 18:30:21 +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="Y9elrmdX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E2EC21775 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 3706C6B0005; Thu, 6 Feb 2020 13:30:20 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 321B66B0006; Thu, 6 Feb 2020 13:30:20 -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 20F5B6B0007; Thu, 6 Feb 2020 13:30:20 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 088006B0005 for ; Thu, 6 Feb 2020 13:30:20 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A28371EF3 for ; Thu, 6 Feb 2020 18:30:19 +0000 (UTC) X-FDA: 76460542158.29.sort32_772855cb0314f X-Spam-Summary: 2,0,0,f4fc6f255dbc2730,d41d8cd98f00b204,cai@lca.pw,,RULES_HIT:41:355:379:421:541:800:960:967:973:988:989:1260:1311:1314:1345:1437:1515:1535:1542:1711:1730:1747:1777:1792:2198:2199:2393:2525:2559:2563:2682:2685:2859:2895:2918:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6238:6261:6653:7903:7904:8784:8957:9025:9036:9163:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12740:12895:12986:13870:13894:14018:14096:14181:14394:14721:21080:21444:21451:21627:21990:30029:30054:30056:30065:30070,0,RBL:209.85.219.68:@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:278,LUA_SUMMARY:none X-HE-Tag: sort32_772855cb0314f X-Filterd-Recvd-Size: 5505 Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Feb 2020 18:30:18 +0000 (UTC) Received: by mail-qv1-f68.google.com with SMTP id z3so3341167qvn.0 for ; Thu, 06 Feb 2020 10:30:18 -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=JL75aBY+rZk3H0gime7n0VDi14qO+XDQsjQrhb4dCCU=; b=Y9elrmdXu1s9jb4qNTQQZUlZo0MoZAxDXVkEZWGy5Apy1XGOSW9zfqDQo3nVJbY5fC YCMWsAm4hhcP6dc0XH9FWLY/AkzQRA7nzkNeIDEy6D9oa/pZVm7K6CGiitTsGu3NdOHG m67nOhGjy+AgB1kxy+8BFcq3maoPJuImfvyNbWQW3PmEv3O3D8bavTKDdnAvb6fj/Ks8 eQgr6QblA/2YHlNn4V8WHhDdLThemHXeWmAms7F3a3TkmRdKS4BmdsC4PVMyyPOBfqDG YZUGHVwc0kH96ooz/AAA1b0yYmdmTog2EuBPMr76Aj9nrXCad4LF+Da7xt0L8lfPHC6e hmxg== 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=JL75aBY+rZk3H0gime7n0VDi14qO+XDQsjQrhb4dCCU=; b=nVPcdm5TcW4vhp0NeVTH5ox4HMpGHe3GqOBXe3epZXUYpM6VI7ZGP9U3hcmzIByDa9 kUI2sJ8jkbqDac5H81Vjjtb1UDyy4efl8/cl4mBrq60dDL5ix5o2uTmV52+ty5c3IvNY IsXJ2FwkYpltvZWvhMTCSNzbaY9Gd2QW4+uXHAT1YMpiYrBD70cUkttZaTd++o44bZL/ 1gHTuvdpxnuUGsMQsLKFIaRSIZdm+QR9rFyF236ixzFTyczzBZ4WQxhzbqV03lTr9dDn xb2eW51Fl8g11EAyRkBSuKT+Aom2gQd+b/hVGM9lrPPTxRKevi6A07079kv84/9erMFq Byew== X-Gm-Message-State: APjAAAUXwgEhM2vjELComwBlhl2jTnkY2GzHuPU6VVqD6sW5QIAkhG2g d9AN6WsW3MbtP++poVPq+NOhzw== X-Google-Smtp-Source: APXvYqw0/Xgpcw3i5p54MgfadehdUhtQtZo43pmPlIku1IX9sHJPd9raCVM06PrDzr6VJDwPEzShbQ== X-Received: by 2002:ad4:57c7:: with SMTP id y7mr3407811qvx.174.1581013818171; Thu, 06 Feb 2020 10:30:18 -0800 (PST) Received: from Qians-MBP.fios-router (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id f17sm55169qtq.19.2020.02.06.10.30.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Feb 2020 10:30:17 -0800 (PST) From: Qian Cai To: akpm@linux-foundation.org Cc: elver@google.com, jhubbard@nvidia.com, ira.weiny@intel.com, dan.j.williams@intel.com, jack@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next v2] mm: mark an intentional data race in page_zonenum Date: Thu, 6 Feb 2020 13:30:00 -0500 Message-Id: <20200206183000.913-1-cai@lca.pw> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: page->flags could be accessed concurrently as noticied by KCSAN, BUG: KCSAN: data-race in page_cpupid_xchg_last / put_page write (marked) to 0xfffffc0d48ec1a00 of 8 bytes by task 91442 on cpu 3: page_cpupid_xchg_last+0x51/0x80 page_cpupid_xchg_last at mm/mmzone.c:109 (discriminator 11) wp_page_reuse+0x3e/0xc0 wp_page_reuse at mm/memory.c:2453 do_wp_page+0x472/0x7b0 do_wp_page at mm/memory.c:2798 __handle_mm_fault+0xcb0/0xd00 handle_pte_fault at mm/memory.c:4049 (inlined by) __handle_mm_fault at mm/memory.c:4163 handle_mm_fault+0xfc/0x2f0 handle_mm_fault at mm/memory.c:4200 do_page_fault+0x263/0x6f9 do_user_addr_fault at arch/x86/mm/fault.c:1465 (inlined by) do_page_fault at arch/x86/mm/fault.c:1539 page_fault+0x34/0x40 read to 0xfffffc0d48ec1a00 of 8 bytes by task 94817 on cpu 69: put_page+0x15a/0x1f0 page_zonenum at include/linux/mm.h:923 (inlined by) is_zone_device_page at include/linux/mm.h:929 (inlined by) page_is_devmap_managed at include/linux/mm.h:948 (inlined by) put_page at include/linux/mm.h:1023 wp_page_copy+0x571/0x930 wp_page_copy at mm/memory.c:2615 do_wp_page+0x107/0x7b0 __handle_mm_fault+0xcb0/0xd00 handle_mm_fault+0xfc/0x2f0 do_page_fault+0x263/0x6f9 page_fault+0x34/0x40 Reported by Kernel Concurrency Sanitizer on: CPU: 69 PID: 94817 Comm: systemd-udevd 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 only with the non-exclusive mmap_sem held. Since the read only check for a specific bit range (up to 3 bits) in the flag but the write here never change those 3 bits, so load tearing would be harmless here. Thus, just mark it as an intentional data races using the data_race() macro which is designed for those situations [1]. [1] https://lore.kernel.org/linux-fsdevel/CAHk-=wg5CkOEF8DTez1Qu0XTEFw_oHhxN98bDnFqbY7HL5AB2g@mail.gmail.com/ Signed-off-by: Qian Cai --- v2: update the commit log. include/linux/mm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 52269e56c514..cafccad584c2 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -920,7 +920,7 @@ vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf); static inline enum zone_type page_zonenum(const struct page *page) { - return (page->flags >> ZONES_PGSHIFT) & ZONES_MASK; + return data_race((page->flags >> ZONES_PGSHIFT) & ZONES_MASK); } #ifdef CONFIG_ZONE_DEVICE