Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp107010ybg; Mon, 8 Jun 2020 17:47:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm8O/w8InkPu7Euu/Z89SJ9UBtCenjQ7fe5SvqoaXbSgC+O+/2y+/2iwaRvvowy2+rmu83 X-Received: by 2002:a17:906:7a19:: with SMTP id d25mr23940893ejo.333.1591663627540; Mon, 08 Jun 2020 17:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663627; cv=none; d=google.com; s=arc-20160816; b=csqAzeE+wjPmnV/CRDHq8DZpZo6TTLQEOfPUotFFiAOFM5nhiy8V4fE6cDUdjTRJ4A wrM0aattvFDbOBNLzvgU9hDHOhwjxr34m5TUt9waSp+tsYf8C5fmbfllrs5eCylCov8C 7gr8mZqWcty1wYlwZ3GTCPMZAHtULpnnPlcsPwHoYT56F/rEc+HpH0Q5aK0QMv30kKl+ COqcB4bK+krMaWSoqzx4AwoWgzI7GKP6sodpJTA+Imx2HZD6NyqVewDOMVRl7wcLAUBb +lOkq8MpMuZvH4XCC3uJ1ZtHipz+gZaxjZEPsU5Yuqzu4j0YLk7EnrMuxVC9+47KaKn0 9+Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LexGp1vVIHJjFjwI4mwclbliZfsViBMTvf3nsv1sF0Q=; b=dD9zqHIW89jdQyAUIVRdgRAVwEDONgsot5nUQm4ICYzYMu+/OYBumf2xX3HUeHZGEm qTmESAbg/olEa5/IzZjWe7Os9vkocGaqFUuvDaHJQXAv64GnOj5Fko8l6D6yid4ezJXo 5yPEuIs7Bm30VdQ0CIL8TGL5C4Ha5atsBeP9ccDGctBBRh5C7RFcqQbwIYpoOX1Td2Gf 7JsJfIKTvGPWRc86WphqevOQfhEVzD9T1Tg9wCjgpFSYRyEkN1j5oIjsJJIC/CDtz4KJ JxHEJq259Xmr6Y+sk/6oi4baapSwQmtxzqL7gAOchvmXP5KfaqQPU9KruoJJ/cK6kTTJ 3hUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jy1vcd0E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q17si10783509edb.42.2020.06.08.17.46.43; Mon, 08 Jun 2020 17:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jy1vcd0E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732750AbgFIApA (ORCPT + 99 others); Mon, 8 Jun 2020 20:45:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:58994 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729008AbgFHXLy (ORCPT ); Mon, 8 Jun 2020 19:11:54 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 79EE820C56; Mon, 8 Jun 2020 23:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657914; bh=NxAJsTGELpCsWIQyrpwGz1O0iqdSozOGgaX3qe3alLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jy1vcd0Eo6Lc4swo5/oWRIvdhu98ZjZbANPilov7WG8NEyRhL4u1YtWTe8BsnhkvQ 1fgNx9jdTNfJwLygc0CgQCL2nyhCSL56PhNqynmsAiO8mIvdWyuRZDOzq0haWociCx a3eBn/I6zOzV6hhm5u+sqksuM2PE92VK3pMo/Lfw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eelco Chaudron , Daniel Borkmann , Andrii Nakryiko , Alexei Starovoitov , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 265/274] libbpf: Fix perf_buffer__free() API for sparse allocs Date: Mon, 8 Jun 2020 19:05:58 -0400 Message-Id: <20200608230607.3361041-265-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eelco Chaudron [ Upstream commit 601b05ca6edb0422bf6ce313fbfd55ec7bbbc0fd ] In case the cpu_bufs are sparsely allocated they are not all free'ed. These changes will fix this. Fixes: fb84b8224655 ("libbpf: add perf buffer API") Signed-off-by: Eelco Chaudron Signed-off-by: Daniel Borkmann Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/159056888305.330763.9684536967379110349.stgit@ebuild Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index cd53204d33f0..0c5b4fb553fb 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -7809,9 +7809,12 @@ void perf_buffer__free(struct perf_buffer *pb) if (!pb) return; if (pb->cpu_bufs) { - for (i = 0; i < pb->cpu_cnt && pb->cpu_bufs[i]; i++) { + for (i = 0; i < pb->cpu_cnt; i++) { struct perf_cpu_buf *cpu_buf = pb->cpu_bufs[i]; + if (!cpu_buf) + continue; + bpf_map_delete_elem(pb->map_fd, &cpu_buf->map_key); perf_buffer__free_cpu_buf(pb, cpu_buf); } -- 2.25.1