From patchwork Wed Jan 3 08:41: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: 13509718 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 5FC0FC47079 for ; Wed, 3 Jan 2024 08:41:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E817D6B0327; Wed, 3 Jan 2024 03:41:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2DE06B0328; Wed, 3 Jan 2024 03:41:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C57E96B0329; Wed, 3 Jan 2024 03:41:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B58ED6B0327 for ; Wed, 3 Jan 2024 03:41:44 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8B0C38022D for ; Wed, 3 Jan 2024 08:41:44 +0000 (UTC) X-FDA: 81637356528.16.99B8A51 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id ED881A0017 for ; Wed, 3 Jan 2024 08:41:42 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=D9eZc7RV; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+f852f126c6d693376302+7437+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+f852f126c6d693376302+7437+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704271303; a=rsa-sha256; cv=none; b=xo1QlP67nTL0RQb8HK9rm2vofOsTjPkHImFn2K6FDsvhqWgx0Ti7ZDErSwHOQRhbsvwwGD gcaHCHAthcv+ZXvh3PSwRawOUi0/+nh2ThjnqxHJ51HWBG7WU0P1JYOQed+oK0E0lHoTUt D/tUEJVgE8ZN3MmvNzv/yHNgDwAjHG4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=D9eZc7RV; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+f852f126c6d693376302+7437+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+f852f126c6d693376302+7437+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=1704271303; 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=MnEk4kJaE+n+b3v1j4i9S3VKDanv67ejVN4lnTe2Pcw=; b=H8j9B9GxHX6rCuXb9yMnc7Nyc5GN5K4VAMRgu1QYu6/fyCv4rqVjnCdtQSGKaCyVk4/DWZ abS5zze55wbXpHHdWx6tqzawUpmMkeeO9Sl0LzfQI4WL21jUhkzi9kWcjeYI7h4Umiouvf tKmXtST/d64BP3OrFyMv68Gssof4qFQ= 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=MnEk4kJaE+n+b3v1j4i9S3VKDanv67ejVN4lnTe2Pcw=; b=D9eZc7RVxxXXOXkgoj7zZ58Fl0 jMw2mz7+rfptKsKGD2aMtn4h2BUSroL0SOyvQ/wIomLgwWbFAlMztnWTc0uKonXjwdsaB3ObGgJW1 hvFV+kBeNG78FsfdgR9MYcsJFW9ssjZRpVhKYz/54DGPEF53EfXnSnl/VO+vZ/vRrR+fi9m5Er8W6 JWo3lelBuE2aKxAETb4bvr+f+lyoSO0Pw6asoiRKV/gaasS256KHO2aMX5jYNBWPg0JUl7w1bhHSH q/QnhPhcZPaClOC8i3T5qgcJ+N4L/tl4GbrVW3otEMtx6boSodtS7BsbP8ro8gr/p81k9i0f/jJe/ hSkg/fEg==; Received: from [89.144.222.185] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rKwoi-00A6WW-1d; Wed, 03 Jan 2024 08:41:37 +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 01/15] shmem: move the shmem_mapping assert into shmem_get_folio_gfp Date: Wed, 3 Jan 2024 08:41:12 +0000 Message-Id: <20240103084126.513354-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240103084126.513354-1-hch@lst.de> References: <20240103084126.513354-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: ED881A0017 X-Stat-Signature: p6hy4gjt6b1huxy3gzt41ki4fnj6woiy X-HE-Tag: 1704271302-993968 X-HE-Meta: U2FsdGVkX19CdTp6jL/wl74VVdG+s2xA3aAD/1oN7ySA+pXXE4Dv0KDJUUpG1W2akm+EEjOV5X87Y42uBx+1oy2BJ61+vt2LzPwp53nUJukuMWE/4TN+MPHiDlyWDMp33aLSbYmLaquRWR+eSgaK0+sb55R10i00hRn7R/iZzS6rVe5O5hgSm2VdViwEVSWs/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EBgjB72FYrWM/AgA0uPeLCMFTtqGwxi8AMa8ke3hoeh9pFm3530Ja84i6YTsWbQdSpqMJFQ8iKqTsUVoJqEES7aEEWewSWn2UPIjwiX1yX8PqYYM/9DlGrne9hcp+cW8VLgBCTh9DVjAvVfy5MaoT9qnw== 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 --- mm/shmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 91e2620148b2f6..3349df6d4e0360 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1951,6 +1951,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: @@ -4895,7 +4898,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)