Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp360065rwi; Wed, 26 Oct 2022 01:42:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7wEU5SeyCZFfdr9uGcPTwZrRXuPtl/tabP0FOyzOscSpgC/KjyDxsa7iJ8Q638lpMcqz4S X-Received: by 2002:a17:906:db0e:b0:77b:82cf:54a6 with SMTP id xj14-20020a170906db0e00b0077b82cf54a6mr35577875ejb.691.1666773766110; Wed, 26 Oct 2022 01:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666773766; cv=none; d=google.com; s=arc-20160816; b=qF4ImBDV23368YCZHXHqgVe0MT2uMauXXGEr4E+YIdCvGWudCp+UHlF9KpstRT0Dps zFyXfbbfs1JbQ+dCTf6xB7TRuFZlUG6gxaU0F+DrzWNpG+gj7MYHh5ATErqrwaWHuMG9 FOK3G3Vsiyd4m5EsGpBRnB2GwUPIdHJR8AcsazKl44La966pSrwtVf2tofGWHKFB+3ol HTz6Z2aAFH9VmFkClBRZmNmZvbBqW5r9QUSQRFQ7eYhGbKeEAW6UEkhZnRnI4RvW7Wg6 O1fe8zBu1Zs5K0hGsI129aoutQr/XnBrTeSRaSrnGVpA+rWxL7QdlZDJTPMOxz8E5vD7 sjqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=iHufS2whdreYtdhYPJfeojBWCOrpClK1O+A7MBPwaN4=; b=FirW3WZQzpkl9JwV0vQV367t8ee+b43PuqM6xB/HtU41w7E4gOXo1WsfZC2zPEZz6a IuHN3oFcsbBj3DEw140b33g+OGbq3zGFMoJ7cEQyeX/snQ9nu+KHkKm8qx9oauuS/XBK kdPar9iCB76jiwD9yn7rpiTK79DQJMLSoFIxGUXohqCme/+f9k2iTpK9kYV+CjAOVPPt 4YTx9F3bL2qfXdefHPdoUenmB4IlSU6rEJ0g+fG2htNx6RKFSJ2ILWzcCThomqMrYahJ +StuSfR1aH9SVDEaujOp4xy5jL1aniYzScZhCS4m9QoT4vnfO2u4PtTdSOMqL4js/K+h +4gw== 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 jp19-20020a170906f75300b0078797f6668fsi4113571ejb.364.2022.10.26.01.42.19; Wed, 26 Oct 2022 01:42:46 -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 S232201AbiJZIgP (ORCPT + 99 others); Wed, 26 Oct 2022 04:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233256AbiJZIgI (ORCPT ); Wed, 26 Oct 2022 04:36:08 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8A15D4A801 for ; Wed, 26 Oct 2022 01:36:02 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3A25A23A; Wed, 26 Oct 2022 01:36:08 -0700 (PDT) Received: from [10.163.37.85] (unknown [10.163.37.85]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A5B563F792; Wed, 26 Oct 2022 01:35:58 -0700 (PDT) Message-ID: <3c545133-71aa-9a8d-8a13-09186c4fa767@arm.com> Date: Wed, 26 Oct 2022 14:06:00 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH -next 1/1] mm: hugetlb_vmemmap: Fix WARN_ON in vmemmap_remap_pte Content-Language: en-US To: Muchun Song 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 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> From: Anshuman Khandual In-Reply-To: <3D6FDA43-A812-4907-B9C8-C2B25567DBBC@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 10/26/22 12:31, Muchun Song wrote: > > >> On Oct 26, 2022, at 13:06, Anshuman Khandual wrote: >> >> >> >> On 10/25/22 12:06, 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. >>> >>> 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 >> >> 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. > > Right. > >> >> 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)); >> >> 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 >> the PFN in 'old_pte' and 'pte' will be different. Hence is there still > > Right. > >> a possibility for a race condition even when the PFN changes ? > > 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? 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 ?