Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1867813pxb; Sat, 22 Jan 2022 08:30:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyaNd5+bz6Pw/EQy/vP+rwN8khBf1uiWgfGLz7ZBvXamTKCfPcHqr2KrUca4hF3l4fHkuW4 X-Received: by 2002:a63:3e0f:: with SMTP id l15mr6307843pga.101.1642869048734; Sat, 22 Jan 2022 08:30:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642869048; cv=none; d=google.com; s=arc-20160816; b=MO36cmutqRyNdXHg/Pd2H0h/Ik4Cm8ycC45JoWYFpRcfDX9ZKS8C1VJEDVXED3Xzzl 5FH/bmKsMTbA8Ct2KfWWh9TzJ4wBozjyAsPr4UeHpEtYoy7u6nRAEl30X+/ms21HPWx/ CcqY5nokH3kKO71zJ8l+LBEgU5f0l1tmrNAnpF2iMS8pNxGUn9z5BWZETOVxBbwp9Koz p5br9OA5l7eUihYiDhCrpTOTOBBqKoWvwiGSbrzddBXV06tSUc77RlbUvXQXrb6ZHr+w oUVsz55QQf/EIDW1wU4Ro69GhjmSyXMRYjV5VcgAtOoMF+AAVV7y5hv5kbPyJ4PFDCgI Keng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=0lPulDTNyk1tT0uyWXBSfXERYQLBy2175ie9JUMp2N4=; b=VbxmT/X7vqWEg7w2GUVJCC1IeWpdUqfN61GQTfwtKnfU3P9kkCCMdqHCxJgUZmXmge nfivTSB/X7kqt2BUFViH1LjTRPU2BXi3mz3E7GVr9n/naLl6q1xN9G6N1H0hUnpd5CnI HCzeuyskfvQHwSsrodT3IDRp0m7+RFDSn9rR6GtrNPUoPBwsM3y8hYbl9KAIHf81WMiZ sGdBBALzxbaSXtCe3k+iGBpPYcbGRawJrGteMQStbkhLdIAmufUFzbZIa0bLm+iExMWX bZi+4F1UOYhH89zUWfVcyZG1agPWR7eoGh9YvjX+uALTdPhmwFAYKiOoZSghqTz/3FfC 3ncQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=irAoru8G; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m6si10142214pfk.281.2022.01.22.08.30.05; Sat, 22 Jan 2022 08:30:48 -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=@google.com header.s=20210112 header.b=irAoru8G; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230457AbiAUWfv (ORCPT + 99 others); Fri, 21 Jan 2022 17:35:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230136AbiAUWfu (ORCPT ); Fri, 21 Jan 2022 17:35:50 -0500 Received: from mail-ua1-x92c.google.com (mail-ua1-x92c.google.com [IPv6:2607:f8b0:4864:20::92c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EB12C06173B for ; Fri, 21 Jan 2022 14:35:50 -0800 (PST) Received: by mail-ua1-x92c.google.com with SMTP id y4so19520686uad.1 for ; Fri, 21 Jan 2022 14:35:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0lPulDTNyk1tT0uyWXBSfXERYQLBy2175ie9JUMp2N4=; b=irAoru8GAZzoUOxiaEjcHP1bv4tmeWLyRhmRZkD+NLtC5XfBtuYM52oRoGamnEloZW 3tFevZbNyl4g+rfx0hO92ibSsoodiQRcMgGk6X2mh4m2NMGU4wqJ0yKqMov8F11cNDN9 tj7ClcGH1afsoCIXopKvub9otzw5KmYm+hoDNR9iEBc+e+q0+QWDnTQ3c7DjS4Czjjzj nYum5NyaKP9vkCAJVY1ivd2drT2ahKYnDJktGh/lREw2y5+aE/U+e5Pdhr7FaR/ou/To 3ek+vQsYWrxfhEPi53onAfsGziGiMYXK4ksZL6ua4tGNY8ZguMhg7q3RqGoii+f3kIZB oreQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0lPulDTNyk1tT0uyWXBSfXERYQLBy2175ie9JUMp2N4=; b=QncFZA61IfkpqOkGcIp1QXLTMBTItTfUHG41ZpeAe3RgXzSqvbcSAwAEk39YCjSvI+ bMbJmhaAA2kzns77I8r1OosUA6l/Y2zua9ok5NwIxRsAX1N7UNBAHmkJ5P+pE+LYKZ3Y KXNRWH7Sr/pYJo82mZ4f79rVthG5fZCjg3yZ0omUrkJ7QA/TdGuujGfLPmALxhMh8NTI zCK+fTcKgMijdp8W4xyCRC15eiyTmPeXNlZzbR6BCgAQt27ItfuOH69eiiaCnZHVSFT+ CtSNVtL0YfWNyGk5q34FDvsYK6gjJOQHWIO0ijVk4LDBWl7IGmB+E/6RC9Ea2OSMRQE9 Ttsw== X-Gm-Message-State: AOAM531p8ARm7WHXTtxM45OdRUA2S31hdMwXLdqn/V2aPq95Qp+CycgX QTAhVtTBtROZ3pTNtERhf4WlLPhy9FfFa9t9oMFTXQ== X-Received: by 2002:a67:c48e:: with SMTP id d14mr2674726vsk.67.1642804547204; Fri, 21 Jan 2022 14:35:47 -0800 (PST) MIME-Version: 1.0 References: <20220118230539.323058-1-pcc@google.com> In-Reply-To: From: Peter Collingbourne Date: Fri, 21 Jan 2022 14:35:36 -0800 Message-ID: Subject: Re: [PATCH] mm/mmzone.c: fix page_cpupid_xchg_last() to READ_ONCE() the page flags To: Peter Zijlstra Cc: Andrey Konovalov , Andrew Morton , Linux Memory Management List , Linux Kernel Mailing List , Mel Gorman , "# 3.4.x" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 20, 2022 at 2:43 AM Peter Zijlstra wrote: > > 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. Yes it looks like it's at least as powerful as a barrier() because the implementations I looked at (arm64 and x86) use inline asm with memory operand (i.e. same as barrier()). > 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. Right, the patch you provided (which I posted as v2) inlines the page_cpuid_last() and should resolve this. > > > > 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.. I'd be surprised if it went away any time soon, the same hosting is used for projects like Android and Chromium which have been using it for years and have a long track record of stability. Also note that the link is useful independent of the host continuing to be up, it means that you can also do a search of the mailing list archive like so: https://lore.kernel.org/all/?q=I2e1f5b5b080ac9c4e0eb7f98768dba6fd7821693 (or the equivalent link on a different mailing list archive if lore.kernel.org ever gets shut down) and find the progression of the patch that way. This is particularly useful if (as in this case) the subject line of the patch changes. Peter