Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2207114ybb; Sat, 21 Mar 2020 15:47:41 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuQOhoBpJOMepugf1qeuFUmnspLipiQT71CUNKyVvlP0hjiISzuqDfjsC37wGkgCM2GwVbb X-Received: by 2002:a9d:53c4:: with SMTP id i4mr13286785oth.48.1584830861117; Sat, 21 Mar 2020 15:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584830861; cv=none; d=google.com; s=arc-20160816; b=YhgsG7zk3oaUKatJdshHDTOQhfaMJgxa2OyB2t+20SvXbONXiMkD1WT5K52H2PxdIg EsG5sjgyfiqxSnzSuGDV4QlBRKhrFRK/x+BaFKi85N295vuwa4kAQ6UIPcDKCoM+LXcw tiLOnTnmS4D6+FKg3Ei4avfyN6AnIWSL0DAbn/8zRuLFTIQ65nMerlRC0WoABjVO6xSM P3CTPFftv+KHD5oGTxvSGt5b/MyQKOYN+5ZrFS485dGtGJed27WThDr5d6I7Z4ytR29w wULPX+w3uBVq/QNDo/RUQuRN8N0EOw67NZWF8zvAf+pXNeltphl7fF2CTDA8jI6+qmk9 3HOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=tObw2BxaqMGvgTde3/6XgPvAZdTmDg8WjTnQvHQ4KrQ=; b=AB45bSOywdN3OXhFA9F1hex6f9n8tDqYebQJNFfwRVRAz8XF74cfI72HcaAGORSVBQ ncUrpARekWiZBq6CzXFl49pJMntHr++iLHvCBQTCD4fad25mVq3Qz+LMTPqkWDwwNl+p K6so1z3tN1Hxx90jd3bQ2SM4pY8txe2Eynx2CvXa2hi43r8LxvgUSbrsUvV58z9jYovS 3lB0H7fmPsTiZ5czMrB3SjWHKuoK+7sNHZbFP8hPhxp2pGdIo3mAMa+MGHUgdHP2tf7l 23UNZIiqgu+dlFv991VFBQw5b5SMI0hFfYwJFOtDEQ51PeV9QcxtpXuGlUrbxlHOjBCY zDUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Yg0udSPD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11si4971415oib.32.2020.03.21.15.47.04; Sat, 21 Mar 2020 15:47:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Yg0udSPD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728101AbgCUWqq (ORCPT + 99 others); Sat, 21 Mar 2020 18:46:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:56994 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726859AbgCUWqq (ORCPT ); Sat, 21 Mar 2020 18:46:46 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C425E20754; Sat, 21 Mar 2020 22:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584830805; bh=pBP/6b4ajfKJCuF6Edxia1qiK6WLfxFlX24bBcuc9dY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Yg0udSPDLvx9DBCpAS4miIQcR5my3Wgw5OgVsuwCeEHl3PEU5nW/yxpZ1ta/O3PqT 2VkvG93i+WOHoL0LiinoUqBAndeB6sqyl9BMeBmJxGy7RZmu+3jGlmTBVQ75eFy86N HjQsE/5wuMkFKDW1r/OxKU9b0IbpsHSa7H5C78H0= Date: Sat, 21 Mar 2020 15:46:44 -0700 From: Andrew Morton To: Mike Kravetz Cc: "Longpeng (Mike)" , Matthew Wilcox , Qian Cai , kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, arei.gonglei@huawei.com, weidong.huang@huawei.com, weifuqiang@huawei.com, kvm@vger.kernel.org, linux-mm@kvack.org, Sean Christopherson , stable@vger.kernel.org Subject: Re: [PATCH v2] mm/hugetlb: fix a addressing exception caused by huge_pte_offset() Message-Id: <20200321154644.bcbedca64f620d3cbe215231@linux-foundation.org> In-Reply-To: <1b61f55a-d825-5721-2bfe-5e0efc9c9c2d@oracle.com> References: <20200222170222.GJ24185@bombadil.infradead.org> <1b61f55a-d825-5721-2bfe-5e0efc9c9c2d@oracle.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 27 Feb 2020 13:41:46 -0800 Mike Kravetz wrote: > > Secondly, huge_pte_offset in mm/hugetlb.c is for ARCH_WANT_GENERAL_HUGETLB, many > > architectures use it, can you make sure there is no issue on all the > > architectures using it with all the version of gcc ? > > > > Thirdly, there are several places use READ_ONCE to access the page table in mm/* > > (e.g. gup_pmd_range), they're also generical for all architectures, and they're > > much more like unnecessary than here, so why there can use but not here? What's > > more, you can read this commit 688272809. > > Apologies for the late reply. > > In commit 20a004e7 the message says that "Whilst there are some scenarios > where this cannot happen ... the overhead of using READ_ONCE/WRITE_ONCE > everywhere is minimal and makes the code an awful lot easier to reason about." > Therefore, a decision was made to ALWAYS use READ_ONCE in the arm64 code > whether or not it was absolutely necessary. Therefore, I do not think > we can assume all the READ_ONCE additions made in 20a004e7 are necessary. > Then the question remains, it it necessary in two statements above? > I do not believe it is necessary. Why? In the statements, > if (!pgd_present(*pgd)) > and > if (!p4d_present(*p4d)) > the variables are only accessed and dereferenced once. I can not imagine > any way in which the compiler could perform multiple accesses of the variable. > > I do believe the READ_ONCE in code accessing the pud and pmd is necessary. > This is because the variables (pud_entry or pmd_entry) are accessed more than > once. And, I could imagine some strange compiler optimization where it would > dereference the pud or pmd pointer more than once. For this same reason > (multiple accesses), I believe the READ_ONCE was added in commit 688272809. > > I am no expert in this area, so corrections/comments appreciated. > > BTW, I still think there may be races present in lookup_address_in_pgd(). > Multiple dereferences of a p4d, pud and pmd are done. Based on Mike's observations I shall drop this patch. If we still believe it is needed, please enhance the changelog, resend and let's take another look.