Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4309049ybv; Tue, 25 Feb 2020 17:31:28 -0800 (PST) X-Google-Smtp-Source: APXvYqx3CVCqypEAsXwiFPMKBINlhF7JPCosjLZ1ib3wnLbuNNl0t0gN0hEu+scbWBSYORPi65dS X-Received: by 2002:a05:6808:611:: with SMTP id y17mr1260098oih.146.1582680688782; Tue, 25 Feb 2020 17:31:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582680688; cv=none; d=google.com; s=arc-20160816; b=aphfAzvF3UVkHA+OHvPLRLrAAXld2uwuAEY3eMN4AbA/pVJzkBNWafFb6TETgtc+AG ogJNIF1AdXItNf90VKkD8X+n//S+vzsLfjig7AvCYl9A7ZZq9/0qv65KSR8T02istWLO YaCTRxlReGKGIA4c7zThHpux6evuMAhv3fvOBs02+i4WFWwAONIl19Wn6nYZ42XCxA43 M8kEoGGHA7EiR8/kEkqecuQ9mjWSLX4ij65l3yhXQ2YqRAHEe6DgxzKnmr8uEHNMoLmj dRUECiJJK4LPzGwZEBgiqV5+bNtAAFrzoD/46LV+y6ecYr4SNjA3k4WWvV/1Txrf6tLN aVqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=f0M9pTXksi/4gAdPbOMhWiXGju+Jg2ed8su13b9OEus=; b=O4A06bV60Www3WcRZ8c8acKk3Y9Wi0a5Lcorr/EhYac5RosP1ZV0iz22cbtqxF3R0d SwYi2Mjrp7hnsa0GlpIP9YoFnIH4uPzjJy6NQEKEhfBSO2nL1Fdsebgg2Yztz5TH6QUr 3kFhR9YYiQHeCkgnZgaPXbuYgJrvJDip6X6Bp1K/8bR7BQgVl/CTWknUDE59l00OFMl4 a6tEUILvjbwyNk1fpYEZ53Hv2YsQyKb6vPe6GkJBDec4kuX7xQgfOM++vKYpGfsWRefU dreE/7Ru+7ZzFDe1wakhYH2dOZU0Za6yKlH3lbr6OMI19FjOfjmchm4CUoPNj3tBrAAD yk2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=G2lnM6jJ; 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 y12si337026oti.162.2020.02.25.17.31.16; Tue, 25 Feb 2020 17:31:28 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=G2lnM6jJ; 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 S1729653AbgBZBaC (ORCPT + 99 others); Tue, 25 Feb 2020 20:30:02 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:39458 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729170AbgBZBaC (ORCPT ); Tue, 25 Feb 2020 20:30:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=f0M9pTXksi/4gAdPbOMhWiXGju+Jg2ed8su13b9OEus=; b=G2lnM6jJj1akbMJAyGC37MnXzJ O6MCG2g4Myrkqv+/4A5AdEgf3m6KJPl4eeI62mVAGs/AXIo3l37SrV6qZ/aB9nSNPtpz2/FjVa29l A3EWCc+3b0q++puV9gruRmIZTtb4yudjw/NgTbo6WUU5r+K/lfECbtKswv319+mTC5AXKFCEoR6Le 7zHyLP3lJpdQZqOV49IykmyDLwsWIEdLE8XME8gmlydvnw9EG/xQAPfSyGrr8Bkyys97fPKmw4Ojb CQ8sZ7ePfd1et9+ZNVI/FGBsH7LQneHNo++MSf4OmQLfv6BdMyWQrsonz5NFl+YCW54YIWu3Sjr8D At5rGWNw==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j6lWK-0004C5-HK; Wed, 26 Feb 2020 01:29:52 +0000 Date: Tue, 25 Feb 2020 17:29:52 -0800 From: Matthew Wilcox To: Qian Cai Cc: akpm@linux-foundation.org, elver@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/vmscan: fix data races at kswapd_classzone_idx Message-ID: <20200226012952.GV24185@bombadil.infradead.org> References: <1582649726-15474-1-git-send-email-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1582649726-15474-1-git-send-email-cai@lca.pw> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 25, 2020 at 11:55:26AM -0500, Qian Cai wrote: > - if (pgdat->kswapd_classzone_idx == MAX_NR_ZONES) > - pgdat->kswapd_classzone_idx = classzone_idx; > - else > - pgdat->kswapd_classzone_idx = max(pgdat->kswapd_classzone_idx, > - classzone_idx); > + if (READ_ONCE(pgdat->kswapd_classzone_idx) == MAX_NR_ZONES || > + READ_ONCE(pgdat->kswapd_classzone_idx) < classzone_idx) > + WRITE_ONCE(pgdat->kswapd_classzone_idx, classzone_idx); > + > pgdat->kswapd_order = max(pgdat->kswapd_order, order); Doesn't this line have the exact same problem you're "solving" above? 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? And there are a _lot_ of places which access kswapd_classzone_idx without a lock. Are you sure this patch is sufficient?