From patchwork Thu Jul 4 04:31:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13723202 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FE63C30653 for ; Thu, 4 Jul 2024 04:33:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59AFC6B00AF; Thu, 4 Jul 2024 00:32:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 522456B00B0; Thu, 4 Jul 2024 00:32:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 325F76B00B1; Thu, 4 Jul 2024 00:32:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0EB876B00AF for ; Thu, 4 Jul 2024 00:32:24 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C0CA840A8F for ; Thu, 4 Jul 2024 04:32:23 +0000 (UTC) X-FDA: 82300798566.06.5BC6BDC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf07.hostedemail.com (Postfix) with ESMTP id A7C6440010 for ; Thu, 4 Jul 2024 04:32:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZZlPRFX8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=DZydrxp6; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZZlPRFX8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=DZydrxp6; spf=pass (imf07.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720067509; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HbU3NixA+ORa4pbwAalk6/qaoqPhUeSqtYDCOzcSsu0=; b=JyWN/bcGlBwJUvN20Evz4/UunomWz0jIJeJnL/gt9TEGdqu3ue+lTXdxcBaU3YAoxH4rzH EfBSi9OER2q9rN//Hw16t2/jmOjGDSs5l7AZXZjstLcr9KH9qnoYA1Vd7Pps0JYiJ41od+ eqq8hT5CP9sI1r1U5Vr316daV257k+4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZZlPRFX8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=DZydrxp6; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZZlPRFX8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=DZydrxp6; spf=pass (imf07.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720067509; a=rsa-sha256; cv=none; b=TCyxgl3HApjzwF5vPiagjkXoqSY6u7SAhvOzbESFmSr8b4VqHMkKa//ROquiyLl8cE3rbE F2YHaPcT349nMWnNKC6skySnonkTrgxqGHC3giJGqDAlrgdidKpuE2bZfKB/G9SPXB4wU/ Ww3Nwiam2/FF/1Q4N9akNRPWupo7NHs= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6CA131FCFE; Thu, 4 Jul 2024 04:32:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720067540; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HbU3NixA+ORa4pbwAalk6/qaoqPhUeSqtYDCOzcSsu0=; b=ZZlPRFX8HPVeyLyltxoPjntrB3vyrMGorhnSIvawEhprDCtQiJ8kvY1aBNeBJMEnFNoka7 zEhX5cg2k/xkhsjTOrqeSfEe1lZe8CG3PQEh3+8UdhDAt9ff/QXS9LBS82y+sKrbT8fyYn t7/3YM8I8df36X7okK3RGPJBJuuuMoQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720067540; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HbU3NixA+ORa4pbwAalk6/qaoqPhUeSqtYDCOzcSsu0=; b=DZydrxp6It5HlKS3mNh//5MUdSN05oCnIEplA26v4hntyU+xxNFeMDdkBpvi66dQmJHnJM /gkrpKtXKANlwKBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720067540; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HbU3NixA+ORa4pbwAalk6/qaoqPhUeSqtYDCOzcSsu0=; b=ZZlPRFX8HPVeyLyltxoPjntrB3vyrMGorhnSIvawEhprDCtQiJ8kvY1aBNeBJMEnFNoka7 zEhX5cg2k/xkhsjTOrqeSfEe1lZe8CG3PQEh3+8UdhDAt9ff/QXS9LBS82y+sKrbT8fyYn t7/3YM8I8df36X7okK3RGPJBJuuuMoQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720067540; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HbU3NixA+ORa4pbwAalk6/qaoqPhUeSqtYDCOzcSsu0=; b=DZydrxp6It5HlKS3mNh//5MUdSN05oCnIEplA26v4hntyU+xxNFeMDdkBpvi66dQmJHnJM /gkrpKtXKANlwKBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 5045F13889; Thu, 4 Jul 2024 04:32:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id +B4rDtMlhmbnDAAAD6G6ig (envelope-from ); Thu, 04 Jul 2024 04:32:19 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , SeongJae Park , Miaohe Lin , Michal Hocko , Matthew Wilcox , Christophe Leroy , Oscar Salvador Subject: [PATCH 24/45] mm/memory_failure: Enable check_hwpoisoned_pmd_entry to handle hugetlb vmas Date: Thu, 4 Jul 2024 06:31:11 +0200 Message-ID: <20240704043132.28501-25-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240704043132.28501-1-osalvador@suse.de> References: <20240704043132.28501-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A7C6440010 X-Stat-Signature: i3kqx19qc4ysjh5ck3zaawyx9g3cadk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Bd0ds1IpecPVSyBuBUvVKAN3c01oeEIm5XPGd6MBk0PYa8z9hOSG6OHLYwUJ20u4CoqSqanA4QeNuj8cWNNoH25/M4RR4CttMlDYbyJCq47ZWSurVbcfmTOxs4t328PhWWOA/vBj+5RIiG8bxmUnrXn6AZwjJXAhmqNW5ShjQd6bEdA/Q3K7Oaq7N+HiomeCVLgwQS//WN27RiQVGpUpVtl8xijoZYZLNv8SsRng== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: PMD-mapped hugetlb vmas will also check_hwpoisoned_pmd_entry. Add the required code so it knows how to handle those there. Signed-off-by: Oscar Salvador --- mm/memory-failure.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 0cb1b7bea9a5..8cae95e36365 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -771,27 +771,43 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, return 1; } -#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES static int check_hwpoisoned_pmd_entry(pmd_t *pmdp, unsigned long addr, - struct hwpoison_walk *hwp) + struct hwpoison_walk *hwp, + struct vm_area_struct *vma) { pmd_t pmd = *pmdp; unsigned long pfn; - unsigned long hwpoison_vaddr; + unsigned short shift; + unsigned long hwpoison_vaddr = addr; - if (!pmd_present(pmd)) - return 0; - pfn = pmd_pfn(pmd); - if (pfn <= hwp->pfn && hwp->pfn < pfn + HPAGE_PMD_NR) { - hwpoison_vaddr = addr + ((hwp->pfn - pfn) << PAGE_SHIFT); - set_to_kill(&hwp->tk, hwpoison_vaddr, PAGE_SHIFT); - return 1; + if (pmd_present(pmd)) { + pfn = pmd_pfn(pmd); + } else { + swp_entry_t swp = pmd_to_swp_entry(pmd); + + if (!is_hwpoison_entry(swp)) + return 0; + pfn = swp_offset_pfn(swp); } - return 0; + + shift = is_vm_hugetlb_page(vma) ? huge_page_shift(hstate_vma(vma)) + : PAGE_SHIFT; + + if (pfn > hwp->pfn || hwp->pfn > pfn + HPAGE_PMD_NR) + return 0; + + if (!is_vm_hugetlb_page(vma)) + hwpoison_vaddr += (hwp->pfn - pfn) << PAGE_SHIFT; + + set_to_kill(&hwp->tk, hwpoison_vaddr, shift); + + return 1; } #else static int check_hwpoisoned_pmd_entry(pmd_t *pmdp, unsigned long addr, - struct hwpoison_walk *hwp) + struct hwpoison_walk *hwp, + struct vm_area_struct *vma) { return 0; } @@ -805,9 +821,9 @@ static int hwpoison_pte_range(pmd_t *pmdp, unsigned long addr, pte_t *ptep, *mapped_pte; spinlock_t *ptl; - ptl = pmd_trans_huge_lock(pmdp, walk->vma); + ptl = pmd_huge_lock(pmdp, walk->vma); if (ptl) { - ret = check_hwpoisoned_pmd_entry(pmdp, addr, hwp); + ret = check_hwpoisoned_pmd_entry(pmdp, addr, hwp, walk->vma); spin_unlock(ptl); goto out; }