Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp739670lqd; Wed, 24 Apr 2024 15:55:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFPFMtKIbdpQbavVZcNNGqLjI0JhlRW/KeGVx7w5JTupLypVQ7BbfuGql4ESTadg6SumSx8T2aVXKu+VZrTafCVtsQ60+7QsyZ9aVmqg== X-Google-Smtp-Source: AGHT+IFlEABk7/maQX01E3dhPGwO6v7DRVncDdRHgUSyKC5thT0M3hI/kCKROfeq+0MPhcNqtwsc X-Received: by 2002:a19:8c0c:0:b0:51b:528e:ce7d with SMTP id o12-20020a198c0c000000b0051b528ece7dmr3356570lfd.34.1713999327897; Wed, 24 Apr 2024 15:55:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713999327; cv=pass; d=google.com; s=arc-20160816; b=mkGfeRl1k8YuOR2qaLBpgIX0Hhd0JheHaKW8tFkLuD71Yf+OTGEA95PgesBuxzs025 bBOaFMWP4eokN1htXDDUlyFXhbuqekLXBYxoWGP+M5k2ixWUFg9doKfzawZ75vB6ZtqC PUr5m8JxHclrrSumCu7YGzoTWI2AKKIF4PcS838+YIaSJfFwPq9erXxzBPAT43HvSy3d 4XWrC2o7+yxfbysYaErlT59NtWjALTdtnQDM18UYyDhb3gqX5TpEH0INTLULlgbtOvrI J17Zgc6c2Znkflgq0NwtTzVB+5YMdmK9f7WUi3ppkBA7yllcRsEj7Spi+c+Au5p2Vqu/ dZJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=muDeZ0tlWt27kuip/KmoQCU5uSua2F4Lkz04HVCl3SI=; fh=cMQOMgVyRKTASoSL9rhUTfkUzP6uZcdGljnQrcJHWHA=; b=rGsQKV39fHehyYqsxQdteAOnWWSIv3SipdbLXBcHOSuBoCRE4p//Qt+JaS/lCkA42U THN3ccWLnV2Uz7QJWpGDwBR2XXq7aDaqoji0UkdkaLBxlWugV8CcPJBHCi2pnH+3UwlH VePVcBquVrstQKjhD1kPcWXXtGR6J8/x7CXHhNUWv6xsp0lYmyu5gtoYUivOuTiM548C vxnkt/rx2wFa2PKovmRMOvSxLoXptnbn5FHj1WkOCWNRmVEbtfW5smMFFHbbHjDdWN+h EGrui58yW2qW4XYpSe01Pfiz6WEEZxIOK+syIZ3MB6xxV0BYpl7UXi5nW8LczdtQPF8P 39oQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=GLOJ7n9M; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-157811-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157811-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qu25-20020a170907111900b00a55622d1960si8990858ejb.1010.2024.04.24.15.55.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 15:55:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157811-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=GLOJ7n9M; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-157811-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157811-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 96C631F24D16 for ; Wed, 24 Apr 2024 22:55:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE54216F0EC; Wed, 24 Apr 2024 22:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GLOJ7n9M" Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3883D16192C; Wed, 24 Apr 2024 22:54:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713999294; cv=none; b=G3IBqpnaHqh/ccUq4qIOi/n5n5fJgMSJxvpgsz5PcibV3MwPwmqPbVruknQj6gQt1VY5SyfOE9wq4k34eJrN+rXTYPZb3893BdLrtWhjAeWpultKG/ZovsIv545FUMrm8aqbjekb0Qpn0ZQMoGdc0VB5PQ0gSqLgjDOmmO3+gyg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713999294; c=relaxed/simple; bh=T1ca1SK2WRVFnYrwkN6XvRdji6bMVu9U9aghprD8oY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BIRE+EVNI1ynciTf8Goa1/j0ACFXvsGCJWaogEy9iCMTOcehTxD8Zv9GessxGwzULS63Yr3NR/qUgUl7pU1dngVP5ZpI3Pqar2G2x3wIHAQp7TsewQtdpqM0OTx8xXLddwiQEEnPmf9U8Tk8BRB9FQ8vEC6SbgCaE8Ro3ZDT9Io= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=GLOJ7n9M; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=muDeZ0tlWt27kuip/KmoQCU5uSua2F4Lkz04HVCl3SI=; b=GLOJ7n9MsnX8cT7Ol0Jq3B7oke XakDrBz62nFCW1+7tSom1DWnxTdrx9vfGaOdqMPsIZ3ASsJb27N+95zaDfI9JcOOHneo4BZzRhLfP 23kOwiSO5Fm9sTN/ITMOdHhWZ9K9WlMoCGYyaAimCi2UjGE7sbQS808i1stHQBDY66QLmwe/Nvuii jQzyEow4oaq8dhWNg8SajN1NXgQTpBYs9ZhstehX7hnHSa9c3k73IhGttYUG9rOPirt9ejCJiCo4i Ft/vzmSmsCm85YZBlmV+Yx0Z0CiUcXMJ08/mdpkYv5gyGp5+4fSPGZzZjSoj6QXDk8Teij6FTM8xc Jz3b6GVg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzlVq-00000006HlX-16Z2; Wed, 24 Apr 2024 22:54:50 +0000 From: Luis Chamberlain To: akpm@linux-foundation.org, ziy@nvidia.com, linux-mm@kvack.org Cc: fstests@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, willy@infradead.org, hare@suse.de, john.g.garry@oracle.com, p.raghav@samsung.com, da.gomez@samsung.com, mcgrof@kernel.org Subject: [PATCH 2/2] mm/huge_memory: cap max length on debugfs file entry folio split Date: Wed, 24 Apr 2024 15:54:49 -0700 Message-ID: <20240424225449.1498244-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424225449.1498244-1-mcgrof@kernel.org> References: <20240424225449.1498244-1-mcgrof@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain Don't allow to query beyond a mapped file's length. Since this is just a debugfs interface allow userspace to be lazy and use a large value so we can just use the entire file. Without this we can end up wasting cycles looking for folios which just don't exist for no good reason. Signed-off-by: Luis Chamberlain --- mm/huge_memory.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8386d24a163e..86a8c7b3b8dc 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3535,7 +3535,7 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, struct file *candidate; struct address_space *mapping; int ret = -EINVAL; - pgoff_t index; + pgoff_t index, fsize; int nr_pages = 1; unsigned long total = 0, split = 0; @@ -3547,11 +3547,14 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, if (IS_ERR(candidate)) goto out; + mapping = candidate->f_mapping; + fsize = i_size_read(mapping->host); + if (off_end > fsize) + off_end = fsize; + pr_debug("split file-backed THPs in file: %s, page offset: [0x%lx - 0x%lx]\n", file_path, off_start, off_end); - mapping = candidate->f_mapping; - for (index = off_start; index < off_end; index += nr_pages) { struct folio *folio = filemap_get_folio(mapping, index); -- 2.43.0