Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4948084ybv; Wed, 26 Feb 2020 05:51:19 -0800 (PST) X-Google-Smtp-Source: APXvYqzCUW3gD2U6Ky3b5DQp5+G2n8L6CmoPFwSCsTA6XjmZZ5d4TszLyEoxL6ubzewqkshB0jWq X-Received: by 2002:a9d:7599:: with SMTP id s25mr314281otk.285.1582725079805; Wed, 26 Feb 2020 05:51:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582725079; cv=none; d=google.com; s=arc-20160816; b=jOUWbZ0Btad40EXgi4Yc0EjRVXlMhGzcrtYFlBo2zm0jmcI5TteokQgKBxpWM5ct1I R+1FIDuhe9fF5ofbnCUX+wF1arW6RWEQ3WWm/ib1u2GIj6ljeaf2Cp3ER8ZHXdLcpC+t 0hKp1Qf1C5a3du+44ae+eWCYWlyKHaJ+7mfEL4DWpJ7IIjJ8oQwC+OKFzjbaqqRVMkk/ dPQN68FAjVT5Wok5O7a4cizTSBqhtU+M7EG/rtulZjs454wP9oT/MDh/nPYPrvIJ0c6P J624W422QmOuq/q1CuwaN/13rdhwgYhRsWJec2d3mI3GCgyyRqWKIONsYJU6sunQlQR1 36KA== 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 :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=yWqfStOVOE4upSG3IQV9mFoVvDm1OYcG0f/E2Oz8iac=; b=QB62NfGDDZ4DxDCbeGWmXvJK9aX25jtc26IzutSmiFrutJDltAVtcneBRaq2fUx43r saj+FnLptvwRSNkczCxiFaaj2LM67ctnCr+R/M8oCpwmnEuvi/LxzN2KmXFrR3T5NijT vE6Yx0Dk+3MYKxLOvACOVUuFQWVlEy39fQwKEvRWyz1Yi+rrbjdpgrmRdSLls0Xs7szq S8Hspeix45VIptWXIDzRu36SdHr3z+7yWps913a+yexXqOY8D7r5QKtnbVbaIs+Sq8nV gj0UQMd+DzDWzlxj5+/cdE7Gk8AdvFw3nItOztpOtCOmWPFCK0HONHNLXh+kmjspZoSN tSEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=rOYLBwuy; 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 q65si1200471oic.123.2020.02.26.05.51.07; Wed, 26 Feb 2020 05:51:19 -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=rOYLBwuy; 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 S1726974AbgBZNtf (ORCPT + 99 others); Wed, 26 Feb 2020 08:49:35 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:38269 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726440AbgBZNte (ORCPT ); Wed, 26 Feb 2020 08:49:34 -0500 Received: by mail-qk1-f194.google.com with SMTP id z19so2641578qkj.5 for ; Wed, 26 Feb 2020 05:49:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=yWqfStOVOE4upSG3IQV9mFoVvDm1OYcG0f/E2Oz8iac=; b=rOYLBwuy/fjzuNxUGQ6b//BhL9lHBCg/kbnuC59/WT7EbqyYyZNYhvfUMSTAT8OzFd 0SSuBCRr5Tq9m74HCpK7PJFKzIUktmIdK1BICVFNc7jtIOEPNOX+9SHMU5Uu/z86fYEt iBIjyAWFJ9Zpqm+dH64xkcKQDma9MvNgx/nW7zdtoMga26C66BaOzzqC9YWcLQ7af3ul ROuMdUfYcTZSM8fYtiw2f9ob+C0HL5ZlGLkXvVVCtldqVurWf1+iJCkGzaFczsgwjoe6 VupvlDzJ+m9WBV9TUWMtVJkgotWN6+Q6oQs+npLFlArYuFeWNNUtZOVaEGFu9txcXvKu Xieg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=yWqfStOVOE4upSG3IQV9mFoVvDm1OYcG0f/E2Oz8iac=; b=h3xpvewiiDyXYmnsYG7KgC/wvo6LVFr6dd9S9GzRkiVrJjsYHK51P/akxdvu02py07 d7XKEcCwrajd4oB7IBj06+15twsarBfU8Ao1PUpbzxW/NVGUUHqBuRO0chff+a8j6N82 PPC71agJNERbvCwaOxD1y6motkB+LaGqwLeEhpS3eLuxRRF+daB3HPkPAaL1y0ExFqoX 0prMiKwTjHM5Bq+Sc9uud+K/lXVPicJ99BNQV3kMm/LCtsEG6zEBx/npXL5Yq6O9eLrE o7LD75gpq28x/IpbSHj8I5Mu4Lek4JbJ1DZy3jbe4kDGymhiQtDHBSdRVJyVOzYgKS7o i66g== X-Gm-Message-State: APjAAAXT937n3PRZT1f2XDA2gXrrE4dw39MqKdjtdOfgiC2/7u4wA5Ho kHyKxueqgBpUBBK6hF5sWJOUmA== X-Received: by 2002:a05:620a:1279:: with SMTP id b25mr5653871qkl.385.1582724973567; Wed, 26 Feb 2020 05:49:33 -0800 (PST) Received: from dhcp-41-57.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id 79sm1147768qkf.129.2020.02.26.05.49.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Feb 2020 05:49:32 -0800 (PST) Message-ID: <1582724970.7365.121.camel@lca.pw> Subject: Re: [PATCH v2] mm/vmscan: fix data races at kswapd_classzone_idx From: Qian Cai To: Matthew Wilcox Cc: akpm@linux-foundation.org, elver@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Wed, 26 Feb 2020 08:49:30 -0500 In-Reply-To: <20200226040612.GW24185@bombadil.infradead.org> References: <20200226035827.1285-1-cai@lca.pw> <20200226040612.GW24185@bombadil.infradead.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6 (3.22.6-10.el7) 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 On Tue, 2020-02-25 at 20:06 -0800, Matthew Wilcox wrote: > On Tue, Feb 25, 2020 at 10:58:27PM -0500, Qian Cai wrote: > > pgdat->kswapd_classzone_idx could be accessed concurrently in > > wakeup_kswapd(). Plain writes and reads without any lock protection > > result in data races. Fix them by adding a pair of READ|WRITE_ONCE() as > > well as saving a branch (compilers might well optimize the original code > > in an unintentional way anyway). While at it, also take care of > > pgdat->kswapd_order and non-kswapd threads in allow_direct_reclaim(). > > I don't understand why the usages of kswapd_classzone_idx in kswapd() and > kswapd_try_to_sleep() don't need changing too? kswapd_classzone_idx() > looks safe to me, but I'm prone to missing stupid things that compilers > are allowed to do. Right, I did capture the race this time. I'll post a v3. [  924.803628][ T6299] BUG: KCSAN: data-race in kswapd / wakeup_kswapd  [  924.809949][ T6299]   [  924.812170][ T6299] write to 0xffff90973ffff2dc of 4 bytes by task 820 on cpu 6:  [  924.819630][ T6299]  kswapd+0x27c/0x8d0  [  924.823509][ T6299]  kthread+0x1e0/0x200  [  924.827471][ T6299]  ret_from_fork+0x27/0x50  [  924.831774][ T6299]   [  924.833987][ T6299] read to 0xffff90973ffff2dc of 4 bytes by task 6299 on cpu 0:  [  924.841442][ T6299]  wakeup_kswapd+0xf3/0x450  [  924.845838][ T6299]  wake_all_kswapds+0x59/0xc0  [  924.850409][ T6299]  __alloc_pages_slowpath+0xdcc/0x1290  [  924.855769][ T6299]  __alloc_pages_nodemask+0x3bb/0x450  [  924.861040][ T6299]  alloc_pages_vma+0x8a/0x2c0  [  924.865612][ T6299]  do_anonymous_page+0x170/0x700  [  924.870443][ T6299]  __handle_mm_fault+0xc9f/0xd00  [  924.875276][ T6299]  handle_mm_fault+0xfc/0x2f0  [  924.879849][ T6299]  do_page_fault+0x263/0x6f9  [  924.884334][ T6299]  page_fault+0x34/0x40