From patchwork Thu Jul 13 00:18:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13311063 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 4CC97EB64DA for ; Thu, 13 Jul 2023 00:18:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A20498E0002; Wed, 12 Jul 2023 20:18:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D0108E0001; Wed, 12 Jul 2023 20:18:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 898358E0002; Wed, 12 Jul 2023 20:18:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7B00C8E0001 for ; Wed, 12 Jul 2023 20:18:41 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 431CDC0403 for ; Thu, 13 Jul 2023 00:18:41 +0000 (UTC) X-FDA: 81004677642.19.70D0131 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf23.hostedemail.com (Postfix) with ESMTP id 92EDD140014 for ; Thu, 13 Jul 2023 00:18:38 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=sSvffJG7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 33UKvZAgKCEwxwo4wCo1u22uzs.q20zw18B-00y9oqy.25u@flex--jiaqiyan.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=33UKvZAgKCEwxwo4wCo1u22uzs.q20zw18B-00y9oqy.25u@flex--jiaqiyan.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689207518; 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=ja2GaLe3g335IB6oeNLcPuMSFkLQtw6DqY/qEV7GBLU=; b=mF4pXfrzkVsr/Bx4LcSVWO/mK8AUNb6OSqDpZDtLURjP800WXNgXfAI6dlq6OhvS9dS317 TsAfS6ovSXzuQ/T4falC4VU5dBA4esP+sMB/oN7gjgK1bI1d97ZT4XXRVMkPegZUS59AG0 Lbrk/1XcskXLzhzrApD9CWJuMzNeFm8= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=sSvffJG7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 33UKvZAgKCEwxwo4wCo1u22uzs.q20zw18B-00y9oqy.25u@flex--jiaqiyan.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=33UKvZAgKCEwxwo4wCo1u22uzs.q20zw18B-00y9oqy.25u@flex--jiaqiyan.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689207518; a=rsa-sha256; cv=none; b=uDAS9RsHdx4kqYAQVJJ21vKWT1SzXQLzgYYke4zXmHZAd5ItEVAxQ6p1WZQWu0J41T02H8 J1YQbS1n9duqAw6YfF1t1D+SdHrFGqYtkhYF+dasa97IZaQGmup76vE/Fn8ZcpI6FYSWfr XzSISprteLHL2sosSyZjhqWisY3m0kc= Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-55bb5191cd1so99256a12.2 for ; Wed, 12 Jul 2023 17:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689207517; x=1691799517; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ja2GaLe3g335IB6oeNLcPuMSFkLQtw6DqY/qEV7GBLU=; b=sSvffJG7xloWj0xslk56oYNElU6sGdnDP1NivBKRPkTAcD4pqPFb2cRhNF7GGpfuZC i/SDqj16RtWk2642Ou/AMLJ3ec5/si1D7yta4V4NLBWU4Ycjo5wWKl7/sfJZNmHEYiYN +9NA30YQ7GSXJStIzq5GrOCNHfnhK7v3UJMmpPixPkcKGW1d1Z53jD6+fXe3aXmJZsXL g9MlPog3zzfQp5oY4ltY0as50tJyEmtIF0twGgvrUDE8LocBNwtQzn8gme4Ofy0RF0dz eKsFs49Nxvp3xxcLigbFaO8Hc08TYXMGkZDZjOi1Fj2zsufrl26geQ3cYggVyBKzLDX+ PYhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689207517; x=1691799517; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ja2GaLe3g335IB6oeNLcPuMSFkLQtw6DqY/qEV7GBLU=; b=JnzqhNW2xqYvQjxlNV3B7rlAQ9MH2jA4HU9qDph7uyEkyaL4lU4nYLtYMiJK9de+mf eWVrEZOkCgZitKJBa27+3AYrZtR5rv2YtPVDatK/RKoD1EL9V/FCYRmulVmSOG/G/PtB kN2P4fyQD+YHN4wWzUlg9xdCCTU3hQ7a73JIFLYQyPHWrt1DVL+MRq1ilkegmuPydQLv UENhI5/uQ8veLamtHEm7Rj9Hi9U6BPEwcU9H5zaSuLgnjhbNOKcltrpwebjo4fMc5kWw puilgB9bAx3aDQ2on1m2ejQxkWAALLsS7TYqsfDxmc0UpwIYZPSzKFy2jr1CajZ4qZ2N a+Pw== X-Gm-Message-State: ABy/qLZ9RktoTBMiXy00Wuy2lG9yswL2e/df4CbPt6oJwDpaIQYmbXdK rw1VL94xefMEZAtWCM+uWzfkTvuDXFRUrw== X-Google-Smtp-Source: APBJJlGtncLzAwvfmCIMVnb1+qNlBnXGUpvLOlivkS2jNCdjnGNupfd6nQULBZqoNC0x0OsjN3lvv2K6cMUGBA== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a65:6a84:0:b0:55a:c629:4047 with SMTP id q4-20020a656a84000000b0055ac6294047mr10115518pgu.6.1689207517185; Wed, 12 Jul 2023 17:18:37 -0700 (PDT) Date: Thu, 13 Jul 2023 00:18:29 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230713001833.3778937-1-jiaqiyan@google.com> Subject: [PATCH v4 0/4] Improve hugetlbfs read on HWPOISON hugepages From: Jiaqi Yan To: linmiaohe@huawei.com, mike.kravetz@oracle.com, naoya.horiguchi@nec.com Cc: akpm@linux-foundation.org, songmuchun@bytedance.com, shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jthoughton@google.com, Jiaqi Yan X-Rspamd-Queue-Id: 92EDD140014 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: tmf8wjhwem6hz4tcginixq48qpsz76nc X-HE-Tag: 1689207518-149823 X-HE-Meta: U2FsdGVkX188DC3o2s6FI97fwfP0jULW0gBug+CcdGY9ImOXawB+vO5lpF96jHaMvtuTJpV4IOst/IiQttt6sUcNiSb+cyNJc4mBqgQt5dfiX4eue36MjXIfhJEPeLjywlask+4bMDw1ecpwnaPVtf8irkML2TCEATIGCPQXg9jULVNMZ+/XY9Ej3RVOM42AmacDdOp2rtg8fhwWyVpsuSiiBVzcGyOiMJazDFFRqEGP4dECxNTTdcbKaLzDLx9nOggqrqtZZoKlbvs78XeY3x93evhXw91E4rg3Tlfsqa42RnEZY3LkrPRp1KQpXhV1SLz0LXuT8C7EwGsSoL0yMkl6S2pvBPdN0ZmN3RiTfU369RAU+p/0QWm1JCiaaqI+PFJFfh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1MnAlSn5uwG3XYKbMrgLZePo79cvj4k9+uNw8WwgWtmsc3n+P/FzzFyteo94wFsSUa7zDa6ynVtsMQhobNLR3gvIsIg9B2h1naX4Z3573ymR5++E4ARiYguaQfEvmgqbidjsn/nHtlcHI+v6/ohaaniScu8cYWkiW02K2BecYBj2+t1UK8gj9PC+050cfumHI1rLt2fQdwXQ2VjlILXqaVWY35/A5xXnDA1v6Dgp2xklxBIPSrJB+YrEA6hVJitUpqpe9z1XksuMu+Ivbmy 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: Today when hardware memory is corrupted in a hugetlb hugepage, kernel leaves the hugepage in pagecache [1]; otherwise future mmap or read will suject to silent data corruption. This is implemented by returning -EIO from hugetlb_read_iter immediately if the hugepage has HWPOISON flag set. Since memory_failure already tracks the raw HWPOISON subpages in a hugepage, a natural improvement is possible: if userspace only asks for healthy subpages in the pagecache, kernel can return these data. This patchset implements this improvement. It consist of three parts. The 1st commit exports the functionality to tell if a subpage inside a hugetlb hugepage is a raw HWPOISON page. The 2nd commit teaches hugetlbfs_read_iter to return as many healthy bytes as possible. The 3rd commit properly tests this new feature. [1] commit 8625147cafaa ("hugetlbfs: don't delete error page from pagecache") Changelog v3 => v4 * incorporate feedbacks from Matthew Wilcox , Miaohe Lin , Mike Kravetz and Naoya Horiguchi . * rename is_raw_hwp_subpage => is_raw_hwpoison_page_in_hugepage. * instead of taking hugetlb_lock, is_raw_hwpoison_page_in_hugepage needs to hold mf_mutex. * use llist_for_each_entry, instead of llist_for_each_entry_safe in is_raw_hwpoison_page_in_hugepage. * is_raw_hwpoison_page_in_hugepage doesn't need the folio argument. * no need to export struct raw_hwp_page to header file. * v4 is based on commit fd3006d2d0e7 ("Sync mm-stable with v6.5-rc1."). v2 => v3 * Update commit messages for future reader to know background and code details. * v3 is based on commit 5bb367dca2b9 ("Merge branch 'master' into mm-stable"). v1 => v2 * incorporate feedbacks from both Mike Kravetz and Naoya Horiguchi . * __folio_free_raw_hwp deletes all entries in raw_hwp_list before it traverses and frees raw_hwp_page. * find_raw_hwp_page => __is_raw_hwp_subpage and __is_raw_hwp_subpage only returns bool instead of a raw_hwp_page entry. * is_raw_hwp_subpage holds hugetlb_lock while checking __is_raw_hwp_subpage. * No need to do folio_lock in adjust_range_hwpoison. * v2 is based on commit a6e79df92e4a ("mm/gup: disallow FOLL_LONGTERM GUP-fast writing to file-backed mappings"). Jiaqi Yan (4): mm/hwpoison: delete all entries before traversal in __folio_free_raw_hwp mm/hwpoison: check if a raw page in a hugetlb folio is raw HWPOISON hugetlbfs: improve read HWPOISON hugepage selftests/mm: add tests for HWPOISON hugetlbfs read fs/hugetlbfs/inode.c | 57 +++- include/linux/hugetlb.h | 5 + mm/memory-failure.c | 48 ++- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/hugetlb-read-hwpoison.c | 322 ++++++++++++++++++ 6 files changed, 421 insertions(+), 13 deletions(-) create mode 100644 tools/testing/selftests/mm/hugetlb-read-hwpoison.c