Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1928969lqa; Tue, 30 Apr 2024 03:44:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUyfhnYd5ZOapjL0qlF9V8WJuf0qWutFJZytLq1rCqsl0xIDKIFcYGKEzYmV+gzhc27w5ahfw5gF6n1r21u3bFGOgtpMaHhPlxmqXO41Q== X-Google-Smtp-Source: AGHT+IEvdvfzGzVF63Bs04MiEm/rT1J0rypNoKfu6WNydSKYECRDNDXmSrCEOilciRG0FXaNLJeC X-Received: by 2002:a50:d68d:0:b0:570:3b4:53ff with SMTP id r13-20020a50d68d000000b0057003b453ffmr1600912edi.6.1714473843272; Tue, 30 Apr 2024 03:44:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714473843; cv=pass; d=google.com; s=arc-20160816; b=FU2wd2eTOaP4YsRR4taHHPzIxrb42KCEJegeRr7+BdlZUp2zaWmQNxmhXCnpPyhPtZ 7Bvhb0IvHzXNiTo+oblP7cyZ+IbIo+6QgX1JTe4oH5UelD2Eiy6iCckL2fFxELsCcgPg ofuB5j65P2pBgNQXr7bTGdemwiBe0vkVtEorhY4Gw6vkZuGMdOuhd0Z4IkymuN4EDuwp xE9aWGVciGRUo6gaWSuX8KkmtbwZh7gtWLc2bjftJjTlbyyEdXdtEWiyP5Fd3kk5faGF jaMMaLg9IjW92FvZsZkZEMLy1V8ORGyzxIKfjjxjoRNTUL1rfvZEqNAm96iqzwxDfqmf QyxQ== 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=RWDbaID348gi5Wb2g4j4niXzRltFuc9+jsD2KUMySi0=; fh=Cxwo/A+C89tjOzVq8R/o/DH+l+P6Lpt8VwbqwppZI0Y=; b=ap9Q05zfaiJx1Wr3msJcdx0RGlNDTqKA96/0vafgzWsPf7UAlrXDcwsifjI1vI7FPF moSzOaS9gGVzYZbTvOklL4g/SvwB80S0DrFb4fNtonEFIFWut+D+mwH+hPYFz0rMh1eB dsB5mg/Ay7SYHlV/8k0Db2EozLNyPsOZ1WEx5ICxaan2OBcUJzY8IkWqEADIxCGjpvFQ Jl5VL+Nqhw0rEjGY3EiUiCuOQQVgDNXsD86d6uWz7C8zrFppPcnXs43w14BplKTVrNJi //7Eilh8I+XaEsAjj/ZkUd5LIiEBNNdpd5eWcC+cO+sGQ+CbAjv2zHfnPpHLOfsxXiS3 /l4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CwemDBum; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-163785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163785-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 a30-20020a509b5e000000b005726b824aafsi4138631edj.396.2024.04.30.03.44.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 03:44:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163785-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=CwemDBum; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-163785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163785-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 068451F215FC for ; Tue, 30 Apr 2024 10:44:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E2F112CDAE; Tue, 30 Apr 2024 10:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CwemDBum" 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 3DA5412CD88; Tue, 30 Apr 2024 10:43:37 +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=1714473817; cv=none; b=iW1hVUETOju28OBy+19P8RTpnqzj89DH9oM5+p1mS8bvOphdp0zi4gfELOL/O8rEz47aNDuspZKTDaBQn2Ba6ErqZmU/3iIBxSCgsw556Goh0QG8kWaziEMrOjJvIFN9dL3IYfbAQVG2xmIJiMoJ0vuK7X2mQBh2YsYkB5QAo74= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714473817; c=relaxed/simple; bh=2DbLgfRPOuQjtWgbOdxT93yoQ/Xxj7Etz/Li4OEnMe4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pg8M96a9FwcRd1QZ+jQfLyuxBPVfRnRRrtt7YwP7OoTxJrZJnoAylFEt8ryK+n3SMDHpRYpyKoiT5WugNBzyZY820naNy4GmrztrGmh9IeWw3IRuHCHKLIAWOlFd8WQTIbH+LtEPe0GhL7ID55iA3rFE2PjHi+53RAJB/NLkdT4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CwemDBum; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7EA2C2BBFC; Tue, 30 Apr 2024 10:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714473817; bh=2DbLgfRPOuQjtWgbOdxT93yoQ/Xxj7Etz/Li4OEnMe4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CwemDBumFWOv3RQoJS6ME8j80MgE/M38tYI5FqsAhMypHiM24SHGc4DG/J2qb1/BR LiiV/dTeClQeZuI+eG1KKrSgQO2yq+Pe7OxFvnZtBHxijTCorqFTmkKQ22/4ZPsG8f +3pZlKn3PEq24wMp57rV6E7Iaeq82xm6KseJIihChz5Y6h8mWQ+eAw4v9p5314pDaE Pm77Js3/u3Halh4f3OLYkw0LGHENEswuAANzQo1sd/cV/Y5OKHYFxZuPr8cA8FToY4 SA26efYxmNZvTEF0eYiL/BTqMvsiG9vvuYIe8h/N+YAJjgD7bPoq5WUNPAeTgen6nC 0EmwNpehbPvKQ== From: Benjamin Tissoires Date: Tue, 30 Apr 2024 12:43:24 +0200 Subject: [PATCH bpf-next v3 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-v3-1-27afe7f3b17c@kernel.org> References: <20240430-bpf-next-v3-0-27afe7f3b17c@kernel.org> In-Reply-To: <20240430-bpf-next-v3-0-27afe7f3b17c@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=1714473809; l=1679; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=2DbLgfRPOuQjtWgbOdxT93yoQ/Xxj7Etz/Li4OEnMe4=; b=bLOyRikr37Rv6TtAU8CNK9bpzfelszIO81xHpwQbLkZkchDjeXzOcB+veuA9vAGW059bXuqOL wbBE8+z3610B3GRskiP899gGK2d5KhojbMCwAdX7gpT17EbB8eTddDP 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 v3 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