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 X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5DDAC34047 for ; Wed, 19 Feb 2020 12:52:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A62C020801 for ; Wed, 19 Feb 2020 12:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727716AbgBSMwx (ORCPT ); Wed, 19 Feb 2020 07:52:53 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:33276 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726491AbgBSMwx (ORCPT ); Wed, 19 Feb 2020 07:52:53 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E9F2C4E3A921C48424B1; Wed, 19 Feb 2020 20:52:12 +0800 (CST) Received: from [127.0.0.1] (10.177.246.209) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.439.0; Wed, 19 Feb 2020 20:52:03 +0800 Subject: Re: [PATCH] mm/hugetlb: avoid get wrong ptep caused by race To: Mike Kravetz CC: Matthew Wilcox , , , , , , , , Sean Christopherson References: <1582027825-112728-1-git-send-email-longpeng2@huawei.com> <20200218205239.GE24185@bombadil.infradead.org> <593d82a3-1d1e-d8f2-6b90-137f10441522@huawei.com> <8292299c-4c5a-a8cb-22e2-d5c9051f122a@oracle.com> From: "Longpeng (Mike)" Message-ID: <805f6f4b-af57-b08c-49c6-6c2f02ee2f96@huawei.com> Date: Wed, 19 Feb 2020 20:52:02 +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: <8292299c-4c5a-a8cb-22e2-d5c9051f122a@oracle.com> Content-Type: text/plain; charset="gbk" 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/19 11:49, Mike Kravetz дµÀ: > On 2/18/20 6:09 PM, Longpeng (Mike) wrote: >> ÔÚ 2020/2/19 4:52, Matthew Wilcox дµÀ: >>> On Tue, Feb 18, 2020 at 08:10:25PM +0800, Longpeng(Mike) wrote: >>>> { >>>> - pgd_t *pgd; >>>> - p4d_t *p4d; >>>> - pud_t *pud; >>>> - pmd_t *pmd; >>>> + pgd_t *pgdp; >>>> + p4d_t *p4dp; >>>> + pud_t *pudp, pud; >>>> + pmd_t *pmdp, pmd; >>> >>> Renaming the variables as part of a fix is a really bad idea. It obscures >>> the actual fix and makes everybody's life harder. Plus, it's not even >>> renaming to follow the normal convention -- there are only two places >>> (migrate.c and gup.c) which follow this pattern in mm/ while there are >>> 33 that do not. >>> >> Good suggestion, I've never noticed this, thanks. >> By the way, could you give an example if we use this way to fix the bug? > > Matthew and others may have better suggestions for naming. However, I would > keep the existing names and add: > > pud_t pud_entry; > pmd_t pmd_entry; > > Then the *_entry variables are the target of the READ_ONCE() > > pud_entry = READ_ONCE(*pud); > if (sz != PUD_SIZE && pud_none(pud_entry)) > ... > ... > pmd_entry = READ_ONCE(*pmd); > if (sz != PMD_SIZE && pmd_none(pmd_entry)) > ... > ... > Uh, looks much better. BTW, I missed one of your email in my mail client, but I find it in lkml.org. ''' I too would like some more information on the panic. If your analysis is correct, then I would expect the 'ptep' returned by huge_pte_offset() to not point to a pte but rather some random address. This is because the 'pmd' calculated by pmd_offset(pud, addr) is not really the address of a pmd. So, perhaps there is an addressing exception at huge_ptep_get() near the beginning of hugetlb_fault()? ptep = huge_pte_offset(mm, haddr, huge_page_size(h)); if (ptep) { entry = huge_ptep_get(ptep); ... ''' Yep, your analysis above is the same as mine, we got a 'dummy pmd' and then cause access a bad address. What's your opinion about the solution to fix this problem, not only huge_pte_offset, some other places also have the same problem(e.g. lookup_address_in_pgd) ? > BTW, thank you for finding this issue! > -- Regards, Longpeng(Mike)