Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp546781ybv; Sat, 22 Feb 2020 09:03:06 -0800 (PST) X-Google-Smtp-Source: APXvYqw2kKej0LLSagzeaopEYauzkYbvmPmlSLA9z/OWdW935JrhQyQIcP25wisASKV8Ex/jENiw X-Received: by 2002:a54:488d:: with SMTP id r13mr6512056oic.115.1582390986409; Sat, 22 Feb 2020 09:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582390986; cv=none; d=google.com; s=arc-20160816; b=BeON5lBJyvmFzIwH3k/4uBqY7E6RE0De5b3CB7KZk3piWavkizN1zTp99WEXTzVpFg wWw7YLM2UPG7wCf8/ZhIi7Rx2IOuXEzbtVvGfCQe+8R9SOiWNrMWqiPOvGBuEDiQRwn0 /TX0yYsXqG3OyTkv5d18XKguEmT7aj4ltTLWf2DNHccl2makhsAQTgB0mVcRn08uDrjl NmXDA8Z5uR4NbS01gIGl9fx9Ln8IYTegJEXWwcSgeRJyXVcmi1OYSvFafP9glFpE3WWZ KIh0xqfjFMPtID6dU8aZIUaJpBtyzw8tZBIWs5Cr5tDbqb7I+R4TFbiwHoD9FcB9SeOk sX8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SY35JLLv+vBVjF2AfSVM5A43C4jm9v1brv6q5yWkRzU=; b=AOlrs+ObDqkB8PhUzkp1kaHn9HPAQ1XzXAqPV6g8PGUs+pjiHSXqm/Anf370zABigs pHen9ELc7w99+ZXsEaz9qZao8lKIVLiwxn02SXq0DYv+/YrtmCOvrrXl2zxgx+FxhjA+ BdEM2K7iKbzRXe6pKY9auRLXZrLRTxWA0Itb1lkzCgpiJ4ITRpePtIp2LyKXZlEU5AX4 /BkiuzOgg7lRV1JlxzbmtRlGT+crSf0frTTpcwMBh2xCcRSMf4m157JVnlW5ybUYFj2d yDFmt/KivEA2uqgZ1vzeINnwTSZufkwT/qdd86Uw955sXNIXsa4LMQGJTm7Q3w0dJAxK taAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=cC5CpFYD; 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 t24si3713941oth.319.2020.02.22.09.02.52; Sat, 22 Feb 2020 09:03:06 -0800 (PST) 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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=cC5CpFYD; 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 S1726707AbgBVRCn (ORCPT + 99 others); Sat, 22 Feb 2020 12:02:43 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:54650 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726198AbgBVRCn (ORCPT ); Sat, 22 Feb 2020 12:02:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=SY35JLLv+vBVjF2AfSVM5A43C4jm9v1brv6q5yWkRzU=; b=cC5CpFYDWqcMFhwSbiePfLpJKa kwoTL5cYHcxmTKP4DMbY102XnLlQ1/AzXURwUHkNRRfyLgSJvx1zzHEhf3reZhSBiyR3e8zzxZAoe lVTUiNE3CXPjPBQntPEKui5NqJqN+VkYowNZbqQ1iFWjRy61gEIz7SI8cJH/Gf816sEfp7aV5upTJ mQzDU8DQZuG0Cz9vLDeWs37a/PRueidkzItJknwFV3xw3PrAsaobmY+hCTKsyAtHlJnVxOo7NEXsl umj5CTV59yw67b98GLGClqC66/erz7kWsWGm1tYystlInM0vFwwgmk85tI/OwDg0x2lSuGmpjJ9TR qVbURNWA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j5YAY-0005UU-St; Sat, 22 Feb 2020 17:02:22 +0000 Date: Sat, 22 Feb 2020 09:02:22 -0800 From: Matthew Wilcox To: "Longpeng (Mike)" Cc: Qian Cai , akpm@linux-foundation.org, mike.kravetz@oracle.com, 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: <20200222170222.GJ24185@bombadil.infradead.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 22, 2020 at 02:33:10PM +0800, Longpeng (Mike) wrote: > 在 2020/2/22 13:23, Qian Cai 写道: > >> On Feb 21, 2020, at 10:34 PM, Longpeng(Mike) wrote: > >> > >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c > >> index dd8737a..90daf37 100644 > >> --- a/mm/hugetlb.c > >> +++ b/mm/hugetlb.c > >> @@ -4910,28 +4910,30 @@ pte_t *huge_pte_offset(struct mm_struct *mm, > >> { > >> pgd_t *pgd; > >> p4d_t *p4d; > >> - pud_t *pud; > >> - pmd_t *pmd; > >> + pud_t *pud, pud_entry; > >> + pmd_t *pmd, pmd_entry; > >> > >> pgd = pgd_offset(mm, addr); > >> - if (!pgd_present(*pgd)) > >> + if (!pgd_present(READ_ONCE(*pgd))) > >> return NULL; > >> p4d = p4d_offset(pgd, addr); > >> - if (!p4d_present(*p4d)) > >> + if (!p4d_present(READ_ONCE(*p4d))) > >> return NULL; > > > > What’s the point of READ_ONCE() on those two places? > > > As explained in the commit messages, it's for safe(e.g. avoid the compilier > mischief). You can also find the same usage in the ARM64's huge_pte_offset() in > arch/arm64/mm/hugetlbpage.c I rather agree with Qian; if we need something like READ_ONCE() here, why don't we always need it as part of pgd_present()? It seems like an unnecessary burden for every user.