From patchwork Fri Jan 26 13:28:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13532579 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 BDFACC47DDF for ; Fri, 26 Jan 2024 13:30:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C6B46B0092; Fri, 26 Jan 2024 08:30:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 400D56B0093; Fri, 26 Jan 2024 08:30:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F0636B0095; Fri, 26 Jan 2024 08:30:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1EBA16B0092 for ; Fri, 26 Jan 2024 08:30:20 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D9C6CA1B99 for ; Fri, 26 Jan 2024 13:30:19 +0000 (UTC) X-FDA: 81721546158.02.A0C644C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP id 333DE180021 for ; Fri, 26 Jan 2024 13:30:17 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xBGHGj1Y; dmarc=none; spf=none (imf06.hostedemail.com: domain of BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706275818; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V5jPIUfKsRr3xLsTmFNsrdIB2xqWv10CXj3w8yCOnis=; b=A7IflLPS5pPo6kdIYoQRuTe3dcEHKNRELDrut4zRY/PZqWF8QY8akhHWWMav3qefz+CCS1 ofqPCK66fwcvVQcpJmOSQFUtyKDBF2nJ1Fk2o9p1y6BYt+UmasEB4TKsaYc4MCYBTPF0qW /HiD3PsvhFV5AnQKdwVHDq3lTp/fXUI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xBGHGj1Y; dmarc=none; spf=none (imf06.hostedemail.com: domain of BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706275818; a=rsa-sha256; cv=none; b=hFbVqTNXaAL2Ei36fc+YV74dqdGIa31o0l8ZEX2yQT41J5FDGtkht2N+6SK2Gwy/y0QE3I ib6lFeokAOL9oJuagrBAwIpcAuk/TD3E8vPjVdqypJVhH0WOaPuI4i+GhVUOeRkWWU+FwJ qkFsG5WhVvyOZQj+B8Sk6fh/VMlWQQ8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=V5jPIUfKsRr3xLsTmFNsrdIB2xqWv10CXj3w8yCOnis=; b=xBGHGj1YCvV8LW1bNvApAzq9s2 +XE2hub7o2/AJNtq37KwJ2Q+3ma57HUBNiG6rICNZVXDFHwoT5eTlKlpRnzcviEeSqJD+EFL74+2j rE42kauLYoPjXb5Li/njzEu2xtBBkD5iXHLqKjftVAtQbGhTbdLgMX0DPoBZUo8WgrsZfnnuJ9I03 kcLvGUkg6CTQMPpsFOkzfVLy0Zon9JmN0EDBmCLtyPJIv7m9zLj6bK1I2y5BQjbXVEJ/h84WCwYBd UsFCmk8v7Nn8BTE6HEXoidT98Asq2lyAA4h+fJPEx0R80aDE8gRpCpr5l8kkRkeksaOPk1tyusiSb s/QwandA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTMHf-00000004Cuq-3E2m; Fri, 26 Jan 2024 13:30:16 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" , Hugh Dickins , Andrew Morton Cc: linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 16/21] xfs: improve detection of lost xfile contents Date: Fri, 26 Jan 2024 14:28:58 +0100 Message-Id: <20240126132903.2700077-17-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240126132903.2700077-1-hch@lst.de> References: <20240126132903.2700077-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Stat-Signature: kdqihzb1h63ts1gj4zhchbybcugorbcm X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 333DE180021 X-HE-Tag: 1706275817-95630 X-HE-Meta: U2FsdGVkX19LH4qzN61qwy1R/JfCpqEu13PfU1kKP3u0cBqgbn9DIwgp6hVgjcNb21MkeUQJD46zMEe+wKb1M6T5QcVe17Rwf2pbV1qERhD1Fyb0npTmuWK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Pi5cF7/SVbiSNgzWKA/NUeMMjJTjJOeZtP+yv3uaI2/1Mi+V1O3LxftXO4nF5MBV2H0G+5Xutkl0CIA4tGYvfmWnaOIko06QKpvJ8ZLZaHN4UMF3sx3A6fdmk7UwvtOHRM7KvZ1IkdsC62rpjPjfgWBOuyhNegginGW3J6Xqk5KZht8kOZU9YkTFAppIfObJqvsP3o+iddQKaOYOLJ+Vi24tsNamLJd4iqxFle6x1eqMgmv1/TP3nfAHlifS6wNrj+1pCE7dgX0hx1kpG1Yw== 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: List-Subscribe: List-Unsubscribe: From: "Darrick J. Wong" shmem files are weird animals with respect to figuring out if we've lost any data. The memory failure code can set HWPoison on a page, but it also sets writeback errors on the file mapping. Replace the twisty multi-line if logic with a single helper that looks in all the places that I know of where memory errors can show up. Signed-off-by: Darrick J. Wong Signed-off-by: Christoph Hellwig --- fs/xfs/scrub/xfile.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/fs/xfs/scrub/xfile.c b/fs/xfs/scrub/xfile.c index 077f9ce6e81409..2d802c20a8ddfe 100644 --- a/fs/xfs/scrub/xfile.c +++ b/fs/xfs/scrub/xfile.c @@ -99,6 +99,31 @@ xfile_destroy( kfree(xf); } +/* Has this file lost any of the data stored in it? */ +static inline bool +xfile_has_lost_data( + struct inode *inode, + struct folio *folio) +{ + struct address_space *mapping = inode->i_mapping; + + /* This folio itself has been poisoned. */ + if (folio_test_hwpoison(folio)) + return true; + + /* A base page under this large folio has been poisoned. */ + if (folio_test_large(folio) && folio_test_has_hwpoisoned(folio)) + return true; + + /* Data loss has occurred anywhere in this shmem file. */ + if (test_bit(AS_EIO, &mapping->flags)) + return true; + if (filemap_check_wb_err(mapping, 0)) + return true; + + return false; +} + /* * Load an object. Since we're treating this file as "memory", any error or * short IO is treated as a failure to allocate memory. @@ -138,9 +163,7 @@ xfile_load( PAGE_SIZE - offset_in_page(pos)); memset(buf, 0, len); } else { - if (folio_test_hwpoison(folio) || - (folio_test_large(folio) && - folio_test_has_hwpoisoned(folio))) { + if (xfile_has_lost_data(inode, folio)) { folio_unlock(folio); folio_put(folio); break; @@ -201,9 +224,7 @@ xfile_store( if (shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio, SGP_CACHE) < 0) break; - if (folio_test_hwpoison(folio) || - (folio_test_large(folio) && - folio_test_has_hwpoisoned(folio))) { + if (xfile_has_lost_data(inode, folio)) { folio_unlock(folio); folio_put(folio); break;