Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4845750ioa; Wed, 27 Apr 2022 12:25:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7FedQSocOVmcv1QSUOxDsWlikfD+oznCgLgPdOaC4+8CNVZc0nRyxOHFfL5cdrX4qXZ7w X-Received: by 2002:a65:5acd:0:b0:399:24bc:bbfd with SMTP id d13-20020a655acd000000b0039924bcbbfdmr25127101pgt.323.1651087519961; Wed, 27 Apr 2022 12:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651087519; cv=none; d=google.com; s=arc-20160816; b=xsMT7JaBXL2X8MBOviJ0KLg9jam/geQhyxdgBeeZvZT6KZvrQq3cEgRxx9O5j1q5Oy YW9/HFrT6I/J0h8sU5NAEFw6HO7hSSL4E2g1W5LhBsisrX32EGR51D8QzX82kn4InlbA RuxbsUZRlGWK1Gkhc8dIv9i8c/epFlXrLMoLZlDumBzyLYIGdtlWDBo8Y3XiOez54FMM C4gqSSd4jbOMSq1DXLbjWFyyyjx2t+s5ye4y7o4WZn6dj0AtV6GEsNmQvw1m5KSnZ1Ei UmHIAAfhnAXOC1JcGYx84FvkS4PQ/wYbRtsGcOHjpYWXADLQdsRoWNisbzpohjHHGGeb fuVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=VJ91s6H07ClEByjQbgZruheBlPpsvHRlP6vfpPqzZKY=; b=DJpGA7xN4l+yj/hcUtNjjPfcl9i0V3LgTQwcplABNWQKv02k8cbv5fOPZZEFJXobuZ 2tQxBKDGBmfwxXF6XLB7MIoxdFFC13zUaEyWHdAvdn9OnVttr8DlkEaNgGtgBvhMx3NN ViCDaVF9jXkEWW6Hw1mC7Ph7WShtzxNAFivZARY0y8JaHUlCTuuMPGqeT7kzOAzqQXRl v9lFRHYnqLfUxq32k4fLhuglwDV9O19oYL11Am7Brxjw5VCwRhfwutThJAtKyqFIjLpC AFcDchUTsWV87SjXILYpIrdhyBqzKBnG+HvPwQmMcty8WKNz29IZMD0YUxb37nG+4CRp /rIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EKwxHil5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a63cc05000000b003aa36a97803si2302896pgf.517.2022.04.27.12.25.02; Wed, 27 Apr 2022 12:25:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EKwxHil5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232706AbiD0TH0 (ORCPT + 99 others); Wed, 27 Apr 2022 15:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232434AbiD0THA (ORCPT ); Wed, 27 Apr 2022 15:07:00 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D00EBF71; Wed, 27 Apr 2022 11:53:52 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id f2so3981801ioh.7; Wed, 27 Apr 2022 11:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VJ91s6H07ClEByjQbgZruheBlPpsvHRlP6vfpPqzZKY=; b=EKwxHil5G0kU+wbkmov0G1EaEobARTaBhSglDRm/pqjMlzyw2xWvkwLpGcmiuCwiWJ At36hRwRARLjFsB0PsstrYFE9MGEZmMhqVj6IkdW1Qe3i77MufwhagvCIO3pyldfedH+ 1L5FME3HrT5gXe+YfTuK1vScwvVdBBAvF3r85wZ4RSEairsG6Sl93FEnp+wFW9Lub42h JoeSUxM+XtEzDhZiGXt0UT79mhVEXx13upi3pSqqFpUs393Ub5H4TEiurTeKxrq4SzOx bx8DqZf4u4eSuipwPj4ZXSXZxkJ0PDwLmP82YCvAND/nMeSjVzccZu1gkgmHm97aBOf9 qsLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VJ91s6H07ClEByjQbgZruheBlPpsvHRlP6vfpPqzZKY=; b=7DgfYkHZAWMo6vQgfeQRIq5cEzoy5ln7IM4WnC5QDK5RNvL4sWJhf8HfrdWkhFIOLV hZwD88uaM1y7aZa5X4MtHbpN5H7ivchG2GjCDVFQTsjzbAoYSUehfkSZkAuaLDzYL56w JYvz+MOw2q7H1gWClR1iaI273B5yOzpAZoRvmO87ppgdJHmi1VMNb/gTM48LlIBpGsJ1 f1IczIgT4Pmid1K7r44pCn0Pe6ahYFS9Gcl7BMy6PTzC5HKopCyfYL8vV1j5yTsBY1D+ vvrwmmCHmPwZF4vA2y8nGmx430i6yWvsbAA2wLJGFQdVflkg0Xb741PxTv7Q+CM3q14Y CgCw== X-Gm-Message-State: AOAM532Bq7F0sbmi/E6zbD8SAY5HUkSBJ3uSyn/AWDmJS4Bj5awY7QNB D8gF+4EQofjMuQ93QyuDwEl9BHTLQEPPi0DJ0N4= X-Received: by 2002:a5d:9f4e:0:b0:652:2323:2eb8 with SMTP id u14-20020a5d9f4e000000b0065223232eb8mr12051724iot.79.1651085631636; Wed, 27 Apr 2022 11:53:51 -0700 (PDT) MIME-Version: 1.0 References: <20220414223704.341028-1-alobakin@pm.me> <20220414223704.341028-9-alobakin@pm.me> <05d21d85-7b59-a8f9-73dc-89189986db11@fb.com> In-Reply-To: <05d21d85-7b59-a8f9-73dc-89189986db11@fb.com> From: Andrii Nakryiko Date: Wed, 27 Apr 2022 11:53:40 -0700 Message-ID: Subject: Re: [PATCH bpf-next 08/11] samples: bpf: fix shifting unsigned long by 32 positions To: Yonghong Song Cc: Alexander Lobakin , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , "linux-perf-use." , open list , Networking , bpf , llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 27, 2022 at 8:55 AM Yonghong Song wrote: > > > > On 4/20/22 10:18 AM, Andrii Nakryiko wrote: > > On Thu, Apr 14, 2022 at 3:46 PM Alexander Lobakin wrote: > >> > >> On 32 bit systems, shifting an unsigned long by 32 positions > >> yields the following warning: > >> > >> samples/bpf/tracex2_kern.c:60:23: warning: shift count >= width of type [-Wshift-count-overflow] > >> unsigned int hi = v >> 32; > >> ^ ~~ > >> > > > > long is always 64-bit in BPF, but I suspect this is due to > > samples/bpf/Makefile still using this clang + llc combo, where clang > > is called with native target and llc for -target bpf. Not sure if we > > are ready to ditch that complicated combination. Yonghong, do we still > > need that or can we just use -target bpf in samples/bpf? > > Current most bpf programs in samples/bpf do not use vmlinux.h and CO-RE. > They direct use kernel header files. That is why clang C -> IR > compilation still needs to be native. > > We could just use -target bpf for the whole compilation but that needs > to change the code to use vmlinux.h and CO-RE. There are already a > couple of sample bpf programs did this. Right, I guess I'm proposing to switch samples/bpf to vmlinux.h. Only purely networking BPF apps can get away with not using vmlinux.h because they might avoid dependency on kernel types. But even then a lot of modern networking apps seem to be gaining elements of more generic tracing and would rely on CO-RE for staying "portable" between kernels. So it might be totally fine to just use CO-RE universally in samples/bpf? > > > > > > >> The usual way to avoid this is to shift by 16 two times (see > >> upper_32_bits() macro in the kernel). Use it across the BPF sample > >> code as well. > >> > >> Fixes: d822a1926849 ("samples/bpf: Add counting example for kfree_skb() function calls and the write() syscall") > >> Fixes: 0fb1170ee68a ("bpf: BPF based latency tracing") > >> Fixes: f74599f7c530 ("bpf: Add tests and samples for LWT-BPF") > >> Signed-off-by: Alexander Lobakin > >> --- > >> samples/bpf/lathist_kern.c | 2 +- > >> samples/bpf/lwt_len_hist_kern.c | 2 +- > >> samples/bpf/tracex2_kern.c | 2 +- > >> 3 files changed, 3 insertions(+), 3 deletions(-) > >> > > > > [...]