Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1248447pxb; Fri, 21 Jan 2022 13:19:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxfP1fupYdFFpKaiBdgKLxciaAkERuDUlxua3eF4vffBRx9xOxl3yZX7czIONNmAJbYK8C4 X-Received: by 2002:a63:a744:: with SMTP id w4mr4204007pgo.142.1642799941039; Fri, 21 Jan 2022 13:19:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642799941; cv=none; d=google.com; s=arc-20160816; b=zzbwGKt8t/tdnBHM/KAl9XQMXmwyf/wbdkjiQPf1u8jcviCvM63ltFQWpacjlcgwP7 WvvIGSiqCA691hfq1yYX5alv8lzLvj1DyE5oM6o78MItVuAkS/YFNTw+ZWB18lZVYUiq jAU7GEjx2btPlfwAH7CdYzqu6IIzCcYBxIfrMO9Mtek9amn1DWjaNfi8VJJLdJTZa1y+ Xvm79GxyHdAuZqaBG0/UXz6Crs1k1VY+DPbejRBDZDFzkwbquj7Fmw6hd6TCJSMUHtza RX+9P3i3O4CzQkj6TEHO+aSfNpH5opfbr6GrJ3g333YoYLtjhFXvmZPf4Fvik2wqqTOh 4J2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RUxAMIPHh8EnpD7PkzX4ApuOdrcdTPZnoa+y0am0Ul0=; b=ojzXG+2j7tp8m7JirV5jW4Dn1+e4+vwMkt8Oqch4MigVy/RwczCq7536l6fzOHyOL2 F/2NB4RF78KbnSx7qI3MhmmCQG0Xbr/rUYZRhyUxCAOSt/ql7H+sH0HXKyK2fgI4S+pg cqgokO72eEfvn72MKH0sVwZDN56Kx4BY9qr67s1EvzX04U1zxK7YBAI26Swld+2/Ir3t 5TVmdhQ+u0GYZYtW2A9IW6SrWehzO79Q/JR88UCs/dxEQcVUuIAmPh+9L8lT+XwioFVn jvvHlhvKmuSUOyb43Bk+LL0e4dlG6nkRI8LwO1JaxVVCoC/xszIETrhTDYxgHZ+oEKJS Y5Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=E5o6FGrX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si7885653plx.86.2022.01.21.13.18.49; Fri, 21 Jan 2022 13:19:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=E5o6FGrX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376362AbiATKnm (ORCPT + 99 others); Thu, 20 Jan 2022 05:43:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243288AbiATKnl (ORCPT ); Thu, 20 Jan 2022 05:43:41 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A0E6C061574; Thu, 20 Jan 2022 02:43:41 -0800 (PST) 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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..