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 3BFDF30FC34 for ; Wed, 10 Jun 2026 07:02:47 +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=1781074969; cv=none; b=UgvOD2YjSKBKh/f+wE61EguQfSCZwA6zldYljLmwLk2dUPHF4SfsZxrx2U7RfCqiORMRwbfRK2u+CLyxqTfdv9q5R0PnlTvKwwyDtPZQHiuJZghIziTCJvXQKek1SCxvAZTllEEh6VCpEXQQM+h61bLiYoN/fPQFBF4Og02MznE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781074969; c=relaxed/simple; bh=mjeJyLvpHgCIWn39mq3WZXEt/2CgxvbNKK+rP/DAWSI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=XoWhmvsGI5RQrDog0eYQi0fQ2UUQc7MNcjikSZ40yshGI+K2Q001BhFatOp8+9RIBh3Lus0lBheuUrvF/p1sUBKzW38nt4NVo1/ie+MjRqZPEyGGg3lH0e7SuHPLkrUX4ReGmrlFxItevnNBcZ+DSbCq+3HQE9mRkr3TdgSYlrk= 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=XxFrg+Dh; 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="XxFrg+Dh" 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 22FFB1570; Wed, 10 Jun 2026 00:02:41 -0700 (PDT) Received: from [10.164.148.46] (MacBook-Pro.blr.arm.com [10.164.148.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BDAAC3FD88; Wed, 10 Jun 2026 00:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1781074965; bh=mjeJyLvpHgCIWn39mq3WZXEt/2CgxvbNKK+rP/DAWSI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=XxFrg+Dh0yhaVjDbomgvIHuvRQUN8RCxS2FR3mVktSR6DHlCOYKWQWc4TngGprxJ1 F1eg35vzTb+d4Y/H3rQIDxzazn8ZcU9uDB3+Rzquh5+wmYfEI+vmTXZV5vfnXcm4Go pMXy1nFEn+SGarHixrLYWiolF8MNe3dKBvAueeJQ= Message-ID: Date: Wed, 10 Jun 2026 12:32:33 +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 v4 01/12] mm/rmap: convert page -> folio for hwpoison checks To: "David Hildenbrand (Arm)" , akpm@linux-foundation.org, ljs@kernel.org, chrisl@kernel.org, kasong@tencent.com, hughd@google.com, liam@infradead.org Cc: riel@surriel.com, vbabka@kernel.org, harry@kernel.org, jannh@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, qi.zheng@linux.dev, shakeel.butt@linux.dev, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, bhe@redhat.com, youngjun.park@lge.com, baolin.wang@linux.alibaba.com, pfalcato@suse.de, ryan.roberts@arm.com, anshuman.khandual@arm.com References: <20260526063635.61721-1-dev.jain@arm.com> <20260526063635.61721-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: 7bit On 09/06/26 7:14 pm, David Hildenbrand (Arm) wrote: > On 5/26/26 08:36, Dev Jain wrote: >> If any page of a folio is poisoned, try_to_unmap() is called with the >> intent to remove any mappings pointing to any part of the folio. >> >> Therefore, an hwpoison check on a single page does not make sense >> (although everything works out because the memory-failure path sets >> hwpoison on the head page too). Convert these checks to check whether >> the folio has at least one hwpoisoned page. > > I think the reasoning is different and should better be described: > > 1) For hugetlb, we will always get subpage == head page (single PTE -> first PFN). > > try_memory_failure_hugetlb()->try_memory_failure_hugetlb()->hugetlb_update_hwpoison() > will do the folio_test_set_hwpoison(). > > folio_test_set_hwpoison() is the same as setting it on the head page. > > For hugetlb, subpage==headpage > > That's why PageHWPoison(subpage) used to work. > > > 2) try_to_unmap() cannot handle large folios (besides hugetlb folios). > > unmap_poisoned_folio() spells that out. That's why subpage==headpage right now. Should have mentioned: subpage != headpage for contpte mapped hugetlb folios on arm64. But I think even in that case, hwpoison is not set on the specific pfn, it is set only on the head page. So I think folio_test_hwpoison() would suffice. > > > That's why PageHWPoison(subpage) used to work. > >> >> While at it, convert VM_BUG_* to VM_WARN_*. >> >> Signed-off-by: Dev Jain >> --- >> mm/rmap.c | 9 +++++---- >> 1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/mm/rmap.c b/mm/rmap.c >> index fb3c351f8c458..430c91c8fe2ae 100644 >> --- a/mm/rmap.c >> +++ b/mm/rmap.c >> @@ -2116,10 +2116,11 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, >> bool anon = folio_test_anon(folio); >> >> /* >> - * The try_to_unmap() is only passed a hugetlb page >> - * in the case where the hugetlb page is poisoned. >> + * The try_to_unmap() is only passed a hugetlb folio >> + * in the case where the hugetlb folio contains a >> + * poisoned page. >> */ >> - VM_BUG_ON_PAGE(!PageHWPoison(subpage), subpage); >> + VM_WARN_ON_FOLIO(!folio_contain_hwpoisoned_page(folio), folio); > > I think we could also just use folio_test_hwpoison() here. > >> /* >> * huge_pmd_unshare may unmap an entire PMD page. >> * There is no way of knowing exactly which PMDs may >> @@ -2198,7 +2199,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, >> /* Update high watermark before we lower rss */ >> update_hiwater_rss(mm); >> >> - if (PageHWPoison(subpage) && (flags & TTU_HWPOISON)) { >> + if (folio_contain_hwpoisoned_page(folio) && (flags & TTU_HWPOISON)) { >> pteval = swp_entry_to_pte(make_hwpoison_entry(subpage)); >> if (folio_test_hugetlb(folio)) { >> hugetlb_count_sub(folio_nr_pages(folio), mm); > > And here. Which might be cleaner, because folio_contain_hwpoisoned_page() is so > far never called on hugetlb folios. > > Because folio_set_has_hwpoisoned() is only ever used on THPs, not hugetlb. It > would currently work, but the expectation so far is that these primitives are > for small folios+thp, not hugetlb. > > You could add a comment here, that with TTU_HWPOISON, we only ever expect small > folios or hugetlb folios for now. >