From patchwork Thu Aug 15 09:08:46 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: 13764600 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 E4887C3DA7F for ; Thu, 15 Aug 2024 09:09:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77FFF6B00AE; Thu, 15 Aug 2024 05:09:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72EBA6B00AF; Thu, 15 Aug 2024 05:09:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F6116B00B0; Thu, 15 Aug 2024 05:09: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 42AD16B00AE for ; Thu, 15 Aug 2024 05:09:43 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B70BF14137C for ; Thu, 15 Aug 2024 09:09:42 +0000 (UTC) X-FDA: 82453907004.27.0700151 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf02.hostedemail.com (Postfix) with ESMTP id E9C158001F for ; Thu, 15 Aug 2024 09:09:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=kDAMcgZw; spf=pass (imf02.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=1723712945; 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=RF1+EqUrrDTKJUmrTUijzur9qT2UQhc5doN0Sx+Rh9WkhC3/Hd7KTky766rjFZjYd2Q38I BUObZCXgb3gOS7zlD54DGobhvz8pn52a2UjSVgVEc+qtzoWrhT4z7UxSIxVi2YiY3u9mKW xDN2FIdOSPlZYQaQgpimoxUk5riWibM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=kDAMcgZw; spf=pass (imf02.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=1723712945; a=rsa-sha256; cv=none; b=ULmw2BAl4xEr2h1qnluY0DmHQeB1BfIarug3XkvvK73RvchvRs4fVkR2e2Bndrfi0XD6NX 5/iVYNNPIDXhuWjrknuVslg+ceizRc2fcBLQPQ5WUFbG776J5pPMt6XZF2bZ0bKN3OXGhq Ka75HtCzziu0iahV1qnacUIMvncuXY4= 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 4WkzpT42Qbz9sWd; Thu, 15 Aug 2024 11:09:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712977; 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=kDAMcgZweQ0Bnu/S+QiyFuf0x+LiYm8/+zNP/SNOMkulmMCghzRCdWiM9gDS39eTc1PUdN ROxyw1J3DTm7hSUB7YLwZAaVcv04gs/+2quOPaXWLj4x92lH7Uhc4D1hPtUFF0t38M1F7H FH14Zshstp4/00yVytPxrMlgOTpBd0zrXZp/DyHSgdueQZrmiQpx3PUQbf0e1fzoxaiwY/ B7OPvZxCGTp+GgR6YisGSCCXmnw6Qr6TWS9kI1kqouF6LSASD1/TDdYWvZJyCUZh/gA3UP 35GHOtJbIRHxs4Jykd16PlN9CB88JThH+BepMJ8LbEwdC2phQhCsnP3xx1bV0w== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com, Dave Chinner Subject: [PATCH v12 07/10] xfs: use kvmalloc for xattr buffers Date: Thu, 15 Aug 2024 11:08:46 +0200 Message-ID: <20240815090849.972355-8-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: E9C158001F X-Stat-Signature: sdbaupcnmxap3ym8iepbd84tr4r4gxwf X-HE-Tag: 1723712980-655963 X-HE-Meta: U2FsdGVkX18nrE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bRkOakyTDqfLMyAuINiyjFWNiu4nc3D++HTOcwYIlG3r4S9hASF5J0CRGU3Qxdxmym/rOKdWP+9IZQghe3j1HX+ZRdVFMXpHKkwmc5O0l9/shPhEPC3B2n6LgVU8Lv6Cp/PhCTg9kB0dZ4fpu8nFlmfAlEMszg+fMggp0X2M6a11fmLkEpKupSEnyjt0m99mFjNGNRFFo3bCsCBaW9IlDOXhUIcyulCxsV0mDUYExoCQqxkL8jlMWnF+hfJaxYDmVgVA7axmq4YsQct/6g34x88jsGGgjYmfqSw59TDHMCeKKfn0g== 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);