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 E6B15C433FE for ; Mon, 7 Nov 2022 18:06:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 187498E0002; Mon, 7 Nov 2022 13:06:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 136948E0001; Mon, 7 Nov 2022 13:06:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04DA28E0002; Mon, 7 Nov 2022 13:06:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EB2728E0001 for ; Mon, 7 Nov 2022 13:06:09 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BCEC540889 for ; Mon, 7 Nov 2022 18:06:09 +0000 (UTC) X-FDA: 80107425258.17.9A306AE Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf27.hostedemail.com (Postfix) with ESMTP id 5743D40005 for ; Mon, 7 Nov 2022 18:06:09 +0000 (UTC) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-37342ba89dbso114315497b3.1 for ; Mon, 07 Nov 2022 10:06:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=j60fk1GX1r+NlL9MlNZCmp8WSDoORaTrNw5+KLoJy/4=; b=Mf6r8tPrYM3LamVKchqSLk/dmvuFcNjB5NxU9/TNA/LJR4+Uh6XqGidKCN9FLz9j6m 5gN67h9p+bLYpCjhvc8IX2CAcX4UVPj8TTNmTLQlD8LZNhhCBfuUhNVOyi4YFV9Cslm6 AhdPCARfNOufm6rPh+qX4CH2KdXaRwv31osB1U4pHViwGvPXTpaxGAj8nSPx7FSGxRB4 +bKsZS3bxkBP2fqFSyYSg3BcOjx2bkaxsJ2wtpBxsnFPpuiZfD1FUTU7e48qA9xSUo21 QvC3cJW2wJT2ZTT75eLJOPbDmwnzWYEohD/r29NC7k+wM2btkY3eRlPA4CapntnDrd5R pr/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=j60fk1GX1r+NlL9MlNZCmp8WSDoORaTrNw5+KLoJy/4=; b=LPmTawdkx1Ql9LqCCUMm3jf5ivjrTRANMVzUAtkojgXFfmbHUM6mS+HmJjWo4eliGR 2TX7dVa2yxVpEVq0ZULVeay9yg50o3UJPGfEy8AlB10vvjEboSQiM1pTDwjh4RHE5wH7 LBLbjlX34AP10JzgAIe+1LxwZs+FanDPdhOsqTKEYg+QQzFwpzf/B1dP1elCblFqbi+C P8LzWD133tezhF1YFMT/eunwttXzyK13mDNj6VRjO0SJocev/NHZFhH9M5NCyIzz0GeY MO1JRcfGjKk9puj7MdyT5e9OZ9n+9NRHsnBA94NwNAmB8oKBZpiSityk4UfHa9QCNxzi FBPg== X-Gm-Message-State: ACrzQf1v9Oc6LgwwLhA0Ha8pqY4ESKBnSPM7eHeTsTI3vejlKnzYf1uX 4Y7MihgNtVBrEUGvgRSjRgJb/vrBT6/OEMxT X-Google-Smtp-Source: AMsMyM7RHwAxsAmUPng5raelGOKXR8aFY878B1n1s2rNW5vI6CWnaeE3l0ZswkUAr2+iO/m1XeFXM+P1fxqlCA2J X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a81:e0f:0:b0:349:a047:655e with SMTP id 15-20020a810e0f000000b00349a047655emr50840803ywo.373.1667844368522; Mon, 07 Nov 2022 10:06:08 -0800 (PST) Date: Mon, 7 Nov 2022 18:05:48 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221107180548.2095056-1-jthoughton@google.com> Subject: [PATCH v2] hugetlbfs: don't delete error page from pagecache From: James Houghton To: Mike Kravetz , Muchun Song , Naoya Horiguchi , Miaohe Lin , Andrew Morton Cc: Yang Shi , Axel Rasmussen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, James Houghton Content-Type: text/plain; charset="UTF-8" ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Mf6r8tPr; spf=pass (imf27.hostedemail.com: domain of 3EElpYwoKCGkQaOVbNOaVUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--jthoughton.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3EElpYwoKCGkQaOVbNOaVUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667844369; a=rsa-sha256; cv=none; b=uMLBu84FTI3p2xKIvx8NmbmV2fwAvrwWCKzs5lwdrlKJiA8Qd+2GRC1PV6M8fO8vyhZjAA IEQl9xZgrvEyMutc6PHc1NTu4gsCARNIqKuv+YDj1cke8C+2Tz9JcOO9EAYxET8HffJ/U3 h3nczVlei3/3AopfAobPIkuzBLh6l18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667844369; 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: references:dkim-signature; bh=j60fk1GX1r+NlL9MlNZCmp8WSDoORaTrNw5+KLoJy/4=; b=3eGxjEoYk3PPJwjrLam3Wda9C3w1S8t2DtwVJI4qqBdoqEV+0541c4RDabbs77r7xib277 rtstpcr+OoG81qJczAToPs3v3mMXEbSaj87j4hWDNEFChmowvSbxahMILJvTtEOLkQaNmt 8uq9PgiIsZVA19PpsNDJCOiSub+qbmQ= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5743D40005 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Mf6r8tPr; spf=pass (imf27.hostedemail.com: domain of 3EElpYwoKCGkQaOVbNOaVUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--jthoughton.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3EElpYwoKCGkQaOVbNOaVUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: aj8irmjofz16bumep3za46wuskrca3jd X-Rspam-User: X-HE-Tag: 1667844369-727672 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: 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 --- 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