From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (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 5831F4315A for ; Mon, 22 Dec 2025 03:01:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766372497; cv=none; b=YciMtd8+QB3iqFnByM7YnBcRQbUAQjH3JQXqHJC0oedVvAY9JpQ2V+9cuU0JDR/ZqEoq0ZDAe2W3LaPSJq7vyJsw9wZR0Xw0lthHTeasaP4aKujUmqckXN2w31UoJ/7TIpCfYUYv0yYH8nY0IQCg9u2QO0ScS17cZ0hkKeXSx2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766372497; c=relaxed/simple; bh=I14p7WyocmwvqSejMCEbB7yzsJYI31VkrI7NO77ZIFo=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=qs5IjYtdlfojng7cnBI/foGoBQsXvX7yMfgb6ukhRQfAnvhGodAfflaecTivcUsyon87YUx0N4UyUw3gCgJA+LEx9B+N3Mjj9eXsxgcqTvok4EJmDGutNGzEz/cvEXPhuQ5v62rWsfzNbmNQMQWbxJ4RKGZKPTx5RK7HTM3o8lA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=N6UMCA1D; arc=none smtp.client-ip=113.46.200.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="N6UMCA1D" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=/NJyvc3PgNYOTFxlhtVOKVMv9S/i9bqSK4QKL3La4/E=; b=N6UMCA1DtgJeIoYtheayhpcT3L3ynp0uUtd+f+M7MLngQXSI7ZI0HBAoDQA1IcQ8Ryae4M6tS GvVcWTbSG8pFDY3uidrVZvrSV12mzyJy8+bhFA2BbUKQchyjZjkERsObSE0Q6F2iXvV8CX5MkOO Lm4iMlocPAFm3tP3ABF5cok= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4dZNB213cjz1prQ2; Mon, 22 Dec 2025 10:58:18 +0800 (CST) Received: from dggemv706-chm.china.huawei.com (unknown [10.3.19.33]) by mail.maildlp.com (Postfix) with ESMTPS id BDA4D4056B; Mon, 22 Dec 2025 11:01:25 +0800 (CST) Received: from kwepemq500010.china.huawei.com (7.202.194.235) by dggemv706-chm.china.huawei.com (10.3.19.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 22 Dec 2025 11:01:25 +0800 Received: from [10.173.125.37] (10.173.125.37) by kwepemq500010.china.huawei.com (7.202.194.235) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 22 Dec 2025 11:01:24 +0800 Subject: Re: [PATCH] mm/memory-failure: teach kill_accessing_process to accept hugetlb tail page pfn To: CC: , , , , , , , , , , , , , References: <20251219062819.2499399-1-jane.chu@oracle.com> <38c098ea-95bb-476f-80c9-de9231b9c991@oracle.com> From: Miaohe Lin Message-ID: <93ce8e83-500f-9f97-a90c-64d9b3c73f3a@huawei.com> Date: Mon, 22 Dec 2025 11:01:24 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <38c098ea-95bb-476f-80c9-de9231b9c991@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemq500010.china.huawei.com (7.202.194.235) On 2025/12/19 16:06, jane.chu@oracle.com wrote: > > > On 12/19/2025 12:01 AM, Miaohe Lin wrote: >> On 2025/12/19 14:28, Jane Chu wrote: >>> When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() >>> passed head pfn to kill_accessing_process(), that is not right. >>> The precise pfn of the poisoned page should be used in order to >>> determine the precise vaddr as the SIGBUS payload. >>> >>> This issue has already been taken care of in the normal path, that is, >>> hwpoison_user_mappings(), see [1][2].  Further more, for [3] to work >>> correctly in the hugetlb repoisoning case, it's essential to inform >>> VM the precise poisoned page, not the head page. >>> >>> [1] https://lkml.kernel.org/r/20231218135837.3310403-1-willy@infradead.org >>> [2] https://lkml.kernel.org/r/20250224211445.2663312-1-jane.chu@oracle.com >>> [3] https://lore.kernel.org/lkml/20251116013223.1557158-1-jiaqiyan@google.com/ >>> >> >> Thanks for your patch. >> >>> Cc: >>> Signed-off-by: Jane Chu >>> --- >>>   mm/memory-failure.c | 22 ++++++++++++---------- >>>   1 file changed, 12 insertions(+), 10 deletions(-) >>> >>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >>> index 3edebb0cda30..c9d87811b1ea 100644 >>> --- a/mm/memory-failure.c >>> +++ b/mm/memory-failure.c >>> @@ -681,9 +681,11 @@ static void set_to_kill(struct to_kill *tk, unsigned long addr, short shift) >>>   } >>>     static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, >>> -                unsigned long poisoned_pfn, struct to_kill *tk) >>> +                unsigned long poisoned_pfn, struct to_kill *tk, >>> +                int pte_nr) >>>   { >>>       unsigned long pfn = 0; >>> +    unsigned long hwpoison_vaddr; >>>         if (pte_present(pte)) { >>>           pfn = pte_pfn(pte); >>> @@ -694,10 +696,11 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, >>>               pfn = swp_offset_pfn(swp); >>>       } >>>   -    if (!pfn || pfn != poisoned_pfn) >>> +    if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn)) >>>           return 0; >> >> Can we get pte_nr from @shift? I.e. something like "pte_nr = 1UL << (shift - PAGE_SHIFT);"? > > Why?  Is there any concern with using the macro pages_per_huge_page(h) ? No, I was trying to get rid of new @pte_nr parameter. Something like below: static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, - unsigned long poisoned_pfn, struct to_kill *tk, - int pte_nr) + unsigned long poisoned_pfn, struct to_kill *tk) { unsigned long pfn = 0; unsigned long hwpoison_vaddr; + int pte_nr; if (pte_present(pte)) { pfn = pte_pfn(pte); @@ -701,7 +701,8 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, pfn = softleaf_to_pfn(entry); } - if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn)) + pte_nr = 1UL << (shift - PAGE_SHIFT); + if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn)) return 0; hwpoison_vaddr = addr + ((poisoned_pfn - pfn) << PAGE_SHIFT); So we don't have to pass in pte_nr from all callers. But that's trivial. Thanks. .