Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1704418ybl; Thu, 30 Jan 2020 04:37:49 -0800 (PST) X-Google-Smtp-Source: APXvYqwLcPC9z73R+nxbHYEja7Xwemq75oEOf4GIl3q8FLYuxHe9qBtgKwvqHSNw1kH3Wmi4oscb X-Received: by 2002:aca:2407:: with SMTP id n7mr2755554oic.14.1580387868990; Thu, 30 Jan 2020 04:37:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580387868; cv=none; d=google.com; s=arc-20160816; b=UXDd3xI1DmG6MvX4MPocu5k97I/iDN89KwMxPKhVcgD56WbHg3Z30chdpkrVNq4kR2 SO7ivuI6dyABScXSuB1/EVH0JeeuqXiKifiB4oL+VDXSFapW1qLAYYd4jqBCvQPOMpzS UKKNFWCZZ0OKdfMK0lctQjrKvozrae+0pJBjHZANBfGbvHSFtNP2etqVXvnuCYZxWqiZ nSkE8oAHgVg1kZk4FDYWv3nKMIE7SFSdrCMoarEHrcWS3tNvKgxjEq0IGYvikKKaSd/0 XcDI1mA/baR1yKBRDeTTcGFsxZwztAFneLSZ9L+62ViNdSWGQlJI7hFHNYNnd7epNV6p Eb5Q== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=JChikV2eDuxHeLtfwZM5oT2t0AhKhE72FILijwgC87M=; b=weA3OJutVmlVwaVJNeKJWAN9l9+vgKvZkh7c6z1ev9KUgl0y1wwxLkTgEtc5j/zivZ R/rjOxDV2O1cAidpzyw0FWed7AWcnXV5Yom1YR+EJMtADVGe1k7CLoPkSC9DkcU9TkYW uzYCfdNLDBPbDA0jGBkVEIzeqblgQws9OlRtXyS8uIDj5KuyBiGIoE/EzzPIVHGGErs6 Xim742+CjT93S3CRrQddkywy7IMwNZMX5YDjhQWzfxHSS9cLxi13N/w4rqh97VA/Nb7r zSP467V9nZa0b6ULEJar16uXofp5UTa7jJAEGzjAm1SHnmmvbDa8mATowdRSLYH3ZtH3 FHdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YUsBAZ71; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v67si2817362oia.26.2020.01.30.04.37.36; Thu, 30 Jan 2020 04:37:48 -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=@google.com header.s=20161025 header.b=YUsBAZ71; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727227AbgA3Mfd (ORCPT + 99 others); Thu, 30 Jan 2020 07:35:33 -0500 Received: from mail-ot1-f67.google.com ([209.85.210.67]:36373 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727107AbgA3Mfd (ORCPT ); Thu, 30 Jan 2020 07:35:33 -0500 Received: by mail-ot1-f67.google.com with SMTP id g15so2964045otp.3 for ; Thu, 30 Jan 2020 04:35:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=JChikV2eDuxHeLtfwZM5oT2t0AhKhE72FILijwgC87M=; b=YUsBAZ71sBC1TVR1hKRZFi1hmpwB9zhsnlhdWL3ICTqBooSAMFFMXZbSBFSKgdRiRs 2xsfHXBBEj7yGw0MZ0CGqRBIfoJlZVnnBAVwixr97b3sdPC7zE3bdgnIZiMsmjnl4kta 7otz7uWSguPylhanlVvJmGvb9wkkGJn83byq0JK2qzqW2QxovIam5kWVILEYi++eLZgC 3Bjd4uumjplegcu8AiADFuzxLn05QfbOtY/PhGncK+3qM6wwUm/c/CpY0o8suWm3UiMl 3zkdHX1df6YOWpCuAAolzgzgxy3/itRkFubaSIbf2WSQVtTZWmGp5EfW8hnz0rWRvHCY /HnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=JChikV2eDuxHeLtfwZM5oT2t0AhKhE72FILijwgC87M=; b=ofKSCWH1oDofmbH5spCyGiuHrDix4c36ML5+645Aa0fRz2hE/C02tnzR1GczGt4RJ7 zQbNAuLNSoVJGYJfdiHCPOXitu/DjpLZJefBVl0UPu7sYwaEwkXpVdnSxrhKiXRLeovO kI2Q0LvemHz/5Fthvb2fGWtEu74pBH8Mn3jFrIleZykhEU3jFmxbRz1/lT23TSEjeSXK 5j0ztwdbpocXdK5hfZ3brni8KDLSUNeA8+i9cP+J4a43Nt4qSfCjNkAoFbvsckEAfcdQ 4dOApLwk1TZXvV9xGxCMlk8oI87I0GSbnwYJSKAN2g95MCl5J9gdInXCmQWPW8gwmA3Y 4Yrw== X-Gm-Message-State: APjAAAUTlwKLd6CbSFuZnCCeuKWggec/EYtAql8bIEqHuctGG60PVzC5 DFRkD8O+jkNpWM0fqOW8j+zMsSE/t77+OUQcRrSGXw== X-Received: by 2002:a9d:4711:: with SMTP id a17mr3422842otf.233.1580387729374; Thu, 30 Jan 2020 04:35:29 -0800 (PST) MIME-Version: 1.0 References: <20200130042011.GI6615@bombadil.infradead.org> <1135BD67-4CCB-4700-8150-44E7E323D385@lca.pw> In-Reply-To: <1135BD67-4CCB-4700-8150-44E7E323D385@lca.pw> From: Marco Elver Date: Thu, 30 Jan 2020 13:35:18 +0100 Message-ID: Subject: Re: [PATCH] mm/util: fix a data race in __vm_enough_memory() To: Qian Cai Cc: Matthew Wilcox , Andrew Morton , dennis@kernel.org, tj@kernel.org, Christoph Lameter , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 30 Jan 2020 at 12:50, Qian Cai wrote: > > > On Jan 29, 2020, at 11:20 PM, Matthew Wilcox wrot= e: > > > > I'm really not a fan of exposing the internals of a percpu_counter outs= ide > > the percpu_counter.h file. Why shouldn't this be fixed by putting the > > READ_ONCE() inside percpu_counter_read()? > > It is because not all places suffer from a data race. For example, in __w= b_update_bandwidth(), it was protected by a lock. I was a bit worry about b= lindly adding READ_ONCE() inside percpu_counter_read() might has unexpected= side-effect. For example, it is unnecessary to have READ_ONCE() for a vola= tile variable. So, I thought just to keep the change minimal with a trade o= ff by exposing a bit internal details as you mentioned. > > However, I had also copied the percpu maintainers to see if they have any= preferences? I would not add READ_ONCE to percpu_counter_read(), given the writes (increments) are not atomic either, so not much is gained. Notice that this is inside a WARN_ONCE, so you may argue that a data race here doesn't matter to the correct behaviour of the system (except if you have panic_on_warn on). For the warning to trigger, vm_committed_as must decrease. Assume that a data race (assuming bad compiler optimizations) can somehow accomplish this, then the load or write must cause a transient value to somehow be less than a stable value. My hypothesis is this is very unlikely. Given the fact this is a WARN_ONCE, and the fact that a transient decrease in the value is unlikely, you may consider 'VM_WARN_ONCE(data_race(percpu_counter_read(&vm_committed_as)) < ...)'. That way you won't modify percpu_counter_read and still catch unintended races elsewhere. [ Note that the 'data_race()' macro is still only in -next, -tip, and -rcu.= ] Thanks, -- Marco