From mboxrd@z Thu Jan 1 00:00:00 1970 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 DB1F6C4332F for ; Mon, 7 Nov 2022 18:54:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 755EF6B0078; Mon, 7 Nov 2022 13:54:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 705FE6B007B; Mon, 7 Nov 2022 13:54:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CDFC8E0001; Mon, 7 Nov 2022 13:54:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 49B466B0078 for ; Mon, 7 Nov 2022 13:54:07 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 221A1140897 for ; Mon, 7 Nov 2022 18:54:07 +0000 (UTC) X-FDA: 80107546134.03.96D19CE Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf25.hostedemail.com (Postfix) with ESMTP id B67A1A0004 for ; Mon, 7 Nov 2022 18:54:06 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id gw22so11425999pjb.3 for ; Mon, 07 Nov 2022 10:54:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=lAsPldyH1+ehPpIMIyGZ2Vh4cO9qav4LSbU+Q7y0YxQ=; b=U85gWRsDqLX0LQBt2vQ3TkgGPDTGTFbzCUlE3Zfx0OVbRkG6ETW1wqrGcAb3LrUf/c 1WAw19BVcC4wWo/dXaGo1joKXPkckqLJwBPqo98cJ1u8G5sXNpZvIc4AnGRms5wRvJTD nsurz6HyKVDvQAujo8f5x4dmUof+0gfe6Fg9MEq9+4rpW6hF7rVPKlrJApYU2H2uxfmn aK6w+S76NYCsAp43HmrdaCDEpixBof6bOIZWMu2eGsPAomAJlwvlAKlWmBMJB8itQkDh 0/NrratewXAxRepTTSK/x3JBxn814WWOwQ+qzLd3yrn6kQq8gLdu0jqTElYG6ePKiJpO PQOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=lAsPldyH1+ehPpIMIyGZ2Vh4cO9qav4LSbU+Q7y0YxQ=; b=UxJ/fkZjFcfsd7zIMdcxzKWM94T1RU87ApcxaP3Kw+0cUuZWQ603cK4IywWFuMF5Oy +30T30xO5kjkwayQrX0OdcUhilvRwNR/8LAyJU7wy+8KOY+WVypM6CUvgez2hzpI8iW0 v9bF0ibQfYbrHYudxwgX+WT1Fbv1c0oZl8sNVR6Hqu5tSH9ztHQ+cZ4hiohN4qJVHAWR vEnfAyn0R8Et8XE9uEUvZxTkUtf7I1qN4TdO8w8ehrgp26oWc5ZmGQp9Vvj0z1ovqRTg 7Ofw49HM5/DZavFtES96SIZz5WbRDfDgF7TpFb/KVGfKmJwR8T/y/AyW9zUhvpo/JfAp t1Eg== X-Gm-Message-State: ACrzQf13YDGZdVVV8oEkCSFSTrHIaNyZOyI7ZhoBHuYwP8QbJl0tZMie laAtUmpRa/hZbBsS9pGZn31KYwuvnCYK/DevBFs= X-Google-Smtp-Source: AMsMyM7TkXgERxyf/LGmK6OXqXmyCV8AVdKCqfR9fWU8njcLEuOJo21O6kgcmd/BG+bxwnjRHSvJBnZymZusZgQiZBA= X-Received: by 2002:a17:902:d512:b0:181:f1f4:fcb4 with SMTP id b18-20020a170902d51200b00181f1f4fcb4mr52554484plg.102.1667847245779; Mon, 07 Nov 2022 10:54:05 -0800 (PST) MIME-Version: 1.0 References: <20221107180548.2095056-1-jthoughton@google.com> In-Reply-To: <20221107180548.2095056-1-jthoughton@google.com> From: Yang Shi Date: Mon, 7 Nov 2022 10:53:53 -0800 Message-ID: Subject: Re: [PATCH v2] hugetlbfs: don't delete error page from pagecache To: James Houghton Cc: Mike Kravetz , Muchun Song , Naoya Horiguchi , Miaohe Lin , Andrew Morton , Axel Rasmussen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667847246; 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=lAsPldyH1+ehPpIMIyGZ2Vh4cO9qav4LSbU+Q7y0YxQ=; b=jJ3WO0XcwH3qIg6uvYbXu3u85mdnxAvG2uEbDL5R7OyDEhDCVcgnFiwqrjXUVsG8frGguK UueVm+SpV3RmMi7uFC6yb0ZDBpTO4GU3LJtjhYy+7zwdjSUhj30QuZDWcfKLL9/fiaYHnW Wmb0cvxVW+yOxjZ1ksAJ6mM6TaMD+5Q= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=U85gWRsD; spf=pass (imf25.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667847246; a=rsa-sha256; cv=none; b=dLCFPkdhy78lw6ZDG59DAxTH/AsSHXPBI36VPAQi24YTXOGwy2/rnCXwvW4dl6LzGjQjLw XhE6SiPt2W35MjkzUkYci5OeD8bb61Uf9kwb3cGmpfTedvOa6/q98KKBOb+ydcsu+RWrXS 83tJWfPgFrC8ClRsTt1AJGqhFgb/a2A= X-Rspamd-Queue-Id: B67A1A0004 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=U85gWRsD; spf=pass (imf25.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: gqqe1qwt3jczu9pxzjij64a1ajwt37yk X-HE-Tag: 1667847246-998583 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: On Mon, Nov 7, 2022 at 10:06 AM James Houghton wrote: > > This change is very similar to the change that was made for shmem [1], > and it solves the same problem but for HugeTLBFS instead. > > Currently, when poison is found in a HugeTLB page, the page is removed > from the page cache. That means that attempting to map or read that > hugepage in the future will result in a new hugepage being allocated > instead of notifying the user that the page was poisoned. As [1] states, > this is effectively memory corruption. > > The fix is to leave the page in the page cache. If the user attempts to > use a poisoned HugeTLB page with a syscall, the syscall will fail with > EIO, the same error code that shmem uses. For attempts to map the page, > the thread will get a BUS_MCEERR_AR SIGBUS. > > [1]: commit a76054266661 ("mm: shmem: don't truncate page if memory failure happens") > > Fixes: 78bb920344b8 ("mm: hwpoison: dissolve in-use hugepage in unrecoverable memory error") > Cc: > Signed-off-by: James Houghton > Reviewed-by: Mike Kravetz > Reviewed-by: Naoya Horiguchi > Tested-by: Naoya Horiguchi Reviewed-by: Yang Shi > --- > fs/hugetlbfs/inode.c | 13 ++++++------- > mm/hugetlb.c | 4 ++++ > mm/memory-failure.c | 5 ++++- > 3 files changed, 14 insertions(+), 8 deletions(-) > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index dd54f67e47fd..df7772335dc0 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -328,6 +328,12 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to) > } else { > unlock_page(page); > > + if (PageHWPoison(page)) { > + put_page(page); > + retval = -EIO; > + break; > + } > + > /* > * We have the page, copy it to user space buffer. > */ > @@ -1111,13 +1117,6 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping, > static int hugetlbfs_error_remove_page(struct address_space *mapping, > struct page *page) > { > - struct inode *inode = mapping->host; > - pgoff_t index = page->index; > - > - hugetlb_delete_from_page_cache(page); > - if (unlikely(hugetlb_unreserve_pages(inode, index, index + 1, 1))) > - hugetlb_fix_reserve_counts(inode); > - > return 0; > } > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 546df97c31e4..e48f8ef45b17 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -6111,6 +6111,10 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, > > ptl = huge_pte_lock(h, dst_mm, dst_pte); > > + ret = -EIO; > + if (PageHWPoison(page)) > + goto out_release_unlock; > + > /* > * We allow to overwrite a pte marker: consider when both MISSING|WP > * registered, we firstly wr-protect a none pte which has no page cache > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > index 145bb561ddb3..bead6bccc7f2 100644 > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c > @@ -1080,6 +1080,7 @@ static int me_huge_page(struct page_state *ps, struct page *p) > int res; > struct page *hpage = compound_head(p); > struct address_space *mapping; > + bool extra_pins = false; > > if (!PageHuge(hpage)) > return MF_DELAYED; > @@ -1087,6 +1088,8 @@ static int me_huge_page(struct page_state *ps, struct page *p) > mapping = page_mapping(hpage); > if (mapping) { > res = truncate_error_page(hpage, page_to_pfn(p), mapping); > + /* The page is kept in page cache. */ > + extra_pins = true; > unlock_page(hpage); > } else { > unlock_page(hpage); > @@ -1104,7 +1107,7 @@ static int me_huge_page(struct page_state *ps, struct page *p) > } > } > > - if (has_extra_refcount(ps, p, false)) > + if (has_extra_refcount(ps, p, extra_pins)) > res = MF_FAILED; > > return res; > -- > 2.38.1.431.g37b22c650d-goog >