From patchwork Thu Jul 4 11:23:17 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: 13723627 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 34F10C30653 for ; Thu, 4 Jul 2024 11:24:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB6586B00D3; Thu, 4 Jul 2024 07:23:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B652F6B00D4; Thu, 4 Jul 2024 07:23:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B7ED6B00D5; Thu, 4 Jul 2024 07:23:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 78AD26B00D3 for ; Thu, 4 Jul 2024 07:23:59 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EC59B140DD7 for ; Thu, 4 Jul 2024 11:23:58 +0000 (UTC) X-FDA: 82301835756.29.C62E817 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf14.hostedemail.com (Postfix) with ESMTP id 1E97A100012 for ; Thu, 4 Jul 2024 11:23:56 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=RqsX1L+R; spf=pass (imf14.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=1720092218; 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=4aDrl/sy5zZHTJ5jkdlthBK9giYuQeWmAwM4M+iIdieeJQObPowq3W1dfvaenMRfYN+bXD fkZTjmsp85+MjoRQKs+QEcVPYqjY9VKWJMHwa8/IJNeZasXJ/jvDLO9kkB6UTZQLb3GCMG 0hRsMISy7I9TVoDFbBX2Gcvt3uZN+uE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=RqsX1L+R; spf=pass (imf14.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720092218; a=rsa-sha256; cv=none; b=qFxK+Faqhmqxby1PUhMzI4i7lFJcmIGd7/Ldd36o0HEkTej4GD9LEPN2STAVV9NkJwaHgG 2NhqJT2Q9zu2lxZQNBna8vLt5IvY240xrzYviwLXMXGVpJaYYUATw5WAiBIZKOs7hpeUZy NNmlNgQzaUN3fyaNxdXWN5eXf07GIGk= Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (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 4WFDmn5pzdz9sqG; Thu, 4 Jul 2024 13:23:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1720092233; 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=RqsX1L+RvCdjBZycaeWBvEWTaV3SYjEP7XegGBKhcmMCtOiOSmxoMzmYYuCkvFVshaczSy PQnwsecosj2dPaGVL6Y4I1/FJqCLOsarUwSnwjfB2FDVtLuAt6/Inww2x3vpbmwQhpJroF vgtUaC7DfS8locLUgvYuaecnTEHrwYKREpRna5EypLLSaEXJhYFoaZcenAITFqyev+BWpd J6cuoxBI7poy5xGJ21ERYEOUtKn+3O8aowAOjCKwXwJSwAeyRUj99QeDntaATsCMBe7Iwy 5YAOpzBaeAc6DcTyi9dXZruGWF9rCgPwsvKlPMkiAW5SBQOU9tnyCCITPgSOQA== 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: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, 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, hch@lst.de, Zi Yan , Dave Chinner Subject: [PATCH v9 07/10] xfs: use kvmalloc for xattr buffers Date: Thu, 4 Jul 2024 11:23:17 +0000 Message-ID: <20240704112320.82104-8-kernel@pankajraghav.com> In-Reply-To: <20240704112320.82104-1-kernel@pankajraghav.com> References: <20240704112320.82104-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: 8iu4ikh84979kfw4frbybjr3n99urepz X-Rspam-User: X-Rspamd-Queue-Id: 1E97A100012 X-Rspamd-Server: rspam02 X-HE-Tag: 1720092236-337174 X-HE-Meta: U2FsdGVkX1/DT+0cWepgfiQJ0fgJCUO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N5ffVMngTN42DXo/qBa4MjrLahXdxAZksP2tbtkwEiQscfoxwfX1zvcjd60ujoW+xE3QchnugQTMAJw6NbHa9QVHBD6oNgDo7MUTqOlwaP27tYU1HwyqX4R4afn+hAp7UPzWEfYDfpXap/N6VpPJ8YXOQZXHWa7K0ltA6GKcgCZpAmAowYtQt7PIcvfqtT1R3XjV04jyL/G6BMruA01T1GidqcbttWVyGyDHTiAdR/xNFj8924KOBiUooP/LEicEAcBko0 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);