Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2681197ioo; Tue, 24 May 2022 03:37:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9/KHuYcQqfJLoxjqdmgbMyQJf/XTN4cY8s6Om4h/mwkw6BDZP7EzT6zdLprlIyfw/HdQJ X-Received: by 2002:a17:90b:314c:b0:1e0:35e9:e6b with SMTP id ip12-20020a17090b314c00b001e035e90e6bmr3905227pjb.25.1653388651306; Tue, 24 May 2022 03:37:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653388651; cv=none; d=google.com; s=arc-20160816; b=mCi4ANZO9kxLFdpAvQdqpceoklshAxytOIlQNfafx4murNPBfnlwFtyhCZjYkm1Nh9 NwnCfnJwi/87e2QBvPXiATIaKrWQzTe4T04f/Vu6Nol2yC1BVggvlVcodOITurJwSIcK JkKnXmQm5y9KLOsVRVGpYCJVM8PT1ep4cXuFsq4peB6/nCHol4NQtH0s195WP9PBGWem yr7YTR1OguFETA18u9T2xEY21R1W0VhwGxjRjDt6HWjvxAtd8UP8nVBGQtmDiEKv9zit IEAwrWhaue64u2Br5hstKSisNaX7OECpco3eZ4CZ3S0bI/cD8IDZJMBioy09RoWzitaa CkaQ== 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:sender:dkim-signature; bh=tQCOa3IH60VXmxlz7qxuQA0xwwvIVCrbt/GEpedjsGY=; b=txsKPjGBq1vPb+U1JPb0DxPFdOqYwr0Mfb9wSGIqvAAcP0aW3XzVfyLLXVHINKJVE0 kdjtTaw4Dcg0VYemNndDE7SzgoKhqsQY7ec1+WY0febB4a/oEkLsXkX+NPaWoZNYGN/Y r0tLZHbm9qemPGa5V09twy4UIOM0ZjaJmezK59QywOIG97B+I/Fr1ywwCskyRzvh6CuS BP6rrN/8qWapiSnrYOhUnTeafMaPVkYnsVLwoTbBeQXgQK5imgwy1XGdGs0Vx/fQXJ/1 dEs+Hgypi58gFY7MlLZJbF1qg+W27JBO4kS/fKexmCUu4KNoepPQu8F703DAZIdJwgM/ 164g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QBGQx2+C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a170903004c00b001567e872208si8421589pla.217.2022.05.24.03.37.18; Tue, 24 May 2022 03:37:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QBGQx2+C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233344AbiEXFRD (ORCPT + 99 others); Tue, 24 May 2022 01:17:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbiEXFRC (ORCPT ); Tue, 24 May 2022 01:17:02 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB92473552 for ; Mon, 23 May 2022 22:16:59 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id z25so2807632pfr.1 for ; Mon, 23 May 2022 22:16:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tQCOa3IH60VXmxlz7qxuQA0xwwvIVCrbt/GEpedjsGY=; b=QBGQx2+Cy7tW9UqeW8jJmQslZMNcie20t35LOpCM8ZuvqWrvfO1vkTmMFXVSRqOEZs LE7bW0Af5q6tcuvF6B6z0KQyIz8IRXLlpeQNZEkeln6oWA5pCBL9gX8eqQmiayqao/Uo 4CNzMTK3W7qgKlSBO1Dy8Uga2So9FKj9uaiHqBgDY8GAtoI9qv4Nk65CLgfe4TEhIi3t EsYdcRdIK5RAMJaPYETYeet58NfE6x9NPcEWP0AHqGHe5HDyi3eKxLCJJUTq63+OHxhc RUytoZt7ZLQbP7CC6gyewugxCbXmK6mTpl/9w+/NDZKUKgjwFsALar+ZG9R0xw3ZTy+s ysCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=tQCOa3IH60VXmxlz7qxuQA0xwwvIVCrbt/GEpedjsGY=; b=aQ7eVBgaIFiySwIwxgg3jyCDwt7SGtIudHqfeOEguReH1J094zx4Uw5l5PMTB4p48j X0bCrSuuPqf/kD5iEAjZA1YoDKqZuMd/jqVyU2KvJDSWODgS2Vw4swYMK0JpxvpV4vX4 YHwFuszGA8NhWFfTqWrTnLBpqDTAFoDCLmthFFnePpNP2jdnKCk+37CKoV7apqoCtpLb 5jJNtYmIpFqfJsc9WAPjsf4HlaZdKPr/pR3u06CrUkWCNKMtsGAFy8JNRBxLrBnBwgxR AP96RfvOaacq8vWTnguHZvJcx/75YXf63iZMHBy3/Zn+j3qxua1TaexOh37S8AESLmqy iSaA== X-Gm-Message-State: AOAM530RjIzPhyLBowMSmnR/1gX6LPDpS7xdWrUwFyQwpA2GeeuEiOmB qQIQUZmoZ7cl9lJ5HulpFwWuD+cSUZM= X-Received: by 2002:a65:5385:0:b0:3fa:52e3:6468 with SMTP id x5-20020a655385000000b003fa52e36468mr7333773pgq.366.1653369419350; Mon, 23 May 2022 22:16:59 -0700 (PDT) Received: from google.com (c-67-188-95-58.hsd1.ca.comcast.net. [67.188.95.58]) by smtp.gmail.com with ESMTPSA id k9-20020aa79d09000000b0050dc76281b5sm8500767pfp.143.2022.05.23.22.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 22:16:58 -0700 (PDT) Sender: Minchan Kim Date: Mon, 23 May 2022 22:16:58 -0700 From: Minchan Kim To: John Hubbard Cc: Jason Gunthorpe , "Paul E. McKenney" , Andrew Morton , linux-mm , LKML , John Dias , David Hildenbrand Subject: Re: [PATCH v4] mm: fix is_pinnable_page against on cma page Message-ID: References: <0accce46-fac6-cdfb-db7f-d08396bf9d35@nvidia.com> <20220517140049.GF63055@ziepe.ca> <20220517192825.GM63055@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 23, 2022 at 07:55:25PM -0700, John Hubbard wrote: > On 5/23/22 09:33, Minchan Kim wrote: > ... > > > So then: > > > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > > index 0e42038382c1..b404f87e2682 100644 > > > --- a/mm/page_alloc.c > > > +++ b/mm/page_alloc.c > > > @@ -482,7 +482,12 @@ unsigned long __get_pfnblock_flags_mask(const struct page *page, > > > word_bitidx = bitidx / BITS_PER_LONG; > > > bitidx &= (BITS_PER_LONG-1); > > > > > > - word = bitmap[word_bitidx]; > > > + /* > > > + * This races, without locks, with set_pageblock_migratetype(). Ensure > > set_pfnblock_flags_mask would be better? > > > + * a consistent (non-tearing) read of the memory array, so that results, > > > > Thanks for proceeding and suggestion, John. > > > > IIUC, the load tearing wouldn't be an issue since [1] fixed the issue. > > Did it? [1] fixed something, but I'm not sure we can claim that that > code is now safe against tearing in all possible cases, especially given > the recent discussion here. Specifically, having this code do a read, > then follow that up with calculations, seems correct. Anything else is The load tearing you are trying to explain in the comment would be solved by [1] since the bits will always align on a word and accessing word size based on word aligned address is always atomic so there is no load tearing problem IIUC. Instead of the tearing problem, what we are trying to solve with READ_ONCE is to prevent refetching when the function would be inlined in the future. > sketchy... > > > > > The concern in our dicussion was aggressive compiler(e.g., LTO) or code refactoring > > to make the code inline in *future* could potentially cause forcing refetching(i.e., > > re-read) tie bitmap[word_bitidx]. > > > > If so, shouldn't the comment be the one you helped before? > > Well, maybe updated to something like this? > > /* > * This races, without locks, with set_pageblock_migratetype(). Ensure set_pageblock_migratetype is more upper level function so it would be better fit to say set_pfnblock_flags_mask. > * a consistent (non-tearing) read of the memory array, so that results, So tearing problem should't already happen by [1] so I am trying to explain refetching(or re-read) problem in the comment. > * even though racy, are not corrupted--even if this function is The value is already atomic so I don't think it could be corrupted even though it would be inlined in the future. Please correct me if I miss something. > * refactored and/or inlined. > */