From patchwork Fri Jan 26 13:28:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13532567 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 25889C47DDF for ; Fri, 26 Jan 2024 13:29:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A913B6B0080; Fri, 26 Jan 2024 08:29:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A682D6B0081; Fri, 26 Jan 2024 08:29:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92F826B0082; Fri, 26 Jan 2024 08:29:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7F5936B0080 for ; Fri, 26 Jan 2024 08:29:26 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5556C140EF3 for ; Fri, 26 Jan 2024 13:29:26 +0000 (UTC) X-FDA: 81721543932.13.8208D8C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id A732840028 for ; Fri, 26 Jan 2024 13:29:24 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=jH19Kj60; spf=none (imf12.hostedemail.com: domain of BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706275764; 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=N3rE3t+7Sfh1ch+jG4/rL3OFi8MZBkGfEkeN2S3CLmM=; b=iw44WNagt70eDgPIQpc/yCcyJ/+JULI51lKDxXTqtQZ58i2wG7O7gTERymQMfMsWNTtgJZ R9nJAxzRezSd1Qtb4S6Ofu522Uj6tjIRevn0//wH796uqHwbMsoZseVq0zkVDB+k2veXIO Fi9s/kS0NTXaFg1seoNttzRr4skdRKk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=jH19Kj60; spf=none (imf12.hostedemail.com: domain of BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706275764; a=rsa-sha256; cv=none; b=BNpqCZaLv8vlX031evZnZoR2IGn4ol45xRYPxQEoPeu5EB9AxeDofkGqeZp8tpmt0+kH/s 7Dvv3ElsnPD+9yMtztYibBtkMmVB04HftfU3hL78fDAxsmJwIl5q95hXAyI5kAG1co/I4v rcEcfdudD0In4PSGrLa3kIrHTPEFij4= 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=N3rE3t+7Sfh1ch+jG4/rL3OFi8MZBkGfEkeN2S3CLmM=; b=jH19Kj60uBDT5ZT7yUS36ynTVX cmD+U0mwww+RdyWA75x0RtpSmsuslCrGZVbWSAdM8/55p49Tc77N8oFKzsOHo6pQGPJuRyxxQkvLE QvkBzZtnVnWU9sMc44kK35fu+5k9buUPG28aqwHXTgvAaG1YhVhrnnjAAhSQuGGmeiXsaMrUrvwZ0 G2PvG0AEf7veIxjQ1TmXlO1ee7RCEBnM6wrkCqjBv3Z3+XVcmOtlDnSEL4XlCRJRQMNvre6lkyLim yCgcL0EWFEACRe4+puqj0/shszRBRqMYMaOVC7pEDfEgc3jBaWn9a5mn5pm3wpUEp0nlXBpI3YG9V JWpJIosQ==; 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 1rTMGo-00000004Ccm-01iG; Fri, 26 Jan 2024 13:29:22 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" , Hugh Dickins , Andrew Morton Cc: linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 04/21] shmem: move the shmem_mapping assert into shmem_get_folio_gfp Date: Fri, 26 Jan 2024 14:28:46 +0100 Message-Id: <20240126132903.2700077-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240126132903.2700077-1-hch@lst.de> References: <20240126132903.2700077-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-Rspamd-Queue-Id: A732840028 X-Rspam-User: X-Stat-Signature: aacjosssfxfe6kffgizgyi45khakq4mc X-Rspamd-Server: rspam01 X-HE-Tag: 1706275764-827605 X-HE-Meta: U2FsdGVkX18nx9Gmwen0VwdFozzBAHzl176jwRH/Ic/vhCv3L/Iyd7P06+10z4sY6BpKJnQ+WTSFEMniSca5GpEMAvN+JQFgfEnNFIOiLrf4gBULAYk2Yy0HjIEAziYM5vOiyb5hA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W1RxPUURYNz4C3vV0/r8fOCMSpck1Z1A/+8PmMY41u/ldNFjgvnzWcAq3/nddEKEs6mEluW29f7gzxsr051DPYQviocqnm1+/sVYUg3VpQYL+gGEqiVM7+81LDA6sLO6J0muo3ZBN03VhrTRvHyF7rF2vOFxHmxDYYLLc5z6HFgpf11jyY7WcLzqW5icayv5pp+Em3mH8g4ph7UDpQvsLLAzsDtn0eABh33nJFDxDAJ8B5H/x8XUbvwmMvJlQitzyS3eN+ZQl8B3APPGxrcECmGg= 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: Darrick J. Wong Reviewed-by: Matthew Wilcox (Oracle) --- 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)