From patchwork Fri Jun 7 14:58:59 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: 13690334 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 B75BFC27C53 for ; Fri, 7 Jun 2024 14:59:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BC316B00AD; Fri, 7 Jun 2024 10:59:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 518D66B00AE; Fri, 7 Jun 2024 10:59:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 369AE6B00AF; Fri, 7 Jun 2024 10:59:48 -0400 (EDT) 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 0F9396B00AD for ; Fri, 7 Jun 2024 10:59:48 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C7A3E818F1 for ; Fri, 7 Jun 2024 14:59:47 +0000 (UTC) X-FDA: 82204402014.20.3211E83 Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by imf16.hostedemail.com (Postfix) with ESMTP id 750FA180004 for ; Fri, 7 Jun 2024 14:59:44 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=NolyD4e3; spf=pass (imf16.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 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=1717772384; 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=kZG/lL31K25//iaIAV7jBbt1MNjj987Sk8ll7Dxjdts=; b=LY2/qhf18l7BaS5yFhH4ew/bNk0XZ6kG6q/wifIV6NzaIxCp/ODMX3+VeUVcKDOZIwyEQ5 BHv50sitGTGOQFIJyvDu5M6F65lOVued/s5nG5oGho12xV2I6skwFuOfcIzCMf/59fCWfp aG3cvwmEDObaDojlPu2w+55mM9lqVe0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=NolyD4e3; spf=pass (imf16.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 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=1717772384; a=rsa-sha256; cv=none; b=5P4M988snPP1JDrakPj77qaJbF1hxJ/Op32a44+FjuRmm5Keo99NoQEQGf01kwcUjC+q9U 34xNADzbvNy0lTywXmqP0Yh0c5OLFOHttwj/StPVxNiExfMhR5VwUnhFnuMB/RPjuZIn2L 5s4oGsvmbi8W3E7Vx6AZMOHxutCJtWI= Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.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-103.mailbox.org (Postfix) with ESMTPS id 4VwkrF2Pd1z9sng; Fri, 7 Jun 2024 16:59:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1717772381; 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=kZG/lL31K25//iaIAV7jBbt1MNjj987Sk8ll7Dxjdts=; b=NolyD4e3omUCcx8jYDPY5ZsDQIHnS6RImuHNHeschPG7wr1uaeUR7qeU92o88kizWNRrAr SPhn3Cqkx/nm6ynGmBxDMlx2bkrNAdRZYpqYRswXXrTZ4S9FOqoHy95aPpCwC7eWGKAhgV UYRW6njfy8HdZueqtcGalhYbUfZUliyN9Dpi69gv2Rf3twKEUV51yeGEhqz47K6Gfi/vUp WvGe3GyAxkVYhSTpOGarHrkIJRYmf6bgft57mVFmQofyk/wz89uXsAMB/OeiiET5V3FeLw +IKc3x61zFHlTj9qpPNiPwyTtnKkR+k3siGQMDaR8gHW6pfH/5JO6whYg9+Jqg== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, djwong@kernel.org, chandan.babu@oracle.com, brauner@kernel.org, akpm@linux-foundation.org, willy@infradead.org Cc: mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, linux-kernel@vger.kernel.org, yang@os.amperecomputing.com, Zi Yan , linux-xfs@vger.kernel.org, p.raghav@samsung.com, linux-fsdevel@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, gost.dev@samsung.com, cl@os.amperecomputing.com, john.g.garry@oracle.com, Dave Chinner Subject: [PATCH v7 08/11] xfs: use kvmalloc for xattr buffers Date: Fri, 7 Jun 2024 14:58:59 +0000 Message-ID: <20240607145902.1137853-9-kernel@pankajraghav.com> In-Reply-To: <20240607145902.1137853-1-kernel@pankajraghav.com> References: <20240607145902.1137853-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: pssb5fm16p5cgwcseirxwpmhc7mjamfu X-Rspamd-Queue-Id: 750FA180004 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1717772384-79543 X-HE-Meta: U2FsdGVkX18qLGjBtO3GiMwHdXjM2hGwfIEvNvssG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r6GQiuCPG22t4URt95kdDpKHKJF+WffcEmdpDu3TKQIy4TdTVTmR3/BwXjnPI6xvs3PI5gQwfIcaYgUnIaVqJ8T6nMXCnj5Ajy92D2p0P+C949zaoiZmWyYb6gSjFa5N3jNOLYIB/RUS5vClsH3Qky20hdvOeK8wllZ2MNV1h5pBRmHGs3Y5YxigOjWianPFuDH25q0cilSomQWUnB6cepHGUacqJSFA8Lx22lPO 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 b9e98950eb3d..09f4cb061a6e 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);