Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp894959pxb; Tue, 1 Feb 2022 12:39:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJz69YTsNYmOHKcLqYIghEQ6egoMFPMljOKIThWDQZrWcYKizjQBvPYqXbS8VhmeR2pVTr1T X-Received: by 2002:a62:1dcc:: with SMTP id d195mr26714987pfd.4.1643747953404; Tue, 01 Feb 2022 12:39:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643747953; cv=none; d=google.com; s=arc-20160816; b=YR+qpBcyfnFsEwdrKb7A92rzQcNbks14mg3xkFLbhXpbVMaHs7lN8edtcJnydpWHvX WhGPUHxhymBB1WnvHkszanZ9PAd/mO4R80ZEBzQCcM1ymlfGdtami/5mVRdou9pdQQ0K wxhIum4GaiTmTOETZPTHjtkYzv9ZtqK/FdNAa2CanLTa2bmTKowaCtC4Wo+Thz30Kyd1 kl0T2eTsPFM3+vqqt47KSGN0mjCs1JhgLrESNtH2OD3vJORuHXIfDGADYfd252prJu+B FDNu5+WJD6aNYjFojcDEartuArCYaa4IKw0jsh/BYxrrHzKzk02tWy1lebDy7bg+Z+d4 Epcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OTKoir2+xcoumP1Iky+cUAgPj3dlbdxo9BpxQp1yt8Q=; b=TM2C3nGt1G3dIpLdLzH6Qy+68SQx7Cu2/3mJryOCkZWBJl44xWN90C7NYBqmUHHC8c vrfrh85vKUptWiPR2VDz7zES8mia6TF5ZzosKtdu6IPF0KeRtK4LbCa2SVbfnCA7pwtJ GU3L0TXeirRs7+wvicIVQsWQD705Wv51VZ/q1qGnyyp6/hSqoGkNfTlKd/lSplx4Ky0g YfiuW/rwA6JM+dREAmxTh7HYKDNG+1MQLt2oecLyLHVvam80zFKarL/mR6QU/GVZ+e7j AJ52gbLy9Meivx3wXBtnTKuunNhPz/K7gcAWYyWiG2hX94202hUoYA1IQPwqhAxtM1K5 e40g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=aQq2lT8H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q195si17418094pgq.607.2022.02.01.12.39.01; Tue, 01 Feb 2022 12:39:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=aQq2lT8H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376660AbiAaNYt (ORCPT + 99 others); Mon, 31 Jan 2022 08:24:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378676AbiAaNYd (ORCPT ); Mon, 31 Jan 2022 08:24:33 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B9AEC06173D for ; Mon, 31 Jan 2022 05:24:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=OTKoir2+xcoumP1Iky+cUAgPj3dlbdxo9BpxQp1yt8Q=; b=aQq2lT8Hv17Vxf87P/InoA66Ph RTKgC9KXM797g48rjI1n9nUP9Efhq28xRamieYhQs0gsOvwmP/M/ie+MZl9Nr19b51ny5F7D20Q9u VUzAX5ekOyGkk1bX2dh6D7TlrjPoJSRfdTHHMcTrDA8IZfih1J5wI/ITt1phKIhslvDJwb2rjbiON AMRMSoRzVGlMuc7yvYUy/AJ1mPIoc94tBrWCa0zYHjd8a3oPQ9jFvMalcQycH3u9zuDCgummzvnJf VE/m9mnL5jjhdLgo/TzeiIjy455XvQbEEoRAmde9rn8a3ITn2qOJfl4XW/zhFzkgHVu6Py4RhzdpU lcbAaH7g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEWfT-009teD-24; Mon, 31 Jan 2022 13:24:27 +0000 Date: Mon, 31 Jan 2022 13:24:27 +0000 From: Matthew Wilcox To: HORIGUCHI =?utf-8?B?TkFPWUEo5aCA5Y+j44CA55u05LmfKQ==?= Cc: David Rientjes , Andrew Morton , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] mm/hwpoison: Check the subpage, not the head page Message-ID: References: <20220130013042.1906881-1-willy@infradead.org> <20220131054432.GA856839@hori.linux.bs1.fc.nec.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220131054432.GA856839@hori.linux.bs1.fc.nec.co.jp> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 31, 2022 at 05:44:35AM +0000, HORIGUCHI NAOYA(堀口 直也) wrote: > On Sun, Jan 30, 2022 at 09:14:21PM +0000, Matthew Wilcox wrote: > > On Sun, Jan 30, 2022 at 12:58:17PM -0800, David Rientjes wrote: > > > On Sun, 30 Jan 2022, Matthew Wilcox (Oracle) wrote: > > > > > > > Hardware poison is tracked on a per-page basis, not on the head page. > > > > > > > > Signed-off-by: Matthew Wilcox (Oracle) > > > > --- > > > > mm/rmap.c | 4 ++-- > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/mm/rmap.c b/mm/rmap.c > > > > index 6a1e8c7f6213..09b08888120e 100644 > > > > --- a/mm/rmap.c > > > > +++ b/mm/rmap.c > > > > @@ -1553,7 +1553,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, > > > > /* Update high watermark before we lower rss */ > > > > update_hiwater_rss(mm); > > > > > > > > - if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) { > > > > + if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) { > > > > pteval = swp_entry_to_pte(make_hwpoison_entry(subpage)); > > > > if (PageHuge(page)) { > > > > hugetlb_count_sub(compound_nr(page), mm); > > > > @@ -1873,7 +1873,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, > > > > * memory are supported. > > > > */ > > > > subpage = page; > > > > - } else if (PageHWPoison(page)) { > > > > + } else if (PageHWPoison(subpage)) { > > > > pteval = swp_entry_to_pte(make_hwpoison_entry(subpage)); > > > > if (PageHuge(page)) { > > > > hugetlb_count_sub(compound_nr(page), mm); > > > > > > This looks correct. Correct me if I'm wrong that this is for consistency > > > and cleanup and that there is no bug being fixed by this, however. > > > > Oh, no, I think there's a real bug here. It's just that we're looking > > at an uncommon & hence rarely-tested scenario -- a memory fault in the > > middle of a THP (in mainline; obviously it'll be a little more common > > with arbitrary sized folios). I don't do HWPoison testing myself, so > > this was by inspection and not from testing. A scenario where things > > would go wrong is a memory error on a non-head-page would go unnoticed > > when migrating or unmapping. Contrariwise, if there's a hardware error > > on a head page, all the subpages get treated as poisoned, even though > > they shouldn't be. > > Thank you for reporting. As you point out, the current check does not > handle thp properly. The reason of checking head page here is to handle > hwpoisoned hugetlb (which has PG_hwpoison on the head page even if the error > is on any of tail page). So I think that the proper fix is to add a helper > function to check page type (normal, thp, or hugetlb) as well as PageHWPoison. I think this handles HugeTLB pages correctly: subpage = page - page_to_pfn(page) + pte_pfn(*pvmw.pte); As I understand the HugeTLB code, pvmw.pte refers to the head page, not the subpage (unlike a PTE-mapped THP page, where it would refer to the precise page). But I cheerfully admit that the intricacies of the HugeTLB code are not something I'm an expert on.