From nobody Thu Sep 19 01:52:25 2024 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 660D117C208; Fri, 26 Jul 2024 12:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721995243; cv=none; b=eyH0acMx91SB8eiAs7LmssU5jHRNxsyhH6t3I3WfQNoa7HF7sRnpRre5muaGXwoh8iJPP/NkNORFFmXFphiy/qvkrqZVHpVsFTNhPeahuUOw+Cem6k/U+BZOPe94i7cSiAd+vr5stRc0mlRZIqmJVsZ0KA+tD/dSp1SJi33I7c0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721995243; c=relaxed/simple; bh=2GhI+azvlVmJ+XNkvELFCX60TvrX+df0OCxGC4NRcjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I+Aygebl37dtfsn3RlIpqdh0XaoZ3nQJS0hOozsVgSCx6+0446GSERNle5iDmOAEk6XSw7kLzeFjqknYeBk2Dd5Y/2FQFZnwbEj13Gu8zvmU0U0ul28jBX/7dv9JMPU3JkSsgVqx0uC4Zl+SoPWt/D5JxemaIKKl7Mhq05V6r1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com; spf=pass smtp.mailfrom=pankajraghav.com; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b=m8OIhx4v; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pankajraghav.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="m8OIhx4v" 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4WVmY152KXz9t5k Content-Type: text/plain; charset="utf-8" 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( =20 trace_xfs_attr_leaf_to_sf(args); =20 - tmpbuffer =3D kmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); - if (!tmpbuffer) - return -ENOMEM; - + tmpbuffer =3D kvmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); memcpy(tmpbuffer, bp->b_addr, args->geo->blksize); =20 leaf =3D (xfs_attr_leafblock_t *)tmpbuffer; @@ -1205,7 +1202,7 @@ xfs_attr3_leaf_to_shortform( error =3D 0; =20 out: - kfree(tmpbuffer); + kvfree(tmpbuffer); return error; } =20 @@ -1613,7 +1610,7 @@ xfs_attr3_leaf_compact( =20 trace_xfs_attr_leaf_compact(args); =20 - tmpbuffer =3D kmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); + tmpbuffer =3D 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 =3D (xfs_attr_leafblock_t *)tmpbuffer; @@ -1651,7 +1648,7 @@ xfs_attr3_leaf_compact( */ xfs_trans_log_buf(trans, bp, 0, args->geo->blksize - 1); =20 - kfree(tmpbuffer); + kvfree(tmpbuffer); } =20 /* @@ -2330,7 +2327,7 @@ xfs_attr3_leaf_unbalance( struct xfs_attr_leafblock *tmp_leaf; struct xfs_attr3_icleaf_hdr tmphdr; =20 - tmp_leaf =3D kzalloc(state->args->geo->blksize, + tmp_leaf =3D kvzalloc(state->args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); =20 /* @@ -2371,7 +2368,7 @@ xfs_attr3_leaf_unbalance( } memcpy(save_leaf, tmp_leaf, state->args->geo->blksize); savehdr =3D tmphdr; /* struct copy */ - kfree(tmp_leaf); + kvfree(tmp_leaf); } =20 xfs_attr3_leaf_hdr_to_disk(state->args->geo, save_leaf, &savehdr); --=20 2.44.1