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: 11752 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp3524239vqx; Fri, 7 Jul 2023 13:33:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlEVE4nMkUVDqyrPb9XcYw1xuVuNoamuBW8whTWxh9k3otPDvcXRvPQSAdrmSWhix48+YGLS X-Received: by 2002:a2e:a312:0:b0:2b6:ccd6:3eae with SMTP id l18-20020a2ea312000000b002b6ccd63eaemr3924158lje.17.1688762027075; Fri, 07 Jul 2023 13:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762027; cv=none; d=google.com; s=arc-20160816; b=Tx2tQCCgAqnzdhKy3zQ8Rzid1k/D7P67kV8kRB7E9dg4MtWUZ5Am7S9kVRMWgXzo1P 6zw18f8jBMAjEiN6gxDCdLJQxNMFAmUTeWL0OvJueSLlXbFDcVqmKuS4gsFNtWU0d135 +68CTX8gVyRJvlX2oaq8fROlRmmfuqe5KHAOrHSfA00lDhBEf2cFj2xv8B5FnPDBbfJz FlWlvMXPS77xbrqGTufKmDtyZHuq7/zv1Tck79QxTM5Clb/rUai9Pw1paM0ZAd+M00gg he8486nry31x83Sbm/pTPdqarE0+5n92ZX+mPy5vfGhsuqZoSxPUE++E3QzVHPRbCDLU uVlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=5cuWPEEHk0qemKXdohzw8tGEj12XWM9UTKttPYReOKw=; fh=dXuKmv+n+4RrXbgVwL2QlK4VwZMBf3WumGals2t2WtM=; b=MztITynCeUVM5icpSsuP1T8RG+mnNTyVtc+kcqaRZnrwOLQGGlrJ/Epm0FMFVMpiEQ 78FeqYNKq6dEx4QrLlXjik/xQCzxqUv9p4d/tbvUXo1TXmKAkNvPWbIsKmPgAkfK8+Mn MI/ypPETLKo9ZaD/APyTU6whetjoVQOTpAccEUBiCNv79+KYhVu5KnoFmoSB2sNvbfBz einhrpjyrHlRsbhd+W/6H1A04j9jXTbSsJc8ti58lpT/MTc6iEUywWw3VQIk9A1PYJgc XKrMHZj4T7L/dVoC/++NZWF/InfpGyzWNY/QdhD8PN/kpxh/jlnBQf3a/Mi0FBMVnobh zIYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=PaHzD33A; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a170906858d00b00993a37b5e5csi2528889ejx.394.2023.07.07.13.33.23; Fri, 07 Jul 2023 13:33:47 -0700 (PDT) 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=@google.com header.s=20221208 header.b=PaHzD33A; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232738AbjGGUTX (ORCPT + 99 others); Fri, 7 Jul 2023 16:19:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232729AbjGGUTT (ORCPT ); Fri, 7 Jul 2023 16:19:19 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EB10FE for ; Fri, 7 Jul 2023 13:19:15 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-666eb721e75so2860686b3a.1 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=IiTfqpLTs54h64eMIrPrqZU3Dah85Rq7geT+PbbqX70ZjyYBOAdo8LKHzjQr2DUC4D t0YLuNbMCCaSXLb/zqwlwdCWy9NKdl6CCap3hN+OTPO2Elt77gWfIsar/AJ7+s2JYWtD sZCIZXO5ncs6VTsxps6TSsp3U9TOJZOmci9TkatrW2Xp3inczVcZx6tQsKJwQjpMJUtB JB5PMdshE43T2OxN8CdrRH2KOPbZiKY3Qgq6hS9YOXdnASfgvxgxOFQBZufwCqPv1xkc JfR0x4jM+uVQQuDPp4lIqVw9qcf4V2iSuHWz2W2xcMfZhr1kt6foP7NOJUtmiK7YSfWW uRww== X-Gm-Message-State: ABy/qLYXqhiZw63iMx/2EA6+d105vDGJ7C8uD7u0N5wKxEnTTiN13wo1 lO2pSM1T+aWPwXtAbpbbZuRUGHw75pbjfg== 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-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770795331464705440?= X-GMAIL-MSGID: =?utf-8?q?1770795331464705440?= 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