Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4322559ybv; Tue, 25 Feb 2020 17:48:43 -0800 (PST) X-Google-Smtp-Source: APXvYqwb2KQ/0b//Rfqk3+Kbl+kWvwzL+E04pEDOaz2QMxigb/CmHkx72GlxCdGSXheqlsxXL6+t X-Received: by 2002:a05:6808:3ae:: with SMTP id n14mr1360172oie.63.1582681723003; Tue, 25 Feb 2020 17:48:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582681722; cv=none; d=google.com; s=arc-20160816; b=Yf1Y3XPDu8rfZLw6BSNE3mYXd8O2EoRoFyLn34eA/IHbsLjWmWrK59nK0HtFm2spiL /kabMsizmlA+C+c5Mx7I2AyR3WHeXSlyCWFfKtRK4pYA3n3cxSw0l4YaIyydUfkqXQbN LbAXbl5hhBXHVa8saFz0Uv67ZL6lQK8jKcXAH4WLLXN9CLaF6llT5w4WvUrbg9ylT5Lm iRnyE3MYvw8Ku0rMZ8vOSEpx5bA1fFHzVcrKJ2MAT+wlFiNyfNV01z/bXIc9FEjYqKRJ 46Zeb2MxNJ8Njuor7W7N6dHwDokjpvWHoGwu8/N6A+2TbDJ21bQTmZoCaEUmOwCoKxRU Hpxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=i+uuXL4ROSQrRMXJx8YzNpaMLWaT0zkBrSK5utVMd+4=; b=ZR6FDWoExJ6r1Zr0IsnhU0vZLrz3zH5QLOfRd0W0n0xAfUYl6OGJKt1+q6oilZjKvI FUMrU0hKsSoPCcI27FIEVj8DATe/UI9Sf2J07+M6Eoub/7EbUVwbTcz00g5rHvbff1Tl 1fAYXx9F8RlEJMcvXZCADbgC8g6qHnjNvKVYQ0ufMaJZC14lwlXopR9Bj/Kmdv9CqrEU mMkVH5qFLvRIJnlg/C1T4fuBbySUd+p00r9nCUXklAcvj/3/i4/+tXSBCyIKAb8Y9Kuu fk+KeiMSj/4iZ0Sy6ojdt6XWIvheR6XSEtAFM287FEO8pI7o9wZBa2JStoKBY7bax4Ff IlGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=IOjaXzZe; 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 z15si399267oti.126.2020.02.25.17.48.29; Tue, 25 Feb 2020 17:48:42 -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=IOjaXzZe; 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 S1729582AbgBZBsT (ORCPT + 99 others); Tue, 25 Feb 2020 20:48:19 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:38052 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729403AbgBZBsT (ORCPT ); Tue, 25 Feb 2020 20:48:19 -0500 Received: by mail-qk1-f193.google.com with SMTP id z19so1186359qkj.5 for ; Tue, 25 Feb 2020 17:48:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=i+uuXL4ROSQrRMXJx8YzNpaMLWaT0zkBrSK5utVMd+4=; b=IOjaXzZe1BC2Kf4gSBwQNKcZFSNsnH3EsyM+t3Nhcp3RvkIjMByJLbob6MO0u0OJyp F0cNre9pQTozbRAjk+FU6TR7MQ0fvlr31Gl4ITEnzYchcxSgHKZ8acop3YebW97Z1ACP dqFvtrGYi6yD60HVlt0bsSA+Ji/moA0Zyp+sI9ZHieZi/lOrRRwRZx2rO+T/PkZj1R4k 6FPRBa1DdSYiUvZl3Pf0PvL/vAIya/1wy5gUUtGwOAYFQ04l2Ok4joyG62vk9UWBQoLw vSY9yZevZ9szs+od3YMepRRF9IiprTWYLffUgmR6+fA/w2KIa65H39+9ECrGS3OUsoQI 1EXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=i+uuXL4ROSQrRMXJx8YzNpaMLWaT0zkBrSK5utVMd+4=; b=cwOyb7HaFNJ0mJpH5Q1qJLxlS+bQUJ+IVmYeX0TKCQ0aPPidahFyjTJF6Q4B3CmrMm dSwDx4HeAYQW7fLbV+pBwIFQY+rO00pmK/RwikzrTqhkCfS+Sl5hF0oMnmgHZ8q15suo /HVaTSBKgY2NFOa3Fb+B605sp6ZToPKaRyh1zl8ntZz4M8bE0VfeANvBv0Z9mHVxJJRx MFwHJFu4P4jpc6V444oENWS8oAgErZM4b7tF+stm+lU7oayijxYPu017/CTTCaMb2Z2M EdxwE6noVgFPwIJk+nQ1KlLHk6WNmjhidD01DRIEgcf99u98yh1VliWoqn/WXrjpRlm4 7arQ== X-Gm-Message-State: APjAAAUF+yZCT64jN99pDgJsgbx/5noOE2PPU+e+E9mdXNakR+ZrUVk6 ED7U8AEyI7Rpf9T+QsksC6pwFgNA/3WIZQ== X-Received: by 2002:a37:a982:: with SMTP id s124mr2359705qke.496.1582681696856; Tue, 25 Feb 2020 17:48:16 -0800 (PST) Received: from [192.168.1.153] (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id o17sm245069qtj.80.2020.02.25.17.48.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Feb 2020 17:48:16 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: [PATCH] mm/vmscan: fix data races at kswapd_classzone_idx From: Qian Cai In-Reply-To: <20200226012952.GV24185@bombadil.infradead.org> Date: Tue, 25 Feb 2020 20:48:14 -0500 Cc: Andrew Morton , elver@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <984ADA76-837B-4B07-88C5-0D82FE8FA9A5@lca.pw> References: <1582649726-15474-1-git-send-email-cai@lca.pw> <20200226012952.GV24185@bombadil.infradead.org> To: Matthew Wilcox X-Mailer: Apple Mail (2.3608.60.0.2.5) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Feb 25, 2020, at 8:29 PM, Matthew Wilcox = wrote: >=20 > On Tue, Feb 25, 2020 at 11:55:26AM -0500, Qian Cai wrote: >> - if (pgdat->kswapd_classzone_idx =3D=3D MAX_NR_ZONES) >> - pgdat->kswapd_classzone_idx =3D classzone_idx; >> - else >> - pgdat->kswapd_classzone_idx =3D = max(pgdat->kswapd_classzone_idx, >> - classzone_idx); >> + if (READ_ONCE(pgdat->kswapd_classzone_idx) =3D=3D MAX_NR_ZONES = || >> + READ_ONCE(pgdat->kswapd_classzone_idx) < classzone_idx) >> + WRITE_ONCE(pgdat->kswapd_classzone_idx, classzone_idx); >> + >> pgdat->kswapd_order =3D max(pgdat->kswapd_order, order); >=20 > Doesn't this line have the exact same problem you're "solving" above? Good catch. I missed that. >=20 > Also, why would you do this crazy "f(READ_ONCE(x)) || g(READ_ONCE(x))? > Surely you should be stashing READ_ONCE(x) into a local variable? Not a bad idea. >=20 > And there are a _lot_ of places which access kswapd_classzone_idx > without a lock. Are you sure this patch is sufficient? I am not sure, but KCSAN did not complain about other places after = running extended period of testing, so I will look into once other places show up later.