From patchwork Mon Jul 15 09:44:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13733200 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 3622FC3DA59 for ; Mon, 15 Jul 2024 09:45:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBCB76B009F; Mon, 15 Jul 2024 05:45:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B44FD6B00A0; Mon, 15 Jul 2024 05:45:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 998C16B00A1; Mon, 15 Jul 2024 05:45:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 728C86B009F for ; Mon, 15 Jul 2024 05:45:46 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2DEC81414D4 for ; Mon, 15 Jul 2024 09:45:46 +0000 (UTC) X-FDA: 82341505092.09.C3533B1 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 690E740017 for ; Mon, 15 Jul 2024 09:45:44 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=uM8OlI5I; spf=pass (imf11.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721036708; 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=D613TVQCptAW9VynAGuVSOK0s4oeJXQu1SypShzHmM4=; b=DsqsDsA47Gjs2KxW7OJFVWVC1GSX1ku3+Fm0qkoG+pwa6i4wgLLtr4CAnrY3XuJHTPTv2x X1dCEm2EV54a8dN8LQYCv5tZe2aslEKUwIt1QbVCRVoCAp4c0CVuZcwAawFVQeKnh7wSw3 tqWta9GRDjqFBXxjFukT4pfrnzckSew= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721036708; a=rsa-sha256; cv=none; b=Rhw1FQiNig14JYF/tUJSIDDIQw+wVEOw38cZwpFlUSveOf1ujDIudWdWud4P7xNQ/FaY+l PhtU7kOf+9Al2x5clhGyshA5G3WYqi8S9pmASgx4fLdMwahpiWjxp2tdYfmqsZqMzvpV2f IiqX5XnxaIwXr3cDVJKrUcGhMJuyxXk= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=uM8OlI5I; spf=pass (imf11.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4WMy4P1gdnz9sWC; Mon, 15 Jul 2024 11:45:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721036741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D613TVQCptAW9VynAGuVSOK0s4oeJXQu1SypShzHmM4=; b=uM8OlI5IEQGqmikVhy8VZ5B3cKaYJYBPNRpBgkLZIib8ODN2Fl/BqmG7kAmfQ7PjReqyBp J+XuclRTwXs8G7QKLPWDxuO7VLEauyYRUf1avtK8kwNAvSWtgPn7oF/yC9O/8Gw3bThwwi n4dQx3gfrkYw1HDKQ84AnP0PyosggCXx+A5m4bnptcbSvuN7wb1qMH6JqOy4kjVAUUPV+u Ku93aX1GWrXEKWIGpzmCPEOohhvIHxLXnjH0Kd0c8/TD89CXBciUEKtNZd3ShvDKgoz/ag w3MwxrhqgwWCDYsf9EgsE5C0+65MTag8GZA0OKT0kw3WEIR4gqegmU6LJTym6A== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, yang@os.amperecomputing.com, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan , Dave Chinner Subject: [PATCH v10 07/10] xfs: use kvmalloc for xattr buffers Date: Mon, 15 Jul 2024 11:44:54 +0200 Message-ID: <20240715094457.452836-8-kernel@pankajraghav.com> In-Reply-To: <20240715094457.452836-1-kernel@pankajraghav.com> References: <20240715094457.452836-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 690E740017 X-Stat-Signature: 6mn5wt7sm4rboqzupqg1bucbcofbtdh5 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1721036744-519342 X-HE-Meta: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wR0j5fnB2vojXPiSf4kGs82VNI/4mOxLmmDm1CS6hGy6BX8WgxqiUOKieWZf9Z6ZllFL07pxM3D5i3uP07Y2C0E/Q7mb2awYqThhJoT+08IUG9mn3Q/vYqoTR7grneEwuxogbxHNUrvRCFq1zu32GUiN+AQpZ+WdmXDzyI4ZpJ26+39edtQ7PbpR2gB4gdpgAMmTAj9SsiaSNG5fh/oyRA91gGJ9mibhU4V5sbW6m8yI3TX45tP3QKb8zRiY/jMYvhbrKxh5x9v5brRlLOVWdGgGEhMN4b3LNgVxF4P3FQ2Hxbd+geKwy9VGHQWiqQ== 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: From: Dave Chinner Pankaj Raghav reported that when filesystem block size is larger than page size, the xattr code can use kmalloc() for high order allocations. This triggers a useless warning in the allocator as it is a __GFP_NOFAIL allocation here: static inline struct page *rmqueue(struct zone *preferred_zone, struct zone *zone, unsigned int order, gfp_t gfp_flags, unsigned int alloc_flags, int migratetype) { struct page *page; /* * We most definitely don't want callers attempting to * allocate greater than order-1 page units with __GFP_NOFAIL. */ >>>> WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1)); ... Fix this by changing all these call sites to use kvmalloc(), which will strip the NOFAIL from the kmalloc attempt and if that fails will do a __GFP_NOFAIL vmalloc(). This is not an issue that productions systems will see as filesystems with block size > page size cannot be mounted by the kernel; Pankaj is developing this functionality right now. Reported-by: Pankaj Raghav Fixes: f078d4ea8276 ("xfs: convert kmem_alloc() to kmalloc()") Signed-off-by: Dave Chinner Reviewed-by: Darrick J. Wong Reviewed-by: Pankaj Raghav --- fs/xfs/libxfs/xfs_attr_leaf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index b9e98950eb3d8..09f4cb061a6e0 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -1138,10 +1138,7 @@ xfs_attr3_leaf_to_shortform( trace_xfs_attr_leaf_to_sf(args); - tmpbuffer = kmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); - if (!tmpbuffer) - return -ENOMEM; - + tmpbuffer = kvmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); memcpy(tmpbuffer, bp->b_addr, args->geo->blksize); leaf = (xfs_attr_leafblock_t *)tmpbuffer; @@ -1205,7 +1202,7 @@ xfs_attr3_leaf_to_shortform( error = 0; out: - kfree(tmpbuffer); + kvfree(tmpbuffer); return error; } @@ -1613,7 +1610,7 @@ xfs_attr3_leaf_compact( trace_xfs_attr_leaf_compact(args); - tmpbuffer = kmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); + tmpbuffer = kvmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); memcpy(tmpbuffer, bp->b_addr, args->geo->blksize); memset(bp->b_addr, 0, args->geo->blksize); leaf_src = (xfs_attr_leafblock_t *)tmpbuffer; @@ -1651,7 +1648,7 @@ xfs_attr3_leaf_compact( */ xfs_trans_log_buf(trans, bp, 0, args->geo->blksize - 1); - kfree(tmpbuffer); + kvfree(tmpbuffer); } /* @@ -2330,7 +2327,7 @@ xfs_attr3_leaf_unbalance( struct xfs_attr_leafblock *tmp_leaf; struct xfs_attr3_icleaf_hdr tmphdr; - tmp_leaf = kzalloc(state->args->geo->blksize, + tmp_leaf = kvzalloc(state->args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); /* @@ -2371,7 +2368,7 @@ xfs_attr3_leaf_unbalance( } memcpy(save_leaf, tmp_leaf, state->args->geo->blksize); savehdr = tmphdr; /* struct copy */ - kfree(tmp_leaf); + kvfree(tmp_leaf); } xfs_attr3_leaf_hdr_to_disk(state->args->geo, save_leaf, &savehdr);