Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6059C433EF for ; Thu, 20 Jan 2022 10:43:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7787E6B00A6; Thu, 20 Jan 2022 05:43:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 729A56B00A8; Thu, 20 Jan 2022 05:43:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 618226B00AB; Thu, 20 Jan 2022 05:43:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 533206B00A6 for ; Thu, 20 Jan 2022 05:43:40 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 10AC0180C3C46 for ; Thu, 20 Jan 2022 10:43:40 +0000 (UTC) X-FDA: 79050329400.20.CF990F0 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf11.hostedemail.com (Postfix) with ESMTP id 6A14940002 for ; Thu, 20 Jan 2022 10:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=RUxAMIPHh8EnpD7PkzX4ApuOdrcdTPZnoa+y0am0Ul0=; b=E5o6FGrXSZ1r9rnEjy8o+ycLlk FAE77GFFmK1xFTUF8V3yI/pRFm9u8ipxwYnGaGMbTSS4vvJbTofWtLgpOv0Xg/uzwmw1yC9KEACRA 4We19fE6P33qJcUSpx0jzDb4FYIpO8t1uNWiwvLFWmaJtGSYQRzv1yb8iTpvenavYLHNisQuiQPhy enPckymC/F4GPe1oBe39u2M54k4nAGBJBnN8k/TUBETZttv8W5a95qjZlF69MDS/qGyw3+7JYstY0 kVf3lKkPkxzlmUAXQJCvq5QATbtZDqMLPTloG5X5lcH3SAxA5X7d+QFKZXYrxr/S0QqTiXyvI7WsP xgVGvoeg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAUul-00E9Vb-L1; Thu, 20 Jan 2022 10:43:36 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 1045F3002F1; Thu, 20 Jan 2022 11:43:33 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E320C2C4BFBCC; Thu, 20 Jan 2022 11:43:32 +0100 (CET) Date: Thu, 20 Jan 2022 11:43:32 +0100 From: Peter Zijlstra To: Peter Collingbourne Cc: Andrey Konovalov , Andrew Morton , Linux Memory Management List , Linux Kernel Mailing List , Mel Gorman , "# 3.4.x" Subject: Re: [PATCH] mm/mmzone.c: fix page_cpupid_xchg_last() to READ_ONCE() the page flags Message-ID: References: <20220118230539.323058-1-pcc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 6A14940002 X-Stat-Signature: k58w87g8jn3zxnrbfbcuuhz5k8miijuy Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=E5o6FGrX; dmarc=none; spf=none (imf11.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org X-Rspamd-Server: rspam02 X-HE-Tag: 1642675419-43040 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Jan 19, 2022 at 03:28:32PM -0800, Peter Collingbourne wrote: > On Wed, Jan 19, 2022 at 2:03 AM Peter Zijlstra wrote: > > > > On Tue, Jan 18, 2022 at 03:05:39PM -0800, Peter Collingbourne wrote: > > > After submitting a patch with a compare-exchange loop similar to this > > > one to set the KASAN tag in the page flags, Andrey Konovalov pointed > > > out that we should be using READ_ONCE() to read the page flags. Fix > > > it here. > > > > What does it actually fix? If it manages to split the read and read > > garbage the cmpxchg will fail and we go another round, no harm done. > > What I wasn't sure about was whether the compiler would be allowed to > break this code by hoisting the read of page->flags out of the loop > (because nothing in the loop actually writes to page->flags aside from > the compare-exchange, and if that succeeds we're *leaving* the loop). The cmpxchg is a barrier() and as such I don't think it's allowed to hoist anything out of the loop. Except perhaps since it's do-while, it could try and unroll the first iteration and wreck that something fierce. The bigger problem is I think that page_cpuid_last() usage which does a second load of page->flags, and given sufficient races that could actually load a different value and then things would be screwy. But that's not actually fixed. > > > Signed-off-by: Peter Collingbourne > > > Link: https://linux-review.googlesource.com/id/I2e1f5b5b080ac9c4e0eb7f98768dba6fd7821693 > > > > That's that doing here? > > I upload my changes to Gerrit and link to them here so that I (and > others) can see the progression of the patch via the web UI. What's the life-time guarantee for that URL existing? Because if it becomes part of the git commit, it had better stay around 'forever' etc..