Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1900735lqa; Tue, 30 Apr 2024 02:39:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWxkqRrj5VIU63PpH3lXI8Y/1LmlE94NWCbrLQ3AiJB+qRjdsZ3c2MBWt3RzhWjUrVEicA1bjA/kXiSJJUCxLO/RxbSvBO8qdUtMiCY3A== X-Google-Smtp-Source: AGHT+IHoQXXzn9Puta9cpqkQFkJqjnISWnO7g8aKKwn9QpsucC1QbJibgQ6rAqDmP8/GvJGgGX34 X-Received: by 2002:a05:6a21:8015:b0:1ad:7e4e:428d with SMTP id ou21-20020a056a21801500b001ad7e4e428dmr14074119pzb.20.1714469948736; Tue, 30 Apr 2024 02:39:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714469948; cv=pass; d=google.com; s=arc-20160816; b=vOqQtV9IFtxCDAbnsxM6OklpXINV1tzKDxHqenb69WFVc/d2/+Tbw4cyjRl3Kc4Ito ZwNjxrl4qii6oXJBZFYwPn7ZAR6qQ8fz1it73FyotU5HBftja8HAqSDPINv0tNZ0YmkS fh8rN+hpy/YPr4CKDn+2j3cONM4fIPyfxS+Fj8Sq5NPRi7GsxyIef50W3l0VYKigfDtz udytsbYF677Wq/UwgQ0gEhZ2nBEu5xtNk77mqQ19puuH99FAOXTCOnzXrfjXVbsk8uz+ x/muVlfmntTaDvExa3IcwBkpckcbOUig+JdSyAmjeQmF8zaSpgsFVs2NaYakCBg+Vmtz FOcA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=gcMNsml+GC1l+4JRu4dd732G8nzYrsaHxAzqVed5cKs=; fh=Cxwo/A+C89tjOzVq8R/o/DH+l+P6Lpt8VwbqwppZI0Y=; b=A9voaKNqoIg6v5qVIgKcB1VKBy55oj3+uXkIS1vlgKzaIqYP2iRg1KVDvtuErGjPlA kLEa5JeSXK9uPz1YOTPGtlcCAxGVkuBV2MXmuLFZDlJe4EKN1yPq/heV4Tv3KrAQ40QG 7EuB/glm2wFsxShrlsdjvK9Rktjj6u+TmXgpwKHFamSkLSi2Cfq53hHiDed6OOEhtuIN bERf3t7HPT0ZZ75LgFWWmHUINBLUQnFkMXqsW804DNW6rxElH8pv+FQ7yWSflvhOKQlS jEg+Tj98V30E+bsWfMYzRxR1pDYmxpcMTAexkBDjE2arqc2n5kNbMhaZy3w8MmeSvpN2 M63g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GRIdCHTK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-163709-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163709-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id t12-20020a17090340cc00b001e8f4ff887dsi11109837pld.341.2024.04.30.02.39.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 02:39:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163709-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GRIdCHTK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-163709-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163709-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E112E283BF1 for ; Tue, 30 Apr 2024 09:38:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A2C919DF6B; Tue, 30 Apr 2024 09:36:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GRIdCHTK" 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 9D79C28DDF; Tue, 30 Apr 2024 09:36:25 +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=1714469785; cv=none; b=pG+VEanqL3FNPefOr+BD/kOWjLLE+Fi7RtWmjW9D+VvaReWkfHUhq4YHYlHCe8y8XDXWNkxSA+dj4leb/ONvbsrvINe7qRFV0Aenwi46oTOnAxRoWvMdsJXKdeET5pXFZF+P9ydSY8ngBIVwdmiwclt9PWsXheNqdTz6RYO6cTE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714469785; c=relaxed/simple; bh=O9q/3BVp7ykhUDY0RgKC9pwWwJupmmRs4n4Uim9KjQo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b7H9W/utSHU0e4YX2CF2JFgmz50gn/DMca0M+UXVIVLpsuv8ebsb0lVmn9rOomXKaDErGNTCtTnNN7WYxSI2PS6pndDXhWqi206MI6gCwx4+s8998sjqn6PPKySZCI2ykDvwmisk/7quQdGt6mTowW8t4wode1f89okJQDHffa8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GRIdCHTK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27BA5C4AF4D; Tue, 30 Apr 2024 09:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714469785; bh=O9q/3BVp7ykhUDY0RgKC9pwWwJupmmRs4n4Uim9KjQo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GRIdCHTKlzYxlFIDQZxwLusiDbaaSNK+vyOYCFIS+Eeuwtkc25B5EhSFk7B6hm0AW Bn5v0vU5AsaO/VGeI6QQ8agnAOVJTHihuOnlWVAXnqXKX1pZ7JUWUFmd3jaJu3s61J WFprkS/cLzBy0TjxYJjquM/cO6Jn8njMH0dxF2O6VsqzAjrabmM8o8/0gGbUEXqjPi 7aTXAi0xiIpmURazQOz0DiN7AFp5edaHC6wpTRqx1Bp81bIvozJjpKh3XXk/VQfuDc 8FoyKVb5mNg5nOA4FSaloJe92drJHJ92jjNzZP15GfWsed+PLVFpgLOYtHja2a/rqx iZvaUjo9XT7pQ== From: Benjamin Tissoires Date: Tue, 30 Apr 2024 11:36:10 +0200 Subject: [PATCH v2 1/3] bpf: do not walk twice the map on free 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: 7bit Message-Id: <20240430-bpf-next-v2-1-140aa50f0f19@kernel.org> References: <20240430-bpf-next-v2-0-140aa50f0f19@kernel.org> In-Reply-To: <20240430-bpf-next-v2-0-140aa50f0f19@kernel.org> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714469778; l=1659; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=O9q/3BVp7ykhUDY0RgKC9pwWwJupmmRs4n4Uim9KjQo=; b=0RyqTthwuyYXXJCv8I7WMlwiJL8U8W7Ho72KCoMyZwbQmNDJeUVyrN160lRYUE53SKRsmLoQX TWvL8F4mT2lBbE2+hmP8fKXA1iaDX0Ap0FI62ZgR0QPYq11FKrMzilo X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= If someone stores both a timer and a workqueue in a map, on free we would walk it twice. Add a check in array_map_free_timers_wq and free the timers and workqueues if they are present. Fixes: 246331e3f1ea ("bpf: allow struct bpf_wq to be embedded in arraymaps and hashmaps") Signed-off-by: Benjamin Tissoires --- no changes in v2 --- kernel/bpf/arraymap.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 580d07b15471..feabc0193852 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -436,13 +436,14 @@ static void array_map_free_timers_wq(struct bpf_map *map) /* We don't reset or free fields other than timer and workqueue * on uref dropping to zero. */ - if (btf_record_has_field(map->record, BPF_TIMER)) - for (i = 0; i < array->map.max_entries; i++) - bpf_obj_free_timer(map->record, array_map_elem_ptr(array, i)); - - if (btf_record_has_field(map->record, BPF_WORKQUEUE)) - for (i = 0; i < array->map.max_entries; i++) - bpf_obj_free_workqueue(map->record, array_map_elem_ptr(array, i)); + if (btf_record_has_field(map->record, BPF_TIMER | BPF_WORKQUEUE)) { + for (i = 0; i < array->map.max_entries; i++) { + if (btf_record_has_field(map->record, BPF_TIMER)) + bpf_obj_free_timer(map->record, array_map_elem_ptr(array, i)); + if (btf_record_has_field(map->record, BPF_WORKQUEUE)) + bpf_obj_free_workqueue(map->record, array_map_elem_ptr(array, i)); + } + } } /* Called when map->refcnt goes to zero, either from workqueue or from syscall */ -- 2.44.0