From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B69AA3B0AE5 for ; Mon, 11 May 2026 08:18:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778487544; cv=none; b=XNAYSdh6J85HbfOUWapegKecR55c/LtCDwIiK01roMe2/dolXpQ5ZhY8uXeAPGxDc9fCA0mbtoluxjJr0bygJauhloAe4nphJC0lpGokwkGWmShMHBFdF8dcajfwVblcZytx2hsHPtG4o3STCGcoyE/qM5InjYCAzV72bvHu9Lk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778487544; c=relaxed/simple; bh=3Qk0rhC0x0MmkiwJFCNV/yWVxTDnzu2XXnAciL+iVZA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gXkO0Lof6+235/hF0ZwGNMCCSAOpWjOyt4acdrF0IUWLoLjaAYvkw21V1qxM53NT+77wIsbwDZFHCvNWfpVaJysGjXc6y9Ntb6rvjBiz1y/WraeKnCpCJNV48SsEzui6SeRcvIuJOH7mjNOOe0kHBL81oBGRCOhJJr5kKniefmo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=epGTUN05; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="epGTUN05" 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 8FA9E1713; Mon, 11 May 2026 01:18:47 -0700 (PDT) Received: from [10.164.148.37] (MacBook-Pro.blr.arm.com [10.164.148.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 64D163F7B4; Mon, 11 May 2026 01:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778487532; bh=3Qk0rhC0x0MmkiwJFCNV/yWVxTDnzu2XXnAciL+iVZA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=epGTUN05kehIbYfaoSskXQTPl16giKeapCElsPK+msLNWWa83OCWnMf5P2VSFnDLB oTGvj8cVFncOae/jEbjCnJpkuVnO7ELjYAh1ibBVy54OlKFJC/DXnIa0PGS6ELUihA oVcub2cB++Nrclu4uAYeqHJ/NdI3M3MtuZw5cqJs= Message-ID: <06029485-9e85-4d2d-a324-abba918eecf3@arm.com> Date: Mon, 11 May 2026 13:48:39 +0530 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 v3 1/9] mm/rmap: initialize nr_pages to 1 at loop start in try_to_unmap_one To: "David Hildenbrand (Arm)" , akpm@linux-foundation.org, ljs@kernel.org, hughd@google.com, chrisl@kernel.org, kasong@tencent.com Cc: riel@surriel.com, liam@infradead.org, vbabka@kernel.org, harry@kernel.org, jannh@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, rppt@kernel.org, surenb@google.com, mhocko@suse.com, baolin.wang@linux.alibaba.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, bhe@redhat.com, youngjun.park@lge.com, pfalcato@suse.de, ryan.roberts@arm.com, anshuman.khandual@arm.com References: <20260506094504.2588857-1-dev.jain@arm.com> <20260506094504.2588857-2-dev.jain@arm.com> Content-Language: en-US From: Dev Jain In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 11/05/26 12:18 pm, David Hildenbrand (Arm) wrote: > On 5/6/26 11:44, Dev Jain wrote: >> Initialize nr_pages to 1 at the start of each loop iteration, like >> folio_referenced_one() does. >> >> Without this, nr_pages computed by a previous folio_unmap_pte_batch() call >> can be reused on a later iteration that does not run >> folio_unmap_pte_batch() again. >> >> I don’t think this is causing a bug today, but it is fragile. >> >> A real bug would require this sequence within the same try_to_unmap_one() >> call: >> >> 1. Hit the pte_present(pteval) branch and set nr_pages > 1. >> 2. Later hit the else branch and do pte_clear() for device-exclusive PTE, >> and execute rest of the code with nr_pages > 1. > > Right, for hugetlb folios it should always stay at 1. > >> >> Executing the above would imply a lazyfree folio is mapped by a mix of >> present PTEs and device-exclusive PTEs. > > Why lazyfree? We use nr_pages also for > > folio_remove_rmap_ptes(folio, subpage, nr_pages, vma); > > and > > folio_put_refs(folio, nr_pages); > > Given that make_device_exclusive() operates on individual PTEs, wouldn't it be > possible to trigger that? At the point of this patch, batching is supported for lazyfree and file folios. make_device_exclusive does not operate on file folios. > >