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 E4EE1C38A2D for ; Wed, 26 Oct 2022 08:53:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 629ED8E0002; Wed, 26 Oct 2022 04:53:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D9968E0001; Wed, 26 Oct 2022 04:53:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A1998E0002; Wed, 26 Oct 2022 04:53:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 382E48E0001 for ; Wed, 26 Oct 2022 04:53:52 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0295DC0AB0 for ; Wed, 26 Oct 2022 08:53:51 +0000 (UTC) X-FDA: 80062487904.24.70CFF1A Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf10.hostedemail.com (Postfix) with ESMTP id 599A6C0039 for ; Wed, 26 Oct 2022 08:53:51 +0000 (UTC) Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1666774429; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RXR/lAFz86mG9q2ZJofRnpXszeaU/ER/Y/nKQPHzKgU=; b=PU+hs6TreoiqzMMQOr/t4miTssPjIWp6M9N6LFYYkFXeFWIWsrWAFDeY4PWtwjl5FNH5pw IQLPcYoGYcCPHB6OqWLe4pJ0kyvRVrtgUt64quQfC69Al84Nya8BOPDUGzMxrdh4djgRLH x4UHdnSr4MxQDSWb+soL4BFTbsfoxLE= Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.200.110.1.12\)) Subject: Re: [PATCH -next 1/1] mm: hugetlb_vmemmap: Fix WARN_ON in vmemmap_remap_pte X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <3c545133-71aa-9a8d-8a13-09186c4fa767@arm.com> Date: Wed, 26 Oct 2022 16:53:33 +0800 Cc: Wupeng Ma , Andrew Morton , Mike Kravetz , Muchun Song , Michal Hocko , Oscar Salvador , catalin.marinas@arm.com, Linux Memory Management List , linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <46A852E1-B19E-4ABE-B96C-992DC7C67414@linux.dev> References: <20221025014215.3466904-1-mawupeng1@huawei.com> <614E3E83-1EAB-4C39-AF9C-83C0CCF26218@linux.dev> <35dd51eb-c266-f221-298a-21309c17971a@arm.com> <3D6FDA43-A812-4907-B9C8-C2B25567DBBC@linux.dev> <3c545133-71aa-9a8d-8a13-09186c4fa767@arm.com> To: Anshuman Khandual X-Migadu-Flow: FLOW_OUT ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666774431; a=rsa-sha256; cv=none; b=URpKfrOrxYk066fkUZnsJAk9mBeW/6+h9+nMG8JtiQ4a77JnBhlUIatITFhWAVrrnaj9g7 AITG6x2YG963EXbVYeYJsERGvpRibCg6XwvE1yTL8nGHY+Aq7AOIQi+r1AKAKL8d21SkOq dMESs5yrEHeuLKYpo9Q+o3wVcpW0u0M= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=PU+hs6Tr; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of muchun.song@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=muchun.song@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666774431; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RXR/lAFz86mG9q2ZJofRnpXszeaU/ER/Y/nKQPHzKgU=; b=RKQdiEdfiafA0m7kOi+SHT2wFm0+zXF14hV15L+MIUMl3qRZjZ+5KTFXqAewcI2/tZJ66t hVlX56RLvZ07JyjZNBBSkSzJ+dUYDPpHuhf6zA2Anh5LS3hXh0JyexZ/+KHs1wf6gEaWrV dmti7s2IL8BHA7pWku0LdHxuYQLVgp0= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 599A6C0039 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=PU+hs6Tr; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of muchun.song@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=muchun.song@linux.dev X-Stat-Signature: 6pyo39ohxw6hq9fpsc3jrr9cwej8y17j X-HE-Tag: 1666774431-300344 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 Oct 26, 2022, at 16:36, Anshuman Khandual = wrote: >=20 >=20 >=20 > On 10/26/22 12:31, Muchun Song wrote: >>=20 >>=20 >>> On Oct 26, 2022, at 13:06, Anshuman Khandual = wrote: >>>=20 >>>=20 >>>=20 >>> On 10/25/22 12:06, Muchun Song wrote: >>>>=20 >>>>=20 >>>>> On Oct 25, 2022, at 09:42, Wupeng Ma wrote: >>>>>=20 >>>>> From: Ma Wupeng >>>>>=20 >>>>> 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. >>>>>=20 >>>>> However this will lead to WARN_ON in arm64 in = __check_racy_pte_update() >>>>=20 >>>> Thanks for your finding this issue. >>>>=20 >>>>> 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: >>>>>=20 >>>>> BUG_ON(pte_write(*ptep) && !pte_dirty(pte)); >>>>>=20 >>>>> 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. >>>>=20 >>>> In theory, the waring does not affect anything since the tail = vmemmap >>>> pages are supposed to be read-only. So, skipping this check for = vmemmap >>>=20 >>> Tails vmemmap pages are supposed to be read-only, in practice but = their >>> backing pages do have pte_write() enabled. Otherwise the = VM_WARN_ONCE() >>> warning would not have triggered. >>=20 >> Right. >>=20 >>>=20 >>> VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte), >>> "%s: racy dirty state clearing: 0x%016llx -> = 0x%016llx", >>> __func__, pte_val(old_pte), pte_val(pte)); >>>=20 >>> Also, is not it true that the pte being remapped into a different = page >>> as read only, than what it had originally (which will be freed up) = i.e=20 >>> the PFN in 'old_pte' and 'pte' will be different. Hence is there = still >>=20 >> Right. >>=20 >>> a possibility for a race condition even when the PFN changes ? >>=20 >> Sorry, I didn't get this question. Did you mean the PTE is changed = from >> new (pte) to the old one (old_pte) by the hardware because of the = update >> of dirty bit when a concurrent write operation to the tail vmemmap = page? >=20 > No, but is not vmemmap_remap_pte() reuses walk->reuse_page for all = remaining > tails pages ? Is not there a PFN change, along with access permission = change > involved in this remapping process ? Alright, yes, both the PFN and the access permission are changed.