Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2251438rwb; Mon, 7 Nov 2022 10:58:49 -0800 (PST) X-Google-Smtp-Source: AMsMyM40SVFGlop/CPdyezHMABvMdkFJpVG8F/9ZHnI1Re3URvSC2yXQWPvx3L29MWAE9336DX8z X-Received: by 2002:a05:6a00:2187:b0:56d:4d02:5776 with SMTP id h7-20020a056a00218700b0056d4d025776mr46104518pfi.4.1667847529543; Mon, 07 Nov 2022 10:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667847529; cv=none; d=google.com; s=arc-20160816; b=os+/qp64LRK8Tl96G6xepX4UcyaCKam4zeqOwHvbPR11uQynueAKoYJ36wgOhW3tSj c+PGo2U+NGieMfUMhUklvmzl4XwKqKUhDPVKeB5lEujywrgCLe11q/ZMswNH+PKSK3G/ LgvKtWXuJp44BpTfEpNDdw1T6+XRWhiQFLIwXhQw2kEuzto/QW6hC2fhI7RfCYVYCXDk jvzBk6J//4EGmafcWmt0/zQNxuDI87KswG9U1XiMrqe8XmBbK20GnF/XjwzFMWWskMB1 f9d4G5JLqjIsKFDk715KbAzKr2J+z10pRKd1JFDbDnf8LAnwiuMiv956W1ptDAE3ZkaE xHJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=lAsPldyH1+ehPpIMIyGZ2Vh4cO9qav4LSbU+Q7y0YxQ=; b=cGtsTn0703PcQhNYI+qUPk0fKtFNK4a8QqgrfQxHSNoe0bsw6ex8CewbJL72GbNi0Q MWAfRcYD+823EPzdJeLwtQeMRpELw9ePVHYXLNOtP5DowuvlZSAQ6xf3/ReCbHtdevAc n3u4iy3kkIJ5kvlCHYInI8I6MwuqnWo5HzdyE81KQmOQG65FGcw8w5LgFDDH7G7qnLoj yobI/GTqT/K4LEY5VkRK9jDXvVPWT/Xin4Nysp1/3TEONrA5z7A4tfuVuRePsjK3vJVW 39eyghgQygAT449QTDnQcIe1+zjfd9KE6R5BTZQYP+mPFIiPOZulj72h00e+AsVmMEYE ffGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=U85gWRsD; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k186-20020a6284c3000000b0056b972a8cfasi9797058pfd.121.2022.11.07.10.58.37; Mon, 07 Nov 2022 10:58:49 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=U85gWRsD; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232913AbiKGSyI (ORCPT + 92 others); Mon, 7 Nov 2022 13:54:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231426AbiKGSyH (ORCPT ); Mon, 7 Nov 2022 13:54:07 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D6411116; Mon, 7 Nov 2022 10:54:06 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id o7so11436009pjj.1; 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=h1/1a3ND5eQxTPW3a8MJECYSP1jCP+dN5o/SQo5y3hwWEdAvgSp/RF8QFTTtVStpj8 nhBsiuWkorBwzoLSsx34CNd4/6CQeziWJ1xa2YfSFVebS2F9CIu7Z9u/XGpAUrDvRQ8n /EG4nNo/pKncrrp2/ohwanUM3b/oAqZ30wfqRbw2wN3ANoDdvQqaF9MhKUjCuXOKW0L+ 6s0+oJk8Q48E62OVDFHSg/QH7c3BelsrJ6OhkbE03PJzUoXr3VXWCkg8exj0Ss05idUa JDmv8MVhL2uGr57g+SXpTUCwk+Vixnj13mjUHVmmkywt/XWtismNbteWgWGocirDcgWM l0Hw== X-Gm-Message-State: ACrzQf2bCG5dxdyHnystAyi2C/T3ZI9QWmY6l7ija0fLTYMWx7Avn2+I hPAPM1qIq4445M2ZnFoMZTWrhhRY1PnAyYjC9UQ= 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" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 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 >