From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 295DE170A04; Thu, 1 Aug 2024 08:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722502659; cv=none; b=Yb4N82TbnFhKhlrMIWzoU6DmZpeM4vj4vnHk4j0JWPA/WLNvdZCU5v4sp2No7juqutwR5eP9Ta/XuGZm9Cpdm7w229mPGFG0UhCkSzE+dkhOPQ+reALeHYqArWTUXU6pvkGkI0/xUVV2cFX8htxrg8ydgnmLuOBGy0rnd5hevcI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722502659; c=relaxed/simple; bh=k5VaIutaAbdCNTUxxxN3B3JYAkNM71+Jpw/ngo+ftNQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Bg8Mxd7gTsV1WAoMEbioDPrcmFYIn8CvGyav2d4kZl/pyPqxjRc2nJ5gDdkO1zs4m0cf05iW5Mf7zXbnqlK4f9zZzdrSfnCWZT1kAP97kuy8av8EIgawJ/oPRAlo4FkTTfGSbvC5RfP0TCLDil0B0JOpQ4QTkhvDeLJosbfJzos= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=FTGlziMh; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="FTGlziMh" Received: by mail.gandi.net (Postfix) with ESMTPSA id EDFD040009; Thu, 1 Aug 2024 08:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1722502654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3WsXu4DF188KRUc+keQqY5t0HhVNNFj4+qllkduf6go=; b=FTGlziMhNOYWsG4wO3LrWRbe59v6obLoRgt0K7Dk7eP6bEB6xiwoBgqwmm0JCPLBhTkTD6 MrH7/pZ/enn4PFdja31VufJ0kekMOUusqzNZ3+l2MJYXFdliwwul1Yj1Am/pok1q1qpdXk 22UX13wMhKuHnhUQ6R83B3OlqBkktutK0+skgMOafEMfffGFGvSqFF7NBGc8jnN0qoSAaF aD4mauoyrntX443wXXaCpjdcC3EP6W5xN0b8butXab818/kYzFjkr37hHqV0d/DpUe7bRp aIgcbVH027sxjaJYEsxAJvE8JmlqW3Ub3D4SgCsWhZMbBFLchW1O7GCWDGp4Uw== Message-ID: Date: Thu, 1 Aug 2024 10:57:28 +0200 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf-next 1/4] selftests/bpf: convert get_current_cgroup_id_user to test_progs To: Alan Maguire , 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: ebpf@linuxfoundation.org, Thomas Petazzoni , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20240731-convert_cgroup_tests-v1-0-14cbc51b6947@bootlin.com> <20240731-convert_cgroup_tests-v1-1-14cbc51b6947@bootlin.com> From: =?UTF-8?Q?Alexis_Lothor=C3=A9?= Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: alexis.lothore@bootlin.com Hello Alan, On 8/1/24 10:17, Alan Maguire wrote: > On 31/07/2024 19:53, Alexis Lothoré wrote: >> Hello Alan, >> >> On 7/31/24 19:23, Alan Maguire wrote: >>> On 31/07/2024 11:38, Alexis Lothoré (eBPF Foundation) wrote: >> >> [...] >> >>>> + pid = getpid(); >>>> + if (!ASSERT_OK(bpf_map__update_elem(skel->maps.pidmap, &key, >>>> + sizeof(key), &pid, sizeof(pid), 0), >>>> + "write pid")) >>>> + goto cleanup_progs; >>>> + >>> >>> I think it would be worth using a global variable in the BPF program >>> my_pid, and setting skel->bss->my_pid here as other more up-to-date >>> tests do (example progs/test_usdt.c, prog_tests/usdt.c). No need for a >>> separate map anymore. >> >> That sounds like a good improvement, thanks for the hint and the example :) I'll >> spin a new revision with this, and make sure to use it in my next test >> conversion patches too when relevant. >> >> TBH I am not familiar with global variables usage in ebpf/libbpf, so it is not >> clear for me when I should prefer it over classic maps. From some quick search I >> feel like it should be the default choice when needing basic controls >> knobs/feedback on a bpf program from userspace ? Or maybe it should be used even >> more broadly by default ? >> > > Yeah, it's certainly what I use by default, unless I need multiple > instances of an object. Under the hood, the BPF skeleton creates > single-element array maps for .bss, .data and .rodata sections which > contain all the initialized, uninitialized and constant globals in the > BPF object and mmaps() them so you can read/update the values in > userspace via skel->bss/skel->data without needing a map-related syscalls. Thanks a lot for the additional details, much appreciated :) -- Alexis Lothoré, Bootlin Embedded Linux and Kernel engineering https://bootlin.com