Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2125191ybv; Thu, 6 Feb 2020 16:29:02 -0800 (PST) X-Google-Smtp-Source: APXvYqzKAqV55yjtpGwC+fVSB3WRrxt3+0WHf/+AiIFx9p2LoEMhmp3lMwob88MA6IfAJbb6pbre X-Received: by 2002:aca:554d:: with SMTP id j74mr334421oib.92.1581035342361; Thu, 06 Feb 2020 16:29:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581035342; cv=none; d=google.com; s=arc-20160816; b=tSm+eR3r484OLB+ccJHbxINbpFI7orN1RULmcNqn/UDyo5jIdSRkmYi7tkf5gVjYy5 I3vB97Pe4lHj+10HbszbOtG9RTNw6gX3EbJ4KQnvMD462gzQ3DRA8DZC+5n6a7qNJhvO yw702bnSVhANcqM/c/6cir1Wmw/Rp/78KjZJ9WhUagbVoBeC+NcbDW4OHhNsSd/kAVjI uwU+2Wac2pv7K8g5CWfbdItCYo/+J9W6lbNarD/nbBGWM1N7DT/eWqd2YT7uEkjtRKPn ngCUlSwoy6nVI3bX5iXoUNg9Xsf2GEwSjzi/9sYyqQ4k6A9CccLsQTCt+64tQkuvxi+x 4TxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=pB+e0J8CDnr1RA7mN63T5ahx5bEiD5ff9DW/6lG1XnU=; b=H2UU8GDdw4+1wD84R+AMdN+kDLaN9vTVODlEmqbfWwJ/fxNddY3vz4NB3RIvbXCNV4 Fz8cIJTGZ7VYXWnoZe9gmKkrSYcwlAj4wyQMzZ/zQ7z2T93AfsuxOs+gQiG9BhG3Nms2 HaTRtatosLufNk58cOeKzx8kvQOcmafqYVjO2PA9VPUoIGDW+iLKAZ3bppY8BjFf/g3n TL/+6YF0oMWnQTasiTtoG+YmZMBdzXg5v3D1jO+HmlAtdtJaU6Ab/QXBcMhH1R/jpXqi LdaKreZ0Dk/CqSlCGICnOjfKfLoVeOS1SglkYQP4QFrlOzovBZUnNQrnaEbIYrAeve00 wqvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=S2cuqs7j; 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=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e20si3023313oig.199.2020.02.06.16.28.48; Thu, 06 Feb 2020 16:29:02 -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=@nvidia.com header.s=n1 header.b=S2cuqs7j; 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=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726755AbgBGA1j (ORCPT + 99 others); Thu, 6 Feb 2020 19:27:39 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:3017 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726509AbgBGA1j (ORCPT ); Thu, 6 Feb 2020 19:27:39 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 06 Feb 2020 16:27:13 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 06 Feb 2020 16:27:38 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 06 Feb 2020 16:27:38 -0800 Received: from [10.110.48.28] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 7 Feb 2020 00:27:35 +0000 Subject: Re: [PATCH] mm: fix a data race in put_page() To: Qian Cai CC: Jan Kara , David Hildenbrand , , , , , , References: <20200206145501.GD26114@quack2.suse.cz> <079c4429-8a11-154d-cf5c-473d2698d18d@nvidia.com> <235ACF21-35BE-4EDA-BA64-9553DA53BF12@lca.pw> From: John Hubbard X-Nvconfidentiality: public Message-ID: <90ab0b09-0f70-fe6d-259e-f529f4ef9174@nvidia.com> Date: Thu, 6 Feb 2020 16:27:34 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: <235ACF21-35BE-4EDA-BA64-9553DA53BF12@lca.pw> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1581035233; bh=pB+e0J8CDnr1RA7mN63T5ahx5bEiD5ff9DW/6lG1XnU=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=S2cuqs7jxI+Yz2WpcZsM50KxZjg3hS9AyvT0oVMZ2cnpQANtBqBm0zXp50hPdyFne ACRVBJR2K16wvgfAJhlHAs23BYy6bcJUgosLeSf8YsH1uJgoR1MCnd40x7xQt5GvXi 7L7OE5RrS29BrdAEloemxLdPjkE5zuLYwAARPWFLlLhcLHq+tIa8ffcOdVCVgGNRqx v166Z9J+14Y9nrqOm2uI+V9CUEXlqzDjfONv2qklVvXQcFQe8II8Dls41h8AaxNE8m hUMYvggOel0fyy3lBlJWoarQ0w6UrRT/cvR3jo5yZmSILDj66SAxvwSJMJpa5A+7eZ i4Ybo85P6ShXQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). >>> >>> 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. >>> >> >> Yes, but both READ_ONCE() and data_race() would be saying untrue things about this code, >> and that somewhat offends my sense of perfection... :) >> >> * 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(). >> >> * 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. >> >> I'd propose one or both of the following: >> >> 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 > > 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(), > > https://lore.kernel.org/lkml/CANpmjNN8J1oWtLPHTgCwbbtTuU_Js-8HD=cozW5cYkm8h-GTBg@mail.gmail.com/#r > Thanks for that link to the previous discussion, good context. >> >> b) Add a new, better-named macro to indicate what's going on. Initial bikeshed-able >> candidates: >> >> READ_RO_BITS() >> READ_IMMUTABLE_BITS() >> ...etc... >> > > Actually, Linus might hate those kinds of complication rather than a simple data_race() macro, > > https://lore.kernel.org/linux-fsdevel/CAHk-=wg5CkOEF8DTez1Qu0XTEFw_oHhxN98bDnFqbY7HL5AB2g@mail.gmail.com/ > Another good link. However, my macros above haven't been proposed yet, and I'm perfectly comfortable proposing something that Linus *might* (or might not!) hate. No point in guessing about it, IMHO. If you want, I'll be happy to put on my flame suit and post a patchset proposing READ_IMMUTABLE_BITS() (or a better-named thing, if someone has another name idea). :) thanks, -- John Hubbard NVIDIA