Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp37531418rwd; Tue, 11 Jul 2023 16:01:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlHUsEdwoVmuKCVeNQX+L/9wbcgzOezpdBtCmPdMtoq+znCDnKKyR7FeqrVgqUw4U8ejq+lX X-Received: by 2002:a05:6a00:3387:b0:675:8627:a291 with SMTP id cm7-20020a056a00338700b006758627a291mr17055854pfb.3.1689116511200; Tue, 11 Jul 2023 16:01:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689116511; cv=none; d=google.com; s=arc-20160816; b=GmTlnFz2DwicvG38AVKhaj/Ry1gApEr1RVPyfbDQNEvFp4T3wOP5OKgJNFw1jlf2hf g7J9e+8Fs9JghKKZNVF+M2KAN7KioqLevl05r0YORPTjX0Gnk0kmixQBACGdqkTpMICX NXgXetHdUAcKgqHQk1e7B6+wNdxpyp3UFVdJQXPBzNDTjKItlW5MkJYCI5pu+zIT5RBv lLbJFKu0LDFRc1bt6rFeRItb/TwFJRqhBb76EADfRqFXGxIEvksiZ5pOu0Xoc4rxXamW pcLkPs3PjHe6DAsd5ZRdSBTNv4Fl1Kf9WSFVI0NfoaoYMMYsixKP4stncdqfY/WUbLzJ ZkYw== 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=d/GtFb0EqNYu9Ozo0dSp+bce5y10je/SnpQEJxWby1c=; fh=bGQlcTA2PygxX11N2Z8xBEcUPcayCtlID8rH0MVIKsc=; b=ALqrIKhyri0DaAMs4C+YKmAm1/EkfUs3xiWiu1oq3BP08r69wCKpxPxKKOQX56zN6w iRnC2cLf/gPZ661K7cPMtVD/xjLfPkPhkHocIoNtW0CZ2MbbnJ78SJy7xKYsDr9h7JHN U1hLXacvt0P3fRY4V29mJChIeQvu8xVQfnSH3MIp1CX6ITnpDCsNL60CDOylDIWbpiFA O6VP9Kbz/Cp17k6Fj8H19cjn95uy53CgD3zGmtctgV2ahgtm5mipRNFZU8FT6kvjYJMA qPmUcpdiLSJu0BtXdJIrpdJdMMwaREpXxFZ920FAo/FAHPajPlkp/IwF5O6rSM5jwnGv rvpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="PA+wbm1/"; 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 ca21-20020a056a00419500b006815bf78633si2089226pfb.315.2023.07.11.16.01.39; Tue, 11 Jul 2023 16:01:51 -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="PA+wbm1/"; 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 S230006AbjGKWXM (ORCPT + 99 others); Tue, 11 Jul 2023 18:23:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjGKWXL (ORCPT ); Tue, 11 Jul 2023 18:23:11 -0400 Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D95A910FA for ; Tue, 11 Jul 2023 15:23:05 -0700 (PDT) Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-5700b15c12fso71725357b3.1 for ; Tue, 11 Jul 2023 15:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689114185; x=1691706185; 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=d/GtFb0EqNYu9Ozo0dSp+bce5y10je/SnpQEJxWby1c=; b=PA+wbm1/vKXTWoURcR4YLVKRbPS4NYL89xg1LcdSjSXGTOIbJsyPT0jnF5DAtptEjs HlUQ2PCyfmiLOAeXyc7/PGo7uTaOQr3Gi85X78rf0hchLpcHH/eOk9MMv2S9adwTtieu xf9fy1r+AYNS/LmNYZyoamQOHp8cItfQ7nmo+F0PLRPPSJBBB3tas3aXYlVwiHLqhAVy 0VT+CRUdGLwJtXbZQ6QCpP0VZtTB6fsru0GYFIAhwXUjYYxOk0GwXVqEdDVmGyjB5cXl g4TADxuLnA4kC+wve/uLFqvdGulI74qIhETkD4T2SBS30WfwyF7QRx23+/i+ySAFYi9v dfXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689114185; x=1691706185; 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=d/GtFb0EqNYu9Ozo0dSp+bce5y10je/SnpQEJxWby1c=; b=HZhpzHDtJFLdcVhUy+MelINp+Oj7ZfB9yxP40OmJiNsbP8adDinVZTB/nTpfDfRy// lRY0bMiaNNMkbe4/0okttRMKNHx+oSmQKy1Q8pl56pN2RVfM7qZ49VP+L8DBOJQje1oZ L93jsoIlS+hBx1JZYAJ6QifMTL1sTvM6OrjD2oDOeeM0jDRiN+xMnffKPqWM/VYy73z8 rnZm9tlurU8/wiNnnx4Mk8MRGpY/gRMAEHB0Em57Fabtbv/6/VWTzVSgBABI7qEGiW1S xUkTmgvxtU2wwXKUg1AToZwD51S9Sb4FJwRdKr2tdR//Cd/tvkzshHCbhNwWsF0p9IaH pSOQ== X-Gm-Message-State: ABy/qLYFtEKSo3/ljxTlVJGWFdh9c174+B5AnexPftH5g/FOrffzEmWY CfgzAMysQgzW9mPRR2Nc0KxmvhTyyVCbXbg+SD0SEg== X-Received: by 2002:a81:6ad6:0:b0:56d:297e:7c8c with SMTP id f205-20020a816ad6000000b0056d297e7c8cmr15936031ywc.8.1689114184945; Tue, 11 Jul 2023 15:23:04 -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> <20230711180159.GA3887@monkey> In-Reply-To: <20230711180159.GA3887@monkey> From: Jiaqi Yan Date: Tue, 11 Jul 2023 15:22:52 -0700 Message-ID: Subject: Re: [PATCH v3 2/4] mm/hwpoison: check if a subpage of a hugetlb folio is raw HWPOISON To: Mike Kravetz Cc: Miaohe Lin , akpm@linux-foundation.org, 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 Tue, Jul 11, 2023 at 11:02=E2=80=AFAM Mike Kravetz wrote: > > On 07/11/23 10:05, Jiaqi Yan wrote: > > On Mon, Jul 10, 2023 at 8:16=E2=80=AFAM Jiaqi Yan = wrote: > > > On Fri, Jul 7, 2023 at 7:57=E2=80=AFPM Miaohe Lin wrote: > > > > On 2023/7/8 4:19, Jiaqi Yan wrote: > > > > > > > > > + 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_m= emory: > > > > unpoison_memory __is_raw_hwp_subpage > > > > if (!folio_test_hwpoison(folio)) = -- hwpoison 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 coul= dn't reach 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. > > > > At my 2nd thought, if __is_raw_hwp_subpage simply takes mf_mutex > > before llist_for_each_entry, it will introduce a deadlock: > > > > unpoison_memory __is_raw_hwp_subpage > > held mf_mutex held hugetlb_lock > > get_hwpoison_hugetlb_folio attempts mf_mutex > > attempts hugetlb lock > > > > Not for this patch series, but for future, is it a good idea to make > > mf_mutex available to hugetlb code? Then enforce the order of locking > > to be mf_mutex first, hugetlb_lock second? I believe this is the > > current locking pattern / order for try_memory_failure_hugetlb. > > I think only holding mf_mutex in __is_raw_hwp_subpage would be sufficient > to prevent races with unpoison_memory. memory failure code needs to take > both mf_mutex and hugetlb_lock. The hugetlb lock is to prevent hugetlb > page state changes. IIUC, __is_raw_hwp_subpage is only taking hugetlb_lo= ck > to prevent races with memory failure code. Thanks Mike, I think mf_mutex is a simple and correct solution. I will drop hugetlb_lock from __is_raw_hwp_subpage in v4. > > Of course, I could be missing something as there are subtle issues with > locking in the memory failure code. > -- > Mike Kravetz