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 D749BC433F5 for ; Tue, 24 May 2022 15:48:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47AFF8D0003; Tue, 24 May 2022 11:48:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 42A368D0001; Tue, 24 May 2022 11:48:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 317A08D0003; Tue, 24 May 2022 11:48:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 23DE68D0001 for ; Tue, 24 May 2022 11:48:34 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E9D0934E8E for ; Tue, 24 May 2022 15:48:33 +0000 (UTC) X-FDA: 79501068906.25.A16C309 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by imf18.hostedemail.com (Postfix) with ESMTP id 060B31C002E for ; Tue, 24 May 2022 15:48:16 +0000 (UTC) Received: by mail-qv1-f54.google.com with SMTP id b11so5879102qvv.4 for ; Tue, 24 May 2022 08:48:33 -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=hWo9Bh8Rusf7eYw4FNO2yhUn6v5U25aYOQhsBBIC7XE=; b=KVed7RtXba0869bB9np3IE7JU4RHUTooAjzTeCZv0y8jHUUnpfrWQk4XpHzA9gt/b0 z24JdkfMCQfox9fBonuKsyL8qnNOfHVcBqivjKRVsoIrVpZnUcziUJzQ4pO8GLle6cyu HAiEmGUWHdTd2ptoKbvfWtUV7WMKpt5+AgNNvDrlbfIgfU9cDs/bMIsudtMjgc58wv4m BdJoBDUIZqpsnENvN5635RLIsLyGDrYpUCA38O0o7OfjL042ivcaX3T0HBQglhAsXz3Q t5qgU6RRp+YfSv1pBwhWVOxJsQDZu9BEouftxbuwmUOFVZiENMKVyw8Vep0K3aureq89 9wGg== 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=hWo9Bh8Rusf7eYw4FNO2yhUn6v5U25aYOQhsBBIC7XE=; b=kPsk3r/1hiSIOdZmMOCXMmf22knn38+0lXcMTDzDkixlsWV3g+mgbsv6OE+meBAF+q 0zreclxnzFkkGSFLNh992RO1OzyQaAI05YM7ezZSRheeLcCnKpBUybZPQWU+s7JTNzJn et6NDJ6vlzTgrK9z6oU1OcmrobWyazfFje4ujLSP+gmH+S2VFYmEaGcnkn2LpIdG1ut9 zDnT0eITokaPjTOi8Sne/UZq/VCitEczfdXdVQxiBuebr1g8hJWXL1yMYGX6Hzo7w+Oz AV7js6JjUHQLt7r1pDpOXBwlbtaX6i73Mk9ln4i7xn4fNwr7PqnwK62/XFOlkyS5NLe2 kYQw== X-Gm-Message-State: AOAM531vx9OrmrxG/EQvgTmQCRgNyOyFw2lSEAXyj6KXS1/j28UEd3lK CZPrMKPKMm2P8wxYU1GeHnhXUw== X-Google-Smtp-Source: ABdhPJwCagbsFvuDCCmZfoGWTxPXfWGu0wSXS88thKs9HBOg8xwa5wwPEEi44z/h89tY+75XEIlI7g== X-Received: by 2002:a05:6214:d03:b0:462:344c:554a with SMTP id 3-20020a0562140d0300b00462344c554amr10026099qvh.104.1653407312650; Tue, 24 May 2022 08:48:32 -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 c13-20020ac85a8d000000b002f39b99f6bfsm6705923qtc.89.2022.05.24.08.48.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 08:48:32 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1ntWlr-00BPZd-7s; Tue, 24 May 2022 12:48:31 -0300 Date: Tue, 24 May 2022 12:48:31 -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: <20220524154831.GC2661880@ziepe.ca> References: <20220517140049.GF63055@ziepe.ca> <20220517192825.GM63055@ziepe.ca> <20220524141937.GA2661880@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 060B31C002E X-Stat-Signature: i8apoowiq1tatza5j5ngixsrwj5r99ui Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=KVed7RtX; dmarc=none; spf=pass (imf18.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.219.54 as permitted sender) smtp.mailfrom=jgg@ziepe.ca X-Rspamd-Server: rspam04 X-HE-Tag: 1653407296-20883 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 Tue, May 24, 2022 at 08:43:27AM -0700, Minchan Kim wrote: > On Tue, May 24, 2022 at 11:19:37AM -0300, Jason Gunthorpe wrote: > > 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. > > Oh, does word access based on the aligned address still happen > load tearing? > > I just referred to > https://elixir.bootlin.com/linux/latest/source/Documentation/memory-barriers.txt#L1759 I read that as saying load tearing is technically allowed but doesn't happen in gcc, and so must use the _ONCE macros. > I didn't say it doesn't refetch the value without the READ_ONCE. > > What I am saying is READ_ONCE(bitmap_word_bitidx] prevents "refetching" > issue rather than "tearing" issue in specific __get_pfnblock_flags_mask > context because I though there is no load-tearing issue there since > bitmap is word-aligned/accessed. No? It does both. AFAIK our memory model has no guarentees on what naked C statements will do. Tearing, multi-load, etc - it is all technically permitted. Use the proper accessors. Jason