From patchwork Mon Feb 19 06:27:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13562206 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 8BF7FC48BC3 for ; Mon, 19 Feb 2024 06:27:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B74F18D0009; Mon, 19 Feb 2024 01:27:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AFEE98D0008; Mon, 19 Feb 2024 01:27:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B6128D0009; Mon, 19 Feb 2024 01:27:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 716F98D0008 for ; Mon, 19 Feb 2024 01:27:39 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4A33F120253 for ; Mon, 19 Feb 2024 06:27:39 +0000 (UTC) X-FDA: 81807572238.30.70D010C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf08.hostedemail.com (Postfix) with ESMTP id 8848D160006 for ; Mon, 19 Feb 2024 06:27:37 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uMHAlgvF; dmarc=none; spf=none (imf08.hostedemail.com: domain of BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708324057; a=rsa-sha256; cv=none; b=aiyLMNfMs1nitIAbyNyk47b5Kz3PoZU/obZheq/MdsY/BusySCzR3+KlkOFmcWJ7za6kcF vowSP7FXJXKGt2+VdGmALAwnCZeJSTRA8jGMmK9vs48PJ0GwOjFhrKBA0nm0iATRsYkfYT 2foDSdmdYVStTkCH+C2DiqXAQEMaN88= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uMHAlgvF; dmarc=none; spf=none (imf08.hostedemail.com: domain of BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708324057; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=G9kCHf8br8WAlr/5Maj7Cft4763G9D9A1HkLivVroEo=; b=yS6Rs1rRF6puIBTV55BzTps20/FA/U7qM7DP5dZMttmeqJ/fcnGdIM1sO7FRkCJEw5ufkr DbsneI67koNRYLPODw8O6nsbH3txZShCnF5CED/y19C7PcQpw4htgvpTssHhtWa5P5ejUn zIiOOjIUVmG8d0CFqNfGLchv59eh56s= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=G9kCHf8br8WAlr/5Maj7Cft4763G9D9A1HkLivVroEo=; b=uMHAlgvFkjgJFvg8rWoBpfry0I B/cRAS3o+MWlhEdAz7eBRD1bgWGbyVxrJtL2M1GJeGs5h7HrweyCLyAuRBVJGrlqvbkADqgAcr/cO qwFQFNnXTB9zPkAz+9ZKXk9VWtwGS6yBs7Cow7qllaMFDgz4yi3Z0PETha4gird3YMUMeohSWtliW P8dGvtwAnW54RQ09zW6zT/Z+6/DLK05M9ZZaLWdgE5cmkHz5LDK+SSwuNKvio07YB3dSJFeW2fcZJ NCuWhCtb95mm/DsCXI+mbC0tWpglIVRIwxOL2OidobsnTtsQjr30tXwFZi7ZmfaLAxeeETHK7+VQr YzbJmnuA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbx7m-00000009F6v-27MR; Mon, 19 Feb 2024 06:27:35 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" , Hugh Dickins , Andrew Morton Cc: Hui Su , linux-xfs@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox Subject: [PATCH 04/22] shmem: move the shmem_mapping assert into shmem_get_folio_gfp Date: Mon, 19 Feb 2024 07:27:12 +0100 Message-Id: <20240219062730.3031391-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240219062730.3031391-1-hch@lst.de> References: <20240219062730.3031391-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8848D160006 X-Stat-Signature: 663149t87hr9c4ispyanbu6yaj8c3q4j X-HE-Tag: 1708324057-844398 X-HE-Meta: U2FsdGVkX1+wrba0WL7sMu4Wdj2/GHrfhDszWJUcu0hj90TqI94qLq9qXSTRlVz3X0WtsGMN23tYq5507cX6QvUyFmJ+QgKtorsm2DSi0NSV+jIh1H+SAl2OnLYG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qJUk2cZw6vuYd3QzyoWm8f3QtTch40jUyKu8KIpqaxKOGNgl2HM/FY/wfubqqghFNHXZCVkqZc9mQZTvL112o4LnCUZp55i6ymFabtmJZXRGZKDhPh8qjPuMMHKj0MxsuaCWhhUWgr2m9WFUYjQcpM/jlaSSc8tbc62P0c3tZdOVPYnH3Bw4o0djrB3xC1QglOA4YRebIuCeDZd/YeHpplMNeY0k7gYqj0JPvyOCT8ab8eOe0WBNhWTS4icmClyHpeYq+T7tqKPLaSJNf+ty8TywBr03dlt/3FvagLq5nkJUutc67303XoEK3NskzI0cq3sYeeNgexG4nuQuZQjNDGXNhBtqSoe9Y/FeeTl+5Feo= 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: List-Subscribe: List-Unsubscribe: Move the check that the inode really is a shmemfs one from shmem_read_folio_gfp to shmem_get_folio_gfp given that shmem_get_folio can also be called from outside of shmem.c. Also turn it into a WARN_ON_ONCE and error return instead of BUG_ON to be less severe. Signed-off-by: Christoph Hellwig Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Darrick J. Wong --- mm/shmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 1900916aa84d13..ad533b2f0721a7 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1972,6 +1972,9 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, int error; bool alloced; + if (WARN_ON_ONCE(!shmem_mapping(inode->i_mapping))) + return -EINVAL; + if (index > (MAX_LFS_FILESIZE >> PAGE_SHIFT)) return -EFBIG; repeat: @@ -4915,7 +4918,6 @@ struct folio *shmem_read_folio_gfp(struct address_space *mapping, struct folio *folio; int error; - BUG_ON(!shmem_mapping(mapping)); error = shmem_get_folio_gfp(inode, index, &folio, SGP_CACHE, gfp, NULL, NULL); if (error)