From patchwork Thu Jul 13 00:18:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13311065 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 8D011C001DE for ; Thu, 13 Jul 2023 00:18:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDF218E000D; Wed, 12 Jul 2023 20:18:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8DFE8E0001; Wed, 12 Jul 2023 20:18:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D05C88E000D; Wed, 12 Jul 2023 20:18:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C35BC8E0001 for ; Wed, 12 Jul 2023 20:18:44 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 91513C03D3 for ; Thu, 13 Jul 2023 00:18:44 +0000 (UTC) X-FDA: 81004677768.29.A15C281 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf29.hostedemail.com (Postfix) with ESMTP id CA08412000E for ; Thu, 13 Jul 2023 00:18:42 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=dypHe3K1; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 34UKvZAgKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=34UKvZAgKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689207522; 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:in-reply-to:references:references:dkim-signature; bh=6XARlF0BXnO6/4Atr6/Ka8Rsp7ITnYdH8gSSlCIsHmQ=; b=d1QD+vNkMkFC2qaG7ZppjVJYC3++1RBODducVLrdwrqV+e4xmAvVAsCNqkLWOClEqv/f6C CKbhKQ+rVji8y2Z7J46e/ODUK10+6BLh+8FamCn3xBFJA0Pwkwk8ivWz9GAfSeD7jHbomx 039+81wTqn8VCi/DQC5Twnii8x2pwH8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=dypHe3K1; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 34UKvZAgKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=34UKvZAgKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689207522; a=rsa-sha256; cv=none; b=lCj2LIZi/ysxqammwaU+ipvYiSeGIGIqG/OwjTpI1VpiIXagBgvDmRAaWkF3aGLV0jflbK /S+fazN/b7mMhk571xIUgosVEGkuql6gIzBnS/4gaqwZvLuJB3TiCdZDwuxF6bsLRtyhJE SAenPIqGwSucOUKSV3wb/elGsLrGL1o= Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1b8a44ee130so895445ad.1 for ; Wed, 12 Jul 2023 17:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689207522; x=1691799522; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6XARlF0BXnO6/4Atr6/Ka8Rsp7ITnYdH8gSSlCIsHmQ=; b=dypHe3K1l/c1oaj2HHVrHq7fKVxuhlr/Ku9wHIlgid2l5uxeWU6gepVzV2p5HJ+Mtn HQbc73phPu16+ziP3vR3iq444D/tI3BAZT+QtWryBgLc3sVCy5eU27hzqaAtG1F8EqMl o/uPkLyFyiabmK6g1nZ8jFcEXuWM0VnyC/xfa332OEOupMY+ygXwWjny1snuRDFi0JkG s3xf57LVHLyYM8qLCEOrGRoywDSE6krtphd9CuaI+egnsX7ey3Kuc8nYch5I/S9m9RGe skHC5e2MOBIE+ANgafHaV29E/DQKCyjKboQ/a6THaV0HVxs4uK2tWwdUET7s3EB7CyXK CWZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689207522; x=1691799522; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6XARlF0BXnO6/4Atr6/Ka8Rsp7ITnYdH8gSSlCIsHmQ=; b=efKwAW9mbGDcdPJ2dXoLQ8OP2ze6IzzuDKkz24wHR+E9UXmIMpubIP+8VrXFKiZgHe jHmgKky58jOt13rcc0pbwpdRdFoY1U5YPUVI0s0abXJnrGlVrZe8mcU0Z4IKh98Aou/j iqTkqFJx3VNVB0LQ8Z6ZC1vn3rlmRjFEj0+8e3vWOYmApERxRb3mRc6QmCAqDkVwiwYb BipOHKEMeofUnxN/yQcR9OqXpnsq4hYW3j6tdCtX83qXoEXTYPFj8PcgvpSPy1U1vKHX tTkNzGT5OuXScFCbb6d2gYBhlBkC964mziE86jAG8KcVYODxvQYdIF6Wr9FHfjoe1Lm0 PUUw== X-Gm-Message-State: ABy/qLYmz0XTQ29Yhivn3ElSTFBidgm7LvA7jVkaBwJvxLw8nHn1BBVG mS7MENCy7y01Yudl2lXmlf579uzFD4iYoQ== X-Google-Smtp-Source: APBJJlG1dH5gtGtj7+R2nOPMgHiIgop3mdrBpT2PYcsdRrW+V38DX7do6vdw3iO2pKOF0QHuX8mPhg685Rik7A== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a17:902:7448:b0:1b7:dbb0:782b with SMTP id e8-20020a170902744800b001b7dbb0782bmr496plt.10.1689207521799; Wed, 12 Jul 2023 17:18:41 -0700 (PDT) Date: Thu, 13 Jul 2023 00:18:32 +0000 In-Reply-To: <20230713001833.3778937-1-jiaqiyan@google.com> Mime-Version: 1.0 References: <20230713001833.3778937-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230713001833.3778937-4-jiaqiyan@google.com> Subject: [PATCH v4 3/4] hugetlbfs: improve read HWPOISON hugepage 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-Rspam-User: X-Stat-Signature: dj5jfejstt5uhos3n4zqoda9fhasn1zx X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CA08412000E X-HE-Tag: 1689207522-388640 X-HE-Meta: U2FsdGVkX1+8bNc6ogbEVLN14WJVxKzTkhZT10oWS2Jxj2Ax/cl/5WK+3GDxLBdJUxyruTbMqktsTfbY17MYUPtgjIuUCWBM5dG+ATl6tu9D9Maut4DVMAHlYr+FrQ2IGiS0ZkAt2ouo5/bP61VRSLz7wzR+Dj8zMXayFHAqdRBenrgX3CjFR3mB5HgrClV1E6r6R+bAHJM3kQ4Xf8b1QuFTK9lAO9LjQaXuHZmXfLmgPzntg1WVK0uMKQNfVO0ZFVQBaFu4hRWj8p7fu6kaWScOWgIlNFNICahGeVpyfX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tA2nTGcbt+JKQ4P1ziBXuCQzeRLZ7D6w1MOmg3RmDjftFtiBHUgwVOEp/kml2vPK69fn8toCbCb2+6Tj4ZKEu9qnzFOQ7+hhFEf8bFdrZeJsM2Asu+BN+KIO+HgufBgRC65SE2tchRUP9dyicjlZGMlHt51Mw3unxNxPv0tC9UtJ/ES1BHCW7DDLB5fqjtPDnNC6DwY+fOWawJi+9l+K3mmt6frP0e/BvXga39B0KKqixfJz50cXBR10NoYU9pjSCXfdzWhKTAgg6DG+mgBmXOQfojmM3I1763dRJPVX468= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000483, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When a hugepage contains HWPOISON pages, read() fails to read any byte of the hugepage and returns -EIO, although many bytes in the HWPOISON hugepage are readable. Improve this by allowing hugetlbfs_read_iter returns as many bytes as possible. For a requested range [offset, offset + len) that contains HWPOISON page, return [offset, first HWPOISON page addr); the next read attempt will fail and return -EIO. Reviewed-by: Mike Kravetz Reviewed-by: Naoya Horiguchi Signed-off-by: Jiaqi Yan --- fs/hugetlbfs/inode.c | 57 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 7b17ccfa039d..e7611ae1e612 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -282,6 +282,41 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr, } #endif +/* + * Someone wants to read @bytes from a HWPOISON hugetlb @page from @offset. + * Returns the maximum number of bytes one can read without touching the 1st raw + * HWPOISON subpage. + * + * The implementation borrows the iteration logic from copy_page_to_iter*. + */ +static size_t adjust_range_hwpoison(struct page *page, size_t offset, size_t bytes) +{ + size_t n = 0; + size_t res = 0; + + /* First subpage to start the loop. */ + page += offset / PAGE_SIZE; + offset %= PAGE_SIZE; + while (1) { + if (is_raw_hwpoison_page_in_hugepage(page)) + break; + + /* Safe to read n bytes without touching HWPOISON subpage. */ + n = min(bytes, (size_t)PAGE_SIZE - offset); + res += n; + bytes -= n; + if (!bytes || !n) + break; + offset += n; + if (offset == PAGE_SIZE) { + page++; + offset = 0; + } + } + + return res; +} + /* * Support for read() - Find the page attached to f_mapping and copy out the * data. This provides functionality similar to filemap_read(). @@ -300,7 +335,7 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to) while (iov_iter_count(to)) { struct page *page; - size_t nr, copied; + size_t nr, copied, want; /* nr is the maximum number of bytes to copy from this page */ nr = huge_page_size(h); @@ -328,16 +363,26 @@ 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; + if (!PageHWPoison(page)) + want = nr; + else { + /* + * Adjust how many bytes safe to read without + * touching the 1st raw HWPOISON subpage after + * offset. + */ + want = adjust_range_hwpoison(page, offset, nr); + if (want == 0) { + put_page(page); + retval = -EIO; + break; + } } /* * We have the page, copy it to user space buffer. */ - copied = copy_page_to_iter(page, offset, nr, to); + copied = copy_page_to_iter(page, offset, want, to); put_page(page); } offset += copied;