From patchwork Thu Aug 22 08:25:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Malik X-Patchwork-Id: 13772956 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 9D48516F0DE for ; Thu, 22 Aug 2024 08:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724315133; cv=none; b=OZrR6312oFbMU7Dj31c/vxg66AF1TYNlpm0hWDITWwKTpkcoQH0gjx0boa8CW4gMElpPxI59cI3WgjODS60DPHxVLcIaDP6yAGQ8Dfm5ZUTc6h+5KWoHtyY0cLWehrQAVTLR4IW6mLHmJK8/UsxaX4vnwrx8Dfq+6SY3GX0Y7ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724315133; c=relaxed/simple; bh=nvGsja343OkPEOmTnZePk7VBpQa7rGsvn+1UyN4C8Xw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=H5OwTE0pXMrf+2bmyt6guB1yXCkPeCQAMQqnp23RFTLutZoKH5LfGsBXCueDQfaHmD5/HaJfeKsFNhEUj/fTpEVHeLd1XOzrUF6+KO/QWvfEzLHInwyyI7j1pfp7Nqgibneb9qj356+uPYf8DjuZy4Qkg+7deXTk649ALLPRwe8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=H4JMernf; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H4JMernf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724315130; 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; bh=60ZmGMMj/oNEyr5Dg12eoH4vxkNmR3gh9oRVlxexhQw=; b=H4JMernf6GvR86V8T+mo4VCitbNBQjdb7Sb75gqABJxv9pAodXlmvhjl9s13/nSxGgq69V 6szxpDrlb+yb6WieXXPTm2keHmmh/AhVpz+9/WqmB95UKBAZ5z9rXwyg9bIzOwSYKCD7AM di6PktaHiKrD2KG8IU6z+qABXAatjKA= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-NTHhRH1kMPekFS4LfkPL7g-1; Thu, 22 Aug 2024 04:25:28 -0400 X-MC-Unique: NTHhRH1kMPekFS4LfkPL7g-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 036CE1954B0F; Thu, 22 Aug 2024 08:25:27 +0000 (UTC) Received: from vmalik-fedora.brq.redhat.com (unknown [10.43.17.27]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C61A01955F21; Thu, 22 Aug 2024 08:25:24 +0000 (UTC) From: Viktor Malik To: linux-trace-kernel@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu , Matt Wu , bpf@vger.kernel.org, Viktor Malik Subject: [PATCH] objpool: fix choosing allocation for percpu slots Date: Thu, 22 Aug 2024 10:25:19 +0200 Message-ID: <20240822082519.216070-1-vmalik@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 objpool intends to use vmalloc for default (non-atomic) allocations of percpu slots and objects. However, the condition checking if GFP flags are equal to GFP_ATOMIC is wrong and causes kmalloc to be used in most cases (even if GFP_KERNEL is requested). Since kmalloc cannot allocate large amounts of memory, this may lead to unexpected OOM errors. For instance, objpool is used by fprobe rethook which in turn is used by BPF kretprobe.multi and kprobe.session probe types. Trying to attach these to all kernel functions with libbpf using SEC("kprobe.session/*") int kprobe(struct pt_regs *ctx) { [...] } fails on objpool slot allocation with ENOMEM. Fix the condition to truly use vmalloc by default. Fixes: b4edb8d2d464 ("lib: objpool added: ring-array based lockless MPMC") Signed-off-by: Viktor Malik Acked-by: Andrii Nakryiko Reviewed-by: Matt Wu --- lib/objpool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/objpool.c b/lib/objpool.c index 234f9d0bd081..fd108fe0d095 100644 --- a/lib/objpool.c +++ b/lib/objpool.c @@ -76,7 +76,7 @@ objpool_init_percpu_slots(struct objpool_head *pool, int nr_objs, * mimimal size of vmalloc is one page since vmalloc would * always align the requested size to page size */ - if (pool->gfp & GFP_ATOMIC) + if ((pool->gfp & GFP_ATOMIC) == GFP_ATOMIC) slot = kmalloc_node(size, pool->gfp, cpu_to_node(i)); else slot = __vmalloc_node(size, sizeof(void *), pool->gfp,