Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3067584ioo; Tue, 24 May 2022 12:15:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/GSmgFAlG72Qn4tLxabbZvZI55WL3MMFNI0geFJS4o10yBjzdoNMzY8FzM3yyENHxc8wR X-Received: by 2002:aa7:d414:0:b0:42a:b49e:d502 with SMTP id z20-20020aa7d414000000b0042ab49ed502mr31590082edq.68.1653419702393; Tue, 24 May 2022 12:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653419702; cv=none; d=google.com; s=arc-20160816; b=KsNXNsvkCthoqJSg6zLqmmfte6HhvJany8+Jl4iHSTSE1h63pTg78iziu6OvbM/GV7 r8Fa0B8xlxWxWF3Gya0+TpeChGwx0R3W/6hpc0ckIFx12AR3NLwcmoewpu2we5bB4+st nM5X6zIgeCg3NnBmEfjtqA8yppecqVGafGFW4nOsLfGWQGWBsUjB+s9Ne0sX8FW76yMl MOAS3GqBhEfA2BqGcNRe/BhVoipGsdQKrJwNaWpnoj9w123leNrZOgHy9x1+9h8pqB1w cA9V56JbckGEj1LYkX75+Jx1OrrWdfhH+vfOsbxkjYaubmNrHd4rRVGVo30i0ysoaqNo i4Cw== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=sop9eRhLeR2Mt4vpPD4iSoU86nKIPrhcqlUVXi3a2Go=; b=oOe/qKHwhWzzYDO4pij6wr8+DRF2RiXO8GrXHOM5LRF33T/lZ9aepX3tJb+HTHizJo iVi9iDO9JOGXeaZj7DgEKkTR2eGqcnsV0XeNK/fs/cEs1tx5jxhRmTiC8fuexJF3pbxM cc9SjzQNCf29ThhpDJXxYTJvHkaNHrhgdJbwbFmB/KCunlE/ogpkrDbqwU956PXsvJ4f 94z/OkcoRFfzuGzq/Q3ozwsnYw/lZWycSnS5DGwZxq58n9SX9Mm3WvMPUHG20SAI5NhV S1cI3+BrEU+Rhgy2Tj7VcW08qfkgHGwmWmVOGA0LzcoUqBL/O3N832aL656ktWFpba2Z cxMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qDk7C1uG; 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 gn20-20020a1709070d1400b006fed8dfb78dsi8677462ejc.43.2022.05.24.12.14.35; Tue, 24 May 2022 12:15:02 -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=@kernel.org header.s=k20201202 header.b=qDk7C1uG; 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 S236723AbiEXQhg (ORCPT + 99 others); Tue, 24 May 2022 12:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233418AbiEXQhd (ORCPT ); Tue, 24 May 2022 12:37:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E485CE023 for ; Tue, 24 May 2022 09:37:31 -0700 (PDT) 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 8FAB4B81802 for ; Tue, 24 May 2022 16:37:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BC82C34115; Tue, 24 May 2022 16:37:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653410249; bh=vvGHSyTSQoD32553zowylQZDuq/Dd/Xycf277l12l3A=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=qDk7C1uGg7Rl1YLLlZmO8RkOH5lXUc49Jn912boOAKy4m1vVg8Re7zaIXrRQIIl1n 9OHLaj0LviXw/atAy2xJ92dOPqXdlWqDyI962E6KUqHiY3uPxALcB+5pEU8bQppfiU OxfYuERn4TU4UudxNti08UxM6WXY5AVTrj+SJk5Jl0la30QudhpUKLiE51SKnPvt3v FsjTEmm9ti2JpEQjAOLVAknpIyvljmyp/g0fiqgxH7BZmucHYwCIGR5rv9n2CI9ufE jCmMvECHxmyYvqBtUltLDLF+mZTtbng9btGoW662/25kLVgS2eiBAb4uaVzaYTgrt4 LR/EOQCzUjdxQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id F09605C0378; Tue, 24 May 2022 09:37:28 -0700 (PDT) Date: Tue, 24 May 2022 09:37:28 -0700 From: "Paul E. McKenney" To: Jason Gunthorpe Cc: Minchan Kim , 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: <20220524163728.GO1790663@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220517140049.GF63055@ziepe.ca> <20220517192825.GM63055@ziepe.ca> <20220524141937.GA2661880@ziepe.ca> <20220524154831.GC2661880@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220524154831.GC2661880@ziepe.ca> X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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. > > 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. 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. Thanx, Paul