From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 508DD308F05 for ; Mon, 9 Feb 2026 10:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770632012; cv=none; b=Sc3BWPwSZhY2PT456Hn0Gmn954voymyAUPAvH61C+oXV/AXxfKLz4J8A2i4mE/sj/4r87BebYF3jqtOw0iTHiznIvb1P9DoB6ydX5KX70UDmnXc67CEdwS9InaAppIbvO/+buCVqh8I0hPW9772O06ez6KXzI2OIb4PaavRMZd4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770632012; c=relaxed/simple; bh=Nd44YZ+26oYO+tXA/V6CriG+q5taqx0FKp8KfCLqpLg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UjtAq/oawasT4QMDshzxN6NM0JVEaZU9c71xEr0979AfkEwsiZWqIMvuM4jMGRefxAmuwHBUA3nbIN2y5XlS7z1LsxrePb+cOEy1Q2sJnnXhBocOEOwuw6mHUpRQTiOnM0pLt9zLeQGnvIi358d7TGPPe8+Ofw3gSNKKjDj1w60= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=r9JhN7La; arc=none smtp.client-ip=115.124.30.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="r9JhN7La" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1770632003; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=KuHdmbMe8FhR6HcphPrJrW4PyN3G5yZpYJxJ7bkfPFc=; b=r9JhN7LagucDS/mcNXWlPbnNp4akRDHHOKwUnv7wRfxu/NmLO8Hn0y34HxdSGa+DOKYMtY/u8xZMBkPt6jmeFxtYpI0S7EKtvduVawSCoKEBsZgQe1S7wk/9c0RxOUHwNHcsBbTQYMK7Bfp7TArGTrzKB9KK4F8iunckCsvIhoQ= Received: from 30.74.144.127(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WyqmBGB_1770632001 cluster:ay36) by smtp.aliyun-inc.com; Mon, 09 Feb 2026 18:13:21 +0800 Message-ID: <6817c7b9-e67c-46b6-b3b5-1bc3d9eed4a2@linux.alibaba.com> Date: Mon, 9 Feb 2026 18:13:19 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/5] arm64: mm: implement the architecture-specific clear_flush_young_ptes() To: "David Hildenbrand (Arm)" , Chris Mason Cc: akpm@linux-foundation.org, catalin.marinas@arm.com, will@kernel.org, lorenzo.stoakes@oracle.com, ryan.roberts@arm.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, riel@surriel.com, harry.yoo@oracle.com, jannh@google.com, willy@infradead.org, baohua@kernel.org, dev.jain@arm.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <9d866a2644051e13a41ef4d6ca3909c6e1f9e229.1766631066.git.baolin.wang@linux.alibaba.com> <20260128114936.72280-1-clm@meta.com> <07d55759-a50a-457a-badd-85697174116f@kernel.org> <280ae63e-d66e-438f-8045-6c870420fe76@linux.alibaba.com> <16fb7985-ec0f-4b56-91e7-404c5114f899@kernel.org> From: Baolin Wang In-Reply-To: <16fb7985-ec0f-4b56-91e7-404c5114f899@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2/9/26 5:55 PM, David Hildenbrand (Arm) wrote: > On 2/9/26 10:36, Baolin Wang wrote: >> >> >> On 2/9/26 5:09 PM, David Hildenbrand (Arm) wrote: >>> On 1/29/26 02:42, Baolin Wang wrote: >>>> >>>> >>>> >>>> Indeed. I previously discussed with Ryan whether using pte_cont() >>>> was enough, and we believed that invalid PTEs wouldn’t have the >>>> PTE_CONT bit set. But we clearly missed the device-folio cases. >>>> Thanks for reporting. >>>> >>>> Andrew, could you please squash the following fix into this patch? >>>> If you prefer a new version, please let me know. Thanks. >>> >>> Isn't the real problem that we should never ever ever ever, try >>> clearing the young bit on a non-present pte? >>> >>> See damon_ptep_mkold() how that is handled with the flushing/notify. >>> >>> There needs to be a pte_present() check in the caller. >> >> The handling of ZONE_DEVICE memory in check_pte() makes me me doubt my >> earlier understanding. And I think you are right. >> >>      } else if (pte_present(ptent)) { >>          pfn = pte_pfn(ptent); >>      } else { >>          const softleaf_t entry = softleaf_from_pte(ptent); >> >>          /* Handle un-addressable ZONE_DEVICE memory */ >>          if (!softleaf_is_device_private(entry) && >>              !softleaf_is_device_exclusive(entry)) >>              return false; >> >>          pfn = softleaf_to_pfn(entry); >>      } >> >> >>> BUT >>> >>> I recall that folio_referenced() should never apply to ZONE_DEVICE >>> folios. folio_referenced() is only called from memory reclaim code, >>> and ZONE_DEVICE pages never get reclaimed through vmscan.c >> >> Thanks for clarifying. So I can drop the pte valid check. > > We should probably add a safety check in folio_referenced(), warning > if we would ever get a ZONE_DEVICE folio passed. > > Can someone look into that ? :) Sure, I can take a close look and address that in my follow-up patchset.