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 84A6FC433F5 for ; Tue, 24 May 2022 15:43:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF5708D0003; Tue, 24 May 2022 11:43:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA0848D0001; Tue, 24 May 2022 11:43:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98E158D0003; Tue, 24 May 2022 11:43:31 -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 872C28D0001 for ; Tue, 24 May 2022 11:43:31 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 3E4501205E5 for ; Tue, 24 May 2022 15:43:31 +0000 (UTC) X-FDA: 79501056222.09.EB47CAC Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf19.hostedemail.com (Postfix) with ESMTP id 2AEFA1A00DF for ; Tue, 24 May 2022 15:43:18 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id l7-20020a17090aaa8700b001dd1a5b9965so2539799pjq.2 for ; Tue, 24 May 2022 08:43:30 -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=pf0+E+bPvDSgYa/T7iTzIo9HKHg3McchanAWaQlbysQ=; b=B5MiMKVQlemTDS03gOO/L3KJ9t7GDmbf79xoMfDT2pfTS1Vq3o0JFHoY7NhoPXPN3Q bjRJfqbbcNyYGviExfIPZtiXa5AgXYL8e+4ig+ySXNpoa3BhMeMTypPT2jcwFqTK+wT1 +AtNYgGdF094q1EvfUsc2ZWZuvdjqoS4fBuo/gj5qR3euhWvR2yDH28pkDLknWOlCHxe nYYZH+uohQSCficiCRJcW4R3iS8uAjG/lDgSA184BZo8Yn91hjigBNPZuLmAhZPat8Aq thtcd4Q9lyaAiCrccollE1aIqU2wae4maucrm+Ts4rKdcQaAuHo+vA99qDMmfWGfn0Cp KodA== 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=pf0+E+bPvDSgYa/T7iTzIo9HKHg3McchanAWaQlbysQ=; b=M2UQRlSmpWP68pLbxM4YRTGVlDjWtO0U1GjDpSekq/k5Ex9UxzPFLSnPi7XWzchKXp yYc+dV+dgXgN716X1hSTSy1c0kQdeoxXqELLPH8vx8KbYEgnlipZrf5Vl5rdCcJjCpu7 PeTRiLRO7LGdqygDE+MBdb6DyPEd6M7+He8RTuZWkuxnX3rem2iM0e5DEyFnW5rKDBrL gBAV4yvyAiIfw+CNgy1WmBVskG0tuVvJgCfwdrdGXbiX9uTcpKfnKYNrhR4nMoDEpmAf h7pKwsP8TieuctjEKxLn6INYVTf5BCcaE4TcCEIneOJFvyPWKtjJEtYgoafQ8+2i2QlT y/Tg== X-Gm-Message-State: AOAM530wftnPZ0pQtkq8U6pu1Fo+Jzn+eK2T30e+FpcQ2QstTMWeY+qD ySMue2wWonnXoqh0ukdwQDM= X-Google-Smtp-Source: ABdhPJx8hC6Hbv5o9ECk8v8Rv0hySyLeU0gITGRF2Cj+MALKpzJkb6XVz8ARiwmqWuy0Q0pY0vfO0Q== X-Received: by 2002:a17:902:d58f:b0:161:9abd:cff1 with SMTP id k15-20020a170902d58f00b001619abdcff1mr27696008plh.135.1653407009504; Tue, 24 May 2022 08:43:29 -0700 (PDT) Received: from google.com ([2620:15c:211:201:20f:8bc7:9098:371f]) by smtp.gmail.com with ESMTPSA id i23-20020a056a00225700b0050dc7628168sm9506489pfu.66.2022.05.24.08.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 08:43:28 -0700 (PDT) Date: Tue, 24 May 2022 08:43:27 -0700 From: Minchan Kim To: Jason Gunthorpe 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: 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: <20220524141937.GA2661880@ziepe.ca> Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=B5MiMKVQ; spf=pass (imf19.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.216.43 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: u1srgjs3nuot4cojzxydnagcdce9q4fr X-Rspamd-Queue-Id: 2AEFA1A00DF X-Rspamd-Server: rspam01 X-HE-Tag: 1653406998-338975 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 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 > > > 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? 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? If the load tearing would still happens in the bitmap, it would be better to keep last suggestion from John. + /* + * This races, without locks, with set_pfnblock_flags_mask(). Ensure + * a consistent read of the memory array, so that results, even though + * racy, are not corrupted. + */