Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1834713rdd; Thu, 11 Jan 2024 10:30:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHRbEaaxxsJ9LeViEYSuYqDXWwU31gku2tZxWRb59yiH9LJuYFUKKeDf3IbBE+pavGKTQJ X-Received: by 2002:ae9:e209:0:b0:783:4260:a083 with SMTP id c9-20020ae9e209000000b007834260a083mr249460qkc.12.1704997848878; Thu, 11 Jan 2024 10:30:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704997848; cv=none; d=google.com; s=arc-20160816; b=gPTdZjGQr1qEdq3cExBQ4Sx1RRBgsb0TF5Dk2+Xgyl3Ruam82enoGAWsJ3LkZqEXfV zhnURvJ9gh76NpxVG5ozBHcqtPa5T9oj5HhtvFgoTqH/xQzajpmKpAaYl/Zn2P2MH4p4 eYpF5eWhoPjFisvibQxUkZinOiXmnr1Pjah8hpWZlvsKP5jlj9MiOqeoVMjn19ktxrf0 oPFNZnz7YNTBfu6wUh7TMHiboDPbrjXKrhSTn1PPZtCi0TRO4VU72bKsaa3jI5TmAOtF J+micuAdknZG+9CyzsN2dEPN5JjQ4iBkXIoUzFkEmpzCMIZWyAqHQ7j7OzlDO5iOSlke 38Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=8fY44QehQLsPtLxgWQHF6aw3Iv2rADsazU3iCR26tI4=; fh=JLMCrzcNsYWj1q+fCm2+dadsrvJ3Vjohi4sD7Oyb3Z4=; b=ZhXwvBPAfwMsBYB8VnzYnCbfsE3Aq4Z8UsLypPF3p6WHDT4ZZBXY99fzxZej2Cc6Dm Yd0sYf4dU9Z10mUHRgotYGc8kfz/rKh+HfLNByap57OxvlGT/+E/cmQpQJQIz6+wF1Nn /emaS0b+bDILCjJ4up74Ln6TT/f935iOMeV4/16aLvdcmqgImR1YNhQhpuX+kItAYTdw Ht01wrCN3LwhFQ9t2S1zJIByLlmyGvvI6rsLHz7jjPwtOQjcMcpHrYJKac3+AiLPLaeM EIRrstxBtGD1mhCxL4hsn62rZXGzJkMPiPwWvvMJ2jpeQbw/djZTtMyQwbsGnY0t8ekR bbuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BLOEg84O; spf=pass (google.com: domain of linux-kernel+bounces-23980-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23980-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z13-20020a05620a260d00b00781bd7d3bb1si1480346qko.775.2024.01.11.10.30.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 10:30:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23980-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BLOEg84O; spf=pass (google.com: domain of linux-kernel+bounces-23980-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23980-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 917921C23C85 for ; Thu, 11 Jan 2024 18:30:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9EA13282E9; Thu, 11 Jan 2024 18:30:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BLOEg84O" Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41B2939F for ; Thu, 11 Jan 2024 18:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-dbed729a4f2so4948191276.2 for ; Thu, 11 Jan 2024 10:30:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704997838; x=1705602638; darn=vger.kernel.org; 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=8fY44QehQLsPtLxgWQHF6aw3Iv2rADsazU3iCR26tI4=; b=BLOEg84OGqP6/LxGRTOKdsqFBMG7UiFoYcbh4XQzJVwo124HhclJOxVEoM/wVUTnat IkfJP9crixkeBwLRZuW8r7v+UkCzsWyJHmRHPgd6xjsgsoFLh24wyBPhEjxyIj3qvWMD jQWtrrEfo+CV1iiDuEFpO+TtN+Tq+yZUbL99TzP4uEfKIQ5+J2ai5fY/ZM3KROdz5jQP A8AESvEgnF3peje86XWACFPCypqw8DUfv291uofkSqoWiT3vtF4HWELXFgXwXrq1Iw/F 2X7Jg3cBiUGy8WyviOvM1jX3Mi2/CqAsCHpSRimhzq9hA3RCSJSJ9KbfabIU8sNbrjTw cvVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704997838; x=1705602638; 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=8fY44QehQLsPtLxgWQHF6aw3Iv2rADsazU3iCR26tI4=; b=E7j/AZGAxAMBknOW42E4bk6kDE7eh/gv4Tu5GulzcncVS+vyDAVWsJX3qN9F2D66Yt 0noWeZ/rQUPisVKCr7/PQxbGaZ6qH+o05y9PXQEavJsj2k+lb/YjZdAhKhInkMW/K0BI pvV6lu02r4TPXadZr5G2DQgWypjm1uks26KIyajHyjrmABy1IGZMjE6aYFrucqTHnI7X j/DdSstjksjujhUprr7U1+ObECIs7xG7ObhgijB9pEpwxHHdM/aWcc6JivDDJj40Yd8z qEiMb0RKctdmWJJRbYWSp3bEFSoVOVyCb6AbDJ9YwwAa6Wdm1IV+k4GmTYjyHnQPXPqy nKYw== X-Gm-Message-State: AOJu0YxTvRFpxbkM9CF1vFbHsyVcHvimye40t6s4OsiiXEwZQPMcRkXz 5QqeTWNzcMVlue4ifvoWA5FWDNPgcFHx177dsp+O+Cp6M/fr X-Received: by 2002:a5b:8:0:b0:dbf:23cd:c05c with SMTP id a8-20020a5b0008000000b00dbf23cdc05cmr66460ybp.13.1704997838063; Thu, 11 Jan 2024 10:30:38 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20230713001833.3778937-1-jiaqiyan@google.com> <20230713001833.3778937-5-jiaqiyan@google.com> <079335ab-190f-41f7-b832-6ffe7528fd8b@collabora.com> <6bacbd7c-88cb-1399-8bd0-db98c93a1adf@oracle.com> <39b90dce-fe0f-e1d8-3094-75cabbfa38a3@oracle.com> In-Reply-To: <39b90dce-fe0f-e1d8-3094-75cabbfa38a3@oracle.com> From: Jiaqi Yan Date: Thu, 11 Jan 2024 10:30:25 -0800 Message-ID: Subject: Re: [PATCH v4 4/4] selftests/mm: add tests for HWPOISON hugetlbfs read To: Sidhartha Kumar Cc: Matthew Wilcox , Muhammad Usama Anjum , linmiaohe@huawei.com, mike.kravetz@oracle.com, naoya.horiguchi@nec.com, akpm@linux-foundation.org, songmuchun@bytedance.com, shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jthoughton@google.com, "kernel@collabora.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 11, 2024 at 10:11=E2=80=AFAM Sidhartha Kumar wrote: > > On 1/11/24 10:03 AM, Matthew Wilcox wrote: > > On Thu, Jan 11, 2024 at 09:51:47AM -0800, Sidhartha Kumar wrote: > >> On 1/11/24 9:34 AM, Jiaqi Yan wrote: > >>>> - if (!folio_test_has_hwpoisoned(folio)) > >>>> + if (!folio_test_hwpoison(folio)) > >>> > >>> Sidhartha, just curious why this change is needed? Does > >>> PageHasHWPoisoned change after commit > >>> "a08c7193e4f18dc8508f2d07d0de2c5b94cb39a3"? > >> > >> No its not an issue PageHasHWPoisoned(), the original code is testing = for > >> the wrong flag and I realized that has_hwpoison and hwpoison are two > >> different flags. The memory-failure code calls folio_test_set_hwpoison= () to > >> set the hwpoison flag and does not set the has_hwpoison flag. When > >> debugging, I realized this if statement was never true despite the cod= e > >> hitting folio_test_set_hwpoison(). Now we are testing the correct flag= . > >> > >> From page-flags.h > >> > >> #ifdef CONFIG_MEMORY_FAILURE > >> PG_hwpoison, /* hardware poisoned page. Don't touch */ > >> #endif > >> > >> folio_test_hwpoison() checks this flag ^^^ > >> > >> /* At least one page in this folio has the hwpoison flag set */ > >> PG_has_hwpoisoned =3D PG_error, > >> > >> while folio_test_has_hwpoisoned() checks this flag ^^^ > > > > So what you're saying is that hugetlb behaves differently from THP > > with how memory-failure sets the flags? > > I think so, in memory_failure() THP goes through this path: > > hpage =3D compound_head(p); > if (PageTransHuge(hpage)) { > /* > * The flag must be set after the refcount is bumped > * otherwise it may race with THP split. > * And the flag can't be set in get_hwpoison_page() since > * it is called by soft offline too and it is just called > * for !MF_COUNT_INCREASED. So here seems to be the best > * place. > * > * Don't need care about the above error handling paths f= or > * get_hwpoison_page() since they handle either free page > * or unhandlable page. The refcount is bumped iff the > * page is a valid handlable page. > */ > SetPageHasHWPoisoned(hpage); > > which sets has_hwpoisoned flag while hugetlb goes through > folio_set_hugetlb_hwpoison() which calls folio_test_set_hwpoison(). Yes, hugetlb sets HWPoison flag as the whole hugepage is poisoned once a raw page is poisoned. It can't split to make other supages still available as THP. This "Improve hugetlbfs read on HWPOISON hugepages" patchset only improves fs case as splitting is not needed. I found commit a08c7193e4f18 ("mm/filemap: remove hugetlb special casing in filemap.c") has the following changes in inode.c: --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -334,7 +334,7 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to) ssize_t retval =3D 0; while (iov_iter_count(to)) { - struct page *page; + struct folio *folio; size_t nr, copied, want; /* nr is the maximum number of bytes to copy from this page= */ @@ -352,18 +352,18 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to) } nr =3D nr - offset; /* nr is the maximum number of bytes to copy from this page= */ @@ -352,18 +352,18 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to) } nr =3D nr - offset; - /* Find the page */ - page =3D find_lock_page(mapping, index); - if (unlikely(page =3D=3D NULL)) { + /* Find the folio */ + folio =3D filemap_lock_hugetlb_folio(h, mapping, index); + if (IS_ERR(folio)) { /* * We have a HOLE, zero out the user-buffer for the * length of the hole or request. */ copied =3D iov_iter_zero(nr, to); } else { - unlock_page(page); + folio_unlock(folio); - if (!PageHWPoison(page)) + if (!folio_test_has_hwpoisoned(folio)) want =3D nr; So I guess this "PageHWPoison =3D> folio_test_has_hwpoisoned" change is another regression aside from the refcount thing?