Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp38412ybv; Fri, 21 Feb 2020 22:35:43 -0800 (PST) X-Google-Smtp-Source: APXvYqxFRQjhwJfSj/e9+6u1mlXgnIo3nwxc7+TJOJb07cP8mpSPPyS+p78mJDAmU4q6M9KmCeTW X-Received: by 2002:aca:3017:: with SMTP id w23mr4995210oiw.152.1582353343397; Fri, 21 Feb 2020 22:35:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582353343; cv=none; d=google.com; s=arc-20160816; b=aRDbbq2vk4e7EAbp5GZL1Q16WBi3o7Bs49lAH60e2uXfL64RQXvpzS1MHJWY2km4bf CRDQy7Ah2YFDG/fAVCmfDZImDRv7XAQCTruxI7Tth7eN/KYWVglybhxgb1s2LpWaS08w ZDJuar4bAO86ukmV50V+NHUEXRzFyJNgHNpub8OQHkNkBfS3HBF6zpWPc2yCjxXuaEjS JhYVtIboWNOtg4PJBkDpHIKCtyYSWBNzQLvYeNohfUXcXN0uzMhV6Enbd3T351Nbln2i BM0Av6hZGDf9qvselU2Poi1FVAyIH1wwmyAcpW7xBEfJA5XbFCgihTfbs7klEYM04AYC Jq7w== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=hyz9luJUfLT6wQ/pX5czBAk4gJcLSpKt3nsvtmNIqEM=; b=FjKpoG3agGLtLf1KxFp0e88UFrOheiUe2grin/6r+H/OB2XFa5KucX/B6DeUJGik/d KgayFQ9reIJlAQV7e6MtYjK1poo8bVBfAb8A2XEnPx6y00xBFM2Q+vTvmHLVP+6ClPxP FIZGPq2GwkQ7xg2sSBlOjk2prpkJgXx8doyhY+PXJ3YYW0MbR9/f64Jp9d5FvKdy8RxY NCr57Wzt1shX8aHGzUustPRB2hfRmH8lEHDQQglPHfTondybejJ9yoMxjCrCag6rhdJ+ 97YCR4jAQIIJJAjvUvfAxOgjdLzW+d0oaoi4fYQkSTIb2LohttRrOCez+DftIASQbzI6 /mUA== ARC-Authentication-Results: i=1; mx.google.com; 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 7si1945119oij.29.2020.02.21.22.35.29; Fri, 21 Feb 2020 22:35:43 -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; 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 S1727044AbgBVGd3 (ORCPT + 99 others); Sat, 22 Feb 2020 01:33:29 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:44120 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726684AbgBVGd3 (ORCPT ); Sat, 22 Feb 2020 01:33:29 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 315C9FA8F813A2B4B96F; Sat, 22 Feb 2020 14:33:20 +0800 (CST) Received: from [127.0.0.1] (10.177.246.209) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.439.0; Sat, 22 Feb 2020 14:33:11 +0800 Subject: Re: [PATCH v2] mm/hugetlb: fix a addressing exception caused by huge_pte_offset() To: Qian Cai CC: , , , , , , , , , "Matthew Wilcox" , Sean Christopherson , References: From: "Longpeng (Mike)" Message-ID: Date: Sat, 22 Feb 2020 14:33:10 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.177.246.209] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 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 -- Regards, Longpeng(Mike)