Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35580249rwd; Mon, 10 Jul 2023 09:22:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHM00Y70ZlE1Uz55zEaoG9gEvI+5oo5DtFuOtKTcvPviJRZ3r4pHa9tdNDUu1bQrkRMU8aD X-Received: by 2002:a17:907:91c3:b0:992:a85d:278b with SMTP id h3-20020a17090791c300b00992a85d278bmr11321481ejz.59.1689006131093; Mon, 10 Jul 2023 09:22:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689006131; cv=none; d=google.com; s=arc-20160816; b=TJbqeObM7201qPmeO7GS6S8UtolfhyN6voLgoCxb4giVzOa70m46mWt/De8T2h5j6x 9G+w6N16jSFq0+hNCZZjlHQX84ld90YFl72QQhbHNq4Gs5TJ2NGErniHEVLooGNNisSI rtCZ7pGPvKo01WaYfeS0Tq8wYu0NWDYjijz5zjecFrGYVi7y8zLY+woukGhTFD6u0167 3L5hA8W/rF8BiA3fBLgrc44sHm1BfCnlwboozvd4cVIpH0gPExg1NuTVoO6ssyCqQn5z wAlZIX0POMzcxqm+gNFmFXwH5ZXDkiUq6o6oZVpjeq6ETtcDjhBr4//ymULGIoeDcv6r K9PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ev9w8qY5qeXK6l96dBjt1M0c/nck2SlIA1nfO//2Cvg=; fh=a7w88TzjQk9HRf2p++v9Wfs7UJlaYajZL7dMgPk2Uwk=; b=JI7w+dcE+IuQwzbnJ9rFzJCTqBM3Lu2x9ygpyDAqqjXFbqcj5DtE5sRJiCzlGesSoe nEfRqUmbCouQIWiZ3CcnDGuEezWloxiWqMiuR1cjsICSctDQ+zGVT5PY2T1E4WFWZOz6 Byx99eRxbpZPPDxDJciQhdj5qhNsbwZ1iSA22LG07wYDcLREupJKsorJ9kW60qh5AH37 OaW8wbYOUgwrQgVMm/Lje38km8N/2ZTS9Lub7U82MShG3lJmYCKDbysiD9P3WPfmqCNj PygonjZJ6q4s5+krRgsiMCV94WSVzSIEp8a5fDHMN86oqqOkqvjZlBJSz70nPEaWp3TM ZPzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=UXvy2lXu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw16-20020a170906fcb000b009930d4e327dsi9059345ejb.880.2023.07.10.09.21.46; Mon, 10 Jul 2023 09:22:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=UXvy2lXu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230464AbjGJPRL (ORCPT + 99 others); Mon, 10 Jul 2023 11:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbjGJPRI (ORCPT ); Mon, 10 Jul 2023 11:17:08 -0400 Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F3BA0 for ; Mon, 10 Jul 2023 08:17:07 -0700 (PDT) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-57012b2973eso59829157b3.2 for ; Mon, 10 Jul 2023 08:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689002227; x=1691594227; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ev9w8qY5qeXK6l96dBjt1M0c/nck2SlIA1nfO//2Cvg=; b=UXvy2lXuacyPSAIEDq5qk/QFhDP0pWrsvmHQao1FdXfgkWCCTkvztAJoL4KblYUUIn Id6XFTfQ7pGHNwDVV0tIbF3GxZp5av38rOxIT6RcYIEhgy4qlSnbmn/zrnLUvwzPWO0Y WYU6B8NWzON02+L61fxZmg49WwdNMkUrzaCU3ws366Y1MNmH4VJ3/IozxXvyFjnCM5Rv 8tJzfW4PTjiifwQ0kUJ6+yrqLA7N9CGXNOpufniE4821v5bcmEe2cP6YitHieT7uRIBW 7UWH+6fhv8DJJL9XxsmXLAEqeQaVt/0wfaTD+1WUG3ujlv6L5G6kjyH9qwzAVkrFBAdV AIjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689002227; x=1691594227; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ev9w8qY5qeXK6l96dBjt1M0c/nck2SlIA1nfO//2Cvg=; b=Vh1GgHnGiL6AB+T+ZdRJjgIccolbLgfjkABXyLwKRkugO1/uemP3CqzyNFLOgLcbeq 0YLF4aIhkLnX84vGrag6DQJv7J7pCnloJ5K+mfFLnMfbRYlktz9PmlypWI/Qu+5uoD2H Bh7SUDTy2Q2nJdWD87C1IqlwOynmsy064+3j+5gRvkR9m83xMiceOvEoCSCdL1O0UClJ Hh9CJUXlvC3gJcbK8QYbNFOUts1a+0XOyWfioEc9JGckCsev0KVQJQFHogUPhMdm0LUH Ej32uB7VDbqY8UkFPxuwSNAJJVNxGP4ph4BlOROaiVi4U06yT5nIdOroT71BHuNugjF1 4qBw== X-Gm-Message-State: ABy/qLa/K0/WHbOTnBwoqMK1MtY8sJPAMUHKNcwkKUrrXEUlAokzX2qT 4dDkrq3WNiLGXM1Go4BAG6a+x+DrVoSTdLqCWtmyUA== X-Received: by 2002:a0d:ca0e:0:b0:56d:28b:8042 with SMTP id m14-20020a0dca0e000000b0056d028b8042mr11153655ywd.40.1689002226674; Mon, 10 Jul 2023 08:17:06 -0700 (PDT) MIME-Version: 1.0 References: <20230707201904.953262-1-jiaqiyan@google.com> <20230707201904.953262-3-jiaqiyan@google.com> <6682284d-7ad3-9b59-687d-899f4d08d911@huawei.com> In-Reply-To: <6682284d-7ad3-9b59-687d-899f4d08d911@huawei.com> From: Jiaqi Yan Date: Mon, 10 Jul 2023 08:16:53 -0700 Message-ID: Subject: Re: [PATCH v3 2/4] mm/hwpoison: check if a subpage of a hugetlb folio is raw HWPOISON To: Miaohe Lin Cc: akpm@linux-foundation.org, mike.kravetz@oracle.com, naoya.horiguchi@nec.com, songmuchun@bytedance.com, shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duenwen@google.com, axelrasmussen@google.com, jthoughton@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 7, 2023 at 7:57=E2=80=AFPM Miaohe Lin wr= ote: > > On 2023/7/8 4:19, Jiaqi Yan wrote: > > Add the functionality, is_raw_hwp_subpage, 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 raw HWPOISON list > > becomes meaningless. > > > > is_raw_hwp_subpage needs to hold hugetlb_lock in order to synchronize > > with __get_huge_page_for_hwpoison, who iterates and inserts an entry to > > raw_hwp_list. llist itself doesn't ensure insertion is synchornized wit= h > > the iterating used by __is_raw_hwp_list. Caller can minimize the > > overhead of lock cycles by first checking if folio / head page's > > HWPOISON flag is set. > > > > Exports this functionality to be immediately used in the read operation > > for hugetlbfs. > > > > Reviewed-by: Mike Kravetz > > Reviewed-by: Naoya Horiguchi > > Signed-off-by: Jiaqi Yan > > --- > > 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(-) > > ... > > -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 =3D false; > > + > > + if (!folio_test_hwpoison(folio)) > > + return false; > > + > > + /* > > + * When RawHwpUnreliable is set, kernel lost track of which subpa= ges > > + * are HWPOISON. So return as if ALL subpages are HWPOISONed. > > + */ > > + if (folio_test_hugetlb_raw_hwp_unreliable(folio)) > > + return true; > > + > > + raw_hwp_head =3D raw_hwp_list_head(folio); > > + llist_for_each_entry_safe(p, tmp, raw_hwp_head->first, node) { > > Since we don't free the raw_hwp_list, does llist_for_each_entry works sam= e as llist_for_each_entry_safe? > > > + if (subpage =3D=3D p->page) { > > + ret =3D true; > > + break; > > + } > > + } > > + > > + return ret; > > } > > It seems there's a race between __is_raw_hwp_subpage and unpoison_memory: > unpoison_memory __is_raw_hwp_subpage > if (!folio_test_hwpoison(folio)) -- hwp= oison is set > folio_free_raw_hwp llist_for_each_entry_safe raw_hwp_list > llist_del_all .. > folio_test_clear_hwpoison > Thanks Miaohe for raising this concern. > But __is_raw_hwp_subpage is used in hugetlbfs, unpoison_memory couldn't r= each here because there's a > folio_mapping =3D=3D NULL check before folio_free_raw_hwp. I agree. But in near future I do want to make __is_raw_hwp_subpage work for shared-mapping hugetlb, so it would be nice to work with unpoison_memory. It doesn't seem to me that holding mf_mutex in __is_raw_hwp_subpage is nice or even absolutely correct. Let me think if I can come up with something in v4. > > Anyway, this patch looks good to me. > > Reviewed-by: Miaohe Lin > Thanks. >