Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp8702ybv; Thu, 6 Feb 2020 16:57:29 -0800 (PST) X-Google-Smtp-Source: APXvYqwC6y4Ycpb6oEsEcAi3OtIDDLhzqBYraxhSmsLPWeiDzutDF7FX5E2P1O/32qGYxZuChOep X-Received: by 2002:a05:6830:12d5:: with SMTP id a21mr723629otq.296.1581037049138; Thu, 06 Feb 2020 16:57:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581037049; cv=none; d=google.com; s=arc-20160816; b=rsBorLkkGdXWh/kzLbfmUrQRNfVAAkwcU9JFZZcLBoZoNelbqILog3ENFQcwqjhOrM Wn5V3R3Zg79yrKVS2amT5HIrNOTFW3KID6LqocISB/TZ6zh05TEc1i5a79O+TwuGvFGe xtWG7D8NeKk4XdoUJZvwccQ6HlFWKxYIiwD9guCpU2N91IGNFSzSXS66dZ1iyCsEJAJr 7g+vBS/uVhOWf41vBU/ZUZWsto8o5d81q5S3cr2MD/xaPz7I1+OQBdTpB5J/aUZKvQPf 0naexkZ+hfEMMzPpCMi5N1lvYeTHvEsO52utwKI1MzKD5VLRZ2JFsQtbU/duLlYbVJF7 CklQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=p/R0f3V2QFDfmc86YhIhDY9+JDhyDpcA5H1ziRMRmpw=; b=b24oB/ZSx0T1FVzqSo+tUQm3DKAox7o2O8rmJ8s+WD7k1JT5j6JQSW18Phoutwn9a1 YdxlJW2NzJw1P0e2np91MLrABpOX7/lfXSFBjnQaP9wywyZOlLzWSDyjd9mMJ3p5KFsG ShoVrvYPMCyS/cRp641xmgEBJ8wB8rAUSk2mXlYpG7JWyHHvnde18c9PlL3vnz4Z+zq8 vD1MZCIkqqDDS/1MMr7nEdpPb99+Y50AFB5NhAm9D17bfMElI25/yPO1vyOSF2iNzfpV e3KhfMoFt5JByiltArczqaq24bo8tLuBAw1R4fJv2g7fm8oKWhULXmBfhQp0afR+UfFl bB4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=BBGuoH4l; 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 n21si3007679oic.0.2020.02.06.16.57.15; Thu, 06 Feb 2020 16:57:29 -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=@lca.pw header.s=google header.b=BBGuoH4l; 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 S1727123AbgBGAzm (ORCPT + 99 others); Thu, 6 Feb 2020 19:55:42 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:39983 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726543AbgBGAzm (ORCPT ); Thu, 6 Feb 2020 19:55:42 -0500 Received: by mail-qk1-f194.google.com with SMTP id b7so610190qkl.7 for ; Thu, 06 Feb 2020 16:55:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=p/R0f3V2QFDfmc86YhIhDY9+JDhyDpcA5H1ziRMRmpw=; b=BBGuoH4ljNf/nsbHXmKFXmeibCtToF0UNbAw3aMRh+69fImEKVZ7WDHIxU2vwAK/rM qRtIQA2bAYT6FF8ZqdcCwDjiUKoQNSw1CAD4bOxrp9icysMpkOzz8lKO56W4yNo6OriH Jt9VtlgGaId+xsdyXSF2zzVf3CAOxStkjWu4y4GBU5bhqH8SZdjgcr6d15n44iGoU0/r yt6Khu+Jf6Ng5yanUKjysg4Etfyzk3QlHJLsgsaD50bX2dQki4v8udeniiVNW21JKm7O W9A8kGUkdbL2L2rlz5GocvQiIiBqRij4BY4mKcl2tKcX5s/h6ZuXnsjQg/8uVzjd38AJ Qr+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=p/R0f3V2QFDfmc86YhIhDY9+JDhyDpcA5H1ziRMRmpw=; b=WdlFItif/296z6bys4EahxduogiZz1Td8WhY1LYz/EnKYTAoQXSiln2tRFTNIYAd2q S0RBhckdb0pWfHsxyqc7ZyMF0liHv4fgZjbSenWwIvV9wEeRSCroxdqZdUBzy6BegTaz ITkWsfmTmYPic0MH6Ef8SYghMiZ7/QnRhMeXYAgVfWd4tmnMpWSkOiMDKKC7cnJjRkkf tjNQj/yutBlyrd14y0npAOkmnJEVYm6ruxQ74xehpMDuk39fNylSoUI3Qyc6niqGh2cu mvdFUH/swHt/JX3sa1v6RHjeUxpjhq7xVratb8IoNLTGv/4QNtMfvPcTNhgz2KzoIFMN Ea2Q== X-Gm-Message-State: APjAAAV9UNsNVk73y+F9sZx0TtbSCwFYZNThFshGF6hqg/TgqKKGSCn4 RAZxUdi+34z2vWWCsFDICz6SQQ== X-Received: by 2002:ae9:f709:: with SMTP id s9mr5073023qkg.463.1581036940798; Thu, 06 Feb 2020 16:55:40 -0800 (PST) Received: from [192.168.1.153] (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id f32sm540876qtk.89.2020.02.06.16.55.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Feb 2020 16:55:40 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: [PATCH] mm: fix a data race in put_page() From: Qian Cai In-Reply-To: <90ab0b09-0f70-fe6d-259e-f529f4ef9174@nvidia.com> Date: Thu, 6 Feb 2020 19:55:38 -0500 Cc: Jan Kara , David Hildenbrand , Andrew Morton , ira.weiny@intel.com, Dan Williams , Marco Elver , Linux Memory Management List , Linux Kernel Mailing List Content-Transfer-Encoding: quoted-printable Message-Id: <1CFC5A47-3334-4696-89FE-CDF01026B12B@lca.pw> References: <20200206145501.GD26114@quack2.suse.cz> <079c4429-8a11-154d-cf5c-473d2698d18d@nvidia.com> <235ACF21-35BE-4EDA-BA64-9553DA53BF12@lca.pw> <90ab0b09-0f70-fe6d-259e-f529f4ef9174@nvidia.com> To: John Hubbard X-Mailer: Apple Mail (2.3608.60.0.2.5) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Feb 6, 2020, at 7:27 PM, John Hubbard wrote: >=20 > On 2/6/20 4:18 PM, Qian Cai wrote: >>> On Feb 6, 2020, at 6:34 PM, John Hubbard = wrote: >>> On 2/6/20 7:23 AM, Qian Cai wrote: >>>>> On Feb 6, 2020, at 9:55 AM, Jan Kara wrote: >>>>> I don't think the problem is real. The question is how to make = KCSAN happy >>>>> in a way that doesn't silence other possibly useful things it can = find and >>>>> also which makes it most obvious to the reader what's going on... = IMHO >>>>> using READ_ONCE() fulfills these targets nicely - it is free >>>>> performance-wise in this case, it silences the checker without = impacting >>>>> other races on page->flags, its kind of obvious we don't want the = load torn >>>>> in this case so it makes sense to the reader (although a comment = may be >>>>> nice). >>>>=20 >>>> Actually, use the data_race() macro there fulfilling the same = purpose too, i.e, silence the splat here but still keep searching for = other races. >>>>=20 >>>=20 >>> Yes, but both READ_ONCE() and data_race() would be saying untrue = things about this code, >>> and that somewhat offends my sense of perfection... :) >>>=20 >>> * READ_ONCE(): this field need not be restricted to being read only = once, so the >>> name is immediately wrong. We're using side effects of READ_ONCE(). >>>=20 >>> * data_race(): there is no race on the N bits worth of page zone = number data. There >>> is only a perceived race, due to tools that look at word-level = granularity. >>>=20 >>> I'd propose one or both of the following: >>>=20 >>> a) Hope that Marco (I've fixed the typo in his name. --jh) has an = idea to enhance KCSAN so as to support this model of >>> access, and/or >>=20 >> A similar thing was brought up before, i.e., anything compared to = zero is immune to load-tearing >> issues, but it is rather difficult to implement it in the compiler, = so it was settled to use data_race(), >>=20 >> = https://lore.kernel.org/lkml/CANpmjNN8J1oWtLPHTgCwbbtTuU_Js-8HD=3DcozW5cYk= m8h-GTBg@mail.gmail.com/#r >>=20 >=20 >=20 > Thanks for that link to the previous discussion, good context. >=20 >=20 >>>=20 >>> b) Add a new, better-named macro to indicate what's going on. = Initial bikeshed-able >>> candidates: >>>=20 >>> READ_RO_BITS() >>> READ_IMMUTABLE_BITS() >>> ...etc... >>>=20 >>=20 >> Actually, Linus might hate those kinds of complication rather than a = simple data_race() macro, >>=20 >> = https://lore.kernel.org/linux-fsdevel/CAHk-=3Dwg5CkOEF8DTez1Qu0XTEFw_oHhxN= 98bDnFqbY7HL5AB2g@mail.gmail.com/ >>=20 >=20 > Another good link. However, my macros above haven't been proposed yet, = and I'm perfectly=20 > comfortable proposing something that Linus *might* (or might not!) = hate. No point in=20 > guessing about it, IMHO. >=20 > If you want, I'll be happy to put on my flame suit and post a patchset = proposing=20 > READ_IMMUTABLE_BITS() (or a better-named thing, if someone has another = name idea). :) >=20 BTW, the current comment said (note, it is called =E2=80=9Caccess=E2=80=9D= which in this case it does read the whole word rather than those 3 bits, even though it is only those bits are of = interested for us), /* * data_race(): macro to document that accesses in an expression may = conflict with * other concurrent accesses resulting in data races, but the resulting * behaviour is deemed safe regardless. * * This macro *does not* affect normal code generation, but is a hint to = tooling * that data races here should be ignored. */ Macro might have more to say.=