From patchwork Fri Jun 23 16:40:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13290810 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 B60E6EB64D7 for ; Fri, 23 Jun 2023 16:40:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 035FF8D0007; Fri, 23 Jun 2023 12:40:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00C778D0001; Fri, 23 Jun 2023 12:40:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E16108D0007; Fri, 23 Jun 2023 12:40:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CE7BC8D0001 for ; Fri, 23 Jun 2023 12:40:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9068D160C20 for ; Fri, 23 Jun 2023 16:40:25 +0000 (UTC) X-FDA: 80934575610.19.6F57B31 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf26.hostedemail.com (Postfix) with ESMTP id 37EF214000E for ; Fri, 23 Jun 2023 16:40:22 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="G/oR7IPV"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 39cqVZAgKCA4xwo4wCo1u22uzs.q20zw18B-00y9oqy.25u@flex--jiaqiyan.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=39cqVZAgKCA4xwo4wCo1u22uzs.q20zw18B-00y9oqy.25u@flex--jiaqiyan.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687538423; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Im1IN1ikrfOM9Z5Ok/IoUeSFmmXZyMPCiNwLLRYtHmQ=; b=MQszuvYPo4M4xSumzt4boy6OveLuoJHf3eI2koCm2DKhT9cnxO01s2vM6k06MoUkukJQ3h 5AixC3AE9VNxwTqKlkeSE624n3PqqRuqtxodP04Q4NmXJ/vbkpqET7rCFo8lF8OvGgFDZe 8xyd9pI5TXJcQWmezXYnB4C4y05J3zY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="G/oR7IPV"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 39cqVZAgKCA4xwo4wCo1u22uzs.q20zw18B-00y9oqy.25u@flex--jiaqiyan.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=39cqVZAgKCA4xwo4wCo1u22uzs.q20zw18B-00y9oqy.25u@flex--jiaqiyan.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687538423; a=rsa-sha256; cv=none; b=FrSou8HaaKDAyAfxCGSZKiFmj/ibJaUUylExA6jdGIIdOb92wsi4y+2u8o1fMWl8ukRALu 2k60E2RXIR8rQ7ldkiEyyzg6LYsbIQxsQp7vu6iBEEFDKKdLcYR7tEbHRek91Sjy1hnZuF ANFHIC3H3uAS4hHd1ohiW6VZGNz7cdM= Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-260a18f1b43so403714a91.0 for ; Fri, 23 Jun 2023 09:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687538422; x=1690130422; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Im1IN1ikrfOM9Z5Ok/IoUeSFmmXZyMPCiNwLLRYtHmQ=; b=G/oR7IPVEFTa1GT55h/HZHzutGu3XFeJ0x7CMVx0sQ3+iu4UkSa6QKG8Axe8YoI6ut f73cf7IUkzK073BhTuK3KODwM+XdHg/4/r/ugKvr2NDUxM1pyepVAp2riS8MYC6p3ycL A2dFBf9Sto7NcNpOUMSK12m/QRbu0JbpEfwyv6/fMSIQ4op5bwAMFK4VNKbcf1YjRgCy bsnc7/zKLPO4xteCLLsHZLJ9ZqQdRAZ//cIsnb9+r6XJ40mlk9+1lH8fixAisniBj3qi u3V4W4Qj6vOZ7nmsGBXnq6l/L9udH1IJeP0i8d2d/6/8vmobg24T5d8qWWXJVpt8zltv ipQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538422; x=1690130422; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Im1IN1ikrfOM9Z5Ok/IoUeSFmmXZyMPCiNwLLRYtHmQ=; b=BLFl0k87dG76WLuKNAN3pOzSM246wyR6gtrP5VR6x8MWng/va2qbQCAEra0zItd0x9 UgFHxLd3VRJJVRDXXqHUR2OQE8u04xdrUUuHDalpTDiPIulIpCCEGBubv6XdfVTnugTU dNYERZtuooryhDyf23ufq6VLrRut1NtGnWTqD6JW1KqBgsK/eP05ySTutRMelGxnr9Kp TZldlC1XzBnBIyXwIxuOMiDi8gO0Vd68VDVQj5wSXMHXk+YjRzrQUbCG7KVMYV69Ph4m 1AA3jUOQbRgTz01F7gGrbrAQFkKRU5lt5JQtbnN2ExibX+AxXsakilzr5paNJsmZ9X/j jPrg== X-Gm-Message-State: AC+VfDyW+DSniH/BlWBHkY+OpAyRV+k0mMFDz5LzvFyo6ZX4YI3LdeD4 Ju051NXioxXLYh9aalSokDVCO+v+lexmkg== X-Google-Smtp-Source: ACHHUZ7C66BEaKbQBmvL2pZjnqc3R82KIAB0G9Tt/kvXK5rICRDXs/YcwnK1MlTu5X6j4+3CatJBx/dm8KHUHQ== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a17:90a:bc8e:b0:25b:d596:fd30 with SMTP id x14-20020a17090abc8e00b0025bd596fd30mr3104900pjr.1.1687538421988; Fri, 23 Jun 2023 09:40:21 -0700 (PDT) Date: Fri, 23 Jun 2023 16:40:13 +0000 In-Reply-To: <20230623164015.3431990-1-jiaqiyan@google.com> Mime-Version: 1.0 References: <20230623164015.3431990-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230623164015.3431990-3-jiaqiyan@google.com> Subject: [PATCH v2 2/4] mm/hwpoison: check if a subpage of a hugetlb folio is raw HWPOISON From: Jiaqi Yan To: mike.kravetz@oracle.com, naoya.horiguchi@nec.com Cc: songmuchun@bytedance.com, shy828301@gmail.com, linmiaohe@huawei.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duenwen@google.com, axelrasmussen@google.com, jthoughton@google.com, Jiaqi Yan X-Rspamd-Queue-Id: 37EF214000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: oujz4y3bdh4w3bp9jmq6u19wjncin89b X-HE-Tag: 1687538422-115567 X-HE-Meta: U2FsdGVkX1/v8YQZpIzBF+z4h8VnYppxct+p0kvkS+nsyN+MFWi7mri0gTKNp+sRsve95FeQzHnNn7UPKNV1hAnTvesi+ATzibCBnPQ9Mg3NaOaRylwpAsLaplu6NMYHk3XkUYESItMPGcq0bbNr0Jm63DuhIashvzrw9AxSbt8QqnwbfXxp4XmEHinQh6uAUMb/JI/86ivYo0iyV1FAGu9qHcTI8ySutcx95LFYQ3d145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YRfTJAiwrYEL1Hv0OnMtxhX+ILcy55lkg9j5iMkRizYLgJE/405AIdYWU8tPUHqaK+yTl+AJQYI2bGUcM8/7Zz1MMKR1PcNk+kaiyClr6RmJ5Fw0ABhMWy8pZ2uyDEP51O1n1IIPFbbXq0MlE9wkkEYp0qqC+6Rbr40U0Zz3LjJz9HYyVeLxOblJkBtUSD3wMnu4h4rrNpu1TQwCKEpnX8i24BS5DWunSiRDXqiEcUvuAnXEEf/Oa8G+5VtW+7xz49cFYQZMbgmZtNXd8OmPyX3gLuGhVkUXBRo2Xdhw== 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: Adds the functionality to tell if a subpage of a hugetlb folio is a raw HWPOISON page. This functionality relies on RawHwpUnreliable to be not set; otherwise hugepage's HWPOISON list becomes meaningless. Exports this functionality to be immediately used in the read operation for hugetlbfs. Signed-off-by: Jiaqi Yan Reviewed-by: Mike Kravetz Acked-by: Naoya Horiguchi --- include/linux/hugetlb.h | 19 +++++++++++++++++++ include/linux/mm.h | 7 +++++++ mm/hugetlb.c | 10 ++++++++++ mm/memory-failure.c | 34 ++++++++++++++++++++++++---------- 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 21f942025fec..8b73a12b7b38 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1013,6 +1013,25 @@ void hugetlb_register_node(struct node *node); void hugetlb_unregister_node(struct node *node); #endif +/* + * Struct raw_hwp_page represents information about "raw error page", + * constructing singly linked list from ->_hugetlb_hwpoison field of folio. + */ +struct raw_hwp_page { + struct llist_node node; + struct page *page; +}; + +static inline struct llist_head *raw_hwp_list_head(struct folio *folio) +{ + return (struct llist_head *)&folio->_hugetlb_hwpoison; +} + +/* + * Check if a given raw @subpage in a hugepage @folio is HWPOISON. + */ +bool is_raw_hwp_subpage(struct folio *folio, struct page *subpage); + #else /* CONFIG_HUGETLB_PAGE */ struct hstate {}; diff --git a/include/linux/mm.h b/include/linux/mm.h index 66032f0d515c..41a283bd41a7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3671,6 +3671,7 @@ extern const struct attribute_group memory_failure_attr_group; extern void memory_failure_queue(unsigned long pfn, int flags); extern int __get_huge_page_for_hwpoison(unsigned long pfn, int flags, bool *migratable_cleared); +extern bool __is_raw_hwp_subpage(struct folio *folio, struct page *subpage); void num_poisoned_pages_inc(unsigned long pfn); void num_poisoned_pages_sub(unsigned long pfn, long i); struct task_struct *task_early_kill(struct task_struct *tsk, int force_early); @@ -3685,6 +3686,12 @@ static inline int __get_huge_page_for_hwpoison(unsigned long pfn, int flags, return 0; } +static inline bool __is_raw_hwp_subpage(struct folio *folio, + struct page *subpage) +{ + return false; +} + static inline void num_poisoned_pages_inc(unsigned long pfn) { } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ea24718db4af..6b860de87590 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -7377,6 +7377,16 @@ int get_huge_page_for_hwpoison(unsigned long pfn, int flags, return ret; } +bool is_raw_hwp_subpage(struct folio *folio, struct page *subpage) +{ + bool ret; + + spin_lock_irq(&hugetlb_lock); + ret = __is_raw_hwp_subpage(folio, subpage); + spin_unlock_irq(&hugetlb_lock); + return ret; +} + void folio_putback_active_hugetlb(struct folio *folio) { spin_lock_irq(&hugetlb_lock); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index c415c3c462a3..891248e2930e 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1809,18 +1809,32 @@ EXPORT_SYMBOL_GPL(mf_dax_kill_procs); #endif /* CONFIG_FS_DAX */ #ifdef CONFIG_HUGETLB_PAGE -/* - * Struct raw_hwp_page represents information about "raw error page", - * constructing singly linked list from ->_hugetlb_hwpoison field of folio. - */ -struct raw_hwp_page { - struct llist_node node; - struct page *page; -}; -static inline struct llist_head *raw_hwp_list_head(struct folio *folio) +bool __is_raw_hwp_subpage(struct folio *folio, struct page *subpage) { - return (struct llist_head *)&folio->_hugetlb_hwpoison; + struct llist_head *raw_hwp_head; + struct raw_hwp_page *p, *tmp; + bool ret = false; + + if (!folio_test_hwpoison(folio)) + return false; + + /* + * When RawHwpUnreliable is set, kernel lost track of which subpages + * are HWPOISON. So return as if ALL subpages are HWPOISONed. + */ + if (folio_test_hugetlb_raw_hwp_unreliable(folio)) + return true; + + raw_hwp_head = raw_hwp_list_head(folio); + llist_for_each_entry_safe(p, tmp, raw_hwp_head->first, node) { + if (subpage == p->page) { + ret = true; + break; + } + } + + return ret; } static unsigned long __folio_free_raw_hwp(struct folio *folio, bool move_flag)