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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A10FEFA373D for ; Tue, 1 Nov 2022 09:56:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E89186B0072; Tue, 1 Nov 2022 05:56:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E398B6B0073; Tue, 1 Nov 2022 05:56:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D27D96B0074; Tue, 1 Nov 2022 05:56:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C31C06B0072 for ; Tue, 1 Nov 2022 05:56:10 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8CB8612060E for ; Tue, 1 Nov 2022 09:56:10 +0000 (UTC) X-FDA: 80084417700.14.10A810C Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf08.hostedemail.com (Postfix) with ESMTP id EA9AE160016 for ; Tue, 1 Nov 2022 09:56:09 +0000 (UTC) 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 ams.source.kernel.org (Postfix) with ESMTPS id 5952AB81C58; Tue, 1 Nov 2022 09:56:08 +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> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667296570; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4AYR/2JvaykvXlrOwQjGO9kw2CMZTMBn6zXsJGS+cWc=; b=q6YX0ehgIF5OgPNHGVCOSwNC8wZsSNFUWiJVFZeMQIUv/m2+nwS1AXA2FVuWHGRxVXPtsN PBGg23Xl6+GcAbDooCTwh0j/6nNtsA4UOnoYe27E4VqweCG76A8m6+2vODzE0bWMri8XNY HsBqLXPr0dVu10s/8Yvph3gUawasdwQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667296570; a=rsa-sha256; cv=none; b=WsCZNFN541MCdVggQyf76SsM9O7Ax2IKN9H7KU0e94Q60dA7A5w2nvpPS22HmRhXHc6IGD KzWPuQyf+f3QpzVkTOHeHv/CWL8aBb/egjp7Vsn4S+s7+GTefbneqzEq9eEQycNtkaceD3 m/0NfyL3iYyUY9GwRraFyQuczAwKRdQ= X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EA9AE160016 Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-Stat-Signature: 6h5dgyxe3mctu419j13i7hp3h5tg7wxs X-HE-Tag: 1667296569-58056 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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