Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp55507lfe; Fri, 15 Apr 2022 19:14:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqUfFxhyBiBXXkJElQqGWkd3mUMwc9sY3ELQEkA9zeGRFfPoHPvoxmn2QZcPnwMXYS1EZm X-Received: by 2002:a63:6f87:0:b0:398:2d6d:848a with SMTP id k129-20020a636f87000000b003982d6d848amr1371480pgc.343.1650075258218; Fri, 15 Apr 2022 19:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650075258; cv=none; d=google.com; s=arc-20160816; b=bOEfYwnFojhIjbDM7HkVNGNA/jGAjwhdXPGSKO0R50NIo09+FSRmvsaSt8kvqHAxv+ ohzBFbDItWqN4m/8jRv1ND4uVn6MXE1O/K9EQT3G1YiGuov+/42gnUIHp/hPhL0Deeia kHB/pfgo+DWn7+thKdZ2Fy/TI3y4DFYY+pN+D7kB1nKrrfaj3SNsJR3XOO1N73txQU6E dAzSbg7YcHJQ0y+euXlFBi65TeIVyt6eXrbt/oJGZZ9qrbMuup14K4DVWW0eS5NwUBJS xMo8YKtukSaw62oljNXawes/xPjdZbOx4BwU0rh8GnNvjDIyRTbSzzTpNc3hjY5Q0MNa Ieig== 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=/5ouIAVwQXcW8KlE3sRRwdzrG6YztYcstZ7gErmL92Y=; b=zWMMCnVKllC+vvrGOS4+sF33ki+ZDi9Qj+vDsFiwLNx+GD8wJBnBA1RzK3hwglr4oA OwBkDUx7wEPit0SBw18NEYn58seNhFRuZKFZGcvP7bFzSq7qV6TRL5znMUhfvjMaelS/ Zo/fiyftmloeEE+D8S+v3JlBNgDGjo9TMXMX+YWTr/S1sGAi6ARSYZf8bwkKO0DkBDMw 9nPN2nqOjR89lA6I0Vfk2FdO93uzkmEyEEpo00yjpPVJ2z5pZaPggOgRP2zSCgkJp+tn w7xy7R/+ASeBnMc5lJOO/V+gq06UDHB6bFrN+xI60n0ySE+b3cLaaPM4ACzjBNi3ufWb FfAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="pOQhh5/F"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n5-20020a170902e54500b00153c0334fd4si337681plf.559.2022.04.15.19.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:14:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="pOQhh5/F"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C2BB3210284; Fri, 15 Apr 2022 18:31:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355487AbiDOX47 (ORCPT + 99 others); Fri, 15 Apr 2022 19:56:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbiDOX44 (ORCPT ); Fri, 15 Apr 2022 19:56:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A81C12AE7; Fri, 15 Apr 2022 16:54:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5E738B831BC; Fri, 15 Apr 2022 23:54:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B83DC385B4; Fri, 15 Apr 2022 23:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650066863; bh=zB3P6rJZN/By5Iuun6emUQBHSdfFSQaOz0rSzPoCu88=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=pOQhh5/FCCUl6mq3o7UPQLlRBJuQIU1MhhHZPGuA+F55YhbJYQjPt77tb4QUxVd1O W0D9K6Nd144QRfk3wXYS04dXgv5kTc7Mnb/fs3nc0aEA8iCHtMdPMSn07ddWCspohY eLd6vn2JqHrGZ7/YlmpU6ktydWKWsC3GZ72EX597u8Plv8Nzxuq+HPkYFbrfY56mvs fKz6iF08n0r1VFB93pBSeHgcdsH1krCsbmhgHLmFuwsfDlJctJlEtUn6QmV3qTn4Hu dMIcdelqBXj49wdXu2nb+c9Pq/oN4SRKP8DA8ZvPf2lvZvxQp6W1Qjivhs676dK+Xu M/bAtVaQBSuNQ== Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-2eafabbc80aso95246127b3.11; Fri, 15 Apr 2022 16:54:22 -0700 (PDT) X-Gm-Message-State: AOAM532ickrxeJeKrzHjlc9dyzFGxDyBMkTz2N1xv9KRkonam6c4MIMF JEAFB2Kzcx0ekruD4stQqohrf0xK/gXvZTxeq3g= X-Received: by 2002:a81:9b57:0:b0:2f1:49eb:1ad9 with SMTP id s84-20020a819b57000000b002f149eb1ad9mr1277161ywg.130.1650066861971; Fri, 15 Apr 2022 16:54:21 -0700 (PDT) MIME-Version: 1.0 References: <20220414223704.341028-1-alobakin@pm.me> <20220414223704.341028-9-alobakin@pm.me> In-Reply-To: <20220414223704.341028-9-alobakin@pm.me> From: Song Liu Date: Fri, 15 Apr 2022 16:54:10 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next 08/11] samples: bpf: fix shifting unsigned long by 32 positions To: Alexander Lobakin Cc: 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 , Yonghong Song , 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-users@vger.kernel.org, open list , Networking , bpf , llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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; > ^ ~~ > > 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 Acked-by: Song Liu > --- > 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) > { > - 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 > -- > 2.35.2 > >