From nobody Mon Nov 25 11:53:20 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EE6228C11 for ; Mon, 28 Oct 2024 03:26:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730085991; cv=none; b=eqarHn7/DAKzxpYHtrBdb5XmFdYGGFGUGIxFSIYnteY/qghyw+FGJldHjRRFhjBtTToN04C3PTfJA8a1gXxgQvUJJ2vsElQ/eoxg3O02RfTPk0nOCDsfoOWsvxqx+q1mOKGbA6RgJxIYx72H6QTcMV2KpO09g9sTs7drATaQedQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730085991; c=relaxed/simple; bh=wsyKI219Uy+NE28dwnFpejiIUgxT0s45lNvb4gOQOqI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Enrb8srmKHhkc+X3wXnykxX/C9oSGr3wRMMqbLcCGaXo6G4o+P+yqOrfTW9OsZ+sDSceZ4OPZOEFZtGIwyc47fxQTTjcv5uu8f24r6tlKO+vkGOrHzMGVlgtYbz8ic3GamyXIU3MffvM7OuArLJybfRJhWXE3DPTeW1+p9yKT5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=etGuEUQL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="etGuEUQL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7970AC4CEC3; Mon, 28 Oct 2024 03:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730085990; bh=wsyKI219Uy+NE28dwnFpejiIUgxT0s45lNvb4gOQOqI=; h=From:To:Cc:Subject:Date:From; b=etGuEUQLVkXZOuKI4a4BFVbpHVS6FlG5+QL+meiPq90d1p/8Zde+J9WVOlhFzRoWo ParNe55fL39WDdHJJ9BAzgCuZaYSK7TXA8D6/e1DzQEBuqviww/YGHiU7oj/bcQx92 5tNrcbQhQt3tlo3C2z36mNorKrh65Y/XJe6oUVHXF7gS4FaMw28o8YSbUeimwTUACF /9LOvC+bjrF9yB8hoWZ50xKyjCK/t/zDU3ATnAnbE2Yg0vU88i3S4cL/D5+jFlXRPL 5MsEciSO8bwwML9cgE9H5hlsslejLazHFp6mLEUZpQqcRueLKO5lrcMGpqm+73LvTV /xxET9jq8Avjg== From: "Masami Hiramatsu (Google)" To: Andrew Morton , Matt Wu , linux-kernel@vger.kernel.org Cc: Linus Torvalds , Leo Yan , Mikel Rychliski , Viktor Malik , Steven Rostedt Subject: [PATCH] objpool: Fix to make percpu slot allocation more robust Date: Mon, 28 Oct 2024 12:26:27 +0900 Message-ID: <173008598713.1262174.2959179484209897252.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) Since gfp & GFP_ATOMIC =3D=3D GFP_ATOMIC is true for GFP_KERNEL | GFP_HIGH, it will use kmalloc if user specifies that combination. Here the reason why combining the __vmalloc_node() and kmalloc_node() is that the vmalloc does not support all GFP flag, especially GFP_ATOMIC. So we should check if gfp & (GFP_ATOMIC | GFP_KERNEL) !=3D GFP_ATOMIC for vmalloc first. This ensures caller can sleep. And for the robustness, even if vmalloc fails, it should retry with kmalloc to allocate it. Reported-by: Linus Torvalds Closes: https://lore.kernel.org/all/CAHk-=3DwhO+vSH+XVRio8byJU8idAWES0SPGVZ= 7KAVdc4qrV0VUA@mail.gmail.com/ Fixes: aff1871bfc81 ("objpool: fix choosing allocation for percpu slots") Signed-off-by: Masami Hiramatsu (Google) --- lib/objpool.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/objpool.c b/lib/objpool.c index fd108fe0d095..b998b720c732 100644 --- a/lib/objpool.c +++ b/lib/objpool.c @@ -74,15 +74,21 @@ objpool_init_percpu_slots(struct objpool_head *pool, in= t nr_objs, * warm caches and TLB hits. in default vmalloc is used to * reduce the pressure of kernel slab system. as we know, * mimimal size of vmalloc is one page since vmalloc would - * always align the requested size to page size + * always align the requested size to page size. + * but if vmalloc fails or it is not available (e.g. GFP_ATOMIC) + * allocate percpu slot with kmalloc. */ - if ((pool->gfp & GFP_ATOMIC) =3D=3D GFP_ATOMIC) - slot =3D kmalloc_node(size, pool->gfp, cpu_to_node(i)); - else + slot =3D NULL; + + if ((pool->gfp & (GFP_ATOMIC | GFP_KERNEL)) !=3D GFP_ATOMIC) slot =3D __vmalloc_node(size, sizeof(void *), pool->gfp, cpu_to_node(i), __builtin_return_address(0)); - if (!slot) - return -ENOMEM; + + if (!slot) { + slot =3D kmalloc_node(size, pool->gfp, cpu_to_node(i)); + if (!slot) + return -ENOMEM; + } memset(slot, 0, size); pool->cpu_slots[i] =3D slot;