From patchwork Sun Apr 7 13:05:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13620158 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 49AB6CD11C2 for ; Sun, 7 Apr 2024 13:06:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 399E16B0082; Sun, 7 Apr 2024 09:05:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3499F6B0083; Sun, 7 Apr 2024 09:05:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 211E06B0085; Sun, 7 Apr 2024 09:05:59 -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 041396B0082 for ; Sun, 7 Apr 2024 09:05:58 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 83A4640B21 for ; Sun, 7 Apr 2024 13:05:58 +0000 (UTC) X-FDA: 81982758396.29.7D89394 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf02.hostedemail.com (Postfix) with ESMTP id 4FA5B80017 for ; Sun, 7 Apr 2024 13:05:56 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="2KO/DJmV"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ftE4mxiq; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=11kQdusK; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=b1GRYztO; spf=pass (imf02.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 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=1712495156; 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:references:dkim-signature; bh=+qGlEDHzb7FpeLjonTz5IywzApZvF8isqA+3qX4uTqc=; b=CwoNA6cF8vh28DiJTxk/7nc48qGMjwdvmSriL48EFuOjDtGXRxXaGR188eMkcZ2/sRvD7N 4fDkHIJYPQ9O2pTKruajcbNX1OY5sb6B2hTGBdPOouQi8/JfhHNhbd4IEuFyZvka4269+2 wkMDIKpBqJRetflgRIC1EIOvDQmzy0I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712495156; a=rsa-sha256; cv=none; b=bz214oV7I0fYfEf/hzCatOaoVgZOn22INidVqp/B3P09J9XdgGkuZeMDUeSh5rT4UvyFWI TxHvmZEzDmhbKUDDtUuknAmoERyJoJZ48E+SsC1UXhnqofCLyz43+PVXJ2nAvHXCB0/M2G RfyshOF1z9l3C5hzUfZZbzwugw6Wh4I= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="2KO/DJmV"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ftE4mxiq; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=11kQdusK; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=b1GRYztO; spf=pass (imf02.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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-out1.suse.de (Postfix) with ESMTPS id 0948321C63; Sun, 7 Apr 2024 13:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712495154; 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; bh=+qGlEDHzb7FpeLjonTz5IywzApZvF8isqA+3qX4uTqc=; b=2KO/DJmVlWLwlOtRKvqvGbMboDYBH7XvgAY96MSIU+p2/mcEMgqYm0zCoY0UiiYkLlmfNd SZYwUP2Ce7mjRwxKXi35f7R8bkOCqBn3AVRPRGLkHaeeLSbH8FGkjvzYIgb7EAZQQ2buNH JogiPUvA2wsBBjex3mqUshQq22DMy+g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712495154; 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; bh=+qGlEDHzb7FpeLjonTz5IywzApZvF8isqA+3qX4uTqc=; b=ftE4mxiqJ9fwKCk+l8nytwyWct/mrgohQy55PbmD8Bl6Uc+14ZP1O6reM7vsTGOuxl1ThE wM58OqDCrh8uMIBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712495153; 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; bh=+qGlEDHzb7FpeLjonTz5IywzApZvF8isqA+3qX4uTqc=; b=11kQdusKXO52CX7ndjEh1QLOe//sOt2mH0JDv8ya7h+XOA9ACbTv8Sy0YFJTwqJzPCr43M Zwx/WrDA1Dh/znkMy6OPMVy4ExcYT9dXpDG5ThInHXLSi67uF0XJVZUcKLs0GG9bM9NqxT 5lD5rxn2hRPcoktrrf8gVfPvwYgvjmw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712495153; 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; bh=+qGlEDHzb7FpeLjonTz5IywzApZvF8isqA+3qX4uTqc=; b=b1GRYztO14KMD0OEKnjw5YGVMFvVdei3gUIl2Jut8bSAwUuQ6zxhjpMRzOwM2DOjpv0fdQ Sc9lmXdNuoil3oBQ== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 716C7132FF; Sun, 7 Apr 2024 13:05:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id K/XtGDCaEmYGDQAAn2gu4w (envelope-from ); Sun, 07 Apr 2024 13:05:52 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Miaohe Lin , David Hildenbrand , Peter Xu , stable@vger.kernel.org, Oscar Salvador , Tony Luck Subject: [PATCH] mm,swapops: Update check in is_pfn_swap_entry for hwpoison entries Date: Sun, 7 Apr 2024 15:05:37 +0200 Message-ID: <20240407130537.16977-1-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Queue-Id: 4FA5B80017 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 4z4ye88bc9yrerd8e8xfqpio79ouac6d X-HE-Tag: 1712495156-94270 X-HE-Meta: U2FsdGVkX19ogWgfBJyGXE3KgjUj5yEtj8Cgjv81/8z0oTLikoA4f8Vv+1UbYd4xz6tSDJL0D63Bw0lQlsXkIUG260tMvyx7uvG/IZd9oHbIRody3POdzhlosSOpmyu2qvG9ODbcd67qBLTvo88C8v0Gy19iavVd1oNwohyKdhJ+AGR+El9KHg6AjgBDHuszVJrNVqMz03hTkxlxKcblqONnJwM9qGvR0YhJZjwi5CptMOUlKfCybLR1dblFXlQEK9EuJzBFRGhcXYRrPsy9lqzBqf5e6oRzUeT/3MWOWgaSF8Ye8zyj24q36zqZhyB6iQyCZaRrct2r4rlFaupZVwvzsiHIGwdey4lIFVcnZq0NAClKs4MaSi81yl/3tKWawfaSZPEV03eXuOjMNcIgdZAmuTGlycYIvxc7vnfsacEtZKZxEAaiF5MOwIkJKV11Fby22pQZfZvyiDhb4R2YFp4DZK2FThjzUxBLMxLLFwm/y4ihFz7aZKRNN9RxyamEkaWVB6Qk2GkAvopIaR9R3DxdmJMTI2GAKSxUapj8EX530S1IPQdCcyRCtlD78vPDCkxF4PxE+VLs0PrZIra8OdTun5fvf90vZ9u/71513IkxkT/rAo9PkGwjafWl7SLiuUiVYOVWcIB3YkuGM/YxlbqSul9GCUofC7oB52s+fsZLeVcT4V+X1TlCr4MdhjNZoM+KaIrNbYzTHjuTDo3k8/qIB7hOUWIvQV76r93rLbdCJT0QPgCmRs9m9lA7M10z9CAFtIOLdTp77FuyCS+/l3HCyzNx/MX43D8gcDljar7X+J3gYpLvptcTjPo4ytsOEHwW0DklCv1cD9FnWLcLlLZNwDUhGpTYkDGn77VA2L3kByzvTWq23ytR7A6sVZ9LuFYWbW/A+l1iUTnn594ofmM26YijerMwslhBew2JSP2l2mleQwZXa748QYiB+62zJDHQqWQ4cmIreXQsNMs BC8Rrhy1 RRua1egG01Arf1L6Js6IiUfiSUNBJbo1mWHeO 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: Tony reported that the Machine check recovery was broken in v6.9-rc1, as he was hitting a VM_BUG_ON when injecting uncorrectable memory errors to DRAM. After some more digging and debugging on his side, he realized that this went back to v6.1, with the introduction of 'commit 0d206b5d2e0d ("mm/swap: add swp_offset_pfn() to fetch PFN from swap entry")'. That commit, among other things, introduced swp_offset_pfn(), replacing hwpoison_entry_to_pfn() in its favour. The patch also introduced a VM_BUG_ON() check for is_pfn_swap_entry(), but is_pfn_swap_entry() never got updated to cover hwpoison entries, which means that we would hit the VM_BUG_ON whenever we would call swp_offset_pfn() for such entries on environments with CONFIG_DEBUG_VM set. Fix this by updating the check to cover hwpoison entries as well, and update the comment while we are it. Reported-by: Tony Luck Closes: https://lore.kernel.org/all/Zg8kLSl2yAlA3o5D@agluck-desk3/ Tested-by: Tony Luck Fixes: 0d206b5d2e0d ("mm/swap: add swp_offset_pfn() to fetch PFN from swap entry") Cc: # 6.1.x Signed-off-by: Oscar Salvador Reviewed-by: Peter Xu Reviewed-by: David Hildenbrand Acked-by: Miaohe Lin --- include/linux/swapops.h | 65 +++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 48b700ba1d18..a5c560a2f8c2 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -390,6 +390,35 @@ static inline bool is_migration_entry_dirty(swp_entry_t entry) } #endif /* CONFIG_MIGRATION */ +#ifdef CONFIG_MEMORY_FAILURE + +/* + * Support for hardware poisoned pages + */ +static inline swp_entry_t make_hwpoison_entry(struct page *page) +{ + BUG_ON(!PageLocked(page)); + return swp_entry(SWP_HWPOISON, page_to_pfn(page)); +} + +static inline int is_hwpoison_entry(swp_entry_t entry) +{ + return swp_type(entry) == SWP_HWPOISON; +} + +#else + +static inline swp_entry_t make_hwpoison_entry(struct page *page) +{ + return swp_entry(0, 0); +} + +static inline int is_hwpoison_entry(swp_entry_t swp) +{ + return 0; +} +#endif + typedef unsigned long pte_marker; #define PTE_MARKER_UFFD_WP BIT(0) @@ -483,8 +512,9 @@ static inline struct folio *pfn_swap_entry_folio(swp_entry_t entry) /* * A pfn swap entry is a special type of swap entry that always has a pfn stored - * in the swap offset. They are used to represent unaddressable device memory - * and to restrict access to a page undergoing migration. + * in the swap offset. They can either be used to represent unaddressable device + * memory, to restrict access to a page undergoing migration or to represent a + * pfn which has been hwpoisoned and unmapped. */ static inline bool is_pfn_swap_entry(swp_entry_t entry) { @@ -492,7 +522,7 @@ static inline bool is_pfn_swap_entry(swp_entry_t entry) BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS); return is_migration_entry(entry) || is_device_private_entry(entry) || - is_device_exclusive_entry(entry); + is_device_exclusive_entry(entry) || is_hwpoison_entry(entry); } struct page_vma_mapped_walk; @@ -561,35 +591,6 @@ static inline int is_pmd_migration_entry(pmd_t pmd) } #endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ -#ifdef CONFIG_MEMORY_FAILURE - -/* - * Support for hardware poisoned pages - */ -static inline swp_entry_t make_hwpoison_entry(struct page *page) -{ - BUG_ON(!PageLocked(page)); - return swp_entry(SWP_HWPOISON, page_to_pfn(page)); -} - -static inline int is_hwpoison_entry(swp_entry_t entry) -{ - return swp_type(entry) == SWP_HWPOISON; -} - -#else - -static inline swp_entry_t make_hwpoison_entry(struct page *page) -{ - return swp_entry(0, 0); -} - -static inline int is_hwpoison_entry(swp_entry_t swp) -{ - return 0; -} -#endif - static inline int non_swap_entry(swp_entry_t entry) { return swp_type(entry) >= MAX_SWAPFILES;