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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42B42C433EF for ; Tue, 24 May 2022 14:19:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FDAD8D0003; Tue, 24 May 2022 10:19:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A8E38D0001; Tue, 24 May 2022 10:19:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8721E8D0003; Tue, 24 May 2022 10:19:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 773918D0001 for ; Tue, 24 May 2022 10:19:40 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4665C34B44 for ; Tue, 24 May 2022 14:19:40 +0000 (UTC) X-FDA: 79500844920.24.2E2E94A Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf03.hostedemail.com (Postfix) with ESMTP id 85FA2200DC for ; Tue, 24 May 2022 14:19:27 +0000 (UTC) Received: by mail-qk1-f179.google.com with SMTP id x65so10852460qke.2 for ; Tue, 24 May 2022 07:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QIFSK7+q86peBNyVF83M929mz5YDWsMa1JplQe+w7Nk=; b=Inf+g6txiTsyfphgQvO6mWRJ0v2To4UMd2hLgKSIOSaHtvXY9tUdBiG+GrrEWQMeK2 rWOuSOQTj/E5eMu/jSqWLm7Nbe8hdaxY6Ggwc4waFUwhOuvk9hlhjwxdWpAoBlbtoKPN +SOriD+ZQERrpaJIrmNopEBCZ2I3BI8eH49U+QHxrGYEXxEBFT8RQ8sKJSWa6dzw0tzL eK04TQZtOe7bCaXApA7M4/uIcyLGkys5YB3GAzxwHtwmLg14bMbQazrJJ7m6K5PSukNM HDQA6l1EQ/0e1NLgpwTzX+g/77xLqkvirgqiANe0VnOa81F3Zze9KIf1Wcz5nQbUl2j+ JAkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QIFSK7+q86peBNyVF83M929mz5YDWsMa1JplQe+w7Nk=; b=3PiODlIOX34GpfwyvrJSzIo58MxgS0a16gEQcJ7RQl5chxH5IjnRPafLvBaueGSOCB 6XxE6lEZ9Myc7foG4jM9rrYvg37DYCxwchdiuoFhipCwPjxs44SgaCIKCUq23Ouamoih c+sDIa4DSdeOS7kauKgBxiC5KmvkdBjGQDUsI6G8FT3uyMw4tkVBX+R6aBTnh+9GQn/E X1r8AjbnXCGLBvYvarWCAQuXxYmONJqlUEULC3H18rg90vMCHQEdpvuVx9kjkOXq1ISK J8BB+QR2YdmGfBEFC4mDu/COJGrbixSomMBaNBBPdwcpQ7ehx0W/my6g8i4ZEnwFiLGb m99g== X-Gm-Message-State: AOAM533rVUiB3tVeS2WAnNnbt2ZZrSL8YeU0sJ1AUn226lVEhNfRv7Tg eK3/5FQYTo7TNzViUU6VdAZKcQ== X-Google-Smtp-Source: ABdhPJxOzDiG7VBFbmRvLO2WitMeyjUue0KUWacGzqB401AecLJ3spFnkhPVFUrtg2jKOjn3gxJ22A== X-Received: by 2002:a05:620a:4544:b0:6a0:40ef:ca7a with SMTP id u4-20020a05620a454400b006a040efca7amr16839267qkp.754.1653401979010; Tue, 24 May 2022 07:19:39 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id w7-20020ac857c7000000b002f9303ce545sm5996376qta.39.2022.05.24.07.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 07:19:38 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1ntVNp-00BBym-J3; Tue, 24 May 2022 11:19:37 -0300 Date: Tue, 24 May 2022 11:19:37 -0300 From: Jason Gunthorpe To: Minchan Kim Cc: John Hubbard , "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: <20220524141937.GA2661880@ziepe.ca> 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-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 85FA2200DC X-Stat-Signature: dfh79mpd693ekqk4q68y3r5n17r58hh4 X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=Inf+g6tx; dmarc=none; spf=pass (imf03.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.222.179 as permitted sender) smtp.mailfrom=jgg@ziepe.ca X-HE-Tag: 1653401967-108271 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 Mon, May 23, 2022 at 10:16:58PM -0700, Minchan Kim wrote: > 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 > > > > +++ 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. That is not technically true. It is exactly the sort of thing READ_ONCE is intended to guard against. > 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. It is the same problem, who is to say it doesn't refetch while doing the maths? Jason