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 B0695C433EF for ; Tue, 17 May 2022 20:21:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0ECC36B0071; Tue, 17 May 2022 16:21:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09BDF6B0073; Tue, 17 May 2022 16:21:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7EC06B0074; Tue, 17 May 2022 16:21:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D52526B0071 for ; Tue, 17 May 2022 16:21:19 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A68CA33A97 for ; Tue, 17 May 2022 20:21:19 +0000 (UTC) X-FDA: 79476354678.08.8A873DB Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf12.hostedemail.com (Postfix) with ESMTP id 7C6CF4001E for ; Tue, 17 May 2022 20:20:50 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 05FA1B81C07; Tue, 17 May 2022 20:21:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A465CC385B8; Tue, 17 May 2022 20:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652818875; bh=FUw9l4CEWJbA9/ZM7b1TCp7eWq+8/wCm8DPSvUGG3T4=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=r4KUhRHhufPM63pNUB6CmLAX4u4xMJo5dlQGS2SMPpOWhshwbXRO/d66JtnfYOO5q 0LbTnM7jIHPi4aa6j/kxlk+UXIh/KXQQg3C05ODO02/e8MxJcF/08bnl1EUXljw39F jFHhuhOAYWqTUAOlF20+Z4IUlmlvWjgvgP2FEh1fS7/st8pxPHfliv6dTXQ7smWUXa Fa5ZG0ZxoCVnb6YHe6Rd/cToc11p2hb5gVQHYHsHZOba/yYJ5dlu5IGhB6DYOfQYiD JbzxyCcn/muQruVQz2t10S6lUmnVXX4p3emmkDkQvtMm6OHDwZlePrqUtEo+17yyaR r+XVcgvdcDJ0w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 41A4E5C086D; Tue, 17 May 2022 13:21:15 -0700 (PDT) Date: Tue, 17 May 2022 13:21:15 -0700 From: "Paul E. McKenney" To: John Hubbard Cc: Jason Gunthorpe , Minchan Kim , Andrew Morton , linux-mm , LKML , John Dias , David Hildenbrand Subject: Re: [PATCH v4] mm: fix is_pinnable_page against on cma page Message-ID: <20220517202115.GE1790663@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220512004949.GK1790663@paulmck-ThinkPad-P17-Gen-1> <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-Stat-Signature: yj7syfgatxnz79w3f6zra5s9z7a3rn1q X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7C6CF4001E Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=r4KUhRHh; spf=pass (imf12.hostedemail.com: domain of "SRS0=siJO=VZ=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 145.40.68.75 as permitted sender) smtp.mailfrom="SRS0=siJO=VZ=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org"; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-HE-Tag: 1652818850-671519 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 17, 2022 at 01:12:02PM -0700, John Hubbard wrote: > On 5/17/22 12:28, Jason Gunthorpe wrote: > > > If you compare this to the snippet above, you'll see that there is > > > an extra mov statement, and that one dereferences a pointer from > > > %rax: > > > > > > mov (%rax),%rbx > > > > That is the same move as: > > > > mov 0x8(%rdx,%rax,8),%rbx > > > > Except that the EA calculation was done in advance and stored in rax. > > > > lea isn't a memory reference, it is just computing the pointer value > > that 0x8(%rdx,%rax,8) represents. ie the lea computes > > > > %rax = %rdx + %rax*8 + 6 > > > > Which is then fed into the mov. Maybe it is an optimization to allow > > one pipe to do the shr and an other to the EA - IDK, seems like a > > random thing for the compiler to do. Maybe an optimization suppressed due to the volatile nature of the load? If so, perhaps it might be considered a compiler bug. Though it is quite difficult to get optimization bugs involving volatile to be taken seriously. > Apologies for getting that wrong, and thanks for walking me through the > asm. > > [...] > > > > Paul can correct me, but I understand we do not have a list of allowed > > operations that are exempted from the READ_ONCE() requirement. ie it > > is not just conditional branching that requires READ_ONCE(). > > > > This is why READ_ONCE() must always be on the memory load, because the > > point is to sanitize away the uncertainty that comes with an unlocked > > read of unstable memory contents. READ_ONCE() samples the value in > > memory, and removes all tearing, multiload, etc "instability" that may > > effect down stream computations. In this way down stream compulations > > become reliable. > > > > Jason > > So then: Works for me! Acked-by: Paul E. McKenney Thanx, Paul > 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 > + * a consistent (non-tearing) read of the memory array, so that results, > + * even though racy, are not corrupted. > + */ > + word = READ_ONCE(bitmap[word_bitidx]); > return (word >> bitidx) & mask; > } > > > thanks, > -- > John Hubbard > NVIDIA