Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2100555rwi; Tue, 1 Nov 2022 04:00:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4OeRlcAniGKb9QQGgC4PRSAsEXhkbPqKLBW2weWbq7nptGtjC0lRcrrbbfuveSgKW1VY5r X-Received: by 2002:a17:906:a29a:b0:7a1:2691:ed72 with SMTP id i26-20020a170906a29a00b007a12691ed72mr97200ejz.558.1667300428184; Tue, 01 Nov 2022 04:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667300428; cv=none; d=google.com; s=arc-20160816; b=z47qb2DpjBJksktUPZ1co5Q0fSHw3AlalMTFwi4dIJRCnzM/iTbN8N9XFopdIF9o8V Ms8e0yJt6ZmcJONzEQ+/pKB8LjxtwHVKXVxE4oWnanFSCIRr9zHC6rpIdWBoM3zFWoJ6 C86TRXcx0alJHEQnyL/nS/+U/t9B37PxE7SCVgqqZQqvjMaPkChrVTTtFSMu+Q45pAUt pz6EUME+pl3eHNgzZMsDl/Ep3hI4DuiQOjJMGjOLWjCdeXTJXaCOTiINxOL28nGmTzTz /HG/K7N/11LB2Tc8AVtWxkIhKEmkwLCQ1v3gbYYR3EY88LYrUGPqw4C4IOfgHzvaXO2y 5Lvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=4AYR/2JvaykvXlrOwQjGO9kw2CMZTMBn6zXsJGS+cWc=; b=fODzZz7XmV2sGUoK3ShHXDp6FTK10BMf2j+Z3kgsGbbswvGN3t5q37bLgGclOByKcq 8U8GwmpFe8shHg35sbfReHZURQJ3EO5UlwrKO8zFs86gx5/tSDaM/9h25Xyeg4V5MJqy cx3DRruFPWW/13vnhVhTQMG7FGruvYqB1WzBqK9KAAHRITvcAhd0lJWTSL+lNQ7rcNqE sGA2dQqTf/KtiZcL+1LLkhjkJK0tvMDUW/4oYhvezW2F6OuY/TnIhxfMfD0xKMz1yAEv 32FtwwbRFfIxc1Q6rEgOUNol2m+15o320yeSpP/Q2pgpzLKRdSEhSIP2x0qlFjzy3IAl 1Qvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht9-20020a170907608900b007470b52f94esi12399084ejc.199.2022.11.01.04.00.03; Tue, 01 Nov 2022 04:00:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230002AbiKAJ4L (ORCPT + 97 others); Tue, 1 Nov 2022 05:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbiKAJ4I (ORCPT ); Tue, 1 Nov 2022 05:56:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06DF313F79 for ; Tue, 1 Nov 2022 02:56:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A02B56153B for ; Tue, 1 Nov 2022 09:56:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A48AC433D6; Tue, 1 Nov 2022 09:56:04 +0000 (UTC) Date: Tue, 1 Nov 2022 09:56:01 +0000 From: Catalin Marinas To: mawupeng Cc: muchun.song@linux.dev, songmuchun@bytedance.com, anshuman.khandual@arm.com, akpm@linux-foundation.org, mike.kravetz@oracle.com, mhocko@suse.com, osalvador@suse.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH -next 1/1] mm: hugetlb_vmemmap: Fix WARN_ON in vmemmap_remap_pte Message-ID: References: <20221025014215.3466904-1-mawupeng1@huawei.com> <614E3E83-1EAB-4C39-AF9C-83C0CCF26218@linux.dev> <1b2e03b2-5e91-2e60-82d0-ea111840c81d@huawei.com> <305231eb-e46a-9295-a845-73237c98855b@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <305231eb-e46a-9295-a845-73237c98855b@huawei.com> X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 29, 2022 at 09:55:15AM +0800, mawupeng wrote: > On 2022/10/26 11:01, mawupeng wrote: > > On 2022/10/25 14:36, Muchun Song wrote: > >>> On Oct 25, 2022, at 09:42, Wupeng Ma wrote: > >>> > >>> From: Ma Wupeng > >>> > >>> Commit f41f2ed43ca5 ("mm: hugetlb: free the vmemmap pages associated with > >>> each HugeTLB page") add vmemmap_remap_pte to remap the tail pages as > >>> read-only to catch illegal write operation to the tail page. > >>> > >>> However this will lead to WARN_ON in arm64 in __check_racy_pte_update() > >> > >> Thanks for your finding this issue. > >> > >>> since this may lead to dirty state cleaned. This check is introduced by > >>> commit 2f4b829c625e ("arm64: Add support for hardware updates of the > >>> access and dirty pte bits") and the initial check is as follow: > >>> > >>> BUG_ON(pte_write(*ptep) && !pte_dirty(pte)); > >>> > >>> Since we do need to mark this pte as read-only to catch illegal write > >>> operation to the tail pages, use set_pte to replace set_pte_at to bypass > >>> this check. [...] > IMHO, arm64 or other archs do some work on the dirty bit and rdonly bit in > pte in commit 2f4b829c625e ("arm64: Add support for hardware updates of the > access and dirty pte bits"). > > Maybe we can use pte_wrprotect() to mark this pte read-only? It will add > PTE_DIRTY bit for the new pte entry compare to the old one. > > Here is the diff: > > diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c > index ba2a2596fb4e..24a230895316 100644 > --- a/mm/hugetlb_vmemmap.c > +++ b/mm/hugetlb_vmemmap.c > @@ -244,8 +244,7 @@ static void vmemmap_remap_pte(pte_t *pte, unsigned long addr, > * Remap the tail pages as read-only to catch illegal write operation > * to the tail pages. > */ > - pgprot_t pgprot = PAGE_KERNEL_RO; > - pte_t entry = mk_pte(walk->reuse_page, pgprot); > + pte_t entry = pte_wrprotect(mk_pte(walk->reuse_page, PAGE_KERNEL)); This may silence the warning but we plan to add another to detect a change in the pfn without going through a break-before-make sequence. -- Catalin