Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp945982pxb; Fri, 22 Apr 2022 15:03:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxm3+W7bSZJIH8IGGYThVw7A3KoZgeGYs3oLwC6VlY7s2mCeNN6uAvb0IZlBwzY6fFKu2fw X-Received: by 2002:a17:90a:8d82:b0:1d8:a5a9:5489 with SMTP id d2-20020a17090a8d8200b001d8a5a95489mr3871977pjo.102.1650665004480; Fri, 22 Apr 2022 15:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650665004; cv=none; d=google.com; s=arc-20160816; b=cRzrab3RQmvIJeQX9iDL5LnZd5mTA0D4HVj7hev+rzhN+fYm8hJTPzLqaAntRep4+n RrHXsr2R2ZIUPLsovtvEStR3l+m3uFA2ekEqosvXs1CHofQCV+cYV2XdGe8r0VrWtxvk 8aQHb9zaOSPDrheewMfvKLbyFpDWuzPEo0QbfyvT4SMe4isV5oTvqqLpTqEtdJ2Jd93C dg0gP/Et4sXKvEJOVMolSIvrbpdZLus9ReXkI/ba+DDwyVorRde4d7jM4CDxAi/nguWn q7B8loDgM3cxOMZcS9rQM9BTfVaT9BPZLWmJUVSP7AzbKTTgrP7PsqgCk7kgqKXBpHKW bQ9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:reply-to:cc :from:to:dkim-signature:date; bh=OfNKhPyskwu1Q+3O0NrPPcm3lyoLjqwkLF7TAXF+zrM=; b=PZRNgqD+27IrtKurveHUF8Cu0/wjK3Hvueb8oI7GX2Lu4cM8zKOp1QN5oOZxnbQ7qe yoxkDaZxOhhQZ6ihc4nh4fujrDUTVnQZQNKiivqAgJ5eQxU85Zk0uMTd+4rphMKuJY7P /JvRYWXSQP22YAxkPK23Qe81CymtFo9keloErp+HEBcNvhoiV0ejWmJq8BDaUS93NzLU M6Cu82zOpFk0aP8LRYz4skL12Z937aIZSGGFO8Zn6NIDkxoszd5q+yZRW3+YVEIhzpJT qnCtsIBjtUKCcJGTGlFAzaU0n4pP3ifFGPsnXQcw2oy0eHW8QlZs5W6KvdVFE7K5qovw Y5SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=Gv76EDdw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id cm18-20020a056a00339200b004fa86593770si9490780pfb.145.2022.04.22.15.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 15:03:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=Gv76EDdw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8100E37E60F; Fri, 22 Apr 2022 13:11:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383526AbiDUAmv (ORCPT + 99 others); Wed, 20 Apr 2022 20:42:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383561AbiDUAmg (ORCPT ); Wed, 20 Apr 2022 20:42:36 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C8A5C1D for ; 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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no 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 32 bit systems, shifting an unsigned long by 32 positions yields the following warning: samples/bpf/tracex2_kern.c:60:23: warning: shift count >=3D width of type [= -Wshift-count-overflow] unsigned int hi =3D 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() fun= ction 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(-) 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) { -=09unsigned int hi =3D v >> 32; +=09unsigned int hi =3D (v >> 16) >> 16; =09if (hi) =09=09return log2(hi) + 32; diff --git a/samples/bpf/lwt_len_hist_kern.c b/samples/bpf/lwt_len_hist_ker= n.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) { -=09unsigned int hi =3D v >> 32; +=09unsigned int hi =3D (v >> 16) >> 16; =09if (hi) =09=09return log2(hi) + 32; =09else 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) { -=09unsigned int hi =3D v >> 32; +=09unsigned int hi =3D (v >> 16) >> 16; =09if (hi) =09=09return log2(hi) + 32; =09else -- 2.36.0