From patchwork Fri Jun 23 16:40:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13290809 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 990D1C0015E for ; Fri, 23 Jun 2023 16:40:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 147748D0005; Fri, 23 Jun 2023 12:40:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0822F8D0001; Fri, 23 Jun 2023 12:40:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3D1B8D0005; Fri, 23 Jun 2023 12:40:23 -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 D6EC38D0001 for ; Fri, 23 Jun 2023 12:40:23 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ACAC8A0C95 for ; Fri, 23 Jun 2023 16:40:23 +0000 (UTC) X-FDA: 80934575526.05.BD7086A Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf07.hostedemail.com (Postfix) with ESMTP id AC7294000D for ; Fri, 23 Jun 2023 16:40:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=34QbFsFB; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 39MqVZAgKCA0wvn3vBn0t11tyr.p1zyv07A-zzx8npx.14t@flex--jiaqiyan.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=39MqVZAgKCA0wvn3vBn0t11tyr.p1zyv07A-zzx8npx.14t@flex--jiaqiyan.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687538421; 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=Awz9MouaWvhYEsa6uGhopM2ZzPpu93glS/WPXSA5BTo=; b=fpa0C5k0laeyx//K5LP0f0BUAFruu4VuptKjpnOnYSIo5ZUraBCTDVLsKWWA3lhQmwVEaO UoMztWf+Aq52FKyl+2/Cua5MgwdnB4sTu9OIoOeanUWIS8bu6k3RkQzaE+SeH00rQ+whbU tQiQQ7IWXDglMg2Pkb4M3FPKhSzAvQs= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=34QbFsFB; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 39MqVZAgKCA0wvn3vBn0t11tyr.p1zyv07A-zzx8npx.14t@flex--jiaqiyan.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=39MqVZAgKCA0wvn3vBn0t11tyr.p1zyv07A-zzx8npx.14t@flex--jiaqiyan.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687538421; a=rsa-sha256; cv=none; b=WAxYwAqSfj5vBK6G3So0nJc/nbx9sZ2apPZProSicjP2ISwYt9rHDHqroSrFye1RcGQIdV NQQCrUY5vWzETWlxvmS+m9zwyVQI8ehD53I2352LMfNVXGoIac62GZTLDkDnxyAkLOfhuV H+vFwVEVHvemq42vBBOzqtEASPgSofs= Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-53fa2d0c2ebso503886a12.1 for ; Fri, 23 Jun 2023 09:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687538420; x=1690130420; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Awz9MouaWvhYEsa6uGhopM2ZzPpu93glS/WPXSA5BTo=; b=34QbFsFBy9aHUrBbbyPZvNf2E6cREYDEJ3OjWNnfkIABbwc6TGNrC1vrgVO6MW9NbF eqg/aLoYmKTPEpf/V4fsvvxZE2OH/jKO4vFZZEDXI9Fw9rFIdjqAghj7mM553FLclePO KLLFRlkp1ktiExq7SI5uSKhq1wmLqwGDDEZNOLOElvL4lS0kRfXPXgsWyOuJxhzdyMqv nNxyqnDxgcoLV/l2B8Oh7QU4LpW04N+ipd0x+tjGDQNo7DnIZ+46hlrSdKqHVfqSfpu2 IMvjSxyQLqGS45aGc7DQuYRsR+7dKrGsp2eRYXyTB07mxB+Es4MLo7hX+4zKOg4KauQE RrNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538420; x=1690130420; 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=Awz9MouaWvhYEsa6uGhopM2ZzPpu93glS/WPXSA5BTo=; b=AS8+myiPeyEqrp6g9Du7S0Hae7GLD3QTdVl1p/KIgMBl0TwB/s8iBsX4NYZlZR3wl8 23mvPewfA6wq9pdSXVXarAHaRkjQ8M+aMurmSWWmfodYcIzmrU1gyz5v1wsW3K8GpWm7 tT+QOeTDRxUXFU6cIowrBazIEfzCIyjzcnir5xYEBpZWhjB8Ir7yzToxJiYIrohIX3eB oGrNFZumZXgd4/8TRqsBDdGDO64pIaGrt2etPjskA+d2ohTXBs62rTA05tvFpan+PwUv sa+mJfN4zSGIn1HqS9xG24LBODHQ38sfznSymO+eXH9A3iYGDHluQ6KjaROnTWc4yY19 osLw== X-Gm-Message-State: AC+VfDwvbjZMxz3DhHHBQMo9R33spJ600BbadOGXpzb3V2nQFFQtxqpp 8WboErWu7DJNetGXue/VDcf3yI+6IO+9HQ== X-Google-Smtp-Source: ACHHUZ5jab1Tbf6QleE2xBkm4fTrRupoObLUsNIdT3ISEaHPrxP1Xi1eIjnLCw3mlAhfFGWA7aDdu24vu/Y4Uw== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a65:6793:0:b0:553:9251:558b with SMTP id e19-20020a656793000000b005539251558bmr2555744pgr.8.1687538420513; Fri, 23 Jun 2023 09:40:20 -0700 (PDT) Date: Fri, 23 Jun 2023 16:40:12 +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-2-jiaqiyan@google.com> Subject: [PATCH v2 1/4] mm/hwpoison: delete all entries before traversal in __folio_free_raw_hwp 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-Rspam-User: X-Stat-Signature: mxwu84w8sgypea7x55chkg1o3h6tapr1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: AC7294000D X-HE-Tag: 1687538421-817825 X-HE-Meta: U2FsdGVkX18ag9t/trC6d8WNysQDuMFQRCtB5sqfV1tj/pEWEyCFDTQfTbYMcOLhye2dJ7kImmDkjlsrKwK01vB4Stjukvy1eysoYqJmRwzsj45MRHsL7opkDlRxfXO92PxhwlWelpcO3lMvrJUyngVvwV0dyXWFFwCY8HI2VWr8qTF83BVcesGXEAiRdibIWFut/CgZNqrvm3MOM0NlNCfdoqeUiEll/gOagzxfJd53o1VmdVkL95qxzmoj8Z68bLXllSeSnRyDGemAkQbKCr3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IBUHpR4k5dR5ksIV/zMS2sbAeWZ58eK0+tXmw7DFKLNyvDzIE9ftPPHZ4Fo0kugR8QygXrXbVLzyJXLGuFmWiatqwkwLWo+MRMJp6G+jx3zh1RgtFtHg65Op+GSz2gsyICdohidf1ZEVTtwYGTKB3DuF3TVBMwKQw47odaLoBKtQ3ApsSepFnx/U9Cwrf6WQncCcV1PVOsRMohvFT2n3PVML8JKKIus6JE3d/I27dzJHHYi0AxZie2Q7JmrcGc5Jlctj36zpBMOrQIjDifPajYfMJSBBoKoAb+uzRAhV+lJohywqvrVpckvxUtuh3EIO+/X60eMlLA= 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: Traversal on llist (e.g. llist_for_each_safe) is only safe AFTER entries are deleted from the llist. llist_del_all are lock free with itself. folio_clear_hugetlb_hwpoison()s from __update_and_free_hugetlb_folio and memory_failure won't need explicit locking when freeing the raw_hwp_list. Signed-off-by: Jiaqi Yan Acked-by: Naoya Horiguchi Acked-by: Mike Kravetz --- mm/memory-failure.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 004a02f44271..c415c3c462a3 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1825,12 +1825,11 @@ static inline struct llist_head *raw_hwp_list_head(struct folio *folio) static unsigned long __folio_free_raw_hwp(struct folio *folio, bool move_flag) { - struct llist_head *head; - struct llist_node *t, *tnode; + struct llist_node *t, *tnode, *head; unsigned long count = 0; - head = raw_hwp_list_head(folio); - llist_for_each_safe(tnode, t, head->first) { + head = llist_del_all(raw_hwp_list_head(folio)); + llist_for_each_safe(tnode, t, head) { struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node); if (move_flag) @@ -1840,7 +1839,6 @@ static unsigned long __folio_free_raw_hwp(struct folio *folio, bool move_flag) kfree(p); count++; } - llist_del_all(head); return count; }