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 8611CC433F5 for ; Tue, 24 May 2022 16:59:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F21948D0002; Tue, 24 May 2022 12:59:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED0958D0001; Tue, 24 May 2022 12:59:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D96048D0002; Tue, 24 May 2022 12:59:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C99008D0001 for ; Tue, 24 May 2022 12:59:08 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A1C2934ED0 for ; Tue, 24 May 2022 16:59:08 +0000 (UTC) X-FDA: 79501246776.23.3B6FDE3 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf14.hostedemail.com (Postfix) with ESMTP id 176CE100029 for ; Tue, 24 May 2022 16:59:04 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id x143so16938599pfc.11 for ; Tue, 24 May 2022 09:59:07 -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=H/DtubZRV7+ZvAxCcXKcVcJC6FOQ/XSxjh1i8plYq8E=; b=IEuiV1KeWuIAcNcCISdUIiHcWWP1KJRAs3fa0pHMvO5vMyfyBqrfLsRT/rZjpslM4r SVnnvlDGHlmn5HQ1Neyg18m/enu3+pQtgY1uk5KUJgNHUD/8GW8R+vL/kD6bOdTJM9eG QrEILSJ22hzajUE3DsSFNteYaE3cKCjFEtvLTFicOtkLK1iRoK3jLMFX+cyaZtIkY+JH tc734EMQg5ghsGwZzA+0f3tgUQdHaqOMFccoF9wHKkideIM2R47mwvp5f76R/wbKLEuX EvOqvZZhGN8duC6fI1LkDQNGZhrRFWyb2kRt2tTDsrbrCf0tRXwmvPzWT94mMU5QtB72 950w== 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=H/DtubZRV7+ZvAxCcXKcVcJC6FOQ/XSxjh1i8plYq8E=; b=tzJIqbqxuj7iZA+ioFBZre/fm9M6hye/BEE7T6y1PeWCuLmzpG2/wfs/xFXH4cBN4c G3Jp1kVjsxyMuzUvQlYGqpNH1WVDeksVXL2V95EYUVLmICnTLKfA3cIl6mMzwEzxgiFy mg4v38bdyOddzHaVv5ky8rAn9zKZg/8XmmGEaQrIwzESPm+CL6NTj9DTbbjoQ9NtaUKT Cv70AbS/zR/qzO8CUtoM0Ln8Qq3zdVavyz7rgtPGyk8enEBugYZ2RRrv/hMeynG85Ek1 fPB+IQ2o9VHRRkcI0zg64HNo+pDkZSYP1+xrB2pKlVYzhzxkfOri3fNN4r4jHdcwmbkX nQrg== X-Gm-Message-State: AOAM532XWEUu40CnwYzDGl9yQxOW5uvrhKiJY6kIszY3G4fMOXxMJmmy AAcmFxfN/eO/QOuGW2phmXU= X-Google-Smtp-Source: ABdhPJw0xiqNUbqGmI1l6crxfJjDQWf95J/3+y1s+hIoflR3DM1A6OaKu1llWGqfdCzhZnql5UlTtQ== X-Received: by 2002:a05:6a00:1411:b0:4fd:e594:fac0 with SMTP id l17-20020a056a00141100b004fde594fac0mr29249931pfu.79.1653411546988; Tue, 24 May 2022 09:59:06 -0700 (PDT) Received: from google.com ([2620:15c:211:201:20f:8bc7:9098:371f]) by smtp.gmail.com with ESMTPSA id h11-20020a65518b000000b003c644b2180asm6894498pgq.77.2022.05.24.09.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 09:59:06 -0700 (PDT) Date: Tue, 24 May 2022 09:59:04 -0700 From: Minchan Kim To: "Paul E. McKenney" Cc: Jason Gunthorpe , John Hubbard , 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: <20220517192825.GM63055@ziepe.ca> <20220524141937.GA2661880@ziepe.ca> <20220524154831.GC2661880@ziepe.ca> <20220524163728.GO1790663@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220524163728.GO1790663@paulmck-ThinkPad-P17-Gen-1> Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=IEuiV1Ke; spf=pass (imf14.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) X-Rspam-User: X-Stat-Signature: 1dx5bsq4t9eqxb3e1a8ed46tgk7r6ahy X-Rspamd-Queue-Id: 176CE100029 X-Rspamd-Server: rspam01 X-HE-Tag: 1653411544-544918 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 09:37:28AM -0700, Paul E. McKenney wrote: > On Tue, May 24, 2022 at 12:48:31PM -0300, Jason Gunthorpe wrote: > > 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. > > This is in fact the intent, except... > > And as that passage goes on to state, there really are compilers (such > as GCC) that tear stores of constants to machine aligned/sized locations. > > In short, use of the _ONCE() macros can save you a lot of pain. Thanks for the correction, Jason and Paul > > > > 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. Seems like there was some misunderstanding here. I didn't mean not to use READ_ONCE for the bitmap but wanted to have more concrete comment. Since you guys corrected "even though word-alinged access could be wrong without READ_ONCE", I would keep the comment John suggested. > > I am with Jason on this one. > > In fact, I believe that any naked C-language access to mutable shared > variables should have a comment stating why the compiler cannot mangle > that access. Agreed. Thanks!