From patchwork Thu Apr 21 00:39:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12820961 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8DF6C433F5 for ; Thu, 21 Apr 2022 00:40:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383488AbiDUAmv (ORCPT ); Wed, 20 Apr 2022 20:42:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383557AbiDUAmg (ORCPT ); Wed, 20 Apr 2022 20:42:36 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68239C15; Wed, 20 Apr 2022 17:39:48 -0700 (PDT) Date: Thu, 21 Apr 2022 00:39:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1650501586; bh=OfNKhPyskwu1Q+3O0NrPPcm3lyoLjqwkLF7TAXF+zrM=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:Feedback-ID:From:To:Cc:Date:Subject:Reply-To: Feedback-ID:Message-ID; b=Gv76EDdwK9liHoTdSS5w4HVGCnBoPqoi3KllzNoPJOPyTIw/8Wv6ASNOOEnAaaiV7 USoT99Z/UgYq7jIIHonFsaWa295GFVDledCPqvv3mz7wzzRaM9oi7RZGOTMwP/80Lv +CJeuYfL8NoE16JL/srqKP5qB3g3DZShwM0RmOEnc7Si7lfo2mrbjnj9Dfrcjasi3W FIPRcZY2BdqZJo73Tjn/lEAio+PldaIxuztKQQ8UvgQ+ImRZ/HhuoMp9mWCKdRHTxt Fdfv7fMtgrfHze1/IHWmrEvY+i9eObYepH/YJIb/LcRSJGQI05eT+pPIjO35jDwWWK LSsqxigXJRV/w== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Alexander Lobakin , Maciej Fijalkowski , Song Liu , Kumar Kartikeya Dwivedi , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v2 bpf 08/11] samples/bpf: fix false-positive right-shift underflow warnings Message-ID: <20220421003152.339542-9-alobakin@pm.me> In-Reply-To: <20220421003152.339542-1-alobakin@pm.me> References: <20220421003152.339542-1-alobakin@pm.me> Feedback-ID: 22809121:user:proton MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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; ^ ~~ sizeof(long) is always 8 for the BPF architecture, so this is not correct, but the BPF samples Makefile still uses the Clang native + LLC combo which enforces that. Until the samples are switched to `-target bpf`, do it the usual way: shift by 16 two times (see upper_32_bits() macro in the kernel). 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") Acked-by: Song Liu 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(-) -- 2.36.0 diff --git a/samples/bpf/lathist_kern.c b/samples/bpf/lathist_kern.c index 4adfcbbe6ef4..9744ed547abe 100644 --- a/samples/bpf/lathist_kern.c +++ b/samples/bpf/lathist_kern.c @@ -53,7 +53,7 @@ static unsigned int log2(unsigned int v) static unsigned int log2l(unsigned long v) { - unsigned int hi = v >> 32; + unsigned int hi = (v >> 16) >> 16; if (hi) return log2(hi) + 32; diff --git a/samples/bpf/lwt_len_hist_kern.c b/samples/bpf/lwt_len_hist_kern.c index 1fa14c54963a..bf32fa04c91f 100644 --- a/samples/bpf/lwt_len_hist_kern.c +++ b/samples/bpf/lwt_len_hist_kern.c @@ -49,7 +49,7 @@ static unsigned int log2(unsigned int v) static unsigned int log2l(unsigned long v) { - unsigned int hi = v >> 32; + unsigned int hi = (v >> 16) >> 16; if (hi) return log2(hi) + 32; else diff --git a/samples/bpf/tracex2_kern.c b/samples/bpf/tracex2_kern.c index 5bc696bac27d..6bf22056ff95 100644 --- a/samples/bpf/tracex2_kern.c +++ b/samples/bpf/tracex2_kern.c @@ -57,7 +57,7 @@ static unsigned int log2(unsigned int v) static unsigned int log2l(unsigned long v) { - unsigned int hi = v >> 32; + unsigned int hi = (v >> 16) >> 16; if (hi) return log2(hi) + 32; else