Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1131605lqd; Thu, 25 Apr 2024 06:59:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXq75lUsqoqPpnxCyp+lm/legCgPI6WT02o3r3kVvAVec8g4Xm6zQST3jXpBZh6/AmvLrznpoXGFNLDbOE5g1akEiHdxPwtkXB6/R9Ktg== X-Google-Smtp-Source: AGHT+IFhC9JYBHIk16p/CW5AZPK8qgUiFFpuykTIqyN+eolg1aMRw2xmNia+n2tMqcQZHdxce4NQ X-Received: by 2002:a17:906:3084:b0:a52:5baf:23d with SMTP id 4-20020a170906308400b00a525baf023dmr3940698ejv.15.1714053591497; Thu, 25 Apr 2024 06:59:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714053591; cv=pass; d=google.com; s=arc-20160816; b=INZMYK3UhV4qHBIPv23OIT0ZaNl3c5kAxsm7ULODv4tsEWx69d//Zlbg5dseZopF/u OxdPhT+zU7g3XOC0+y8duhCYHKg4ICn4V6AUJzzGpfCAluZRra8LUI4xeBH8Xr0WSjfM m+7g3lUHIGthQ+dW+wc0lCYqvNHoLrFhFafuZuDBXrCCDttcCa35JEGqaBviUDXgcWsq TaXUkOBYt2OHmeoqYn7tFiuJh1wsvvTINyWLqPQpjk4gD3W8fPml20GmokoSi0NFmF2T 2/eHfgEzSd814Yf1D4/dWb4FUYxEz1+4WIEJwsl71AB15Ywnc/Nm4VBVDMkDku5kPnOc Ll1w== 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=XZxxme4zh2pq9SlqEE33aHXjReUfs3vAhV0WKUUXBS0=; fh=Cxwo/A+C89tjOzVq8R/o/DH+l+P6Lpt8VwbqwppZI0Y=; b=EYRaEAeWovOq+JazdkQkInD4w0zGAQmj+4sXvE/WKrHkeTJ01A8b5hCjXr1gT5nxEG fP8WmM6tetaVOpZ8lttzlmfMG0tzTlPinCJAOA5R5OP7xC0B1qmtHFO8E/ShDkZuweXl VA+B5OJ4HTOgzkU48CLwqmMJK998bNsD/f7wR/08uJYPJMA7WgKk5Ei062KHqWRVL1Pn ReHO0j92EkRtvDIEriNhM+FHhkOu0/wky3M37aaa0bTULrXCSbpqgJD9TGSKM1qBPAJX aNAv/0mu2IcYzI4DasxkgvfjN7yD/fhJsHFuhv0nii/6788mSNYglrcPeZGl8ZguAO8x 5ULw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gjQcqWbv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-158638-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158638-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bh26-20020a170906a0da00b00a4737d45afasi10255077ejb.449.2024.04.25.06.59.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 06:59:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158638-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gjQcqWbv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-158638-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158638-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3D3FD1F2263E for ; Thu, 25 Apr 2024 13:59:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F50714A096; Thu, 25 Apr 2024 13:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gjQcqWbv" 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 AABD6149E1A; Thu, 25 Apr 2024 13:59:26 +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=1714053567; cv=none; b=ZNusgrClbFZFP2/TEsY20+y0DLzyiCBVjBam142hGF84gAtnsHLQfY4MxzU4M+Wxg4m33nW8z2pX+gajy5luPZvGSU/yGZQvj2GGGDORWLkQbl9PEUlEl6bEJ5jJ4/E9Y7jSTGWsgpdXh+4hjjdoAYEsp1blZ1KpHuBjpQjtFqk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714053567; c=relaxed/simple; bh=0UjWtmDw4NdWdiV9RiGFH2oVaGYWk2wAWC/NqY/by9Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ei1rgL8me9c+C3ekFzDbLUIqIl/c3XVvSfjsz09DCHQdaTFBKwRaKuKjasJkJa5i045TkwKmPdgSvis6VUI2b551X6vekRP1y/j7PvFSsu0qBjeVENzYjavJxElcCF3RzZUVDqsCC+LbvPjD4KGJ30zzpaDNsMLr88UrqCvW/vs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gjQcqWbv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB899C32783; Thu, 25 Apr 2024 13:59:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714053566; bh=0UjWtmDw4NdWdiV9RiGFH2oVaGYWk2wAWC/NqY/by9Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gjQcqWbveWT4Z3rfSXEl8UidlmtW2NjT9zckTQTkeo5WUxvUK14hRzMfntdGZJZw6 3chcFyQXhhSkQ0KP6pnigxqxM2jVH9GVgkc3vg/u4ynDVh56TkgMBDUXh/0KIzzOgY VvfVH+sAHiReO19p+7Qkx84eOekFWVB7KDYQrnDllSVI6ip/W1aIIw80KyQmQrtxZp oBCFGFBxqP6pcZL21v3fbVXLW5eC8LMjlWA79+d9xwQ8aTVmzPgEMnJbloE+uH+CI3 YrWX6iCoBW+CG25wfuqjgs36c8VihCyav2vn9ZjolqoEdKFgdIV3oSZ/7WKopJVrTP oP/xkv85jvq7w== From: Benjamin Tissoires Date: Thu, 25 Apr 2024 15:59:12 +0200 Subject: [PATCH 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: <20240425-bpf-next-v1-1-1d8330e6c643@kernel.org> References: <20240425-bpf-next-v1-0-1d8330e6c643@kernel.org> In-Reply-To: <20240425-bpf-next-v1-0-1d8330e6c643@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=1714053558; l=1632; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=0UjWtmDw4NdWdiV9RiGFH2oVaGYWk2wAWC/NqY/by9Y=; b=RKtnAsLvD2iqjvzpo5k2I1Q4VyNf7Rj1fx5HEQ/MKI+iKzaLwwaZr/XnRQswXFymVJeBFXfYW gqBO+/jQGrtA7khINJp9kK4fFri609NjGRLuTokCwimqhrKmAoER7J8 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 --- 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