From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E38FC352A3 for ; Mon, 10 Feb 2020 12:16:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0EEDA20842 for ; Mon, 10 Feb 2020 12:16:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lca.pw header.i=@lca.pw header.b="a+Nlc5bM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0EEDA20842 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lca.pw Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 81E366B00EA; Mon, 10 Feb 2020 07:16:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CEF96B00EB; Mon, 10 Feb 2020 07:16:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E4296B00EC; Mon, 10 Feb 2020 07:16:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id 56CB06B00EA for ; Mon, 10 Feb 2020 07:16:39 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F2348181AEF00 for ; Mon, 10 Feb 2020 12:16:38 +0000 (UTC) X-FDA: 76474115676.21.work44_914d607527b62 X-HE-Tag: work44_914d607527b62 X-Filterd-Recvd-Size: 4848 Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Mon, 10 Feb 2020 12:16:38 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id r5so3571114qtt.9 for ; Mon, 10 Feb 2020 04:16:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=jOS4lF/HfGt+hqkWTYE7/ikX0I8M0rt4XoEg2BiMX2I=; b=a+Nlc5bMsGl55jCxMRqbTGgnyr9X0K+VNpY85sE997TDTXoZb1kP/m9K/Zylpq7CEG BQ9Z9lbuTvBp0AYjDvTU+Y93ujo1SdGB1BLxxIJF2Isb1Kwf44iyRLvlwgVUXLH2G8Pt xnImYyZd5VrRvZxn3E+86q9FzbWriBT+t4/edFZlZcCWbtIsS8xgX9zTFmgSAs10UH9X xqCQR7/2rxRUGRnvRCyTsw1qWoU1CqrpqAWc02XImxSFEarOAAifh4tJ6hMdGHU69yDp /FP6se8zh+Skzt4Uy/jCLmhS4kQ7eBcdFNzyNKyIsHWLyhzUFvfqK38raf5Y7gBp5Yru 46Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=jOS4lF/HfGt+hqkWTYE7/ikX0I8M0rt4XoEg2BiMX2I=; b=JQdqnyB+Ltd0hH7s9TL8nhxOa3NVdYRKCqc2FXQbPMky3C+YWQkkq0hhxMyBYWdeyd 5dMq/gxBqs9EUOUB62z7MUlpbO6QJhg1GBGLy2pzgfc+w1gq/+hz1dapTTWN3qoC5ivO IfLb3jT9mnk69g//8cjA/cd0M6oGQw4YRc5Xz8JPLOfzsqMsfkNm/YwMEayYZhrC0ZDz YGFZOdXlasVSmWeYOYdnyedDVu+nfTo1TTj0eHFYq4EYzO5WdDBU3c+e/MQJdJIjRYWD abqPazQNZ6Z34LivBFXUlz9PNWK+f88khbDg9Gw++s5Xc5NiBE7uQXduLVBz1HG48vLo 9f7Q== X-Gm-Message-State: APjAAAW6k2/JN3mV0z3L4BAInx/d0jLF+9cwg7y40vprUmipF+7OXR8K CRS2pw5irYzRE2oavGVObCp6Xg== X-Google-Smtp-Source: APXvYqyl/cjx3W37/YdnY8dDHkhzfpIYJo29jFFJpcy6EqwGmlKtlD9YY2t1EXEDbTZDgDqiUuQPjA== X-Received: by 2002:ac8:198c:: with SMTP id u12mr9826102qtj.225.1581336997787; Mon, 10 Feb 2020 04:16:37 -0800 (PST) Received: from [192.168.1.183] (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id i13sm40735qki.70.2020.02.10.04.16.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Feb 2020 04:16:37 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Qian Cai Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] mm: fix a data race in put_page() Date: Mon, 10 Feb 2020 07:16:36 -0500 Message-Id: <26B88005-28E6-4A09-B3A7-DC982DABE679@lca.pw> References: Cc: John Hubbard , Jan Kara , David Hildenbrand , Andrew Morton , ira.weiny@intel.com, Dan Williams , Linux Memory Management List , Linux Kernel Mailing List , "Paul E. McKenney" , kasan-dev In-Reply-To: To: Marco Elver X-Mailer: iPhone Mail (17D50) 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 Feb 10, 2020, at 2:48 AM, Marco Elver wrote: >=20 > Here is an alternative: >=20 > Let's say KCSAN gives you this: > /* ... Assert that the bits set in mask are not written > concurrently; they may still be read concurrently. > The access that immediately follows is assumed to access those > bits and safe w.r.t. data races. >=20 > For example, this may be used when certain bits of @flags may > only be modified when holding the appropriate lock, > but other bits may still be modified locklessly. > ... > */ > #define ASSERT_EXCLUSIVE_BITS(flags, mask) .... >=20 > Then we can write page_zonenum as follows: >=20 > static inline enum zone_type page_zonenum(const struct page *page) > { > + ASSERT_EXCLUSIVE_BITS(page->flags, ZONES_MASK << ZONES_PGSHIFT); > return (page->flags >> ZONES_PGSHIFT) & ZONES_MASK; > } >=20 > This will accomplish the following: > 1. The current code is not touched, and we do not have to verify that > the change is correct without KCSAN. > 2. We're not introducing a bunch of special macros to read bits in various= ways. > 3. KCSAN will assume that the access is safe, and no data race report > is generated. > 4. If somebody modifies ZONES bits concurrently, KCSAN will tell you > about the race. > 5. We're documenting the code. >=20 > Anything I missed? I don=E2=80=99t know. Having to write the same line twice does not feel me a= ny better than data_race() with commenting occasionally.=