Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3026006ioo; Tue, 24 May 2022 11:12:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1n44Jb/uXlORsUcMWvouAYqSFJmO+K3HF4NrJPqp5k+eC9GPp8nEA907Ml9fvoZVgXrjP X-Received: by 2002:aa7:8dd8:0:b0:518:11:18db with SMTP id j24-20020aa78dd8000000b00518001118dbmr29637867pfr.29.1653415960234; Tue, 24 May 2022 11:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653415960; cv=none; d=google.com; s=arc-20160816; b=i0rX7WXYrpXL5qb/Rziu887odkCAmZcOWf+O8cehCzyHFqSgP2Y7QfBvungAu0bC+P 9vq5f55UfPnt0dYO9S74luF8dySoXUloupHgKxNZycJ9nFSQ9N7qm+HGX7pdStCNvdac /KyD0/Xx6ufCGvSkQ9a0Ze89h0YWYbJ3Gv3cHyEZ30jplorD0O7DW8+zD2oEux6oZNEy nLKk7JdcOAOT9iZybt1ciD/bpNVndrNurBY+dGaBrDs6v02EK9EJ/ZBPsYjQnP7HWQ5y uDd5dlMXPeR6J0MWSUkuTzfZxwl5akYdgfHywOHl7A8Ff06aemmA0XUmqdyjxwEmJacX 0Tyg== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=QIFSK7+q86peBNyVF83M929mz5YDWsMa1JplQe+w7Nk=; b=kV031gL+8s5sJwzFi3gje9Ux8x0Xx3QWYfmEk4+u9SpSGYUReaKx2o8ODRdT+/A2Ui P4QOjV61f2pL73peZDwXVhtedUDlNJPui8NpCAqEeWD7xAcItyGjCajFernqfQmCX+lj RG7kIA3/tv8TXdW+6J+ftyzsFzTykZrbfWshrSxt2COh0htlmVsDShXfWC+vB3ml5FpC yWKyv6MWkj5Oxv/DPjRNXw3P7gHrVgn2zgF5HEYYYcjmqTz9EV0ovGrSR9X1zdw34rcF sRp4JueR/78RzP782s+sjMlEmox13Him5kSr3F3wHoh7TjPbGQcR0V8vZT/sIXv/zj4S aGTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=Inf+g6tx; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020a63a547000000b003db8a4dfb6esi14882890pgu.422.2022.05.24.11.12.27; Tue, 24 May 2022 11:12:40 -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=@ziepe.ca header.s=google header.b=Inf+g6tx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238132AbiEXOTm (ORCPT + 99 others); Tue, 24 May 2022 10:19:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234426AbiEXOTl (ORCPT ); Tue, 24 May 2022 10:19:41 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4FDD5E77B for ; Tue, 24 May 2022 07:19:39 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id l82so10416597qke.3 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=CzKNrbHH1MiPUGb4K+QIEWm0OJ+Ij2cYSeXgIu41HiYvHCmOW09XDXWTAZHB/R4Dqv LMaDV3oTOs8nfD+A4kULU+PfwGxJBv/cZUSgwPz2sAshxubr3zOrqOWLBgBBD5KlHxV/ sA1fDBoL1rFITcvviJN2LFBF/8qBhp0pIVS7dQtCyuW6PnLKWrdvIuOEYb6MmehElgIM HhRnaVwCrNzFkFXENYN2VB6FcUXzY2BhAZiJ8mu1VNJtcazVjCW+gXja/PSY7AUUkaxs 3mXJyu9nplMIpuTpmD/ro6UawsWCN8GoD1Jy3owrmO3qwcxDME4u8mZrzFJIxZBRTPEi MLlA== X-Gm-Message-State: AOAM530A038VoBMt2+yf+NsXptm2TOjQIUOmLN+QDacDa9De1nydYM9R UNotWN1FLS9NX5QdaXHdUBC/iA== 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 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