From patchwork Fri Jul 7 20:19:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13305250 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 953A3EB64D9 for ; Fri, 7 Jul 2023 20:19:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F15926B0075; Fri, 7 Jul 2023 16:19:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC47C6B0078; Fri, 7 Jul 2023 16:19:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB4358D0001; Fri, 7 Jul 2023 16:19:17 -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 C830E6B0075 for ; Fri, 7 Jul 2023 16:19:17 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9489A8010B for ; Fri, 7 Jul 2023 20:19:17 +0000 (UTC) X-FDA: 80985930354.16.FE4C651 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf10.hostedemail.com (Postfix) with ESMTP id E0969C0016 for ; Fri, 7 Jul 2023 20:19:15 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=PaHzD33A; spf=pass (imf10.hostedemail.com: domain of 3QnOoZAgKCPUgfXnfvXkdlldib.Zljifkru-jjhsXZh.lod@flex--jiaqiyan.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3QnOoZAgKCPUgfXnfvXkdlldib.Zljifkru-jjhsXZh.lod@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688761156; a=rsa-sha256; cv=none; b=wGsRRyFwlI1e2VIwSHYPkv7G0SWlk9lUdWcuRVLlj2LgqRiZ08kY+6jfUCCvo5GfNio9lG 7YrLgWn8qqKtqps5cFFznwT6eFNdi8TuISVbMjrMfkxclJRBvC4O0sWwN6RYDWu4bNd6xG Qt10bgS4r8DuF69Dx0XNab1jNzAr5oc= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=PaHzD33A; spf=pass (imf10.hostedemail.com: domain of 3QnOoZAgKCPUgfXnfvXkdlldib.Zljifkru-jjhsXZh.lod@flex--jiaqiyan.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3QnOoZAgKCPUgfXnfvXkdlldib.Zljifkru-jjhsXZh.lod@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688761156; 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=5cuWPEEHk0qemKXdohzw8tGEj12XWM9UTKttPYReOKw=; b=7fAT8gEH/fVCmrqKfa3N6aComffEzxAy1sJPrIVKDKcIvP+QOBfXgtNLqnbE3joWHEUENz OVp6Ic6SGXGDN1P+lsahaWVaP18w/DI7Iu1tmoY6ENt9Tzr6UG05JsWIDyHf5gPqTFsQZI Mf1KrF5zmWxpkbSEemmcpuayLSYv2wk= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-682abcb2fdeso2851872b3a.3 for ; Fri, 07 Jul 2023 13:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688761154; x=1691353154; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=5cuWPEEHk0qemKXdohzw8tGEj12XWM9UTKttPYReOKw=; b=PaHzD33A8GbxvtEGuq9tWAYnBOW1xlL2mqiPI2ahcXOm9fn/nE59FBtXB4ixnXnOyi xeKzyZtFH98ipx/zrWpe9QI5rvEzBaA9YyLIHiy1e6jZo5fx/949E8OXquAa8EnMbarA rphXYw+5/NRi1dLVvfbKVoIKQ9IUV4Ori5NuSONz5JWNTPWJV85MBD85a1Lru3KvKb8b 7VsjE9t8VWk/2KbXcHk7dUh6beDQU4dJeNJoMf1RNzK4VwTrjJhDSKBpLkYv8PX9CQRU RTB5aIUDCq6Be1gUe1Ii0aSlYbWQTU3c6+LAunFTzBAYzquOxCH/Sg6uVeHz6ABG5uE6 M55w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688761154; x=1691353154; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5cuWPEEHk0qemKXdohzw8tGEj12XWM9UTKttPYReOKw=; b=ULw61rMppqhD4STarTP5V26wbUUyx+Q2812RpOMuL7wGerkEonyw1oLEonRRB7XnjM JPIz6eaBGtJyh8Ugnp3PyjR4hniAtgqxT338ZCmclHu7pZh0OyPGoGRktenBFFsWOCWS oF2ZGSLZ63X+DHzP3iltRXUn10/9FJF+vB2xLFqBgjeXADqH4dum1S8GbnNc17U6rbu1 QmRLpsf6wDkmPuODKFg6yiRUyGoVoHZq4yZ1pdCkTQHAMfYM2Z1jSa8zUCpsBmHUgJMl PudivT6cNErKjH0gqkPKgVH6WWtihROTm2klhV5Cw3X5gF4d196TszEsNsrBfX4ZSa0j aSYw== X-Gm-Message-State: ABy/qLYnsgoX2q9GxZit/EfE/mXFSl1LSjq1WN0MgjkhpBlzZ6luoM6y VQCfmhTtOib4j6AnZ1T7sWrACZfadjWi5A== X-Google-Smtp-Source: APBJJlELEHiYxWCanU50B0NWcctTGr6R0VtA3e+AA6Y9l8crmkhCRoeflyMRWIMkxMRvVNTQwRWTUXdFG3wmTw== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a05:6a00:3923:b0:674:a3be:2773 with SMTP id fh35-20020a056a00392300b00674a3be2773mr8362712pfb.5.1688761154687; Fri, 07 Jul 2023 13:19:14 -0700 (PDT) Date: Fri, 7 Jul 2023 20:19:00 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230707201904.953262-1-jiaqiyan@google.com> Subject: [PATCH v3 0/4] Improve hugetlbfs read on HWPOISON hugepages From: Jiaqi Yan To: akpm@linux-foundation.org, mike.kravetz@oracle.com, naoya.horiguchi@nec.com Cc: songmuchun@bytedance.com, shy828301@gmail.com, linmiaohe@huawei.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duenwen@google.com, axelrasmussen@google.com, jthoughton@google.com, Jiaqi Yan X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E0969C0016 X-Stat-Signature: cjz5xng5rmzyg8nhuq49in8ec9tje5kx X-Rspam-User: X-HE-Tag: 1688761155-861015 X-HE-Meta: U2FsdGVkX1+uHhya0d5kriRkqGF8/lAJYHmwDSqtNki6dX26qqno23r9z7gwvVwDEiWu41rQ4Aog/hWga+1Un3S199Lt/mTDJy2amb+avc9uX5ZKna1VT7b9zlmNzpJswYnUmNSpUzn8thyDd9Ui4nPHJgdblzvv8/Ql+vz+4O+l8gqRVSz1vO+4KfMngaEBhb8dV1p0O8gyytaydEgWD1hmVZlOtalFvr/IvMtGAd4zA0e4gomjQ8R71kzUr2PfSQbpcz4+wJlJsn3ryNdNV0tN3FuOM4Z731eHVmkGuxWcKEKlbv5U0SndEXUqz2gJMp+9j7yASI0NIXOo9H+lT9XM76QbT9tpO1vSvUeb/V44LbA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iVtcGHndZX2siaRShjcbIuVtzb2skb0kC5hsiqxMRRL1HDDLOHJb9XwZMAzhG44ZETGbVYgh/jQgWaMCCNtXT3MZ+hqWbzOLaYgVaLzzwpzs3x6FAlvcg4tlRvvpXNB 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 v2 => v3 * Updates 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 * __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 subpage of a hugetlb folio is raw HWPOISON hugetlbfs: improve read HWPOISON hugepage selftests/mm: add tests for HWPOISON hugetlbfs read fs/hugetlbfs/inode.c | 58 +++- include/linux/hugetlb.h | 19 ++ include/linux/mm.h | 7 + mm/hugetlb.c | 10 + mm/memory-failure.c | 42 ++- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/hugetlb-read-hwpoison.c | 322 ++++++++++++++++++ 8 files changed, 439 insertions(+), 21 deletions(-) create mode 100644 tools/testing/selftests/mm/hugetlb-read-hwpoison.c