From patchwork Fri Jul 26 11:59:53 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: 13742706 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 E9D2EC3DA49 for ; Fri, 26 Jul 2024 12:00:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47F666B00B2; Fri, 26 Jul 2024 08:00:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 409F66B00B3; Fri, 26 Jul 2024 08:00:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2829D6B00B4; Fri, 26 Jul 2024 08:00:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0062F6B00B2 for ; Fri, 26 Jul 2024 08:00:42 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B33AB1617E9 for ; Fri, 26 Jul 2024 12:00:42 +0000 (UTC) X-FDA: 82381761924.26.E6F3F45 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf13.hostedemail.com (Postfix) with ESMTP id DA30A20041 for ; Fri, 26 Jul 2024 12:00:40 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=m8OIhx4v; spf=pass (imf13.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=1721995215; a=rsa-sha256; cv=none; b=rwLqgQGpARX1rY9fFxQUJtj86Gle6N1SfutGFpdOCOf03/TfBdg8GsDuIk+EoKrVMnY2RU K2xaPlbMZM9rY7pFYNlp3aQ5ls6yzmsOUw2/X+gSFlfi71wn8PXrr8UVdqCgXt+1Pk/b7R 9yzCPQFxp32L4EuDuNnT5+bJrv+JgWg= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=m8OIhx4v; spf=pass (imf13.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=1721995215; 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=Vtmgcwv8VAWyC3iKjlFnGJ4xcUJZeVkRpHTKtI91JWEf1S6FzihLnMteJ4anO2FmXDdt2r golhGKTzcdw/PEK8ezQEUc4VTBI2lH0VKyVtiW2LO56kRyLIFXbUOnPuuMOR7fDKWVA0d9 IC+gBILoXASAOJgRKjqIHvflIBw+cdo= Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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 4WVmY152KXz9t5k; Fri, 26 Jul 2024 14:00:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995237; 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=m8OIhx4vQkeOLF8y08Q0KTEgePfhq6CQ2dg6JHoWh+YM7TqCvvOBtpwEXUEdYyEfI/D+/O Sl5a3UufWE0H/KBMqwFsalNbKnfh5qKJNC1JzXqS4+ne10mXzdVzWf6nV/TBgjheEQ0D0b pTYTpsTnlXbqBUXpGUE1ooGiUbYe/Ht4QSWCkWX4oSvfsc1wf9yWcSS5r3jp/iBXnhSH2/ /cfQolFTUywEp2DRPtHYm7qg3ZceAHcQ5GGFbCdLnjA0bMUIE2b02v8faOCBCeumDGHkfF xLHaMxRHIRrgKrEPYW13wMa8LT8p5Y7b8BQOWKVPJitjWvCvBU6g8473romXdQ== 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, ryan.roberts@arm.com, hch@lst.de, Zi Yan , Dave Chinner Subject: [PATCH v11 07/10] xfs: use kvmalloc for xattr buffers Date: Fri, 26 Jul 2024 13:59:53 +0200 Message-ID: <20240726115956.643538-8-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: a9ocq6ufxk6orquyt8yypixa5ccht49s X-Rspamd-Queue-Id: DA30A20041 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721995240-763586 X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3uZr9hy3oG6MQfOyh9uT8IJLL8rVU5ae+iCaQl7diyqUelUT0SytRK7xHDZGntZ0Nx3/w6GfDCuUVArQsPRznDPyV8MMV+uX0aaRAVxYWHifO8/Tx4NmElBG1YE1+g8noPXfYCYksszAECjMRSmT06nvasJxOXTLQNJswa6KJqzMPVIsgKGm0kygcVGQ5v/tLmJ+FPzel3TJ2GIzjPUr/FKj1BE8LgdF7fPHQ1J9CHOAGimqcwRxItlsAof2gZ/4eAPAlPXHfGSG7pDN0dAA07xyYiLdH1NxBDH1EjrllaVGAOkvLL5lHJMdLi6WvdXg== 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);